-
Notifications
You must be signed in to change notification settings - Fork 38
F 1483 : Fix SHA-1 prefix match overwriting SHA-256/384/512 output #216
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: main
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -121,7 +121,7 @@ int wolfCLU_hash(WOLFSSL_BIO* bioIn, WOLFSSL_BIO* bioOut, const char* alg, | |||||||
| } | ||||||||
|
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] The fix is correct but the if-chain ordering is fragile In Suggestion:
Suggested change
|
||||||||
| #endif | ||||||||
| #ifndef NO_SHA | ||||||||
| if (ret == WOLFCLU_SUCCESS && XSTRNCMP(alg, "sha", 3) == 0) { | ||||||||
| if (ret == WOLFCLU_SUCCESS && XSTRCMP(alg, "sha") == 0) { | ||||||||
| ret = wc_ShaHash(input, inputSz, output); | ||||||||
| } | ||||||||
| #endif | ||||||||
|
|
||||||||
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.
🟡 [Medium] Remaining XSTRNCMP calls could be made consistent with the fix
💡 SUGGEST
conventionThe PR correctly changes
XSTRNCMP(alg, "sha", 3)toXSTRCMP(alg, "sha")to prevent the SHA-1 branch from matching sha256/sha384/sha512. However, other algorithm checks in bothwolfCLU_hash()andwolfCLU_hashSetup()still useXSTRNCMP(e.g.,XSTRNCMP(alg, "md5", 3)at clu_hash.c:104,XSTRNCMP(alg, "md5", 3)at clu_hash_setup.c:138). While these are functionally safe today because none of those prefixes collide with other algorithm names,wolfCLU_hash()is a public function that acceptsalgfrom external callers (e.g.,clu_alg_hash.c). Switching all comparisons toXSTRCMPwould be more defensive and consistent with the spirit of this fix — preventing future prefix-collision bugs if new algorithms are added.Suggestion: