X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=bmw%2Fbmw_small.c;h=d52f92ef49d145ca9d59eb1a423db6198ba2b1fa;hb=fb928c1c4c392b9e987631f84f1027af94e05beb;hp=6a531580f7c41226c8e57755ff183a7780b7f69c;hpb=d70d1d77bab1a5f5278227d674bc59da0378fe15;p=arm-crypto-lib.git diff --git a/bmw/bmw_small.c b/bmw/bmw_small.c index 6a53158..d52f92e 100644 --- a/bmw/bmw_small.c +++ b/bmw/bmw_small.c @@ -28,7 +28,7 @@ #include #include #include "bmw_small.h" -#include "memxor/memxor.h" +#include "memxor.h" #define SHL32(a,n) ((a)<<(n)) #define SHR32(a,n) ((a)>>(n)) @@ -401,38 +401,42 @@ void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){ } void bmw_small_lastBlock(bmw_small_ctx_t* ctx, const void* block, uint16_t length_b){ - uint8_t buffer[64]; + union { + uint8_t v8[64]; + uint32_t v32[16]; + uint64_t v64[ 8]; + } buffer; while(length_b >= BMW_SMALL_BLOCKSIZE){ bmw_small_nextBlock(ctx, block); length_b -= BMW_SMALL_BLOCKSIZE; block = (uint8_t*)block + BMW_SMALL_BLOCKSIZE_B; } - memset(buffer, 0, 64); - memcpy(buffer, block, (length_b+7)/8); - buffer[length_b>>3] |= 0x80 >> (length_b&0x07); + memset(buffer.v8, 0, 64); + memcpy(buffer.v8, block, (length_b+7)/8); + buffer.v8[length_b>>3] |= 0x80 >> (length_b&0x07); if(length_b+1>64*8-64){ - bmw_small_nextBlock(ctx, buffer); - memset(buffer, 0, 64-8); + bmw_small_nextBlock(ctx, buffer.v8); + memset(buffer.v8, 0, 64-8); ctx->counter -= 1; } - *((uint64_t*)&(buffer[64-8])) = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b; - bmw_small_nextBlock(ctx, buffer); + buffer.v64[7] = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b; + bmw_small_nextBlock(ctx, buffer.v8); #if TWEAK uint8_t i; uint32_t q[32]; - memset(buffer, 0xaa, 64); + memset(buffer.v8, 0xaa, 64); for(i=0; i<16;++i){ - buffer[i*4] = i+0xa0; + buffer.v8[i*4] = i+0xa0; } -// dump_x(buffer, 16, 'A'); +// dump_x(buffer.v8, 16, 'A'); dump_x(ctx->h, 16, 'M'); - bmw_small_f0(q, (uint32_t*)buffer, ctx->h); - dump_x(buffer, 16, 'a'); + bmw_small_f0(q, buffer.v32, ctx->h); + dump_x(buffer.v8, 16, 'a'); dump_x(q, 16, 'Q'); - bmw_small_f1(q, ctx->h, (uint32_t*)buffer); + bmw_small_f1(q, ctx->h, buffer.v32); dump_x(q, 32, 'Q'); - bmw_small_f2((uint32_t*)buffer, q, ctx->h); - memcpy(ctx->h, buffer, 64); + bmw_small_f2(buffer.v32, q, ctx->h); + memcpy(ctx->h, buffer.v8, 64); #endif }