added Whirlpool-0 and Whirlpool-T

This commit is contained in:
bg 2011-01-05 09:32:41 +00:00
parent 1de7784dc5
commit 3f759a542c
18 changed files with 22346 additions and 21 deletions

View File

@ -136,7 +136,7 @@ all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
#-------------------------------------------------------------------------------
define TestBin_TEMPLATE
$(1)_TEST_BIN: $(2)
$(1)_TESTBIN: $(2)
endef
$(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
@ -301,7 +301,7 @@ info:
@echo " docu - build doxygen documentation"
@echo " clean - remove a lot of builded files"
@echo " depclean - also remove dependency files"
@echo " *_TEST_BIN - build test program"
@echo " *_TESTBIN - build test program"
@echo " *_TESTRUN - run nessie test"
@echo " *_OBJ - build algorithm core"
@echo " *_FLASH - flash test program"

49
hfal/hfal_whirlpool_0.c Normal file
View File

@ -0,0 +1,49 @@
/* hfal_whirlpool_0.c */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/**
* \file hfal_whirlpool_0.c
* \email daniel.otte@rub.de
* \author Daniel Otte
* \date 2011-02-04
* \license GPLv3 or later
*
*/
#include <avr/pgmspace.h>
#include <stdlib.h>
#include "hashfunction_descriptor.h"
#include "whirlpool.h"
static const char whirlpool_0_str[] PROGMEM = "Whirlpool-0";
const hfdesc_t whirlpool_0_desc PROGMEM = {
HFDESC_TYPE_HASHFUNCTION,
0,
whirlpool_0_str,
sizeof(whirlpool_ctx_t),
512,
512,
(hf_init_fpt)whirlpool_init,
(hf_nextBlock_fpt)whirlpool_nextBlock,
(hf_lastBlock_fpt)whirlpool_lastBlock,
(hf_ctx2hash_fpt)whirlpool_ctx2hash,
(hf_free_fpt)NULL,
(hf_mem_fpt)NULL
};

36
hfal/hfal_whirlpool_0.h Normal file
View File

@ -0,0 +1,36 @@
/* hfal_whirlpool_0.h */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/**
* \file hfal_whirlpool_0.h
* \email daniel.otte@rub.de
* \author Daniel Otte
* \date 2011-02-04
* \license GPLv3 or later
*
*/
#ifndef HFAL_WHIRLPOOL_0_H_
#define HFAL_WHIRLPOOL_0_H_
#include <avr/pgmspace.h>
#include "hashfunction_descriptor.h"
extern const hfdesc_t whirlpool_0_desc;
#endif /* HFAL_WHIRLPOOL_0_H_ */

49
hfal/hfal_whirlpool_t.c Normal file
View File

@ -0,0 +1,49 @@
/* hfal_whirlpool_t.c */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/**
* \file hfal_whirlpool_t.c
* \email daniel.otte@rub.de
* \author Daniel Otte
* \date 2011-02-04
* \license GPLv3 or later
*
*/
#include <avr/pgmspace.h>
#include <stdlib.h>
#include "hashfunction_descriptor.h"
#include "whirlpool.h"
static const char whirlpool_t_str[] PROGMEM = "Whirlpool-T";
const hfdesc_t whirlpool_t_desc PROGMEM = {
HFDESC_TYPE_HASHFUNCTION,
0,
whirlpool_t_str,
sizeof(whirlpool_ctx_t),
512,
512,
(hf_init_fpt)whirlpool_init,
(hf_nextBlock_fpt)whirlpool_nextBlock,
(hf_lastBlock_fpt)whirlpool_lastBlock,
(hf_ctx2hash_fpt)whirlpool_ctx2hash,
(hf_free_fpt)NULL,
(hf_mem_fpt)NULL
};

36
hfal/hfal_whirlpool_t.h Normal file
View File

@ -0,0 +1,36 @@
/* hfal_whirlpool_t.h */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/**
* \file hfal_whirlpool_t.h
* \email daniel.otte@rub.de
* \author Daniel Otte
* \date 2011-02-04
* \license GPLv3 or later
*
*/
#ifndef HFAL_WHIRLPOOL_T_H_
#define HFAL_WHIRLPOOL_T_H_
#include <avr/pgmspace.h>
#include "hashfunction_descriptor.h"
extern const hfdesc_t whirlpool_t_desc;
#endif /* HFAL_WHIRLPOOL_T_H_ */

View File

@ -118,7 +118,7 @@ $sp.write(command);
if(readTestVector(param)==false)
puts("ERROR: test seems not to be implemented");
exit(3);
exit(0); # 3
end
while(readTestVector(param))

View File

@ -0,0 +1,14 @@
# Makefile for Whirlpool-0
ALGO_NAME := WHIRLPOOL_0_FAST_C
# comment out the following line for removement of Whirlpool from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_DIR := whirlpool/
$(ALGO_NAME)_INCDIR := hfal/ memxor/ gf256mul/
$(ALGO_NAME)_OBJ := whirlpool.o gf256mul.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-whirlpool-0-test.o $(CLI_STD) $(HFAL_STD) hfal_whirlpool_0.o dump-asm.o dump-decl.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
$(ALGO_NAME)_DEF := SBOX_PROG=0 WHIRLPOOL_0=1

View File

@ -1,5 +1,5 @@
# Makefile for Whirlpool
ALGO_NAME := WHIRLPOOL_C
ALGO_NAME := WHIRLPOOL_FAST_C
# comment out the following line for removement of Whirlpool from the build process
HASHES += $(ALGO_NAME)
@ -10,4 +10,5 @@ $(ALGO_NAME)_OBJ := whirlpool.o gf256mul.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-whirlpool-test.o $(CLI_STD) $(HFAL_STD) hfal_whirlpool.o dump-asm.o dump-decl.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
$(ALGO_NAME)_DEF := SBOX_PROG=0

View File

@ -0,0 +1,14 @@
# Makefile for Whirlpool
ALGO_NAME := WHIRLPOOL_SMALL_C
# comment out the following line for removement of Whirlpool from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_DIR := whirlpool/
$(ALGO_NAME)_INCDIR := hfal/ memxor/ gf256mul/
$(ALGO_NAME)_OBJ := whirlpool.o gf256mul.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-whirlpool-test.o $(CLI_STD) $(HFAL_STD) hfal_whirlpool.o dump-asm.o dump-decl.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
$(ALGO_NAME)_DEF := SBOX_PROG=1

View File

@ -0,0 +1,14 @@
# Makefile for Whirlpool-T
ALGO_NAME := WHIRLPOOL_T_FAST_C
# comment out the following line for removement of Whirlpool from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_DIR := whirlpool/
$(ALGO_NAME)_INCDIR := hfal/ memxor/ gf256mul/
$(ALGO_NAME)_OBJ := whirlpool.o gf256mul.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-whirlpool-t-test.o $(CLI_STD) $(HFAL_STD) hfal_whirlpool_t.o dump-asm.o dump-decl.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
$(ALGO_NAME)_DEF := SBOX_PROG=0 WHIRLPOOL_T=1

View File

@ -0,0 +1,14 @@
# Makefile for Whirlpool-t
ALGO_NAME := WHIRLPOOL_T_SMALL_C
# comment out the following line for removement of Whirlpool from the build process
HASHES += $(ALGO_NAME)
$(ALGO_NAME)_DIR := whirlpool/
$(ALGO_NAME)_INCDIR := hfal/ memxor/ gf256mul/
$(ALGO_NAME)_OBJ := whirlpool.o gf256mul.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-whirlpool-t-test.o $(CLI_STD) $(HFAL_STD) hfal_whirlpool_t.o dump-asm.o dump-decl.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
$(ALGO_NAME)_DEF := SBOX_PROG=1 WHIRLPOOL_T=1

View File

@ -0,0 +1,171 @@
/* main-whirlpool-0-test.c */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/*
* Whirlpool-0 test-suit
*
*/
#include "config.h"
#include "uart_i.h"
#include "debug.h"
#include "whirlpool.h"
#include "nessie_hash_test.h"
#include "performance_test.h"
#include "hfal-performance.h"
#include "hfal-nessie.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "cli.h"
#include "shavs.h"
#include "hfal_whirlpool_0.h"
#include "dump.h"
char* algo_name = "Whirlpool-0";
const hfdesc_t* algolist[] PROGMEM = {
(hfdesc_t*)&whirlpool_0_desc,
NULL
};
/*****************************************************************************
* additional validation-functions *
*****************************************************************************/
void testrun_nessie_whirlpool(void){
hfal_nessie_multiple(algolist);
}
void testrun_whirlpool(void){
whirlpool_ctx_t ctx;
uint8_t hash[64];
uint8_t data[64];
memset(data, 0, 64);
data[0] = 'a';
data[1] = 'b';
data[2] = 'c';
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, 3*8);
whirlpool_ctx2hash(hash, &ctx);
cli_putstr_P(PSTR("\r\nEmpty message hash:"));
cli_hexdump_block(hash, 64, 4, 16);
}
void testrun_performance_whirlpool(void){
hfal_performance_multiple(algolist);
}
void testrun_nessie2(void){
uint16_t i;
uint8_t j;
uint8_t data[128], hash[64];
whirlpool_ctx_t ctx;
char str[8];
memset(data, 0, 128);
cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
for(i=0; i<1024; ++i){
cli_putstr_P(PSTR("\r\n L = "));
itoa(i, str, 10);
j=4;
j-= strlen(str);
if(j>3){
j=0;
}
while(j--){
cli_putc(' ');
}
cli_putstr(str);
cli_putstr_P(PSTR(": "));
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, i);
whirlpool_ctx2hash(hash, &ctx);
cli_hexdump(hash, 64);
}
cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
for(i=0; i<512; ++i){
cli_putstr_P(PSTR("\r\n S = "));
data[i/8] = 0x80>>(i&7);
cli_hexdump(data, 64);
cli_putstr_P(PSTR(": "));
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, 512);
whirlpool_ctx2hash(hash, &ctx);
data[i/8] = 0x00;
cli_hexdump(hash, 64);
}
cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
uint32_t c;
memset(hash, 0, 64);
for(c=0; c<1000000; ++c){
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, hash, 512);
whirlpool_ctx2hash(hash, &ctx);
}
cli_hexdump(hash, 64);
cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
}
/*****************************************************************************
* main *
*****************************************************************************/
const char nessie_str[] PROGMEM = "nessie";
const char nessie2_str[] PROGMEM = "nessie2";
const char test_str[] PROGMEM = "test";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
const char shavs_set_str[] PROGMEM = "shavs_set";
const char shavs_test1_str[] PROGMEM = "shavs_test1";
const char shavs_test2_str[] PROGMEM = "shavs_test2";
const char shavs_test3_str[] PROGMEM = "shavs_test3";
const char dump_str[] PROGMEM = "dump";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_whirlpool },
{ nessie2_str, NULL, testrun_nessie2 },
{ test_str, NULL, testrun_whirlpool },
{ performance_str, NULL, testrun_performance_whirlpool },
{ echo_str, (void*)1, (void_fpt)echo_ctrl },
{ shavs_list_str, NULL, shavs_listalgos },
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo },
{ shavs_test1_str, NULL, shavs_test1 },
{ shavs_test2_str, NULL, shavs_test2 },
{ shavs_test3_str, NULL, shavs_test3 },
{ dump_str, (void*)1, (void_fpt)dump },
{ NULL, NULL, NULL }
};
int main (void){
DEBUG_INIT();
cli_rx = (cli_rx_fpt)uart0_getc;
cli_tx = (cli_tx_fpt)uart0_putc;
shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&whirlpool_0_desc;
for(;;){
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
cli_putstr(algo_name);
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
cmd_interface(cmdlist);
}
}

View File

@ -0,0 +1,171 @@
/* main-whirlpool-t-test.c */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2011 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/>.
*/
/*
* Whirlpool test-suit
*
*/
#include "config.h"
#include "uart_i.h"
#include "debug.h"
#include "whirlpool.h"
#include "nessie_hash_test.h"
#include "performance_test.h"
#include "hfal-performance.h"
#include "hfal-nessie.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "cli.h"
#include "shavs.h"
#include "hfal_whirlpool_t.h"
#include "dump.h"
char* algo_name = "Whirlpool-T";
const hfdesc_t* algolist[] PROGMEM = {
(hfdesc_t*)&whirlpool_t_desc,
NULL
};
/*****************************************************************************
* additional validation-functions *
*****************************************************************************/
void testrun_nessie_whirlpool(void){
hfal_nessie_multiple(algolist);
}
void testrun_whirlpool(void){
whirlpool_ctx_t ctx;
uint8_t hash[64];
uint8_t data[64];
memset(data, 0, 64);
data[0] = 'a';
data[1] = 'b';
data[2] = 'c';
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, 3*8);
whirlpool_ctx2hash(hash, &ctx);
cli_putstr_P(PSTR("\r\nEmpty message hash:"));
cli_hexdump_block(hash, 64, 4, 16);
}
void testrun_performance_whirlpool(void){
hfal_performance_multiple(algolist);
}
void testrun_nessie2(void){
uint16_t i;
uint8_t j;
uint8_t data[128], hash[64];
whirlpool_ctx_t ctx;
char str[8];
memset(data, 0, 128);
cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
for(i=0; i<1024; ++i){
cli_putstr_P(PSTR("\r\n L = "));
itoa(i, str, 10);
j=4;
j-= strlen(str);
if(j>3){
j=0;
}
while(j--){
cli_putc(' ');
}
cli_putstr(str);
cli_putstr_P(PSTR(": "));
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, i);
whirlpool_ctx2hash(hash, &ctx);
cli_hexdump(hash, 64);
}
cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
for(i=0; i<512; ++i){
cli_putstr_P(PSTR("\r\n S = "));
data[i/8] = 0x80>>(i&7);
cli_hexdump(data, 64);
cli_putstr_P(PSTR(": "));
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, data, 512);
whirlpool_ctx2hash(hash, &ctx);
data[i/8] = 0x00;
cli_hexdump(hash, 64);
}
cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
uint32_t c;
memset(hash, 0, 64);
for(c=0; c<1000000; ++c){
whirlpool_init(&ctx);
whirlpool_lastBlock(&ctx, hash, 512);
whirlpool_ctx2hash(hash, &ctx);
}
cli_hexdump(hash, 64);
cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
}
/*****************************************************************************
* main *
*****************************************************************************/
const char nessie_str[] PROGMEM = "nessie";
const char nessie2_str[] PROGMEM = "nessie2";
const char test_str[] PROGMEM = "test";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
const char shavs_set_str[] PROGMEM = "shavs_set";
const char shavs_test1_str[] PROGMEM = "shavs_test1";
const char shavs_test2_str[] PROGMEM = "shavs_test2";
const char shavs_test3_str[] PROGMEM = "shavs_test3";
const char dump_str[] PROGMEM = "dump";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_whirlpool },
{ nessie2_str, NULL, testrun_nessie2 },
{ test_str, NULL, testrun_whirlpool },
{ performance_str, NULL, testrun_performance_whirlpool },
{ echo_str, (void*)1, (void_fpt)echo_ctrl },
{ shavs_list_str, NULL, shavs_listalgos },
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo },
{ shavs_test1_str, NULL, shavs_test1 },
{ shavs_test2_str, NULL, shavs_test2 },
{ shavs_test3_str, NULL, shavs_test3 },
{ dump_str, (void*)1, (void_fpt)dump },
{ NULL, NULL, NULL }
};
int main (void){
DEBUG_INIT();
cli_rx = (cli_rx_fpt)uart0_getc;
cli_tx = (cli_tx_fpt)uart0_putc;
shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&whirlpool_t_desc;
for(;;){
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
cli_putstr(algo_name);
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
cmd_interface(cmdlist);
}
}

View File

@ -74,18 +74,6 @@ void testrun_performance_whirlpool(void){
hfal_performance_multiple(algolist);
}
void test_sbox(void){
uint8_t i=0;
cli_putstr_P(PSTR("\r\nWhirlpool S-Box:"));
do{
if(i%16==0){
cli_putstr_P(PSTR("\r\n\t"));
}
cli_hexdump_byte(whirlpool_sbox(i++));
cli_putc(' ');
}while(i);
}
void testrun_nessie2(void){
uint16_t i;
uint8_t j;
@ -143,7 +131,6 @@ void testrun_nessie2(void){
const char nessie_str[] PROGMEM = "nessie";
const char nessie2_str[] PROGMEM = "nessie2";
const char test_str[] PROGMEM = "test";
const char test_sbox_str[] PROGMEM = "test_sbox";
const char performance_str[] PROGMEM = "performance";
const char echo_str[] PROGMEM = "echo";
const char shavs_list_str[] PROGMEM = "shavs_list";
@ -157,7 +144,6 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_whirlpool },
{ nessie2_str, NULL, testrun_nessie2 },
{ test_str, NULL, testrun_whirlpool },
{ test_sbox_str, NULL, test_sbox },
{ performance_str, NULL, testrun_performance_whirlpool },
{ echo_str, (void*)1, (void_fpt)echo_ctrl },
{ shavs_list_str, NULL, shavs_listalgos },

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,14 @@
#include "cli.h"
#endif
#if WHIRLPOOL_0
#ifdef SBOX_PROG
#undef SBOX_PROG
#endif
#define SBOX_PROG 0
#endif
#if SBOX_PROG
/*
u 0 1 2 3 4 5 6 7 8 9 A B C D E F
E(u) 1 B 9 C D 6 F 3 E 8 7 4 A 2 5 0
@ -46,7 +54,7 @@ static uint8_t r_box[16] PROGMEM = {
0x66, 0x33, 0x88, 0xAA, 0x22, 0x55, 0x11, 0x00
};
uint8_t whirlpool_sbox(uint8_t a){
static uint8_t whirlpool_sbox(uint8_t a){
uint8_t b,c,d;
b = pgm_read_byte(eeinv_box+(a&0x0f));
d = pgm_read_byte(eeinv_box+(a>>4));
@ -58,6 +66,51 @@ uint8_t whirlpool_sbox(uint8_t a){
return c;
}
#else
#if WHIRLPOOL_0
static uint8_t sbox[256] PROGMEM = {
0x68, 0xd0, 0xeb, 0x2b, 0x48, 0x9d, 0x6a, 0xe4, 0xe3, 0xa3, 0x56, 0x81, 0x7d, 0xf1, 0x85, 0x9e,
0x2c, 0x8e, 0x78, 0xca, 0x17, 0xa9, 0x61, 0xd5, 0x5d, 0x0b, 0x8c, 0x3c, 0x77, 0x51, 0x22, 0x42,
0x3f, 0x54, 0x41, 0x80, 0xcc, 0x86, 0xb3, 0x18, 0x2e, 0x57, 0x06, 0x62, 0xf4, 0x36, 0xd1, 0x6b,
0x1b, 0x65, 0x75, 0x10, 0xda, 0x49, 0x26, 0xf9, 0xcb, 0x66, 0xe7, 0xba, 0xae, 0x50, 0x52, 0xab,
0x05, 0xf0, 0x0d, 0x73, 0x3b, 0x04, 0x20, 0xfe, 0xdd, 0xf5, 0xb4, 0x5f, 0x0a, 0xb5, 0xc0, 0xa0,
0x71, 0xa5, 0x2d, 0x60, 0x72, 0x93, 0x39, 0x08, 0x83, 0x21, 0x5c, 0x87, 0xb1, 0xe0, 0x00, 0xc3,
0x12, 0x91, 0x8a, 0x02, 0x1c, 0x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7, 0xEB,
0x3C, 0x81, 0x94, 0xF7, 0xB9, 0x13, 0x2C, 0xD3, 0xE7, 0x6E, 0xC4, 0x03, 0x56, 0x44, 0x7F, 0xA9,
0x2A, 0xBB, 0xC1, 0x53, 0xDC, 0x0B, 0x9D, 0x6C, 0x31, 0x74, 0xF6, 0x46, 0xAC, 0x89, 0x14, 0xE1,
0x16, 0x3A, 0x69, 0x09, 0x70, 0xB6, 0xD0, 0xED, 0xCC, 0x42, 0x98, 0xA4, 0x28, 0x5C, 0xF8, 0x86
};
#endif
#define whirlpool_sbox(a) pgm_read_byte(sbox+a)
#endif
static void gamma(uint8_t* a){
uint8_t i;
for(i=0; i<64; ++i){
@ -79,9 +132,15 @@ static void pi(uint8_t* a){
}
}
#if WHIRLPOOL_0 || WHIRLPOOL_T
static uint8_t theta_matrix[8] PROGMEM = {
0x1, 0x1, 0x3, 0x1, 0x5, 0x8, 0x9, 0x5
};
#else
static uint8_t theta_matrix[8] PROGMEM = {
0x1, 0x1, 0x4, 0x1, 0x8, 0x5, 0x2, 0x9
};
#endif
#define POLYNOM 0x1D
@ -128,14 +187,19 @@ static void w_enc(uint8_t *a, const uint8_t* k){
cli_hexdump_block(k, 64, 4, 8);
#endif
uint8_t rk[64], rc[64];
uint8_t r,i;
uint8_t r;
memxor(a, k, 64);
memcpy(rk, k, 64);
memset(rc+8, 0, 56);
for(r=0; r<10; ++r){
#if SBOX_PROG
uint8_t i;
for(i=0; i<8; ++i){
rc[i] = whirlpool_sbox(r*8+i);
}
#else
memcpy_P(rc, sbox+r*8, 8);
#endif
w_round(rk, rc);
w_round(a, rk);
#if DEBUG

View File

@ -27,7 +27,6 @@ typedef struct {
uint32_t blocks;
} whirlpool_ctx_t;
uint8_t whirlpool_sbox(uint8_t a);
void whirlpool_init(whirlpool_ctx_t* ctx);
void whirlpool_nextBlock(whirlpool_ctx_t* ctx,const void* block);