Skip to content

Commit 70ef31f

Browse files
committed
add flag for normalizing pgno in HMAC check
1 parent 7a9b9e3 commit 70ef31f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/crypto.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@
5757
#endif
5858

5959
/* possible flags for cipher_ctx->flags */
60-
#define CIPHER_FLAG_HMAC 0x01
60+
#define CIPHER_FLAG_HMAC 0x01
61+
#define CIPHER_FLAG_LE_PGNO 0x02
6162

6263
#ifndef DEFAULT_CIPHER_FLAGS
63-
#define DEFAULT_CIPHER_FLAGS CIPHER_FLAG_HMAC
64+
#define DEFAULT_CIPHER_FLAGS CIPHER_FLAG_HMAC | CIPHER_FLAG_LE_PGNO
6465
#endif
6566

6667

src/crypto_impl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,11 @@ int sqlcipher_page_hmac(cipher_ctx *ctx, Pgno pgno, unsigned char *in, int in_sz
512512
valid pages out of order in a database */
513513
HMAC_Update(&ctx->hctx, in, in_sz);
514514

515-
HMAC_Update(&ctx->hctx, (const unsigned char*) pgno_le, sizeof(pgno_le));
515+
if(ctx->flags & CIPHER_FLAG_LE_PGNO) /* default compute hmac using little endian */
516+
HMAC_Update(&ctx->hctx, (const unsigned char*) pgno_le, sizeof(pgno_le));
517+
else /* legacy setting - compute using native byte ordering */
518+
HMAC_Update(&ctx->hctx, (const unsigned char*) &pgno, sizeof(pgno));
519+
516520
HMAC_Final(&ctx->hctx, out, NULL);
517521
HMAC_CTX_cleanup(&ctx->hctx);
518522
return SQLITE_OK;

0 commit comments

Comments
 (0)