1 /* threefish1024_enc_asm.S */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * \email daniel.otte@rub.de
23 * \license GPLv3 or later
26 #include "avr-asm-macros.S"
28 /******************************************************************************/
30 void permute_inv16(void *data){
51 void add_key_16(void *data, const threefish1024_ctx_t *ctx, uint8_t s){
54 X(i) -= ctx->k[(s+i)%17];
56 X(13) -= ctx->k[(s+13)%17] + ctx->t[s%3];
57 X(14) -= ctx->k[(s+14)%17] + ctx->t[(s+1)%3];
58 X(15) -= ctx->k[(s+15)%17] + s;
60 void threefish1024_dec(void *data, const threefish1024_ctx_t *ctx){
62 uint8_t r0[8] = {0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79};
63 uint8_t r1[8] = {0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53};
64 uint8_t r2[8] = {0x33, 0x40, 0x22, 0x69, 0x31, 0x22, 0x6a, 0x5b};
65 uint8_t r3[8] = {0x72, 0x6b, 0x31, 0x60, 0x74, 0x71, 0x2b, 0x50};
66 uint8_t r4[8] = {0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20};
67 uint8_t r5[8] = {0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a};
68 uint8_t r6[8] = {0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a};
69 uint8_t r7[8] = {0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14};
73 add_key_16(data, ctx, s);
77 threefish_invmix((uint8_t*)data + 0, r0[i%8]);
78 threefish_invmix((uint8_t*)data + 16, r1[i%8]);
79 threefish_invmix((uint8_t*)data + 32, r2[i%8]);
80 threefish_invmix((uint8_t*)data + 48, r3[i%8]);
81 threefish_invmix((uint8_t*)data + 64, r4[i%8]);
82 threefish_invmix((uint8_t*)data + 80, r5[i%8]);
83 threefish_invmix((uint8_t*)data + 96, r6[i%8]);
84 threefish_invmix((uint8_t*)data +112, r7[i%8]);
87 add_key_16(data, ctx, s);
106 * param data: r24:r25
109 .global threefish1024_dec
125 ldi r30, lo8(threefish1024_slut17)
126 ldi r31, hi8(threefish1024_slut17)
171 ldi r30, lo8(threefish1024_slut17)
172 ldi r31, hi8(threefish1024_slut17)
216 /* now the remaining key */
218 ldi r30, lo8(threefish1024_slut3)
219 ldi r31, hi8(threefish1024_slut3)
225 adiw r30, 7*8 /* make Z pointing to (extended tweak) */
270 /* now the permutation */
271 movw r26, DATA0 /* X1 <-> X15 */
277 movw r26, DATA0 /* X15 <-> X7 */
283 movw r26, DATA0 /* X9 <-> X7 */
290 movw r26, DATA0 /* X3 <-> X11 */
296 movw r26, DATA0 /* X11 <-> X5 */
302 movw r26, DATA0 /* X13 <-> X5 */
309 movw r26, DATA0 /* X8 <-> X14 */
316 movw r26, DATA0 /* X14 <-> X12 */
323 movw r26, DATA0 /* X10 <-> X12 */
331 movw r26, DATA0 /* X4 <-> X6 */
338 ldi r30, lo8(threefish1024_rc0)
339 ldi r31, hi8(threefish1024_rc0)
366 call threefish_invmix_asm /* no rcall? */
370 call threefish_invmix_asm /* no rcall? */
374 call threefish_invmix_asm /* no rcall? */
378 call threefish_invmix_asm /* no rcall? */
383 call threefish_invmix_asm /* no rcall? */
388 call threefish_invmix_asm /* no rcall? */
393 call threefish_invmix_asm /* no rcall? */
398 call threefish_invmix_asm /* no rcall? */
403 threefish1024_slut17:
404 .byte 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38
405 .byte 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78
406 .byte 0x80, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30
407 .byte 0x38, 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70
408 .byte 0x78, 0x80, 0x00, 0x08, 0x10
410 .byte 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08
411 .byte 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00
412 .byte 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10
415 /* old round constants
416 threefish1024_rc0: .byte 0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79
417 threefish1024_rc1: .byte 0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53
418 threefish1024_rc2: .byte 0x33, 0x40, 0x22, 0x69, 0x31, 0x22, 0x6a, 0x5b
419 threefish1024_rc3: .byte 0x72, 0x6b, 0x31, 0x60, 0x74, 0x71, 0x2b, 0x50
420 threefish1024_rc4: .byte 0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20
421 threefish1024_rc5: .byte 0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a
422 threefish1024_rc6: .byte 0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a
423 threefish1024_rc7: .byte 0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14
425 threefish1024_rc0: .byte 0x11, 0x49, 0x20, 0x51, 0x1b, 0x41, 0x5a, 0x30
426 threefish1024_rc1: .byte 0x60, 0x54, 0x42, 0x11, 0x24, 0x04, 0x23, 0x2b
427 threefish1024_rc2: .byte 0x43, 0x69, 0x70, 0x5b, 0x60, 0x63, 0x12, 0x10
428 threefish1024_rc3: .byte 0x64, 0x6a, 0x63, 0x49, 0x51, 0x2b, 0x79, 0x69
429 threefish1024_rc4: .byte 0x39, 0x23, 0x04, 0x14, 0x69, 0x42, 0x61, 0x10
430 threefish1024_rc5: .byte 0x49, 0x52, 0x7b, 0x69, 0x34, 0x51, 0x22, 0x21
431 threefish1024_rc6: .byte 0x5b, 0x54, 0x52, 0x54, 0x20, 0x73, 0x39, 0x3a
432 threefish1024_rc7: .byte 0x24, 0x31, 0x51, 0x4a, 0x31, 0x21, 0x64, 0x5b