-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathutils.c
More file actions
60 lines (50 loc) · 1.34 KB
/
utils.c
File metadata and controls
60 lines (50 loc) · 1.34 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
52
53
54
55
56
57
58
59
60
/*
* SPDX-License-Identifier: MIT
*/
#if defined(HAVE_CONFIG_H)
#include <config.h>
#endif
#include "utils.h"
#include <assert.h>
#include <string.h>
static inline uint16_t num_rec_2(const uint8_t* v) {
uint16_t r;
memcpy(&r, v, sizeof(r));
return le16toh(r);
}
// DecodeChall_3
static bool decode_chall_3(uint8_t* decoded_chall, const uint8_t* chall, unsigned int i,
const faest_paramset_t* params) {
if (i >= params->tau) {
return false;
}
const unsigned int t1 = params->tau1;
const unsigned int k = params->k;
unsigned int lo;
unsigned int hi;
if (i < t1) {
lo = i * k;
hi = (i + 1) * k;
} else {
const unsigned int t = i - t1;
lo = (t1 * k) + (t * (k - 1));
hi = (t1 * k) + ((t + 1) * (k - 1));
}
assert(hi - lo == k || hi - lo == k - 1);
// TODO: this could be implemented more efficiently using bit shifts
for (unsigned int j = lo; j < hi; ++j) {
ptr_set_bit(decoded_chall, j - lo, ptr_get_bit(chall, j));
}
return true;
}
bool decode_all_chall_3(uint16_t* decoded_chall, const uint8_t* chall,
const faest_paramset_t* params) {
for (unsigned int i = 0; i != params->tau; ++i) {
uint8_t tmp[2] = {0};
if (!decode_chall_3(tmp, chall, i, params)) {
return false;
}
decoded_chall[i] = num_rec_2(tmp);
}
return true;
}