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
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
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
7268SQLITE_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