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"
34 nessie_stream_ctx_t nessie_stream_ctx;
37 #define BLOCKSIZE_B 64
41 void nessie_gen_block(void *ctx, uint8_t *block){
43 for(i=0; i<BLOCKSIZE_B; ++i){
44 block[i] = nessie_stream_ctx.cipher_enc(ctx);
49 void nessie_stream_enc(uint8_t *key){
50 uint8_t ctx[nessie_stream_ctx.ctx_size_B];
51 uint8_t buffer[BLOCKSIZE_B];
52 uint8_t xorbuffer[BLOCKSIZE_B];
55 memset(xorbuffer, 0, BLOCKSIZE_B);
57 nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
59 nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
61 nessie_gen_block(ctx, buffer);
62 memxor(xorbuffer, buffer, BLOCKSIZE_B);
63 nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
65 for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
66 nessie_gen_block(ctx, buffer);
67 memxor(xorbuffer, buffer, BLOCKSIZE_B);
70 nessie_gen_block(ctx, buffer);
71 memxor(xorbuffer, buffer, BLOCKSIZE_B);
72 nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
74 nessie_gen_block(ctx, buffer);
75 memxor(xorbuffer, buffer, BLOCKSIZE_B);
76 nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
78 for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
79 nessie_gen_block(ctx, buffer);
80 memxor(xorbuffer, buffer, BLOCKSIZE_B);
83 nessie_gen_block(ctx, buffer);
84 memxor(xorbuffer, buffer, BLOCKSIZE_B);
85 nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
87 nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
93 void nessie_stream_enc_large(uint8_t *key){
94 uint8_t ctx[nessie_stream_ctx.ctx_size_B];
95 uint8_t buffer[BLOCKSIZE_B];
96 uint8_t xorbuffer[BLOCKSIZE_B];
99 memset(xorbuffer, 0, BLOCKSIZE_B);
101 nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
103 nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
105 nessie_gen_block(ctx, buffer);
106 memxor(xorbuffer, buffer, BLOCKSIZE_B);
107 nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
109 for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
110 nessie_gen_block(ctx, buffer);
111 memxor(xorbuffer, buffer, BLOCKSIZE_B);
112 NESSIE_SEND_ALIVE_A(i);
115 nessie_gen_block(ctx, buffer);
116 memxor(xorbuffer, buffer, BLOCKSIZE_B);
117 nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
119 nessie_gen_block(ctx, buffer);
120 memxor(xorbuffer, buffer, BLOCKSIZE_B);
121 nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
123 for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
124 nessie_gen_block(ctx, buffer);
125 memxor(xorbuffer, buffer, BLOCKSIZE_B);
126 NESSIE_SEND_ALIVE_A(i);
129 nessie_gen_block(ctx, buffer);
130 memxor(xorbuffer, buffer, BLOCKSIZE_B);
131 nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
133 nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
137 void nessie_stream_run(void){
140 uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
142 nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
143 0, 0, 0, nessie_stream_ctx.ivsize_b);
146 nessie_print_setheader(set);
147 for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
148 nessie_print_set_vector(set, i);
149 memset(key, 0, (nessie_stream_ctx.keysize_b+7)/8);
150 key[i/8] |= 0x80>>(i%8);
151 nessie_stream_enc(key);
155 nessie_print_setheader(set);
156 for(i=0; i<256; ++i){
157 nessie_print_set_vector(set, i);
158 memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
159 nessie_stream_enc(key);
163 nessie_print_setheader(set);
164 for(i=0; i<256; ++i){
166 nessie_print_set_vector(set, i);
167 for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
170 nessie_stream_enc(key);
174 nessie_print_setheader(set);
177 nessie_print_set_vector(set, i);
178 for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
179 key[j]=(i*5+j*0x53)&0xff;
181 nessie_stream_enc_large(key);
184 nessie_print_footer();