MCPcopy Create free account
hub / github.com/assaultcube/AC / compress

Function compress

source/src/crypto.cpp:34–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 chunk sboxes[4*256];
33
34 void compress(const chunk *str, chunk state[3])
35 {
36 ASSERT(sizeof(chunk) == 8);
37 chunk a, b, c;
38 chunk aa, bb, cc;
39 chunk x0, x1, x2, x3, x4, x5, x6, x7;
40
41 a = state[0];
42 b = state[1];
43 c = state[2];
44
45 x0 = lilswap(str[0]); x1 = lilswap(str[1]); x2 = lilswap(str[2]); x3 = lilswap(str[3]);
46 x4 = lilswap(str[4]); x5 = lilswap(str[5]); x6 = lilswap(str[6]); x7 = lilswap(str[7]);
47
48 aa = a;
49 bb = b;
50 cc = c;
51 loop(pass_no, TIGER_PASSES)
52 {
53 if(pass_no)
54 {
55 x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL; x1 ^= x0; x2 += x1; x3 -= x2 ^ ((~x1)<<19);
56 x4 ^= x3; x5 += x4; x6 -= x5 ^ ((~x4)>>23); x7 ^= x6;
57 x0 += x7; x1 -= x0 ^ ((~x7)<<19); x2 ^= x1; x3 += x2;
58 x4 -= x3 ^ ((~x2)>>23); x5 ^= x4; x6 += x5; x7 -= x6 ^ 0x0123456789ABCDEFULL;
59 }
60
61#define sb1 (sboxes)
62#define sb2 (sboxes+256)
63#define sb3 (sboxes+256*2)
64#define sb4 (sboxes+256*3)
65
66#define tround(a, b, c, x) \
67 c ^= x; \
68 a -= sb1[((c)>>(0*8))&0xFF] ^ sb2[((c)>>(2*8))&0xFF] ^ \
69 sb3[((c)>>(4*8))&0xFF] ^ sb4[((c)>>(6*8))&0xFF] ; \
70 b += sb4[((c)>>(1*8))&0xFF] ^ sb3[((c)>>(3*8))&0xFF] ^ \
71 sb2[((c)>>(5*8))&0xFF] ^ sb1[((c)>>(7*8))&0xFF] ; \
72 b *= mul;
73
74 uint mul = !pass_no ? 5 : (pass_no==1 ? 7 : 9);
75 tround(a, b, c, x0) tround(b, c, a, x1) tround(c, a, b, x2) tround(a, b, c, x3)
76 tround(b, c, a, x4) tround(c, a, b, x5) tround(a, b, c, x6) tround(b, c, a, x7)
77
78 chunk tmp = a; a = c; c = b; b = tmp;
79 }
80
81 a ^= aa;
82 b -= bb;
83 c += cc;
84
85 state[0] = a;
86 state[1] = b;
87 state[2] = c;
88 }
89
90 void gensboxes()
91 {

Callers 4

gensboxesFunction · 0.85
hash_incrementalFunction · 0.85
hash_finishFunction · 0.85
hashFunction · 0.85

Calls 1

lilswapFunction · 0.85

Tested by

no test coverage detected