1 /* nessie_stream_test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * email: daniel.otte@rub.de
25 * a suit for running the nessie-tests for streamciphers
30 #include "nessie_stream_test.h"
31 #include "nessie_common.h"
33 nessie_stream_ctx_t nessie_stream_ctx;
36 #define BLOCKSIZE_B 64
39 void memxor(void* dest, void* src, uint8_t length){
41 *((uint8_t*)dest) ^= *((uint8_t*)src);
42 dest = (uint8_t*)dest +1;
43 src = (uint8_t*)src +1;
49 void nessie_gen_block(void* ctx, uint8_t* block){
51 for(i=0; i<BLOCKSIZE_B; ++i){
52 block[i] = nessie_stream_ctx.cipher_enc(ctx);
57 void nessie_stream_enc(uint8_t* key){
58 uint8_t ctx[nessie_stream_ctx.ctx_size_B];
59 uint8_t buffer[BLOCKSIZE_B];
60 uint8_t xorbuffer[BLOCKSIZE_B];
63 memset(xorbuffer, 0, BLOCKSIZE_B);
65 nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
67 nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
69 nessie_gen_block(ctx, buffer);
70 memxor(xorbuffer, buffer, BLOCKSIZE_B);
71 nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
73 for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
74 nessie_gen_block(ctx, buffer);
75 memxor(xorbuffer, buffer, BLOCKSIZE_B);
78 nessie_gen_block(ctx, buffer);
79 memxor(xorbuffer, buffer, BLOCKSIZE_B);
80 nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
82 nessie_gen_block(ctx, buffer);
83 memxor(xorbuffer, buffer, BLOCKSIZE_B);
84 nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
86 for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
87 nessie_gen_block(ctx, buffer);
88 memxor(xorbuffer, buffer, BLOCKSIZE_B);
91 nessie_gen_block(ctx, buffer);
92 memxor(xorbuffer, buffer, BLOCKSIZE_B);
93 nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
95 nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
101 void nessie_stream_enc_large(uint8_t* key){
102 uint8_t ctx[nessie_stream_ctx.ctx_size_B];
103 uint8_t buffer[BLOCKSIZE_B];
104 uint8_t xorbuffer[BLOCKSIZE_B];
107 memset(xorbuffer, 0, BLOCKSIZE_B);
109 nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
111 nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
113 nessie_gen_block(ctx, buffer);
114 memxor(xorbuffer, buffer, BLOCKSIZE_B);
115 nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
117 for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
118 nessie_gen_block(ctx, buffer);
119 memxor(xorbuffer, buffer, BLOCKSIZE_B);
120 NESSIE_SEND_ALIVE_A(i);
123 nessie_gen_block(ctx, buffer);
124 memxor(xorbuffer, buffer, BLOCKSIZE_B);
125 nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
127 nessie_gen_block(ctx, buffer);
128 memxor(xorbuffer, buffer, BLOCKSIZE_B);
129 nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
131 for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
132 nessie_gen_block(ctx, buffer);
133 memxor(xorbuffer, buffer, BLOCKSIZE_B);
134 NESSIE_SEND_ALIVE_A(i);
137 nessie_gen_block(ctx, buffer);
138 memxor(xorbuffer, buffer, BLOCKSIZE_B);
139 nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
141 nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
145 void nessie_stream_run(void){
148 uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
150 nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
151 0, 0, 0, nessie_stream_ctx.ivsize_b);
154 nessie_print_setheader(set);
155 for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
156 nessie_print_set_vector(set, i);
157 memset(key, 0, (nessie_stream_ctx.keysize_b+7)/8);
158 key[i/8] |= 0x80>>(i%8);
159 nessie_stream_enc(key);
163 nessie_print_setheader(set);
164 for(i=0; i<256; ++i){
165 nessie_print_set_vector(set, i);
166 memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
167 nessie_stream_enc(key);
171 nessie_print_setheader(set);
172 for(i=0; i<256; ++i){
174 nessie_print_set_vector(set, i);
175 for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
178 nessie_stream_enc(key);
182 nessie_print_setheader(set);
185 nessie_print_set_vector(set, i);
186 for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
187 key[j]=(i*5+j*0x53)&0xff;
189 nessie_stream_enc_large(key);
192 nessie_print_footer();