]> pd.if.org Git - zpackage/blob - crypto/ref10/fe_cswap.c
remove stray debug fprintf
[zpackage] / crypto / ref10 / fe_cswap.c
1 #include <stdint.h>
2
3 /*
4 Replace (f,g) with (g,f) if b == 1;
5 replace (f,g) with (f,g) if b == 0.
6
7 Preconditions: b in {0,1}.
8 */
9
10 void fe_cswap(int32_t f[10], int32_t g[10], unsigned int b) {
11         int32_t f0 = f[0];
12         int32_t f1 = f[1];
13         int32_t f2 = f[2];
14         int32_t f3 = f[3];
15         int32_t f4 = f[4];
16         int32_t f5 = f[5];
17         int32_t f6 = f[6];
18         int32_t f7 = f[7];
19         int32_t f8 = f[8];
20         int32_t f9 = f[9];
21         int32_t g0 = g[0];
22         int32_t g1 = g[1];
23         int32_t g2 = g[2];
24         int32_t g3 = g[3];
25         int32_t g4 = g[4];
26         int32_t g5 = g[5];
27         int32_t g6 = g[6];
28         int32_t g7 = g[7];
29         int32_t g8 = g[8];
30         int32_t g9 = g[9];
31         int32_t x0 = f0 ^ g0;
32         int32_t x1 = f1 ^ g1;
33         int32_t x2 = f2 ^ g2;
34         int32_t x3 = f3 ^ g3;
35         int32_t x4 = f4 ^ g4;
36         int32_t x5 = f5 ^ g5;
37         int32_t x6 = f6 ^ g6;
38         int32_t x7 = f7 ^ g7;
39         int32_t x8 = f8 ^ g8;
40         int32_t x9 = f9 ^ g9;
41         b = -b;
42         x0 &= b;
43         x1 &= b;
44         x2 &= b;
45         x3 &= b;
46         x4 &= b;
47         x5 &= b;
48         x6 &= b;
49         x7 &= b;
50         x8 &= b;
51         x9 &= b;
52         f[0] = f0 ^ x0;
53         f[1] = f1 ^ x1;
54         f[2] = f2 ^ x2;
55         f[3] = f3 ^ x3;
56         f[4] = f4 ^ x4;
57         f[5] = f5 ^ x5;
58         f[6] = f6 ^ x6;
59         f[7] = f7 ^ x7;
60         f[8] = f8 ^ x8;
61         f[9] = f9 ^ x9;
62         g[0] = g0 ^ x0;
63         g[1] = g1 ^ x1;
64         g[2] = g2 ^ x2;
65         g[3] = g3 ^ x3;
66         g[4] = g4 ^ x4;
67         g[5] = g5 ^ x5;
68         g[6] = g6 ^ x6;
69         g[7] = g7 ^ x7;
70         g[8] = g8 ^ x8;
71         g[9] = g9 ^ x9;
72 }