Skip to content

Commit

Permalink
Fix for AES-CFB1 encrypt/decrypt on size (8*x-1) bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Lealem Amedie committed Apr 18, 2024
1 parent d1efccd commit 2950334
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -11863,7 +11863,7 @@ static WARN_UNUSED_RESULT int wc_AesFeedbackCFB1(
}

if (ret == 0) {
if (bit > 0 && bit < 7) {
if (bit >= 0 && bit < 7) {
out[0] = cur;
}
}
Expand Down
14 changes: 14 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9152,6 +9152,11 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
{
0xC0
};

WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
{
0x1C
};
#endif /* WOLFSSL_AES_128 */
#ifdef WOLFSSL_AES_192
WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
Expand Down Expand Up @@ -9252,6 +9257,15 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
#endif /* HAVE_AES_DECRYPT */

XMEMSET(cipher, 0, sizeof(cipher));
ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);

if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);

if (cipher[0] != cipher1_7bit[0])
ERROR_OUT(WC_TEST_RET_ENC_NC, out);

#ifdef OPENSSL_EXTRA
ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
if (ret != 0)
Expand Down

0 comments on commit 2950334

Please sign in to comment.