X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=echo%2Fecho.c;h=2037dc8ca8f2e8fc47626323f416fae5289d0072;hp=407b1c5d3daab884a876dbcbcd6562c79af99d15;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=7b5401ab9ce23a5da1de8b6c7de3a1aa20ac4cf8 diff --git a/echo/echo.c b/echo/echo.c index 407b1c5..2037dc8 100644 --- a/echo/echo.c +++ b/echo/echo.c @@ -1,7 +1,7 @@ /* echo.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2010 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 @@ -19,8 +19,9 @@ #include "echo.h" -#include "gf256mul/gf256mul.h" -#include "memxor/memxor.h" +#include "gf256mul.h" +#include "memxor.h" +#include "aes_enc_round.h" #include #include @@ -35,7 +36,6 @@ #include "cli.h" #endif -void aes_encrypt_round(void* state, void* key); #define INDEX(c,r) ((c)*16*4+(r)*16) @@ -43,7 +43,7 @@ void aes_encrypt_round(void* state, void* key); #define GF256MUL_2(a) (gf256mul(2, (a), 0x1b)) #define GF256MUL_3(a) (gf256mul(3, (a), 0x1b)) -static void mixcol(uint8_t* s){ +static void mixcol(uint8_t *s){ uint8_t t, tmp[4]; tmp[0] = *(s+16*0); tmp[1] = *(s+16*1); @@ -70,7 +70,7 @@ static void mixcol(uint8_t* s){ } #if DEBUG -static void dump_state(void* s){ +static void dump_state(void *s){ uint8_t row, col; for(col=0; col<4; col++){ for(row=0; row<4; row++){ @@ -91,14 +91,17 @@ static void dump_state(void* s){ } #endif -static void echo_compress(uint8_t* s, uint8_t iterations, uint64_t* c, void* salt){ +static void echo_compress(uint8_t *s, uint8_t iterations, uint64_t *c, void *salt){ uint8_t i, j; - uint8_t k[16]; + union { + uint8_t v8[16]; + uint64_t v64[2]; + } k; #if DEBUG uint8_t round=0; #endif - memcpy(k, c, 8); - memset(k+8, 0, 8); + memcpy(k.v8, c, 8); + memset(k.v8+8, 0, 8); do{ /* BIG.SubWords */ #if DEBUG @@ -110,9 +113,9 @@ static void echo_compress(uint8_t* s, uint8_t iterations, uint64_t* c, void* sal } #endif for(i=0; i<16; ++i){ - aes_encrypt_round(s+16*i, k); - aes_encrypt_round(s+16*i, salt); - *((uint64_t*)(k)) += 1; + aes_enc_round((aes_cipher_state_t*)(s+16*i), (aes_roundkey_t*)k.v8); + aes_enc_round((aes_cipher_state_t*)(s+16*i), (aes_roundkey_t*)salt); + k.v64[0] += 1; } #if DEBUG if(roundcounter += ECHO_SMALL_BLOCKSIZE; compress512(ctx->v, block, &(ctx->counter), ctx->salt); } -void echo_small_lastBlock(echo_small_ctx_t* ctx, void* block, uint16_t length_b){ +void echo_small_lastBlock(echo_small_ctx_t *ctx, void *block, uint16_t length_b){ while(length_b>=ECHO_SMALL_BLOCKSIZE){ echo_small_nextBlock(ctx, block); block = (uint8_t*)block + ECHO_SMALL_BLOCKSIZE_B; @@ -230,12 +233,12 @@ void echo_small_lastBlock(echo_small_ctx_t* ctx, void* block, uint16_t length_b) /******************************************************************************/ -void echo_large_nextBlock(echo_large_ctx_t* ctx, void* block){ +void echo_large_nextBlock(echo_large_ctx_t *ctx, void *block){ ctx->counter += ECHO_LARGE_BLOCKSIZE; compress1024(ctx->v, block, &(ctx->counter), ctx->salt); } -void echo_large_lastBlock(echo_large_ctx_t* ctx, void* block, uint16_t length_b){ +void echo_large_lastBlock(echo_large_ctx_t *ctx, void *block, uint16_t length_b){ while(length_b>=ECHO_LARGE_BLOCKSIZE){ echo_large_nextBlock(ctx, block); block = (uint8_t*)block + ECHO_LARGE_BLOCKSIZE_B; @@ -261,31 +264,31 @@ void echo_large_lastBlock(echo_large_ctx_t* ctx, void* block, uint16_t length_b) } /******************************************************************************/ -void echo_ctx2hash(void* dest, uint16_t length_b, echo_small_ctx_t* ctx){ +void echo_ctx2hash(void *dest, uint16_t length_b, echo_small_ctx_t *ctx){ memcpy(dest, ctx->v, (length_b+7)/8); } -void echo224_ctx2hash(void* dest, echo_small_ctx_t* ctx){ +void echo224_ctx2hash(void *dest, echo_small_ctx_t *ctx){ memcpy(dest, ctx->v, 224/8); } -void echo256_ctx2hash(void* dest, echo_small_ctx_t* ctx){ +void echo256_ctx2hash(void *dest, echo_small_ctx_t *ctx){ memcpy(dest, ctx->v, 256/8); } /******************************************************************************/ -void echo384_ctx2hash(void* dest, echo_large_ctx_t* ctx){ +void echo384_ctx2hash(void *dest, echo_large_ctx_t *ctx){ memcpy(dest, ctx->v, 384/8); } -void echo512_ctx2hash(void* dest, echo_large_ctx_t* ctx){ +void echo512_ctx2hash(void *dest, echo_large_ctx_t *ctx){ memcpy(dest, ctx->v, 512/8); } /******************************************************************************/ -void echo224_init(echo_small_ctx_t* ctx){ +void echo224_init(echo_small_ctx_t *ctx){ memset(ctx->v, 0, 4*16); ctx->counter = 0; memset(ctx->salt, 0, 16); @@ -296,7 +299,7 @@ void echo224_init(echo_small_ctx_t* ctx){ ctx->v[0+16*3] = 0xE0; } -void echo256_init(echo_small_ctx_t* ctx){ +void echo256_init(echo_small_ctx_t *ctx){ memset(ctx->v, 0, 4*16); ctx->counter = 0; memset(ctx->salt, 0, 16); @@ -309,7 +312,7 @@ void echo256_init(echo_small_ctx_t* ctx){ /******************************************************************************/ -void echo384_init(echo_large_ctx_t* ctx){ +void echo384_init(echo_large_ctx_t *ctx){ uint8_t i; memset(ctx->v, 0, 8*16); ctx->counter = 0; @@ -321,7 +324,7 @@ void echo384_init(echo_large_ctx_t* ctx){ } } -void echo512_init(echo_large_ctx_t* ctx){ +void echo512_init(echo_large_ctx_t *ctx){ uint8_t i; memset(ctx->v, 0, 8*16); ctx->counter = 0;