]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-shacal2_enc-test.c
7c5d1eab77053b52169a0fedcc8ab69500e974d4
[avr-crypto-lib.git] / main-shacal2_enc-test.c
1 /*
2  * Shacal2 encryption only test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "shacal2_enc.h"
12 #include "nessie_bc_test.h"
13 #include "cli.h"
14 #include "performance_test.h"
15
16 #include <stdlib.h>
17 #include <stdint.h>
18 #include <string.h>
19
20 char* cipher_name = "Shacal2 encryption only";
21
22 /*****************************************************************************
23  *  additional validation-functions                                                                                      *
24  *****************************************************************************/
25 void shacal2_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
26         memcpy(ctx, key, (keysize_b+7)/8);
27 }
28
29 void shacal2_enc_dummy(void* buffer, void* ctx){
30         shacal2_enc(buffer, ctx, SHACAL2_KEYSIZE);
31 }
32
33 void testrun_nessie_shacal2enc(void){
34         nessie_bc_ctx.blocksize_B = SHACAL2_BLOCKSIZE_B;
35         nessie_bc_ctx.keysize_b   = SHACAL2_KEYSIZE;
36         nessie_bc_ctx.name        = cipher_name;
37         nessie_bc_ctx.ctx_size_B  = SHACAL2_KEYSIZE_B;
38         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)shacal2_enc_dummy;
39         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)NULL;
40         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)shacal2_genctx_dummy;
41         
42         nessie_bc_run();        
43 }
44
45 void testrun_performance_shacal2enc(void){
46         uint64_t t;
47         uint8_t key[SHACAL2_KEYSIZE_B], data[SHACAL2_BLOCKSIZE_B];
48         
49         calibrateTimer();
50         print_overhead();
51         
52         memset(key,  0, SHACAL2_KEYSIZE_B);
53         memset(data, 0, SHACAL2_BLOCKSIZE_B);
54         
55         
56         startTimer(1);
57         shacal2_enc(data, key, SHACAL2_KEYSIZE);
58         t = stopTimer();
59         print_time_P(PSTR("\tencrypt time: "), t);
60         
61         uart_putstr_P(PSTR("\r\n"));
62 }
63
64 /*****************************************************************************
65  *  main                                                                                                                                         *
66  *****************************************************************************/
67
68 int main (void){
69         char  str[20];
70         DEBUG_INIT();
71         uart_putstr("\r\n");
72
73         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
74         uart_putstr(cipher_name);
75         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
76
77         PGM_P    u   = PSTR("nessie\0test\0performance\0");
78         void_fpt v[] = {testrun_nessie_shacal2enc, 
79                             testrun_nessie_shacal2enc,
80                             testrun_performance_shacal2enc};
81
82         while(1){ 
83                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
84                 if(execcommand_d0_P(str, u, v)<0){
85                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
86                 }
87                 continue;
88         error:
89                 uart_putstr("ERROR\r\n");
90         }
91         
92 }