44 using namespace QARMA;
48 QARMA::rotCell(uint8_t incell,
int amount)
50 uint8_t res = ((incell <<
amount) | (incell >> (4-
amount)))& 0xF;
57 uint8_t outcell = 0x0;
58 outcell = incell << 1;
59 uint8_t
t = 0x1 & (incell ^ (incell>>3));
67 uint8_t outcell = 0x0;
68 outcell = incell >> 1;
69 uint8_t
t = 0x1 & (incell ^ (incell>>1));
79 outdata.b1 = indata.b13;
80 outdata.b2 = indata.b5;
81 outdata.b3 = indata.b6;
82 outdata.b4 = indata.b0;
83 outdata.b5 = indata.b1;
85 outdata.b7 = indata.b3;
90 outdata.b12 = indata.b8;
91 outdata.b13 = indata.b9;
92 outdata.b14 = indata.b10;
101 outdata.b0 = indata.b4;
102 outdata.b1 = indata.b5;
104 outdata.b3 = indata.b7;
106 outdata.b5 = indata.b2;
107 outdata.b6 = indata.b3;
109 outdata.b8 = indata.b12;
110 outdata.b9 = indata.b13;
111 outdata.b10 = indata.b14;
114 outdata.b13 = indata.b1;
125 outdata.b0 = indata.b3;
126 outdata.b1 = indata.b6;
127 outdata.b2 = indata.b12;
128 outdata.b3 = indata.b9;
129 outdata.b4 = indata.b14;
130 outdata.b5 = indata.b11;
131 outdata.b6 = indata.b1;
132 outdata.b7 = indata.b4;
133 outdata.b8 = indata.b8;
134 outdata.b9 = indata.b13;
135 outdata.b10 = indata.b7;
136 outdata.b11 = indata.b2;
137 outdata.b12 = indata.b5;
138 outdata.b13 = indata.b0;
139 outdata.b14 = indata.b10;
140 outdata.b15 = indata.b15;
148 outdata.b0 = indata.b13;
149 outdata.b1 = indata.b6;
150 outdata.b2 = indata.b11;
151 outdata.b3 = indata.b0;
152 outdata.b4 = indata.b7;
153 outdata.b5 = indata.b12;
154 outdata.b6 = indata.b1;
155 outdata.b7 = indata.b10;
156 outdata.b8 = indata.b8;
157 outdata.b9 = indata.b3;
158 outdata.b10 = indata.b14;
159 outdata.b11 = indata.b5;
160 outdata.b12 = indata.b2;
161 outdata.b13 = indata.b9;
162 outdata.b14 = indata.b4;
163 outdata.b15 = indata.b15;
172 uint64_t t_output = 0x0;
173 for (
int i=15;
i>=0;
i--) {
174 t_output = t_output << 4;
175 uint8_t
b = (tInput >>
i*4 ) & 0xF;
236 uint64_t t_output = 0x0;
237 for (
int i=15;
i>=0;
i--) {
238 t_output = t_output << 4;
239 uint8_t
b = (tInput >>
i*4 ) & 0xF;
300 uint64_t t_output = 0;
302 for (
int i=0;
i<=3;
i++) {
303 uint8_t
b8 = (tInput >> (4*(
i+8))) & 0xF;
304 uint8_t
b4 = (tInput >> (4*(
i+4))) & 0xF;
305 uint8_t
b12 = (tInput >> (4*(
i+12))) & 0xF;
306 uint8_t
b0 = (tInput >> (4*(
i))) & 0xF;
308 uint64_t
t0 = rotCell(
b8, 1) ^ rotCell(
b4, 2);
311 uint64_t
t1 = rotCell(
b12, 1) ^ rotCell(
b4, 1);
314 uint64_t
t2 = rotCell(
b12, 2) ^ rotCell(
b8, 1);
317 uint64_t
t3 = rotCell(
b12, 1) ^ rotCell(
b8, 2);
320 t_output |= (
t3 << (4*
i));
321 t_output |= (
t2 << (4*(
i+4)));
322 t_output |= (
t1 << (4*(
i+8)));
323 t_output |= (
t0 << (4*(
i+12)));
335 std::array<BIT64, 5> RC;
336 RC[0] = (BIT64) 0x0000000000000000;
337 RC[1] = (BIT64) 0x13198A2E03707344;
338 RC[2] = (BIT64) 0xA4093822299F31D0;
339 RC[3] = (BIT64) 0x082EFA98EC4E6C89;
340 RC[4] = (BIT64) 0x452821E638D01377;
342 const BIT64 alpha = 0xC0AC29B7C97C50DD;
345 modk0 = (key0 & 0x1) << 63;
346 modk0 = modk0 | ((key0 & ~0x3) >> 1);
347 modk0 = modk0 | ((key0.b15>>3) ^ ((key0.b0 & 0x2)>>1));
349 runningmod = modifier;
350 workingval =
data^key0;
351 for (
int i=0;
i<=4;
i++) {
352 roundkey = key1 ^ runningmod;
353 workingval = workingval ^ roundkey;
354 workingval = workingval ^ RC[
i];
358 workingval =
PACMult(workingval);
360 workingval =
PACSub(workingval);
363 roundkey = modk0 ^ runningmod;
364 workingval = workingval ^ roundkey;
367 workingval =
PACMult(workingval);
368 workingval =
PACSub(workingval);
370 workingval =
PACMult(workingval);
371 workingval = key1 ^ workingval;
375 workingval =
PACMult(workingval);
377 workingval = workingval ^ key0;
378 workingval = workingval ^ runningmod;
380 for (
int i=0;
i<=4;
i++) {
383 workingval =
PACMult(workingval);
387 roundkey = key1 ^ runningmod;
388 workingval = workingval ^ RC[4-
i];
389 workingval = workingval ^ roundkey;
390 workingval = workingval ^ alpha;
392 workingval = workingval ^ modk0;