X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=sidebyside;f=shabea.c;h=52c9461c0ba00152f99cd4762ec7ed845491807b;hb=cf1c79ef3fa4bb22f0cab28b2b6e958293aca739;hp=62ff6b4a27e72b5af76223f3e8c06f09bd2df6de;hpb=96ebafd201c9e8441c7677577b24aa402c1defc6;p=avr-crypto-lib.git diff --git a/shabea.c b/shabea.c index 62ff6b4..52c9461 100644 --- a/shabea.c +++ b/shabea.c @@ -35,14 +35,8 @@ #include "config.h" #include "uart.h" #include "debug.h" -/* - * - */ -void memxor(uint8_t * dest, uint8_t * src, uint8_t length){ - while(length--){ - *dest++ ^= *src++; - } -} +#include "memxor.h" + /* * SHABEA256-n @@ -55,29 +49,29 @@ void memxor(uint8_t * dest, uint8_t * src, uint8_t length){ #define L ((uint8_t*)block+ 0) #define R ((uint8_t*)block+16) -void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds){ +void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds){ int8_t r; /**/ - uint8_t tb[HALFSIZEB+2+(keysize+7)/8]; /**/ + uint8_t tb[HALFSIZEB+2+(keysize_b+7)/8]; /**/ uint16_t kbs; /* bytes used for the key / temporary block */ sha256_hash_t hash; r = (enc?0:(rounds-1)); - kbs = (keysize+7)/8; + kbs = (keysize_b+7)/8; memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */ tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */ for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */ memcpy(tb, R, HALFSIZEB); /* copy right half into tb */ tb[HALFSIZEB+1] = r; - sha256(&hash, tb, HALFSIZE+16+keysize); + sha256(&hash, tb, HALFSIZE+16+keysize_b); if(!(r==(enc?(rounds-1):0))){ /* swap */ - memxor(hash, L, HALFSIZE); - memcpy(L, R, HALFSIZE); - memcpy(R, hash, HALFSIZE); + memxor(hash, L, HALFSIZEB); + memcpy(L, R, HALFSIZEB); + memcpy(R, hash, HALFSIZEB); } else { /* no swap */ - memxor(L, hash, HALFSIZE); + memxor(L, hash, HALFSIZEB); } } }