-
Notifications
You must be signed in to change notification settings - Fork 975
Fix SAKKE OOB write and correctness gap in sakke_hash_to_range #10442
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
Open
JeremiahM37
wants to merge
4
commits into
wolfSSL:master
Choose a base branch
from
JeremiahM37:zd21783
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−16
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6162,20 +6162,30 @@ static int sakke_calc_h_v(SakkeKey* key, enum wc_HashType hashType, | |
| static void sakke_xor_in_v(const byte* v, word32 hashSz, byte* out, word32 idx, | ||
| word32 n) | ||
| { | ||
| int o; | ||
| word32 i; | ||
| word32 skip; | ||
| word32 off; | ||
| word32 len; | ||
|
|
||
| /* RFC 6508, Section 5.1: output is the low n octets of | ||
| * v_1||v_2||...||v_l (the concatenation of l hash outputs taken | ||
| * modulo 2^(n*8)). When n is not a multiple of hashSz, drop the | ||
| * leading 'skip' high bytes of the first hash output. */ | ||
| skip = n % hashSz; | ||
| skip = (skip == 0) ? 0 : (hashSz - skip); | ||
|
|
||
| if (idx == 0) { | ||
| i = hashSz - (n % hashSz); | ||
| if (i == hashSz) { | ||
| i = 0; | ||
| } | ||
| off = 0; | ||
| len = hashSz - skip; | ||
|
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. No need to assign to 'len' here - just put this into the xorbuf call. |
||
| xorbuf(out + off, v + skip, len); | ||
| } | ||
| else { | ||
| i = 0; | ||
| off = idx - skip; | ||
| len = n - off; | ||
| if (len > hashSz) { | ||
| len = hashSz; | ||
| } | ||
| xorbuf(out + off, v, len); | ||
| } | ||
| o = (int)i; | ||
| xorbuf(out + idx + i - o, v + i, hashSz - i); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -6682,8 +6692,9 @@ static int sakke_compute_point_r(SakkeKey* key, const byte* id, word16 idSz, | |
| * @param [out] auth Authentication data. | ||
| * @param [out] authSz Size of authentication data in bytes. | ||
| * @return 0 on success. | ||
| * @return BAD_FUNC_ARG when key, ssv or encSz is NULL, ssvSz is to big or | ||
| * encSz is too small. | ||
| * @return BAD_FUNC_ARG when key, ssv or authSz is NULL, ssvSz is 0 or | ||
| * larger than the curve modulus byte length, or *authSz is too | ||
| * small when encapsulating. | ||
| * @return BAD_STATE_E when identity not set. | ||
| * @return LENGTH_ONLY_E when auth is NULL. authSz contains required size of | ||
| * auth in bytes. | ||
|
|
@@ -6699,7 +6710,7 @@ int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key, enum wc_HashType hashType, | |
| word16 outSz = 0; | ||
| byte a[WC_MAX_DIGEST_SIZE]; | ||
|
|
||
| if ((key == NULL) || (ssv == NULL) || (authSz == NULL)) { | ||
| if ((key == NULL) || (ssv == NULL) || (authSz == NULL) || (ssvSz == 0)) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| if ((err == 0) && (key->idSz == 0)) { | ||
|
|
@@ -6718,7 +6729,14 @@ int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key, enum wc_HashType hashType, | |
| /* Uncompressed point */ | ||
| outSz = (word16)(1 + 2 * n); | ||
|
|
||
| if ((auth != NULL) && (*authSz < outSz)) { | ||
| /* RFC 6508, Section 6.2.1, Step 1 places SSV in 0..2^n-1, so | ||
| * ssvSz must be <= n. Enforced on both the encapsulation and | ||
| * size-query paths so callers cannot probe authSz with an | ||
| * invalid ssvSz. */ | ||
| if (ssvSz > n) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| else if ((auth != NULL) && (*authSz < outSz)) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| } | ||
|
|
@@ -6813,7 +6831,7 @@ int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv, word16* ssvSz) | |
| if (err == 0) { | ||
| n = (word16)WC_BITS_TO_BYTES(mp_count_bits(&key->params.prime)); | ||
|
|
||
| if ((ssv != NULL) && (*ssvSz > n)) { | ||
| if ((ssv != NULL) && ((*ssvSz == 0) || (*ssvSz > n))) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| } | ||
|
|
@@ -6857,7 +6875,8 @@ int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv, word16* ssvSz) | |
| * @param [in] auth Authentication data. | ||
| * @param [in] authSz Size of authentication data in bytes. | ||
| * @return 0 on success. | ||
| * @return BAD_FUNC_ARG when key, ssv or auth is NULL. | ||
| * @return BAD_FUNC_ARG when key, ssv or auth is NULL, ssvSz is 0 or | ||
| * larger than the curve modulus byte length. | ||
| * @return BAD_STATE_E when RSK or identity not set. | ||
| * @return SAKKE_VERIFY_FAIL_E when calculated R doesn't match the encapsulated | ||
| * data's R. | ||
|
|
@@ -6876,7 +6895,7 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv, | |
| byte* test = NULL; | ||
| byte a[WC_MAX_DIGEST_SIZE] = {0}; | ||
|
|
||
| if ((key == NULL) || (ssv == NULL) || (auth == NULL)) { | ||
| if ((key == NULL) || (ssv == NULL) || (auth == NULL) || (ssvSz == 0)) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| if ((err == 0) && (!key->rsk.set || (key->idSz == 0))) { | ||
|
|
@@ -6895,6 +6914,11 @@ int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType, byte* ssv, | |
| if (authSz != 2 * n + 1) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| /* RFC 6508, Section 6.2.1: SSV is in 0..2^n-1, so ssvSz must | ||
| * be <= n. */ | ||
| else if (ssvSz > n) { | ||
| err = BAD_FUNC_ARG; | ||
| } | ||
| } | ||
| if (err == 0) { | ||
| err = sakke_load_base_point(key); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for 'off' here.