Skip to content

Commit fe1b63d

Browse files
committed
crypto: Update to Mbed Crypto 2.0.0d2
1 parent a304ec9 commit fe1b63d

File tree

20 files changed

+741
-122
lines changed

20 files changed

+741
-122
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedcrypto-2.0.0d1
1+
mbedcrypto-2.0.0d2

features/mbedtls/mbed-crypto/importer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Set the Mbed Crypto release to import (this can/should be edited before
3131
# import)
32-
CRYPTO_RELEASE ?= mbedcrypto-2.0.0d1
32+
CRYPTO_RELEASE ?= mbedcrypto-2.0.0d2
3333
CRYPTO_REPO_URL ?= [email protected]:ARMmbed/mbed-crypto.git
3434

3535
# Translate between Mbed Crypto namespace and Mbed OS namespace

features/mbedtls/mbed-crypto/inc/mbedtls/bignum.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
defined(__ppc64__) || defined(__powerpc64__) || \
130130
defined(__ia64__) || defined(__alpha__) || \
131131
( defined(__sparc__) && defined(__arch64__) ) || \
132-
defined(__s390x__) || defined(__mips64) )
132+
defined(__s390x__) || defined(__mips64) || \
133+
defined(__aarch64__) )
133134
#if !defined(MBEDTLS_HAVE_INT64)
134135
#define MBEDTLS_HAVE_INT64
135136
#endif /* MBEDTLS_HAVE_INT64 */

features/mbedtls/mbed-crypto/inc/mbedtls/bn_mul.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@
198198

199199
#endif /* AMD64 */
200200

201+
#if defined(__aarch64__)
202+
203+
#define MULADDC_INIT \
204+
asm(
205+
206+
#define MULADDC_CORE \
207+
"ldr x4, [%2], #8 \n\t" \
208+
"ldr x5, [%1] \n\t" \
209+
"mul x6, x4, %3 \n\t" \
210+
"umulh x7, x4, %3 \n\t" \
211+
"adds x5, x5, x6 \n\t" \
212+
"adc x7, x7, xzr \n\t" \
213+
"adds x5, x5, %0 \n\t" \
214+
"adc %0, x7, xzr \n\t" \
215+
"str x5, [%1], #8 \n\t"
216+
217+
#define MULADDC_STOP \
218+
: "+r" (c), "+r" (d), "+r" (s) \
219+
: "r" (b) \
220+
: "x4", "x5", "x6", "x7", "cc" \
221+
);
222+
223+
#endif /* Aarch64 */
224+
201225
#if defined(__mc68020__) || defined(__mcpu32__)
202226

203227
#define MULADDC_INIT \

features/mbedtls/mbed-crypto/inc/mbedtls/ecdh.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242

4343
#include "mbedtls/ecp.h"
4444

45+
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
46+
#undef MBEDTLS_ECDH_LEGACY_CONTEXT
47+
#include "everest/everest.h"
48+
#endif
49+
4550
#ifdef __cplusplus
4651
extern "C" {
4752
#endif
@@ -66,6 +71,9 @@ typedef enum
6671
{
6772
MBEDTLS_ECDH_VARIANT_NONE = 0, /*!< Implementation not defined. */
6873
MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */
74+
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
75+
MBEDTLS_ECDH_VARIANT_EVEREST /*!< Everest implementation */
76+
#endif
6977
} mbedtls_ecdh_variant;
7078

7179
/**
@@ -119,6 +127,9 @@ typedef struct mbedtls_ecdh_context
119127
union
120128
{
121129
mbedtls_ecdh_context_mbed mbed_ecdh;
130+
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
131+
mbedtls_ecdh_context_everest everest_ecdh;
132+
#endif
122133
} ctx; /*!< Implementation-specific context. The
123134
context in use is specified by the \c var
124135
field. */
@@ -133,6 +144,15 @@ typedef struct mbedtls_ecdh_context
133144
}
134145
mbedtls_ecdh_context;
135146

147+
/**
148+
* \brief Check whether a given group can be used for ECDH.
149+
*
150+
* \param gid The ECP group ID to check.
151+
*
152+
* \return \c 1 if the group can be used, \c 0 otherwise
153+
*/
154+
int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
155+
136156
/**
137157
* \brief This function generates an ECDH keypair on an elliptic
138158
* curve.

features/mbedtls/mbed-crypto/inc/mbedtls/ecdsa.h

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ typedef void mbedtls_ecdsa_restart_ctx;
125125

126126
#endif /* MBEDTLS_ECP_RESTARTABLE */
127127

128+
/**
129+
* \brief This function checks whether a given group can be used
130+
* for ECDSA.
131+
*
132+
* \param gid The ECP group ID to check.
133+
*
134+
* \return \c 1 if the group can be used, \c 0 otherwise
135+
*/
136+
int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
137+
128138
/**
129139
* \brief This function computes the ECDSA signature of a
130140
* previously-hashed message.
@@ -166,6 +176,12 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
166176
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
167177

168178
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
179+
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
180+
#if defined(MBEDTLS_DEPRECATED_WARNING)
181+
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
182+
#else
183+
#define MBEDTLS_DEPRECATED
184+
#endif
169185
/**
170186
* \brief This function computes the ECDSA signature of a
171187
* previously-hashed message, deterministic version.
@@ -180,6 +196,19 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
180196
* (SECG): SEC1 Elliptic Curve Cryptography</em>, section
181197
* 4.1.3, step 5.
182198
*
199+
* \warning Since the output of the internal RNG is always the same for
200+
* the same key and message, this limits the efficiency of
201+
* blinding and leaks information through side channels. For
202+
* secure behavior use mbedtls_ecdsa_sign_det_ext() instead.
203+
*
204+
* (Optimally the blinding is a random value that is different
205+
* on every execution. In this case the blinding is still
206+
* random from the attackers perspective, but is the same on
207+
* each execution. This means that this blinding does not
208+
* prevent attackers from recovering secrets by combining
209+
* several measurement traces, but may prevent some attacks
210+
* that exploit relationships between secret data.)
211+
*
183212
* \see ecp.h
184213
*
185214
* \param grp The context for the elliptic curve to use.
@@ -204,7 +233,55 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
204233
int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
205234
mbedtls_mpi *s, const mbedtls_mpi *d,
206235
const unsigned char *buf, size_t blen,
207-
mbedtls_md_type_t md_alg );
236+
mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
237+
#undef MBEDTLS_DEPRECATED
238+
#endif /* MBEDTLS_DEPRECATED_REMOVED */
239+
240+
/**
241+
* \brief This function computes the ECDSA signature of a
242+
* previously-hashed message, deterministic version.
243+
*
244+
* For more information, see <em>RFC-6979: Deterministic
245+
* Usage of the Digital Signature Algorithm (DSA) and Elliptic
246+
* Curve Digital Signature Algorithm (ECDSA)</em>.
247+
*
248+
* \note If the bitlength of the message hash is larger than the
249+
* bitlength of the group order, then the hash is truncated as
250+
* defined in <em>Standards for Efficient Cryptography Group
251+
* (SECG): SEC1 Elliptic Curve Cryptography</em>, section
252+
* 4.1.3, step 5.
253+
*
254+
* \see ecp.h
255+
*
256+
* \param grp The context for the elliptic curve to use.
257+
* This must be initialized and have group parameters
258+
* set, for example through mbedtls_ecp_group_load().
259+
* \param r The MPI context in which to store the first part
260+
* the signature. This must be initialized.
261+
* \param s The MPI context in which to store the second part
262+
* the signature. This must be initialized.
263+
* \param d The private signing key. This must be initialized
264+
* and setup, for example through mbedtls_ecp_gen_privkey().
265+
* \param buf The hashed content to be signed. This must be a readable
266+
* buffer of length \p blen Bytes. It may be \c NULL if
267+
* \p blen is zero.
268+
* \param blen The length of \p buf in Bytes.
269+
* \param md_alg The hash algorithm used to hash the original data.
270+
* \param f_rng_blind The RNG function used for blinding. This must not be
271+
* \c NULL.
272+
* \param p_rng_blind The RNG context to be passed to \p f_rng. This may be
273+
* \c NULL if \p f_rng doesn't need a context parameter.
274+
*
275+
* \return \c 0 on success.
276+
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
277+
* error code on failure.
278+
*/
279+
int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
280+
mbedtls_mpi *s, const mbedtls_mpi *d,
281+
const unsigned char *buf, size_t blen,
282+
mbedtls_md_type_t md_alg,
283+
int (*f_rng_blind)(void *, unsigned char *, size_t),
284+
void *p_rng_blind );
208285
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
209286

210287
/**
@@ -283,7 +360,8 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
283360
* the signature written. Must not be \c NULL.
284361
* \param f_rng The RNG function. This must not be \c NULL if
285362
* #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise,
286-
* it is unused and may be set to \c NULL.
363+
* it is used only for blinding and may be set to \c NULL, but
364+
* doing so is DEPRECATED.
287365
* \param p_rng The RNG context to be passed to \p f_rng. This may be
288366
* \c NULL if \p f_rng is \c NULL or doesn't use a context.
289367
*

features/mbedtls/mbed-crypto/inc/mbedtls/ecp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp );
437437
* mbedtls_ecp_curve_info() for all supported curves in order
438438
* of preference.
439439
*
440+
* \note This function returns information about all curves
441+
* supported by the library. Some curves may not be
442+
* supported for all algorithms. Call mbedtls_ecdh_can_do()
443+
* or mbedtls_ecdsa_can_do() to check if a curve is
444+
* supported for ECDH or ECDSA.
445+
*
440446
* \return A statically allocated array. The last entry is 0.
441447
*/
442448
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
@@ -446,6 +452,12 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
446452
* identifiers of all supported curves in the order of
447453
* preference.
448454
*
455+
* \note This function returns information about all curves
456+
* supported by the library. Some curves may not be
457+
* supported for all algorithms. Call mbedtls_ecdh_can_do()
458+
* or mbedtls_ecdsa_can_do() to check if a curve is
459+
* supported for ECDH or ECDSA.
460+
*
449461
* \return A statically allocated array,
450462
* terminated with MBEDTLS_ECP_DP_NONE.
451463
*/

0 commit comments

Comments
 (0)