Skip to content

Commit 915ca4d

Browse files
committed
mbedtls: Update to upstream version 2.28.8
1 parent f6a78f8 commit 915ca4d

File tree

22 files changed

+260
-117
lines changed

22 files changed

+260
-117
lines changed

thirdparty/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ in the MSVC debugger.
521521
## mbedtls
522522

523523
- Upstream: https://github.com/Mbed-TLS/mbedtls
524-
- Version: 2.28.7 (555f84735aecdbd76a566cf087ec8425dfb0c8ab, 2024)
524+
- Version: 2.28.8 (5a764e5555c64337ed17444410269ff21cb617b1, 2024)
525525
- License: Apache 2.0
526526

527527
File extracted from upstream release tarball:

thirdparty/mbedtls/include/mbedtls/aesni.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
* macros that may change in future releases.
4747
*/
4848
#undef MBEDTLS_AESNI_HAVE_INTRINSICS
49-
#if defined(_MSC_VER)
49+
#if defined(_MSC_VER) && !defined(__clang__)
5050
/* Visual Studio supports AESNI intrinsics since VS 2008 SP1. We only support
5151
* VS 2013 and up for other reasons anyway, so no need to check the version. */
5252
#define MBEDTLS_AESNI_HAVE_INTRINSICS
5353
#endif
5454
/* GCC-like compilers: currently, we only support intrinsics if the requisite
5555
* target flag is enabled when building the library (e.g. `gcc -mpclmul -msse2`
5656
* or `clang -maes -mpclmul`). */
57-
#if defined(__GNUC__) && defined(__AES__) && defined(__PCLMUL__)
57+
#if (defined(__GNUC__) || defined(__clang__)) && defined(__AES__) && defined(__PCLMUL__)
5858
#define MBEDTLS_AESNI_HAVE_INTRINSICS
5959
#endif
6060

thirdparty/mbedtls/include/mbedtls/config.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,26 @@
15701570
*/
15711571
//#define MBEDTLS_PSA_INJECT_ENTROPY
15721572

1573+
/**
1574+
* \def MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
1575+
*
1576+
* Assume all buffers passed to PSA functions are owned exclusively by the
1577+
* PSA function and are not stored in shared memory.
1578+
*
1579+
* This option may be enabled if all buffers passed to any PSA function reside
1580+
* in memory that is accessible only to the PSA function during its execution.
1581+
*
1582+
* This option MUST be disabled whenever buffer arguments are in memory shared
1583+
* with an untrusted party, for example where arguments to PSA calls are passed
1584+
* across a trust boundary.
1585+
*
1586+
* \note Enabling this option reduces memory usage and code size.
1587+
*
1588+
* \note Enabling this option causes overlap of input and output buffers
1589+
* not to be supported by PSA functions.
1590+
*/
1591+
//#define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
1592+
15731593
/**
15741594
* \def MBEDTLS_RSA_NO_CRT
15751595
*

thirdparty/mbedtls/include/mbedtls/ecp.h

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,8 @@ int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
12651265
/**
12661266
* \brief This function reads an elliptic curve private key.
12671267
*
1268+
* \note This function does not support Curve448 yet.
1269+
*
12681270
* \param grp_id The ECP group identifier.
12691271
* \param key The destination key.
12701272
* \param buf The buffer containing the binary representation of the
@@ -1286,17 +1288,43 @@ int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
12861288
/**
12871289
* \brief This function exports an elliptic curve private key.
12881290
*
1291+
* \note Note that although this function accepts an output
1292+
* buffer that is smaller or larger than the key, most key
1293+
* import interfaces require the output to have exactly
1294+
* key's nominal length. It is generally simplest to
1295+
* pass the key's nominal length as \c buflen, after
1296+
* checking that the output buffer is large enough.
1297+
* See the description of the \p buflen parameter for
1298+
* how to calculate the nominal length.
1299+
*
1300+
* \note If the private key was not set in \p key,
1301+
* the output is unspecified. Future versions
1302+
* may return an error in that case.
1303+
*
1304+
* \note This function does not support Curve448 yet.
1305+
*
12891306
* \param key The private key.
12901307
* \param buf The output buffer for containing the binary representation
1291-
* of the key. (Big endian integer for Weierstrass curves, byte
1292-
* string for Montgomery curves.)
1308+
* of the key.
1309+
* For Weierstrass curves, this is the big-endian
1310+
* representation, padded with null bytes at the beginning
1311+
* to reach \p buflen bytes.
1312+
* For Montgomery curves, this is the standard byte string
1313+
* representation (which is little-endian), padded with
1314+
* null bytes at the end to reach \p buflen bytes.
12931315
* \param buflen The total length of the buffer in bytes.
1316+
* The length of the output is
1317+
* (`grp->nbits` + 7) / 8 bytes
1318+
* where `grp->nbits` is the private key size in bits.
1319+
* For Weierstrass keys, if the output buffer is smaller,
1320+
* leading zeros are trimmed to fit if possible. For
1321+
* Montgomery keys, the output buffer must always be large
1322+
* enough for the nominal length.
12941323
*
12951324
* \return \c 0 on success.
1296-
* \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key
1297-
representation is larger than the available space in \p buf.
1298-
* \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for
1299-
* the group is not implemented.
1325+
* \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL or
1326+
* #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the \p key
1327+
* representation is larger than the available space in \p buf.
13001328
* \return Another negative error code on different kinds of failure.
13011329
*/
13021330
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,

thirdparty/mbedtls/include/mbedtls/net_sockets.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *
140140
* \param client_ctx Will contain the connected client socket
141141
* \param client_ip Will contain the client IP address, can be NULL
142142
* \param buf_size Size of the client_ip buffer
143-
* \param ip_len Will receive the size of the client IP written,
143+
* \param cip_len Will receive the size of the client IP written,
144144
* can be NULL if client_ip is null
145145
*
146146
* \return 0 if successful, or
@@ -153,7 +153,7 @@ int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *
153153
*/
154154
int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
155155
mbedtls_net_context *client_ctx,
156-
void *client_ip, size_t buf_size, size_t *ip_len);
156+
void *client_ip, size_t buf_size, size_t *cip_len);
157157

158158
/**
159159
* \brief Check and wait for the context to be ready for read/write

thirdparty/mbedtls/include/mbedtls/version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
*/
2727
#define MBEDTLS_VERSION_MAJOR 2
2828
#define MBEDTLS_VERSION_MINOR 28
29-
#define MBEDTLS_VERSION_PATCH 7
29+
#define MBEDTLS_VERSION_PATCH 8
3030

3131
/**
3232
* The single version number has the following structure:
3333
* MMNNPP00
3434
* Major version | Minor version | Patch version
3535
*/
36-
#define MBEDTLS_VERSION_NUMBER 0x021C0700
37-
#define MBEDTLS_VERSION_STRING "2.28.7"
38-
#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 2.28.7"
36+
#define MBEDTLS_VERSION_NUMBER 0x021C0800
37+
#define MBEDTLS_VERSION_STRING "2.28.8"
38+
#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 2.28.8"
3939

4040
#if defined(MBEDTLS_VERSION_C)
4141

thirdparty/mbedtls/library/aes.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static const uint32_t RT3[256] = { RT };
322322
/*
323323
* Round constants
324324
*/
325-
static const uint32_t RCON[10] =
325+
static const uint32_t round_constants[10] =
326326
{
327327
0x00000001, 0x00000002, 0x00000004, 0x00000008,
328328
0x00000010, 0x00000020, 0x00000040, 0x00000080,
@@ -369,7 +369,7 @@ static uint32_t RT3[256];
369369
/*
370370
* Round constants
371371
*/
372-
static uint32_t RCON[10];
372+
static uint32_t round_constants[10];
373373

374374
/*
375375
* Tables generation code
@@ -399,7 +399,7 @@ static void aes_gen_tables(void)
399399
* calculate the round constants
400400
*/
401401
for (i = 0, x = 1; i < 10; i++) {
402-
RCON[i] = (uint32_t) x;
402+
round_constants[i] = (uint32_t) x;
403403
x = MBEDTLS_BYTE_0(XTIME(x));
404404
}
405405

@@ -625,7 +625,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
625625
case 10:
626626

627627
for (i = 0; i < 10; i++, RK += 4) {
628-
RK[4] = RK[0] ^ RCON[i] ^
628+
RK[4] = RK[0] ^ round_constants[i] ^
629629
((uint32_t) FSb[MBEDTLS_BYTE_1(RK[3])]) ^
630630
((uint32_t) FSb[MBEDTLS_BYTE_2(RK[3])] << 8) ^
631631
((uint32_t) FSb[MBEDTLS_BYTE_3(RK[3])] << 16) ^
@@ -640,7 +640,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
640640
case 12:
641641

642642
for (i = 0; i < 8; i++, RK += 6) {
643-
RK[6] = RK[0] ^ RCON[i] ^
643+
RK[6] = RK[0] ^ round_constants[i] ^
644644
((uint32_t) FSb[MBEDTLS_BYTE_1(RK[5])]) ^
645645
((uint32_t) FSb[MBEDTLS_BYTE_2(RK[5])] << 8) ^
646646
((uint32_t) FSb[MBEDTLS_BYTE_3(RK[5])] << 16) ^
@@ -657,7 +657,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
657657
case 14:
658658

659659
for (i = 0; i < 7; i++, RK += 8) {
660-
RK[8] = RK[0] ^ RCON[i] ^
660+
RK[8] = RK[0] ^ round_constants[i] ^
661661
((uint32_t) FSb[MBEDTLS_BYTE_1(RK[7])]) ^
662662
((uint32_t) FSb[MBEDTLS_BYTE_2(RK[7])] << 8) ^
663663
((uint32_t) FSb[MBEDTLS_BYTE_3(RK[7])] << 16) ^

thirdparty/mbedtls/library/aesni.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#if defined(MBEDTLS_AESNI_HAVE_CODE)
2828

2929
#if MBEDTLS_AESNI_HAVE_CODE == 2
30-
#if !defined(_WIN32)
30+
#if defined(__GNUC__)
3131
#include <cpuid.h>
32-
#else
32+
#elif defined(_MSC_VER)
3333
#include <intrin.h>
34+
#else
35+
#error "`__cpuid` required by MBEDTLS_AESNI_C is not supported by the compiler"
3436
#endif
3537
#include <immintrin.h>
3638
#endif
@@ -45,7 +47,7 @@ int mbedtls_aesni_has_support(unsigned int what)
4547

4648
if (!done) {
4749
#if MBEDTLS_AESNI_HAVE_CODE == 2
48-
static unsigned info[4] = { 0, 0, 0, 0 };
50+
static int info[4] = { 0, 0, 0, 0 };
4951
#if defined(_MSC_VER)
5052
__cpuid(info, 1);
5153
#else
@@ -179,7 +181,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
179181
const unsigned char a[16],
180182
const unsigned char b[16])
181183
{
182-
__m128i aa, bb, cc, dd;
184+
__m128i aa = { 0 }, bb = { 0 }, cc, dd;
183185

184186
/* The inputs are in big-endian order, so byte-reverse them */
185187
for (size_t i = 0; i < 16; i++) {

thirdparty/mbedtls/library/common.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,31 @@ static inline const unsigned char *mbedtls_buffer_offset_const(
350350
#define MBEDTLS_STATIC_ASSERT(expr, msg)
351351
#endif
352352

353+
/* Suppress compiler warnings for unused functions and variables. */
354+
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__has_attribute)
355+
# if __has_attribute(unused)
356+
# define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
357+
# endif
358+
#endif
359+
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__GNUC__)
360+
# define MBEDTLS_MAYBE_UNUSED __attribute__((unused))
361+
#endif
362+
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__IAR_SYSTEMS_ICC__) && defined(__VER__)
363+
/* IAR does support __attribute__((unused)), but only if the -e flag (extended language support)
364+
* is given; the pragma always works.
365+
* Unfortunately the pragma affects the rest of the file where it is used, but this is harmless.
366+
* Check for version 5.2 or later - this pragma may be supported by earlier versions, but I wasn't
367+
* able to find documentation).
368+
*/
369+
# if (__VER__ >= 5020000)
370+
# define MBEDTLS_MAYBE_UNUSED _Pragma("diag_suppress=Pe177")
371+
# endif
372+
#endif
373+
#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(_MSC_VER)
374+
# define MBEDTLS_MAYBE_UNUSED __pragma(warning(suppress:4189))
375+
#endif
376+
#if !defined(MBEDTLS_MAYBE_UNUSED)
377+
# define MBEDTLS_MAYBE_UNUSED
378+
#endif
379+
353380
#endif /* MBEDTLS_LIBRARY_COMMON_H */

thirdparty/mbedtls/library/ecp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp,
927927
size_t plen;
928928
ECP_VALIDATE_RET(grp != NULL);
929929
ECP_VALIDATE_RET(pt != NULL);
930-
ECP_VALIDATE_RET(buf != NULL);
930+
ECP_VALIDATE_RET(ilen == 0 || buf != NULL);
931931

932932
if (ilen < 1) {
933933
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
@@ -996,7 +996,7 @@ int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp,
996996
ECP_VALIDATE_RET(grp != NULL);
997997
ECP_VALIDATE_RET(pt != NULL);
998998
ECP_VALIDATE_RET(buf != NULL);
999-
ECP_VALIDATE_RET(*buf != NULL);
999+
ECP_VALIDATE_RET(buf_len == 0 || *buf != NULL);
10001000

10011001
/*
10021002
* We must have at least two bytes (1 for length, at least one for data)
@@ -1068,7 +1068,7 @@ int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp,
10681068
mbedtls_ecp_group_id grp_id;
10691069
ECP_VALIDATE_RET(grp != NULL);
10701070
ECP_VALIDATE_RET(buf != NULL);
1071-
ECP_VALIDATE_RET(*buf != NULL);
1071+
ECP_VALIDATE_RET(len == 0 || *buf != NULL);
10721072

10731073
if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, len)) != 0) {
10741074
return ret;
@@ -1088,7 +1088,7 @@ int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp,
10881088
const mbedtls_ecp_curve_info *curve_info;
10891089
ECP_VALIDATE_RET(grp != NULL);
10901090
ECP_VALIDATE_RET(buf != NULL);
1091-
ECP_VALIDATE_RET(*buf != NULL);
1091+
ECP_VALIDATE_RET(len == 0 || *buf != NULL);
10921092

10931093
/*
10941094
* We expect at least three bytes (see below)
@@ -2614,8 +2614,8 @@ static int ecp_mul_mxz(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
26142614
/* RP.X might be slightly larger than P, so reduce it */
26152615
MOD_ADD(RP.X);
26162616

2617+
/* Randomize coordinates of the starting point */
26172618
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2618-
/* Derandomize coordinates of the starting point */
26192619
if (f_rng == NULL) {
26202620
have_rng = 0;
26212621
}
@@ -3358,10 +3358,10 @@ int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
33583358
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
33593359
unsigned char *buf, size_t buflen)
33603360
{
3361-
int ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
3361+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
33623362

33633363
ECP_VALIDATE_RET(key != NULL);
3364-
ECP_VALIDATE_RET(buf != NULL);
3364+
ECP_VALIDATE_RET(buflen == 0 || buf != NULL);
33653365

33663366
#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
33673367
if (mbedtls_ecp_get_type(&key->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) {

0 commit comments

Comments
 (0)