From 6e4d46f8cf911b82a10e8cd25b65fcc421bbc712 Mon Sep 17 00:00:00 2001 From: Aleksi Lindeman <0xdec05eba@gmail.com> Date: Sat, 14 Apr 2018 19:45:15 +0200 Subject: Store database storage to files, also loading --- src/Encryption.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Encryption.cpp') diff --git a/src/Encryption.cpp b/src/Encryption.cpp index 7f8700b..e67c719 100644 --- a/src/Encryption.cpp +++ b/src/Encryption.cpp @@ -12,14 +12,14 @@ namespace odhtdb if(_key.data) { - if(_key.size != KEY_BYTE_SIZE) + if(_key.size != ENCRYPTION_KEY_BYTE_SIZE) throw EncryptionException("Encryption key is wrong size"); memcpy(key, _key.data, _key.size); } else crypto_aead_xchacha20poly1305_ietf_keygen(key); - randombytes_buf(nonce, NONCE_BYTE_SIZE); + randombytes_buf(nonce, ENCRYPTION_NONCE_BYTE_SIZE); if(crypto_aead_xchacha20poly1305_ietf_encrypt(cipherText, &cipherTextLength, (const unsigned char*)data.data, data.size, (const unsigned char*)additionalData.data, additionalData.size, nullptr, nonce, key) < 0) throw EncryptionException("Failed to encrypt data"); } @@ -31,12 +31,12 @@ namespace odhtdb DataView Encryption::getKey() const { - return DataView((void*)key, KEY_BYTE_SIZE); + return DataView((void*)key, ENCRYPTION_KEY_BYTE_SIZE); } DataView Encryption::getNonce() const { - return DataView((void*)nonce, NONCE_BYTE_SIZE); + return DataView((void*)nonce, ENCRYPTION_NONCE_BYTE_SIZE); } DataView Encryption::getCipherText() const @@ -49,10 +49,10 @@ namespace odhtdb decryptedText = new unsigned char[data.size]; decryptedTextLength = data.size; - if(nonce.size < NONCE_BYTE_SIZE) + if(nonce.size < ENCRYPTION_NONCE_BYTE_SIZE) throw DecryptionException("Nonce is not big enough"); - if(key.size < KEY_BYTE_SIZE) + if(key.size < ENCRYPTION_KEY_BYTE_SIZE) throw DecryptionException("Key is not big enough"); if(crypto_aead_xchacha20poly1305_ietf_decrypt(decryptedText, &decryptedTextLength, nullptr, (const unsigned char*)data.data, data.size, nullptr, 0, (const unsigned char*)nonce.data, (const unsigned char*)key.data) < 0) -- cgit v1.2.3