From e26c95df4413562ccfb7464a5c90539fab8bd18a Mon Sep 17 00:00:00 2001 From: Walker Thompson Date: Wed, 10 Jun 2026 02:33:22 +0200 Subject: Add support for multiple secrets (breaks compatibility + adds dependency: NLohmann JSON) --- crypto.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'crypto.cpp') diff --git a/crypto.cpp b/crypto.cpp index 818f68a..cd5f5f4 100644 --- a/crypto.cpp +++ b/crypto.cpp @@ -20,7 +20,7 @@ extern "C" { sizeof(unsigned char))); bool -TOTPGen::GenTOTP(std::string& secret_str) +TOTPGen::GenTOTP(const std::string& secret_str) { uint32_t bits, code, count, hmacsize; uint64_t clock; @@ -87,7 +87,7 @@ TOTPGen::InitAES(const char *passphrase, unsigned char *salt, { char *key_data = strdup(passphrase); int key_text_len = strlen(passphrase); - int nrounds = 0xFF; + int nrounds = 1 << 20; EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), salt, reinterpret_cast(key_data), @@ -97,7 +97,7 @@ TOTPGen::InitAES(const char *passphrase, unsigned char *salt, } bool -TOTPGen::EncryptSecret(std::string& secret_str) +TOTPGen::EncryptDB(const std::string& secret_str) { unsigned char salt[SALT_BYTES], key[KEY_BYTES], iv[IV_BYTES]; @@ -115,7 +115,7 @@ TOTPGen::EncryptSecret(std::string& secret_str) reinterpret_cast(&key), reinterpret_cast(&iv)); - size_t plaintext_len = strlen(secret_str.c_str()) ; + size_t plaintext_len = strlen(secret_str.c_str()); unsigned char *plaintext = AES_BUFFER(plaintext_len); strncpy(reinterpret_cast(plaintext), @@ -129,7 +129,7 @@ TOTPGen::EncryptSecret(std::string& secret_str) EVP_EncryptFinal_ex(ctx, ciphertext + len, &len); ciphertext_len += len; - FILE *secret_file = fopen(SecretFile.c_str(), "wb"); + FILE *secret_file = fopen(SecretDB_File.c_str(), "wb"); if (!secret_file) { return false; } @@ -148,14 +148,14 @@ TOTPGen::EncryptSecret(std::string& secret_str) bool -TOTPGen::DecryptSecret(void) +TOTPGen::DecryptDB(void) { unsigned char salt[SALT_BYTES], key[KEY_BYTES], iv[IV_BYTES]; memset(&key, 0, KEY_BYTES); memset(&iv, 0, IV_BYTES); - FILE *secret_file = fopen(SecretFile.c_str(), "rb"); + FILE *secret_file = fopen(SecretDB_File.c_str(), "rb"); if (!secret_file) { return false; } @@ -190,7 +190,7 @@ TOTPGen::DecryptSecret(void) return false; } - Secret = reinterpret_cast(plaintext); + KeyDB = json::parse(reinterpret_cast(plaintext)); EVP_CIPHER_CTX_free(ctx); free(ciphertext); -- cgit v1.3