diff options
author | Marek Vasut <marex@denx.de> | 2014-03-05 19:58:38 +0100 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-03-21 16:43:56 -0400 |
commit | dc24bb6ddb416db52a60165931c0864fdba1f60b (patch) | |
tree | 3fe6c7b3144be31fa5e62591413ad44cb927c60b /lib | |
parent | 6e7b9f4fa0aed88051d6700afa510430b5d3fb69 (diff) |
aes: Implement AES-128-CBC decryption function
Implement a compatible AES-128-CBC decryption function as a counterpart
of the encryption function pulled from tegra20-common/crypto.c .
Signed-off-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/aes.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/aes.c b/lib/aes.c index a6648f90db2..9dadb22c3ad 100644 --- a/lib/aes.c +++ b/lib/aes.c @@ -632,3 +632,31 @@ void aes_cbc_encrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks) dst += AES_KEY_LENGTH; } } + +void aes_cbc_decrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks) +{ + u8 tmp_data[AES_KEY_LENGTH], tmp_block[AES_KEY_LENGTH]; + /* Convenient array of 0's for IV */ + u8 cbc_chain_data[AES_KEY_LENGTH] = { 0 }; + u32 i; + + for (i = 0; i < num_aes_blocks; i++) { + debug("encrypt_object: block %d of %d\n", i, num_aes_blocks); + debug_print_vector("AES Src", AES_KEY_LENGTH, src); + + memcpy(tmp_block, src, AES_KEY_LENGTH); + + /* Decrypt the AES block */ + aes_decrypt(src, key_exp, tmp_data); + debug_print_vector("AES Xor", AES_KEY_LENGTH, tmp_data); + + /* Apply the chain data */ + apply_cbc_chain_data(cbc_chain_data, tmp_data, dst); + debug_print_vector("AES Dst", AES_KEY_LENGTH, dst); + + /* Update pointers for next loop. */ + memcpy(cbc_chain_data, tmp_block, AES_KEY_LENGTH); + src += AES_KEY_LENGTH; + dst += AES_KEY_LENGTH; + } +} |