err_status_t aes_test_inverse(void) { v128_t x, y; aes_expanded_key_t expanded_key, decrypt_key; uint8_t plaintext[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; v128_t k; v128_set_to_zero(&x); v128_copy_octet_string(&k, key); v128_copy_octet_string(&x, plaintext); aes_expand_encryption_key(k, expanded_key); aes_expand_decryption_key(k, decrypt_key); aes_encrypt(&x, expanded_key); aes_decrypt(&x, decrypt_key); /* compare to expected value then report */ v128_copy_octet_string(&y, plaintext); if (v128_is_eq(&x, &y)) return err_status_ok; return err_status_algo_fail; }
err_status_t aes_cbc_set_iv(aes_cbc_ctx_t *c, void *iv, int direction) { err_status_t status; int i; /* v128_t *input = iv; */ uint8_t *input = (uint8_t*) iv; /* set state and 'previous' block to iv */ for (i=0; i < 16; i++) c->previous.v8[i] = c->state.v8[i] = input[i]; debug_print(mod_aes_cbc, "setting iv: %s", v128_hex_string(&c->state)); /* expand key for the appropriate direction */ switch (direction) { case (direction_encrypt): status = aes_expand_encryption_key(c->key, c->key_len, &c->expanded_key); memset(c->key, 0, 32); if (status) return status; break; case (direction_decrypt): status = aes_expand_decryption_key(c->key, c->key_len, &c->expanded_key); memset(c->key, 0, 32); if (status) return status; break; default: return err_status_bad_param; } return err_status_ok; }
void aes_decrypt_with_raw_key(void *ciphertext, const void *key, int key_len) { aes_expanded_key_t expanded_key; aes_expand_decryption_key(key, key_len, &expanded_key); srtp_aes_decrypt(ciphertext, &expanded_key); }
err_status_t aes_cbc_context_init(aes_cbc_ctx_t *c, const uint8_t *key, cipher_direction_t dir) { v128_t tmp_key; /* set tmp_key (for alignment) */ v128_copy_octet_string(&tmp_key, key); debug_print(mod_aes_cbc, "key: %s", v128_hex_string(&tmp_key)); /* expand key for the appropriate direction */ switch (dir) { case (direction_encrypt): aes_expand_encryption_key(&tmp_key, c->expanded_key); break; case (direction_decrypt): aes_expand_decryption_key(&tmp_key, c->expanded_key); break; default: return err_status_bad_param; } return err_status_ok; }
void aes_decrypt_with_raw_key(void *ciphertext, const void *key, int key_len) { #ifndef OPENSSL //FIXME: need to get this working through the crypto module interface aes_expanded_key_t expanded_key; aes_expand_decryption_key(key, key_len, &expanded_key); aes_decrypt(ciphertext, &expanded_key); #endif }