2008-05-26 19:13:21 +00:00
|
|
|
/* nessie_stream_test.c */
|
|
|
|
/*
|
2009-01-30 23:00:04 +00:00
|
|
|
This file is part of the AVR-Crypto-Lib.
|
2008-05-26 19:13:21 +00:00
|
|
|
Copyright (C) 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/>.
|
|
|
|
*/
|
2008-04-06 02:42:32 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* author: Daniel Otte
|
|
|
|
* email: daniel.otte@rub.de
|
|
|
|
* license: GPLv3
|
|
|
|
*
|
|
|
|
* a suit for running the nessie-tests for streamciphers
|
|
|
|
*
|
|
|
|
* */
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "nessie_stream_test.h"
|
2008-04-08 03:21:13 +00:00
|
|
|
#include "nessie_common.h"
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
nessie_stream_ctx_t nessie_stream_ctx;
|
|
|
|
|
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
#define BLOCKSIZE_B 64
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
void memxor(void* dest, void* src, uint8_t length){
|
|
|
|
while(length--){
|
|
|
|
*((uint8_t*)dest) ^= *((uint8_t*)src);
|
|
|
|
dest = (uint8_t*)dest +1;
|
|
|
|
src = (uint8_t*)src +1;
|
|
|
|
}
|
2008-04-08 03:21:13 +00:00
|
|
|
}
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void nessie_gen_block(void* ctx, uint8_t* block){
|
|
|
|
uint16_t i;
|
|
|
|
for(i=0; i<BLOCKSIZE_B; ++i){
|
|
|
|
block[i] = nessie_stream_ctx.cipher_enc(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void nessie_stream_enc(uint8_t* key){
|
|
|
|
uint8_t ctx[nessie_stream_ctx.ctx_size_B];
|
|
|
|
uint8_t buffer[BLOCKSIZE_B];
|
|
|
|
uint8_t xorbuffer[BLOCKSIZE_B];
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
memset(xorbuffer, 0, BLOCKSIZE_B);
|
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
|
|
|
}
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
|
|
|
}
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
void nessie_stream_enc_large(uint8_t* key){
|
|
|
|
uint8_t ctx[nessie_stream_ctx.ctx_size_B];
|
|
|
|
uint8_t buffer[BLOCKSIZE_B];
|
|
|
|
uint8_t xorbuffer[BLOCKSIZE_B];
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
memset(xorbuffer, 0, BLOCKSIZE_B);
|
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2009-02-04 13:50:15 +00:00
|
|
|
NESSIE_SEND_ALIVE_A(i);
|
2008-04-06 02:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2009-02-04 13:50:15 +00:00
|
|
|
NESSIE_SEND_ALIVE_A(i);
|
2008-04-06 02:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nessie_gen_block(ctx, buffer);
|
|
|
|
memxor(xorbuffer, buffer, BLOCKSIZE_B);
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
|
2008-04-06 02:42:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void nessie_stream_run(void){
|
|
|
|
uint16_t i;
|
|
|
|
uint8_t set;
|
|
|
|
uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
|
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
|
2008-04-11 02:52:10 +00:00
|
|
|
0, 0, 0, nessie_stream_ctx.ivsize_b);
|
2008-04-06 02:42:32 +00:00
|
|
|
/* test set 1 */
|
|
|
|
set=1;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_setheader(set);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_set_vector(set, i);
|
2008-04-06 02:42:32 +00:00
|
|
|
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;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_setheader(set);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(i=0; i<256; ++i){
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_set_vector(set, i);
|
2008-04-06 02:42:32 +00:00
|
|
|
memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
|
|
|
|
nessie_stream_enc(key);
|
|
|
|
}
|
|
|
|
/* test set 3 */
|
|
|
|
set=3;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_setheader(set);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(i=0; i<256; ++i){
|
|
|
|
uint8_t j;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_set_vector(set, i);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
|
|
|
|
key[j]=(i+j)&0xff;
|
|
|
|
}
|
|
|
|
nessie_stream_enc(key);
|
|
|
|
}
|
|
|
|
/* test set 4 */
|
|
|
|
set=4;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_setheader(set);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(i=0; i<4; ++i){
|
|
|
|
uint8_t j;
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_set_vector(set, i);
|
2008-04-06 02:42:32 +00:00
|
|
|
for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
|
|
|
|
key[j]=(i*5+j*0x53)&0xff;
|
|
|
|
}
|
|
|
|
nessie_stream_enc_large(key);
|
|
|
|
}
|
|
|
|
|
2008-04-08 03:21:13 +00:00
|
|
|
nessie_print_footer();
|
2008-04-06 02:42:32 +00:00
|
|
|
}
|