Skip to content

Commit ec898fb

Browse files
committed
tls: Upgrade to Mbed TLS 2.20.0
1 parent 41e1c2d commit ec898fb

25 files changed

+6688
-6439
lines changed

features/mbedtls/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedtls-2.20.0d0
1+
mbedtls-2.21.0

features/mbedtls/importer/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#
2828

2929
# Set the mbed TLS release to import (this can/should be edited before import)
30-
MBED_TLS_RELEASE ?= mbedtls-2.20.0d0
31-
MBED_TLS_REPO_URL ?= [email protected]:ARMmbed/mbedtls-restricted.git
30+
MBED_TLS_RELEASE ?= mbedtls-2.21.0
31+
MBED_TLS_REPO_URL ?= [email protected]:ARMmbed/mbedtls.git
3232

3333
# Translate between mbed TLS namespace and mbed namespace
3434
TARGET_PREFIX:=../

features/mbedtls/inc/mbedtls/check_config.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@
342342
#error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
343343
#endif
344344

345+
#if defined(MBEDTLS_PKCS11_C)
346+
#if defined(MBEDTLS_DEPRECATED_REMOVED)
347+
#error "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS"
348+
#elif defined(MBEDTLS_DEPRECATED_WARNING)
349+
#warning "MBEDTLS_PKCS11_C is deprecated and will be removed in a future version of Mbed TLS"
350+
#endif
351+
#endif /* MBEDTLS_PKCS11_C */
352+
345353
#if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
346354
#error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
347355
#endif
@@ -769,6 +777,22 @@
769777
#error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
770778
#endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
771779

780+
#if defined(MBEDTLS_SSL_PROTO_SSL3)
781+
#if defined(MBEDTLS_DEPRECATED_REMOVED)
782+
#error "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
783+
#elif defined(MBEDTLS_DEPRECATED_WARNING)
784+
#warning "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
785+
#endif
786+
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
787+
788+
#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
789+
#if defined(MBEDTLS_DEPRECATED_REMOVED)
790+
#error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
791+
#elif defined(MBEDTLS_DEPRECATED_WARNING)
792+
#warning "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
793+
#endif
794+
#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
795+
772796
/*
773797
* Avoid warning from -pedantic. This is a convenient place for this
774798
* workaround since this is included by every single file before the

features/mbedtls/inc/mbedtls/config.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,27 +249,27 @@
249249
/**
250250
* \def MBEDTLS_DEPRECATED_WARNING
251251
*
252-
* Mark deprecated functions so that they generate a warning if used.
253-
* Functions deprecated in one version will usually be removed in the next
254-
* version. You can enable this to help you prepare the transition to a new
255-
* major version by making sure your code is not using these functions.
252+
* Mark deprecated functions and features so that they generate a warning if
253+
* used. Functionality deprecated in one version will usually be removed in the
254+
* next version. You can enable this to help you prepare the transition to a
255+
* new major version by making sure your code is not using this functionality.
256256
*
257257
* This only works with GCC and Clang. With other compilers, you may want to
258258
* use MBEDTLS_DEPRECATED_REMOVED
259259
*
260-
* Uncomment to get warnings on using deprecated functions.
260+
* Uncomment to get warnings on using deprecated functions and features.
261261
*/
262262
//#define MBEDTLS_DEPRECATED_WARNING
263263

264264
/**
265265
* \def MBEDTLS_DEPRECATED_REMOVED
266266
*
267-
* Remove deprecated functions so that they generate an error if used.
268-
* Functions deprecated in one version will usually be removed in the next
269-
* version. You can enable this to help you prepare the transition to a new
270-
* major version by making sure your code is not using these functions.
267+
* Remove deprecated functions and features so that they generate an error if
268+
* used. Functionality deprecated in one version will usually be removed in the
269+
* next version. You can enable this to help you prepare the transition to a
270+
* new major version by making sure your code is not using this functionality.
271271
*
272-
* Uncomment to get errors on using deprecated functions.
272+
* Uncomment to get errors on using deprecated functions and features.
273273
*/
274274
//#define MBEDTLS_DEPRECATED_REMOVED
275275

@@ -1587,6 +1587,9 @@
15871587
* Enable support for receiving and parsing SSLv2 Client Hello messages for the
15881588
* SSL Server module (MBEDTLS_SSL_SRV_C).
15891589
*
1590+
* \deprecated This option is deprecated and will be removed in a future
1591+
* version of Mbed TLS.
1592+
*
15901593
* Uncomment this macro to enable support for SSLv2 Client Hello messages.
15911594
*/
15921595
//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
@@ -1618,6 +1621,9 @@
16181621
* Requires: MBEDTLS_MD5_C
16191622
* MBEDTLS_SHA1_C
16201623
*
1624+
* \deprecated This option is deprecated and will be removed in a future
1625+
* version of Mbed TLS.
1626+
*
16211627
* Comment this macro to disable support for SSL 3.0
16221628
*/
16231629
//#define MBEDTLS_SSL_PROTO_SSL3
@@ -2828,7 +2834,10 @@
28282834
/**
28292835
* \def MBEDTLS_PKCS11_C
28302836
*
2831-
* Enable wrapper for PKCS#11 smartcard support.
2837+
* Enable wrapper for PKCS#11 smartcard support via the pkcs11-helper library.
2838+
*
2839+
* \deprecated This option is deprecated and will be removed in a future
2840+
* version of Mbed TLS.
28322841
*
28332842
* Module: library/pkcs11.c
28342843
* Caller: library/pk.c

features/mbedtls/inc/mbedtls/error.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@
5252
* For historical reasons, low-level error codes are divided in even and odd,
5353
* even codes were assigned first, and -1 is reserved for other errors.
5454
*
55-
* Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
55+
* Low-level module errors (0x0002-0x007E, 0x0001-0x007F)
5656
*
5757
* Module Nr Codes assigned
58+
* ERROR 2 0x006E 0x0001
5859
* MPI 7 0x0002-0x0010
5960
* GCM 3 0x0012-0x0014 0x0013-0x0013
6061
* BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
@@ -86,7 +87,7 @@
8687
* CHACHA20 3 0x0051-0x0055
8788
* POLY1305 3 0x0057-0x005B
8889
* CHACHAPOLY 2 0x0054-0x0056
89-
* PLATFORM 1 0x0070-0x0072
90+
* PLATFORM 2 0x0070-0x0072
9091
*
9192
* High-level module nr (3 bits - 0x0...-0x7...)
9293
* Name ID Nr of Errors
@@ -112,6 +113,9 @@
112113
extern "C" {
113114
#endif
114115

116+
#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001 /**< Generic error */
117+
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E /**< This is a bug in the library */
118+
115119
/**
116120
* \brief Translate a mbed TLS error code into a string representation,
117121
* Result is truncated if necessary and always includes a terminating

features/mbedtls/inc/mbedtls/pkcs11.h

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
extern "C" {
4848
#endif
4949

50+
#if defined(MBEDTLS_DEPRECATED_REMOVED)
51+
5052
/**
5153
* Context for PKCS #11 private keys.
5254
*/
@@ -56,47 +58,71 @@ typedef struct mbedtls_pkcs11_context
5658
int len;
5759
} mbedtls_pkcs11_context;
5860

61+
#if defined(MBEDTLS_DEPRECATED_WARNING)
62+
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
63+
#else
64+
#define MBEDTLS_DEPRECATED
65+
#endif
66+
5967
/**
6068
* Initialize a mbedtls_pkcs11_context.
6169
* (Just making memory references valid.)
70+
*
71+
* \deprecated This function is deprecated and will be removed in a
72+
* future version of the library.
6273
*/
63-
void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
74+
MBEDTLS_DEPRECATED void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
6475

6576
/**
6677
* Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
6778
*
79+
* \deprecated This function is deprecated and will be removed in a
80+
* future version of the library.
81+
*
6882
* \param cert X.509 certificate to fill
6983
* \param pkcs11h_cert PKCS #11 helper certificate
7084
*
7185
* \return 0 on success.
7286
*/
73-
int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
87+
MBEDTLS_DEPRECATED int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert,
88+
pkcs11h_certificate_t pkcs11h_cert );
7489

7590
/**
7691
* Set up a mbedtls_pkcs11_context storing the given certificate. Note that the
7792
* mbedtls_pkcs11_context will take over control of the certificate, freeing it when
7893
* done.
7994
*
95+
* \deprecated This function is deprecated and will be removed in a
96+
* future version of the library.
97+
*
8098
* \param priv_key Private key structure to fill.
8199
* \param pkcs11_cert PKCS #11 helper certificate
82100
*
83101
* \return 0 on success
84102
*/
85-
int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
86-
pkcs11h_certificate_t pkcs11_cert );
103+
MBEDTLS_DEPRECATED int mbedtls_pkcs11_priv_key_bind(
104+
mbedtls_pkcs11_context *priv_key,
105+
pkcs11h_certificate_t pkcs11_cert );
87106

88107
/**
89108
* Free the contents of the given private key context. Note that the structure
90109
* itself is not freed.
91110
*
111+
* \deprecated This function is deprecated and will be removed in a
112+
* future version of the library.
113+
*
92114
* \param priv_key Private key structure to cleanup
93115
*/
94-
void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
116+
MBEDTLS_DEPRECATED void mbedtls_pkcs11_priv_key_free(
117+
mbedtls_pkcs11_context *priv_key );
95118

96119
/**
97120
* \brief Do an RSA private key decrypt, then remove the message
98121
* padding
99122
*
123+
* \deprecated This function is deprecated and will be removed in a future
124+
* version of the library.
125+
*
100126
* \param ctx PKCS #11 context
101127
* \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
102128
* \param input buffer holding the encrypted data
@@ -110,15 +136,18 @@ void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
110136
* of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
111137
* an error is thrown.
112138
*/
113-
int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
114-
int mode, size_t *olen,
115-
const unsigned char *input,
116-
unsigned char *output,
117-
size_t output_max_len );
139+
MBEDTLS_DEPRECATED int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
140+
int mode, size_t *olen,
141+
const unsigned char *input,
142+
unsigned char *output,
143+
size_t output_max_len );
118144

119145
/**
120146
* \brief Do a private RSA to sign a message digest
121147
*
148+
* \deprecated This function is deprecated and will be removed in a future
149+
* version of the library.
150+
*
122151
* \param ctx PKCS #11 context
123152
* \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
124153
* \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
@@ -132,40 +161,84 @@ int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
132161
* \note The "sig" buffer must be as large as the size
133162
* of ctx->N (eg. 128 bytes if RSA-1024 is used).
134163
*/
135-
int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
136-
int mode,
137-
mbedtls_md_type_t md_alg,
138-
unsigned int hashlen,
139-
const unsigned char *hash,
140-
unsigned char *sig );
164+
MBEDTLS_DEPRECATED int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
165+
int mode,
166+
mbedtls_md_type_t md_alg,
167+
unsigned int hashlen,
168+
const unsigned char *hash,
169+
unsigned char *sig );
141170

142171
/**
143172
* SSL/TLS wrappers for PKCS#11 functions
173+
*
174+
* \deprecated This function is deprecated and will be removed in a future
175+
* version of the library.
144176
*/
145-
static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
146-
const unsigned char *input, unsigned char *output,
147-
size_t output_max_len )
177+
MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx,
178+
int mode, size_t *olen,
179+
const unsigned char *input, unsigned char *output,
180+
size_t output_max_len )
148181
{
149182
return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
150183
output_max_len );
151184
}
152185

153-
static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
154-
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
155-
int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
156-
const unsigned char *hash, unsigned char *sig )
186+
/**
187+
* \brief This function signs a message digest using RSA.
188+
*
189+
* \deprecated This function is deprecated and will be removed in a future
190+
* version of the library.
191+
*
192+
* \param ctx The PKCS #11 context.
193+
* \param f_rng The RNG function. This parameter is unused.
194+
* \param p_rng The RNG context. This parameter is unused.
195+
* \param mode The operation to run. This must be set to
196+
* MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's
197+
* signature.
198+
* \param md_alg The message digest algorithm. One of the MBEDTLS_MD_XXX
199+
* must be passed to this function and MBEDTLS_MD_NONE can be
200+
* used for signing raw data.
201+
* \param hashlen The message digest length (for MBEDTLS_MD_NONE only).
202+
* \param hash The buffer holding the message digest.
203+
* \param sig The buffer that will hold the ciphertext.
204+
*
205+
* \return \c 0 if the signing operation was successful.
206+
* \return A non-zero error code on failure.
207+
*
208+
* \note The \p sig buffer must be as large as the size of
209+
* <code>ctx->N</code>. For example, 128 bytes if RSA-1024 is
210+
* used.
211+
*/
212+
MBEDTLS_DEPRECATED static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
213+
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
214+
int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
215+
const unsigned char *hash, unsigned char *sig )
157216
{
158217
((void) f_rng);
159218
((void) p_rng);
160219
return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
161220
hashlen, hash, sig );
162221
}
163222

164-
static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
223+
/**
224+
* This function gets the length of the private key.
225+
*
226+
* \deprecated This function is deprecated and will be removed in a future
227+
* version of the library.
228+
*
229+
* \param ctx The PKCS #11 context.
230+
*
231+
* \return The length of the private key.
232+
*/
233+
MBEDTLS_DEPRECATED static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
165234
{
166235
return ( (mbedtls_pkcs11_context *) ctx )->len;
167236
}
168237

238+
#undef MBEDTLS_DEPRECATED
239+
240+
#endif /* MBEDTLS_DEPRECATED_REMOVED */
241+
169242
#ifdef __cplusplus
170243
}
171244
#endif

0 commit comments

Comments
 (0)