@@ -70,6 +70,11 @@ typedef struct {
70
70
cipher_ctx * write_ctx ;
71
71
} codec_ctx ;
72
72
73
+ static void activate_openssl () {
74
+ if (EVP_get_cipherbyname (CIPHER ) == NULL ) {
75
+ OpenSSL_add_all_algorithms ();
76
+ }
77
+ }
73
78
74
79
/*
75
80
** Simple routines for converting hex char strings to binary data
@@ -80,7 +85,7 @@ static int cipher_hex2int(char c) {
80
85
(c >='a' && c <='f' ) ? (c )- 'a' + 10 : 0 ;
81
86
}
82
87
83
- void cipher_hex2bin (const char * hex , int sz , unsigned char * out ){
88
+ static void cipher_hex2bin (const char * hex , int sz , unsigned char * out ){
84
89
int i ;
85
90
for (i = 0 ; i < sz ; i += 2 ){
86
91
out [i /2 ] = (cipher_hex2int (hex [i ])<<4 ) | cipher_hex2int (hex [i + 1 ]);
@@ -410,6 +415,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) {
410
415
struct Db * pDb = & db -> aDb [nDb ];
411
416
412
417
CODEC_TRACE (("sqlite3CodecAttach: entered nDb=%d zKey=%s, nKey=%d\n" , nDb , zKey , nKey ));
418
+ activate_openssl ();
413
419
414
420
if (nKey && zKey && pDb -> pBt ) {
415
421
codec_ctx * ctx ;
@@ -471,7 +477,6 @@ void sqlite3_activate_see(const char* in) {
471
477
472
478
int sqlite3_key (sqlite3 * db , const void * pKey , int nKey ) {
473
479
CODEC_TRACE (("sqlite3_key: entered db=%d pKey=%s nKey=%d\n" , db , pKey , nKey ));
474
- OpenSSL_add_all_algorithms ();
475
480
/* attach key if db and pKey are not null and nKey is > 0 */
476
481
if (db && pKey && nKey ) {
477
482
sqlite3CodecAttach (db , 0 , pKey , nKey ); // operate only on the main db
@@ -496,7 +501,7 @@ int sqlite3_key(sqlite3 *db, const void *pKey, int nKey) {
496
501
*/
497
502
int sqlite3_rekey (sqlite3 * db , const void * pKey , int nKey ) {
498
503
CODEC_TRACE (("sqlite3_rekey: entered db=%d pKey=%s, nKey=%d\n" , db , pKey , nKey ));
499
- OpenSSL_add_all_algorithms ();
504
+ activate_openssl ();
500
505
if (db && pKey && nKey ) {
501
506
struct Db * pDb = & db -> aDb [0 ];
502
507
CODEC_TRACE (("sqlite3_rekey: database pDb=%d\n" , pDb ));
0 commit comments