Debian Codegraph @

crypto_kem/6688128pc/avx/vec128_gf.h

raw
1 // 20240805 djb: more cryptoint usage
2 // 20240508 djb: eliminated unused vec128_copy, vec128_or_reduce
3 // 20240508 djb: split out of vec128.h
4
5 #ifndef vec128_gf_h
6 #define vec128_gf_h
7
8 #include "params.h"
9 #include "gf.h"
10 #include "vec128.h"
11 #include "crypto_int64.h"
12
13 #define vec128_mul_asm CRYPTO_SHARED_NAMESPACE(vec128_mul_asm)
14 #define vec128_mul_GF CRYPTO_NAMESPACE(vec128_mul_GF)
15 extern void vec128_mul_GF(vec128 [GFBITS], vec128 [GFBITS], gf [SYS_T]);
16
17 static inline void vec128_add(vec128 *c, vec128 *a, vec128 *b)
18 {
19 int i;
20
21 for (i = 0; i < GFBITS; i++)
22 c[i] = vec128_xor(a[i], b[i]);
23 }
24
25 extern void vec128_mul_asm(vec128 *, vec128 *, const vec128 *, int);
26
27 /* bitsliced field multiplications */
28 static inline void vec128_mul(vec128 *h, vec128 *f, const vec128 *g)
29 {
30 vec128_mul_asm(h, f, g, 16);
31 }
32
33 static inline void vec128_mul_gf(vec128 out[ GFBITS ], vec128 v[ GFBITS ], gf a)
34 {
35 int i;
36
37 uint64_t b;
38 vec128 bits[GFBITS];
39
40 for (i = 0; i < GFBITS; i++)
41 {
42 b = crypto_int64_bitmod_mask(a, i);
43 bits[i] = vec128_set2x(b, b);
44 }
45
46 vec128_mul(out, v, bits);
47 }
48
49 static inline void vec_mul_gf(uint64_t out[ GFBITS ], uint64_t v[ GFBITS ], gf a)
50 {
51 int i;
52
53 uint64_t bits[GFBITS];
54 vec128 x[GFBITS], y[GFBITS], z[GFBITS];
55
56 for (i = 0; i < GFBITS; i++)
57 bits[i] = crypto_int64_bitmod_mask(a, i);
58
59 for (i = 0; i < GFBITS; i++)
60 {
61 x[i] = vec128_set2x(v[i], 0);
62 y[i] = vec128_set2x(bits[i], 0);
63 }
64
65 vec128_mul(z, x, y);
66
67 for (i = 0; i < GFBITS; i++)
68 out[i] = vec128_extract(z[i], 0);
69 }
70
71 #endif