-
Notifications
You must be signed in to change notification settings - Fork 1k
Add crypto callback only mode for ed25519 #10830
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
2
commits into
wolfSSL:master
Choose a base branch
from
padelsbach:ed25519-cryptocb-only
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.
Open
Changes from all commits
Commits
Show all changes
2 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
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
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 |
|---|---|---|
|
|
@@ -376,14 +376,20 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key) | |
| key->pubKeySet = 0; | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB | ||
| if (key->devId != INVALID_DEVID) { | ||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed25519Gen(rng, keySz, key); | ||
| if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) | ||
| return ret; | ||
| /* fall-through when unavailable */ | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB_ONLY_ED25519 | ||
| return NO_VALID_DEVID; | ||
| #else | ||
| ret = wc_RNG_GenerateBlock(rng, key->k, ED25519_KEY_SIZE); | ||
| if (ret != 0) | ||
| return ret; | ||
|
|
@@ -407,6 +413,7 @@ int wc_ed25519_make_key(WC_RNG* rng, int keySz, ed25519_key* key) | |
| #endif | ||
|
|
||
| return ret; | ||
| #endif /* WOLF_CRYPTO_CB_ONLY_ED25519 */ | ||
| } | ||
| #endif /* HAVE_ED25519_MAKE_KEY */ | ||
|
|
||
|
|
@@ -434,6 +441,30 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out, | |
| (void)contextLen; | ||
| (void)type; | ||
| ret = se050_ed25519_sign_msg(in, inLen, out, outLen, key); | ||
| #elif defined(WOLF_CRYPTO_CB_ONLY_ED25519) | ||
| ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); | ||
|
|
||
| if (in == NULL || out == NULL || outLen == NULL || key == NULL || | ||
| (context == NULL && contextLen != 0)) { | ||
| return BAD_FUNC_ARG; | ||
| } | ||
|
|
||
| if ((type == Ed25519ph) && | ||
| (inLen != WC_SHA512_DIGEST_SIZE)) | ||
| { | ||
| return BAD_LENGTH_E; | ||
| } | ||
|
|
||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed25519Sign(in, inLen, out, outLen, key, type, | ||
| context, contextLen); | ||
| } | ||
| if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) { | ||
| ret = NO_VALID_DEVID; | ||
| } | ||
| #else | ||
| #ifdef FREESCALE_LTC_ECC | ||
| ALIGN16 byte tempBuf[ED25519_PRV_KEY_SIZE]; | ||
|
|
@@ -461,7 +492,10 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out, | |
| } | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB | ||
| if (key->devId != INVALID_DEVID) { | ||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed25519Sign(in, inLen, out, outLen, key, type, | ||
| context, contextLen); | ||
| if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) | ||
|
|
@@ -599,7 +633,8 @@ int wc_ed25519_sign_msg_ex(const byte* in, word32 inLen, byte* out, | |
| ForceZero(nonce, sizeof(nonce)); | ||
| #endif /* WOLFSSL_SE050 */ | ||
|
|
||
| #ifdef WOLFSSL_EDDSA_CHECK_PRIV_ON_SIGN | ||
| #if defined(WOLFSSL_EDDSA_CHECK_PRIV_ON_SIGN) && \ | ||
| !defined(WOLF_CRYPTO_CB_ONLY_ED25519) | ||
|
Comment on lines
+636
to
+637
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. To me it looks like that the priv check must be inside the software blocks, not outside. So this is a bug that predate the PR. Probably a good idea to move it inside that software block instead of gating on !ONLY_ED25519, or just ignore it in this PR. |
||
| if (ret == 0) { | ||
| int i; | ||
| byte c = 0; | ||
|
|
@@ -696,7 +731,7 @@ int wc_ed25519ph_sign_msg(const byte* in, word32 inLen, byte* out, | |
| #endif /* HAVE_ED25519_SIGN */ | ||
|
|
||
| #ifdef HAVE_ED25519_VERIFY | ||
| #ifndef WOLFSSL_SE050 | ||
| #if !defined(WOLFSSL_SE050) && !defined(WOLF_CRYPTO_CB_ONLY_ED25519) | ||
|
|
||
| #ifdef WOLFSSL_CHECK_VER_FAULTS | ||
| static const byte sha512_empty[] = { | ||
|
|
@@ -928,7 +963,7 @@ static int ed25519_verify_msg_final_with_sha(const byte* sig, word32 sigLen, | |
|
|
||
| return ret; | ||
| } | ||
| #endif /* WOLFSSL_SE050 */ | ||
| #endif /* !WOLFSSL_SE050 && !WOLF_CRYPTO_CB_ONLY_ED25519 */ | ||
|
|
||
| #if defined(WOLFSSL_ED25519_STREAMING_VERIFY) && !defined(WOLFSSL_SE050) | ||
|
|
||
|
|
@@ -972,6 +1007,30 @@ int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg, | |
| (void)contextLen; | ||
| (void)ed25519Ctx; | ||
| ret = se050_ed25519_verify_msg(sig, sigLen, msg, msgLen, key, res); | ||
| #elif defined(WOLF_CRYPTO_CB_ONLY_ED25519) | ||
| (void)ed25519Ctx; | ||
| ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); | ||
|
|
||
| if (sig == NULL || msg == NULL || res == NULL || key == NULL || | ||
| (context == NULL && contextLen != 0)) | ||
| return BAD_FUNC_ARG; | ||
|
|
||
| if ((type == Ed25519ph) && | ||
| (msgLen != WC_SHA512_DIGEST_SIZE)) | ||
| { | ||
| return BAD_LENGTH_E; | ||
| } | ||
|
|
||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed25519Verify(sig, sigLen, msg, msgLen, res, key, | ||
| type, context, contextLen); | ||
| } | ||
| if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) { | ||
| ret = NO_VALID_DEVID; | ||
| } | ||
| #else | ||
| #ifdef WOLFSSL_ED25519_PERSISTENT_SHA | ||
| wc_Sha512 *sha; | ||
|
|
@@ -991,7 +1050,10 @@ int wc_ed25519_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg, | |
| } | ||
|
|
||
| #ifdef WOLF_CRYPTO_CB | ||
| if (key->devId != INVALID_DEVID) { | ||
| #ifndef WOLF_CRYPTO_CB_FIND | ||
| if (key->devId != INVALID_DEVID) | ||
| #endif | ||
| { | ||
| ret = wc_CryptoCb_Ed25519Verify(sig, sigLen, msg, msgLen, res, key, | ||
| type, context, contextLen); | ||
| if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) | ||
|
|
||
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.
Semi-related change to add these missing guards. The cb find mechanism would have failed here.