Skip to content

Commit 6576af9

Browse files
nwfmarcelstoer
authored andcommitted
Update mbedTLS (#2214)
* mbedTLS update * mbedtls: vsnprintf macroification * Further update mbedTLS to 2.6.1 * mbedtls: make debugging work again * Silence SSL messages on normal teardown * Drop DTLS support from mbedtls
1 parent fc2f325 commit 6576af9

Some content is hidden

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

101 files changed

+6652
-1997
lines changed

app/include/mbedtls/aes.h

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
4040
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
4141

42+
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
43+
!defined(inline) && !defined(__cplusplus)
44+
#define inline __inline
45+
#endif
46+
4247
#if !defined(MBEDTLS_AES_ALT)
4348
// Regular implementation
4449
//
@@ -253,10 +258,12 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
253258
* \param ctx AES context
254259
* \param input Plaintext block
255260
* \param output Output (ciphertext) block
261+
*
262+
* \return 0 if successful
256263
*/
257-
void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
258-
const unsigned char input[16],
259-
unsigned char output[16] );
264+
int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
265+
const unsigned char input[16],
266+
unsigned char output[16] );
260267

261268
/**
262269
* \brief Internal AES block decryption function
@@ -266,10 +273,49 @@ void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
266273
* \param ctx AES context
267274
* \param input Ciphertext block
268275
* \param output Output (plaintext) block
276+
*
277+
* \return 0 if successful
269278
*/
270-
void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
271-
const unsigned char input[16],
272-
unsigned char output[16] );
279+
int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
280+
const unsigned char input[16],
281+
unsigned char output[16] );
282+
283+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
284+
#if defined(MBEDTLS_DEPRECATED_WARNING)
285+
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
286+
#else
287+
#define MBEDTLS_DEPRECATED
288+
#endif
289+
/**
290+
* \brief Deprecated internal AES block encryption function
291+
* without return value.
292+
*
293+
* \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0
294+
*
295+
* \param ctx AES context
296+
* \param input Plaintext block
297+
* \param output Output (ciphertext) block
298+
*/
299+
MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
300+
const unsigned char input[16],
301+
unsigned char output[16] );
302+
303+
/**
304+
* \brief Deprecated internal AES block decryption function
305+
* without return value.
306+
*
307+
* \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0
308+
*
309+
* \param ctx AES context
310+
* \param input Ciphertext block
311+
* \param output Output (plaintext) block
312+
*/
313+
MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
314+
const unsigned char input[16],
315+
unsigned char output[16] );
316+
317+
#undef MBEDTLS_DEPRECATED
318+
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
273319

274320
#ifdef __cplusplus
275321
}

app/include/mbedtls/bignum.h

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,71 @@
103103
/*
104104
* Define the base integer type, architecture-wise.
105105
*
106-
* 32-bit integers can be forced on 64-bit arches (eg. for testing purposes)
107-
* by defining MBEDTLS_HAVE_INT32 and undefining MBEDTLS_HAVE_ASM
108-
*/
109-
#if ( ! defined(MBEDTLS_HAVE_INT32) && \
110-
defined(_MSC_VER) && defined(_M_AMD64) )
111-
#define MBEDTLS_HAVE_INT64
112-
typedef int64_t mbedtls_mpi_sint;
113-
typedef uint64_t mbedtls_mpi_uint;
114-
#else
115-
#if ( ! defined(MBEDTLS_HAVE_INT32) && \
116-
defined(__GNUC__) && ( \
117-
defined(__amd64__) || defined(__x86_64__) || \
118-
defined(__ppc64__) || defined(__powerpc64__) || \
119-
defined(__ia64__) || defined(__alpha__) || \
120-
(defined(__sparc__) && defined(__arch64__)) || \
121-
defined(__s390x__) || defined(__mips64) ) )
122-
#define MBEDTLS_HAVE_INT64
123-
typedef int64_t mbedtls_mpi_sint;
124-
typedef uint64_t mbedtls_mpi_uint;
125-
/* mbedtls_t_udbl defined as 128-bit unsigned int */
126-
typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
127-
#define MBEDTLS_HAVE_UDBL
128-
#else
129-
#define MBEDTLS_HAVE_INT32
130-
typedef int32_t mbedtls_mpi_sint;
131-
typedef uint32_t mbedtls_mpi_uint;
132-
typedef uint64_t mbedtls_t_udbl;
133-
#define MBEDTLS_HAVE_UDBL
134-
#endif /* !MBEDTLS_HAVE_INT32 && __GNUC__ && 64-bit platform */
135-
#endif /* !MBEDTLS_HAVE_INT32 && _MSC_VER && _M_AMD64 */
106+
* 32 or 64-bit integer types can be forced regardless of the underlying
107+
* architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
108+
* respectively and undefining MBEDTLS_HAVE_ASM.
109+
*
110+
* Double-width integers (e.g. 128-bit in 64-bit architectures) can be
111+
* disabled by defining MBEDTLS_NO_UDBL_DIVISION.
112+
*/
113+
#if !defined(MBEDTLS_HAVE_INT32)
114+
#if defined(_MSC_VER) && defined(_M_AMD64)
115+
/* Always choose 64-bit when using MSC */
116+
#if !defined(MBEDTLS_HAVE_INT64)
117+
#define MBEDTLS_HAVE_INT64
118+
#endif /* !MBEDTLS_HAVE_INT64 */
119+
typedef int64_t mbedtls_mpi_sint;
120+
typedef uint64_t mbedtls_mpi_uint;
121+
#elif defined(__GNUC__) && ( \
122+
defined(__amd64__) || defined(__x86_64__) || \
123+
defined(__ppc64__) || defined(__powerpc64__) || \
124+
defined(__ia64__) || defined(__alpha__) || \
125+
( defined(__sparc__) && defined(__arch64__) ) || \
126+
defined(__s390x__) || defined(__mips64) )
127+
#if !defined(MBEDTLS_HAVE_INT64)
128+
#define MBEDTLS_HAVE_INT64
129+
#endif /* MBEDTLS_HAVE_INT64 */
130+
typedef int64_t mbedtls_mpi_sint;
131+
typedef uint64_t mbedtls_mpi_uint;
132+
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
133+
/* mbedtls_t_udbl defined as 128-bit unsigned int */
134+
typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
135+
#define MBEDTLS_HAVE_UDBL
136+
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
137+
#elif defined(__ARMCC_VERSION) && defined(__aarch64__)
138+
/*
139+
* __ARMCC_VERSION is defined for both armcc and armclang and
140+
* __aarch64__ is only defined by armclang when compiling 64-bit code
141+
*/
142+
#if !defined(MBEDTLS_HAVE_INT64)
143+
#define MBEDTLS_HAVE_INT64
144+
#endif /* !MBEDTLS_HAVE_INT64 */
145+
typedef int64_t mbedtls_mpi_sint;
146+
typedef uint64_t mbedtls_mpi_uint;
147+
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
148+
/* mbedtls_t_udbl defined as 128-bit unsigned int */
149+
typedef __uint128_t mbedtls_t_udbl;
150+
#define MBEDTLS_HAVE_UDBL
151+
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
152+
#elif defined(MBEDTLS_HAVE_INT64)
153+
/* Force 64-bit integers with unknown compiler */
154+
typedef int64_t mbedtls_mpi_sint;
155+
typedef uint64_t mbedtls_mpi_uint;
156+
#endif
157+
#endif /* !MBEDTLS_HAVE_INT32 */
158+
159+
#if !defined(MBEDTLS_HAVE_INT64)
160+
/* Default to 32-bit compilation */
161+
#if !defined(MBEDTLS_HAVE_INT32)
162+
#define MBEDTLS_HAVE_INT32
163+
#endif /* !MBEDTLS_HAVE_INT32 */
164+
typedef int32_t mbedtls_mpi_sint;
165+
typedef uint32_t mbedtls_mpi_uint;
166+
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
167+
typedef uint64_t mbedtls_t_udbl;
168+
#define MBEDTLS_HAVE_UDBL
169+
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
170+
#endif /* !MBEDTLS_HAVE_INT64 */
136171

137172
#ifdef __cplusplus
138173
extern "C" {
@@ -340,7 +375,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
340375

341376
#if defined(MBEDTLS_FS_IO)
342377
/**
343-
* \brief Read X from an opened file
378+
* \brief Read MPI from a line in an opened file
344379
*
345380
* \param X Destination MPI
346381
* \param radix Input numeric base
@@ -349,6 +384,15 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
349384
* \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
350385
* the file read buffer is too small or a
351386
* MBEDTLS_ERR_MPI_XXX error code
387+
*
388+
* \note On success, this function advances the file stream
389+
* to the end of the current line or to EOF.
390+
*
391+
* The function returns 0 on an empty line.
392+
*
393+
* Leading whitespaces are ignored, as is a
394+
* '0x' prefix for radix 16.
395+
*
352396
*/
353397
int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
354398

@@ -665,8 +709,8 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B
665709
*
666710
* \return 0 if successful,
667711
* MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
668-
* MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or nil
669-
MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N
712+
* MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1,
713+
MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N.
670714
*/
671715
int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N );
672716

app/include/mbedtls/bn_mul.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@
162162

163163
#define MULADDC_INIT \
164164
asm( \
165-
"movq %3, %%rsi \n\t" \
166-
"movq %4, %%rdi \n\t" \
167-
"movq %5, %%rcx \n\t" \
168-
"movq %6, %%rbx \n\t" \
169165
"xorq %%r8, %%r8 \n\t"
170166

171167
#define MULADDC_CORE \
@@ -181,12 +177,9 @@
181177
"addq $8, %%rdi \n\t"
182178

183179
#define MULADDC_STOP \
184-
"movq %%rcx, %0 \n\t" \
185-
"movq %%rdi, %1 \n\t" \
186-
"movq %%rsi, %2 \n\t" \
187-
: "=m" (c), "=m" (d), "=m" (s) \
188-
: "m" (s), "m" (d), "m" (c), "m" (b) \
189-
: "rax", "rcx", "rdx", "rbx", "rsi", "rdi", "r8" \
180+
: "+c" (c), "+D" (d), "+S" (s) \
181+
: "b" (b) \
182+
: "rax", "rdx", "r8" \
190183
);
191184

192185
#endif /* AMD64 */
@@ -563,7 +556,23 @@
563556

564557
#endif /* TriCore */
565558

566-
#if defined(__arm__)
559+
/*
560+
* gcc -O0 by default uses r7 for the frame pointer, so it complains about our
561+
* use of r7 below, unless -fomit-frame-pointer is passed. Unfortunately,
562+
* passing that option is not easy when building with yotta.
563+
*
564+
* On the other hand, -fomit-frame-pointer is implied by any -Ox options with
565+
* x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
566+
* clang and armcc5 under the same conditions).
567+
*
568+
* So, only use the optimized assembly below for optimized build, which avoids
569+
* the build error and is pretty reasonable anyway.
570+
*/
571+
#if defined(__GNUC__) && !defined(__OPTIMIZE__)
572+
#define MULADDC_CANNOT_USE_R7
573+
#endif
574+
575+
#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
567576

568577
#if defined(__thumb__) && !defined(__thumb2__)
569578

app/include/mbedtls/certs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
extern "C" {
3030
#endif
3131

32-
#if defined(MBEDTLS_SELF_TEST)
33-
3432
#if defined(MBEDTLS_PEM_PARSE_C)
3533
/* Concatenation of all CA certificates in PEM format if available */
3634
extern const char mbedtls_test_cas_pem[];
@@ -94,8 +92,6 @@ extern const char mbedtls_test_cli_key_rsa[];
9492
extern const size_t mbedtls_test_cli_key_rsa_len;
9593
#endif
9694

97-
#endif
98-
9995
#ifdef __cplusplus
10096
}
10197
#endif

0 commit comments

Comments
 (0)