mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-31 11:31:32 +00:00
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>
This commit is contained in:
parent
6e7b9f4fa0
commit
dc24bb6ddb
2 changed files with 38 additions and 0 deletions
|
@ -63,4 +63,14 @@ void aes_decrypt(u8 *in, u8 *expkey, u8 *out);
|
||||||
*/
|
*/
|
||||||
void aes_cbc_encrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks);
|
void aes_cbc_encrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt multiple blocks of data with AES CBC.
|
||||||
|
*
|
||||||
|
* @key_exp Expanded key to use
|
||||||
|
* @src Source data to decrypt
|
||||||
|
* @dst Destination buffer
|
||||||
|
* @num_aes_blocks Number of AES blocks to decrypt
|
||||||
|
*/
|
||||||
|
void aes_cbc_decrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks);
|
||||||
|
|
||||||
#endif /* _AES_REF_H_ */
|
#endif /* _AES_REF_H_ */
|
||||||
|
|
28
lib/aes.c
28
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue