add flag for normalizing pgno in HMAC check

This commit is contained in:
Stephen Lombardo 2012-07-17 16:45:02 -04:00
parent 7a9b9e39a1
commit 70ef31ff5d
2 changed files with 8 additions and 3 deletions

View File

@ -57,10 +57,11 @@
#endif
/* possible flags for cipher_ctx->flags */
#define CIPHER_FLAG_HMAC 0x01
#define CIPHER_FLAG_HMAC 0x01
#define CIPHER_FLAG_LE_PGNO 0x02
#ifndef DEFAULT_CIPHER_FLAGS
#define DEFAULT_CIPHER_FLAGS CIPHER_FLAG_HMAC
#define DEFAULT_CIPHER_FLAGS CIPHER_FLAG_HMAC | CIPHER_FLAG_LE_PGNO
#endif

View File

@ -512,7 +512,11 @@ int sqlcipher_page_hmac(cipher_ctx *ctx, Pgno pgno, unsigned char *in, int in_sz
valid pages out of order in a database */
HMAC_Update(&ctx->hctx, in, in_sz);
HMAC_Update(&ctx->hctx, (const unsigned char*) pgno_le, sizeof(pgno_le));
if(ctx->flags & CIPHER_FLAG_LE_PGNO) /* default compute hmac using little endian */
HMAC_Update(&ctx->hctx, (const unsigned char*) pgno_le, sizeof(pgno_le));
else /* legacy setting - compute using native byte ordering */
HMAC_Update(&ctx->hctx, (const unsigned char*) &pgno, sizeof(pgno));
HMAC_Final(&ctx->hctx, out, NULL);
HMAC_CTX_cleanup(&ctx->hctx);
return SQLITE_OK;