-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrypt.cpp
More file actions
37 lines (28 loc) · 704 Bytes
/
Crypt.cpp
File metadata and controls
37 lines (28 loc) · 704 Bytes
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
#include "Crypt.h"
#include <functional>
std::hash<uint8_t> hashFunc;
void h(uint8_t* data, uint8_t* rez)
{
// size is NONCE_LEN
uint8_t zero[NONCE_LEN] = { 0 };
int sz = NONCE_LEN;
if (memcmp(&data[NONCE_LEN], zero, NONCE_LEN) != 0)
{
sz *= 2;
}
for (int i = 0; i < sz; i++)
{
rez[i] = hashFunc(data[i]);
}
}
void f(uint8_t* key, uint8_t* data, uint8_t* rez)
{
// size is NONCE_LEN * 2
uint8_t buf[NONCE_LEN * 2] = { 0 };
memcpy(buf, data, NONCE_LEN * sizeof(uint8_t));
memcpy(&buf[NONCE_LEN], key, NONCE_LEN * sizeof(uint8_t));
for (int i = 0; i < NONCE_LEN * 2; i++)
{
rez[i] = hashFunc(buf[i]);
}
}