X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=seed_C.c;h=4460fa5e780626e90eb898c5656c9c8b44d958fa;hb=e5a49deb52521f019e37779d6e9d81ec4f02aba4;hp=f055e7f4a28e6d5b12226d7afff9d5754106c2a6;hpb=e363148c4ed1265a963d310102ce5dd7c9e1e326;p=avr-crypto-lib.git diff --git a/seed_C.c b/seed_C.c index f055e7f..4460fa5 100644 --- a/seed_C.c +++ b/seed_C.c @@ -1,6 +1,6 @@ /* seed_C.c */ /* - This file is part of the Crypto-avr-lib/microcrypt-lib. + 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 @@ -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; } /******************************************************************************/ @@ -204,7 +206,7 @@ typedef struct{ /******************************************************************************/ -void seed_init(uint8_t * key, seed_ctx_t * ctx){ +void seed_init(const void * key, seed_ctx_t * ctx){ memcpy(ctx->k, key, 128/8); } @@ -213,27 +215,27 @@ void seed_init(uint8_t * key, seed_ctx_t * ctx){ #define L (((uint64_t*)buffer)[0]) #define R (((uint64_t*)buffer)[1]) -void seed_enc(void * buffer, seed_ctx_t * ctx){ +void seed_enc(void * buffer, const seed_ctx_t * ctx){ uint8_t r; keypair_t k; for(r=0; r<8; ++r){ - k = getnextkeys(ctx->k, 2*r); + k = getnextkeys(((seed_ctx_t*)ctx)->k, 2*r); /* DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4); DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4); 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); + k = getnextkeys(((seed_ctx_t*)ctx)->k, 2*r+1); /* DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4); DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4); 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; @@ -250,23 +252,23 @@ void seed_dec(void * buffer, seed_ctx_t * ctx){ int8_t r; keypair_t k; for(r=7; r>=0; --r){ - k = getprevkeys(ctx->k, 2*r+1); + k = getprevkeys(((seed_ctx_t*)ctx)->k, 2*r+1); /* DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4); DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4); 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); + k = getprevkeys(((seed_ctx_t*)ctx)->k, 2*r+0); /* DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4); DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4); 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;