From 33e823ddddddd4a13b1a05b90ae5b419b89bcb1d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 17 Feb 2018 14:26:29 +0100 Subject: Add encryption functions (xchacha20) Changed license to GPL 3.0 because of incompatible license with opendht. Should odhtdb stay GPL 3.0 or should opendht be replaced with libdht so license can be changed back to MIT? --- include/Encryption.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/Encryption.hpp (limited to 'include/Encryption.hpp') diff --git a/include/Encryption.hpp b/include/Encryption.hpp new file mode 100644 index 0000000..b70687d --- /dev/null +++ b/include/Encryption.hpp @@ -0,0 +1,29 @@ +#pragma once + +/* + * Encrypts/decrypts data using xchacha20 + */ + +#include + +namespace odhtdb +{ + const int NONCE_BYTE_SIZE = 24; + + struct EncryptedData + { + char nonce[NONCE_BYTE_SIZE]; + std::string data; + }; + + using EncryptionKey = char[32]; + + // Stores randomly generated encryption key in @output + void generateEncryptionKey(EncryptionKey *output); + + // Returns 0 on success, storing encrypted data in @output + int encrypt(EncryptedData *output, const EncryptionKey *key, const void *data, size_t dataSize); + + // Returns 0 on success, storing decrypted data in @output + int decrypt(std::string *output, const EncryptionKey *key, const EncryptedData *encryptedData); +} -- cgit v1.2.3