blob: b70687da5292229f3d1f3812aed517908d44024a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
}
|