5 * \brief SHABEA - a SHA Based Encryption Algorithm implementation
9 * SHABEAn-r where n is the blocksize and r the number of round used
23 void memxor(uint8_t * dest, uint8_t * src, uint8_t length){
34 #define BLOCKSIZEB (BLOCKSIZE/8)
35 #define HALFSIZEB (BLOCKSIZEB/2)
36 #define HALFSIZE (BLOCKSIZE/2)
38 #define L ((uint8_t*)block+ 0)
39 #define R ((uint8_t*)block+16)
40 void shabea256(void * block, void * key, uint16_t keysize, uint8_t enc, uint8_t rounds){
42 uint8_t tb[HALFSIZEB+2+(keysize+7)/8]; /**/
43 uint16_t kbs; /* bytes used for the key / temporary block */
46 r = (enc?0:(rounds-1));
48 memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */
49 tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */
51 for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
52 memcpy(tb, R, HALFSIZEB); /* copy right half into tb */
54 sha256(&hash, tb, HALFSIZE+16+keysize);
55 if(!(r==(enc?(rounds-1):0))){
57 memxor(hash, L, HALFSIZE);
58 memcpy(L, R, HALFSIZE);
59 memcpy(R, hash, HALFSIZE);
62 memxor(L, hash, HALFSIZE);