3 * This file is part of AnonAccess, an access system which can be used
4 * to open door or doing other things with an anonymity featured
6 * Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * \brief SHABEA - a SHA Based Encryption Algorithm implementation
30 * SHABEAn-r where n is the blocksize and r the number of round used
46 #define SHABEA_BLOCKSIZE 256
47 #define SHABEA_BLOCKSIZEB (SHABEA_BLOCKSIZE/8)
48 #define SHABEA_HALFSIZEB (SHABEA_BLOCKSIZEB/2)
49 #define SHABEA_HALFSIZE (SHABEA_BLOCKSIZE/2)
51 #define L ((uint8_t*)block+ 0)
52 #define R ((uint8_t*)block+16)
53 void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds){
55 uint8_t tb[SHABEA_HALFSIZEB+2+(keysize_b+7)/8]; /**/
56 uint16_t kbs; /* bytes used for the key / temporary block */
69 kbs = (keysize_b+7)/8;
70 memcpy(tb+SHABEA_HALFSIZEB+2, key, kbs); /* copy key to temporary block */
71 tb[SHABEA_HALFSIZEB+0] = 0; /* set round counter high value to zero */
73 for(;;r+=dir){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
74 memcpy(tb, R, SHABEA_HALFSIZEB); /* copy right half into tb */
75 tb[SHABEA_HALFSIZEB+1] = r;
76 sha256(&hash, tb, SHABEA_HALFSIZE+16+keysize_b);
79 memxor(hash, L, SHABEA_HALFSIZEB);
80 memcpy(L, R, SHABEA_HALFSIZEB);
81 memcpy(R, hash, SHABEA_HALFSIZEB);
85 memxor(L, hash, SHABEA_HALFSIZEB);