some tunes at the Makefile + code reorganisation at the nessie test banches
This commit is contained in:
parent
158bb85c89
commit
d4b9cfc34c
48
Makefile
48
Makefile
|
@ -25,10 +25,6 @@ ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS))
|
|||
|
||||
PRG = remove_me
|
||||
|
||||
#Multi_OBJ = main.o debug.o uart.o serial-tools.o sha256-asm.o xtea-asm.o arcfour-asm.o prng.o cast5.o
|
||||
|
||||
#OBJ = $(SERPENT_OBJ)
|
||||
|
||||
DEFS =
|
||||
LIBS =
|
||||
|
||||
|
@ -67,17 +63,53 @@ info:
|
|||
# echo $(ALGORITHMS_NESSIE_TEST)
|
||||
# echo $(ALGORITHMS_PERFORMANCE_TEST)
|
||||
|
||||
bc: $(ALGORITHMS_OBJ)
|
||||
%.o: %.c
|
||||
@echo "[gcc]: $@"
|
||||
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
%.o: %.S
|
||||
@echo "[as] : $@"
|
||||
@$(CC) $(ASFLAGS) -c -o $@ $<
|
||||
|
||||
|
||||
.PHONY: cores
|
||||
cores: $(ALGORITHMS_OBJ)
|
||||
|
||||
.PHONY: blockciphers
|
||||
blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
|
||||
|
||||
.PHONY: streamciphers
|
||||
streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
|
||||
|
||||
.PHONY: hashes
|
||||
hashes: $(patsubst %, %_OBJ, $(HASHES))
|
||||
|
||||
.PHONY: macs
|
||||
macs: $(patsubst %, %_OBJ, $(MACS))
|
||||
|
||||
prngs: $(patsubst %, %_OBJ, $(PRNGS))
|
||||
|
||||
tests: $(ALGORITHMS_TEST_BIN) \
|
||||
$(ALGORITHMS_TEST_BIN_MAIN_ELF) \
|
||||
$(ALGORITHMS_TEST_BIN_MAIN_HEX)
|
||||
|
||||
|
||||
$(ALGORITHMS_OBJ): $(ALGORITHMS_OBJ_IMM)
|
||||
$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM)
|
||||
define OBJ_TEMPLATE
|
||||
$(1)_OBJ: $(2)
|
||||
# @echo " ALGO: $(1)"
|
||||
# @echo " REQ: $(2)"
|
||||
endef
|
||||
|
||||
#$(ALGORITHMS):
|
||||
$(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ))))
|
||||
|
||||
|
||||
$(BLOCK_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(BLOCK_CIPHERS))
|
||||
$(STREAM_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(STREAM_CIPHERS))
|
||||
$(HASHES_OBJ): $(patsubst %,%_OBJ, $(HASHES))
|
||||
$(PRNGS_OBJ): $(patsubst %,%_OBJ, $(PRNGS))
|
||||
$(MACS_OBJ): $(patsubst %,%_OBJ, $(MACS))
|
||||
|
||||
$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM)
|
||||
|
||||
.PHONY: all
|
||||
all: $(PRG).elf lst text eeprom
|
||||
|
|
|
@ -6,7 +6,7 @@ STREAM_CIPHERS += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := arcfour-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o debug.o uart.o serial-tools.o \
|
||||
nessie_stream_test.o arcfour-asm.o
|
||||
nessie_stream_test.o nessie_common.o arcfour-asm.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
2
cast5.mk
2
cast5.mk
|
@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := cast5.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o \
|
||||
cast5.o nessie_bc_test.o
|
||||
cast5.o nessie_bc_test.o nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ MACS += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := hmac-sha256.o sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-hmac-sha256-test.o debug.o uart.o serial-tools.o \
|
||||
hmac-sha256.o sha256-asm.o nessie_mac_test.o
|
||||
hmac-sha256.o sha256-asm.o nessie_mac_test.o nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
181
nessie_bc_test.c
181
nessie_bc_test.c
|
@ -10,89 +10,38 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nessie_bc_test.h"
|
||||
#include "nessie_common.h"
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
|
||||
nessie_bc_ctx_t nessie_bc_ctx;
|
||||
|
||||
static void printblock(uint8_t* block, uint16_t blocksize_bit){
|
||||
char tab [] = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
uint16_t i;
|
||||
for(i=0; i<(blocksize_bit+7)/8; ++i){
|
||||
uart_putc(tab[(block[i])>>4]);
|
||||
uart_putc(tab[(block[i])&0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
#define SPACES 31
|
||||
#define BYTESPERLINE 16
|
||||
|
||||
static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
|
||||
uint8_t name_len;
|
||||
uint8_t i;
|
||||
name_len=strlen(name);
|
||||
if(name_len>SPACES-1){
|
||||
uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
|
||||
return;
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES-name_len-1; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
uart_putstr(name);
|
||||
uart_putc('=');
|
||||
/* now the data printing begins */
|
||||
if(size_B<=BYTESPERLINE){
|
||||
/* one line seems sufficient */
|
||||
printblock(buffer, size_B*8);
|
||||
} else {
|
||||
/* we need more lines */
|
||||
printblock(buffer, BYTESPERLINE*8); /* first line */
|
||||
int16_t toprint = size_B - BYTESPERLINE;
|
||||
buffer += BYTESPERLINE;
|
||||
while(toprint > 0){
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
|
||||
buffer += BYTESPERLINE;
|
||||
toprint -= BYTESPERLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nessie_bc_enc(uint8_t* key, uint8_t* pt){
|
||||
uint8_t ctx[nessie_bc_ctx.ctx_size_B];
|
||||
uint8_t buffer[nessie_bc_ctx.blocksize_B];
|
||||
uint16_t i;
|
||||
|
||||
/* single test */
|
||||
printitem("key", key, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
|
||||
memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
|
||||
printitem("plain", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_ctx.cipher_enc(buffer, ctx);
|
||||
printitem("cipher", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_ctx.cipher_dec(buffer, ctx);
|
||||
printitem("decrypted", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
|
||||
|
||||
/* 100 times test */
|
||||
memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
|
||||
for(i=0; i<100; ++i){
|
||||
nessie_bc_ctx.cipher_enc(buffer, ctx);
|
||||
}
|
||||
printitem("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
|
||||
#ifndef NESSIE_NO1KTEST
|
||||
/* 1000 times test, we use the 100 precedig steps to fasten things a bit */
|
||||
for(; i<1000; ++i){
|
||||
nessie_bc_ctx.cipher_enc(buffer, ctx);
|
||||
}
|
||||
printitem("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -101,96 +50,30 @@ void nessie_bc_dec(uint8_t* key, uint8_t* ct){
|
|||
uint8_t buffer[nessie_bc_ctx.blocksize_B];
|
||||
|
||||
/* single test */
|
||||
printitem("key", key, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
|
||||
memcpy(buffer, ct, nessie_bc_ctx.blocksize_B);
|
||||
printitem("cipher", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_ctx.cipher_dec(buffer, ctx);
|
||||
printitem("plain", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_ctx.cipher_enc(buffer, ctx);
|
||||
printitem("encrypted", buffer, nessie_bc_ctx.blocksize_B);
|
||||
nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B);
|
||||
|
||||
}
|
||||
|
||||
static void print_set_vector(uint8_t set, uint16_t vector){
|
||||
uart_putstr_P(PSTR("\r\n\r\nSet "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR(", vector#"));
|
||||
uart_putc((vector<100)?' ':'0'+vector/100);
|
||||
uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
|
||||
uart_putc('0'+vector%10);
|
||||
uart_putc(':');
|
||||
}
|
||||
|
||||
/* example:
|
||||
Test vectors -- set 3
|
||||
=====================
|
||||
*/
|
||||
static void print_setheader(uint8_t set){
|
||||
uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR("\r\n====================="));
|
||||
}
|
||||
|
||||
/* example:
|
||||
********************************************************************************
|
||||
*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
|
||||
********************************************************************************
|
||||
|
||||
Primitive Name: Serpent
|
||||
=======================
|
||||
Key size: 256 bits
|
||||
Block size: 128 bits
|
||||
*/
|
||||
|
||||
static void print_header(void){
|
||||
uint16_t i;
|
||||
uart_putstr_P(PSTR("\r\n\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"\r\n"));
|
||||
uart_putstr_P(PSTR("Primitive Name: "));
|
||||
uart_putstr(nessie_bc_ctx.name);
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<16+strlen(nessie_bc_ctx.name); ++i){
|
||||
uart_putc('=');
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\nKey size: "));
|
||||
if(nessie_bc_ctx.keysize_b>100){
|
||||
uart_putc('0'+nessie_bc_ctx.keysize_b/100);
|
||||
}
|
||||
if(nessie_bc_ctx.keysize_b>10){
|
||||
uart_putc('0'+(nessie_bc_ctx.keysize_b/10)%10);
|
||||
}
|
||||
uart_putc('0'+nessie_bc_ctx.keysize_b%10);
|
||||
uart_putstr_P(PSTR(" bits\r\nBlock size: "));
|
||||
if(nessie_bc_ctx.blocksize_B*8>100){
|
||||
uart_putc('0'+(nessie_bc_ctx.blocksize_B*8)/100);
|
||||
}
|
||||
if(nessie_bc_ctx.blocksize_B*8>10){
|
||||
uart_putc('0'+((nessie_bc_ctx.blocksize_B*8)/10)%10);
|
||||
}
|
||||
uart_putc('0'+(nessie_bc_ctx.blocksize_B*8)%10);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
|
||||
static void print_footer(void){
|
||||
uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
|
||||
}
|
||||
|
||||
void nessie_bc_run(void){
|
||||
uint16_t i;
|
||||
uint8_t set;
|
||||
uint8_t key[(nessie_bc_ctx.keysize_b+7)/8];
|
||||
uint8_t buffer[nessie_bc_ctx.blocksize_B];
|
||||
|
||||
print_header();
|
||||
nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b,
|
||||
nessie_bc_ctx.blocksize_B*8, 0, 0, 0);
|
||||
/* test set 1 */
|
||||
set=1;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
key[i/8] |= 0x80>>(i%8);
|
||||
memset(buffer, 0, nessie_bc_ctx.blocksize_B);
|
||||
|
@ -198,9 +81,9 @@ void nessie_bc_run(void){
|
|||
}
|
||||
/* test set 2 */
|
||||
set=2;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
memset(buffer, 0, nessie_bc_ctx.blocksize_B);
|
||||
buffer[i/8] |= 0x80>>(i%8);
|
||||
|
@ -208,18 +91,18 @@ void nessie_bc_run(void){
|
|||
}
|
||||
/* test set 3 */
|
||||
set=3;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<256; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
memset(buffer, i, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_enc(key, buffer);
|
||||
}
|
||||
/* test set 4 */
|
||||
set=4;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
/* 4 - 0*/
|
||||
print_set_vector(set, 0);
|
||||
nessie_print_set_vector(set, 0);
|
||||
for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
|
||||
key[i]=i;
|
||||
}
|
||||
|
@ -228,7 +111,7 @@ void nessie_bc_run(void){
|
|||
}
|
||||
nessie_bc_enc(key, buffer);
|
||||
/* 4 - 1 */
|
||||
print_set_vector(set, 1);
|
||||
nessie_print_set_vector(set, 1);
|
||||
/* This is the test vectors in Kasumi */
|
||||
static uint8_t kasumi_key[] = {
|
||||
0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
|
||||
|
@ -245,9 +128,9 @@ void nessie_bc_run(void){
|
|||
/* half done ;-) */
|
||||
/* test set 5 */
|
||||
set=5;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
key[i/8] |= 0x80>>(i%8);
|
||||
memset(buffer, 0, nessie_bc_ctx.blocksize_B);
|
||||
|
@ -255,9 +138,9 @@ void nessie_bc_run(void){
|
|||
}
|
||||
/* test set 6 */
|
||||
set=6;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
memset(buffer, 0, nessie_bc_ctx.blocksize_B);
|
||||
buffer[i/8] |= 0x80>>(i%8);
|
||||
|
@ -265,18 +148,18 @@ void nessie_bc_run(void){
|
|||
}
|
||||
/* test set 7 */
|
||||
set=7;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<256; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
|
||||
memset(buffer, i, nessie_bc_ctx.blocksize_B);
|
||||
nessie_bc_dec(key, buffer);
|
||||
}
|
||||
/* test set 8 */
|
||||
set=8;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
/* 8 - 0*/
|
||||
print_set_vector(set, 0);
|
||||
nessie_print_set_vector(set, 0);
|
||||
for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
|
||||
key[i]=i;
|
||||
}
|
||||
|
@ -285,7 +168,7 @@ void nessie_bc_run(void){
|
|||
}
|
||||
nessie_bc_dec(key, buffer);
|
||||
/* 8 - 1 */
|
||||
print_set_vector(set, 1);
|
||||
nessie_print_set_vector(set, 1);
|
||||
for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
|
||||
key[i]=kasumi_key[i%sizeof(kasumi_key)];
|
||||
}
|
||||
|
@ -293,5 +176,5 @@ void nessie_bc_run(void){
|
|||
buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
|
||||
}
|
||||
nessie_bc_dec(key, buffer);
|
||||
print_footer();
|
||||
nessie_print_footer();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
*
|
||||
* author: Daniel Otte
|
||||
* email: daniel.otte@rub.de
|
||||
* license: GPLv3
|
||||
*
|
||||
* common function for nessie-tests
|
||||
*
|
||||
* */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdlib.h> /* utoa() */
|
||||
#include "uart.h"
|
||||
|
||||
void nessie_print_block(uint8_t* block, uint16_t blocksize_bit){
|
||||
char tab [] = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
uint16_t i;
|
||||
for(i=0; i<(blocksize_bit+7)/8; ++i){
|
||||
uart_putc(tab[(block[i])>>4]);
|
||||
uart_putc(tab[(block[i])&0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
#define SPACES 31
|
||||
#define BYTESPERLINE 16
|
||||
|
||||
void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
|
||||
uint8_t name_len;
|
||||
uint8_t i;
|
||||
name_len=strlen(name);
|
||||
if(name_len>SPACES-1){
|
||||
uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
|
||||
return;
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES-name_len-1; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
uart_putstr(name);
|
||||
uart_putc('=');
|
||||
/* now the data printing begins */
|
||||
if(size_B<=BYTESPERLINE){
|
||||
/* one line seems sufficient */
|
||||
nessie_print_block(buffer, size_B*8);
|
||||
} else {
|
||||
/* we need more lines */
|
||||
nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
|
||||
int16_t toprint = size_B - BYTESPERLINE;
|
||||
buffer += BYTESPERLINE;
|
||||
while(toprint > 0){
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
|
||||
buffer += BYTESPERLINE;
|
||||
toprint -= BYTESPERLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nessie_print_set_vector(uint8_t set, uint16_t vector){
|
||||
uart_putstr_P(PSTR("\r\n\r\nSet "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR(", vector#"));
|
||||
uart_putc((vector<100)?' ':'0'+vector/100);
|
||||
uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
|
||||
uart_putc('0'+vector%10);
|
||||
uart_putc(':');
|
||||
}
|
||||
|
||||
/* example:
|
||||
Test vectors -- set 3
|
||||
=====================
|
||||
*/
|
||||
void nessie_print_setheader(uint8_t set){
|
||||
uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR("\r\n====================="));
|
||||
}
|
||||
|
||||
/* example:
|
||||
********************************************************************************
|
||||
*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
|
||||
********************************************************************************
|
||||
|
||||
Primitive Name: Serpent
|
||||
=======================
|
||||
Key size: 256 bits
|
||||
Block size: 128 bits
|
||||
*/
|
||||
|
||||
void nessie_print_header(char* name,
|
||||
uint16_t keysize_b,
|
||||
uint16_t blocksize_b,
|
||||
uint16_t hashsize_b,
|
||||
uint16_t macsize_b,
|
||||
uint16_t ivsize_b ){
|
||||
uint16_t i;
|
||||
uart_putstr_P(PSTR("\r\n\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"\r\n"));
|
||||
uart_putstr_P(PSTR("Primitive Name: "));
|
||||
uart_putstr(name);
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
/* underline */
|
||||
for(i=0; i<16+strlen(name); ++i){
|
||||
uart_putc('=');
|
||||
}
|
||||
char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
|
||||
if(keysize_b){
|
||||
uart_putstr_P(PSTR("\r\nKey size: "));
|
||||
utoa(keysize_b, str, 10);
|
||||
uart_putstr(str);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
if(blocksize_b){
|
||||
uart_putstr_P(PSTR("\r\nBlock size: "));
|
||||
utoa(blocksize_b, str, 10);
|
||||
uart_putstr(str);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
if(hashsize_b){
|
||||
uart_putstr_P(PSTR("\r\nHash size: "));
|
||||
utoa(hashsize_b, str, 10);
|
||||
uart_putstr(str);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
if(macsize_b){
|
||||
uart_putstr_P(PSTR("\r\nMac size: "));
|
||||
utoa(macsize_b, str, 10);
|
||||
uart_putstr(str);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
if(ivsize_b){
|
||||
uart_putstr_P(PSTR("\r\nIV size: "));
|
||||
utoa(ivsize_b, str, 10);
|
||||
uart_putstr(str);
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
uart_putstr_P(PSTR(" bits"));
|
||||
}
|
||||
|
||||
void nessie_print_footer(void){
|
||||
uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
* author: Daniel Otte
|
||||
* email: daniel.otte@rub.de
|
||||
* license: GPLv3
|
||||
*
|
||||
* common function for nessie-tests
|
||||
*
|
||||
* */
|
||||
|
||||
#ifndef NESSIE_COMMON_H_
|
||||
#define NESSIE_COMMON_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void nessie_print_block(uint8_t* block, uint16_t blocksize_bit);
|
||||
void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B);
|
||||
void nessie_print_set_vector(uint8_t set, uint16_t vector);
|
||||
void nessie_print_setheader(uint8_t set);
|
||||
void nessie_print_header(char* name,
|
||||
uint16_t keysize_b,
|
||||
uint16_t blocksize_b,
|
||||
uint16_t hashsize_b,
|
||||
uint16_t macsize_b,
|
||||
uint16_t ivsize_b );
|
||||
void nessie_print_footer(void);
|
||||
|
||||
#endif /*NESSIE_COMMON_H_*/
|
|
@ -10,119 +10,11 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nessie_hash_test.h"
|
||||
#include "nessie_common.h"
|
||||
#include "uart.h"
|
||||
|
||||
nessie_hash_ctx_t nessie_hash_ctx;
|
||||
|
||||
static void printblock(uint8_t* block, uint16_t blocksize_bit){
|
||||
char tab [] = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
uint16_t i;
|
||||
for(i=0; i<(blocksize_bit+7)/8; ++i){
|
||||
uart_putc(tab[(block[i])>>4]);
|
||||
uart_putc(tab[(block[i])&0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
#define SPACES 31
|
||||
#define BYTESPERLINE 16
|
||||
|
||||
static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
|
||||
uint8_t name_len;
|
||||
uint8_t i;
|
||||
name_len=strlen(name);
|
||||
if(name_len>SPACES-1){
|
||||
uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
|
||||
return;
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES-name_len-1; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
uart_putstr(name);
|
||||
uart_putc('=');
|
||||
/* now the data printing begins */
|
||||
if(size_B<=BYTESPERLINE){
|
||||
/* one line seems sufficient */
|
||||
printblock(buffer, size_B*8);
|
||||
} else {
|
||||
/* we need more lines */
|
||||
printblock(buffer, BYTESPERLINE*8); /* first line */
|
||||
int16_t toprint = size_B - BYTESPERLINE;
|
||||
buffer += BYTESPERLINE;
|
||||
while(toprint > 0){
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
|
||||
buffer += BYTESPERLINE;
|
||||
toprint -= BYTESPERLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void print_set_vector(uint8_t set, uint16_t vector){
|
||||
uart_putstr_P(PSTR("\r\n\r\nSet "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR(", vector#"));
|
||||
uart_putc((vector<100)?' ':'0'+vector/100);
|
||||
uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
|
||||
uart_putc('0'+vector%10);
|
||||
uart_putc(':');
|
||||
}
|
||||
|
||||
/* example:
|
||||
Test vectors -- set 3
|
||||
=====================
|
||||
*/
|
||||
static void print_setheader(uint8_t set){
|
||||
uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR("\r\n====================="));
|
||||
}
|
||||
|
||||
/* example:
|
||||
********************************************************************************
|
||||
*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
|
||||
********************************************************************************
|
||||
|
||||
Primitive Name: Serpent
|
||||
=======================
|
||||
Key size: 256 bits
|
||||
Block size: 128 bits
|
||||
*/
|
||||
|
||||
static void print_header(void){
|
||||
uint16_t i;
|
||||
uart_putstr_P(PSTR("\r\n\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"\r\n"));
|
||||
uart_putstr_P(PSTR("Primitive Name: "));
|
||||
uart_putstr(nessie_hash_ctx.name);
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<16+strlen(nessie_hash_ctx.name); ++i){
|
||||
uart_putc('=');
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\nHash size: "));
|
||||
if(nessie_hash_ctx.hashsize_b >100){
|
||||
uart_putc('0'+nessie_hash_ctx.hashsize_b/100);
|
||||
}
|
||||
if(nessie_hash_ctx.hashsize_b>10){
|
||||
uart_putc('0'+(nessie_hash_ctx.hashsize_b/10)%10);
|
||||
}
|
||||
uart_putc('0'+nessie_hash_ctx.hashsize_b%10);
|
||||
uart_putstr_P(PSTR(" bits\r\n"));
|
||||
}
|
||||
|
||||
static void print_footer(void){
|
||||
uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
|
||||
}
|
||||
|
||||
static
|
||||
void ascii_hash(char* data, char* desc){
|
||||
uint8_t ctx[nessie_hash_ctx.ctx_size_B];
|
||||
|
@ -140,7 +32,7 @@ void ascii_hash(char* data, char* desc){
|
|||
}
|
||||
nessie_hash_ctx.hash_last(data, sl*8, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
}
|
||||
|
||||
// message=1 million times "a"
|
||||
|
@ -162,7 +54,7 @@ void amillion_hash(void){
|
|||
}
|
||||
nessie_hash_ctx.hash_last(block, n*8, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
}
|
||||
|
||||
|
||||
|
@ -192,7 +84,7 @@ void zero_hash(uint16_t n){
|
|||
}
|
||||
nessie_hash_ctx.hash_last(block, n, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -234,7 +126,7 @@ void one_in512_hash(uint16_t pos){
|
|||
}
|
||||
nessie_hash_ctx.hash_last(block, n, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -256,13 +148,13 @@ void tv4_hash(void){
|
|||
}
|
||||
nessie_hash_ctx.hash_last(block, n, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
printitem("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */
|
||||
nessie_hash_ctx.hash_init(ctx);
|
||||
nessie_hash_ctx.hash_last(hash, nessie_hash_ctx.hashsize_b, ctx);
|
||||
nessie_hash_ctx.hash_conv(hash, ctx);
|
||||
}
|
||||
printitem("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -281,7 +173,7 @@ void nessie_hash_run(void){
|
|||
uint16_t i;
|
||||
uint8_t set;
|
||||
|
||||
print_header();
|
||||
nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0);
|
||||
/* test set 1 */
|
||||
char* challange[8][2]= {
|
||||
{"", "\"\" (empty string)"},
|
||||
|
@ -299,32 +191,32 @@ void nessie_hash_run(void){
|
|||
"8 times \"1234567890\""}
|
||||
};
|
||||
set=1;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<8; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
ascii_hash(challange[i][0], challange[i][1]);
|
||||
}
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
amillion_hash();
|
||||
/* test set 2 */
|
||||
set=2;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<1024; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
zero_hash(i);
|
||||
}
|
||||
/* test set 3 */
|
||||
set=3;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<512; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
one_in512_hash(i);
|
||||
}
|
||||
/* test set 4 */
|
||||
set=4;
|
||||
print_setheader(set);
|
||||
print_set_vector(set, 0);
|
||||
nessie_print_setheader(set);
|
||||
nessie_print_set_vector(set, 0);
|
||||
tv4_hash();
|
||||
|
||||
print_footer();
|
||||
nessie_print_footer();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nessie_mac_test.h"
|
||||
#include "nessie_common.h"
|
||||
#include "uart.h"
|
||||
|
||||
nessie_mac_ctx_t nessie_mac_ctx;
|
||||
|
@ -17,117 +18,8 @@ nessie_mac_ctx_t nessie_mac_ctx;
|
|||
#define KEYSIZE_B ((nessie_mac_ctx.keysize_b+7)/8)
|
||||
#define MACSIZE_B ((nessie_mac_ctx.macsize_b+7)/8)
|
||||
|
||||
#define PRINTKEY printitem("key", key, KEYSIZE_B)
|
||||
#define PRINTMAC printitem("MAC", mac, MACSIZE_B)
|
||||
|
||||
static void printblock(uint8_t* block, uint16_t blocksize_bit){
|
||||
char tab [] = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
uint16_t i;
|
||||
for(i=0; i<(blocksize_bit+7)/8; ++i){
|
||||
uart_putc(tab[(block[i])>>4]);
|
||||
uart_putc(tab[(block[i])&0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
#define SPACES 31
|
||||
#define BYTESPERLINE 16
|
||||
|
||||
static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
|
||||
uint8_t name_len;
|
||||
uint8_t i;
|
||||
name_len=strlen(name);
|
||||
if(name_len>SPACES-1){
|
||||
uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
|
||||
return;
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES-name_len-1; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
uart_putstr(name);
|
||||
uart_putc('=');
|
||||
/* now the data printing begins */
|
||||
if(size_B<=BYTESPERLINE){
|
||||
/* one line seems sufficient */
|
||||
printblock(buffer, size_B*8);
|
||||
} else {
|
||||
/* we need more lines */
|
||||
printblock(buffer, BYTESPERLINE*8); /* first line */
|
||||
int16_t toprint = size_B - BYTESPERLINE;
|
||||
buffer += BYTESPERLINE;
|
||||
while(toprint > 0){
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
|
||||
buffer += BYTESPERLINE;
|
||||
toprint -= BYTESPERLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void print_set_vector(uint8_t set, uint16_t vector){
|
||||
uart_putstr_P(PSTR("\r\n\r\nSet "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR(", vector#"));
|
||||
uart_putc((vector<100)?' ':'0'+vector/100);
|
||||
uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
|
||||
uart_putc('0'+vector%10);
|
||||
uart_putc(':');
|
||||
}
|
||||
|
||||
/* example:
|
||||
Test vectors -- set 3
|
||||
=====================
|
||||
*/
|
||||
static void print_setheader(uint8_t set){
|
||||
uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR("\r\n====================="));
|
||||
}
|
||||
|
||||
/* example:
|
||||
********************************************************************************
|
||||
*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
|
||||
********************************************************************************
|
||||
|
||||
Primitive Name: Serpent
|
||||
=======================
|
||||
Key size: 256 bits
|
||||
Block size: 128 bits
|
||||
*/
|
||||
|
||||
static void print_header(void){
|
||||
uint16_t i;
|
||||
uart_putstr_P(PSTR("\r\n\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"\r\n"));
|
||||
uart_putstr_P(PSTR("Primitive Name: "));
|
||||
uart_putstr(nessie_mac_ctx.name);
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<16+strlen(nessie_mac_ctx.name); ++i){
|
||||
uart_putc('=');
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\nHash size: "));
|
||||
if(nessie_mac_ctx.macsize_b >100){
|
||||
uart_putc('0'+nessie_mac_ctx.macsize_b/100);
|
||||
}
|
||||
if(nessie_mac_ctx.macsize_b>10){
|
||||
uart_putc('0'+(nessie_mac_ctx.macsize_b/10)%10);
|
||||
}
|
||||
uart_putc('0'+nessie_mac_ctx.macsize_b%10);
|
||||
uart_putstr_P(PSTR(" bits\r\n"));
|
||||
}
|
||||
|
||||
static void print_footer(void){
|
||||
uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
|
||||
}
|
||||
#define PRINTKEY nessie_print_item("key", key, KEYSIZE_B)
|
||||
#define PRINTMAC nessie_print_item("MAC", mac, MACSIZE_B)
|
||||
|
||||
static
|
||||
void ascii_mac(char* data, char* desc, uint8_t* key){
|
||||
|
@ -273,7 +165,7 @@ void tv4_mac(uint8_t* key){
|
|||
nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx);
|
||||
nessie_mac_ctx.mac_conv(mac, ctx);
|
||||
}
|
||||
printitem("iterated 100000 times", mac, MACSIZE_B);
|
||||
nessie_print_item("iterated 100000 times", mac, MACSIZE_B);
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,7 +177,8 @@ void nessie_mac_run(void){
|
|||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
uint8_t key[KEYSIZE_B];
|
||||
|
||||
print_header();
|
||||
nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0,
|
||||
nessie_mac_ctx.macsize_b, 0);
|
||||
/* test set 1 */
|
||||
char* challange[10][2]= {
|
||||
{"", "\"\" (empty string)"},
|
||||
|
@ -305,55 +198,55 @@ void nessie_mac_run(void){
|
|||
{"Now is the time for it", "\"Now is the time for it\""}
|
||||
};
|
||||
set=1;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<KEYSIZE_B; ++i){
|
||||
key[i] = keyproto[i%sizeof(keyproto)];
|
||||
}
|
||||
for(i=0; i<10; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
ascii_mac(challange[i][0], challange[i][1], key);
|
||||
}
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
amillion_mac(key);
|
||||
for(i=0; i<KEYSIZE_B; ++i){
|
||||
key[i] = keyproto[16+i%8];
|
||||
}
|
||||
for(i=0; i<10; ++i){
|
||||
print_set_vector(set, 11+i);
|
||||
nessie_print_set_vector(set, 11+i);
|
||||
ascii_mac(challange[i][0], challange[i][1], key);
|
||||
}
|
||||
print_set_vector(set, 11+i);
|
||||
nessie_print_set_vector(set, 11+i);
|
||||
amillion_mac(key);
|
||||
/* test set 2 */
|
||||
set=2;
|
||||
for(i=0; i<KEYSIZE_B; ++i){
|
||||
key[i] = keyproto[i%sizeof(keyproto)];
|
||||
}
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<1024; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
zero_mac(i, key);
|
||||
}
|
||||
/* test set 3 */
|
||||
set=3;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
/* we use the same key as above */
|
||||
for(i=0; i<512; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
one_in512_mac(i, key);
|
||||
}
|
||||
/* test set 4 */
|
||||
set=4;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
/* we use the same key as above */
|
||||
print_set_vector(set, 0);
|
||||
nessie_print_set_vector(set, 0);
|
||||
tv4_mac(key);
|
||||
/* test set 5 */
|
||||
for(i=0; i<nessie_mac_ctx.keysize_b; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, KEYSIZE_B);
|
||||
key[i>>3]=0x80>>(i&0x7);
|
||||
ascii_mac("ABC", "\"ABC\"", key);
|
||||
}
|
||||
print_footer();
|
||||
nessie_print_footer();
|
||||
}
|
||||
|
|
|
@ -10,59 +10,13 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nessie_stream_test.h"
|
||||
#include "nessie_common.h"
|
||||
#include "uart.h"
|
||||
|
||||
nessie_stream_ctx_t nessie_stream_ctx;
|
||||
|
||||
static void printblock(uint8_t* block, uint16_t blocksize_bit){
|
||||
char tab [] = {'0', '1', '2', '3',
|
||||
'4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B',
|
||||
'C', 'D', 'E', 'F'};
|
||||
uint16_t i;
|
||||
for(i=0; i<(blocksize_bit+7)/8; ++i){
|
||||
uart_putc(tab[(block[i])>>4]);
|
||||
uart_putc(tab[(block[i])&0xf]);
|
||||
}
|
||||
}
|
||||
|
||||
#define SPACES 31
|
||||
#define BYTESPERLINE 16
|
||||
|
||||
static void printitem(char* name, uint8_t* buffer, uint16_t size_B){
|
||||
uint8_t name_len;
|
||||
uint8_t i;
|
||||
name_len=strlen(name);
|
||||
if(name_len>SPACES-1){
|
||||
uart_putstr_P(PSTR("\r\n!!! formatting error !!!\r\n"));
|
||||
return;
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES-name_len-1; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
uart_putstr(name);
|
||||
uart_putc('=');
|
||||
/* now the data printing begins */
|
||||
if(size_B<=BYTESPERLINE){
|
||||
/* one line seems sufficient */
|
||||
printblock(buffer, size_B*8);
|
||||
} else {
|
||||
/* we need more lines */
|
||||
printblock(buffer, BYTESPERLINE*8); /* first line */
|
||||
int16_t toprint = size_B - BYTESPERLINE;
|
||||
buffer += BYTESPERLINE;
|
||||
while(toprint > 0){
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<SPACES; ++i){
|
||||
uart_putc(' ');
|
||||
}
|
||||
printblock(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
|
||||
buffer += BYTESPERLINE;
|
||||
toprint -= BYTESPERLINE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#define BLOCKSIZE_B 64
|
||||
|
||||
static
|
||||
void memxor(void* dest, void* src, uint8_t length){
|
||||
|
@ -71,9 +25,8 @@ void memxor(void* dest, void* src, uint8_t length){
|
|||
dest = (uint8_t*)dest +1;
|
||||
src = (uint8_t*)src +1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define BLOCKSIZE_B 64
|
||||
|
||||
static
|
||||
void nessie_gen_block(void* ctx, uint8_t* block){
|
||||
|
@ -92,13 +45,13 @@ void nessie_stream_enc(uint8_t* key){
|
|||
|
||||
memset(xorbuffer, 0, BLOCKSIZE_B);
|
||||
|
||||
printitem("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
|
||||
nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
|
||||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[0..63]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
|
||||
|
||||
for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
|
||||
nessie_gen_block(ctx, buffer);
|
||||
|
@ -107,11 +60,11 @@ void nessie_stream_enc(uint8_t* key){
|
|||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[192..255]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
|
||||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[256..319]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
|
||||
|
||||
for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
|
||||
nessie_gen_block(ctx, buffer);
|
||||
|
@ -120,9 +73,9 @@ void nessie_stream_enc(uint8_t* key){
|
|||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[448..511]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
|
||||
|
||||
printitem("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
|
||||
|
||||
}
|
||||
|
||||
|
@ -136,13 +89,13 @@ void nessie_stream_enc_large(uint8_t* key){
|
|||
|
||||
memset(xorbuffer, 0, BLOCKSIZE_B);
|
||||
|
||||
printitem("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
|
||||
nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
|
||||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[0..63]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
|
||||
|
||||
for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
|
||||
nessie_gen_block(ctx, buffer);
|
||||
|
@ -151,11 +104,11 @@ void nessie_stream_enc_large(uint8_t* key){
|
|||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[65472..65535]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
|
||||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[65536..65599]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
|
||||
|
||||
for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
|
||||
nessie_gen_block(ctx, buffer);
|
||||
|
@ -164,100 +117,42 @@ void nessie_stream_enc_large(uint8_t* key){
|
|||
|
||||
nessie_gen_block(ctx, buffer);
|
||||
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
||||
printitem("stream[131008..131071]", buffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
|
||||
|
||||
printitem("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
|
||||
nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
|
||||
|
||||
}
|
||||
|
||||
static void print_set_vector(uint8_t set, uint16_t vector){
|
||||
uart_putstr_P(PSTR("\r\n\r\nSet "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR(", vector#"));
|
||||
uart_putc((vector<100)?' ':'0'+vector/100);
|
||||
uart_putc((vector<10 )?' ':'0'+(vector/10)%10);
|
||||
uart_putc('0'+vector%10);
|
||||
uart_putc(':');
|
||||
}
|
||||
|
||||
/* example:
|
||||
Test vectors -- set 3
|
||||
=====================
|
||||
*/
|
||||
static void print_setheader(uint8_t set){
|
||||
uart_putstr_P(PSTR("\r\n\r\nTest vectors -- set "));
|
||||
uart_putc('0'+set%10);
|
||||
uart_putstr_P(PSTR("\r\n====================="));
|
||||
}
|
||||
|
||||
/* example:
|
||||
********************************************************************************
|
||||
*Project NESSIE - New European Schemes for Signature, Integrity, and Encryption*
|
||||
********************************************************************************
|
||||
|
||||
Primitive Name: Serpent
|
||||
=======================
|
||||
Key size: 256 bits
|
||||
Block size: 128 bits
|
||||
*/
|
||||
|
||||
static void print_header(void){
|
||||
uint16_t i;
|
||||
uart_putstr_P(PSTR("\r\n\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"* micro-cryt - crypto primitives for microcontrolles by Daniel Otte *\r\n"
|
||||
"********************************************************************************\r\n"
|
||||
"\r\n"));
|
||||
uart_putstr_P(PSTR("Primitive Name: "));
|
||||
uart_putstr(nessie_stream_ctx.name);
|
||||
uart_putstr_P(PSTR("\r\n"));
|
||||
for(i=0; i<16+strlen(nessie_stream_ctx.name); ++i){
|
||||
uart_putc('=');
|
||||
}
|
||||
uart_putstr_P(PSTR("\r\nKey size: "));
|
||||
if(nessie_stream_ctx.keysize_b>100){
|
||||
uart_putc('0'+nessie_stream_ctx.keysize_b/100);
|
||||
}
|
||||
if(nessie_stream_ctx.keysize_b>10){
|
||||
uart_putc('0'+(nessie_stream_ctx.keysize_b/10)%10);
|
||||
}
|
||||
uart_putc('0'+nessie_stream_ctx.keysize_b%10);
|
||||
uart_putstr_P(PSTR(" bits\r\n"));
|
||||
}
|
||||
|
||||
static void print_footer(void){
|
||||
uart_putstr_P(PSTR("\r\n\r\n\r\n\r\nEnd of test vectors\r\n\r\n"));
|
||||
}
|
||||
|
||||
void nessie_stream_run(void){
|
||||
uint16_t i;
|
||||
uint8_t set;
|
||||
uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
|
||||
|
||||
print_header();
|
||||
nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
|
||||
0, 0, 0, 0);
|
||||
/* test set 1 */
|
||||
set=1;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, 0, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
key[i/8] |= 0x80>>(i%8);
|
||||
nessie_stream_enc(key);
|
||||
}
|
||||
/* test set 2 */
|
||||
set=2;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<256; ++i){
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
|
||||
nessie_stream_enc(key);
|
||||
}
|
||||
/* test set 3 */
|
||||
set=3;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<256; ++i){
|
||||
uint8_t j;
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
|
||||
key[j]=(i+j)&0xff;
|
||||
}
|
||||
|
@ -265,15 +160,15 @@ void nessie_stream_run(void){
|
|||
}
|
||||
/* test set 4 */
|
||||
set=4;
|
||||
print_setheader(set);
|
||||
nessie_print_setheader(set);
|
||||
for(i=0; i<4; ++i){
|
||||
uint8_t j;
|
||||
print_set_vector(set, i);
|
||||
nessie_print_set_vector(set, i);
|
||||
for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
|
||||
key[j]=(i*5+j*0x53)&0xff;
|
||||
}
|
||||
nessie_stream_enc_large(key);
|
||||
}
|
||||
|
||||
print_footer();
|
||||
nessie_print_footer();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
|
||||
serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o
|
||||
serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o \
|
||||
nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
|
||||
sha256-asm.o nessie_hash_test.o
|
||||
sha256-asm.o nessie_hash_test.o nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
2
xtea.mk
2
xtea.mk
|
@ -6,7 +6,7 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
|||
|
||||
$(ALGO_NAME)_OBJ := xtea-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-xtea-test.o debug.o uart.o serial-tools.o \
|
||||
xtea-asm.o nessie_bc_test.o
|
||||
xtea-asm.o nessie_bc_test.o nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||
|
||||
|
|
Loading…
Reference in New Issue