@@ -9,6 +9,12 @@ typedef struct {
99
1010static unsigned int ltc_init = 0 ;
1111
12+ static int sqlcipher_ltc_add_random (void * ctx , void * buffer , int length ) {
13+ ltc_ctx * ltc = (ltc_ctx * )ctx ;
14+ int rc = fortuna_add_entropy (buffer , length , & (ltc -> prng ));
15+ return rc != CRYPT_OK ? SQLITE_ERROR : SQLITE_OK ;
16+ }
17+
1218static int sqlcipher_ltc_activate (void * ctx ) {
1319 ltc_ctx * ltc = (ltc_ctx * )ctx ;
1420 sqlite3_mutex_enter (sqlite3MutexAlloc (SQLITE_MUTEX_STATIC_MASTER ));
@@ -40,7 +46,7 @@ static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) {
4046 ltc_ctx * ltc = (ltc_ctx * )ctx ;
4147 sqlite3_randomness (sizeof (random_value ), & random_value );
4248 sqlite3_snprintf (random_buffer_sz , random_buffer , "%d" , random_value );
43- if (fortuna_add_entropy ( random_buffer , random_buffer_sz , & ( ltc -> prng )) != CRYPT_OK ) return SQLITE_ERROR ;
49+ if (sqlcipher_ltc_add_random ( ctx , random_buffer , random_buffer_sz ) != SQLITE_OK ) return SQLITE_ERROR ;
4450 if (fortuna_ready (& (ltc -> prng )) != CRYPT_OK ) return SQLITE_ERROR ;
4551 fortuna_read (buffer , length , & (ltc -> prng ));
4652 return SQLITE_OK ;
@@ -56,6 +62,7 @@ static int sqlcipher_ltc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, un
5662 if ((rc = hmac_process (& hmac , in , in_sz )) != CRYPT_OK ) return SQLITE_ERROR ;
5763 if ((rc = hmac_process (& hmac , in2 , in2_sz )) != CRYPT_OK ) return SQLITE_ERROR ;
5864 if ((rc = hmac_done (& hmac , out , & outlen )) != CRYPT_OK ) return SQLITE_ERROR ;
65+ sqlcipher_ltc_add_random (ctx , out , outlen );
5966 return SQLITE_OK ;
6067}
6168
@@ -148,6 +155,7 @@ int sqlcipher_ltc_setup(sqlcipher_provider *p) {
148155 p -> ctx_cmp = sqlcipher_ltc_ctx_cmp ;
149156 p -> ctx_init = sqlcipher_ltc_ctx_init ;
150157 p -> ctx_free = sqlcipher_ltc_ctx_free ;
158+ p -> add_random = sqlcipher_ltc_add_random ;
151159}
152160
153161
0 commit comments