X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=main-serpent-test.c;h=fc860357fc301fdc30cbf77cee526466ed399839;hb=cb23251fd9f7c2d9e519a84b6975091bceb0fa66;hp=120d4028cdd52663a7e51c6b48bed8a52f7cf38c;hpb=1bb58b2db7b71d44e4da7fd3f977a388c20e3b39;p=avr-crypto-lib.git diff --git a/main-serpent-test.c b/main-serpent-test.c index 120d402..fc86035 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -1,3 +1,21 @@ +/* main-serpent-test.c */ +/* + This file is part of the Crypto-avr-lib/microcrypt-lib. + 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 . +*/ /* * serpent test-suit * @@ -9,136 +27,104 @@ #include "debug.h" #include "serpent.h" +#include "nessie_bc_test.h" +#include "cli.h" +#include "performance_test.h" #include #include +#include +char* cipher_name = "Serpent"; /***************************************************************************** * additional validation-functions * *****************************************************************************/ - -/***************************************************************************** - * self tests * - *****************************************************************************/ - -void dumpctx(serpent_ctx_t * ctx){ - uint8_t i; - uart_putstr("\r\n --ctx dump--\r\n"); - for(i=0; i<33; ++i){ - uart_putstr(" K["); uart_putc('0'+i/10); uart_putc('0'+i%10); uart_putstr("] = "); - uart_hexdump(ctx->k[i],16); - uart_putstr("\r\n"); - } +void serpent_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ + serpent_genctx(key, keysize&0xff, ctx); } -void testencrypt(uint8_t* block, uint8_t* key){ - serpent_ctx_t ctx; - uart_putstr("\r\n==testy-encrypt==\r\n key: "); - uart_hexdump(key,32); - serpent_genctx(key, &ctx); -// dumpctx(&ctx); - uart_putstr("\r\n plain: "); - uart_hexdump(block,16); - serpent_enc(block, &ctx); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); +void testrun_nessie_serpent(void){ + nessie_bc_ctx.blocksize_B = 16; + nessie_bc_ctx.keysize_b = 128; + nessie_bc_ctx.name = cipher_name; + nessie_bc_ctx.ctx_size_B = sizeof(serpent_ctx_t); + nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)serpent_enc; + nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)serpent_dec; + nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)serpent_genctx_dummy; + + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 192; + nessie_bc_run(); + + nessie_bc_ctx.keysize_b = 256; + nessie_bc_run(); } -void testdecrypt(uint8_t* block, uint8_t* key){ - serpent_ctx_t ctx; - uart_putstr("\r\n==testy-decrypt==\r\n key: "); - uart_hexdump(key,32); - serpent_genctx(key, &ctx); -// dumpctx(&ctx); - uart_putstr("\r\n crypt: "); - uart_hexdump(block,16); - serpent_dec(block, &ctx); - uart_putstr("\r\n plain: "); - uart_hexdump(block,16); -} -/** - Test vectors -- set 4 -===================== - -Set 4, vector# 0: - key=000102030405060708090A0B0C0D0E0F - 101112131415161718191A1B1C1D1E1F - plain=00112233445566778899AABBCCDDEEFF - cipher=2868B7A2D28ECD5E4FDEFAC3C4330074 - decrypted=00112233445566778899AABBCCDDEEFF - Iterated 100 times=8BF56992354F3F1A0F4E49DCBA82CBC0 - Iterated 1000 times=9B1D8B34845DF9BFD36AAAD0CDA1C8FE - -Set 4, vector# 1: - key=2BD6459F82C5B300952C49104881FF48 - 2BD6459F82C5B300952C49104881FF48 - plain=EA024714AD5C4D84EA024714AD5C4D84 - cipher=3E507730776B93FDEA661235E1DD99F0 - decrypted=EA024714AD5C4D84EA024714AD5C4D84 - Iterated 100 times=3B5462E5D87A40C4BE745E3994D5E373 - Iterated 1000 times=99D5D067EF7C787E6A764EB47DAC59AD - - -Set 1, vector# 0: - key=80000000000000000000000000000000 - 00000000000000000000000000000000 - plain=00000000000000000000000000000000 - cipher=A223AA1288463C0E2BE38EBD825616C0 - decrypted=00000000000000000000000000000000 - Iterated 100 times=739E0148971FD975B585EAFDBD659E2C - Iterated 1000 times=BEFD00E0D6E27E56951DC6614440D286 - -*/ - -void testrun_serpent(void){ +void testrun_performance_serpent(void){ + uint64_t t; + char str[16]; + uint8_t key[32], data[16]; + serpent_ctx_t ctx; - uint8_t key[]={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; - - uint8_t data[]={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; -/* * / - uint8_t key[]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - uint8_t data[]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -*/ - testencrypt(data,key); - testdecrypt(data,key); + calibrateTimer(); + print_overhead(); + + memset(key, 0, 32); + memset(data, 0, 16); + + startTimer(1); + serpent_genctx(key, 0, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + serpent_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + + startTimer(1); + serpent_dec(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + uart_putstr_P(PSTR("\r\n")); } - - - /***************************************************************************** * main * *****************************************************************************/ int main (void){ - char str[20]; - + char str[20]; DEBUG_INIT(); uart_putstr("\r\n"); - uart_putstr("\r\n\r\nCrypto-VS (serpent)\r\nloaded and running\r\n"); + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(cipher_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent}; -restart: while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - testrun_serpent(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); } - }