Skip to content

Add support for X448 and Ed448 (take 2) - #5481

Closed
mattcaswell wants to merge 8 commits into
openssl:masterfrom
mattcaswell:curve448-evp2
Closed

mattcaswell wants to merge 8 commits into
openssl:masterfrom
mattcaswell:curve448-evp2

Conversation

@mattcaswell

Copy link
Copy Markdown
Member

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
  • documentation is added or updated
  • tests are added or updated

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.
@mattcaswell mattcaswell mentioned this pull request Feb 28, 2018
2 tasks done

@richsalz richsalz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most are nits, one (priv rand) is important.

Comment thread crypto/ec/ecx_meth.c Outdated

#define ED448_SIGSIZE 114

#define ISX448(id) ((id) == EVP_PKEY_X448 ? 1 : 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the ?: really needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. I removed them

Comment thread crypto/ec/ecx_meth.c
X25519_PUBLIC,
X25519_PRIVATE,
X25519_KEYGEN
KEY_OP_PUBLIC,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I prefer adding a name to the enum, too.

Comment thread crypto/ec/ecx_meth.c Outdated
OPENSSL_free(xkey);
return 0;
if (op == KEY_OP_KEYGEN) {
if (RAND_bytes(privkey, KEYLENID(id)) <= 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use RAND_priv_bytes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually one of my changes in #4665...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crypto/ec/ecx_meth.c Outdated
X509_ALGOR *alg1, X509_ALGOR *alg2,
ASN1_BIT_STRING *str)
{
/* Set algorithms identifiers */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Set algorithm identifier"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread doc/man1/genpkey.pod

The X25519 algorithm does not currently support any key generation options.
The X25519 and X448 algorithms do not currently support any key generation
options.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank line before the NOTES header.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread doc/man7/Ed25519.pod

Ed25519 - EVP_PKEY Ed25519 support
Ed25519,
Ed448

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dash before the text on line 7

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread doc/man7/Ed25519.pod Outdated
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>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hyphenate one-shot

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread crypto/ec/ecx_meth.c Outdated

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: indent with/on previous line

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crypto/ec/ecx_meth.c Outdated
return 1;
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style : useful blank line ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread crypto/ec/ecx_meth.c Outdated

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: indent to fix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crypto/ec/ecx_meth.c Outdated


static int ecd_item_sign448(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
X509_ALGOR *alg1, X509_ALGOR *alg2,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: wrong indentation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crypto/ec/ecx_meth.c Outdated
}

static int ecd_sig_info_set448(X509_SIG_INFO *siginf, const X509_ALGOR *alg,
const ASN1_STRING *sig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: idem

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread crypto/err/openssl.txt
@@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this identifier (and a few others) remain after you renamed the related methods ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...probably we need to do a big cleanup in one go of this kind of thing before we do the final release.

Comment thread crypto/ec/ecx_meth.c Outdated
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 */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: idetifiers

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread CHANGES Outdated

*) 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is out of date

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread crypto/ec/ecx_meth.c
return -2;
return !CRYPTO_memcmp(akey->pubkey, bkey->pubkey, X25519_KEYLEN);

return CRYPTO_memcmp(akey->pubkey, bkey->pubkey, KEYLEN(a)) == 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that they're actually the same type?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, EVP_PKEY_cmp guarantees that we will never get two values with different types.

@kroeckx

kroeckx commented Feb 28, 2018

Copy link
Copy Markdown
Member

Looks good for me, other than the minor comments.

@mattcaswell

Copy link
Copy Markdown
Member Author

Fixup commits pushed addressing all comments.

@richsalz richsalz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reconfirm.

@mattcaswell

Copy link
Copy Markdown
Member Author

Awesome! Thanks - pushed.

@mattcaswell mattcaswell closed this Mar 2, 2018
levitte pushed a commit that referenced this pull request Mar 2, 2018
Reviewed-by: Rich Salz <[email protected]>
Reviewed-by: Kurt Roeckx <[email protected]>
(Merged from #5481)
levitte pushed a commit that referenced this pull request Mar 2, 2018
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)
levitte pushed a commit that referenced this pull request Mar 2, 2018
Reviewed-by: Rich Salz <[email protected]>
Reviewed-by: Kurt Roeckx <[email protected]>
(Merged from #5481)
levitte pushed a commit that referenced this pull request Mar 2, 2018
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)
levitte pushed a commit that referenced this pull request Mar 2, 2018
Reviewed-by: Rich Salz <[email protected]>
Reviewed-by: Kurt Roeckx <[email protected]>
(Merged from #5481)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants