-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.h
More file actions
51 lines (34 loc) · 1.29 KB
/
encrypt.h
File metadata and controls
51 lines (34 loc) · 1.29 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Created by buffer on 2022/1/8.
//
#ifndef TUNA_CPP_ENCRYPT_H
#define TUNA_CPP_ENCRYPT_H
#include <cstdlib>
#include <sodium.h>
#include <cstring>
class BaseDecEncrypter {
public:
virtual ~BaseDecEncrypter() = default;
virtual void encrypt(char *dst, size_t dlen, char *src,
size_t slen, unsigned char *nonce) = 0;
virtual void decrypt(char *dst, size_t dlen, char *src,
size_t slen, unsigned char *nonce) = 0;
};
class XSalsa20poly1305Encrypter : public BaseDecEncrypter {
public:
XSalsa20poly1305Encrypter(unsigned char *shared_key, size_t slen);
~XSalsa20poly1305Encrypter() override;
void encrypt(char *dst, size_t dlen, char *src,
size_t slen, unsigned char *nonce);
void decrypt(char *dst, size_t dlen, char *src,
size_t slen, unsigned char *nonce);
public:
unsigned char nonce[crypto_box_NONCEBYTES];
unsigned char max_nonce[crypto_box_NONCEBYTES];
private:
unsigned char shared_key_[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES];
};
void increaseNonce(unsigned char *nonce, size_t len);
void initNonce(unsigned char *initNonce, int nonceSize, bool initiator);
void maxNonce(unsigned char *maxNonce, int nonceSize, bool initiator);
#endif //TUNA_CPP_ENCRYPT_H