@@ -15,6 +15,11 @@ static unsigned int openssl_external_init = 0;
1515static unsigned int openssl_init_count = 0 ;
1616
1717
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+
1823/* activate and initialize sqlcipher. Most importantly, this will automatically
1924 intialize OpenSSL's EVP system if it hasn't already be externally. Note that
2025 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) {
7176
7277static 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 ) {
7378 HMAC_CTX hctx ;
79+ int outlen ;
7480 HMAC_CTX_init (& hctx );
7581 HMAC_Init_ex (& hctx , hmac_key , key_sz , EVP_sha1 (), NULL );
7682 HMAC_Update (& hctx , in , in_sz );
7783 HMAC_Update (& hctx , in2 , in2_sz );
78- HMAC_Final (& hctx , out , NULL );
84+ HMAC_Final (& hctx , out , & outlen );
7985 HMAC_CTX_cleanup (& hctx );
86+ sqlcipher_openssl_add_random (ctx , out , outlen );
8087 return SQLITE_OK ;
8188}
8289
@@ -168,6 +175,7 @@ int sqlcipher_openssl_setup(sqlcipher_provider *p) {
168175 p -> ctx_cmp = sqlcipher_openssl_ctx_cmp ;
169176 p -> ctx_init = sqlcipher_openssl_ctx_init ;
170177 p -> ctx_free = sqlcipher_openssl_ctx_free ;
178+ p -> add_random = sqlcipher_openssl_add_random ;
171179}
172180
173181#endif
0 commit comments