51QARMA::rotCell(uint8_t incell,
int amount)
53 uint8_t res = ((incell <<
amount) | (incell >> (4-
amount)))& 0xF;
60 uint8_t outcell = 0x0;
61 outcell = incell << 1;
62 uint8_t
t = 0x1 & (incell ^ (incell>>3));
70 uint8_t outcell = 0x0;
71 outcell = incell >> 1;
72 uint8_t
t = 0x1 & (incell ^ (incell>>1));
82 outdata.b1 = indata.b13;
83 outdata.b2 = indata.b5;
84 outdata.b3 = indata.b6;
85 outdata.b4 = indata.b0;
86 outdata.b5 = indata.b1;
88 outdata.b7 = indata.b3;
93 outdata.b12 = indata.b8;
94 outdata.b13 = indata.b9;
95 outdata.b14 = indata.b10;
104 outdata.b0 = indata.b4;
105 outdata.b1 = indata.b5;
107 outdata.b3 = indata.b7;
109 outdata.b5 = indata.b2;
110 outdata.b6 = indata.b3;
112 outdata.b8 = indata.b12;
113 outdata.b9 = indata.b13;
114 outdata.b10 = indata.b14;
117 outdata.b13 = indata.b1;
128 outdata.b0 = indata.b3;
129 outdata.b1 = indata.b6;
130 outdata.b2 = indata.b12;
131 outdata.b3 = indata.b9;
132 outdata.b4 = indata.b14;
133 outdata.b5 = indata.b11;
134 outdata.b6 = indata.b1;
135 outdata.b7 = indata.b4;
136 outdata.b8 = indata.b8;
137 outdata.b9 = indata.b13;
138 outdata.b10 = indata.b7;
139 outdata.b11 = indata.b2;
140 outdata.b12 = indata.b5;
141 outdata.b13 = indata.b0;
142 outdata.b14 = indata.b10;
143 outdata.b15 = indata.b15;
151 outdata.b0 = indata.b13;
152 outdata.b1 = indata.b6;
153 outdata.b2 = indata.b11;
154 outdata.b3 = indata.b0;
155 outdata.b4 = indata.b7;
156 outdata.b5 = indata.b12;
157 outdata.b6 = indata.b1;
158 outdata.b7 = indata.b10;
159 outdata.b8 = indata.b8;
160 outdata.b9 = indata.b3;
161 outdata.b10 = indata.b14;
162 outdata.b11 = indata.b5;
163 outdata.b12 = indata.b2;
164 outdata.b13 = indata.b9;
165 outdata.b14 = indata.b4;
166 outdata.b15 = indata.b15;
175 uint64_t t_output = 0x0;
176 for (
int i=15;
i>=0;
i--) {
177 t_output = t_output << 4;
178 uint8_t
b = (tInput >>
i*4 ) & 0xF;
239 uint64_t t_output = 0x0;
240 for (
int i=15;
i>=0;
i--) {
241 t_output = t_output << 4;
242 uint8_t
b = (tInput >>
i*4 ) & 0xF;
303 uint64_t t_output = 0;
305 for (
int i=0;
i<=3;
i++) {
306 uint8_t
b8 = (tInput >> (4*(
i+8))) & 0xF;
307 uint8_t
b4 = (tInput >> (4*(
i+4))) & 0xF;
308 uint8_t
b12 = (tInput >> (4*(
i+12))) & 0xF;
309 uint8_t
b0 = (tInput >> (4*(
i))) & 0xF;
311 uint64_t
t0 = rotCell(
b8, 1) ^ rotCell(
b4, 2);
314 uint64_t
t1 = rotCell(
b12, 1) ^ rotCell(
b4, 1);
317 uint64_t
t2 = rotCell(
b12, 2) ^ rotCell(
b8, 1);
320 uint64_t
t3 = rotCell(
b12, 1) ^ rotCell(
b8, 2);
323 t_output |= (
t3 << (4*
i));
324 t_output |= (
t2 << (4*(
i+4)));
325 t_output |= (
t1 << (4*(
i+8)));
326 t_output |= (
t0 << (4*(
i+12)));
338 std::array<BIT64, 5> RC;
339 RC[0] = (BIT64) 0x0000000000000000;
340 RC[1] = (BIT64) 0x13198A2E03707344;
341 RC[2] = (BIT64) 0xA4093822299F31D0;
342 RC[3] = (BIT64) 0x082EFA98EC4E6C89;
343 RC[4] = (BIT64) 0x452821E638D01377;
345 const BIT64 alpha = 0xC0AC29B7C97C50DD;
348 modk0 = (key0 & 0x1) << 63;
349 modk0 = modk0 | ((key0 & ~0x3) >> 1);
350 modk0 = modk0 | ((key0.b15>>3) ^ ((key0.b0 & 0x2)>>1));
352 runningmod = modifier;
353 workingval =
data^key0;
354 for (
int i=0;
i<=4;
i++) {
355 roundkey = key1 ^ runningmod;
356 workingval = workingval ^ roundkey;
357 workingval = workingval ^ RC[
i];
361 workingval =
PACMult(workingval);
363 workingval =
PACSub(workingval);
366 roundkey = modk0 ^ runningmod;
367 workingval = workingval ^ roundkey;
370 workingval =
PACMult(workingval);
371 workingval =
PACSub(workingval);
373 workingval =
PACMult(workingval);
374 workingval = key1 ^ workingval;
378 workingval =
PACMult(workingval);
380 workingval = workingval ^ key0;
381 workingval = workingval ^ runningmod;
383 for (
int i=0;
i<=4;
i++) {
386 workingval =
PACMult(workingval);
390 roundkey = key1 ^ runningmod;
391 workingval = workingval ^ RC[4-
i];
392 workingval = workingval ^ roundkey;
393 workingval = workingval ^ alpha;
395 workingval = workingval ^ modk0;
uint8_t tweakCellRot(uint8_t incell)
BIT64 tweakInvShuffle(BIT64 indata)
uint64_t PACInvSub(uint64_t tInput)
BIT64 PACCellInvShuffle(BIT64 indata)
uint8_t tweakCellInvRot(uint8_t incell)
BIT64 computePAC(BIT64 data, BIT64 modifier, BIT64 key0, BIT64 key1)
uint64_t PACSub(uint64_t tInput)
BIT64 tweakShuffle(BIT64 indata)
BIT64 PACCellShuffle(BIT64 indata)
uint64_t PACMult(uint64_t tInput)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....