Debian Codegraph @

crypto_kem/8192128pcf/vec/transpose.h

raw
1 /*
2 This file is for matrix transposition
3 */
4
5 #ifndef TRANSPOSE_H
6 #define TRANSPOSE_H
7
8 /* input: in, a 64x64 matrix over GF(2) */
9 /* output: out, transpose of in */
10 static inline void transpose_64x64(uint64_t * out, uint64_t * in)
11 {
12 int i, j, s, d;
13
14 uint64_t x, y;
15 uint64_t masks[6][2] = {
16 {0x5555555555555555, 0xAAAAAAAAAAAAAAAA},
17 {0x3333333333333333, 0xCCCCCCCCCCCCCCCC},
18 {0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0},
19 {0x00FF00FF00FF00FF, 0xFF00FF00FF00FF00},
20 {0x0000FFFF0000FFFF, 0xFFFF0000FFFF0000},
21 {0x00000000FFFFFFFF, 0xFFFFFFFF00000000}
22 };
23
24 for (i = 0; i < 64; i++)
25 out[i] = in[i];
26
27 for (d = 5; d >= 0; d--)
28 {
29 s = 1 << d;
30
31 for (i = 0; i < 64; i += s*2)
32 for (j = i; j < i+s; j++)
33 {
34 x = (out[j] & masks[d][0]) | ((out[j+s] & masks[d][0]) << s);
35 y = ((out[j] & masks[d][1]) >> s) | (out[j+s] & masks[d][1]);
36
37 out[j+0] = x;
38 out[j+s] = y;
39 }
40 }
41 }
42
43 #endif
44