Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/source/cbc_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
outlen == 0 ||
(inlen % TC_AES_BLOCK_SIZE) != 0 ||
(outlen % TC_AES_BLOCK_SIZE) != 0 ||
outlen != inlen - TC_AES_BLOCK_SIZE) {
outlen != inlen) {
return TC_CRYPTO_FAIL;
}

Expand All @@ -101,7 +101,7 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
* that would not otherwise be possible.
*/
p = iv;
for (n = m = 0; n < inlen; ++n) {
for (n = m = 0; n < outlen; ++n) {
if ((n % TC_AES_BLOCK_SIZE) == 0) {
(void)tc_aes_decrypt(buffer, in, sched);
in += TC_AES_BLOCK_SIZE;
Expand Down
7 changes: 3 additions & 4 deletions tests/test_cbc_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ int test_1_and_2(void)
(void)tc_aes128_set_decrypt_key(&a, key);

p = &encrypted[TC_AES_BLOCK_SIZE];
length = ((unsigned int) sizeof(encrypted)) - TC_AES_BLOCK_SIZE;
length = ((unsigned int) sizeof(encrypted));

if (tc_cbc_mode_decrypt(decrypted, length - TC_AES_BLOCK_SIZE, p, length,
encrypted, &a) == 0) {
if (tc_cbc_mode_decrypt(decrypted, length, p, length, encrypted, &a) == 0) {
TC_ERROR("CBC test #2 (decryption SP 800-38a tests) failed in. "
"%s\n", __func__);
result = TC_FAIL;
Expand All @@ -161,7 +160,7 @@ int main(void)

TC_PRINT("Performing CBC tests:\n");
result = test_1_and_2();
if (result == TC_FAIL) {
if (result == TC_FAIL) {
/* terminate test */
TC_ERROR("CBC test #1 failed.\n");
goto exitTest;
Expand Down