Skip to content

Commit 06630fd

Browse files
committed
Fix invalid use of algorithm symbols
1 parent a80065d commit 06630fd

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

src/cipher_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ sqlite3mcConfigureSQLCipherVersion(sqlite3* db, int configDefault, int legacyVer
629629
static char* defNames[] = { "default:legacy_page_size", "default:kdf_iter", "default:hmac_use", "default:kdf_algorithm", "default:hmac_algorithm", NULL };
630630
static int versionParams[SQLCIPHER_VERSION_MAX][5] =
631631
{
632-
{ 1024, 4000, 0, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
633-
{ 1024, 4000, 1, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
634-
{ 1024, 64000, 1, SQLCIPHER_KDF_ALGORITHM_SHA1, SQLCIPHER_HMAC_ALGORITHM_SHA1 },
635-
{ 4096, 256000, 1, SQLCIPHER_KDF_ALGORITHM_SHA512, SQLCIPHER_HMAC_ALGORITHM_SHA512 }
632+
{ 1024, 4000, 0, SQLCIPHER_ALGORITHM_SHA1, SQLCIPHER_ALGORITHM_SHA1 },
633+
{ 1024, 4000, 1, SQLCIPHER_ALGORITHM_SHA1, SQLCIPHER_ALGORITHM_SHA1 },
634+
{ 1024, 64000, 1, SQLCIPHER_ALGORITHM_SHA1, SQLCIPHER_ALGORITHM_SHA1 },
635+
{ 4096, 256000, 1, SQLCIPHER_ALGORITHM_SHA512, SQLCIPHER_ALGORITHM_SHA512 }
636636
};
637637
if (legacyVersion > 0 && legacyVersion <= SQLCIPHER_VERSION_MAX)
638638
{

src/cipher_sqlcipher.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
** Purpose: Implementation of cipher SQLCipher (version 1 to 4)
44
** Author: Ulrich Telle
55
** Created: 2020-02-02
6-
** Copyright: (c) 2006-2020 Ulrich Telle
6+
** Copyright: (c) 2006-2024 Ulrich Telle
77
** License: MIT
88
*/
99

@@ -31,13 +31,9 @@
3131
#define SQLCIPHER_HMAC_PGNO_NATIVE 0
3232
#define SQLCIPHER_HMAC_SALT_MASK 0x3a
3333

34-
#define SQLCIPHER_KDF_ALGORITHM_SHA1 0
35-
#define SQLCIPHER_KDF_ALGORITHM_SHA256 1
36-
#define SQLCIPHER_KDF_ALGORITHM_SHA512 2
37-
38-
#define SQLCIPHER_HMAC_ALGORITHM_SHA1 0
39-
#define SQLCIPHER_HMAC_ALGORITHM_SHA256 1
40-
#define SQLCIPHER_HMAC_ALGORITHM_SHA512 2
34+
#define SQLCIPHER_ALGORITHM_SHA1 0
35+
#define SQLCIPHER_ALGORITHM_SHA256 1
36+
#define SQLCIPHER_ALGORITHM_SHA512 2
4137

4238
#define SQLCIPHER_HMAC_ALGO_COMPAT 1
4339

@@ -60,13 +56,13 @@
6056
#if SQLCIPHER_VERSION_DEFAULT < SQLCIPHER_VERSION_4
6157
#define SQLCIPHER_KDF_ITER 64000
6258
#define SQLCIPHER_LEGACY_PAGE_SIZE 1024
63-
#define SQLCIPHER_KDF_ALGORITHM SQLCIPHER_KDF_ALGORITHM_SHA1
64-
#define SQLCIPHER_HMAC_ALGORITHM SQLCIPHER_HMAC_ALGORITHM_SHA1
59+
#define SQLCIPHER_KDF_ALGORITHM SQLCIPHER_ALGORITHM_SHA1
60+
#define SQLCIPHER_HMAC_ALGORITHM SQLCIPHER_ALGORITHM_SHA1
6561
#else
6662
#define SQLCIPHER_KDF_ITER 256000
6763
#define SQLCIPHER_LEGACY_PAGE_SIZE 4096
68-
#define SQLCIPHER_KDF_ALGORITHM SQLCIPHER_KDF_ALGORITHM_SHA512
69-
#define SQLCIPHER_HMAC_ALGORITHM SQLCIPHER_HMAC_ALGORITHM_SHA512
64+
#define SQLCIPHER_KDF_ALGORITHM SQLCIPHER_ALGORITHM_SHA512
65+
#define SQLCIPHER_HMAC_ALGORITHM SQLCIPHER_ALGORITHM_SHA512
7066
#endif
7167

7268
SQLITE_PRIVATE CipherParams mcSQLCipherParams[] =
@@ -277,19 +273,19 @@ GenerateKeySQLCipherCipher(void* cipher, BtShared* pBt, char* userPassword, int
277273
{
278274
switch (sqlCipherCipher->m_kdfAlgorithm)
279275
{
280-
case SQLCIPHER_KDF_ALGORITHM_SHA1:
276+
case SQLCIPHER_ALGORITHM_SHA1:
281277
fastpbkdf2_hmac_sha1((unsigned char*) userPassword, passwordLength,
282278
sqlCipherCipher->m_salt, SALTLENGTH_SQLCIPHER,
283279
sqlCipherCipher->m_kdfIter,
284280
sqlCipherCipher->m_key, KEYLENGTH_SQLCIPHER);
285281
break;
286-
case SQLCIPHER_KDF_ALGORITHM_SHA256:
282+
case SQLCIPHER_ALGORITHM_SHA256:
287283
fastpbkdf2_hmac_sha256((unsigned char*) userPassword, passwordLength,
288284
sqlCipherCipher->m_salt, SALTLENGTH_SQLCIPHER,
289285
sqlCipherCipher->m_kdfIter,
290286
sqlCipherCipher->m_key, KEYLENGTH_SQLCIPHER);
291287
break;
292-
case SQLCIPHER_KDF_ALGORITHM_SHA512:
288+
case SQLCIPHER_ALGORITHM_SHA512:
293289
default:
294290
fastpbkdf2_hmac_sha512((unsigned char*) userPassword, passwordLength,
295291
sqlCipherCipher->m_salt, SALTLENGTH_SQLCIPHER,
@@ -312,22 +308,19 @@ GenerateKeySQLCipherCipher(void* cipher, BtShared* pBt, char* userPassword, int
312308
}
313309
switch (algorithm)
314310
{
315-
case SQLCIPHER_KDF_ALGORITHM_SHA1:
316-
case SQLCIPHER_HMAC_ALGORITHM_SHA1:
311+
case SQLCIPHER_ALGORITHM_SHA1:
317312
fastpbkdf2_hmac_sha1(sqlCipherCipher->m_key, KEYLENGTH_SQLCIPHER,
318313
hmacSalt, SALTLENGTH_SQLCIPHER,
319314
sqlCipherCipher->m_fastKdfIter,
320315
sqlCipherCipher->m_hmacKey, KEYLENGTH_SQLCIPHER);
321316
break;
322-
case SQLCIPHER_KDF_ALGORITHM_SHA256:
323-
case SQLCIPHER_HMAC_ALGORITHM_SHA256:
317+
case SQLCIPHER_ALGORITHM_SHA256:
324318
fastpbkdf2_hmac_sha256(sqlCipherCipher->m_key, KEYLENGTH_SQLCIPHER,
325319
hmacSalt, SALTLENGTH_SQLCIPHER,
326320
sqlCipherCipher->m_fastKdfIter,
327321
sqlCipherCipher->m_hmacKey, KEYLENGTH_SQLCIPHER);
328322
break;
329-
case SQLCIPHER_KDF_ALGORITHM_SHA512:
330-
case SQLCIPHER_HMAC_ALGORITHM_SHA512:
323+
case SQLCIPHER_ALGORITHM_SHA512:
331324
default:
332325
fastpbkdf2_hmac_sha512(sqlCipherCipher->m_key, KEYLENGTH_SQLCIPHER,
333326
hmacSalt, SALTLENGTH_SQLCIPHER,

0 commit comments

Comments
 (0)