void testrun_nist_vectors(void){ uint8_t key[10]; uint8_t data[8]; uint8_t i; cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 1 ===")); memset(key, 0, 10); for(i=0; i<64; ++i){ memset(data, 0, 8); data[i>>3] |= 0x80 >> (i & 7); cli_putstr_P(PSTR("\r\n round: 0x")); cli_hexdump_byte(i); test_enc(data, key); } cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 2 ===")); memset(data, 0, 8); for(i=0; i<80; ++i){ memset(key, 0, 10); key[i>>3] |= 0x80 >> (i & 7); cli_putstr_P(PSTR("\r\n round: 0x")); cli_hexdump_byte(i); test_enc(data, key); } }
void quick_test(void){ uint8_t *ciphertext, *plaintext, rc; uint8_t seed[sizeof(SEED)], seed_out[sizeof(SEED)]; uint16_t clen, plen; if(!keys_allocated){ load_fix_rsa(); } ciphertext = malloc(clen = bigint_length_B(&pub_key.modulus)); plaintext = malloc(clen); memcpy_P(plaintext, MSG, sizeof(MSG)); memcpy_P(seed, SEED, sizeof(SEED)); cli_putstr_P(PSTR("\r\nplaintext:")); cli_hexdump_block(plaintext, sizeof(MSG), 4, 16); cli_putstr_P(PSTR("\r\nseed:")); cli_hexdump_block(seed, sizeof(SEED), 4, 16); cli_putstr_P(PSTR("\r\nencrypting: ...")); rc = rsa_encrypt_pkcs1v15(ciphertext, &clen, plaintext, sizeof(MSG), &pub_key, seed); if(rc){ cli_putstr_P(PSTR("\r\nERROR: rsa_encrypt_pkcs1v15 returned: ")); cli_hexdump_byte(rc); return; } cli_putstr_P(PSTR("\r\n\r\nciphertext:")); cli_hexdump_block(ciphertext, clen, 4, 16); if(clen != sizeof(ENCRYPTED)){ cli_putstr_P(PSTR("\r\n>>FAIL (no size match)<<")); return; }else{ if(memcmp_P(ciphertext, ENCRYPTED, clen)){ cli_putstr_P(PSTR("\r\n>>FAIL (no content match)<<")); return; }else{ cli_putstr_P(PSTR("\r\n>>OK<<")); } } cli_putstr_P(PSTR("\r\ndecrypting: ...")); rc = rsa_decrypt_pkcs1v15(plaintext, &plen, ciphertext, clen, &priv_key, seed_out); if(rc){ cli_putstr_P(PSTR("\r\nERROR: rsa_decrypt_pkcs1v15 returned: ")); cli_hexdump_byte(rc); return; } cli_putstr_P(PSTR("\r\n\r\nplaintext:")); cli_hexdump_block(plaintext, plen, 4, 16); cli_putstr_P(PSTR("\r\n\r\nseed (out):")); cli_hexdump_block(seed_out, sizeof(SEED), 4, 16); free(ciphertext); free(plaintext); }
void test_sbox(void){ uint8_t i=0,x; cli_putstr_P(PSTR("\r\nKhazad Sbox:\r\n\t")); do{ x = khazad_sbox(i); cli_hexdump_byte(x); cli_putc(' '); if(i%16==15){ cli_putstr_P(PSTR("\r\n\t")); } ++i; }while(i); }
void load_key(void){ uint8_t r; if(keys_allocated){ cli_putstr_P(PSTR("\r\nDBG: freeing old keys")); free_key(); } keys_allocated = 1; r = read_key_crt(); if(r){ cli_putstr_P(PSTR("\r\nERROR: read_key_crt returned 0x")); cli_hexdump_byte(r); } }