5 * \brief SHABEA - a SHA Based Encrytion 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){
43 uint16_t kbs; /* bytes used for the key / temporary block */
46 r = (enc?0:(rounds-1));
48 tb = malloc(HALFSIZEB+2+kbs);
49 memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */
50 tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */
52 for(;r!=(enc?(rounds):-1);enc?r++:r--){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
53 memcpy(tb, R, HALFSIZEB); /* copy right half into tb */
55 sha256(&hash, tb, HALFSIZE+16+keysize);
56 if(!(r==(enc?(rounds-1):0))){
58 memxor(hash, L, HALFSIZE);
59 memcpy(L, R, HALFSIZE);
60 memcpy(R, hash, HALFSIZE);
63 memxor(L, hash, HALFSIZE);