X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=jh%2Fjh_simple_small_core.c;h=15d8571d984e549c32ec6c0753e6489d1161bd65;hb=41e9e95f07e04170b8732426b2c5d73400b4a2bd;hp=c3c97aed8cea63c1dd143f9540db0f27dc721357;hpb=e2a5b474634f8c07d75119c2affdc6bb7f4e7848;p=avr-crypto-lib.git diff --git a/jh/jh_simple_small_core.c b/jh/jh_simple_small_core.c index c3c97ae..15d8571 100644 --- a/jh/jh_simple_small_core.c +++ b/jh/jh_simple_small_core.c @@ -50,7 +50,7 @@ uint8_t jh_l(uint8_t v, uint8_t w){ } static -void jh_round(uint8_t* a, uint8_t* rc){ +void jh_round(uint8_t* a, const uint8_t* rc){ uint8_t b[128]; uint8_t i,r,x,y; for(i=0; i<128; ++i){ @@ -103,24 +103,21 @@ void jh_next_round_const(uint8_t* a){ } } +static const uint8_t idx[]={112,80,48,16,96,64,32,0}; static inline void group(uint8_t *a){ uint8_t b[128]; - uint8_t i,x,y; + uint8_t i,j,k,x=0; for(i=0; i<128; ++i){ - x = (((a[i/8+ 0])>>4)&0x8) - | (((a[i/8+ 32])>>5)&0x4) - | (((a[i/8+ 64])>>6)&0x2) - | (((a[i/8+ 96])>>7)&0x1); - a[i/8] <<= 1; a[i/8+32]<<=1; a[i/8+64]<<=1; a[i/8+96]<<=1; - y = (((a[i/8+ 16])>>4)&0x8) - | (((a[i/8+ 48])>>5)&0x4) - | (((a[i/8+ 80])>>6)&0x2) - | (((a[i/8+112])>>7)&0x1); - a[i/8+16] <<= 1; a[i/8+48]<<=1; a[i/8+80]<<=1; a[i/8+112]<<=1; - b[i]= (x<<4)|y; + j=i/8; + for(k=0;k<8;++k){ + x>>=1; + x |= a[j+idx[k]]&0x80; + a[j+idx[k]] <<= 1; + } + b[i]= x; } memcpy(a,b,128); } @@ -128,13 +125,14 @@ void group(uint8_t *a){ static inline void degroup(uint8_t *a){ uint8_t b[128]; - static uint8_t idx[]={112,80,48,16,96,64,32,0}; uint8_t i,j,k,t; for(i=0;i<128;++i){ j=i/8; t = a[i]; for(k=0; k<8; ++k){ - b[j+idx[k]]<<=1; b[j+idx[k]] |= t&1; t>>=1; + b[j+idx[k]]<<=1; + b[j+idx[k]] |= t&1; + t>>=1; } } memcpy(a,b,128); @@ -156,7 +154,7 @@ void jh_encrypt(uint8_t* a){ jh_round(a, rc); jh_next_round_const(rc); } - uint8_t r,x,y; + uint8_t r=0,x,y; for(i=0; i<128; ++i){ if(i%4==0){