Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 8a35f17

Browse files
author
hackermnementh
authored
Merge pull request #26 from rob-brown/master
Fix incorrect buffer size
2 parents b1fed54 + da923ca commit 8a35f17

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/source/cbc_mode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
9191
outlen == 0 ||
9292
(inlen % TC_AES_BLOCK_SIZE) != 0 ||
9393
(outlen % TC_AES_BLOCK_SIZE) != 0 ||
94-
outlen != inlen - TC_AES_BLOCK_SIZE) {
94+
outlen != inlen) {
9595
return TC_CRYPTO_FAIL;
9696
}
9797

@@ -101,7 +101,7 @@ int tc_cbc_mode_decrypt(uint8_t *out, unsigned int outlen, const uint8_t *in,
101101
* that would not otherwise be possible.
102102
*/
103103
p = iv;
104-
for (n = m = 0; n < inlen; ++n) {
104+
for (n = m = 0; n < outlen; ++n) {
105105
if ((n % TC_AES_BLOCK_SIZE) == 0) {
106106
(void)tc_aes_decrypt(buffer, in, sched);
107107
in += TC_AES_BLOCK_SIZE;

tests/test_cbc_mode.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@ int test_1_and_2(void)
132132
(void)tc_aes128_set_decrypt_key(&a, key);
133133

134134
p = &encrypted[TC_AES_BLOCK_SIZE];
135-
length = ((unsigned int) sizeof(encrypted)) - TC_AES_BLOCK_SIZE;
135+
length = ((unsigned int) sizeof(encrypted));
136136

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

162161
TC_PRINT("Performing CBC tests:\n");
163162
result = test_1_and_2();
164-
if (result == TC_FAIL) {
163+
if (result == TC_FAIL) {
165164
/* terminate test */
166165
TC_ERROR("CBC test #1 failed.\n");
167166
goto exitTest;

0 commit comments

Comments
 (0)