X-Git-Url: https://git.cryptolib.org/?p=arm-crypto-lib.git;a=blobdiff_plain;f=blake%2Fblake_small.c;h=ba73edb42599d14f7537caacd508291982aa488f;hp=0b3fca281ad4e101912f6d2a614cf093c6c64dbb;hb=e1db57c69472f52cf2405ef4eb22f085a868eeeb;hpb=06a67c77b1e8c2769a149591d6e00ee0aebdd7f2 diff --git a/blake/blake_small.c b/blake/blake_small.c index 0b3fca2..ba73edb 100644 --- a/blake/blake_small.c +++ b/blake/blake_small.c @@ -27,7 +27,7 @@ #include #include -#include "memxor/memxor.h" +#include "memxor.h" #include "blake_small.h" #include "blake_common.h" @@ -76,21 +76,23 @@ void blake_small_changeendian(void* dest, const void* src){ static void blake_small_compress(uint32_t* v,const void* m){ uint8_t r,i; - uint8_t s0, s1; + uint16_t s, *p=(uint16_t*)blake_sigma; union { uint32_t v32; uint8_t v8[4]; } idx; - for(r=0; r<10; ++r){ + for(r=0; r<14; ++r){ for(i=0; i<8; ++i){ idx.v32 = ((uint32_t*)blake_index_lut)[i]; - s0 = blake_sigma[16*r+2*i+0]; - s1 = blake_sigma[16*r+2*i+1]; - A += B + (((uint32_t*)m)[s0] ^ blake_c[s1]); + s = *p++; + if(p==(uint16_t*)(blake_sigma+160)){ + p=(uint16_t*)blake_sigma; + } + A += B + (((uint32_t*)m)[s&0xff] ^ blake_c[s>>8]); D = ROTR32(A^D, 16); C += D; B = ROTR32(B^C, 12); - A += B + (((uint32_t*)m)[s1] ^ blake_c[s0]); + A += B + (((uint32_t*)m)[s>>8] ^ blake_c[s&0xff]); D = ROTR32(A^D, 8); C += D; B = ROTR32(B^C, 7); @@ -170,17 +172,17 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len } static const -uint32_t blake32_iv[] = { +uint32_t blake256_iv[] = { 0x6A09E667L, 0xBB67AE85, 0x3C6EF372L, 0xA54FF53A, 0x510E527FL, 0x9B05688C, 0x1F83D9ABL, 0x5BE0CD19 }; -void blake32_init(blake32_ctx_t* ctx){ +void blake256_init(blake256_ctx_t* ctx){ uint8_t i; for(i=0; i<8; ++i){ - ctx->h[i] = blake32_iv[i]; + ctx->h[i] = blake256_iv[i]; } memset(ctx->s, 0, 4*4); ctx->counter = 0; @@ -188,73 +190,73 @@ void blake32_init(blake32_ctx_t* ctx){ } static const -uint32_t blake28_iv[] = { +uint32_t blake224_iv[] = { 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4 }; -void blake28_init(blake28_ctx_t* ctx){ +void blake224_init(blake224_ctx_t* ctx){ uint8_t i; for(i=0; i<8; ++i){ - ctx->h[i] = blake28_iv[i]; + ctx->h[i] = blake224_iv[i]; } memset(ctx->s, 0, 4*4); ctx->counter = 0; ctx->appendone = 0; } -void blake32_ctx2hash(void* dest, const blake32_ctx_t* ctx){ +void blake256_ctx2hash(void* dest, const blake256_ctx_t* ctx){ uint8_t i; for(i=0; i<8; ++i){ ((uint32_t*)dest)[i] = CHANGE_ENDIAN32(ctx->h[i]); } } -void blake28_ctx2hash(void* dest, const blake28_ctx_t* ctx){ +void blake224_ctx2hash(void* dest, const blake224_ctx_t* ctx){ uint8_t i; for(i=0; i<7; ++i){ ((uint32_t*)dest)[i] = CHANGE_ENDIAN32(ctx->h[i]); } } -void blake32_nextBlock(blake32_ctx_t* ctx, const void* block){ +void blake256_nextBlock(blake256_ctx_t* ctx, const void* block){ blake_small_nextBlock(ctx, block); } -void blake28_nextBlock(blake28_ctx_t* ctx, const void* block){ +void blake224_nextBlock(blake224_ctx_t* ctx, const void* block){ blake_small_nextBlock(ctx, block); } -void blake32_lastBlock(blake32_ctx_t* ctx, const void* block, uint16_t length_b){ +void blake256_lastBlock(blake256_ctx_t* ctx, const void* block, uint16_t length_b){ blake_small_lastBlock(ctx, block, length_b); } -void blake28_lastBlock(blake28_ctx_t* ctx, const void* block, uint16_t length_b){ +void blake224_lastBlock(blake224_ctx_t* ctx, const void* block, uint16_t length_b){ blake_small_lastBlock(ctx, block, length_b); } -void blake32(void* dest, const void* msg, uint32_t length_b){ +void blake256(void* dest, const void* msg, uint32_t length_b){ blake_small_ctx_t ctx; - blake32_init(&ctx); + blake256_init(&ctx); while(length_b>=BLAKE_SMALL_BLOCKSIZE){ blake_small_nextBlock(&ctx, msg); msg = (uint8_t*)msg + BLAKE_SMALL_BLOCKSIZE_B; length_b -= BLAKE_SMALL_BLOCKSIZE; } blake_small_lastBlock(&ctx, msg, length_b); - blake32_ctx2hash(dest, &ctx); + blake256_ctx2hash(dest, &ctx); } -void blake28(void* dest, const void* msg, uint32_t length_b){ +void blake224(void* dest, const void* msg, uint32_t length_b){ blake_small_ctx_t ctx; - blake28_init(&ctx); + blake224_init(&ctx); while(length_b>=BLAKE_SMALL_BLOCKSIZE){ blake_small_nextBlock(&ctx, msg); msg = (uint8_t*)msg + BLAKE_SMALL_BLOCKSIZE_B; length_b -= BLAKE_SMALL_BLOCKSIZE; } blake_small_lastBlock(&ctx, msg, length_b); - blake28_ctx2hash(dest, &ctx); + blake224_ctx2hash(dest, &ctx); }