… | |
… | |
27 | Source for a non-source form of such a combination shall include the |
27 | Source for a non-source form of such a combination shall include the |
28 | source code for the parts of OpenSSL used as well as that of the |
28 | source code for the parts of OpenSSL used as well as that of the |
29 | covered work. |
29 | covered work. |
30 | */ |
30 | */ |
31 | |
31 | |
32 | #ifndef SSLCOMPAT_H |
32 | #ifndef CRYPTO_H__ |
33 | #define SSLCOMPAT_H |
33 | #define CRYPTO_H__ |
34 | |
34 | |
35 | #include <slog.h> |
35 | #include <slog.h> |
36 | |
36 | |
37 | #include <openssl/opensslv.h> |
37 | #include <openssl/opensslv.h> |
38 | #include <openssl/hmac.h> |
38 | #include <openssl/hmac.h> |
|
|
39 | #include <openssl/evp.h> |
39 | |
40 | |
40 | // openssl 0.9.8/1.0.0 compatibility |
41 | // openssl 0.9.8/1.0.0 compatibility |
41 | #if OPENSSL_VERSION_NUMBER < 0x10001000 |
42 | #if OPENSSL_VERSION_NUMBER < 0x10001000 |
42 | #define require101(exp) exp |
43 | #define require101(exp) exp |
43 | #else |
44 | #else |
44 | #define require101(exp) require (exp) |
45 | #define require101(exp) require (exp) |
45 | #endif |
46 | #endif |
46 | |
47 | |
47 | /* this pretty much wraps the slightly weird openssl api */ |
48 | /* this pretty much wraps the slightly weird openssl api */ |
48 | struct hmac |
49 | class hmac |
49 | { |
50 | { |
50 | HMAC_CTX *ctx; |
51 | HMAC_CTX *ctx; |
|
|
52 | |
|
|
53 | public: |
51 | |
54 | |
52 | hmac (); |
55 | hmac (); |
53 | ~hmac (); |
56 | ~hmac (); |
54 | |
57 | |
55 | void init (const void *key = 0, int key_len = 0, const EVP_MD *hash = 0) |
58 | void init (const void *key, int key_len, const EVP_MD *hash = 0) |
56 | { |
59 | { |
57 | require101 (HMAC_Init_ex (ctx, key, key_len, hash, 0)); |
60 | require101 (HMAC_Init_ex (ctx, key, key_len, hash, 0)); |
|
|
61 | } |
|
|
62 | |
|
|
63 | void init () |
|
|
64 | { |
|
|
65 | require101 (HMAC_Init_ex (ctx, 0, 0, 0, 0)); |
58 | } |
66 | } |
59 | |
67 | |
60 | void |
68 | void |
61 | add (const void *data, int len) |
69 | add (const void *data, int len) |
62 | { |
70 | { |
… | |
… | |
74 | { |
82 | { |
75 | return HMAC_size (ctx); |
83 | return HMAC_size (ctx); |
76 | } |
84 | } |
77 | }; |
85 | }; |
78 | |
86 | |
|
|
87 | /* cheap alloc/free wrapper only atm. */ |
|
|
88 | class cipher |
|
|
89 | { |
|
|
90 | EVP_CIPHER_CTX *ctx; |
|
|
91 | |
|
|
92 | public: |
|
|
93 | |
|
|
94 | cipher (); |
|
|
95 | ~cipher (); |
|
|
96 | |
|
|
97 | operator EVP_CIPHER_CTX *() |
|
|
98 | { |
|
|
99 | return ctx; |
|
|
100 | } |
|
|
101 | }; |
|
|
102 | |
79 | #endif |
103 | #endif |
80 | |
104 | |