-
Notifications
You must be signed in to change notification settings - Fork 2
/
elephant.cpp
169 lines (156 loc) · 7.44 KB
/
elephant.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "delirium.hpp"
#include "dumbo.hpp"
#include "jumbo.hpp"
// Thin C wrapper on top of underlying C++ implementation of Elephant
// authenticated encryption with associated data ( Dumbo, Jumbo & Delirium ),
// which can be used for producing shared library object with conformant C-ABI &
// used from other languages such as Rust, Python
// Function prototype
extern "C"
{
void dumbo_encrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes plain text
uint8_t* const __restrict, // M -bytes encrypted text
const size_t, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict // 64 -bit authentication tag
);
bool dumbo_decrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // 64 -bit authentication tag
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes encrypted text
uint8_t* const __restrict, // M -bytes decrypted text
const size_t // byte length of encrypted/ decrypted text = M | >= 0
);
void jumbo_encrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes plain text
uint8_t* const __restrict, // M -bytes encrypted text
const size_t, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict // 64 -bit authentication tag
);
bool jumbo_decrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // 64 -bit authentication tag
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes encrypted text
uint8_t* const __restrict, // M -bytes decrypted text
const size_t // byte length of encrypted/ decrypted text = M | >= 0
);
void delirium_encrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes plain text
uint8_t* const __restrict, // M -bytes encrypted text
const size_t, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict // 128 -bit authentication tag
);
bool delirium_decrypt(
const uint8_t* const __restrict, // 128 -bit secret key
const uint8_t* const __restrict, // 96 -bit nonce
const uint8_t* const __restrict, // 128 -bit authentication tag
const uint8_t* const __restrict, // N -bytes associated data
const size_t, // byte length of associated data = N | >= 0
const uint8_t* const __restrict, // M -bytes encrypted text
uint8_t* const __restrict, // M -bytes decrypted text
const size_t // byte length of encrypted/ decrypted text = M | >= 0
);
}
// Function implementation
extern "C"
{
void dumbo_encrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict txt, // M -bytes plain text
uint8_t* const __restrict enc, // M -bytes encrypted text
const size_t ctlen, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict tag // 64 -bit authentication tag
)
{
dumbo::encrypt(key, nonce, data, dlen, txt, enc, ctlen, tag);
}
bool dumbo_decrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict tag, // 64 -bit authentication tag
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict enc, // M -bytes encrypted text
uint8_t* const __restrict txt, // M -bytes decrypted text
const size_t ctlen // byte length of encrypted/ decrypted text = M | >= 0
)
{
using namespace dumbo;
return decrypt(key, nonce, tag, data, dlen, enc, txt, ctlen);
}
void jumbo_encrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict txt, // M -bytes plain text
uint8_t* const __restrict enc, // M -bytes encrypted text
const size_t ctlen, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict tag // 64 -bit authentication tag
)
{
jumbo::encrypt(key, nonce, data, dlen, txt, enc, ctlen, tag);
}
bool jumbo_decrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict tag, // 64 -bit authentication tag
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict enc, // M -bytes encrypted text
uint8_t* const __restrict txt, // M -bytes decrypted text
const size_t ctlen // byte length of encrypted/ decrypted text = M | >= 0
)
{
using namespace jumbo;
return decrypt(key, nonce, tag, data, dlen, enc, txt, ctlen);
}
void delirium_encrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict txt, // M -bytes plain text
uint8_t* const __restrict enc, // M -bytes encrypted text
const size_t ctlen, // byte length of plain/ encrypted text = M | >= 0
uint8_t* const __restrict tag // 128 -bit authentication tag
)
{
delirium::encrypt(key, nonce, data, dlen, txt, enc, ctlen, tag);
}
bool delirium_decrypt(
const uint8_t* const __restrict key, // 128 -bit secret key
const uint8_t* const __restrict nonce, // 96 -bit nonce
const uint8_t* const __restrict tag, // 128 -bit authentication tag
const uint8_t* const __restrict data, // N -bytes associated data
const size_t dlen, // byte length of associated data = N | >= 0
const uint8_t* const __restrict enc, // M -bytes encrypted text
uint8_t* const __restrict txt, // M -bytes decrypted text
const size_t ctlen // byte length of encrypted/ decrypted text = M | >= 0
)
{
using namespace delirium;
return decrypt(key, nonce, tag, data, dlen, enc, txt, ctlen);
}
}