Skip to content
Merged
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
38 changes: 35 additions & 3 deletions wolfcrypt/src/port/riscv/riscv-64-aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,10 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
#endif /* WOLFSSL_AES_256 */
break;
default:
/* Not set or corrupted: match the generic wc_AesEncrypt
* (aes.c) behavior for an unusable key schedule. */
WOLFSSL_MSG("Bad AES-CTR round value");
ret = BAD_FUNC_ARG;
ret = KEYUSAGE_E;
}
}

Expand Down Expand Up @@ -2946,7 +2948,7 @@ int wc_AesSetKey(Aes* aes, const byte* key, word32 keyLen, const byte* iv,
int ret = 0;

/* Validate parameters. */
if (aes == NULL) {
if ((aes == NULL) || (key == NULL)) {
ret = BAD_FUNC_ARG;
}
/* Check key size is supported by AES object. */
Expand Down Expand Up @@ -4125,8 +4127,10 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
#endif /* WOLFSSL_AES_256 */
break;
default:
/* Not set or corrupted: match the generic wc_AesEncrypt
* (aes.c) behavior for an unusable key schedule. */
WOLFSSL_MSG("Bad AES-CTR round value");
ret = BAD_FUNC_ARG;
ret = KEYUSAGE_E;
}
}

Expand Down Expand Up @@ -4236,6 +4240,12 @@ int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in)
WOLFSSL_MSG("Invalid input to wc_AesEncryptDirect");
ret = BAD_FUNC_ARG;
}
/* wc_AesEncrypt is void here so it cannot report an unusable key
* schedule itself; match the generic wc_AesEncrypt (aes.c) check. */
if ((ret == 0) &&
(((aes->rounds >> 1) > 7) || ((aes->rounds >> 1) == 0))) {
ret = KEYUSAGE_E;
}
if (ret == 0) {
wc_AesEncrypt(aes, in, out);
}
Expand All @@ -4259,6 +4269,12 @@ int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in)
WOLFSSL_MSG("Invalid input to wc_AesDecryptDirect");
ret = BAD_FUNC_ARG;
}
/* wc_AesDecrypt is void here so it cannot report an unusable key
* schedule itself; match the generic wc_AesDecrypt (aes.c) check. */
if ((ret == 0) &&
(((aes->rounds >> 1) > 7) || ((aes->rounds >> 1) == 0))) {
ret = KEYUSAGE_E;
}
if (ret == 0) {
wc_AesDecrypt(aes, in, out);
}
Expand Down Expand Up @@ -9097,10 +9113,18 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,

/* sanity check on arguments */
if ((aes == NULL) || ((inSz != 0) && ((in == NULL) || (out == NULL))) ||
((authInSz > 0) && (authIn == NULL)) ||
(nonce == NULL) || (authTag == NULL) || (nonceSz < 7) ||
(nonceSz > 13)) {
ret = BAD_FUNC_ARG;
}
/* The block cipher helpers are void here so they cannot report an
* unusable key schedule; match the generic wc_AesEncrypt (aes.c)
* check. */
if ((ret == 0) &&
(((aes->rounds >> 1) > 7) || ((aes->rounds >> 1) == 0))) {
ret = KEYUSAGE_E;
}

if ((ret == 0) && (wc_AesCcmCheckTagSize(authTagSz) != 0)) {
ret = BAD_FUNC_ARG;
Expand Down Expand Up @@ -9188,10 +9212,18 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,

/* sanity check on arguments */
if ((aes == NULL) || ((inSz != 0) && ((in == NULL) || (out == NULL))) ||
((authInSz > 0) && (authIn == NULL)) ||
(nonce == NULL) || (authTag == NULL) || (nonceSz < 7) ||
(nonceSz > 13)) {
ret = BAD_FUNC_ARG;
}
/* The block cipher helpers are void here so they cannot report an
* unusable key schedule; match the generic wc_AesEncrypt (aes.c)
* check. */
if ((ret == 0) &&
(((aes->rounds >> 1) > 7) || ((aes->rounds >> 1) == 0))) {
ret = KEYUSAGE_E;
}

if ((ret == 0) && (wc_AesCcmCheckTagSize(authTagSz) != 0)) {
ret = BAD_FUNC_ARG;
Expand Down
Loading