if(f){
((hf_mem_fpt)f)(dest, msg, length_b);
}else{
-
uint16_t bs,bsb;
uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))];
f=(void_fpt)pgm_read_word(&(hash_descriptor->init));
/* allocate space on stack */
in r30, SPL
in r31, SPH
- in r1, SREG
+ in r0, SREG
subi r30, lo8(64)
sbci r31, hi8(64) /* ??? */
cli
out SPL, r30
+ out SREG, r0
out SPH, r31
- out SREG,r1
adiw r30, 1 /* SP points to next free byte on stack */
mov r18, r20 /* r20 = LSB(length) */
sha1_lastBlock_epilog:
in r30, SPL
in r31, SPH
- in r1, SREG
+ in r0, SREG
adiw r30, 63 ; lo8(64)
adiw r30, 1 ; hi8(64)
cli
out SPL, r30
+ out SREG, r0
out SPH, r31
- out SREG,r1
clr r1
- clr r0
ret
/**/
in r0, SREG
cli ; we want to be uninterrupted while updating SP
out SPL, r20
- out SPH, r21
out SREG, r0
+ out SPH, r21
push r18
push r19 /* push old SP on new stack */
in r0, SREG
cli ; we want to be uninterrupted while updating SP
out SPL, r20
- out SPH, r21
out SREG, r0
+ out SPH, r21
clr r1
pop r29
/* allocate space on stack */
in r30, SPL
in r31, SPH
- in r1, SREG
+ in r0, SREG
subi r30, lo8(64)
sbci r31, hi8(64)
cli
out SPL, r30
+ out SREG,r0
out SPH, r31
- out SREG,r1
adiw r30, 1 /* SP points to next free byte on stack */
mov r18, r20 /* r20 = LSB(length) */
sha256_lastBlock_epilog:
in r30, SPL
in r31, SPH
- in r1, SREG
+ in r0, SREG
adiw r30, 63 ; lo8(64)
adiw r30, 1 ; hi8(64)
cli
out SPL, r30
+ out SREG,r0
out SPH, r31
- out SREG,r1
clr r1
- clr r0
ret
/**/
in r0, SREG
cli ; we want to be uninterrupted while updating SP
out SPL, r20
- out SPH, r21
out SREG, r0
+ out SPH, r21
push r18
push r19
push r24
in r0, SREG
cli ; we want to be uninterrupted while updating SP
out SPL, r20
- out SPH, r21
out SREG, r0
-
+ out SPH, r21
clr r1
pop r29
pop r28
bitrotl_loop:
tst r20
breq fixrotl
+2:
rol r22
rol r23
rol r24
rol r25
rol r21
dec r20
- rjmp bitrotl_loop
+ brne 2b
fixrotl:
or r22, r21
ret
bitrotr_loop:
tst r20
breq fixrotr
+2:
ror r25
ror r24
ror r23
ror r22
ror r21
dec r20
- rjmp bitrotr_loop
+ brne 2b
fixrotr:
or r25, r21
ret
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_test3_str[] PROGMEM = "shavs_test3";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_blake},
{ shavs_list_str, NULL, shavs_listalgos},
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
{ shavs_test1_str, NULL, shavs_test1},
+ { shavs_test3_str, NULL, shavs_test3},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ NULL, NULL, NULL}
};
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_test3_str[] PROGMEM = "shavs_test3";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_bmw},
{ shavs_list_str, NULL, shavs_listalgos},
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
{ shavs_test1_str, NULL, shavs_test1},
+ { shavs_test3_str, NULL, shavs_test3},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ NULL, NULL, NULL}
};
cli_hexdump(hash, 32);
}
+void test_monte2(void){
+ uint8_t data[] = {
+ 0x6c, 0xd4, 0xc0, 0xc5, 0xcb, 0x2c, 0xa2, 0xa0,
+ 0xf1, 0xd1, 0xae, 0xce, 0xba, 0xc0, 0x3b, 0x52,
+ 0xe6, 0x4e, 0xa0, 0x3d, 0x1a, 0x16, 0x54, 0x37,
+ 0x29, 0x36, 0x54, 0x5b, 0x92, 0xbb, 0xc5, 0x48,
+ 0x4a, 0x59, 0xdb, 0x74, 0xbb, 0x60, 0xf9, 0xc4,
+ 0x0c, 0xeb, 0x1a, 0x5a, 0xa3, 0x5a, 0x6f, 0xaf,
+ 0xe8, 0x03, 0x49, 0xe1, 0x4c, 0x25, 0x3a, 0x4e,
+ 0x8b, 0x1d, 0x77, 0x61, 0x2d, 0xdd, 0x81, 0xac,
+ 0xe9, 0x26, 0xae, 0x8b, 0x0a, 0xf6, 0xe5, 0x31,
+ 0x76, 0xdb, 0xff, 0xcc, 0x2a, 0x6b, 0x88, 0xc6,
+ 0xbd, 0x76, 0x5f, 0x93, 0x9d, 0x3d, 0x17, 0x8a,
+ 0x9b, 0xde, 0x9e, 0xf3, 0xaa, 0x13, 0x1c, 0x61,
+ 0xe3, 0x1c, 0x1e, 0x42, 0xcd, 0xfa, 0xf4, 0xb4,
+ 0xdc, 0xde, 0x57, 0x9a, 0x37, 0xe1, 0x50, 0xef,
+ 0xbe, 0xf5, 0x55, 0x5b, 0x4c, 0x1c, 0xb4, 0x04,
+ 0x39, 0xd8, 0x35, 0xa7, 0x24, 0xe2, 0xfa, 0xe7 };
+
+ uint8_t hash[SHA256_HASH_BYTES];
+ sha256(hash, data, 1024);
+ cli_putstr_P(PSTR("\r\n hash(data) = "));
+ cli_hexdump(hash, 32);
+}
+
/*****************************************************************************
* main *
*****************************************************************************/
const char nessie_str[] PROGMEM = "nessie";
const char test_str[] PROGMEM = "test";
const char monte_str[] PROGMEM = "monte";
+const char monte2_str[] PROGMEM = "monte2";
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_sha256},
{ test_str, NULL, testrun_nessie_sha256},
{ monte_str, NULL, test_monte},
+ { monte2_str, NULL, test_monte2},
{ performance_str, NULL, testrun_performance_sha256},
{ 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}
};
*/
/*
* skein test-suit
- *
+ *
*/
#include "config.h"
(hfdesc_t*)&skein256_256_desc,
(hfdesc_t*)&skein256_384_desc,
(hfdesc_t*)&skein256_512_desc,
-
+
(hfdesc_t*)&skein512_128_desc,
(hfdesc_t*)&skein512_160_desc,
(hfdesc_t*)&skein512_224_desc,
(hfdesc_t*)&skein512_384_desc,
(hfdesc_t*)&skein512_512_desc,
(hfdesc_t*)&skein512_1024_desc,
-
+
(hfdesc_t*)&skein1024_128_desc,
(hfdesc_t*)&skein1024_160_desc,
(hfdesc_t*)&skein1024_224_desc,
uint8_t message[64];
uint8_t hash[(outsize_b+7)/8];
uint8_t i;
-
+
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
for(i=0; i<64; ++i)
message[i] = 0xFF-i;
-
+
cli_putstr_P(PSTR("\r\nmessage: "));
cli_hexdump(message, 1);
skein256(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 32, 4, 16);
skein256(hash, outsize_b, message, 32*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 64, 4, 16);
skein256(hash, outsize_b, message, 64*8);
uint8_t message[128];
uint8_t hash[(outsize_b+7)/8];
uint8_t i;
-
+
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
for(i=0; i<128; ++i)
message[i] = 0xFF-i;
-
+
cli_putstr_P(PSTR("\r\nmessage: "));
cli_hexdump(message, 1);
skein512(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 64, 4, 16);
skein512(hash, outsize_b, message, 64*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 128, 4, 16);
skein512(hash, outsize_b, message, 128*8);
uint8_t message[256];
uint8_t hash[(outsize_b+7)/8];
uint16_t i;
-
+
cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
for(i=0; i<256; ++i)
message[i] = 0xFF-i;
-
+
cli_putstr_P(PSTR("\r\nmessage: "));
cli_hexdump(message, 1);
skein1024(hash, outsize_b, message, 8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 128, 4, 16);
skein1024(hash, outsize_b, message, 128*8);
cli_putstr_P(PSTR("\r\nhash:"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
cli_putstr_P(PSTR("\r\nmessage:"));
cli_hexdump_block(message, 256, 4, 16);
skein1024(hash, outsize_b, message, 256*8);
void zeromsg_test_skein(uint16_t outsize_b){
char str[8];
uint8_t hash[(outsize_b+7)/8];
-
+
skein256(hash, outsize_b, NULL, 0);
cli_putstr_P(PSTR("\r\nskein256-"));
utoa(outsize_b, str, 10);
cli_putstr(str);
cli_putstr_P(PSTR(" :"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
skein512(hash, outsize_b, NULL, 0);
cli_putstr_P(PSTR("\r\nskein512-"));
utoa(outsize_b, str, 10);
cli_putstr(str);
cli_putstr_P(PSTR(" :"));
cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
-
+
skein1024(hash, outsize_b, NULL, 0);
cli_putstr_P(PSTR("\r\nskein1024-"));
utoa(outsize_b, str, 10);
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";
cmdlist_entry_t cmdlist[] PROGMEM = {
{ nessie_str, NULL, testrun_nessie_skein},
{ 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},
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
{ NULL, NULL, NULL}
};
int main (void){
DEBUG_INIT();
-
+
cli_rx = (cli_rx_fpt)uart0_getc;
- cli_tx = (cli_tx_fpt)uart0_putc;
+ cli_tx = (cli_tx_fpt)uart0_putc;
shavs_algolist=(hfdesc_t**)algolist;
shavs_algo=(hfdesc_t*)&skein256_256_desc;
for(;;){
cli_putstr_P(PSTR(" "));
cli_putstr(__TIME__);
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
-
+
cmd_interface(cmdlist);
}
}
}
}
-void shavs_test2(void){ /* MonteCarlo - tests */
+void shavs_test2(void){ /* Monte Carlo tests for SHA-1 & SHA-2 */
uint16_t expected_input;
uint16_t count;
uint8_t v;
return;
}
}
- cli_putstr_P(PSTR("\r\n reading seed ml=0x"));
- cli_hexdump_rev(&ml, 1);
expected_input = ml*2;
memset(m+2*ml, 0, ml);
do{
memmove(m, m+ml, 3*ml);
}
cli_putstr_P(PSTR("\r\n\r\nCOUNT = "));
- if(count>10){
+ if(count>=10){
cli_putc(count/10+'0');
}
cli_putc(count%10+'0');
}
}
}
+
+void shavs_test3(void){ /* Monte Carlo tests for SHA-3 */
+ uint16_t expected_input;
+ uint16_t count;
+ uint8_t v;
+ uint8_t index=0;
+ char c;
+ if(!shavs_algo){
+ cli_putstr_P(PSTR("\r\nERROR: select algorithm first!"));
+ return;
+ }
+ uint8_t ml=pgm_read_word(&(shavs_algo->hashsize_b))/8;
+ uint8_t m[ml+128];
+ for(;;){
+ while((c=cli_getc_cecho())!='S' && c!='s'){
+ if(!isblank(c)){
+ cli_putstr_P(PSTR("\r\nERROR: wrong input (1) [0x"));
+ cli_hexdump(&c, 1);
+ cli_putstr_P(PSTR("]!\r\n"));
+ return;
+ }
+ }
+ if((c=cli_getc_cecho())!='e' && c!='e'){
+ cli_putstr_P(PSTR("\r\nERROR: wrong input (2)!\r\n"));
+ return;
+ }
+ if((c=cli_getc_cecho())!='e' && c!='e'){
+ cli_putstr_P(PSTR("\r\nERROR: wrong input (3)!\r\n"));
+ return;
+ }
+ if((c=cli_getc_cecho())!='d' && c!='D'){
+ cli_putstr_P(PSTR("\r\nERROR: wrong input (4)!\r\n"));
+ return;
+ }
+ while((c=cli_getc_cecho())!='='){
+ if(!isblank(c)){
+ cli_putstr_P(PSTR("\r\nERROR: wrong input (5)!\r\n"));
+ return;
+ }
+ }
+ expected_input = 1024/4;
+ memset(m+ml, 0, 1024/8);
+ do{
+ v=0xff;
+ c=cli_getc_cecho();
+ if(c>='0' && c<='9'){
+ v = c - '0';
+ }else{
+ c |= 'A'^'a';
+ if(c>='a' && c<='f'){
+ v = c - 'a' +10;
+ }
+ }
+ if(v<0x10){
+ c=m[ml+index/2];
+ if(index&1){
+ c |= v;
+ }else{
+ c |=v<<4;
+ }
+ m[ml+index/2]=c;
+ index++;
+ expected_input--;
+ }
+ }while(expected_input);
+ /* so we have the seed */
+ cli_putstr_P(PSTR("\r\nstarting processing"));
+ uint16_t j;
+ for(count=0; count<100; ++count){
+ for(j=0; j<1000; ++j){
+ hfal_hash_mem(shavs_algo, m, m+ml, 1024);
+ memmove(m+ml, m, 1024/8);
+ }
+ cli_putstr_P(PSTR("\r\n\r\nj = "));
+ if(count>=10){
+ cli_putc(count/10+'0');
+ }
+ cli_putc(count%10+'0');
+ cli_putstr_P(PSTR("\r\nMD = "));
+ cli_hexdump(m+ml, ml);
+
+ }
+ }
+}
void shavs_setalgo(char* param);
void shavs_test1(void);
void shavs_test2(void);
+void shavs_test3(void);
#endif /* SHAVS */
--- /dev/null
+
+[Skein-256-224]
+algo=a
+file_0=testvectors/shavs/Skein/ShortMsgKAT_224.txt
+file_1=testvectors/shavs/Skein/LongMsgKAT_224.txt
+
+[Skein-256-256]
+algo=b
+file_0=testvectors/shavs/Skein/ShortMsgKAT_256.txt
+file_1=testvectors/shavs/Skein/LongMsgKAT_256.txt
+
+[Skein-512-384]
+algo=c
+file_0=testvectors/shavs/Skein/ShortMsgKAT_384.txt
+file_1=testvectors/shavs/Skein/LongMsgKAT_384.txt
+
+[Skein-512-512]
+algo=d
+file_0=testvectors/shavs/Blake/ShortMsgKAT_512.txt
+file_1=testvectors/shavs/Blake/LongMsgKAT_512.txt
+
+