Skip to content

Commit c04305f

Browse files
committed
Merge remote-tracking branch 'crypto/development' into development-restricted
* crypto/development: (863 commits) crypto_platform: Fix typo des: Reduce number of self-test iterations Fix -O0 build for Aarch64 bignum multiplication. Make GNUC-compatible compilers use the right mbedtls_t_udbl again on Aarch64 builds. Add optimized bignum multiplication for Aarch64. Enable 64-bit limbs for all Aarch64 builds. HMAC DRBG: Split entropy-gathering requests to reduce request sizes psa: Use application key ID where necessary psa: Adapt set_key_id() for when owner is included psa: Add PSA_KEY_ID_INIT psa: Don't duplicate policy initializer crypto_extra: Use const seed for entropy injection getting_started: Update for PSA Crypto API 1.0b3 Editorial fixes. Cross reference 'key handles' from INVALID_HANDLE Update documentation for psa_destroy_key Update documentation for psa_close_key Update psa_open_key documentation Remove duplicated information in psa_open_key Initialize key bits to max size + 1 in psa_import_key ...
2 parents e0b4c43 + 8096969 commit c04305f

File tree

213 files changed

+18658
-5955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+18658
-5955
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ massif-*
3131
# Python build artifacts:
3232
*.pyc
3333

34+
# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
35+
*.dir/
36+
37+
# Visual Studio artifacts
38+
/visualc/VS2010/.localhistory/
39+
/visualc/VS2010/.vs/
40+
/visualc/VS2010/Debug/
41+
/visualc/VS2010/Release/
42+
/visualc/VS2010/*.vcxproj.filters
43+
/visualc/VS2010/*.vcxproj.user
44+
3445
# Generated documentation:
3546
/apidoc
3647

3rdparty/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Makefile

3rdparty/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
list (APPEND thirdparty_src)
2+
list (APPEND thirdparty_lib)
3+
list (APPEND thirdparty_inc)
4+
list (APPEND thirdparty_def)
5+
6+
add_subdirectory(everest)
7+
8+
set(thirdparty_src ${thirdparty_src} PARENT_SCOPE)
9+
set(thirdparty_lib ${thirdparty_lib} PARENT_SCOPE)
10+
set(thirdparty_inc ${thirdparty_inc} PARENT_SCOPE)
11+
set(thirdparty_def ${thirdparty_def} PARENT_SCOPE)

3rdparty/Makefile.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ifeq ($(INCLUDING_FROM_MBEDTLS), 1)
2+
include ../crypto/3rdparty/everest/Makefile.inc
3+
else
4+
include ../3rdparty/everest/Makefile.inc
5+
endif

3rdparty/everest/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.o
2+
Makefile

3rdparty/everest/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
list (APPEND everest_src)
2+
list (APPEND everest_inc)
3+
list (APPEND everest_def)
4+
5+
set(everest_src
6+
${CMAKE_CURRENT_SOURCE_DIR}/library/everest.c
7+
${CMAKE_CURRENT_SOURCE_DIR}/library/x25519.c
8+
${CMAKE_CURRENT_SOURCE_DIR}/library/Hacl_Curve25519_joined.c
9+
)
10+
11+
list(APPEND everest_inc ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/everest ${CMAKE_CURRENT_SOURCE_DIR}/include/everest/kremlib)
12+
13+
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)
14+
15+
if(${result} EQUAL 0)
16+
17+
if(INSTALL_MBEDTLS_HEADERS)
18+
19+
install(DIRECTORY include/everest
20+
DESTINATION include
21+
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
22+
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
23+
FILES_MATCHING PATTERN "*.h")
24+
25+
endif(INSTALL_MBEDTLS_HEADERS)
26+
27+
endif()
28+
29+
set(thirdparty_src ${thirdparty_src} ${everest_src} PARENT_SCOPE)
30+
set(thirdparty_inc ${thirdparty_inc} ${everest_inc} PARENT_SCOPE)
31+
set(thirdparty_def ${thirdparty_def} ${everest_def} PARENT_SCOPE)

3rdparty/everest/Makefile.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
THIRDPARTY_INCLUDES+=-I../3rdparty/everest/include -I../3rdparty/everest/include/everest -I../3rdparty/everest/include/everest/kremlib
2+
3+
THIRDPARTY_CRYPTO_OBJECTS+= \
4+
../3rdparty/everest/library/everest.o \
5+
../3rdparty/everest/library/x25519.o \
6+
../3rdparty/everest/library/Hacl_Curve25519_joined.o

3rdparty/everest/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The files in this directory stem from [Project Everest](https://project-everest.github.io/) and are distributed under the Apache 2.0 license.
2+
3+
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.
4+
5+
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).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
2+
Licensed under the Apache 2.0 License. */
3+
4+
/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
5+
* 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
6+
* F* version: 059db0c8
7+
* KreMLin version: 916c37ac
8+
*/
9+
10+
11+
12+
#ifndef __Hacl_Curve25519_H
13+
#define __Hacl_Curve25519_H
14+
15+
16+
#include "kremlib.h"
17+
18+
void Hacl_Curve25519_crypto_scalarmult(uint8_t *mypublic, uint8_t *secret, uint8_t *basepoint);
19+
20+
#define __Hacl_Curve25519_H_DEFINED
21+
#endif
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/*
2+
* Interface to code from Project Everest
3+
*
4+
* Copyright 2016-2018 INRIA and Microsoft Corporation
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* This file is part of Mbed TLS (https://tls.mbed.org).
20+
*/
21+
22+
#ifndef MBEDTLS_EVEREST_H
23+
#define MBEDTLS_EVEREST_H
24+
25+
#include "everest/x25519.h"
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
/**
32+
* Defines the source of the imported EC key.
33+
*/
34+
typedef enum
35+
{
36+
MBEDTLS_EVEREST_ECDH_OURS, /**< Our key. */
37+
MBEDTLS_EVEREST_ECDH_THEIRS, /**< The key of the peer. */
38+
} mbedtls_everest_ecdh_side;
39+
40+
typedef struct {
41+
mbedtls_x25519_context ctx;
42+
} mbedtls_ecdh_context_everest;
43+
44+
45+
/**
46+
* \brief This function sets up the ECDH context with the information
47+
* given.
48+
*
49+
* This function should be called after mbedtls_ecdh_init() but
50+
* before mbedtls_ecdh_make_params(). There is no need to call
51+
* this function before mbedtls_ecdh_read_params().
52+
*
53+
* This is the first function used by a TLS server for ECDHE
54+
* ciphersuites.
55+
*
56+
* \param ctx The ECDH context to set up.
57+
* \param grp_id The group id of the group to set up the context for.
58+
*
59+
* \return \c 0 on success.
60+
*/
61+
int mbedtls_everest_setup( mbedtls_ecdh_context_everest *ctx, int grp_id );
62+
63+
/**
64+
* \brief This function frees a context.
65+
*
66+
* \param ctx The context to free.
67+
*/
68+
void mbedtls_everest_free( mbedtls_ecdh_context_everest *ctx );
69+
70+
/**
71+
* \brief This function generates a public key and a TLS
72+
* ServerKeyExchange payload.
73+
*
74+
* This is the second function used by a TLS server for ECDHE
75+
* ciphersuites. (It is called after mbedtls_ecdh_setup().)
76+
*
77+
* \note This function assumes that the ECP group (grp) of the
78+
* \p ctx context has already been properly set,
79+
* for example, using mbedtls_ecp_group_load().
80+
*
81+
* \see ecp.h
82+
*
83+
* \param ctx The ECDH context.
84+
* \param olen The number of characters written.
85+
* \param buf The destination buffer.
86+
* \param blen The length of the destination buffer.
87+
* \param f_rng The RNG function.
88+
* \param p_rng The RNG context.
89+
*
90+
* \return \c 0 on success.
91+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
92+
*/
93+
int mbedtls_everest_make_params( mbedtls_ecdh_context_everest *ctx, size_t *olen,
94+
unsigned char *buf, size_t blen,
95+
int( *f_rng )( void *, unsigned char *, size_t ),
96+
void *p_rng );
97+
98+
/**
99+
* \brief This function parses and processes a TLS ServerKeyExhange
100+
* payload.
101+
*
102+
* This is the first function used by a TLS client for ECDHE
103+
* ciphersuites.
104+
*
105+
* \see ecp.h
106+
*
107+
* \param ctx The ECDH context.
108+
* \param buf The pointer to the start of the input buffer.
109+
* \param end The address for one Byte past the end of the buffer.
110+
*
111+
* \return \c 0 on success.
112+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
113+
*
114+
*/
115+
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
116+
const unsigned char **buf, const unsigned char *end );
117+
118+
/**
119+
* \brief This function parses and processes a TLS ServerKeyExhange
120+
* payload.
121+
*
122+
* This is the first function used by a TLS client for ECDHE
123+
* ciphersuites.
124+
*
125+
* \see ecp.h
126+
*
127+
* \param ctx The ECDH context.
128+
* \param buf The pointer to the start of the input buffer.
129+
* \param end The address for one Byte past the end of the buffer.
130+
*
131+
* \return \c 0 on success.
132+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
133+
*
134+
*/
135+
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx,
136+
const unsigned char **buf, const unsigned char *end );
137+
138+
/**
139+
* \brief This function sets up an ECDH context from an EC key.
140+
*
141+
* It is used by clients and servers in place of the
142+
* ServerKeyEchange for static ECDH, and imports ECDH
143+
* parameters from the EC key information of a certificate.
144+
*
145+
* \see ecp.h
146+
*
147+
* \param ctx The ECDH context to set up.
148+
* \param key The EC key to use.
149+
* \param side Defines the source of the key: 1: Our key, or
150+
* 0: The key of the peer.
151+
*
152+
* \return \c 0 on success.
153+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
154+
*
155+
*/
156+
int mbedtls_everest_get_params( mbedtls_ecdh_context_everest *ctx, const mbedtls_ecp_keypair *key,
157+
mbedtls_everest_ecdh_side side );
158+
159+
/**
160+
* \brief This function generates a public key and a TLS
161+
* ClientKeyExchange payload.
162+
*
163+
* This is the second function used by a TLS client for ECDH(E)
164+
* ciphersuites.
165+
*
166+
* \see ecp.h
167+
*
168+
* \param ctx The ECDH context.
169+
* \param olen The number of Bytes written.
170+
* \param buf The destination buffer.
171+
* \param blen The size of the destination buffer.
172+
* \param f_rng The RNG function.
173+
* \param p_rng The RNG context.
174+
*
175+
* \return \c 0 on success.
176+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
177+
*/
178+
int mbedtls_everest_make_public( mbedtls_ecdh_context_everest *ctx, size_t *olen,
179+
unsigned char *buf, size_t blen,
180+
int( *f_rng )( void *, unsigned char *, size_t ),
181+
void *p_rng );
182+
183+
/**
184+
* \brief This function parses and processes a TLS ClientKeyExchange
185+
* payload.
186+
*
187+
* This is the third function used by a TLS server for ECDH(E)
188+
* ciphersuites. (It is called after mbedtls_ecdh_setup() and
189+
* mbedtls_ecdh_make_params().)
190+
*
191+
* \see ecp.h
192+
*
193+
* \param ctx The ECDH context.
194+
* \param buf The start of the input buffer.
195+
* \param blen The length of the input buffer.
196+
*
197+
* \return \c 0 on success.
198+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
199+
*/
200+
int mbedtls_everest_read_public( mbedtls_ecdh_context_everest *ctx,
201+
const unsigned char *buf, size_t blen );
202+
203+
/**
204+
* \brief This function derives and exports the shared secret.
205+
*
206+
* This is the last function used by both TLS client
207+
* and servers.
208+
*
209+
* \note If \p f_rng is not NULL, it is used to implement
210+
* countermeasures against side-channel attacks.
211+
* For more information, see mbedtls_ecp_mul().
212+
*
213+
* \see ecp.h
214+
*
215+
* \param ctx The ECDH context.
216+
* \param olen The number of Bytes written.
217+
* \param buf The destination buffer.
218+
* \param blen The length of the destination buffer.
219+
* \param f_rng The RNG function.
220+
* \param p_rng The RNG context.
221+
*
222+
* \return \c 0 on success.
223+
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
224+
*/
225+
int mbedtls_everest_calc_secret( mbedtls_ecdh_context_everest *ctx, size_t *olen,
226+
unsigned char *buf, size_t blen,
227+
int( *f_rng )( void *, unsigned char *, size_t ),
228+
void *p_rng );
229+
230+
#ifdef __cplusplus
231+
}
232+
#endif
233+
234+
#endif /* MBEDTLS_EVEREST_H */

0 commit comments

Comments
 (0)