aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAleksi Lindeman <0xdec05eba@gmail.com>2018-02-17 14:26:29 +0100
committerAleksi Lindeman <0xdec05eba@gmail.com>2018-03-05 22:48:26 +0100
commit66661e47dc826f50b690e080057f47a0ea27016c (patch)
tree63f0dfd6ed01843daaf78c96ea304d27f4bd2169 /include
parent67957afb6ba01bcd85f1abd1a50ad2c1aa813c7c (diff)
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?
Diffstat (limited to 'include')
-rw-r--r--include/Encryption.hpp29
-rwxr-xr-xinclude/utils.hpp6
2 files changed, 35 insertions, 0 deletions
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 <string>
+
+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);
+}
diff --git a/include/utils.hpp b/include/utils.hpp
new file mode 100755
index 0000000..01e478d
--- /dev/null
+++ b/include/utils.hpp
@@ -0,0 +1,6 @@
+#pragma once
+
+// Disable copying for a class or struct
+#define DISABLE_COPY(ClassName) \
+ ClassName(ClassName&) = delete; \
+ ClassName& operator = (ClassName&) = delete;