void testrun_trivium(void){ uint8_t key[10]; uint8_t iv[4]; uint8_t buffer[64]; scgen_ctx_t ctx; memset(key, 0, 10); memset(iv, 0, 4); key[0] = 0x80; scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx); scal_cipher_gen_fillblock(buffer, 64, &ctx); cli_putstr_P(PSTR("\r\nTest:\r\n Key = ")); cli_hexdump(key, 10); cli_putstr_P(PSTR("\r\n IV = ")); cli_hexdump(iv, 4); cli_putstr_P(PSTR("\r\n Cipher = ")); cli_hexdump_block(buffer, 64, 4, 16); scal_cipher_free(&ctx); key[0] = 0x40; scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx); scal_cipher_gen_fillblock(buffer, 64, &ctx); cli_putstr_P(PSTR("\r\nTest:\r\n Key = ")); cli_hexdump(key, 10); cli_putstr_P(PSTR("\r\n IV = ")); cli_hexdump(iv, 4); cli_putstr_P(PSTR("\r\n Cipher = ")); cli_hexdump_block(buffer, 64, 4, 16); scal_cipher_free(&ctx); key[0] = 0x20; scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx); scal_cipher_gen_fillblock(buffer, 64, &ctx); cli_putstr_P(PSTR("\r\nTest:\r\n Key = ")); cli_hexdump(key, 10); cli_putstr_P(PSTR("\r\n IV = ")); cli_hexdump(iv, 4); cli_putstr_P(PSTR("\r\n Cipher = ")); cli_hexdump_block(buffer, 64, 4, 16); scal_cipher_free(&ctx); key[0] = 0x10; scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx); scal_cipher_gen_fillblock(buffer, 64, &ctx); cli_putstr_P(PSTR("\r\nTest:\r\n Key = ")); cli_hexdump(key, 10); cli_putstr_P(PSTR("\r\n IV = ")); cli_hexdump(iv, 4); cli_putstr_P(PSTR("\r\n Cipher = ")); cli_hexdump_block(buffer, 64, 4, 16); scal_cipher_free(&ctx); }
void scal_nessie_stream_run(const scdesc_t *desc, uint16_t keysize_b, uint16_t ivsize_b){ uint8_t key[(keysize_b+7)/8]; uint8_t iv[(ivsize_b+7)/8]; uint16_t v; scgen_ctx_t ctx; nessie_print_header(desc->name, keysize_b, 0, 0, 0, ivsize_b?ivsize_b:((uint16_t)-1)); if(estream_flag){ stream_n_str[4] = streamX_n_estream; stream_l_str[4] = streamX_l_estream; }else{ stream_n_str[4] = streamX_n_nessie; stream_l_str[4] = streamX_l_nessie; } memset(iv, 0, (ivsize_b+7)/8); memset(key, 0, (keysize_b+7)/8); /*** Test SET 1 ***/ nessie_print_setheader(1); for(v=0;v<keysize_b; v+=estream_flag?9:1){ nessie_print_set_vector(1,v); key[v/8] |= 0x80>>(v&7); nessie_print_item("key", key, (keysize_b+7)/8); if(ivsize_b){ nessie_print_item("IV", iv, (ivsize_b+7)/8); } scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); normal_block(&ctx); key[v/8] = 0; scal_cipher_free(&ctx); } /*** Test SET 2 ***/ nessie_print_setheader(2); for(v=0;v<256; v+=estream_flag?9:1){ nessie_print_set_vector(2,v); memset(key, v&0xff, (keysize_b+7)/8); nessie_print_item("key", key, (keysize_b+7)/8); if(ivsize_b){ nessie_print_item("IV", iv, (ivsize_b+7)/8); } scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); normal_block(&ctx); scal_cipher_free(&ctx); } /*** Test SET 3 ***/ nessie_print_setheader(3); for(v=0;v<256; v+=estream_flag?9:1){ uint8_t i; nessie_print_set_vector(3,v); for(i=0; i<((keysize_b+7)/8); ++i){ key[i]=(i+v)&0xff; } nessie_print_item("key", key, (keysize_b+7)/8); if(ivsize_b){ nessie_print_item("IV", iv, (ivsize_b+7)/8); } scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); normal_block(&ctx); scal_cipher_free(&ctx); } /*** Test SET 4 ***/ nessie_print_setheader(4); for(v=0;v<4; ++v){ uint8_t i; nessie_print_set_vector(4,v); for(i=0; i<((keysize_b+7)/8); ++i){ key[i]=(i*0x53+v*5)&0xff; } nessie_print_item("key", key, (keysize_b+7)/8); if(ivsize_b){ nessie_print_item("IV", iv, (ivsize_b+7)/8); } scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); long_block(&ctx); scal_cipher_free(&ctx); } if(ivsize_b==0){ /* exit if there is no IV */ nessie_print_footer(); return; } /*** Test SET 5 ***/ nessie_print_setheader(5); memset(key, 0, (keysize_b+7)/8); for(v=0;v<ivsize_b; v+=estream_flag?9:1){ nessie_print_set_vector(5,v); iv[v/8] |= 0x80>>(v&7); nessie_print_item("key", key, (keysize_b+7)/8); nessie_print_item("IV", iv, (ivsize_b+7)/8); scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); normal_block(&ctx); scal_cipher_free(&ctx); iv[v/8] = 0; } /*** Test SET 6 ***/ nessie_print_setheader(6); for(v=0;v<4; ++v){ uint8_t i; nessie_print_set_vector(6,v); for(i=0; i<((keysize_b+7)/8); ++i){ key[i]=(i*0x53+v*5)&0xff; } for(i=0; i<((ivsize_b+7)/8); ++i){ iv[i]=(i*0x67+v*9+13)&0xff; } nessie_print_item("key", key, (keysize_b+7)/8); nessie_print_item("IV", iv, (ivsize_b+7)/8); scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); long_block(&ctx); scal_cipher_free(&ctx); } /*** Test SET 7 ***/ if(!estream_flag){ nessie_print_setheader(7); uint8_t u; for(v=0;v<3; ++v){ for(u=0; u<3; ++u){ uint8_t i; nessie_print_set_vector(7,v*3+u); for(i=0; i<((keysize_b+7)/8); ++i){ key[i]=list_of_keys[v][i%20]; } for(i=0; i<((ivsize_b+7)/8); ++i){ key[i]=*((uint8_t*)list_of_keys+4*u+(i%4)); } } nessie_print_item("key", key, (keysize_b+7)/8); nessie_print_item("IV", iv, (ivsize_b+7)/8); scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx); long_block(&ctx); scal_cipher_free(&ctx); } } nessie_print_footer(); }