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

Everest integration #140

Merged
merged 78 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
bee4861
ECDH: Add Everest Curve25519 to 3rdparty/everest
Oct 25, 2018
2a9684e
ECDH: Add VS2010 support files for Everest Curve25519
Oct 25, 2018
de4fcf2
ECDH: Add new ECDH context for Everest Curve25519
Oct 25, 2018
d5fd766
ECDH: Include Everest Curve25519 in build scripts
Oct 25, 2018
696deda
ECDH: Add new (non-legacy) ECDH benchmark
Oct 25, 2018
c9f737b
ECDH: Enable Everest Curve25519 in ECDH/ECDSA/ECP
Oct 25, 2018
6817b9e
ECDH: Add #ifdef filter to tests/scripts/list-enum-consts.pl
Oct 25, 2018
65bab97
ECDH: Rename full handshake benchmark
Dec 6, 2018
78c9c46
ECDH: Fix typo in ecdh.c
Dec 6, 2018
fba94e9
ECDH: Fix error code in mbedtls_ecdsa_sign
Dec 6, 2018
fb72367
ECDH: Remove old code from mbedtls_everest_make_params
Dec 6, 2018
86e36c4
ECDH: Replace hex literal with decimal in ecp.c
Dec 6, 2018
6acfbb5
ECDH: Add #ifdef to cleanly disable the Everest code
Dec 7, 2018
79acf95
ECDH: Improve ECDH full handshake benchmark
Dec 7, 2018
48d26c2
ECDH: Add Everest Curve25519 to VS project files
Dec 6, 2018
4936beb
ECDH: Clean up the interface to Everest code
Dec 12, 2018
999f3b5
ECDH: Remove YOTTA config #define
Dec 14, 2018
c3cbdde
ECDH: Fix whitespace, permissions
Dec 14, 2018
34811a8
ECDH: Use LOCAL_CFLAGS instead of CFLAGS
Dec 14, 2018
3c44962
ECDH: Fix error checks in benchmark.c
Dec 14, 2018
24fbcef
ECDH: Everest: Remove unnecessary file
Dec 14, 2018
2e724a1
ECDH: Fix Everest ECDH side type
Jan 7, 2019
62dddd0
Add new 3rdparty build scripts
Dec 14, 2018
7cc4c68
Fix preprocessor directive recognition in list-enum-consts.pl
Dec 14, 2018
1083a25
ECDH: Exclude FStar and Hacl* from exported symbol checks
Dec 14, 2018
8a0f5bb
Make check-names.sh find the right names in 3rdparty
Dec 14, 2018
0082f9d
ECDSA: Add mbedtls_ecdsa_can_do
Jan 7, 2019
ea24394
ECDH: Fix whitespace and permission problems
Jan 7, 2019
78450a3
ECDH: Disables MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED by default
Jan 17, 2019
405b371
Silences missing documentation warning for MBEDTLS_ECDH_VARIANT_EVERE…
Jan 17, 2019
6ea2dea
3rdparty: Add additional build facilities for 3rd-party code
Jan 21, 2019
9597238
ECDH: Make benchmarks check MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED
Feb 6, 2019
1fdf2c2
Fix build with gcc -Wshadow
gilles-peskine-arm Feb 11, 2019
20b3ef3
Add mbedtls_ecdh_can_do
gilles-peskine-arm Feb 11, 2019
d2085f5
Document that curve lists can include partially-supported curves
gilles-peskine-arm Feb 11, 2019
41fb2c0
ECDSA: Refactor return value checks for mbedtls_ecdsa_can_do
Feb 15, 2019
02174b9
3rdparty: Fix Makefile coding conventions
Feb 15, 2019
20819af
3rdparty: Adjust .gitignore
Feb 15, 2019
f43e1d9
3rdparty: Remove unnecessary copy of license file
Feb 15, 2019
5833de7
3rdparty: Update description of MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Feb 15, 2019
ef17e3b
ECDSA: Fix formatting
Feb 15, 2019
3ff60bc
ECDH/ECDSA: Fix indentation
Feb 15, 2019
2d4725f
3rdparty: Rename THIRDPARTY_OBJECTS
Feb 15, 2019
9b5e77e
3rdparty: Use LOCAL_FLAGS instead of CFLAGS
Feb 15, 2019
737df0c
Fix file permissions
Feb 15, 2019
4061f04
ECDH: Remove unnecessary #include
Feb 15, 2019
cb31073
ECP: add Curve448 to ecp_supported_curves
Feb 15, 2019
f21aba4
3rdparty: Fix Everest platform detection for CMake
Feb 15, 2019
fb779f1
3rdparty: Pull Everest x25519 key size into macro
Feb 15, 2019
088ef49
3rdparty: Make proper use of mbedtls_platform_zeroize in Everest x25519
Feb 15, 2019
537f41e
3rdparty: Updated comments for Everest x25519
Feb 15, 2019
efdf4d7
ECDH: Fix Everest x25519 make_public
Feb 15, 2019
ac0e64d
ECDH: Removed unnecessary calls to mbedtls_ecp_group_load in ECDH ben…
Feb 15, 2019
2be66d4
ECDH: Remove duplicate lines of code
Feb 18, 2019
2f563e3
ECDH: Fix memory leaks due to context re-initialization
Feb 18, 2019
8592958
ECDH: Use macro-based sizes in Everest x25519
Feb 18, 2019
1b73a71
3rdparty: Fix .gitignore
Feb 18, 2019
e7e74ba
3rdparty: Improve Everest README.md
Feb 18, 2019
30bc9ce
ECDH: Fix context initialization
Feb 18, 2019
d8c45d5
Revert "ECDH: Fix context initialization"
Feb 20, 2019
bfc8eb2
Revert "ECDH: Fix memory leaks due to context re-initialization"
Feb 20, 2019
3b58700
ECDH: Fix use of ECDH API in full handshake benchmark
Feb 20, 2019
cf5603f
ECDH: Fix inclusion of platform.h for proper use of MBEDTLS_ERR_PLATF…
Feb 20, 2019
7ec367f
3rdparty: don't claim armcc support in Everest Readme.md
Feb 20, 2019
2c69d10
3rdparty: Adjust use of Everest in ecp_supported_curves
Feb 22, 2019
6e0cac1
3rdparty: Fix Everest build to not depend on build-time macros
Feb 22, 2019
26b98e1
3rdparty: Fix newlines and trailing whitespace
Feb 26, 2019
ec70771
3rdparty: fix paths in Everest build scripts
Apr 5, 2019
d64e1e1
3rdparty: Fix Everest header installation
Apr 8, 2019
7b747fc
3rdparty: fix inclusion order of CMakeLists.txt
Apr 8, 2019
f8d4c88
Update generated files
Apr 12, 2019
6212617
Fix macros in benchmark.c
Apr 15, 2019
19d5c80
3rdparty: Added config checks for Everest
Apr 15, 2019
0969eee
3rdparty: Fix Everest's mbedtls_x25519_get_params
Apr 15, 2019
09a24b3
Add Everest components to all.sh
gilles-peskine-arm Apr 12, 2019
c25df68
Fix code style
Apr 16, 2019
20082cb
Correct 3rdparty include path for Mbed TLS
yanesca Aug 20, 2019
71dcefb
Remove Mbed Crypto headers from everest_inc
yanesca Aug 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 3rdparty/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Makefile
11 changes: 11 additions & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
list (APPEND thirdparty_src)
list (APPEND thirdparty_lib)
list (APPEND thirdparty_inc)
list (APPEND thirdparty_def)

add_subdirectory(everest)

set(thirdparty_src ${thirdparty_src} PARENT_SCOPE)
set(thirdparty_lib ${thirdparty_lib} PARENT_SCOPE)
set(thirdparty_inc ${thirdparty_inc} PARENT_SCOPE)
set(thirdparty_def ${thirdparty_def} PARENT_SCOPE)
5 changes: 5 additions & 0 deletions 3rdparty/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ifeq ($(INCLUDING_FROM_MBEDTLS), 1)
include ../crypto/3rdparty/everest/Makefile.inc
else
include ../3rdparty/everest/Makefile.inc
endif
2 changes: 2 additions & 0 deletions 3rdparty/everest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
Makefile
31 changes: 31 additions & 0 deletions 3rdparty/everest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
list (APPEND everest_src)
list (APPEND everest_inc)
list (APPEND everest_def)

set(everest_src
${CMAKE_CURRENT_SOURCE_DIR}/library/everest.c
${CMAKE_CURRENT_SOURCE_DIR}/library/x25519.c
${CMAKE_CURRENT_SOURCE_DIR}/library/Hacl_Curve25519_joined.c
)

list(APPEND everest_inc ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/everest ${CMAKE_CURRENT_SOURCE_DIR}/include/everest/kremlib)

execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/config.h get MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED RESULT_VARIABLE result)

if(${result} EQUAL 0)

if(INSTALL_MBEDTLS_HEADERS)

install(DIRECTORY include/everest
DESTINATION include
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
FILES_MATCHING PATTERN "*.h")

endif(INSTALL_MBEDTLS_HEADERS)

endif()

set(thirdparty_src ${thirdparty_src} ${everest_src} PARENT_SCOPE)
set(thirdparty_inc ${thirdparty_inc} ${everest_inc} PARENT_SCOPE)
set(thirdparty_def ${thirdparty_def} ${everest_def} PARENT_SCOPE)
6 changes: 6 additions & 0 deletions 3rdparty/everest/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
THIRDPARTY_INCLUDES+=-I../3rdparty/everest/include -I../3rdparty/everest/include/everest -I../3rdparty/everest/include/everest/kremlib

THIRDPARTY_CRYPTO_OBJECTS+= \
../3rdparty/everest/library/everest.o \
../3rdparty/everest/library/x25519.o \
../3rdparty/everest/library/Hacl_Curve25519_joined.o
5 changes: 5 additions & 0 deletions 3rdparty/everest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The files in this directory stem from [Project Everest](https://project-everest.github.io/) and are distributed under the Apache 2.0 license.

This is a formally verified implementation of Curve25519-based handshakes. The C code is automatically derived from the (verified) [original implementation](https://github.com/project-everest/hacl-star/tree/master/code/curve25519) in the [F* language](https://github.com/fstarlang/fstar) by [KreMLin](https://github.com/fstarlang/kremlin). In addition to the improved safety and security of the implementation, it is also significantly faster than the default implementation of Curve25519 in mbedTLS.

The caveat is that not all platforms are supported, although the version in `everest/library/legacy` should work on most systems. The main issue is that some platforms do not provide a 128-bit integer type and KreMLin therefore has to use additional (also verified) code to simulate them, resulting in less of a performance gain overall. Explictly supported platforms are currently `x86` and `x86_64` using gcc or clang, and Visual C (2010 and later).
21 changes: 21 additions & 0 deletions 3rdparty/everest/include/everest/Hacl_Curve25519.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
Licensed under the Apache 2.0 License. */

/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
* KreMLin invocation: /mnt/e/everest/verify/kremlin/krml -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrcLh -minimal -fbuiltin-uint128 -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrcLh -minimal -I /mnt/e/everest/verify/hacl-star/code/lib/kremlin -I /mnt/e/everest/verify/kremlin/kremlib/compat -I /mnt/e/everest/verify/hacl-star/specs -I /mnt/e/everest/verify/hacl-star/specs/old -I . -ccopt -march=native -verbose -ldopt -flto -tmpdir x25519-c -I ../bignum -bundle Hacl.Curve25519=* -minimal -add-include "kremlib.h" -skip-compilation x25519-c/out.krml -o x25519-c/Hacl_Curve25519.c
* F* version: 059db0c8
* KreMLin version: 916c37ac
*/



#ifndef __Hacl_Curve25519_H
#define __Hacl_Curve25519_H


#include "kremlib.h"

void Hacl_Curve25519_crypto_scalarmult(uint8_t *mypublic, uint8_t *secret, uint8_t *basepoint);

#define __Hacl_Curve25519_H_DEFINED
#endif
234 changes: 234 additions & 0 deletions 3rdparty/everest/include/everest/everest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/*
* Interface to code from Project Everest
*
* Copyright 2016-2018 INRIA and Microsoft Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of Mbed TLS (https://tls.mbed.org).
*/

#ifndef MBEDTLS_EVEREST_H
#define MBEDTLS_EVEREST_H

#include "everest/x25519.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Defines the source of the imported EC key.
*/
typedef enum
{
MBEDTLS_EVEREST_ECDH_OURS, /**< Our key. */
MBEDTLS_EVEREST_ECDH_THEIRS, /**< The key of the peer. */
} mbedtls_everest_ecdh_side;

typedef struct {
mbedtls_x25519_context ctx;
} mbedtls_ecdh_context_everest;


/**
* \brief This function sets up the ECDH context with the information
* given.
*
* This function should be called after mbedtls_ecdh_init() but
* before mbedtls_ecdh_make_params(). There is no need to call
* this function before mbedtls_ecdh_read_params().
*
* This is the first function used by a TLS server for ECDHE
* ciphersuites.
*
* \param ctx The ECDH context to set up.
* \param grp_id The group id of the group to set up the context for.
*
* \return \c 0 on success.
*/
int mbedtls_everest_setup( mbedtls_ecdh_context_everest *ctx, int grp_id );

/**
* \brief This function frees a context.
*
* \param ctx The context to free.
*/
void mbedtls_everest_free( mbedtls_ecdh_context_everest *ctx );

/**
* \brief This function generates a public key and a TLS
* ServerKeyExchange payload.
*
* This is the second function used by a TLS server for ECDHE
* ciphersuites. (It is called after mbedtls_ecdh_setup().)
*
* \note This function assumes that the ECP group (grp) of the
* \p ctx context has already been properly set,
* for example, using mbedtls_ecp_group_load().
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param olen The number of characters written.
* \param buf The destination buffer.
* \param blen The length of the destination buffer.
* \param f_rng The RNG function.
* \param p_rng The RNG context.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*/
int mbedtls_everest_make_params( mbedtls_ecdh_context_everest *ctx, size_t *olen,
unsigned char *buf, size_t blen,
int( *f_rng )( void *, unsigned char *, size_t ),
void *p_rng );

/**
* \brief This function parses and processes a TLS ServerKeyExhange
* payload.
*
* This is the first function used by a TLS client for ECDHE
* ciphersuites.
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param buf The pointer to the start of the input buffer.
* \param end The address for one Byte past the end of the buffer.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*
*/
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
const unsigned char **buf, const unsigned char *end );

/**
* \brief This function parses and processes a TLS ServerKeyExhange
* payload.
*
* This is the first function used by a TLS client for ECDHE
* ciphersuites.
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param buf The pointer to the start of the input buffer.
* \param end The address for one Byte past the end of the buffer.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*
*/
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
const unsigned char **buf, const unsigned char *end );

/**
* \brief This function sets up an ECDH context from an EC key.
*
* It is used by clients and servers in place of the
* ServerKeyEchange for static ECDH, and imports ECDH
* parameters from the EC key information of a certificate.
*
* \see ecp.h
*
* \param ctx The ECDH context to set up.
* \param key The EC key to use.
* \param side Defines the source of the key: 1: Our key, or
* 0: The key of the peer.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*
*/
int mbedtls_everest_get_params( mbedtls_ecdh_context_everest *ctx, const mbedtls_ecp_keypair *key,
mbedtls_everest_ecdh_side side );

/**
* \brief This function generates a public key and a TLS
* ClientKeyExchange payload.
*
* This is the second function used by a TLS client for ECDH(E)
* ciphersuites.
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param olen The number of Bytes written.
* \param buf The destination buffer.
* \param blen The size of the destination buffer.
* \param f_rng The RNG function.
* \param p_rng The RNG context.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*/
int mbedtls_everest_make_public( mbedtls_ecdh_context_everest *ctx, size_t *olen,
unsigned char *buf, size_t blen,
int( *f_rng )( void *, unsigned char *, size_t ),
void *p_rng );

/**
* \brief This function parses and processes a TLS ClientKeyExchange
* payload.
*
* This is the third function used by a TLS server for ECDH(E)
* ciphersuites. (It is called after mbedtls_ecdh_setup() and
* mbedtls_ecdh_make_params().)
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param buf The start of the input buffer.
* \param blen The length of the input buffer.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*/
int mbedtls_everest_read_public( mbedtls_ecdh_context_everest *ctx,
const unsigned char *buf, size_t blen );

/**
* \brief This function derives and exports the shared secret.
*
* This is the last function used by both TLS client
* and servers.
*
* \note If \p f_rng is not NULL, it is used to implement
* countermeasures against side-channel attacks.
* For more information, see mbedtls_ecp_mul().
*
* \see ecp.h
*
* \param ctx The ECDH context.
* \param olen The number of Bytes written.
* \param buf The destination buffer.
* \param blen The length of the destination buffer.
* \param f_rng The RNG function.
* \param p_rng The RNG context.
*
* \return \c 0 on success.
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
*/
int mbedtls_everest_calc_secret( mbedtls_ecdh_context_everest *ctx, size_t *olen,
unsigned char *buf, size_t blen,
int( *f_rng )( void *, unsigned char *, size_t ),
void *p_rng );

#ifdef __cplusplus
}
#endif

#endif /* MBEDTLS_EVEREST_H */
29 changes: 29 additions & 0 deletions 3rdparty/everest/include/everest/kremlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016-2018 INRIA and Microsoft Corporation
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of Mbed TLS (https://tls.mbed.org) and
* originated from Project Everest (https://project-everest.github.io/)
*/

#ifndef __KREMLIB_H
#define __KREMLIB_H

#include "kremlin/internal/target.h"
#include "kremlin/internal/types.h"
#include "kremlin/c_endianness.h"

#endif /* __KREMLIB_H */
Loading