@@ -664,12 +664,12 @@ int sqlcipher_codec_ctx_get_fast_kdf_iter(codec_ctx *ctx) {
664664
665665/* set the global default flag for HMAC */
666666void sqlcipher_set_default_use_hmac (int use ) {
667- if (use ) default_flags |= CIPHER_FLAG_HMAC ;
668- else default_flags &= ~ CIPHER_FLAG_HMAC ;
667+ if (use ) SQLCIPHER_FLAG_SET ( default_flags , CIPHER_FLAG_HMAC );
668+ else SQLCIPHER_FLAG_UNSET ( default_flags , CIPHER_FLAG_HMAC );
669669}
670670
671671int sqlcipher_get_default_use_hmac () {
672- return (default_flags & CIPHER_FLAG_HMAC ) != 0 ;
672+ return SQLCIPHER_FLAG_GET (default_flags , CIPHER_FLAG_HMAC );
673673}
674674
675675void sqlcipher_set_hmac_salt_mask (unsigned char mask ) {
@@ -683,16 +683,16 @@ unsigned char sqlcipher_get_hmac_salt_mask() {
683683/* set the codec flag for whether this individual database should be using hmac */
684684int sqlcipher_codec_ctx_set_use_hmac (codec_ctx * ctx , int use ) {
685685 if (use ) {
686- sqlcipher_codec_ctx_set_flag (ctx , CIPHER_FLAG_HMAC );
686+ SQLCIPHER_FLAG_SET (ctx -> flags , CIPHER_FLAG_HMAC );
687687 } else {
688- sqlcipher_codec_ctx_unset_flag (ctx , CIPHER_FLAG_HMAC );
688+ SQLCIPHER_FLAG_UNSET (ctx -> flags , CIPHER_FLAG_HMAC );
689689 }
690690
691691 return sqlcipher_codec_ctx_reserve_setup (ctx );
692692}
693693
694694int sqlcipher_codec_ctx_get_use_hmac (codec_ctx * ctx ) {
695- return (ctx -> flags & CIPHER_FLAG_HMAC ) != 0 ;
695+ return SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HMAC );
696696}
697697
698698/* the length of plaintext header size must be:
@@ -761,20 +761,6 @@ int sqlcipher_codec_ctx_get_kdf_algorithm(codec_ctx *ctx) {
761761 return ctx -> kdf_algorithm ;
762762}
763763
764- int sqlcipher_codec_ctx_set_flag (codec_ctx * ctx , unsigned int flag ) {
765- ctx -> flags |= flag ;
766- return SQLITE_OK ;
767- }
768-
769- int sqlcipher_codec_ctx_unset_flag (codec_ctx * ctx , unsigned int flag ) {
770- ctx -> flags &= ~flag ;
771- return SQLITE_OK ;
772- }
773-
774- int sqlcipher_codec_ctx_get_flag (codec_ctx * ctx , unsigned int flag ) {
775- return (ctx -> flags & flag ) != 0 ;
776- }
777-
778764void sqlcipher_codec_ctx_set_error (codec_ctx * ctx , int error ) {
779765 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_codec_ctx_set_error: ctx=%p, error=%d" , ctx , error );
780766 sqlite3pager_error (ctx -> pBt -> pBt -> pPager , error );
@@ -792,7 +778,7 @@ void* sqlcipher_codec_ctx_get_data(codec_ctx *ctx) {
792778static int sqlcipher_codec_ctx_init_kdf_salt (codec_ctx * ctx ) {
793779 sqlite3_file * fd = sqlite3PagerFile (ctx -> pBt -> pBt -> pPager );
794780
795- if (sqlcipher_codec_ctx_get_flag (ctx , CIPHER_FLAG_HAS_KDF_SALT )) {
781+ if (SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HAS_KDF_SALT )) {
796782 return SQLITE_OK ; /* don't reload salt when not needed */
797783 }
798784
@@ -805,14 +791,14 @@ static int sqlcipher_codec_ctx_init_kdf_salt(codec_ctx *ctx) {
805791 return SQLITE_ERROR ;
806792 }
807793 }
808- sqlcipher_codec_ctx_set_flag (ctx , CIPHER_FLAG_HAS_KDF_SALT );
794+ SQLCIPHER_FLAG_SET (ctx -> flags , CIPHER_FLAG_HAS_KDF_SALT );
809795 return SQLITE_OK ;
810796}
811797
812798int sqlcipher_codec_ctx_set_kdf_salt (codec_ctx * ctx , unsigned char * salt , int size ) {
813799 if (size >= ctx -> kdf_salt_sz ) {
814800 memcpy (ctx -> kdf_salt , salt , ctx -> kdf_salt_sz );
815- sqlcipher_codec_ctx_set_flag (ctx , CIPHER_FLAG_HAS_KDF_SALT );
801+ SQLCIPHER_FLAG_SET (ctx -> flags , CIPHER_FLAG_HAS_KDF_SALT );
816802 return SQLITE_OK ;
817803 }
818804 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_codec_ctx_set_kdf_salt: attempt to set salt of incorrect size %d" , size );
@@ -821,7 +807,7 @@ int sqlcipher_codec_ctx_set_kdf_salt(codec_ctx *ctx, unsigned char *salt, int si
821807
822808int sqlcipher_codec_ctx_get_kdf_salt (codec_ctx * ctx , void * * salt ) {
823809 int rc = SQLITE_OK ;
824- if (!sqlcipher_codec_ctx_get_flag (ctx , CIPHER_FLAG_HAS_KDF_SALT )) {
810+ if (!SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HAS_KDF_SALT )) {
825811 if ((rc = sqlcipher_codec_ctx_init_kdf_salt (ctx )) != SQLITE_OK ) {
826812 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_codec_ctx_get_kdf_salt: error %d from sqlcipher_codec_ctx_init_kdf_salt" , rc );
827813 }
@@ -973,8 +959,8 @@ int sqlcipher_codec_ctx_init(codec_ctx **iCtx, Db *pDb, Pager *pPager, const voi
973959
974960 /* Note that use_hmac is a special case that requires recalculation of page size
975961 so we call set_use_hmac to perform setup */
976- if ((rc = sqlcipher_codec_ctx_set_use_hmac (ctx , default_flags & CIPHER_FLAG_HMAC )) != SQLITE_OK ) {
977- sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_codec_ctx_init: error %d setting use_hmac %d" , rc , default_flags & CIPHER_FLAG_HMAC );
962+ if ((rc = sqlcipher_codec_ctx_set_use_hmac (ctx , SQLCIPHER_FLAG_GET ( default_flags , CIPHER_FLAG_HMAC ) )) != SQLITE_OK ) {
963+ sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_codec_ctx_init: error %d setting use_hmac %d" , rc , SQLCIPHER_FLAG_GET ( default_flags , CIPHER_FLAG_HMAC ) );
978964 return rc ;
979965 }
980966
@@ -1051,9 +1037,9 @@ static int sqlcipher_page_hmac(codec_ctx *ctx, cipher_ctx *c_ctx, Pgno pgno, uns
10511037 backwards compatibility on the most popular platforms, but can optionally be configured
10521038 to use either big endian or native byte ordering via pragma. */
10531039
1054- if (ctx -> flags & CIPHER_FLAG_LE_PGNO ) { /* compute hmac using little endian pgno*/
1040+ if (SQLCIPHER_FLAG_GET ( ctx -> flags , CIPHER_FLAG_LE_PGNO ) ) { /* compute hmac using little endian pgno*/
10551041 sqlcipher_put4byte_le (pgno_raw , pgno );
1056- } else if (ctx -> flags & CIPHER_FLAG_BE_PGNO ) { /* compute hmac using big endian pgno */
1042+ } else if (SQLCIPHER_FLAG_GET ( ctx -> flags , CIPHER_FLAG_BE_PGNO ) ) { /* compute hmac using big endian pgno */
10571043 sqlite3Put4byte (pgno_raw , pgno ); /* sqlite3Put4byte converts 32bit uint to big endian */
10581044 } else { /* use native byte ordering */
10591045 memcpy (pgno_raw , & pgno , sizeof (pgno ));
@@ -1109,7 +1095,7 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int
11091095 memcpy (iv_out , iv_in , ctx -> iv_sz ); /* copy the iv from the input to output buffer */
11101096 }
11111097
1112- if ((ctx -> flags & CIPHER_FLAG_HMAC ) && (mode == CIPHER_DECRYPT )) {
1098+ if (SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HMAC ) && (mode == CIPHER_DECRYPT )) {
11131099 if (sqlcipher_page_hmac (ctx , c_ctx , pgno , in , size + ctx -> iv_sz , hmac_out ) != SQLITE_OK ) {
11141100 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_page_cipher: hmac operation on decrypt failed for pgno=%d" , pgno );
11151101 goto error ;
@@ -1140,7 +1126,7 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int
11401126 goto error ;
11411127 };
11421128
1143- if ((ctx -> flags & CIPHER_FLAG_HMAC ) && (mode == CIPHER_ENCRYPT )) {
1129+ if (SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HMAC ) && (mode == CIPHER_ENCRYPT )) {
11441130 if (sqlcipher_page_hmac (ctx , c_ctx , pgno , out_start , size + ctx -> iv_sz , hmac_out ) != SQLITE_OK ) {
11451131 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_page_cipher: hmac operation on encrypt failed for pgno=%d" , pgno );
11461132 goto error ;
@@ -1178,7 +1164,7 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
11781164 if (c_ctx -> pass && c_ctx -> pass_sz ) { /* if key material is present on the context for derivation */
11791165
11801166 /* if necessary, initialize the salt from the header or random source */
1181- if (!sqlcipher_codec_ctx_get_flag (ctx , CIPHER_FLAG_HAS_KDF_SALT )) {
1167+ if (!SQLCIPHER_FLAG_GET (ctx -> flags , CIPHER_FLAG_HAS_KDF_SALT )) {
11821168 if ((rc = sqlcipher_codec_ctx_init_kdf_salt (ctx )) != SQLITE_OK ) {
11831169 sqlcipher_log (SQLCIPHER_LOG_ERROR , "sqlcipher_cipher_ctx_key_derive: error %d from sqlcipher_codec_ctx_init_kdf_salt" , rc );
11841170 return rc ;
@@ -1538,7 +1524,7 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
15381524 if ( rc != SQLITE_OK ) goto handle_error ;
15391525
15401526 sqlcipherCodecGetKey (db , db -> nDb - 1 , (void * * )& keyspec , & keyspec_sz );
1541- sqlcipher_codec_ctx_unset_flag (ctx , CIPHER_FLAG_KEY_USED );
1527+ SQLCIPHER_FLAG_UNSET (ctx -> flags , CIPHER_FLAG_KEY_USED );
15421528 sqlcipherCodecAttach (db , 0 , keyspec , keyspec_sz );
15431529
15441530 srcfile = sqlite3PagerFile (pSrc -> pBt -> pPager );
0 commit comments