-
Notifications
You must be signed in to change notification settings - Fork 15
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
Curve25519 fixes #83
Merged
Merged
Curve25519 fixes #83
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd13216
passing unit tests with new Curve25519 unified funcitons
bigbrett 74d47ba
cleanups
bigbrett 122d76d
remove unused functions
bigbrett affda77
added more debug printfs in verbose mode
bigbrett b634bc4
fixed CURVE25519 public key only serialization
bigbrett e42ddcd
removed unused definitions
bigbrett d237a02
removed erroneous comment out of test
bigbrett 9a87978
cleanup CI config
bigbrett 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 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 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 |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
#include "wolfssl/wolfcrypt/types.h" | ||
#include "wolfssl/wolfcrypt/error-crypt.h" | ||
#include "wolfssl/wolfcrypt/asn.h" | ||
#include "wolfssl/wolfcrypt/asn_public.h" | ||
#include "wolfssl/wolfcrypt/rsa.h" | ||
#include "wolfssl/wolfcrypt/curve25519.h" | ||
#include "wolfssl/wolfcrypt/ecc.h" | ||
|
@@ -207,49 +208,54 @@ int wh_Crypto_EccUpdatePrivateOnlyKeyDer(ecc_key* key, uint16_t pub_size, | |
#endif /* HAVE_ECC */ | ||
|
||
#ifdef HAVE_CURVE25519 | ||
int wh_Crypto_Curve25519SerializeKey(curve25519_key* key, | ||
uint16_t max_size, uint8_t* buffer, uint16_t *out_size) | ||
|
||
#ifdef HAVE_CURVE25519 | ||
#ifdef HAVE_CURVE25519_KEY_IMPORT | ||
WOLFSSL_API int wc_Curve25519PrivateKeyDecode( | ||
const byte* input, word32* inOutIdx, curve25519_key* key, word32 inSz); | ||
WOLFSSL_API int wc_Curve25519PublicKeyDecode( | ||
const byte* input, word32* inOutIdx, curve25519_key* key, word32 inSz); | ||
#endif | ||
#ifdef HAVE_CURVE25519_KEY_EXPORT | ||
WOLFSSL_API int wc_Curve25519PrivateKeyToDer( | ||
curve25519_key* key, byte* output, word32 inLen); | ||
WOLFSSL_API int wc_Curve25519PublicKeyToDer( | ||
curve25519_key* key, byte* output, word32 inLen, int withAlg); | ||
#endif | ||
#endif /* HAVE_CURVE25519 */ | ||
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. Aren't these already declared in asn_public.h? 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. yep, this should have been removed. fixed |
||
|
||
|
||
/* Store a curve25519_key to a byte sequence in DER format */ | ||
int wh_Crypto_Curve25519SerializeKey(curve25519_key* key, uint8_t* buffer, | ||
uint16_t* derSize) | ||
{ | ||
int ret = 0; | ||
word32 privSz = CURVE25519_KEYSIZE; | ||
word32 pubSz = CURVE25519_KEYSIZE; | ||
|
||
if ( (key == NULL) || | ||
(buffer == NULL)) { | ||
if ((key == NULL) || (buffer == NULL) || (derSize == NULL)) { | ||
return WH_ERROR_BADARGS; | ||
} | ||
|
||
ret = wc_curve25519_export_key_raw(key, | ||
buffer + CURVE25519_KEYSIZE, &privSz, | ||
buffer, &pubSz); | ||
if ( (ret == 0) && | ||
(out_size != NULL)) { | ||
*out_size = CURVE25519_KEYSIZE * 2; | ||
ret = wc_Curve25519KeyToDer(key, buffer, *derSize, 0); | ||
|
||
/* ASN.1 functions return the size of the DER encoded key on success */ | ||
if (ret > 0) { | ||
*derSize = ret; | ||
ret = WH_ERROR_OK; | ||
} | ||
return ret; | ||
} | ||
|
||
int wh_Crypto_Curve25519DeserializeKey(uint16_t size, | ||
const uint8_t* buffer, curve25519_key* key) | ||
/* Restore a curve25519_key from a byte sequence in DER format */ | ||
int wh_Crypto_Curve25519DeserializeKey(const uint8_t* derBuffer, | ||
uint16_t derSize, curve25519_key* key) | ||
{ | ||
int ret = 0; | ||
word32 privSz = CURVE25519_KEYSIZE; | ||
word32 pubSz = CURVE25519_KEYSIZE; | ||
word32 idx = 0; | ||
|
||
if ( (size < (CURVE25519_KEYSIZE * 2)) || | ||
(buffer == NULL) || | ||
(key == NULL)) { | ||
if ((derBuffer == NULL) || (key == NULL)) { | ||
return WH_ERROR_BADARGS; | ||
} | ||
|
||
/* decode the key */ | ||
if (ret == 0) { | ||
ret = wc_curve25519_import_private_raw( | ||
buffer + CURVE25519_KEYSIZE, privSz, | ||
buffer, pubSz, | ||
key); | ||
} | ||
return ret; | ||
return wc_Curve25519KeyDecode(derBuffer, &idx, key, derSize); | ||
} | ||
#endif /* HAVE_CURVE25519 */ | ||
|
||
|
This file contains 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 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.
asn.h include asn_public.h. Were you getting a compile warning/error without asn_public.h explicitly included?
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.
I'm dumb, removed