]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - noekeon_asm.S
updated Makefile
[avr-crypto-lib.git] / noekeon_asm.S
index 0422964cd49d935fe3f1add7ebfc7aeb136a68bc..b0a2a16f93da12843c5d39a022103f04f5781c01 100644 (file)
@@ -1,3 +1,21 @@
+/* noekeon_asm.S */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
+
+    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
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 /* 
  * noekeon assembler implementation for avr
  * author: Daniel Otte
        clr r1
 .endm
 
+push_all_func:
+       pop r31
+       pop r30
+       push_all
+       ijmp
+
+pop_all_func:
+    pop r31
+    pop r30
+    pop_all
+    ijmp
+
 .macro xchg a b
        eor \a, \b
        eor \b, \a
@@ -257,14 +287,15 @@ theta:
        ret
 
 /******************************************************************************/
+#ifndef NOEKEON_NO_ENC
 ; === noekeon_enc ===
 ;
-;  param1: pointer to buffer/state (r24,r25)
+;  param1: pointer to buffer (r24,r25)
 ;  param2: pointer to k (r22,r23) 
 ;
 .global noekeon_enc
 noekeon_enc:
-       push_all
+       rcall push_all_func
        /* load state */
        movw r26, r22
        ldi r28, 2
@@ -294,7 +325,7 @@ noekeon_enc:
        lpm r0, Z
        push r0
 3:
-       call round /* pops rc2 & rc1 */
+       rcall round /* pops rc2 & rc1 */
        pop r22
        dec r22
        push r22
@@ -304,7 +335,7 @@ noekeon_enc:
 
        ldi r22, 0xD4
        eor state0_3, r22
-       call theta
+       rcall theta
 
        pop r31
        pop r30
@@ -317,10 +348,13 @@ noekeon_enc:
        dec r22
        brne 1b
        
-       pop_all
+       rcall pop_all_func
        ret
+#endif
 /******************************************************************************/
 /******************************************************************************/
+#ifndef NOEKEON_NO_DEC
+
 ; === noekeon_dec ===
 ;
 ;  param1: pointer to buffer/state (r24,r25)
@@ -328,7 +362,7 @@ noekeon_enc:
 ;
 .global noekeon_dec
 noekeon_dec:
-       push_all
+       rcall push_all_func
        /* allocate 16 bytes on the stack */
        in r30, _SFR_IO_ADDR(SPL)
        in r31, _SFR_IO_ADDR(SPH)
@@ -359,7 +393,7 @@ noekeon_dec:
 
        movw r26, r30
        sbiw r26, 16 /* set X back to begining of stack key */
-       call theta
+       rcall theta
        
        /* mov state to stackkey */
        clr r29
@@ -401,7 +435,7 @@ noekeon_dec:
        push r0
        push r1
 3:
-       call round /* pops rc2 & rc1 */
+       rcall round /* pops rc2 & rc1 */
        pop r22
        dec r22
        push r22
@@ -409,7 +443,7 @@ noekeon_dec:
 ;----
        pop r22
 
-       call theta
+       rcall theta
        ldi r22, 0x80
        eor state0_3, r22
        
@@ -432,16 +466,18 @@ write_state_back:
        adiw r30, 16 
        out  _SFR_IO_ADDR(SPH), r31
        out  _SFR_IO_ADDR(SPL), r30
-       pop_all
+       rcall pop_all_func
        ret
+#endif
 /******************************************************************************/
        
+       
 round: 
        pop r24
        pop r25
        pop r1
        eor state0_3, r1
-       call theta
+       rcall theta
        pop r1
        eor state0_3, r1
        push r25
@@ -449,9 +485,9 @@ round:
 pi_gamma_pi:
        ldi r30, pm_lo8(bigendian_rotl32)
        ldi r31, pm_hi8(bigendian_rotl32)
-       call pi
+       rcall pi
        /* pi1 done; now gamma */
-       call gamma_1
+       rcall gamma_1
        /* a[0] <-> a[3] */
        xchg state0_0, state3_0
        xchg state0_1, state3_1
@@ -462,10 +498,10 @@ pi_gamma_pi:
        op32 eor, state2, state1
        op32 eor, state2, state3
 
-       call gamma_1
+       rcall gamma_1
        ldi r30, pm_lo8(bigendian_rotr32)
        ldi r31, pm_hi8(bigendian_rotr32)
-       call pi
+       rcall pi
        ret
        
 gamma_1:
@@ -555,6 +591,9 @@ void noekeon_init(void* key, noekeon_ctx_t* ctx){
        noekeon_enc(ctx, nullv);
 }
 */
+
+#ifndef NOEKEON_NO_INIT
+
 .global noekeon_init
 noekeon_init:
 ; === noekeon_init ===
@@ -588,7 +627,7 @@ noekeon_init:
        
        sbiw r26, 16
        movw r24, r26
-       call noekeon_enc
+       rcall noekeon_enc
        
        in r30, _SFR_IO_ADDR(SPL)
        in r31, _SFR_IO_ADDR(SPH)
@@ -597,6 +636,6 @@ noekeon_init:
        out  _SFR_IO_ADDR(SPL), r30     
        ret
        
-
+#endif