Debian Codegraph @

crypto_kem/6688128f/vec/vec.h

raw
1 // 20240810 djb: even more cryptoint usage
2 // 20240805 djb: more cryptoint usage
3 #ifndef VEC_H
4 #define VEC_H
5 #define vec_inv CRYPTO_NAMESPACE(vec_inv)
6 #define vec_mul CRYPTO_NAMESPACE(vec_mul)
7 #define vec_sq CRYPTO_NAMESPACE(vec_sq)
8
9 #include "params.h"
10
11 #include <stdint.h>
12 #include "crypto_int64.h"
13
14 typedef uint64_t vec;
15
16 static inline vec vec_setbits(vec b)
17 {
18 vec ret = -b;
19
20 return ret;
21 }
22
23 static inline vec vec_set1_16b(uint16_t v)
24 {
25 vec ret;
26
27 ret = v;
28 ret |= crypto_int64_shlmod(ret,16);
29 ret |= crypto_int64_shlmod(ret,32);
30
31 return ret;
32 }
33
34 static inline void vec_copy(vec * out, vec * in)
35 {
36 int i;
37
38 for (i = 0; i < GFBITS; i++)
39 out[i] = in[i];
40 }
41
42 static inline vec vec_or_reduce(vec * a)
43 {
44 int i;
45 vec ret;
46
47 ret = a[0];
48 for (i = 1; i < GFBITS; i++)
49 ret |= a[i];
50
51 return ret;
52 }
53
54 static inline int vec_testz(vec a)
55 {
56 a |= a >> 32;
57 a |= a >> 16;
58 a |= a >> 8;
59 a |= a >> 4;
60 a |= a >> 2;
61 a |= a >> 1;
62
63 return (crypto_int64_bottombit_01(a))^1;
64 }
65
66 void vec_mul(vec *, const vec *, const vec *);
67 void vec_sq(vec *, vec *);
68 void vec_inv(vec *, vec *);
69
70 #endif
71