23 #include "Skinny128.h"
25 #include "utility/EndianUtil.h"
26 #include "utility/RotateUtil.h"
27 #include "utility/ProgMemUtil.h"
96 #define USE_AVR_INLINE_ASM 1
99 #ifndef CRYPTO_LITTLE_ENDIAN
100 #error "Arduino platforms are assumed to be little-endian"
110 : s(schedule), r(rounds)
131 #if USE_AVR_INLINE_ASM
135 #define ALIGN256 __attribute__((aligned(256)))
141 static uint8_t
const sbox[256] PROGMEM ALIGN256 = {
142 0x65, 0x4c, 0x6a, 0x42, 0x4b, 0x63, 0x43, 0x6b, 0x55, 0x75, 0x5a, 0x7a,
143 0x53, 0x73, 0x5b, 0x7b, 0x35, 0x8c, 0x3a, 0x81, 0x89, 0x33, 0x80, 0x3b,
144 0x95, 0x25, 0x98, 0x2a, 0x90, 0x23, 0x99, 0x2b, 0xe5, 0xcc, 0xe8, 0xc1,
145 0xc9, 0xe0, 0xc0, 0xe9, 0xd5, 0xf5, 0xd8, 0xf8, 0xd0, 0xf0, 0xd9, 0xf9,
146 0xa5, 0x1c, 0xa8, 0x12, 0x1b, 0xa0, 0x13, 0xa9, 0x05, 0xb5, 0x0a, 0xb8,
147 0x03, 0xb0, 0x0b, 0xb9, 0x32, 0x88, 0x3c, 0x85, 0x8d, 0x34, 0x84, 0x3d,
148 0x91, 0x22, 0x9c, 0x2c, 0x94, 0x24, 0x9d, 0x2d, 0x62, 0x4a, 0x6c, 0x45,
149 0x4d, 0x64, 0x44, 0x6d, 0x52, 0x72, 0x5c, 0x7c, 0x54, 0x74, 0x5d, 0x7d,
150 0xa1, 0x1a, 0xac, 0x15, 0x1d, 0xa4, 0x14, 0xad, 0x02, 0xb1, 0x0c, 0xbc,
151 0x04, 0xb4, 0x0d, 0xbd, 0xe1, 0xc8, 0xec, 0xc5, 0xcd, 0xe4, 0xc4, 0xed,
152 0xd1, 0xf1, 0xdc, 0xfc, 0xd4, 0xf4, 0xdd, 0xfd, 0x36, 0x8e, 0x38, 0x82,
153 0x8b, 0x30, 0x83, 0x39, 0x96, 0x26, 0x9a, 0x28, 0x93, 0x20, 0x9b, 0x29,
154 0x66, 0x4e, 0x68, 0x41, 0x49, 0x60, 0x40, 0x69, 0x56, 0x76, 0x58, 0x78,
155 0x50, 0x70, 0x59, 0x79, 0xa6, 0x1e, 0xaa, 0x11, 0x19, 0xa3, 0x10, 0xab,
156 0x06, 0xb6, 0x08, 0xba, 0x00, 0xb3, 0x09, 0xbb, 0xe6, 0xce, 0xea, 0xc2,
157 0xcb, 0xe3, 0xc3, 0xeb, 0xd6, 0xf6, 0xda, 0xfa, 0xd3, 0xf3, 0xdb, 0xfb,
158 0x31, 0x8a, 0x3e, 0x86, 0x8f, 0x37, 0x87, 0x3f, 0x92, 0x21, 0x9e, 0x2e,
159 0x97, 0x27, 0x9f, 0x2f, 0x61, 0x48, 0x6e, 0x46, 0x4f, 0x67, 0x47, 0x6f,
160 0x51, 0x71, 0x5e, 0x7e, 0x57, 0x77, 0x5f, 0x7f, 0xa2, 0x18, 0xae, 0x16,
161 0x1f, 0xa7, 0x17, 0xaf, 0x01, 0xb2, 0x0e, 0xbe, 0x07, 0xb7, 0x0f, 0xbf,
162 0xe2, 0xca, 0xee, 0xc6, 0xcf, 0xe7, 0xc7, 0xef, 0xd2, 0xf2, 0xde, 0xfe,
163 0xd7, 0xf7, 0xdf, 0xff,
165 static uint8_t
const sbox_inv[256] PROGMEM ALIGN256 = {
166 0xac, 0xe8, 0x68, 0x3c, 0x6c, 0x38, 0xa8, 0xec, 0xaa, 0xae, 0x3a, 0x3e,
167 0x6a, 0x6e, 0xea, 0xee, 0xa6, 0xa3, 0x33, 0x36, 0x66, 0x63, 0xe3, 0xe6,
168 0xe1, 0xa4, 0x61, 0x34, 0x31, 0x64, 0xa1, 0xe4, 0x8d, 0xc9, 0x49, 0x1d,
169 0x4d, 0x19, 0x89, 0xcd, 0x8b, 0x8f, 0x1b, 0x1f, 0x4b, 0x4f, 0xcb, 0xcf,
170 0x85, 0xc0, 0x40, 0x15, 0x45, 0x10, 0x80, 0xc5, 0x82, 0x87, 0x12, 0x17,
171 0x42, 0x47, 0xc2, 0xc7, 0x96, 0x93, 0x03, 0x06, 0x56, 0x53, 0xd3, 0xd6,
172 0xd1, 0x94, 0x51, 0x04, 0x01, 0x54, 0x91, 0xd4, 0x9c, 0xd8, 0x58, 0x0c,
173 0x5c, 0x08, 0x98, 0xdc, 0x9a, 0x9e, 0x0a, 0x0e, 0x5a, 0x5e, 0xda, 0xde,
174 0x95, 0xd0, 0x50, 0x05, 0x55, 0x00, 0x90, 0xd5, 0x92, 0x97, 0x02, 0x07,
175 0x52, 0x57, 0xd2, 0xd7, 0x9d, 0xd9, 0x59, 0x0d, 0x5d, 0x09, 0x99, 0xdd,
176 0x9b, 0x9f, 0x0b, 0x0f, 0x5b, 0x5f, 0xdb, 0xdf, 0x16, 0x13, 0x83, 0x86,
177 0x46, 0x43, 0xc3, 0xc6, 0x41, 0x14, 0xc1, 0x84, 0x11, 0x44, 0x81, 0xc4,
178 0x1c, 0x48, 0xc8, 0x8c, 0x4c, 0x18, 0x88, 0xcc, 0x1a, 0x1e, 0x8a, 0x8e,
179 0x4a, 0x4e, 0xca, 0xce, 0x35, 0x60, 0xe0, 0xa5, 0x65, 0x30, 0xa0, 0xe5,
180 0x32, 0x37, 0xa2, 0xa7, 0x62, 0x67, 0xe2, 0xe7, 0x3d, 0x69, 0xe9, 0xad,
181 0x6d, 0x39, 0xa9, 0xed, 0x3b, 0x3f, 0xab, 0xaf, 0x6b, 0x6f, 0xeb, 0xef,
182 0x26, 0x23, 0xb3, 0xb6, 0x76, 0x73, 0xf3, 0xf6, 0x71, 0x24, 0xf1, 0xb4,
183 0x21, 0x74, 0xb1, 0xf4, 0x2c, 0x78, 0xf8, 0xbc, 0x7c, 0x28, 0xb8, 0xfc,
184 0x2a, 0x2e, 0xba, 0xbe, 0x7a, 0x7e, 0xfa, 0xfe, 0x25, 0x70, 0xf0, 0xb5,
185 0x75, 0x20, 0xb0, 0xf5, 0x22, 0x27, 0xb2, 0xb7, 0x72, 0x77, 0xf2, 0xf7,
186 0x2d, 0x79, 0xf9, 0xbd, 0x7d, 0x29, 0xb9, 0xfd, 0x2b, 0x2f, 0xbb, 0xbf,
187 0x7b, 0x7f, 0xfb, 0xff,
193 "mov r30," reg "\n" \
195 #elif defined(__AVR_HAVE_LPMX__)
197 "mov r30," reg "\n" \
199 #elif defined(__AVR_TINY__)
201 "mov r30," reg "\n" \
205 "mov r30," reg "\n" \
211 #define MIX_COLUMNS(row0, row1, row2, row3) \
212 "eor " row1 "," row2 "\n" \
213 "eor " row2 "," row0 "\n" \
214 "mov __tmp_reg__," row3 "\n" \
215 "eor __tmp_reg__," row2 "\n" \
216 "mov " row3 "," row2 "\n" \
217 "mov " row2 "," row1 "\n" \
218 "mov " row1 "," row0 "\n" \
219 "mov " row0 ",__tmp_reg__\n"
222 #define MIX_COLUMNS_INV(row0, row1, row2, row3) \
223 "mov __tmp_reg__," row3 "\n" \
224 "mov " row3 "," row0 "\n" \
225 "mov " row0 "," row1 "\n" \
226 "mov " row1 "," row2 "\n" \
227 "eor " row3 ",__tmp_reg__\n" \
228 "eor __tmp_reg__," row0 "\n" \
229 "mov " row2 ",__tmp_reg__\n" \
230 "eor " row1 "," row2 "\n"
232 #else // !USE_AVR_INLINE_ASM
234 inline uint32_t skinny128_sbox(uint32_t x)
268 x ^= (((x >> 2) & (x >> 3)) & 0x11111111U);
269 y = (((x << 5) & (x << 1)) & 0x20202020U);
270 x ^= (((x << 5) & (x << 4)) & 0x40404040U) ^ y;
271 y = (((x << 2) & (x << 1)) & 0x80808080U);
272 x ^= (((x >> 2) & (x << 1)) & 0x02020202U) ^ y;
273 y = (((x >> 5) & (x << 1)) & 0x04040404U);
274 x ^= (((x >> 1) & (x >> 2)) & 0x08080808U) ^ y;
279 return ((x & 0x08080808U) << 1) |
280 ((x & 0x32323232U) << 2) |
281 ((x & 0x01010101U) << 5) |
282 ((x & 0x80808080U) >> 6) |
283 ((x & 0x40404040U) >> 4) |
284 ((x & 0x04040404U) >> 2);
287 inline uint32_t skinny128_inv_sbox(uint32_t x)
321 y = (((x >> 1) & (x >> 3)) & 0x01010101U);
322 x ^= (((x >> 2) & (x >> 3)) & 0x10101010U) ^ y;
323 y = (((x >> 6) & (x >> 1)) & 0x02020202U);
324 x ^= (((x >> 1) & (x >> 2)) & 0x08080808U) ^ y;
325 y = (((x << 2) & (x << 1)) & 0x80808080U);
326 x ^= (((x >> 1) & (x << 2)) & 0x04040404U) ^ y;
327 y = (((x << 5) & (x << 1)) & 0x20202020U);
328 x ^= (((x << 4) & (x << 5)) & 0x40404040U) ^ y;
333 return ((x & 0x01010101U) << 2) |
334 ((x & 0x04040404U) << 4) |
335 ((x & 0x02020202U) << 6) |
336 ((x & 0x20202020U) >> 5) |
337 ((x & 0xC8C8C8C8U) >> 2) |
338 ((x & 0x10101010U) >> 1);
341 #endif // !USE_AVR_INLINE_ASM
345 #if USE_AVR_INLINE_ASM
347 uint32_t sbox_addr = (uint32_t)sbox;
349 uint16_t sbox_addr = (uint16_t)sbox;
351 __asm__ __volatile__ (
374 "in __tmp_reg__,%5\n"
376 "ldd __tmp_reg__,%C3\n"
377 "out %5,__tmp_reg__\n"
402 "ld __tmp_reg__,X+\n"
403 "eor r8,__tmp_reg__\n"
404 "ld __tmp_reg__,X+\n"
405 "eor r9,__tmp_reg__\n"
406 "ld __tmp_reg__,X+\n"
407 "eor r10,__tmp_reg__\n"
408 "ld __tmp_reg__,X+\n"
409 "eor r11,__tmp_reg__\n"
410 "ld __tmp_reg__,X+\n"
411 "eor r12,__tmp_reg__\n"
412 "ld __tmp_reg__,X+\n"
413 "eor r13,__tmp_reg__\n"
414 "ld __tmp_reg__,X+\n"
415 "eor r14,__tmp_reg__\n"
416 "ld __tmp_reg__,X+\n"
417 "eor r15,__tmp_reg__\n"
422 "mov __tmp_reg__,r15\n"
426 "mov r12,__tmp_reg__\n"
427 "mov __tmp_reg__,r19\n"
429 "mov r17,__tmp_reg__\n"
430 "mov __tmp_reg__,r18\n"
432 "mov r16,__tmp_reg__\n"
433 "mov __tmp_reg__,r20\n"
437 "mov r23,__tmp_reg__\n"
440 MIX_COLUMNS(
"r8",
"r12",
"r16",
"r20")
441 MIX_COLUMNS(
"r9",
"r13",
"r17",
"r21")
442 MIX_COLUMNS(
"r10",
"r14",
"r18",
"r22")
443 MIX_COLUMNS(
"r11",
"r15",
"r19",
"r23")
454 "out %5,__tmp_reg__\n"
477 : :
"x"(s),
"z"(input),
"Q"(output),
"Q"(sbox_addr),
480 ,
"I" (_SFR_IO_ADDR(RAMPZ))
482 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
483 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
486 #else // !USE_AVR_INLINE_ASM
488 const uint32_t *schedule;
493 memcpy(state, input,
sizeof(state));
497 for (uint8_t index = r; index > 0; --index, schedule += 2) {
499 state[0] = skinny128_sbox(state[0]);
500 state[1] = skinny128_sbox(state[1]);
501 state[2] = skinny128_sbox(state[2]);
502 state[3] = skinny128_sbox(state[3]);
505 state[0] ^= schedule[0];
506 state[1] ^= schedule[1];
512 state[1] = leftRotate8(state[1]);
513 state[2] = leftRotate16(state[2]);
514 state[3] = leftRotate24(state[3]);
517 state[1] ^= state[2];
518 state[2] ^= state[0];
519 temp = state[3] ^ state[2];
527 memcpy(output, state,
sizeof(state));
528 #endif // !USE_AVR_INLINE_ASM
533 #if USE_AVR_INLINE_ASM
535 uint32_t sbox_addr = (uint32_t)sbox_inv;
537 uint16_t sbox_addr = (uint16_t)sbox_inv;
539 __asm__ __volatile__ (
562 "in __tmp_reg__,%5\n"
564 "ldd __tmp_reg__,%C3\n"
565 "out %5,__tmp_reg__\n"
572 MIX_COLUMNS_INV(
"r8",
"r12",
"r16",
"r20")
573 MIX_COLUMNS_INV(
"r9",
"r13",
"r17",
"r21")
574 MIX_COLUMNS_INV(
"r10",
"r14",
"r18",
"r22")
575 MIX_COLUMNS_INV(
"r11",
"r15",
"r19",
"r23")
578 "mov __tmp_reg__,r12\n"
582 "mov r15,__tmp_reg__\n"
583 "mov __tmp_reg__,r19\n"
585 "mov r17,__tmp_reg__\n"
586 "mov __tmp_reg__,r18\n"
588 "mov r16,__tmp_reg__\n"
589 "mov __tmp_reg__,r23\n"
593 "mov r20,__tmp_reg__\n"
596 "ld __tmp_reg__,-X\n"
597 "eor r15,__tmp_reg__\n"
598 "ld __tmp_reg__,-X\n"
599 "eor r14,__tmp_reg__\n"
600 "ld __tmp_reg__,-X\n"
601 "eor r13,__tmp_reg__\n"
602 "ld __tmp_reg__,-X\n"
603 "eor r12,__tmp_reg__\n"
604 "ld __tmp_reg__,-X\n"
605 "eor r11,__tmp_reg__\n"
606 "ld __tmp_reg__,-X\n"
607 "eor r10,__tmp_reg__\n"
608 "ld __tmp_reg__,-X\n"
609 "eor r9,__tmp_reg__\n"
610 "ld __tmp_reg__,-X\n"
611 "eor r8,__tmp_reg__\n"
642 "out %5,__tmp_reg__\n"
665 : :
"x"(s + r * 2),
"z"(input),
"Q"(output),
"Q"(sbox_addr),
668 ,
"I" (_SFR_IO_ADDR(RAMPZ))
670 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
671 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
674 #else // !USE_AVR_INLINE_ASM
676 const uint32_t *schedule;
681 memcpy(state, input,
sizeof(state));
684 schedule = &(s[r * 2 - 2]);
685 for (uint8_t index = r; index > 0; --index, schedule -= 2) {
692 state[2] = temp ^ state[0];
693 state[1] ^= state[2];
696 state[1] = leftRotate24(state[1]);
697 state[2] = leftRotate16(state[2]);
698 state[3] = leftRotate8(state[3]);
701 state[0] ^= schedule[0];
702 state[1] ^= schedule[1];
706 state[0] = skinny128_inv_sbox(state[0]);
707 state[1] = skinny128_inv_sbox(state[1]);
708 state[2] = skinny128_inv_sbox(state[2]);
709 state[3] = skinny128_inv_sbox(state[3]);
713 memcpy(output, state,
sizeof(state));
714 #endif // !USE_AVR_INLINE_ASM
719 clean(s, r * 2 *
sizeof(uint32_t));
722 #if USE_AVR_INLINE_ASM
726 #define PERMUTE_TKn() \
727 "mov __tmp_reg__,r8\n" \
743 "mov r16,__tmp_reg__\n"
745 #else // !USE_AVR_INLINE_ASM
749 #define skinny128_permute_tk(tk) \
751 uint32_t row2 = tk[2]; \
752 uint32_t row3 = tk[3]; \
755 row3 = (row3 << 16) | (row3 >> 16); \
756 tk[0] = ((row2 >> 8) & 0x000000FFU) | \
757 ((row2 << 16) & 0x00FF0000U) | \
758 ( row3 & 0xFF00FF00U); \
759 tk[1] = ((row2 >> 16) & 0x000000FFU) | \
760 (row2 & 0xFF000000U) | \
761 ((row3 << 8) & 0x0000FF00U) | \
762 ( row3 & 0x00FF0000U); \
765 #endif // !USE_AVR_INLINE_ASM
775 #if USE_AVR_INLINE_ASM
776 __asm__ __volatile__ (
822 "mov __tmp_reg__,%3\n"
823 "eor __tmp_reg__,r10\n"
824 "st X+,__tmp_reg__\n"
844 : :
"x"(s),
"z"(key),
"r"(r),
"r"((uint8_t)(tweaked ? 0x02 : 0x00))
845 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
846 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
847 "r24",
"r25",
"memory"
849 #else // !USE_AVR_INLINE_ASM
851 uint32_t *schedule = s;
856 memcpy(TK1, key,
sizeof(TK1));
859 for (uint8_t index = r; index > 0; --index, schedule += 2) {
863 rc = (rc << 1) ^ ((rc >> 5) & 0x01) ^ ((rc >> 4) & 0x01) ^ 0x01;
865 schedule[0] = TK1[0] ^ (rc & 0x0F);
866 schedule[1] = TK1[1] ^ (rc >> 4);
872 schedule[0] ^= 0x00020000;
875 skinny128_permute_tk(TK1);
880 #endif // !USE_AVR_INLINE_ASM
893 #if USE_AVR_INLINE_ASM
894 __asm__ __volatile__ (
918 "eor __tmp_reg__,r8\n"
919 "st X+,__tmp_reg__\n"
921 "eor __tmp_reg__,r9\n"
922 "st X+,__tmp_reg__\n"
924 "eor __tmp_reg__,r10\n"
925 "st X+,__tmp_reg__\n"
927 "eor __tmp_reg__,r11\n"
928 "st X+,__tmp_reg__\n"
930 "eor __tmp_reg__,r12\n"
931 "st X+,__tmp_reg__\n"
933 "eor __tmp_reg__,r13\n"
934 "st X+,__tmp_reg__\n"
936 "eor __tmp_reg__,r14\n"
937 "st X+,__tmp_reg__\n"
939 "eor __tmp_reg__,r15\n"
940 "st X+,__tmp_reg__\n"
951 : :
"x"(s),
"z"(key),
"r"(r)
952 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
953 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
956 #else // !USE_AVR_INLINE_ASM
958 uint32_t *schedule = s;
962 memcpy(TK1, key,
sizeof(TK1));
965 for (uint8_t index = r; index > 0; --index, schedule += 2) {
966 schedule[0] ^= TK1[0];
967 schedule[1] ^= TK1[1];
968 skinny128_permute_tk(TK1);
973 #endif // !USE_AVR_INLINE_ASM
976 #if USE_AVR_INLINE_ASM
981 "adc " reg ",__zero_reg__\n" \
995 #else // !USE_AVR_INLINE_ASM
997 inline uint32_t skinny128_LFSR2(uint32_t x)
999 return ((x << 1) & 0xFEFEFEFEU) ^ (((x >> 7) ^ (x >> 5)) & 0x01010101U);
1002 inline uint32_t skinny128_LFSR3(uint32_t x)
1004 return ((x >> 1) & 0x7F7F7F7FU) ^ (((x << 7) ^ (x << 1)) & 0x80808080U);
1007 #endif // !USE_AVR_INLINE_ASM
1016 #if USE_AVR_INLINE_ASM
1017 __asm__ __volatile__ (
1040 "ld __tmp_reg__,X\n"
1041 "eor __tmp_reg__,r8\n"
1042 "st X+,__tmp_reg__\n"
1043 "ld __tmp_reg__,X\n"
1044 "eor __tmp_reg__,r9\n"
1045 "st X+,__tmp_reg__\n"
1046 "ld __tmp_reg__,X\n"
1047 "eor __tmp_reg__,r10\n"
1048 "st X+,__tmp_reg__\n"
1049 "ld __tmp_reg__,X\n"
1050 "eor __tmp_reg__,r11\n"
1051 "st X+,__tmp_reg__\n"
1052 "ld __tmp_reg__,X\n"
1053 "eor __tmp_reg__,r12\n"
1054 "st X+,__tmp_reg__\n"
1055 "ld __tmp_reg__,X\n"
1056 "eor __tmp_reg__,r13\n"
1057 "st X+,__tmp_reg__\n"
1058 "ld __tmp_reg__,X\n"
1059 "eor __tmp_reg__,r14\n"
1060 "st X+,__tmp_reg__\n"
1061 "ld __tmp_reg__,X\n"
1062 "eor __tmp_reg__,r15\n"
1063 "st X+,__tmp_reg__\n"
1085 : :
"x"(s),
"z"(key),
"r"(r)
1086 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
1087 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
1090 #else // !USE_AVR_INLINE_ASM
1092 uint32_t *schedule = s;
1096 memcpy(TK2, key,
sizeof(TK2));
1099 for (uint8_t index = r; index > 0; --index, schedule += 2) {
1101 schedule[0] ^= TK2[0];
1102 schedule[1] ^= TK2[1];
1105 skinny128_permute_tk(TK2);
1108 TK2[0] = skinny128_LFSR2(TK2[0]);
1109 TK2[1] = skinny128_LFSR2(TK2[1]);
1114 #endif // !USE_AVR_INLINE_ASM
1124 #if USE_AVR_INLINE_ASM
1125 __asm__ __volatile__ (
1148 "ld __tmp_reg__,X\n"
1149 "eor __tmp_reg__,r8\n"
1150 "st X+,__tmp_reg__\n"
1151 "ld __tmp_reg__,X\n"
1152 "eor __tmp_reg__,r9\n"
1153 "st X+,__tmp_reg__\n"
1154 "ld __tmp_reg__,X\n"
1155 "eor __tmp_reg__,r10\n"
1156 "st X+,__tmp_reg__\n"
1157 "ld __tmp_reg__,X\n"
1158 "eor __tmp_reg__,r11\n"
1159 "st X+,__tmp_reg__\n"
1160 "ld __tmp_reg__,X\n"
1161 "eor __tmp_reg__,r12\n"
1162 "st X+,__tmp_reg__\n"
1163 "ld __tmp_reg__,X\n"
1164 "eor __tmp_reg__,r13\n"
1165 "st X+,__tmp_reg__\n"
1166 "ld __tmp_reg__,X\n"
1167 "eor __tmp_reg__,r14\n"
1168 "st X+,__tmp_reg__\n"
1169 "ld __tmp_reg__,X\n"
1170 "eor __tmp_reg__,r15\n"
1171 "st X+,__tmp_reg__\n"
1193 : :
"x"(s),
"z"(key),
"r"(r)
1194 :
"r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
1195 "r16",
"r17",
"r18",
"r19",
"r20",
"r21",
"r22",
"r23",
1198 #else // !USE_AVR_INLINE_ASM
1200 uint32_t *schedule = s;
1204 memcpy(TK3, key,
sizeof(TK3));
1207 for (uint8_t index = r; index > 0; --index, schedule += 2) {
1209 schedule[0] ^= TK3[0];
1210 schedule[1] ^= TK3[1];
1213 skinny128_permute_tk(TK3);
1216 TK3[0] = skinny128_LFSR3(TK3[0]);
1217 TK3[1] = skinny128_LFSR3(TK3[1]);
1222 #endif // !USE_AVR_INLINE_ASM
1266 memcpy(t, tweak, len);
1269 memset(t, 0,
sizeof(t));
1287 memset(t, 0,
sizeof(t));
Skinny128_Tweaked(uint32_t *schedule, uint8_t rounds)
Constructs a tweakable Skinny-128 block cipher object.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
size_t keySize() const
Size of a Skinny128_256 key in bytes.
void xorTK1(const uint8_t *key)
XOR's the key schedule with the schedule for TK1.
size_t keySize() const
Size of a Skinny128_384 key in bytes.
virtual ~Skinny128_256_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
size_t keySize() const
Size of a Skinny128_256_Tweaked key in bytes.
void encryptBlock(uint8_t *output, const uint8_t *input)
Encrypts a single block using this cipher.
void setTK3(const uint8_t *key)
XOR's the key schedule with the schedule for TK3.
virtual ~Skinny128_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
virtual ~Skinny128()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
void clear()
Clears all security-sensitive state from this block cipher.
size_t keySize() const
Size of a Skinny128_128 key in bytes.
Abstract base class for SKINNY tweakable block ciphers with 128-bit blocks.
virtual ~Skinny128_384()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Skinny128_256()
Constructs a Skinny-128 block cipher with a 256-bit key.
Skinny128_384_Tweaked()
Constructs a tweakable Skinny-128 block cipher with a 256-bit key and a 128-bit tweak.
Skinny128_256_Tweaked()
Constructs a tweakable Skinny-128 block cipher with a 128-bit key and a 128-bit tweak.
void setTK2(const uint8_t *key)
XOR's the key schedule with the schedule for TK2.
Abstract base class for SKINNY block ciphers with 128-bit blocks.
Skinny128_128()
Constructs a Skinny-128 block cipher with a 128-bit key.
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Skinny128(uint32_t *schedule, uint8_t rounds)
Constructs a Skinny-128 block cipher object.
void setTK1(const uint8_t *key, bool tweaked=false)
Clears the key schedule and sets it to the schedule for TK1.
virtual ~Skinny128_384_Tweaked()
Destroys this tweakable Skinny-128 block cipher object after clearing sensitive information.
size_t blockSize() const
Size of a Skinny-128 block in bytes.
void resetTweak()
Resets the tweak to all-zeroes.
virtual ~Skinny128_256()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
size_t keySize() const
Size of a Skinny128_384_Tweaked key in bytes.
void decryptBlock(uint8_t *output, const uint8_t *input)
Decrypts a single block using this cipher.
virtual ~Skinny128_128()
Destroys this Skinny-128 block cipher object after clearing sensitive information.
Skinny128_384()
Constructs a Skinny-128 block cipher with a 384-bit key.
bool setTweak(const uint8_t *tweak, size_t len)
Sets the 128-bit tweak value for this block cipher.
void clear()
Clears all security-sensitive state from this block cipher.