Debian Codegraph @

crypto_core/mult3sntrup1277/compact/mult.c

raw
1 // 20250302 djb: port to -Wc++-compat
2 // 20240812 djb: more cryptoint usage
3 #include "crypto_core.h"
4 #include "params.h"
5
6 #include "crypto_int8.h"
7 #include "crypto_int16.h"
8 #define int8 crypto_int8
9 #define int16 crypto_int16
10 typedef int8 small;
11
12 /* works for -16384 <= x < 16384 */
13 static small F3_freeze(int16 x)
14 {
15 return x-3*((10923*x+16384)>>15);
16 }
17
18 void crypto_core(unsigned char *outbytes,const unsigned char *inbytes,const unsigned char *kbytes,const unsigned char *cbytes)
19 {
20 small *h = (small *) outbytes;
21 small f[p];
22 small g[p];
23 int16 fg[p+p-1];
24 int i,j;
25
26 for (i = 0;i < p;++i) {
27 small fi = inbytes[i];
28 small fi0 = crypto_int8_bottombit_01(fi);
29 f[i] = fi0-(fi&(fi0<<1));
30 }
31 for (i = 0;i < p;++i) {
32 small gi = kbytes[i];
33 small gi0 = crypto_int8_bottombit_01(gi);
34 g[i] = gi0-(gi&(gi0<<1));
35 }
36
37 for (i = 0; i < p + p - 1; ++i) fg[i] = 0;
38 for (i = 0; i < p; ++i)
39 for (j = 0; j < p; ++j) fg[i + j] += f[i] * (int16_t)g[j];
40 for (i = p; i < p + p - 1; ++i) fg[i - p] += fg[i];
41 for (i = p; i < p + p - 1; ++i) fg[i - p + 1] += fg[i];
42 for (i = 0; i < p; ++i) h[i] = F3_freeze(fg[i]);
43 }