X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=salsa20%2Fsalsa20.c;h=95a38d54d60a92b75e194ed55a1392c5dfd76fbe;hb=cc6b183296a5852449e3324737e2a2dece788786;hp=ca529a76e682f3f96623ebdea2c034b6627e50c0;hpb=a012cfa921853fb9b8bd484981ab471a9ba25ec9;p=avr-crypto-lib.git diff --git a/salsa20/salsa20.c b/salsa20/salsa20.c index ca529a7..95a38d5 100644 --- a/salsa20/salsa20.c +++ b/salsa20/salsa20.c @@ -69,8 +69,8 @@ void salsa20_hash(uint32_t* a){ } } -uint8_t sigma[] PROGMEM = {'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'}; -uint8_t theta[] PROGMEM = {'e','x','p','a','n','d',' ','1','6','-','b','y','t','e',' ','k'}; +const uint8_t sigma[] PROGMEM = {'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'}; +const uint8_t theta[] PROGMEM = {'e','x','p','a','n','d',' ','1','6','-','b','y','t','e',' ','k'}; void salsa_k32(uint32_t* dest, const uint32_t* k, const uint32_t* n){ memcpy_P(dest+ 0, sigma+ 0, 4); @@ -111,31 +111,31 @@ void salsa20_genBlock128(void* dest, const void* k, const void* iv, uint64_t i){ void salsa20_init(void* key, uint16_t keylength_b, void* iv, salsa20_ctx_t* ctx){ if(keylength_b==256){ - memcpy_P((ctx->a+ 0), sigma+ 0, 4); - memcpy_P((ctx->a+20), sigma+ 4, 4); - memcpy_P((ctx->a+40), sigma+ 8, 4); - memcpy( (ctx->a+44), (uint8_t*)key+16, 16); - memcpy_P((ctx->a+60), sigma+12, 4); + memcpy_P((ctx->a.v8+ 0), sigma+ 0, 4); + memcpy_P((ctx->a.v8+20), sigma+ 4, 4); + memcpy_P((ctx->a.v8+40), sigma+ 8, 4); + memcpy( (ctx->a.v8+44), (uint8_t*)key+16, 16); + memcpy_P((ctx->a.v8+60), sigma+12, 4); }else{ - memcpy_P((ctx->a+ 0), theta+ 0, 4); - memcpy_P((ctx->a+20), theta+ 4, 4); - memcpy_P((ctx->a+40), theta+ 8, 4); - memcpy( (ctx->a+44), (uint8_t*)key+ 0, 16); - memcpy_P((ctx->a+60), theta+12, 4); + memcpy_P((ctx->a.v8+ 0), theta+ 0, 4); + memcpy_P((ctx->a.v8+20), theta+ 4, 4); + memcpy_P((ctx->a.v8+40), theta+ 8, 4); + memcpy( (ctx->a.v8+44), (uint8_t*)key+ 0, 16); + memcpy_P((ctx->a.v8+60), theta+12, 4); } - memcpy( (ctx->a+ 4), key, 16); - memset( (ctx->a+24), 0, 16); + memcpy( (ctx->a.v8+ 4), key, 16); + memset( (ctx->a.v8+24), 0, 16); if(iv){ - memcpy( (ctx->a+24), iv, 8); + memcpy( (ctx->a.v8+24), iv, 8); } ctx->buffer_idx=64; } uint8_t salsa20_gen(salsa20_ctx_t* ctx){ if(ctx->buffer_idx==64){ - memcpy(ctx->buffer, ctx->a, 64); + memcpy(ctx->buffer, ctx->a.v8, 64); salsa20_hash((uint32_t*)(ctx->buffer)); - *((uint64_t*)(ctx->a+32)) += 1; + ctx->a.v64[4] += 1; ctx->buffer_idx = 0; } return ctx->buffer[ctx->buffer_idx++];