Skip to content
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

ECDH: Add the Everest X25519 implementation #2073

Closed

Conversation

wintersteiger
Copy link

Description

These commits add the formally verified X25519 implementation from Project Everest to ECDH.

Status

Waiting for #1958 to be merged

Additional comments

  • Passes the tests and performance benchmarks, but only Ubuntu and Windows have been tested thoroughly.
  • Builds on Extend ECDH interface #1958, which isn't merged yet (yanesca/mbedtls branch kex-into-pk-v5)

CC @fournet @ad-l

@RonEld RonEld added enhancement CLA valid component-crypto Crypto primitives and low-level interfaces labels Oct 9, 2018
@yanesca yanesca requested review from Patater and yanesca October 9, 2018 15:36
@yanesca yanesca added needs-design-approval needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-preceding-pr Requires another PR to be merged first labels Oct 9, 2018
@Patater
Copy link
Contributor

Patater commented Oct 9, 2018

Hi @wintersteiger

Thanks much for your contribution. This is the first third-party code we are adding to Mbed TLS, so we appreciate your patience so far in determining how best to integrate.

I've looked at the code at a glance and can recommend a few changes straight away. We'll need to take the time to review in further detail, but in the mean time could you please, before additional reviewers spend too much time on this:

  • Follow our commit style guidelines at https://os.mbed.com/docs/latest/reference/workflow.html#guidelines-for-github-pull-requests ?
    • Use imperative mood
    • Keep subject lines to 50 characters or so
    • Don't merge from upstream into your PR branch. This makes reviewing more difficult and ties the git history in knots. I'd recommend git cherry-picking your commits atop the latest Extend ECDH interface #1958 branch.
    • Please justify why the change a commit makes is necessary. For example, explain the motivation behind Added filter for #ifdefs in tests/scripts/list-enum-consts.pl in the git commit message.

Thanks again!

@Patater Patater added the component-platform Portability layer and build scripts label Oct 9, 2018
@wintersteiger
Copy link
Author

@Patater That all sounds good. Is it okay to rebase and force-push or do you want to keep the whole history?

@Patater
Copy link
Contributor

Patater commented Oct 10, 2018

@wintersteiger Please link to the original branch in a comment and force push to this PR. You can see an example of this at #2007 (comment)

Thanks!

@wintersteiger wintersteiger force-pushed the everest-into-ecdh branch 3 times, most recently from d0917b6 to af516f8 Compare October 25, 2018 12:39
@wintersteiger
Copy link
Author

Rebased; previous branch at https://github.com/project-everest/mbedtls/tree/everest-into-ecdh-old1.

This is still based on the unmerged #1958, those commits have been reviewed before, so those commits don't need reviewing.

@yanesca yanesca mentioned this pull request Nov 6, 2018
Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

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

I have had a look at it and left a couple of comments. I also have a couple of remarks and questions that are not related to individual lines and therefore I am writing them here:

  1. @Patater mentioned that we would like to have the commit titles in imperative mood. For example instead of "Added minimized Everest Curve25519 code to 3rdparty/everest." we would like to have "Add minimized Everest Curve25519 code to 3rdparty/everest."
  2. The commit message in "Added minimized Everest Curve25519 code to 3rdparty/everest." says that these files are automatically generated by the Everest toolchain. Are all of these files generated? Aren't some of these part of KreMLin? (for example "3rdparty/everest/include/everest/kremlin/c_endianness.h").
  3. FStar_UInt128_extracted.c is not added to CMake and a comment says that we need to pass -DKRML_VERIFIED_UINT128 to use it. How does it work, to which program should I pass that flag to use it?
  4. There is a separate implementation for VS2010, I remember talking about it, but don't remember why do we need it and how it is different than the generic one. Could you please refresh my memory?

3rdparty/everest/include/everest/everest.h Outdated Show resolved Hide resolved
3rdparty/everest/library/everest.c Outdated Show resolved Hide resolved
3rdparty/everest/library/x25519.c Show resolved Hide resolved
3rdparty/everest/library/everest.c Outdated Show resolved Hide resolved
3rdparty/everest/library/everest.c Outdated Show resolved Hide resolved
programs/test/benchmark.c Outdated Show resolved Hide resolved
library/ecdh.c Outdated Show resolved Hide resolved
library/ecdsa.c Outdated Show resolved Hide resolved
library/ecp.c Outdated Show resolved Hide resolved
visualc/VS2010/aescrypt2.vcxproj Show resolved Hide resolved
@wintersteiger
Copy link
Author

@yanesca
Copy link
Contributor

yanesca commented Dec 11, 2018

Hi @wintersteiger, thank you very much for your answers and rework, I'll have a look at them at once!

Meanwhile, could you please do another rebase on current development head? #1958 has been merged recently and would make the PR cleaner and the job of other reviewers easier.

Also could you please update all of your commit message subject lines to

  • use imperative mood
  • be limited to 50 characters
  • not have period at the end?

For example:

- ECDH: Improves ECDH full handshake benchmark.
+ ECDH: Improve ECDH full handshake benchmark

@wintersteiger
Copy link
Author

@yanesca I forgot to answer your 2. and 3.: Visual Studio 2010 does not support uint128_t, so we add our own implementation in FStar_UInt128_extracted.c. This is a fully verified implementation of uint128 operations, but it's slow and needs to be enabled with the pre-processor macro -DKRML_VERIFIED_UINT128.

@yanesca
Copy link
Contributor

yanesca commented Dec 12, 2018

@wintersteiger thank you for your answer! Just to be sure I understand it correctly: I need to add -DKRML_VERIFIED_UINT128 to the preprocessor flags if and only if I build the library in VS2010. This is the only change I need to make (after setting MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED in config.h) and the library will build in VS2010. Is this correct?

@wintersteiger
Copy link
Author

@yanesca No, you don't need to add anything. I just forgot to add that definition to the VS project template in scripts/data_files; it's there now.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

I made a first pass of review. I looked at a build with default options and at the changes to existing files.

include/mbedtls/config.h Outdated Show resolved Hide resolved
include/mbedtls/ecdh.h Outdated Show resolved Hide resolved

/* GCC + using native unsigned __int128 support */

uint128_t load128_le(uint8_t *b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And check-names.sh complains about it, for good reason because it isn't namespaced. If it's static then it doesn't need to be namespaced.

include/mbedtls/config.h Outdated Show resolved Hide resolved

/* GCC + using native unsigned __int128 support */

uint128_t load128_le(uint8_t *b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also GCC and Clang complain about it with -Wmissing-prototypes and we support a clean build with -Wmissing-prototypes.

library/ecp.c Show resolved Hide resolved
library/ecdsa.c Outdated Show resolved Hide resolved
library/ecdh.c Outdated Show resolved Hide resolved
library/Makefile Outdated
@@ -86,6 +89,13 @@ OBJS_CRYPTO= aes.o aesni.o arc4.o \
threading.o timing.o version.o \
version_features.o xtea.o

OBJS_CRYPTO+= \
Copy link
Contributor

Choose a reason for hiding this comment

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

When building without Everest support, I'd prefer to avoid building these objects at all.

@wintersteiger
Copy link
Author

Rebased; old branch is at https://github.com/project-everest/mbedtls/tree/everest-into-ecdh-old3

I'm now going through @gilles-peskine-arm comments/requests.

Christoph M. Wintersteiger and others added 4 commits April 15, 2019 11:09
Mbed-TLS#2124 may suffer from the same problem.
Test a native build and a 32-bit build. For variety, the native build
is with CMake and clang, and the 32-bit build is with GNU make and
gcc.
@wintersteiger
Copy link
Author

All fixed!

The build failures were due to changes in benchmark.c relating to platform.h that I copied over from #2124. I removed some of the #defines so that it passes with both config.hs, but I can't guarantee that this works everywhere.

I still get some failures from ssl-opt.sh and compat.sh, but I get similar ones on the development branch. So, not sure those are related to the changes in this PR.

@yanesca
Copy link
Contributor

yanesca commented Apr 15, 2019

I was referring to 92bd50e because those changes were necessary to pass the new tests.

@gilles-peskine-arm
Copy link
Contributor

You're probably getting failures in ssl-opt.sh and compat.sh because you don't have all the necessary versions of OpenSSL and GnuTLS (some tests with deprecated algorithms require old versions, some tests with newer features require recent versions). They're passing on the CI, so that's fine.

The remaining failures are in jobs that use the crypto submodule. We're in the process of separating the crypto part of the library from the x509+tls parts. @Patater Assuming that Janos and I approve this PR soon, what's the merge strategy here?

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Approved!

There are minor style issues. It would be nice if you could fix them, but they're minor enough that I don't mind merging the code as is.

library/ecdh.c Outdated
{
/* At this time, all groups support ECDH. */
(void) gid;
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Style (here and elsewhere):

Suggested change
return 1;
return( 1 );

Copy link
Author

Choose a reason for hiding this comment

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

No problem, those are easy to fix. 3487b9c

library/ecdsa.c Outdated
@@ -263,7 +263,7 @@ static int ecdsa_sign_restartable( mbedtls_ecp_group *grp,
mbedtls_mpi *pk = &k, *pr = r;

/* Fail cleanly on curves such as Curve25519 that can't be used for ECDSA */
if( grp->N.p == NULL )
if( !mbedtls_ecdsa_can_do( grp->id ) || grp->N.p == NULL )
Copy link
Contributor

Choose a reason for hiding this comment

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

Style (here and elsewhere):

Suggested change
if( !mbedtls_ecdsa_can_do( grp->id ) || grp->N.p == NULL )
if( ! mbedtls_ecdsa_can_do( grp->id ) || grp->N.p == NULL )

Copy link
Author

Choose a reason for hiding this comment

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

CMakeLists.txt Outdated
@@ -168,6 +168,8 @@ else()
set(LIB_INSTALL_DIR lib)
endif()

include_directories(include/)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Patater Do you see any incompatibility between this line and getting the proper include path with the crypto submodule?

Copy link
Contributor

@Patater Patater Apr 16, 2019

Choose a reason for hiding this comment

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

Yes, this shouldn't be necessary to add. Maybe this was mistakenly readded during a rebase.

See 4cb814e for why we don't want this line anymore. We used to have this line, but removed it for submodule support.

Copy link
Author

Choose a reason for hiding this comment

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

I need include/CMakeLists.txt to be included so I can see the INSTALL_MBEDTLS_HEADERS option in 3rdparty/*. It definitely doesn't work without that line, but I've rearranged it make this a bit cleaner. Not sure what your strategy going forward is for this, so feel free to request changes to that. See 16bdf8c.

@gilles-peskine-arm
Copy link
Contributor

Apart from the build scripts, we've agreed on the design for a while. Since the build scripts work on the CI, we can take their design as fundamentally sound. So I'm removing the "needs design approval" label.

@Patater
Copy link
Contributor

Patater commented Apr 16, 2019

what's the merge strategy here?

The merge strategy is test this PR in CI (including a trial merge to Mbed Crypto), merge to Mbed TLS if all goes well. We'll then merge from TLS development to Mbed Crypto development, to get things up to date there as well. Any issues with build scripts not being synchronized we can address as they come up.

yanesca
yanesca previously approved these changes Apr 16, 2019
Copy link
Contributor

@yanesca yanesca left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@yanesca yanesca removed the needs-review Every commit must be reviewed by at least two team members, label Apr 16, 2019
@wintersteiger
Copy link
Author

Just checking; is there anything missing from our side for this to progress to the next stage?

@yanesca
Copy link
Contributor

yanesca commented May 1, 2019

No, it is all on us now. Thank you for checking!

@Patater
Copy link
Contributor

Patater commented Aug 30, 2019

Closing in favor of #2799

@Patater Patater closed this Aug 30, 2019
@gilles-peskine-arm gilles-peskine-arm mentioned this pull request Nov 2, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-crypto Crypto primitives and low-level interfaces component-platform Portability layer and build scripts enhancement needs-ci Needs to pass CI tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants