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 blockciphers
30 #include "nessie_bc_test.h"
31 #include "nessie_common.h"
34 nessie_bc_ctx_t nessie_bc_ctx;
36 void nessie_bc_init(void){
37 memset(&nessie_bc_ctx, 0, sizeof(nessie_bc_ctx_t));
40 void nessie_bc_free(void* ctx){
41 if(nessie_bc_ctx.cipher_free)
42 nessie_bc_ctx.cipher_free(ctx);
45 void nessie_bc_enc(uint8_t* key, uint8_t* pt){
46 uint8_t ctx[nessie_bc_ctx.ctx_size_B];
47 uint8_t buffer[nessie_bc_ctx.blocksize_B];
51 nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
52 nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
54 memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
55 nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
56 nessie_bc_ctx.cipher_enc(buffer, ctx);
57 nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
58 if(nessie_bc_ctx.cipher_dec){
59 nessie_bc_ctx.cipher_dec(buffer, ctx);
60 nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
63 memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
65 nessie_bc_ctx.cipher_enc(buffer, ctx);
66 NESSIE_SEND_ALIVE_A(i);
68 nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
69 #ifndef NESSIE_NO1KTEST
70 /* 1000 times test, we use the 100 precedig steps to fasten things a bit */
72 nessie_bc_ctx.cipher_enc(buffer, ctx);
73 NESSIE_SEND_ALIVE_A(i);
75 nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
80 void nessie_bc_dec(uint8_t* key, uint8_t* ct){
81 uint8_t ctx[nessie_bc_ctx.ctx_size_B];
82 uint8_t buffer[nessie_bc_ctx.blocksize_B];
85 nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
86 nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
87 memcpy(buffer, ct, nessie_bc_ctx.blocksize_B);
88 nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
89 nessie_bc_ctx.cipher_dec(buffer, ctx);
90 nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
91 nessie_bc_ctx.cipher_enc(buffer, ctx);
92 nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B);
96 void nessie_bc_run(void){
99 uint8_t key[(nessie_bc_ctx.keysize_b+7)/8];
100 uint8_t buffer[nessie_bc_ctx.blocksize_B];
102 nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b,
103 nessie_bc_ctx.blocksize_B*8, 0, 0, 0);
106 nessie_print_setheader(set);
107 for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
108 nessie_print_set_vector(set, i);
109 memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
110 key[i/8] |= 0x80>>(i%8);
111 memset(buffer, 0, nessie_bc_ctx.blocksize_B);
112 nessie_bc_enc(key, buffer);
116 nessie_print_setheader(set);
117 for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
118 nessie_print_set_vector(set, i);
119 memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
120 memset(buffer, 0, nessie_bc_ctx.blocksize_B);
121 buffer[i/8] |= 0x80>>(i%8);
122 nessie_bc_enc(key, buffer);
126 nessie_print_setheader(set);
127 for(i=0; i<256; ++i){
128 nessie_print_set_vector(set, i);
129 memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
130 memset(buffer, i, nessie_bc_ctx.blocksize_B);
131 nessie_bc_enc(key, buffer);
135 nessie_print_setheader(set);
137 nessie_print_set_vector(set, 0);
138 for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
141 for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
144 nessie_bc_enc(key, buffer);
146 nessie_print_set_vector(set, 1);
147 /* This is the test vectors in Kasumi */
148 static uint8_t kasumi_key[] = {
149 0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
150 0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48 };
151 static uint8_t kasumi_plain[]={
152 0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 };
153 for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
154 key[i]=kasumi_key[i%sizeof(kasumi_key)];
156 for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
157 buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
159 nessie_bc_enc(key, buffer);
161 if(nessie_bc_ctx.cipher_dec==NULL)
165 nessie_print_setheader(set);
166 for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
167 nessie_print_set_vector(set, i);
168 memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
169 key[i/8] |= 0x80>>(i%8);
170 memset(buffer, 0, nessie_bc_ctx.blocksize_B);
171 nessie_bc_dec(key, buffer);
175 nessie_print_setheader(set);
176 for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
177 nessie_print_set_vector(set, i);
178 memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
179 memset(buffer, 0, nessie_bc_ctx.blocksize_B);
180 buffer[i/8] |= 0x80>>(i%8);
181 nessie_bc_dec(key, buffer);
185 nessie_print_setheader(set);
186 for(i=0; i<256; ++i){
187 nessie_print_set_vector(set, i);
188 memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
189 memset(buffer, i, nessie_bc_ctx.blocksize_B);
190 nessie_bc_dec(key, buffer);
194 nessie_print_setheader(set);
196 nessie_print_set_vector(set, 0);
197 for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
200 for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
203 nessie_bc_dec(key, buffer);
205 nessie_print_set_vector(set, 1);
206 for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
207 key[i]=kasumi_key[i%sizeof(kasumi_key)];
209 for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
210 buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
212 nessie_bc_dec(key, buffer);
213 nessie_print_footer();