44 using namespace QARMA;
49 QARMA::rotCell(uint8_t incell,
int amount)
51 uint8_t res = ((incell <<
amount) | (incell >> (4-
amount)))& 0xF;
58 uint8_t outcell = 0x0;
59 outcell = incell << 1;
60 uint8_t
t = 0x1 & (incell ^ (incell>>3));
68 uint8_t outcell = 0x0;
69 outcell = incell >> 1;
70 uint8_t
t = 0x1 & (incell ^ (incell>>1));
80 outdata.b1 = indata.b13;
81 outdata.b2 = indata.b5;
82 outdata.b3 = indata.b6;
83 outdata.b4 = indata.b0;
84 outdata.b5 = indata.b1;
86 outdata.b7 = indata.b3;
91 outdata.b12 = indata.b8;
92 outdata.b13 = indata.b9;
93 outdata.b14 = indata.b10;
102 outdata.b0 = indata.b4;
103 outdata.b1 = indata.b5;
105 outdata.b3 = indata.b7;
107 outdata.b5 = indata.b2;
108 outdata.b6 = indata.b3;
110 outdata.b8 = indata.b12;
111 outdata.b9 = indata.b13;
112 outdata.b10 = indata.b14;
115 outdata.b13 = indata.b1;
126 outdata.b0 = indata.b3;
127 outdata.b1 = indata.b6;
128 outdata.b2 = indata.b12;
129 outdata.b3 = indata.b9;
130 outdata.b4 = indata.b14;
131 outdata.b5 = indata.b11;
132 outdata.b6 = indata.b1;
133 outdata.b7 = indata.b4;
134 outdata.b8 = indata.b8;
135 outdata.b9 = indata.b13;
136 outdata.b10 = indata.b7;
137 outdata.b11 = indata.b2;
138 outdata.b12 = indata.b5;
139 outdata.b13 = indata.b0;
140 outdata.b14 = indata.b10;
141 outdata.b15 = indata.b15;
149 outdata.b0 = indata.b13;
150 outdata.b1 = indata.b6;
151 outdata.b2 = indata.b11;
152 outdata.b3 = indata.b0;
153 outdata.b4 = indata.b7;
154 outdata.b5 = indata.b12;
155 outdata.b6 = indata.b1;
156 outdata.b7 = indata.b10;
157 outdata.b8 = indata.b8;
158 outdata.b9 = indata.b3;
159 outdata.b10 = indata.b14;
160 outdata.b11 = indata.b5;
161 outdata.b12 = indata.b2;
162 outdata.b13 = indata.b9;
163 outdata.b14 = indata.b4;
164 outdata.b15 = indata.b15;
173 uint64_t t_output = 0x0;
174 for (
int i=15;
i>=0;
i--) {
175 t_output = t_output << 4;
176 uint8_t
b = (tInput >>
i*4 ) & 0xF;
237 uint64_t t_output = 0x0;
238 for (
int i=15;
i>=0;
i--) {
239 t_output = t_output << 4;
240 uint8_t
b = (tInput >>
i*4 ) & 0xF;
301 uint64_t t_output = 0;
303 for (
int i=0;
i<=3;
i++) {
304 uint8_t
b8 = (tInput >> (4*(
i+8))) & 0xF;
305 uint8_t
b4 = (tInput >> (4*(
i+4))) & 0xF;
306 uint8_t
b12 = (tInput >> (4*(
i+12))) & 0xF;
307 uint8_t
b0 = (tInput >> (4*(
i))) & 0xF;
309 uint64_t
t0 = rotCell(
b8, 1) ^ rotCell(
b4, 2);
312 uint64_t
t1 = rotCell(
b12, 1) ^ rotCell(
b4, 1);
315 uint64_t
t2 = rotCell(
b12, 2) ^ rotCell(
b8, 1);
318 uint64_t
t3 = rotCell(
b12, 1) ^ rotCell(
b8, 2);
321 t_output |= (
t3 << (4*
i));
322 t_output |= (
t2 << (4*(
i+4)));
323 t_output |= (
t1 << (4*(
i+8)));
324 t_output |= (
t0 << (4*(
i+12)));
336 std::array<BIT64, 5> RC;
337 RC[0] = (BIT64) 0x0000000000000000;
338 RC[1] = (BIT64) 0x13198A2E03707344;
339 RC[2] = (BIT64) 0xA4093822299F31D0;
340 RC[3] = (BIT64) 0x082EFA98EC4E6C89;
341 RC[4] = (BIT64) 0x452821E638D01377;
343 const BIT64 alpha = 0xC0AC29B7C97C50DD;
346 modk0 = (key0 & 0x1) << 63;
347 modk0 = modk0 | ((key0 & ~0x3) >> 1);
348 modk0 = modk0 | ((key0.b15>>3) ^ ((key0.b0 & 0x2)>>1));
350 runningmod = modifier;
351 workingval =
data^key0;
352 for (
int i=0;
i<=4;
i++) {
353 roundkey = key1 ^ runningmod;
354 workingval = workingval ^ roundkey;
355 workingval = workingval ^ RC[
i];
359 workingval =
PACMult(workingval);
361 workingval =
PACSub(workingval);
364 roundkey = modk0 ^ runningmod;
365 workingval = workingval ^ roundkey;
368 workingval =
PACMult(workingval);
369 workingval =
PACSub(workingval);
371 workingval =
PACMult(workingval);
372 workingval = key1 ^ workingval;
376 workingval =
PACMult(workingval);
378 workingval = workingval ^ key0;
379 workingval = workingval ^ runningmod;
381 for (
int i=0;
i<=4;
i++) {
384 workingval =
PACMult(workingval);
388 roundkey = key1 ^ runningmod;
389 workingval = workingval ^ RC[4-
i];
390 workingval = workingval ^ roundkey;
391 workingval = workingval ^ alpha;
393 workingval = workingval ^ modk0;