Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit dd91b90

Browse files
authored
Merge pull request ARMmbed#7974 from sbutcher-arm/update-mbedtls
Update Mbed TLS to version 2.13.0
2 parents b20fd50 + 7d7b8d4 commit dd91b90

Some content is hidden

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

94 files changed

+9059
-1149
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.10.0
1+
mbedtls-2.13.0

features/mbedtls/importer/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#
2828

2929
# Set the mbed TLS release to import (this can/should be edited before import)
30-
MBED_TLS_RELEASE ?= mbedtls-2.10.0
30+
MBED_TLS_RELEASE ?= mbedtls-2.13.0
3131

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

features/mbedtls/importer/adjust-config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ conf unset MBEDTLS_FS_IO
8181
conf set MBEDTLS_NO_PLATFORM_ENTROPY
8282

8383
conf unset MBEDTLS_CIPHER_MODE_CFB
84+
conf unset MBEDTLS_CIPHER_MODE_OFB
8485
conf unset MBEDTLS_CIPHER_MODE_CTR
8586
conf unset MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
8687
conf unset MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN

features/mbedtls/inc/mbedtls/aes.h

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
* <em>ISO/IEC 18033-2:2006: Information technology -- Security
1414
* techniques -- Encryption algorithms -- Part 2: Asymmetric
1515
* ciphers</em>.
16+
*
17+
* The AES-XTS block mode is standardized by NIST SP 800-38E
18+
* <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
19+
* and described in detail by IEEE P1619
20+
* <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
1621
*/
1722

1823
/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
@@ -74,7 +79,7 @@ extern "C" {
7479
/**
7580
* \brief The AES context-type definition.
7681
*/
77-
typedef struct
82+
typedef struct mbedtls_aes_context
7883
{
7984
int nr; /*!< The number of rounds. */
8085
uint32_t *rk; /*!< AES round keys. */
@@ -89,6 +94,19 @@ typedef struct
8994
}
9095
mbedtls_aes_context;
9196

97+
#if defined(MBEDTLS_CIPHER_MODE_XTS)
98+
/**
99+
* \brief The AES XTS context-type definition.
100+
*/
101+
typedef struct mbedtls_aes_xts_context
102+
{
103+
mbedtls_aes_context crypt; /*!< The AES context to use for AES block
104+
encryption or decryption. */
105+
mbedtls_aes_context tweak; /*!< The AES context used for tweak
106+
computation. */
107+
} mbedtls_aes_xts_context;
108+
#endif /* MBEDTLS_CIPHER_MODE_XTS */
109+
92110
#else /* MBEDTLS_AES_ALT */
93111
#include "aes_alt.h"
94112
#endif /* MBEDTLS_AES_ALT */
@@ -110,6 +128,25 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx );
110128
*/
111129
void mbedtls_aes_free( mbedtls_aes_context *ctx );
112130

131+
#if defined(MBEDTLS_CIPHER_MODE_XTS)
132+
/**
133+
* \brief This function initializes the specified AES XTS context.
134+
*
135+
* It must be the first API called before using
136+
* the context.
137+
*
138+
* \param ctx The AES XTS context to initialize.
139+
*/
140+
void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
141+
142+
/**
143+
* \brief This function releases and clears the specified AES XTS context.
144+
*
145+
* \param ctx The AES XTS context to clear.
146+
*/
147+
void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
148+
#endif /* MBEDTLS_CIPHER_MODE_XTS */
149+
113150
/**
114151
* \brief This function sets the encryption key.
115152
*
@@ -142,6 +179,44 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
142179
int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
143180
unsigned int keybits );
144181

182+
#if defined(MBEDTLS_CIPHER_MODE_XTS)
183+
/**
184+
* \brief This function prepares an XTS context for encryption and
185+
* sets the encryption key.
186+
*
187+
* \param ctx The AES XTS context to which the key should be bound.
188+
* \param key The encryption key. This is comprised of the XTS key1
189+
* concatenated with the XTS key2.
190+
* \param keybits The size of \p key passed in bits. Valid options are:
191+
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
192+
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
193+
*
194+
* \return \c 0 on success.
195+
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
196+
*/
197+
int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
198+
const unsigned char *key,
199+
unsigned int keybits );
200+
201+
/**
202+
* \brief This function prepares an XTS context for decryption and
203+
* sets the decryption key.
204+
*
205+
* \param ctx The AES XTS context to which the key should be bound.
206+
* \param key The decryption key. This is comprised of the XTS key1
207+
* concatenated with the XTS key2.
208+
* \param keybits The size of \p key passed in bits. Valid options are:
209+
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
210+
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
211+
*
212+
* \return \c 0 on success.
213+
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
214+
*/
215+
int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
216+
const unsigned char *key,
217+
unsigned int keybits );
218+
#endif /* MBEDTLS_CIPHER_MODE_XTS */
219+
145220
/**
146221
* \brief This function performs an AES single-block encryption or
147222
* decryption operation.
@@ -213,6 +288,49 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
213288
unsigned char *output );
214289
#endif /* MBEDTLS_CIPHER_MODE_CBC */
215290

291+
#if defined(MBEDTLS_CIPHER_MODE_XTS)
292+
/**
293+
* \brief This function performs an AES-XTS encryption or decryption
294+
* operation for an entire XTS data unit.
295+
*
296+
* AES-XTS encrypts or decrypts blocks based on their location as
297+
* defined by a data unit number. The data unit number must be
298+
* provided by \p data_unit.
299+
*
300+
* NIST SP 800-38E limits the maximum size of a data unit to 2^20
301+
* AES blocks. If the data unit is larger than this, this function
302+
* returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
303+
*
304+
* \param ctx The AES XTS context to use for AES XTS operations.
305+
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
306+
* #MBEDTLS_AES_DECRYPT.
307+
* \param length The length of a data unit in bytes. This can be any
308+
* length between 16 bytes and 2^24 bytes inclusive
309+
* (between 1 and 2^20 block cipher blocks).
310+
* \param data_unit The address of the data unit encoded as an array of 16
311+
* bytes in little-endian format. For disk encryption, this
312+
* is typically the index of the block device sector that
313+
* contains the data.
314+
* \param input The buffer holding the input data (which is an entire
315+
* data unit). This function reads \p length bytes from \p
316+
* input.
317+
* \param output The buffer holding the output data (which is an entire
318+
* data unit). This function writes \p length bytes to \p
319+
* output.
320+
*
321+
* \return \c 0 on success.
322+
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
323+
* smaller than an AES block in size (16 bytes) or if \p
324+
* length is larger than 2^20 blocks (16 MiB).
325+
*/
326+
int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
327+
int mode,
328+
size_t length,
329+
const unsigned char data_unit[16],
330+
const unsigned char *input,
331+
unsigned char *output );
332+
#endif /* MBEDTLS_CIPHER_MODE_XTS */
333+
216334
#if defined(MBEDTLS_CIPHER_MODE_CFB)
217335
/**
218336
* \brief This function performs an AES-CFB128 encryption or decryption
@@ -296,6 +414,56 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
296414
unsigned char *output );
297415
#endif /*MBEDTLS_CIPHER_MODE_CFB */
298416

417+
#if defined(MBEDTLS_CIPHER_MODE_OFB)
418+
/**
419+
* \brief This function performs an AES-OFB (Output Feedback Mode)
420+
* encryption or decryption operation.
421+
*
422+
* For OFB, you must set up the context with
423+
* mbedtls_aes_setkey_enc(), regardless of whether you are
424+
* performing an encryption or decryption operation. This is
425+
* because OFB mode uses the same key schedule for encryption and
426+
* decryption.
427+
*
428+
* The OFB operation is identical for encryption or decryption,
429+
* therefore no operation mode needs to be specified.
430+
*
431+
* \note Upon exit, the content of iv, the Initialisation Vector, is
432+
* updated so that you can call the same function again on the next
433+
* block(s) of data and get the same result as if it was encrypted
434+
* in one call. This allows a "streaming" usage, by initialising
435+
* iv_off to 0 before the first call, and preserving its value
436+
* between calls.
437+
*
438+
* For non-streaming use, the iv should be initialised on each call
439+
* to a unique value, and iv_off set to 0 on each call.
440+
*
441+
* If you need to retain the contents of the initialisation vector,
442+
* you must either save it manually or use the cipher module
443+
* instead.
444+
*
445+
* \warning For the OFB mode, the initialisation vector must be unique
446+
* every encryption operation. Reuse of an initialisation vector
447+
* will compromise security.
448+
*
449+
* \param ctx The AES context to use for encryption or decryption.
450+
* \param length The length of the input data.
451+
* \param iv_off The offset in IV (updated after use).
452+
* \param iv The initialization vector (updated after use).
453+
* \param input The buffer holding the input data.
454+
* \param output The buffer holding the output data.
455+
*
456+
* \return \c 0 on success.
457+
*/
458+
int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
459+
size_t length,
460+
size_t *iv_off,
461+
unsigned char iv[16],
462+
const unsigned char *input,
463+
unsigned char *output );
464+
465+
#endif /* MBEDTLS_CIPHER_MODE_OFB */
466+
299467
#if defined(MBEDTLS_CIPHER_MODE_CTR)
300468
/**
301469
* \brief This function performs an AES-CTR encryption or decryption

features/mbedtls/inc/mbedtls/arc4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
* security risk. We recommend considering stronger ciphers instead.
5454
*
5555
*/
56-
typedef struct
56+
typedef struct mbedtls_arc4_context
5757
{
5858
int x; /*!< permutation index */
5959
int y; /*!< permutation index */

features/mbedtls/inc/mbedtls/aria.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern "C" {
6262
/**
6363
* \brief The ARIA context-type definition.
6464
*/
65-
typedef struct
65+
typedef struct mbedtls_aria_context
6666
{
6767
unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
6868
/*! The ARIA round keys. */

features/mbedtls/inc/mbedtls/bignum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extern "C" {
177177
/**
178178
* \brief MPI structure
179179
*/
180-
typedef struct
180+
typedef struct mbedtls_mpi
181181
{
182182
int s; /*!< integer sign */
183183
size_t n; /*!< total # of limbs */

features/mbedtls/inc/mbedtls/blowfish.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern "C" {
5555
/**
5656
* \brief Blowfish context structure
5757
*/
58-
typedef struct
58+
typedef struct mbedtls_blowfish_context
5959
{
6060
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
6161
uint32_t S[4][256]; /*!< key dependent S-boxes */

features/mbedtls/inc/mbedtls/bn_mul.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
5050
#if defined(__GNUC__) && \
5151
( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
52-
#if defined(__i386__)
52+
53+
/*
54+
* Disable use of the i386 assembly code below if option -O0, to disable all
55+
* compiler optimisations, is passed, detected with __OPTIMIZE__
56+
* This is done as the number of registers used in the assembly code doesn't
57+
* work with the -O0 option.
58+
*/
59+
#if defined(__i386__) && defined(__OPTIMIZE__)
5360

5461
#define MULADDC_INIT \
5562
asm( \
@@ -142,7 +149,7 @@
142149
"movl %%esi, %3 \n\t" \
143150
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
144151
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
145-
: "eax", "ecx", "edx", "esi", "edi" \
152+
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
146153
);
147154

148155
#else
@@ -154,7 +161,7 @@
154161
"movl %%esi, %3 \n\t" \
155162
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
156163
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
157-
: "eax", "ecx", "edx", "esi", "edi" \
164+
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
158165
);
159166
#endif /* SSE2 */
160167
#endif /* i386 */

features/mbedtls/inc/mbedtls/camellia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
/**
5252
* \brief CAMELLIA context structure
5353
*/
54-
typedef struct
54+
typedef struct mbedtls_camellia_context
5555
{
5656
int nr; /*!< number of rounds */
5757
uint32_t rk[68]; /*!< CAMELLIA round keys */

0 commit comments

Comments
 (0)