]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - seed_C.c
seed now in pure asm
[avr-crypto-lib.git] / seed_C.c
index f055e7f4a28e6d5b12226d7afff9d5754106c2a6..e4b77f519b33db198f0c3b1a037ab6f9c77bdda3 100644 (file)
--- a/seed_C.c
+++ b/seed_C.c
@@ -32,6 +32,9 @@
 #include "uart.h"
 #include "debug.h"
 
+
+static
+uint32_t g_function(uint32_t x);
 /******************************************************************************/
 
 static
@@ -88,13 +91,13 @@ uint64_t bigendian_rotr8_64(uint64_t a){
 
 /******************************************************************************/
 static
-uint64_t f_function(uint64_t a, uint32_t k0, uint32_t k1){
+uint64_t f_function(const uint64_t* a, uint32_t k0, uint32_t k1){
        uint32_t c,d;
 
-       c = a & 0x00000000FFFFFFFFLL;
-       d = (a>>32) & 0x00000000FFFFFFFFLL;
+       c = *a & 0x00000000FFFFFFFFLL;
+       d = (*a>>32) & 0x00000000FFFFFFFFLL;
        
-       c ^= k0;        d ^= k1;
+       c ^= k0; d ^= k1;
        d ^= c;
        d = g_function(d);
        c = bigendian_sum32(c,d);
@@ -102,8 +105,7 @@ uint64_t f_function(uint64_t a, uint32_t k0, uint32_t k1){
        d = bigendian_sum32(c,d);
        d = g_function(d);
        c = bigendian_sum32(c,d);
-       a = ((uint64_t)d << 32) | c;
-       return a;
+       return ((uint64_t)d << 32) | c;
 }
 
 /******************************************************************************/
@@ -224,7 +226,7 @@ void seed_enc(void * buffer, seed_ctx_t * ctx){
        DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+0, 8);
        DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+8, 8);
 */
-                       L ^= f_function(R,k.k0,k.k1);
+                       L ^= f_function(&R,k.k0,k.k1);
                        
                        k = getnextkeys(ctx->k, 2*r+1);
 /*
@@ -233,7 +235,7 @@ void seed_enc(void * buffer, seed_ctx_t * ctx){
        DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+8, 8);
        DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+0, 8);
 */
-                       R ^= f_function(L,k.k0,k.k1);
+                       R ^= f_function(&L,k.k0,k.k1);
        }
        /* just an exchange without temp. variable */
        L ^= R;
@@ -257,7 +259,7 @@ void seed_dec(void * buffer, seed_ctx_t * ctx){
        DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+0, 8);
        DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+8, 8);
 */
-                       L ^= f_function(R,k.k0,k.k1);
+                       L ^= f_function(&R,k.k0,k.k1);
                        
                        k = getprevkeys(ctx->k, 2*r+0);
 /*
@@ -266,7 +268,7 @@ void seed_dec(void * buffer, seed_ctx_t * ctx){
        DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+8, 8);
        DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+0, 8);
 */
-                       R ^= f_function(L,k.k0,k.k1);
+                       R ^= f_function(&L,k.k0,k.k1);
        }
        /* just an exchange without temp. variable */
        L ^= R;