aes_rval aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]) { switch(key_len) { #if defined( AES_ERR_CHK ) case 16: case 128: return aes_decrypt_key128(key, cx); case 24: case 192: return aes_decrypt_key192(key, cx); case 32: case 256: return aes_decrypt_key256(key, cx); default: return aes_error; #else case 16: case 128: aes_decrypt_key128(key, cx); return; case 24: case 192: aes_decrypt_key192(key, cx); return; case 32: case 256: aes_decrypt_key256(key, cx); return; #endif } }
aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]) { switch(key_len) { #ifdef AES_ERR_CHK case 16: case 128: return aes_decrypt_key128(in_key, cx); case 24: case 192: return aes_decrypt_key192(in_key, cx); case 32: case 256: return aes_decrypt_key256(in_key, cx); default: return aes_error; #else case 16: case 128: aes_decrypt_key128(in_key, cx); return; case 24: case 192: aes_decrypt_key192(in_key, cx); return; case 32: case 256: aes_decrypt_key256(in_key, cx); return; #endif } }
AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]) { switch(key_len) { case 16: case 128: return aes_decrypt_key128(key, cx); case 24: case 192: return aes_decrypt_key192(key, cx); case 32: case 256: return aes_decrypt_key256(key, cx); default: return EXIT_FAILURE; } }
/* * Expand the cipher key into the decryption key schedule. * * Return the number of rounds for the given cipher key size. * The size of the key schedule depends on the number of rounds * (which can be computed from the size of the key), i.e. 4 * (Nr + 1). * * Parameters: * rk AES key schedule 32-bit array to be initialized * cipherKey User key * keyBits AES key size (128, 192, or 256 bits) */ int rijndael_key_setup_dec_amd64(uint32_t rk[], const uint32_t cipherKey[], int keyBits) { switch (keyBits) { case 128: aes_decrypt_key128((unsigned char *)&cipherKey[0], rk); return (10); case 192: aes_decrypt_key192((unsigned char *)&cipherKey[0], rk); return (12); case 256: aes_decrypt_key256((unsigned char *)&cipherKey[0], rk); return (14); default: /* should never get here */ break; } return (0); }
static bool aes_operation(bool encrypt, const uint8_t *kek, size_t kek_len, uint8_t *block) { uint64_t iv[2] = { 0 }; if (encrypt) { aes_encrypt_ctx encrypt_ctx[1]; switch(kek_len) { #if AES128_KEK case 16: aes_encrypt_key128(kek, encrypt_ctx); break; #endif #if AES192_KEK case 24: aes_encrypt_key192(kek, encrypt_ctx); break; #endif #if AES256_KEK case 32: aes_encrypt_key256(kek, encrypt_ctx); break; #endif default: return false; } aes_encrypt_cbc(block, (uint8_t*)iv, 1, block, encrypt_ctx); } else { aes_decrypt_ctx decrypt_ctx[1]; switch(kek_len) { #if AES128_KEK case 16: aes_decrypt_key128(kek, decrypt_ctx); break; #endif #if AES192_KEK case 24: aes_decrypt_key192(kek, decrypt_ctx); break; #endif #if AES256_KEK case 32: aes_decrypt_key256(kek, decrypt_ctx); break; #endif default: return false; } aes_decrypt_cbc(block, (uint8_t*)iv, 1, block, decrypt_ctx); } return true; }