-
Notifications
You must be signed in to change notification settings - Fork 35
Fix sha512 buffer copy #333
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
padelsbach
wants to merge
1
commit into
wolfSSL:main
Choose a base branch
from
padelsbach:sha512-alt-modes
base: main
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.
+240
−30
Open
Changes from all commits
Commits
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
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
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 |
|---|---|---|
|
|
@@ -1950,6 +1950,149 @@ static int whTest_CryptoSha512(whClientContext* ctx, int devId, WC_RNG* rng) | |
| } | ||
| return ret; | ||
| } | ||
|
|
||
| #if !defined(WOLFSSL_NOSHA512_224) | ||
| static int whTest_CryptoSha512_224(whClientContext* ctx, int devId, | ||
|
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. a multiblock test is missing |
||
| WC_RNG* rng) | ||
| { | ||
| (void)ctx; | ||
| (void)rng; | ||
| int ret = WH_ERROR_OK; | ||
| wc_Sha512 sha512[1]; | ||
| /* Buffer sized for the variant, plus canary to detect overwrite */ | ||
| uint8_t out[WC_SHA512_224_DIGEST_SIZE + 8]; | ||
| const uint8_t canary = 0xA5; | ||
|
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. any reason why to rely on canary and not ASAN? |
||
| /* Same one-block input vector as the SHA512 test */ | ||
| const char inOne[] = | ||
| "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
| "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | ||
| const uint8_t expectedOut[WC_SHA512_224_DIGEST_SIZE] = { | ||
| 0x26, 0x1b, 0x94, 0xbc, 0xba, 0x55, 0x42, 0x64, | ||
| 0xb3, 0xb7, 0x38, 0xe9, 0xe0, 0x9e, 0x7d, 0xc6, | ||
| 0x8a, 0xc8, 0xe0, 0xb4, 0xc8, 0x51, 0x7f, 0xe9, | ||
| 0xbb, 0x7c, 0x36, 0x17}; | ||
|
|
||
| /* Fill canary bytes after the digest area */ | ||
| memset(out, canary, sizeof(out)); | ||
|
|
||
| ret = wc_InitSha512_224_ex(sha512, NULL, devId); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_InitSha512_224 on devId 0x%X: " | ||
| "%d\n", devId, ret); | ||
| } | ||
| else { | ||
| ret = wc_Sha512_224Update(sha512, (const byte*)inOne, | ||
| WC_SHA512_BLOCK_SIZE); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_Sha512_224Update %d\n", ret); | ||
| } | ||
| else { | ||
| ret = wc_Sha512_224Final(sha512, out); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_Sha512_224Final %d\n", | ||
| ret); | ||
| } | ||
| else { | ||
| if (memcmp(out, expectedOut, | ||
| WC_SHA512_224_DIGEST_SIZE) != 0) { | ||
| WH_ERROR_PRINT("SHA512/224 hash mismatch.\n"); | ||
| ret = -1; | ||
| } | ||
| else { | ||
| /* Verify canary was not overwritten */ | ||
| int i; | ||
| for (i = WC_SHA512_224_DIGEST_SIZE; | ||
| i < (int)sizeof(out); i++) { | ||
| if (out[i] != canary) { | ||
| WH_ERROR_PRINT("SHA512/224 overwrote " | ||
| "buffer at byte %d\n", i); | ||
| ret = -1; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| (void)wc_Sha512_224Free(sha512); | ||
| } | ||
| if (ret == 0) { | ||
| WH_TEST_PRINT("SHA512/224 DEVID=0x%X SUCCESS\n", devId); | ||
| } | ||
| return ret; | ||
| } | ||
| #endif /* !WOLFSSL_NOSHA512_224 */ | ||
|
|
||
| #if !defined(WOLFSSL_NOSHA512_256) | ||
| static int whTest_CryptoSha512_256(whClientContext* ctx, int devId, | ||
| WC_RNG* rng) | ||
| { | ||
| (void)ctx; | ||
| (void)rng; | ||
| int ret = WH_ERROR_OK; | ||
| wc_Sha512 sha512[1]; | ||
| /* Buffer sized for the variant, plus canary to detect overwrite */ | ||
| uint8_t out[WC_SHA512_256_DIGEST_SIZE + 8]; | ||
| const uint8_t canary = 0xA5; | ||
| /* Same one-block input vector as the SHA512 test */ | ||
| const char inOne[] = | ||
| "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
| "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | ||
| const uint8_t expectedOut[WC_SHA512_256_DIGEST_SIZE] = { | ||
| 0xb8, 0x8f, 0x97, 0xe2, 0x74, 0xf9, 0xc1, 0xd4, | ||
| 0x9f, 0x18, 0x1c, 0x8c, 0xbd, 0x01, 0xa9, 0xc7, | ||
| 0x49, 0x30, 0xad, 0x05, 0x5a, 0x46, 0xac, 0x44, | ||
| 0x99, 0xa1, 0xd6, 0x01, 0xf1, 0xc8, 0x0b, 0xf2}; | ||
|
|
||
| /* Fill canary bytes after the digest area */ | ||
| memset(out, canary, sizeof(out)); | ||
|
|
||
| ret = wc_InitSha512_256_ex(sha512, NULL, devId); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_InitSha512_256 on devId 0x%X: " | ||
| "%d\n", devId, ret); | ||
| } | ||
| else { | ||
| ret = wc_Sha512_256Update(sha512, (const byte*)inOne, | ||
| WC_SHA512_BLOCK_SIZE); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_Sha512_256Update %d\n", ret); | ||
| } | ||
| else { | ||
| ret = wc_Sha512_256Final(sha512, out); | ||
| if (ret != 0) { | ||
| WH_ERROR_PRINT("Failed to wc_Sha512_256Final %d\n", | ||
| ret); | ||
| } | ||
| else { | ||
| if (memcmp(out, expectedOut, | ||
| WC_SHA512_256_DIGEST_SIZE) != 0) { | ||
| WH_ERROR_PRINT("SHA512/256 hash mismatch.\n"); | ||
| ret = -1; | ||
| } | ||
| else { | ||
| /* Verify canary was not overwritten */ | ||
| int i; | ||
| for (i = WC_SHA512_256_DIGEST_SIZE; | ||
| i < (int)sizeof(out); i++) { | ||
| if (out[i] != canary) { | ||
| WH_ERROR_PRINT("SHA512/256 overwrote " | ||
| "buffer at byte %d\n", i); | ||
| ret = -1; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| (void)wc_Sha512_256Free(sha512); | ||
| } | ||
| if (ret == 0) { | ||
| WH_TEST_PRINT("SHA512/256 DEVID=0x%X SUCCESS\n", devId); | ||
| } | ||
| return ret; | ||
| } | ||
| #endif /* !WOLFSSL_NOSHA512_256 */ | ||
|
|
||
| #endif /* WOLFSSL_SHA512 */ | ||
|
|
||
| #ifdef HAVE_HKDF | ||
|
|
@@ -5915,6 +6058,24 @@ int whTest_CryptoClientConfig(whClientConfig* config) | |
| i++; | ||
| } | ||
| } | ||
| #if !defined(WOLFSSL_NOSHA512_224) | ||
| i = 0; | ||
| while ((ret == WH_ERROR_OK) && (i < WH_NUM_DEVIDS)) { | ||
| ret = whTest_CryptoSha512_224(client, WH_DEV_IDS_ARRAY[i], rng); | ||
| if (ret == WH_ERROR_OK) { | ||
| i++; | ||
| } | ||
| } | ||
| #endif /* !WOLFSSL_NOSHA512_224 */ | ||
| #if !defined(WOLFSSL_NOSHA512_256) | ||
| i = 0; | ||
| while ((ret == WH_ERROR_OK) && (i < WH_NUM_DEVIDS)) { | ||
| ret = whTest_CryptoSha512_256(client, WH_DEV_IDS_ARRAY[i], rng); | ||
| if (ret == WH_ERROR_OK) { | ||
| i++; | ||
| } | ||
| } | ||
| #endif /* !WOLFSSL_NOSHA512_256 */ | ||
| #endif /* WOLFSSL_SHA512 */ | ||
|
|
||
| #ifdef HAVE_HKDF | ||
|
|
||
Oops, something went wrong.
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.
neither
wh_Server_HandleCryptoDmaRequestnorwh_Server_HandleCryptoRequesthanlde SHA512 length variants (wolfHSM/src/wh_server_crypto.c
Lines 4700 to 4711 in 752ca63
This request is never handled by the server.
Test fallback to client side, that's the reason tests are not failing.