@@ -15,6 +15,11 @@ static unsigned int openssl_external_init = 0;
15
15
static unsigned int openssl_init_count = 0 ;
16
16
17
17
18
+ static int sqlcipher_openssl_add_random (void * ctx , void * buffer , int length ) {
19
+ RAND_add (buffer , length , 0 );
20
+ return SQLITE_OK ;
21
+ }
22
+
18
23
/* activate and initialize sqlcipher. Most importantly, this will automatically
19
24
intialize OpenSSL's EVP system if it hasn't already be externally. Note that
20
25
this function may be called multiple times as new codecs are intiialized.
@@ -71,12 +76,14 @@ static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
71
76
72
77
static int sqlcipher_openssl_hmac (void * ctx , unsigned char * hmac_key , int key_sz , unsigned char * in , int in_sz , unsigned char * in2 , int in2_sz , unsigned char * out ) {
73
78
HMAC_CTX hctx ;
79
+ int outlen ;
74
80
HMAC_CTX_init (& hctx );
75
81
HMAC_Init_ex (& hctx , hmac_key , key_sz , EVP_sha1 (), NULL );
76
82
HMAC_Update (& hctx , in , in_sz );
77
83
HMAC_Update (& hctx , in2 , in2_sz );
78
- HMAC_Final (& hctx , out , NULL );
84
+ HMAC_Final (& hctx , out , & outlen );
79
85
HMAC_CTX_cleanup (& hctx );
86
+ sqlcipher_openssl_add_random (ctx , out , outlen );
80
87
return SQLITE_OK ;
81
88
}
82
89
@@ -168,6 +175,7 @@ int sqlcipher_openssl_setup(sqlcipher_provider *p) {
168
175
p -> ctx_cmp = sqlcipher_openssl_ctx_cmp ;
169
176
p -> ctx_init = sqlcipher_openssl_ctx_init ;
170
177
p -> ctx_free = sqlcipher_openssl_ctx_free ;
178
+ p -> add_random = sqlcipher_openssl_add_random ;
171
179
}
172
180
173
181
#endif
0 commit comments