From 28bc7540dd420114dc33371e181b5617a4a66611 Mon Sep 17 00:00:00 2001 From: night1rider Date: Wed, 7 Oct 2026 09:26:40 -0600 Subject: [PATCH] AES: leave WC_AES_DIRECT_CRYPTO_CB off for WOLFSSL_TI_CRYPT, and tie the Direct docs to it Docs say a device that owns the key must not decline; test comments shortened to one line. --- doc/dox_comments/header_files/aes.h | 20 ++++++++++++++------ tests/api/test_aes.c | 24 ++++++++---------------- wolfssl/wolfcrypt/aes.h | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/dox_comments/header_files/aes.h b/doc/dox_comments/header_files/aes.h index addb9b8bfb..0fd0ee9a59 100644 --- a/doc/dox_comments/header_files/aes.h +++ b/doc/dox_comments/header_files/aes.h @@ -222,12 +222,16 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, wc_AesSetKey should have been called with the iv set to NULL. This is only enabled if the configure option WOLFSSL_AES_DIRECT is enabled. __Warning:__ In nearly all use cases ECB mode is considered to be less secure. Please - avoid using ECB API’s directly whenever possible. With WOLF_CRYPTO_CB, if + avoid using ECB API’s directly whenever possible. When + WC_AES_DIRECT_CRYPTO_CB is defined (set automatically for WOLF_CRYPTO_CB + builds that use the generic AES Direct code, not a port's own version), if the AES object has a crypto callback device (devId), that device is asked first to encrypt the block as a one-block ECB request. The software key is used only if the device declines, and a device error is returned as-is. - With WOLF_CRYPTO_CB_FIND, the device find callback picks the device, so a - device can be asked even when the AES object has no devId. + A device that owns the key must handle the request or return an error; it + must not return CRYPTOCB_UNAVAILABLE. With WOLF_CRYPTO_CB_FIND, the device + find callback picks the device, so a device can be asked even when the AES + object has no devId. \return int integer values corresponding to wolfSSL error or success status @@ -261,12 +265,16 @@ int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in); wc_AesSetKey should have been called with the iv set to NULL. This is only enabled if the configure option WOLFSSL_AES_DIRECT is enabled. __Warning:__ In nearly all use cases ECB mode is considered to be less secure. Please - avoid using ECB API’s directly whenever possible. With WOLF_CRYPTO_CB, if + avoid using ECB API’s directly whenever possible. When + WC_AES_DIRECT_CRYPTO_CB is defined (set automatically for WOLF_CRYPTO_CB + builds that use the generic AES Direct code, not a port's own version), if the AES object has a crypto callback device (devId), that device is asked first to decrypt the block as a one-block ECB request. The software key is used only if the device declines, and a device error is returned as-is. - With WOLF_CRYPTO_CB_FIND, the device find callback picks the device, so a - device can be asked even when the AES object has no devId. + A device that owns the key must handle the request or return an error; it + must not return CRYPTOCB_UNAVAILABLE. With WOLF_CRYPTO_CB_FIND, the device + find callback picks the device, so a device can be asked even when the AES + object has no devId. \return int integer values corresponding to wolfSSL error or success status diff --git a/tests/api/test_aes.c b/tests/api/test_aes.c index 8267fd4012..54989dd494 100644 --- a/tests/api/test_aes.c +++ b/tests/api/test_aes.c @@ -12135,12 +12135,10 @@ int test_wc_CryptoCb_AesKeyWrapEcbCompose(void) #include -/* Mock device for the Direct API: counts the one-block ECB requests. It - * declines them, fails them, or does them itself, based on the flags. */ +/* Mock device: counts one-block ECB requests; declines, fails or does them. */ #define TEST_CRYPTOCB_AES_DIRECT_DEVID 15 -/* What the mock device writes when it does the work. Software would never - * produce this, so it proves software did not run afterwards. */ +/* Mock device output; software never makes it, so it proves no software run */ #define TEST_CRYPTOCB_AES_DIRECT_MARK 0xA5 static int cbDirectEncCalled = 0; @@ -12164,8 +12162,7 @@ static int test_CryptoCb_AesDirect_FindCb(int currentId, int algoType) #if defined(WOLF_CRYPTO_CB_AES_SETKEY) || defined(WOLF_CRYPTO_CB_SETKEY) #define TEST_CRYPTOCB_AES_DIRECT_OWN_KEY -/* Device owns the key: it takes SetKey, so wolfSSL keeps no software key, - * and it runs each block itself with the key it was given. */ +/* Device owns the key: it takes SetKey and runs each block with that key */ static int cbDirectOwnKey = 0; static byte cbDirectKey[AES_MAX_KEY_SIZE / 8]; static word32 cbDirectKeySz = 0; @@ -12329,8 +12326,7 @@ int test_wc_CryptoCb_AesDirect(void) wc_AesFree(&aes); cbDirectFail = 0; - /* Device does the work: its output must be returned as-is, with no - * software run afterwards */ + /* Device does the work: its output is returned as-is, no software run */ cbDirectHandle = 1; XMEMSET(mark, TEST_CRYPTOCB_AES_DIRECT_MARK, sizeof(mark)); XMEMSET(&aes, 0, sizeof(aes)); @@ -12349,8 +12345,7 @@ int test_wc_CryptoCb_AesDirect(void) ExpectIntEQ(cbDirectDecCalled, 3); wc_AesFree(&aes); - /* No key set at all: the device still gets asked first and its result - * wins. If it declines, the software key check gives MISSING_KEY. */ + /* No key: device is still asked first; if it declines, MISSING_KEY */ cbDirectEncCalled = 0; cbDirectDecCalled = 0; cbDirectHandle = 1; @@ -12373,8 +12368,7 @@ int test_wc_CryptoCb_AesDirect(void) #endif wc_AesFree(&aes); - /* No device on this Aes: the registered device must not be asked, and - * software gives the answer. If it were asked, out would be the mark. */ + /* No device on this Aes: the registered device is not asked */ cbDirectEncCalled = 0; cbDirectDecCalled = 0; cbDirectHandle = 1; @@ -12396,8 +12390,7 @@ int test_wc_CryptoCb_AesDirect(void) cbDirectHandle = 0; #ifdef WOLF_CRYPTO_CB_FIND - /* Find mode: the finder sends a no-device Aes to the mock, so Direct - * must ask it, and the mock's output must be returned as-is */ + /* Find mode: a no-device Aes still reaches the mock through the finder */ wc_CryptoCb_SetDeviceFindCb(test_CryptoCb_AesDirect_FindCb); cbDirectEncCalled = 0; cbDirectDecCalled = 0; @@ -12427,8 +12420,7 @@ int test_wc_CryptoCb_AesDirect(void) #endif /* WOLF_CRYPTO_CB_FIND */ #ifdef TEST_CRYPTOCB_AES_DIRECT_OWN_KEY - /* Device owns the key: wolfSSL has no software key, so the right answer - * can only come from the device. Software would give a wrong block. */ + /* Device owns the key: only the device can give the right answer */ cbDirectOwnKey = 1; cbDirectEncCalled = 0; cbDirectDecCalled = 0; diff --git a/wolfssl/wolfcrypt/aes.h b/wolfssl/wolfcrypt/aes.h index a97930eb92..3438d127fb 100644 --- a/wolfssl/wolfcrypt/aes.h +++ b/wolfssl/wolfcrypt/aes.h @@ -241,7 +241,7 @@ WOLFSSL_LOCAL void WC_ARG_NOT_NULL(1) GHASH(Gcm* gcm, const byte* a, !(defined(MAX3266X_CB) && defined(HAVE_AES_ECB)) && \ !(defined(WOLFSSL_IMX6_CAAM) && !defined(NO_IMX6_CAAM_AES) && \ !defined(WOLFSSL_QNX_CAAM)) && !defined(WOLFSSL_AFALG) && \ - !defined(WOLFSSL_DEVCRYPTO_AES) && \ + !defined(WOLFSSL_DEVCRYPTO_AES) && !defined(WOLFSSL_TI_CRYPT) && \ (!defined(HAVE_FIPS) || !defined(HAVE_FIPS_VERSION) || \ (HAVE_FIPS_VERSION > 6)) && !defined(HAVE_SELFTEST) #define WC_AES_DIRECT_CRYPTO_CB