]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - skein/threefish512_enc_asm.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / skein / threefish512_enc_asm.S
index cc2967fc4baee981dd08036e0ef9ff677e1240e5..aad6b70757421e2d4428b5bbc04274a662840804 100644 (file)
@@ -1,7 +1,7 @@
 /* threefish512_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
 */
 /*
  * \author  Daniel Otte
- * \email   daniel.otte@rub.de
+ * \email   bg@nerilex.org
  * \date    2009-03-24
  * \license GPLv3 or later
- */ 
+ */
 
 #include "avr-asm-macros.S"
 
@@ -39,7 +39,7 @@ A7 = 21
 
 #define K(s) (((uint64_t*)key)[(s)])
 #define T(s) (((uint64_t*)tweak)[(s)])
-void threefish512_init(const void* key, const void* tweak, threefish512_ctx_t* ctx){
+void threefish512_init(const void *key, const void *tweak, threefish512_ctx_t *ctx){
        memcpy(ctx->k, key, 8*8);
        memcpy(ctx->t, tweak, 2*8);
        uint8_t i;
@@ -61,11 +61,20 @@ threefish512_init:
        movw r30, r20
        movw r26, r24
        ldi r24, 8
-       ldi A7, 0x55
-       mov A6, A7
-       movw A4, A6
-       movw A2, A6
+;      ldi A7, 0x55
+;      mov A6, A7
+;      movw A4, A6
+;      movw A2, A6
+;      movw A0, A6
+       ldi A6, 0x22 ; 0x1BD1.1BDA.A9FC.1A22
+       ldi A7, 0x1A
        movw A0, A6
+       ldi A2, 0xFC
+       ldi A3, 0xA9
+       ldi A4, 0xDA
+       ldi A5, 0x1B
+       ldi A6, 0xD1
+       ldi A7, 0x1B
 1:
        ld r0, X+
        st Z+, r0
@@ -113,7 +122,7 @@ threefish512_init:
        dec r26
        brne 1b
        rjmp 9f
-3:     
+3:
        ld A0, X+
        ld A1, X+
        ld A2, X+
@@ -165,11 +174,11 @@ threefish512_init:
 9:
        pop_range 14, 17
        ret
-       
+
 /******************************************************************************/
 /*
 #define X(a) (((uint64_t*)data)[(a)])
-void permute_8(voiddata){
+void permute_8(void *data){
        uint64_t t;
        t = X(0);
        X(0) = X(2);
@@ -180,7 +189,7 @@ void permute_8(void* data){
        X(3) = X(7);
        X(7) = t;
 }
-void add_key_8(void* data, const threefish512_ctx_t* ctx, uint8_t s){
+void add_key_8(void *data, const threefish512_ctx_t *ctx, uint8_t s){
        uint8_t i;
        for(i=0; i<5; ++i){
                X(i) += ctx->k[(s+i)%9];
@@ -189,9 +198,9 @@ void add_key_8(void* data, const threefish512_ctx_t* ctx, uint8_t s){
        X(6) += ctx->k[(s+6)%9] + ctx->t[(s+1)%3];
        X(7) += ctx->k[(s+7)%9] + s;
 }
-void threefish512_enc(void* data, const threefish512_ctx_t* ctx){
+void threefish512_enc(void *data, const threefish512_ctx_t *ctx){
        uint8_t i=0,s=0;
-       uint8_t r0[8] = {38, 48, 34, 26, 33, 39, 29, 33}; 
+       uint8_t r0[8] = {38, 48, 34, 26, 33, 39, 29, 33};
        uint8_t r1[8] = {30, 20, 14, 12, 49, 27, 26, 51};
        uint8_t r2[8] = {50, 43, 15, 58,  8, 41, 11, 39};
        uint8_t r3[8] = {53, 31, 27,  7, 42, 14,  9, 35};
@@ -238,7 +247,7 @@ threefish512_enc:
        movw CTX0, r22
        clr I
        clr S
-1:     
+1:
        mov r30,  I
        andi r30, 0x03
        breq 2f
@@ -289,7 +298,7 @@ threefish512_enc:
        add r30, IDX7
        adc r31, r1
        rcall add_z_to_x8
-       
+
        /* now the remaining key */
        sbiw r26, 3*8
        ldi r30, lo8(threefish512_slut3)
@@ -341,8 +350,8 @@ exit:
        pop_range 2, 17
        pop r29
        pop r28
-       ret     
-4:     
+       ret
+4:
        /* call mix */
        ldi r30, lo8(threefish512_rc0)
        ldi r31, hi8(threefish512_rc0)
@@ -358,7 +367,7 @@ exit:
        push IDX1
        adiw r30, 8
        lpm IDX1, Z
-       
+
        movw r24, DATA0
        call threefish_mix_asm /* no rcall? */
        movw r24, DATA0
@@ -387,7 +396,7 @@ exit:
        adiw r26, 2*8
        movw r30, DATA0
        adiw r30, 4*8
-       rcall xchg_zx8  
+       rcall xchg_zx8
        movw r26, DATA0
        adiw r26, 3*8
        movw r30, DATA0
@@ -395,22 +404,27 @@ exit:
        rcall xchg_zx8
        inc I
        rjmp 1b
-       
+
 threefish512_slut9:
        .byte 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38
        .byte 0x40, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30
-       .byte 0x38, 0x40, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28 
+       .byte 0x38, 0x40, 0x00, 0x08, 0x10, 0x18, 0x20, 0x28
        .byte 0x30, 0x38, 0x40
 threefish512_slut3:
        .byte 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08
-       .byte 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00 
+       .byte 0x10, 0x00, 0x08, 0x10, 0x00, 0x08, 0x10, 0x00
        .byte 0x08, 0x10, 0x00, 0x08, 0x10, 0x00, 0x08
 
-threefish512_rc0: .byte 0x5a, 0x60, 0x42, 0x32, 0x41, 0x59, 0x4b, 0x41 
-threefish512_rc1: .byte 0x4a, 0x24, 0x2a, 0x14, 0x61, 0x33, 0x32, 0x63 
-threefish512_rc2: .byte 0x62, 0x53, 0x29, 0x72, 0x10, 0x51, 0x13, 0x59 
-threefish512_rc3: .byte 0x7b, 0x49, 0x33, 0x19, 0x52, 0x2a, 0x11, 0x43 
-
+/* old round constants
+threefish512_rc0: .byte 0x5a, 0x60, 0x42, 0x32, 0x41, 0x59, 0x4b, 0x41
+threefish512_rc1: .byte 0x4a, 0x24, 0x2a, 0x14, 0x61, 0x33, 0x32, 0x63
+threefish512_rc2: .byte 0x62, 0x53, 0x29, 0x72, 0x10, 0x51, 0x13, 0x59
+threefish512_rc3: .byte 0x7b, 0x49, 0x33, 0x19, 0x52, 0x2a, 0x11, 0x43
+*/
+threefish512_rc0:  .byte 0x6a, 0x41, 0x21, 0x54, 0x59, 0x2b, 0x31, 0x10
+threefish512_rc1:  .byte 0x44, 0x33, 0x61, 0x11, 0x4a, 0x62, 0x4b, 0x43
+threefish512_rc2:  .byte 0x23, 0x2a, 0x44, 0x7a, 0x42, 0x12, 0x59, 0x70
+threefish512_rc3:  .byte 0x5b, 0x52, 0x59, 0x70, 0x30, 0x21, 0x53, 0x3a
 add_z_to_x8:
        ld r0, Z+
        ld r1, X
@@ -446,16 +460,16 @@ add_z_to_x8:
        st X+, r1
        clr r1
        ret
-       
+
 T0 = IDX0
 T1 = 0
-CNT = 24       
+CNT = 24
 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