summaryrefslogtreecommitdiff
path: root/crypto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'crypto.cpp')
-rw-r--r--crypto.cpp16
1 files changed, 8 insertions, 8 deletions
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<unsigned char *>(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<unsigned char *>(&key),
reinterpret_cast<unsigned char *>(&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<char *>(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<const char *>(plaintext);
+ KeyDB = json::parse(reinterpret_cast<const char *>(plaintext));
EVP_CIPHER_CTX_free(ctx);
free(ciphertext);