Skip to content

WIP: Add X448 and Ed448 support - #4829

Closed
mattcaswell wants to merge 43 commits into
openssl:masterfrom
mattcaswell:curve448
Closed

mattcaswell wants to merge 43 commits into
openssl:masterfrom
mattcaswell:curve448

Conversation

@mattcaswell

Copy link
Copy Markdown
Member

This PR adds libcrypto (EVP level) support for X448 and Ed448. It does not add SSL/TLS support - that will be done in a later PR.

This is based heavily on original work by Mike Hamburg (thanks @bitwiseshiftleft) and contributed under CLA.

This is still WIP because there is still a lot more work to do. Many of the files need their style updating to match OpenSSL coding standards. Also a big issue is that the original code uses a lot of compiler/language features that we do not allow in OpenSSL for portability reasons - at least we don't allow them without appropriate guarding in place. For that reason this is currently using the 32-bit reference implementation rather than some of the platform specific optimised versions. Those optimised versions are still there - I just need to figure out how best to use them. I've tried this on my linux box. It quite likely won't compile on other platforms at the moment.

The Ed448 primitives support PureEDDSA and the pre-hash variant. I have only exposed the PureEDDSA version at the EVP layer due to the lack of OIDs. The underlying primitives also support contexts but I have not exposed those either at this point.

This imports selected files from the src directory of this repository:

https://sourceforge.net/p/ed448goldilocks/code/ci/v0.9.4/tree/

This is from the version tagged as "v0.9.4" with commit id 7527e9.

This code was originally writting by Mike Hamburg and the import is done by
kind permission of Rambus and Mike Hamburg under CLA. As this is under CLA
the files are being relicensed under the OpenSSL licence. Subsequent
commits will correct any licence notices in the individual files.

These files should provide complete self-contained support for X448 and
Ed448. They are imported "as is" from the source repository and this
commit does not attempt to integrate them into the OpenSSL build system,
or modify them in any way to fit OpenSSL style guidelines. That will be
done by subsequent commits.
Most of these were in point_448.h. While I was at it I spotted some unused
declarations, so I deleted those too.
OpenSSL does not currently have this concept. It only provides compiler
warnings so just remove it.
OpenSSL does not have this concept
Make sure we generate the symbolic link required for the library
…lity

Some non-portable includes are left because they are already suitably
guarded.
Convert the curve448 test to use the OpenSSL implementation of shake256.
We have fully converted curve448 to use the OpenSSL shake256 implementation
so we can now remove the old one.
It is no longer used
Unlike X448 the key lengths for ED448 are 57 bytes (as opposed to 56)
ecx_meth.c is specific to the 25519 curve. This commit makes it more generic
so it can handle the 448 curve too.
There's nothing special about being able to set the MAC key. It's just a
private key so the same ctrl can be used for other things other than MAC
algorithms. We also add the ability to set public keys directly.
This enables setting the private and public key directly for X25519,
X448, Ed25519 and Ed448
Previously private and public keys had to be pem encoded to be read by
evp_test. This enables us to embed the raw private/public key values
in the test file. The algorithm has to support EVP_PKEY_new_priv_key()
and EVP_PKEY_new_pub_key() for this to work.
This adds the Ed448 test vectors from RFC8032 and the X448 test vectors
from RFC7748.
Some files talk about the MIT license. This code was contributed under
CLA and was relicensed to the OpenSSL licence when imported.
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*
* Originally written by Mike Hamburg

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.

I think we should take all names out, not just email ones. The git log will show who authored a particular file.

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.

I have no problem with this at all, specially since he's not listed as author in git.

@@ -0,0 +1,38 @@
all: libcurve448.so.1 curve448_test

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.

Is this file going to go away?

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.

Yes - I was using it temporarily before I had integrated the code into our build system.

@@ -0,0 +1,48 @@
/* Copyright (c) 2014-2016 Cryptography Research, Inc.
* Released under the MIT License. See LICENSE.txt for license information.

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.

Update the license text

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.

Oops missed one - I thought I had done all of these!

return ((uint64_t)a) * b;
}

#endif /* __ARCH_ARM_32_ARCH_INTRINSICS_H__ */

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.

It's ARCH_ARCH above, not ARM


__asm__ __volatile__ ("smlal %[lo], %[hi], %[a], %[b]"
: [lo]"+&r"(lo), [hi]"+&r"(hi)
: [a]"r"(a), [b]"r"(b));

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.

I'm going to guess that all this assembler is going to need to get converted to perlasm so that it's works over all our platforms. I'm wondering if we should start with a plain C implementation and add all the assembler implementations at some later time.

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.

As I mentioned in the intro to this PR I've only integrated the 32-bit reference implementation which is C only. The platform specific optimisations are still there, but aren't integrated into the build at this point. This code belongs to one of those non-integrated files.

static __inline__ __attribute((always_inline,unused))
uint32_t word_is_zero(uint32_t a) {
/* let's hope the compiler isn't clever enough to optimize this. */
return (((uint64_t)a)-1)>>32;

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.

I think this function can be replaced by our constant_time_is_zero

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.

Ah...good point.

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.

The types aren't quite the same, so this is probably a non-trivial exercise.

@dot-asm

dot-asm commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

I'd say that it would be unnecessary hard to review this in single request and would like to suggest to break it into smaller steps. And even detach from original commit line. I mean do we actually need to have commits like Makefile updates?

@mattcaswell

Copy link
Copy Markdown
Member Author

I'd say that it would be unnecessary hard to review this in single request and would like to suggest to break it into smaller steps. And even detach from original commit line. I mean do we actually need to have commits like Makefile updates?

I could certainly split it into 1 PR to add the underlying primitives, and 1 PR to integrate it into EVP. WRT the Makefile it was only ever intended to be a temporary artefact that I was going to remove (including the commits). In general though I'd like to preserve most of the commit history as it does document how the code has been transformed from what was contributed to what is eventually used.

@mattcaswell mattcaswell mentioned this pull request Jan 9, 2018
@mattcaswell mattcaswell mentioned this pull request Jan 18, 2018
1 of 2 tasks
@mattcaswell

Copy link
Copy Markdown
Member Author

Replaced by #5105.

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