X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=blake%2Fblake_small.c;h=fafea3994f5cf649216c968914b4086ed1c50a1b;hb=13dbf0a84670c266c122cb5dcd084b394ce30804;hp=d3559401adbe55be31f1c00e08e189d954b6da75;hpb=22b608111d32de8b0c8fa34f35bd0d8892df2285;p=avr-crypto-lib.git diff --git a/blake/blake_small.c b/blake/blake_small.c index d355940..fafea39 100644 --- a/blake/blake_small.c +++ b/blake/blake_small.c @@ -33,7 +33,7 @@ #include "blake_common.h" static -uint32_t blake_c[] PROGMEM = { +const uint32_t blake_c[] PROGMEM = { 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, @@ -141,26 +141,29 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len msg = (uint8_t*)msg + BLAKE_SMALL_BLOCKSIZE_B; length_b -= BLAKE_SMALL_BLOCKSIZE; } - uint8_t buffer[64]; + union { + uint8_t v8[64]; + uint32_t v32[16]; + } buffer; uint32_t v[16]; union { uint64_t v64; uint32_t v32[2]; }ctr; ctr.v64 = ctx->counter*512+length_b; - memset(buffer, 0, 64); - memcpy(buffer, msg, (length_b+7)/8); - buffer[length_b/8] |= 0x80 >> (length_b&0x7); - blake_small_changeendian(buffer, buffer); + memset(buffer.v8, 0, 64); + memcpy(buffer.v8, msg, (length_b+7)/8); + buffer.v8[length_b/8] |= 0x80 >> (length_b&0x7); + blake_small_changeendian(buffer.v8, buffer.v8); blake_small_expand(v, ctx); if(length_b>512-64-2){ v[12] ^= ctr.v32[0]; v[13] ^= ctr.v32[0]; v[14] ^= ctr.v32[1]; v[15] ^= ctr.v32[1]; - blake_small_compress(v, buffer); + blake_small_compress(v, buffer.v8); blake_small_collapse(ctx, v); - memset(buffer, 0, 64-8); + memset(buffer.v8, 0, 64-8); blake_small_expand(v, ctx); }else{ if(length_b){ @@ -171,15 +174,15 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len } } if(ctx->appendone) - buffer[64-8-4] |= 0x01; - *((uint32_t*)(&(buffer[64-8]))) = ctr.v32[1]; - *((uint32_t*)(&(buffer[64-4]))) = ctr.v32[0]; - blake_small_compress(v, buffer); + buffer.v8[64-8-4] |= 0x01; + buffer.v32[14] = ctr.v32[1]; + buffer.v32[15] = ctr.v32[0]; + blake_small_compress(v, buffer.v8); blake_small_collapse(ctx, v); } -uint32_t blake256_iv[] PROGMEM = { +const uint32_t blake256_iv[] PROGMEM = { 0x6A09E667L, 0xBB67AE85, 0x3C6EF372L, 0xA54FF53A, 0x510E527FL, 0x9B05688C, @@ -196,7 +199,7 @@ void blake256_init(blake256_ctx_t* ctx){ ctx->appendone = 1; } -uint32_t blake224_iv[] PROGMEM = { +const uint32_t blake224_iv[] PROGMEM = { 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511,