aboutsummaryrefslogtreecommitdiff
path: root/src/Encryption.cpp
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-14 00:20:11 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-14 00:27:29 +0200
commit9af086151e6d9d3fe88f9e3e21797812a3e701ba (patch)
treea11889f81b8f929c11dccbd2c1c3b3cd74fbb740 /src/Encryption.cpp
parentebff7aeafded4dd9d245dbcfc80d9c8d83fe1242 (diff)
Replace files with sqlite
Using sqlite because sqlite has transactions, storing/loading from files automatically, unloading data that is not accessed often. Removed cosmetic data (node name, username). They can be added using addData by the application that uses odhtdb instead. Database callback functions can now be called with stored data using database.loadNode function. TODO: Add local user storage (with password) back, it has been temorary disabled
Diffstat (limited to 'src/Encryption.cpp')
-rw-r--r--src/Encryption.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Encryption.cpp b/src/Encryption.cpp
index 9000519..ff37270 100644
--- a/src/Encryption.cpp
+++ b/src/Encryption.cpp
@@ -19,7 +19,7 @@ namespace odhtdb
memcpy(key, _key.data, _key.size);
}
else
- crypto_aead_xchacha20poly1305_ietf_keygen(key);
+ generateKey(key);
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)
@@ -46,6 +46,11 @@ namespace odhtdb
return DataView((void*)cipherText, cipherTextLength);
}
+ void Encryption::generateKey(unsigned char *output)
+ {
+ crypto_aead_xchacha20poly1305_ietf_keygen(output);
+ }
+
Decryption::Decryption(const DataView &data, const DataView &nonce, const DataView &key)
{
decryptedTextLength = data.size;