This commit is contained in:
bg 2008-09-21 21:22:23 +00:00
parent 8fcf3f56d6
commit 71a4c5f0a3
3 changed files with 69 additions and 66 deletions

View File

@ -26,9 +26,6 @@
* *
*/ */
#include <avr/io.h>
#include "avr-asm-macros.S"
/* /*
* void memxor(void* dest, const void* src, uint16_t n); * void memxor(void* dest, const void* src, uint16_t n);
*/ */

View File

@ -1,21 +1,24 @@
/* shabea.c */ /* shabea.c */
/* /*
This file is part of the Crypto-avr-lib/microcrypt-lib. * This file is part of AnonAccess, an access system which can be used
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) * to open door or doing other things with an anonymity featured
* account managment.
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** /**
* \file shabea.c * \file shabea.c
* \author Daniel Otte * \author Daniel Otte
@ -33,8 +36,6 @@
#include "sha256.h" #include "sha256.h"
#include "config.h" #include "config.h"
#include "uart.h"
#include "debug.h"
#include "memxor.h" #include "memxor.h"
@ -42,36 +43,47 @@
* SHABEA256-n * SHABEA256-n
*/ */
#define BLOCKSIZE 256 #define SHABEA_BLOCKSIZE 256
#define BLOCKSIZEB (BLOCKSIZE/8) #define SHABEA_BLOCKSIZEB (SHABEA_BLOCKSIZE/8)
#define HALFSIZEB (BLOCKSIZEB/2) #define SHABEA_HALFSIZEB (SHABEA_BLOCKSIZEB/2)
#define HALFSIZE (BLOCKSIZE/2) #define SHABEA_HALFSIZE (SHABEA_BLOCKSIZE/2)
#define L ((uint8_t*)block+ 0) #define L ((uint8_t*)block+ 0)
#define R ((uint8_t*)block+16) #define R ((uint8_t*)block+16)
void shabea256(void * block, void * key, uint16_t keysize_b, 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 r; /**/
uint8_t tb[HALFSIZEB+2+(keysize_b+7)/8]; /**/ uint8_t tb[SHABEA_HALFSIZEB+2+(keysize_b+7)/8]; /**/
uint16_t kbs; /* bytes used for the key / temporary block */ uint16_t kbs; /* bytes used for the key / temporary block */
sha256_hash_t hash; sha256_hash_t hash;
uint8_t termcond;
r = (enc?0:(rounds-1)); int8_t dir;
if(enc){
r = 0;
termcond = rounds-1;
dir = 1;
} else {
r = rounds-1;
termcond = 0;
dir = -1;
}
kbs = (keysize_b+7)/8; kbs = (keysize_b+7)/8;
memcpy(tb+HALFSIZEB+2, key, kbs); /* copy key to temporary block */ memcpy(tb+SHABEA_HALFSIZEB+2, key, kbs); /* copy key to temporary block */
tb[HALFSIZEB+0] = 0; /* set round counter high value to zero */ tb[SHABEA_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 */ for(;;r+=dir){ /* enc: 0..(rounds-1) ; !enc: (rounds-1)..0 */
memcpy(tb, R, HALFSIZEB); /* copy right half into tb */ memcpy(tb, R, SHABEA_HALFSIZEB); /* copy right half into tb */
tb[HALFSIZEB+1] = r; tb[SHABEA_HALFSIZEB+1] = r;
sha256(&hash, tb, HALFSIZE+16+keysize_b); sha256(&hash, tb, SHABEA_HALFSIZE+16+keysize_b);
if(!(r==(enc?(rounds-1):0))){ if(r!=termcond){
/* swap */ /* swap */
memxor(hash, L, HALFSIZEB); memxor(hash, L, SHABEA_HALFSIZEB);
memcpy(L, R, HALFSIZEB); memcpy(L, R, SHABEA_HALFSIZEB);
memcpy(R, hash, HALFSIZEB); memcpy(R, hash, SHABEA_HALFSIZEB);
} else { } else {
/* last round */
/* no swap */ /* no swap */
memxor(L, hash, HALFSIZEB); memxor(L, hash, SHABEA_HALFSIZEB);
return;
} }
} }
} }

View File

@ -1,27 +1,32 @@
/* shabea.h */ /* shabea.h */
/* /*
This file is part of the Crypto-avr-lib/microcrypt-lib. * This file is part of AnonAccess, an access system which can be used
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) * to open door or doing other things with an anonymity featured
* account managment.
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** /**
* \file shabea.h * \file shabea.h
* \author Daniel Otte * \author Daniel Otte
* \date 2007-06-07 * \date 2007-06-07
* \brief SHABEA - a SHA Based Encryption Algorithm declarations * \brief SHABEA - a SHA Based Encryption Algorithm declarations
* \license GPLv3 or later * \par License
* GPL
* *
* SHABEAn-r where n is the blocksize and r the number of round used * SHABEAn-r where n is the blocksize and r the number of round used
* *
@ -30,16 +35,5 @@
#ifndef SHABEA_H_ #ifndef SHABEA_H_
#define SHABEA_H_ #define SHABEA_H_
/** \fn void shabea256(void * block, const void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds); void shabea256(void * block, void * key, uint16_t keysize_b, uint8_t enc, uint8_t rounds);
* \brief shabea256 encryption/decryption
*
* \param block pointer to a 256 bit (32 byte block) to en/decrypt
* \param key pointer to the key material
* \param keysize_b length of the key in bits
* \param enc controls if encryption (1) or decryption (0) is done
* \param rounds rounds to be done by the cipher (it is not recommended to use less then four rounds)
*/
void shabea256(void * block, const void * key, uint16_t keysize_b,
uint8_t enc, uint8_t rounds);
#endif /*SHABEA_H_*/ #endif /*SHABEA_H_*/