Repository navigation
Add support for X448 and Ed448 (take 2) - #5481
mattcaswell wants to merge 8 commits into
Conversation
This adds all of the relevant EVP plumbing required to make X448 and Ed448 work.
This adds the Ed448 test vectors from RFC8032 and the X448 test vectors from RFC7748.
richsalz
left a comment
There was a problem hiding this comment.
Most are nits, one (priv rand) is important.
|
|
||
| #define ED448_SIGSIZE 114 | ||
|
|
||
| #define ISX448(id) ((id) == EVP_PKEY_X448 ? 1 : 0) |
There was a problem hiding this comment.
Are the ?: really needed?
There was a problem hiding this comment.
I guess. I removed them
| X25519_PUBLIC, | ||
| X25519_PRIVATE, | ||
| X25519_KEYGEN | ||
| KEY_OP_PUBLIC, |
There was a problem hiding this comment.
Side note: I prefer adding a name to the enum, too.
| OPENSSL_free(xkey); | ||
| return 0; | ||
| if (op == KEY_OP_KEYGEN) { | ||
| if (RAND_bytes(privkey, KEYLENID(id)) <= 0) { |
There was a problem hiding this comment.
Should use RAND_priv_bytes
| X509_ALGOR *alg1, X509_ALGOR *alg2, | ||
| ASN1_BIT_STRING *str) | ||
| { | ||
| /* Set algorithms identifiers */ |
There was a problem hiding this comment.
Maybe "Set algorithm identifier"
|
|
||
| The X25519 algorithm does not currently support any key generation options. | ||
| The X25519 and X448 algorithms do not currently support any key generation | ||
| options. |
There was a problem hiding this comment.
extra blank line before the NOTES header.
|
|
||
| Ed25519 - EVP_PKEY Ed25519 support | ||
| Ed25519, | ||
| Ed448 |
There was a problem hiding this comment.
missing dash before the text on line 7
| digest sign and digest verify using PureEdDSA and B<Ed25519> (see RFC8032). | ||
| It has associated private and public key formats compatible with | ||
| The B<Ed25519> and B<Ed448> EVP_PKEY implementation supports key generation, one | ||
| shot digest sign and digest verify using PureEdDSA and B<Ed25519> or B<Ed448> |
|
|
||
| static int ecd_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, | ||
| static int ecd_item_sign25519(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, | ||
| X509_ALGOR *alg1, X509_ALGOR *alg2, |
There was a problem hiding this comment.
style: indent with/on previous line
| return 1; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
style : useful blank line ?
|
|
||
| static int ecd_sig_info_set(X509_SIG_INFO *siginf, const X509_ALGOR *alg, | ||
| static int ecd_sig_info_set25519(X509_SIG_INFO *siginf, const X509_ALGOR *alg, | ||
| const ASN1_STRING *sig) |
|
|
||
|
|
||
| static int ecd_item_sign448(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, | ||
| X509_ALGOR *alg1, X509_ALGOR *alg2, |
There was a problem hiding this comment.
style: wrong indentation
| } | ||
|
|
||
| static int ecd_sig_info_set448(X509_SIG_INFO *siginf, const X509_ALGOR *alg, | ||
| const ASN1_STRING *sig) |
| @@ -594,13 +594,16 @@ EC_F_OSSL_ECDSA_SIGN_SIG:249:ossl_ecdsa_sign_sig | |||
| EC_F_OSSL_ECDSA_VERIFY_SIG:250:ossl_ecdsa_verify_sig | |||
| EC_F_PKEY_ECD_CTRL:271:pkey_ecd_ctrl | |||
| EC_F_PKEY_ECD_DIGESTSIGN:272:pkey_ecd_digestsign | |||
There was a problem hiding this comment.
Should this identifier (and a few others) remain after you renamed the related methods ?
There was a problem hiding this comment.
Hmm...probably we need to do a big cleanup in one go of this kind of thing before we do the final release.
| X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_ED448), V_ASN1_UNDEF, NULL); | ||
| if (alg2 != NULL) | ||
| X509_ALGOR_set0(alg2, OBJ_nid2obj(NID_ED448), V_ASN1_UNDEF, NULL); | ||
| /* Algorithm idetifiers set: carry on as normal */ |
|
|
||
| *) Added support for X448 and Ed448. Currently this is only supported in | ||
| libcrypto (not libssl). Use the EVP_PKEY_new_priv_key() and | ||
| EVP_PKEY_new_pub_key() functions to create X448 or Ed448 keys and then |
| return -2; | ||
| return !CRYPTO_memcmp(akey->pubkey, bkey->pubkey, X25519_KEYLEN); | ||
|
|
||
| return CRYPTO_memcmp(akey->pubkey, bkey->pubkey, KEYLEN(a)) == 0; |
There was a problem hiding this comment.
Should we check that they're actually the same type?
There was a problem hiding this comment.
No, EVP_PKEY_cmp guarantees that we will never get two values with different types.
|
Looks good for me, other than the minor comments. |
|
Fixup commits pushed addressing all comments. |
|
Awesome! Thanks - pushed. |
Reviewed-by: Rich Salz <[email protected]> Reviewed-by: Kurt Roeckx <[email protected]> (Merged from #5481)
This adds all of the relevant EVP plumbing required to make X448 and Ed448 work. Reviewed-by: Rich Salz <[email protected]> Reviewed-by: Kurt Roeckx <[email protected]> (Merged from #5481)
Reviewed-by: Rich Salz <[email protected]> Reviewed-by: Kurt Roeckx <[email protected]> (Merged from #5481)
This adds the Ed448 test vectors from RFC8032 and the X448 test vectors from RFC7748. Reviewed-by: Rich Salz <[email protected]> Reviewed-by: Kurt Roeckx <[email protected]> (Merged from #5481)
Reviewed-by: Rich Salz <[email protected]> Reviewed-by: Kurt Roeckx <[email protected]> (Merged from #5481)
This adds EVP layer support for X448 and Ed448 to libcrypto. TLS support is added in #5470.
This is a revised version of #5419. That PR was controversial because of the introduction of a couple of functions and how they were implemented. Those functions aren't actually necessary for the most bare-bones implementation needed for TLS support so I have excluded them from this PR. I will add them back in (possibly implemented slightly differently on the basis of feedback) in a different PR.
Checklist