7 #include "serial-tools.h"
17 /*****************************************************************************
18 * additional validation-functions *
19 *****************************************************************************/
21 /*****************************************************************************
23 *****************************************************************************/
25 void cast5_ctx_dump(cast5_ctx_t *s){
27 uart_putstr("\r\n==== cast5_ctx_dump ====\r\n shortkey: ");
28 uart_putstr(s->shortkey?"yes":"no");
31 uart_putstr("\r\n Km"); uart_hexdump(&i, 1); uart_putc(':');
32 uart_hexdump(&(s->mask[i]), 4);
33 uart_putstr("\r\n Kr"); uart_hexdump(&i, 1); uart_putc(':');
37 r += (s->roth[i>>3]&(1<<(i&0x7)))?0x10:0x00;
43 void test_encrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
46 uart_putstr("\r\nCAST5:\r\n key:\t");
47 uart_hexdump(key, keylength/8);
48 uart_putstr("\r\n plaintext:\t");
49 uart_hexdump(block, 8);
51 cast5_init(&s, key, keylength);
52 // cast5_ctx_dump(&s);
55 uart_putstr("\r\n ciphertext:\t");
56 uart_hexdump(block, 8);
60 void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
63 uart_putstr("\r\nCAST5:\r\n key:\t");
64 uart_hexdump(key, keylength/8);
65 uart_putstr("\r\n ciphertext:\t");
66 uart_hexdump(block, 8);
68 cast5_init(&s, key, keylength);
69 // cast5_ctx_dump(&s);
72 uart_putstr("\r\n plaintext:\t");
73 uart_hexdump(block, 8);
77 void testrun_cast5(void){
80 uint8_t *tda = "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
81 *tka = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A";
82 memcpy(block, tda, 8);
84 test_encrypt(block, key, 128, true);
85 test_decrypt(block, key, 128, true);
86 memcpy(block, tda, 8);
88 test_encrypt(block, key, 80, true);
89 test_decrypt(block, key, 80, true);
90 memcpy(block, tda, 8);
92 test_encrypt(block, key, 40, true);
93 test_decrypt(block, key, 40, true);
95 /**** long test *****/
96 uart_putstr("\r\nmaintance-test");
97 uint8_t a[16]= {0x01, 0x23, 0x45, 0x67, 0x12,
98 0x34, 0x56, 0x78, 0x23, 0x45,
99 0x67, 0x89, 0x34, 0x56, 0x78,
101 b[16]= {0x01, 0x23, 0x45, 0x67, 0x12,
102 0x34, 0x56, 0x78, 0x23, 0x45,
103 0x67, 0x89, 0x34, 0x56, 0x78,
106 for(i=0;i<1000000; ++i){
107 test_encrypt(&(a[0]), &(b[0]), 128, false);
108 test_encrypt(&(a[8]), &(b[0]), 128, false);
109 test_encrypt(&(b[0]), &(a[0]), 128, false);
110 test_encrypt(&(b[8]), &(a[0]), 128, false);
111 if ((i&0x000000ff) == 0){
116 uart_putstr("\r\na = "); uart_hexdump(a, 16);
117 uart_putstr("\r\nb = "); uart_hexdump(b, 16);
123 /*****************************************************************************
125 *****************************************************************************/
134 uart_putstr("\r\n\r\nCrypto-VS\r\nloaded and running\r\n");
137 if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
138 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
143 uart_putstr("ERROR\r\n");