NetBurner 3.1
hash.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef __HASH_H
6 #define __HASH_H
7 
8 #include <stdio.h>
9 
13 #define MD5_HASH_LENGTH (16)
14 #define SHA1_HASH_LENGTH (20)
15 #define SHA2_HASH_LENGTH (32)
16 #define TLS1_HASH_LENGTH MD5_HASH_LENGTH + SHA1_HASH_LENGTH
17 #define TLS1_2_HASH_LENGTH SHA1_HASH_LENGTH + SHA2_HASH_LENGTH
18 #define MAX_HASH_LENGTH SHA2_HASH_LENGTH
19 #define MAX_COMBINED_HASH_LENGTH TLS1_HASH_LENGTH
20 
21 struct __vtable_HASH_CTX_t;
22 
23 struct HASH_CTX
24 {
25  __vtable_HASH_CTX_t *__vtable;
26 
27  void Init();
28  void Update(const unsigned char *data, unsigned int len);
29  void Final(unsigned char *digest);
30  int GetDigestLen() const;
31  int GetOIDLen() const;
32  const unsigned char *GetOID() const;
33 };
34 
35 typedef void (HASH_CTX::*HashInitFn)();
36 typedef void (HASH_CTX::*HashUpdateFn)(const unsigned char *, unsigned int);
37 typedef void (HASH_CTX::*HashFinalFn)(unsigned char *);
38 typedef int (HASH_CTX::*HashDigestLenFn)() const;
39 typedef int (HASH_CTX::*HashOIDLenFn)() const;
40 typedef const unsigned char *(HASH_CTX::*HashOIDFn)() const;
41 
42 struct __vtable_HASH_CTX_t
43 {
44  HashInitFn _Init;
45  HashUpdateFn _Update;
46  HashFinalFn _Final;
47  HashDigestLenFn _GetDigestLen;
48  HashOIDLenFn _GetOIDLen;
49  HashOIDFn _GetOID;
50 };
51 
52 inline void HASH_CTX::Init()
53 {
54  (this->*(this->__vtable->_Init))();
55 }
56 inline void HASH_CTX::Update(const unsigned char *data, unsigned int len)
57 {
58  (this->*(this->__vtable->_Update))(data, len);
59 }
60 
61 inline void HASH_CTX::Final(unsigned char *digest)
62 {
63  (this->*(this->__vtable->_Final))(digest);
64 }
65 inline int HASH_CTX::GetDigestLen() const
66 {
67  return (this->*(this->__vtable->_GetDigestLen))();
68 }
69 inline int HASH_CTX::GetOIDLen() const
70 {
71  return (this->*(this->__vtable->_GetOIDLen))();
72 }
73 inline const unsigned char *HASH_CTX::GetOID() const
74 {
75  return (this->*(this->__vtable->_GetOID))();
76 }
77 
78 #endif /* ----- #ifndef __HASH_H ----- */