]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - skein/threefish1024_dec_asm.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / skein / threefish1024_dec_asm.S
index 574382995575dcc7102a6230f247ebb19ecca656..41ddb35cfa20c1b106c737bf9f0c23d78fb45a1f 100644 (file)
@@ -1,7 +1,7 @@
 /* threefish1024_enc_asm.S */
 /*
     This file is part of the AVR-Crypto-Lib.
 /* threefish1024_enc_asm.S */
 /*
     This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
+    Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 */
 /*
  * \author  Daniel Otte
 */
 /*
  * \author  Daniel Otte
- * \email   daniel.otte@rub.de
+ * \email   bg@nerilex.org
  * \date    2009-03-24
  * \license GPLv3 or later
  * \date    2009-03-24
  * \license GPLv3 or later
- */ 
+ */
 
 #include "avr-asm-macros.S"
 
 /******************************************************************************/
 /*
 
 #include "avr-asm-macros.S"
 
 /******************************************************************************/
 /*
-void permute_inv16(voiddata){
+void permute_inv16(void *data){
        uint64_t t;
        t = X(15);
        X(15) = X(7);
        uint64_t t;
        t = X(15);
        X(15) = X(7);
@@ -38,7 +38,7 @@ void permute_inv16(void* data){
        X(11) = X(5);
        X(5) = X(13);
        X(13) = X(3);
        X(11) = X(5);
        X(5) = X(13);
        X(13) = X(3);
-       X(3) = t;               
+       X(3) = t;
        t = X(4);
        X(4) = X(6);
        X(6) = t;
        t = X(4);
        X(4) = X(6);
        X(6) = t;
@@ -48,7 +48,7 @@ void permute_inv16(void* data){
        X(10) = X(8);
        X(8) = t;
 }
        X(10) = X(8);
        X(8) = t;
 }
-void add_key_16(void* data, const threefish1024_ctx_t* ctx, uint8_t s){
+void add_key_16(void *data, const threefish1024_ctx_t *ctx, uint8_t s){
        uint8_t i;
        for(i=0; i<13; ++i){
                X(i) -= ctx->k[(s+i)%17];
        uint8_t i;
        for(i=0; i<13; ++i){
                X(i) -= ctx->k[(s+i)%17];
@@ -57,7 +57,7 @@ void add_key_16(void* data, const threefish1024_ctx_t* ctx, uint8_t s){
        X(14) -= ctx->k[(s+14)%17] + ctx->t[(s+1)%3];
        X(15) -= ctx->k[(s+15)%17] + s;
 }
        X(14) -= ctx->k[(s+14)%17] + ctx->t[(s+1)%3];
        X(15) -= ctx->k[(s+15)%17] + s;
 }
-void threefish1024_dec(void* data, const threefish1024_ctx_t* ctx){
+void threefish1024_dec(void *data, const threefish1024_ctx_t *ctx){
        uint8_t i=0,s=20;
        uint8_t r0[8] = {0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79};
        uint8_t r1[8] = {0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53};
        uint8_t i=0,s=20;
        uint8_t r0[8] = {0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79};
        uint8_t r1[8] = {0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53};
@@ -66,8 +66,8 @@ void threefish1024_dec(void* data, const threefish1024_ctx_t* ctx){
        uint8_t r4[8] = {0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20};
        uint8_t r5[8] = {0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a};
        uint8_t r6[8] = {0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a};
        uint8_t r4[8] = {0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20};
        uint8_t r5[8] = {0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a};
        uint8_t r6[8] = {0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a};
-       uint8_t r7[8] = {0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14}; 
-       
+       uint8_t r7[8] = {0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14};
+
        do{
                if(i%4==0){
                        add_key_16(data, ctx, s);
        do{
                if(i%4==0){
                        add_key_16(data, ctx, s);
@@ -116,7 +116,7 @@ threefish1024_dec:
        clr I
        ldi r26, 20
        mov S, r26
        clr I
        ldi r26, 20
        mov S, r26
-1:     
+1:
        mov r30,  I
        andi r30, 0x03
        breq 2f
        mov r30,  I
        andi r30, 0x03
        breq 2f
@@ -263,10 +263,10 @@ exit:
        pop_range 2, 17
        pop r29
        pop r28
        pop_range 2, 17
        pop r29
        pop r28
-       ret     
+       ret
 3:
        dec S
 3:
        dec S
-4:     
+4:
        /* now the permutation */
        movw r26, DATA0  /* X1 <-> X15 */
        adiw r26, 1*8
        /* now the permutation */
        movw r26, DATA0  /* X1 <-> X15 */
        adiw r26, 1*8
@@ -286,7 +286,7 @@ exit:
        movw r30, DATA0
        adiw r30, 7*8
        rcall xchg_zx8
        movw r30, DATA0
        adiw r30, 7*8
        rcall xchg_zx8
-       /* --- */       
+       /* --- */
        movw r26, DATA0  /* X3 <-> X11 */
        adiw r26, 3*8
        movw r30, DATA0
        movw r26, DATA0  /* X3 <-> X11 */
        adiw r26, 3*8
        movw r30, DATA0
@@ -333,7 +333,7 @@ exit:
        movw r30, DATA0
        adiw r30, 6*8
        rcall xchg_zx8
        movw r30, DATA0
        adiw r30, 6*8
        rcall xchg_zx8
-               
+
        /* call mix */
        ldi r30, lo8(threefish1024_rc0)
        ldi r31, hi8(threefish1024_rc0)
        /* call mix */
        ldi r30, lo8(threefish1024_rc0)
        ldi r31, hi8(threefish1024_rc0)
@@ -361,7 +361,7 @@ exit:
        push IDX4
        push IDX3
        push IDX2
        push IDX4
        push IDX3
        push IDX2
-       
+
        movw r24, DATA0
        call threefish_invmix_asm /* no rcall? */
        movw r24, DATA0
        movw r24, DATA0
        call threefish_invmix_asm /* no rcall? */
        movw r24, DATA0
@@ -399,8 +399,8 @@ exit:
        inc I
 9:
        rjmp 1b
        inc I
 9:
        rjmp 1b
-       
-threefish1024_slut17:  
+
+threefish1024_slut17:
        .byte 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38
        .byte 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78
        .byte 0x80, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30
        .byte 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38
        .byte 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78
        .byte 0x80, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30
@@ -411,7 +411,8 @@ threefish1024_slut3:
        .byte 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00
        .byte 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10
        .byte 0x00
        .byte 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00
        .byte 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10
        .byte 0x00
-       
+
+/* old round constants
 threefish1024_rc0: .byte 0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79
 threefish1024_rc1: .byte 0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53
 threefish1024_rc2: .byte 0x33, 0x40, 0x22, 0x69, 0x31, 0x22, 0x6a, 0x5b
 threefish1024_rc0: .byte 0x69, 0x72, 0x21, 0x34, 0x42, 0x41, 0x31, 0x79
 threefish1024_rc1: .byte 0x61, 0x19, 0x1a, 0x19, 0x53, 0x10, 0x31, 0x53
 threefish1024_rc2: .byte 0x33, 0x40, 0x22, 0x69, 0x31, 0x22, 0x6a, 0x5b
@@ -419,7 +420,16 @@ threefish1024_rc3: .byte 0x72, 0x6b, 0x31, 0x60, 0x74, 0x71, 0x2b, 0x50
 threefish1024_rc4: .byte 0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20
 threefish1024_rc5: .byte 0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a
 threefish1024_rc6: .byte 0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a
 threefish1024_rc4: .byte 0x5b, 0x23, 0x53, 0x63, 0x54, 0x3b, 0x2a, 0x20
 threefish1024_rc5: .byte 0x60, 0x22, 0x52, 0x11, 0x11, 0x14, 0x2b, 0x3a
 threefish1024_rc6: .byte 0x7b, 0x02, 0x50, 0x43, 0x73, 0x40, 0x64, 0x5a
-threefish1024_rc7: .byte 0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14 
+threefish1024_rc7: .byte 0x70, 0x70, 0x29, 0x51, 0x42, 0x7a, 0x71, 0x14
+*/
+threefish1024_rc0:  .byte 0x11, 0x49, 0x20, 0x51, 0x1b, 0x41, 0x5a, 0x30
+threefish1024_rc1:  .byte 0x60, 0x54, 0x42, 0x11, 0x24, 0x04, 0x23, 0x2b
+threefish1024_rc2:  .byte 0x43, 0x69, 0x70, 0x5b, 0x60, 0x63, 0x12, 0x10
+threefish1024_rc3:  .byte 0x64, 0x6a, 0x63, 0x49, 0x51, 0x2b, 0x79, 0x69
+threefish1024_rc4:  .byte 0x39, 0x23, 0x04, 0x14, 0x69, 0x42, 0x61, 0x10
+threefish1024_rc5:  .byte 0x49, 0x52, 0x7b, 0x69, 0x34, 0x51, 0x22, 0x21
+threefish1024_rc6:  .byte 0x5b, 0x54, 0x52, 0x54, 0x20, 0x73, 0x39, 0x3a
+threefish1024_rc7:  .byte 0x24, 0x31, 0x51, 0x4a, 0x31, 0x21, 0x64, 0x5b
 
 sub_z_from_x8:
        ld r0, Z+
 
 sub_z_from_x8:
        ld r0, Z+
@@ -456,16 +466,16 @@ sub_z_from_x8:
        st X+, r1
        clr r1
        ret
        st X+, r1
        clr r1
        ret
-       
+
 T0 = IDX0
 T1 = 0
 T0 = IDX0
 T1 = 0
-CNT = 24       
+CNT = 24
 xchg_zx8:
        ldi CNT, 8
 1:     ld T0, X
        ld T1, Z
        st X+, T1
 xchg_zx8:
        ldi CNT, 8
 1:     ld T0, X
        ld T1, Z
        st X+, T1
-       st Z+, T0       
+       st Z+, T0
        dec CNT
        brne 1b
        ret
        dec CNT
        brne 1b
        ret