-
Notifications
You must be signed in to change notification settings - Fork 1k
Crypto layer: Add missing input validation #10819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,6 +89,10 @@ int wc_PRF(byte* result, word32 resLen, const byte* secret, | |||||||||||
| Hmac hmac[1]; | ||||||||||||
| #endif | ||||||||||||
|
|
||||||||||||
| if ((result == NULL && resLen != 0) || (secret == NULL && secLen != 0) || | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ [Info] Non-conforming indentation in wc_PRF NULL-argument check The new NULL-check block uses 3-space continuation indentation and a 2-space indent on the Suggestion:
Suggested change
|
||||||||||||
| (seed == NULL && seedLen != 0)) | ||||||||||||
| return BAD_FUNC_ARG; | ||||||||||||
|
|
||||||||||||
| switch (hash) { | ||||||||||||
| #ifndef NO_MD5 | ||||||||||||
| case md5_mac: | ||||||||||||
|
|
@@ -234,8 +238,18 @@ int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret, | |||||||||||
| WC_DECLARE_VAR(sha_result, byte, MAX_PRF_DIG, heap); /* digLen is real size */ | ||||||||||||
| WC_DECLARE_VAR(labelSeed, byte, MAX_PRF_LABSEED, heap); | ||||||||||||
|
|
||||||||||||
| if ((digest == NULL && digLen != 0) || | ||||||||||||
| (secret == NULL && secLen != 0) || | ||||||||||||
| (label == NULL && labLen != 0) || | ||||||||||||
| (seed == NULL && seedLen != 0)) { | ||||||||||||
| return BAD_FUNC_ARG; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /* labLen + seedLen is checked with subtraction to avoid word32 wraparound | ||||||||||||
| * (the labLen bound first ensures MAX_PRF_LABSEED - labLen cannot | ||||||||||||
| * underflow). */ | ||||||||||||
| if (half > MAX_PRF_HALF || | ||||||||||||
| labLen + seedLen > MAX_PRF_LABSEED || | ||||||||||||
| labLen > MAX_PRF_LABSEED || seedLen > (MAX_PRF_LABSEED - labLen) || | ||||||||||||
| digLen > MAX_PRF_DIG) | ||||||||||||
| { | ||||||||||||
| return BUFFER_E; | ||||||||||||
|
lealem47 marked this conversation as resolved.
|
||||||||||||
|
|
@@ -251,8 +265,10 @@ int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret, | |||||||||||
| sha_half = secret + half - secLen % 2; | ||||||||||||
| md5_result = digest; | ||||||||||||
|
|
||||||||||||
| XMEMCPY(labelSeed, label, labLen); | ||||||||||||
| XMEMCPY(labelSeed + labLen, seed, seedLen); | ||||||||||||
| if (labLen != 0) | ||||||||||||
| XMEMCPY(labelSeed, label, labLen); | ||||||||||||
| if (seedLen != 0) | ||||||||||||
| XMEMCPY(labelSeed + labLen, seed, seedLen); | ||||||||||||
|
|
||||||||||||
| if ((ret = wc_PRF(md5_result, digLen, md5_half, half, labelSeed, | ||||||||||||
| labLen + seedLen, md5_mac, heap, devId)) == 0) { | ||||||||||||
|
|
@@ -286,6 +302,13 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen, | |||||||||||
| { | ||||||||||||
| int ret = 0; | ||||||||||||
|
|
||||||||||||
| if ((digest == NULL && digLen != 0) || | ||||||||||||
| (secret == NULL && secLen != 0) || | ||||||||||||
| (label == NULL && labLen != 0) || | ||||||||||||
| (seed == NULL && seedLen != 0)) { | ||||||||||||
| return BAD_FUNC_ARG; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| #ifdef WOLFSSL_DEBUG_TLS | ||||||||||||
| WOLFSSL_MSG(" secret"); | ||||||||||||
| WOLFSSL_BUFFER(secret, secLen); | ||||||||||||
|
|
@@ -298,15 +321,19 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen, | |||||||||||
| if (useAtLeastSha256) { | ||||||||||||
| WC_DECLARE_VAR(labelSeed, byte, MAX_PRF_LABSEED, 0); | ||||||||||||
|
|
||||||||||||
| if (labLen + seedLen > MAX_PRF_LABSEED) { | ||||||||||||
| /* Checked with subtraction to avoid word32 wraparound of | ||||||||||||
| * labLen + seedLen. */ | ||||||||||||
| if (labLen > MAX_PRF_LABSEED || seedLen > (MAX_PRF_LABSEED - labLen)) { | ||||||||||||
| return BUFFER_E; | ||||||||||||
|
lealem47 marked this conversation as resolved.
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| WC_ALLOC_VAR_EX(labelSeed, byte, MAX_PRF_LABSEED, heap, | ||||||||||||
| DYNAMIC_TYPE_DIGEST, return MEMORY_E); | ||||||||||||
|
|
||||||||||||
| XMEMCPY(labelSeed, label, labLen); | ||||||||||||
| XMEMCPY(labelSeed + labLen, seed, seedLen); | ||||||||||||
| if (labLen != 0) | ||||||||||||
| XMEMCPY(labelSeed, label, labLen); | ||||||||||||
| if (seedLen != 0) | ||||||||||||
| XMEMCPY(labelSeed + labLen, seed, seedLen); | ||||||||||||
|
|
||||||||||||
| /* If a cipher suite wants an algorithm better than sha256, it | ||||||||||||
| * should use better. */ | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1825,7 +1825,7 @@ static int RsaUnPad_OAEP(byte *pkcsBlock, unsigned int pkcsBlockLen, | |||||||||||||
| if (ret != 0) { | ||||||||||||||
| ForceZero(tmp, hLen); | ||||||||||||||
| #ifdef WOLFSSL_SMALL_STACK | ||||||||||||||
| XFREE(tmp, NULL, DYNAMIC_TYPE_RSA_BUFFER); | ||||||||||||||
| XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER); | ||||||||||||||
| #elif defined(WOLFSSL_CHECK_MEM_ZERO) | ||||||||||||||
| wc_MemZero_Check(tmp, hLen); | ||||||||||||||
| #endif | ||||||||||||||
|
|
@@ -5412,7 +5412,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) | |||||||||||||
| goto out; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #if defined(HAVE_FIPS) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 [Low] FIPS RSA exponent floor reuses WC_RSA_EXPONENT default macro The new FIPS branch rejects Suggestion:
Suggested change
|
||||||||||||||
| if (e < WC_RSA_EXPONENT || (e & 1) == 0) { | ||||||||||||||
| #else | ||||||||||||||
| if (e < 3 || (e & 1) == 0) { | ||||||||||||||
| #endif | ||||||||||||||
| err = BAD_FUNC_ARG; | ||||||||||||||
| goto out; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.