Skip to content

Commit 5950fca

Browse files
authored
Merge pull request #111845 from akien-mga/mbedtls-3.6.5
mbedTLS: Update to version 3.6.5
2 parents 3776411 + 9de2837 commit 5950fca

29 files changed

+1007
-369
lines changed

thirdparty/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ File extracted from upstream source:
654654
## mbedtls
655655

656656
- Upstream: https://github.com/Mbed-TLS/mbedtls
657-
- Version: 3.6.4 (c765c831e5c2a0971410692f92f7a81d6ec65ec2, 2025)
657+
- Version: 3.6.5 (e185d7fd85499c8ce5ca2a54f5cf8fe7dbe3f8df, 2025)
658658
- License: Apache 2.0
659659

660660
File extracted from upstream release tarball:
@@ -664,7 +664,7 @@ File extracted from upstream release tarball:
664664
- From `library/` to `thirdparty/mbedtls/library/`:
665665
- All `.c` and `.h` files
666666
- Except `bignum_mod.c`, `block_cipher.c`, `ecp_curves_new.c`, `lmots.c`,
667-
`lms.c`, `bignum_core_invasive.h`
667+
`lms.c`
668668
- The `LICENSE` file (edited to keep only the Apache 2.0 variant)
669669
- Added 2 files `godot_core_mbedtls_platform.c` and `godot_core_mbedtls_config.h`
670670
providing configuration for light bundling with core

thirdparty/mbedtls/include/mbedtls/bignum.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ int mbedtls_mpi_random(mbedtls_mpi *X,
974974
* \brief Compute the greatest common divisor: G = gcd(A, B)
975975
*
976976
* \param G The destination MPI. This must point to an initialized MPI.
977+
* This will always be positive or 0.
977978
* \param A The first operand. This must point to an initialized MPI.
978979
* \param B The second operand. This must point to an initialized MPI.
979980
*
@@ -988,10 +989,12 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A,
988989
* \brief Compute the modular inverse: X = A^-1 mod N
989990
*
990991
* \param X The destination MPI. This must point to an initialized MPI.
992+
* The value returned on success will be between [1, N-1].
991993
* \param A The MPI to calculate the modular inverse of. This must point
992-
* to an initialized MPI.
994+
* to an initialized MPI. This value can be negative, in which
995+
* case a positive answer will still be returned in \p X.
993996
* \param N The base of the modular inversion. This must point to an
994-
* initialized MPI.
997+
* initialized MPI and be greater than one.
995998
*
996999
* \return \c 0 if successful.
9971000
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

thirdparty/mbedtls/include/mbedtls/build_info.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 3
2828
#define MBEDTLS_VERSION_MINOR 6
29-
#define MBEDTLS_VERSION_PATCH 4
29+
#define MBEDTLS_VERSION_PATCH 5
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 0x03060400
37-
#define MBEDTLS_VERSION_STRING "3.6.4"
38-
#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 3.6.4"
36+
#define MBEDTLS_VERSION_NUMBER 0x03060500
37+
#define MBEDTLS_VERSION_STRING "3.6.5"
38+
#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 3.6.5"
3939

4040
/* Macros for build-time platform detection */
4141

thirdparty/mbedtls/include/mbedtls/cipher.h

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,15 @@ typedef struct mbedtls_cipher_context_t {
329329
/** Padding functions to use, if relevant for
330330
* the specific cipher mode.
331331
*/
332-
void(*MBEDTLS_PRIVATE(add_padding))(unsigned char *output, size_t olen, size_t data_len);
333-
int(*MBEDTLS_PRIVATE(get_padding))(unsigned char *input, size_t ilen, size_t *data_len);
332+
void(*MBEDTLS_PRIVATE(add_padding))(unsigned char *output, size_t olen,
333+
size_t data_len);
334+
/* Report invalid-padding condition through the output parameter
335+
* invalid_padding. To minimize changes in Mbed TLS 3.6, where this
336+
* declaration is in a public header, use the public type size_t
337+
* rather than the internal type mbedtls_ct_condition_t. */
338+
int(*MBEDTLS_PRIVATE(get_padding))(unsigned char *input, size_t ilen,
339+
size_t *data_len,
340+
size_t *invalid_padding);
334341
#endif
335342

336343
/** Buffer for input that has not been processed yet. */
@@ -878,23 +885,24 @@ int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx,
878885
*
879886
* \note With non-AEAD ciphers, the order of calls for each message
880887
* is as follows:
881-
* 1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce.
882-
* 2. mbedtls_cipher_reset()
883-
* 3. mbedtls_cipher_update() one or more times
884-
* 4. mbedtls_cipher_finish()
888+
* 1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce;
889+
* 2. mbedtls_cipher_reset();
890+
* 3. mbedtls_cipher_update() zero, one or more times;
891+
* 4. mbedtls_cipher_finish_padded() (recommended for decryption
892+
* if the mode uses padding) or mbedtls_cipher_finish().
885893
* .
886894
* This sequence can be repeated to encrypt or decrypt multiple
887895
* messages with the same key.
888896
*
889897
* \note With AEAD ciphers, the order of calls for each message
890898
* is as follows:
891-
* 1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce.
892-
* 2. mbedtls_cipher_reset()
893-
* 3. mbedtls_cipher_update_ad()
894-
* 4. mbedtls_cipher_update() one or more times
895-
* 5. mbedtls_cipher_finish()
899+
* 1. mbedtls_cipher_set_iv() if the mode uses an IV/nonce;
900+
* 2. mbedtls_cipher_reset();
901+
* 3. mbedtls_cipher_update_ad();
902+
* 4. mbedtls_cipher_update() zero, one or more times;
903+
* 5. mbedtls_cipher_finish() (or mbedtls_cipher_finish_padded());
896904
* 6. mbedtls_cipher_check_tag() (for decryption) or
897-
* mbedtls_cipher_write_tag() (for encryption).
905+
* mbedtls_cipher_write_tag() (for encryption).
898906
* .
899907
* This sequence can be repeated to encrypt or decrypt multiple
900908
* messages with the same key.
@@ -930,7 +938,8 @@ int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx,
930938
* many block-sized blocks of data as possible to output.
931939
* Any data that cannot be written immediately is either
932940
* added to the next block, or flushed when
933-
* mbedtls_cipher_finish() is called.
941+
* mbedtls_cipher_finish() or mbedtls_cipher_finish_padded()
942+
* is called.
934943
* Exception: For MBEDTLS_MODE_ECB, expects a single block
935944
* in size. For example, 16 Bytes for AES.
936945
*
@@ -964,30 +973,97 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx,
964973
* contained in it is padded to the size of
965974
* the last block, and written to the \p output buffer.
966975
*
976+
* \warning This function reports invalid padding through an error
977+
* code. Adversaries may be able to decrypt encrypted
978+
* data if they can submit chosen ciphertexts and
979+
* detect whether it has valid padding or not,
980+
* either through direct observation or through a side
981+
* channel such as timing. This is known as a
982+
* padding oracle attack.
983+
* Therefore applications that call this function for
984+
* decryption with a cipher that involves padding
985+
* should take care around error handling. Preferably,
986+
* such applications should use
987+
* mbedtls_cipher_finish_padded() instead of this function.
988+
*
967989
* \param ctx The generic cipher context. This must be initialized and
968990
* bound to a key.
969991
* \param output The buffer to write data to. This needs to be a writable
970992
* buffer of at least block_size Bytes.
971993
* \param olen The length of the data written to the \p output buffer.
972994
* This may not be \c NULL.
995+
* Note that when decrypting in a mode with padding,
996+
* the actual output length is sensitive and may be
997+
* used to mount a padding oracle attack (see warning
998+
* above), although less efficiently than through
999+
* the invalid-padding condition.
9731000
*
9741001
* \return \c 0 on success.
9751002
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
9761003
* parameter-verification failure.
9771004
* \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
9781005
* expecting a full block but not receiving one.
9791006
* \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
980-
* while decrypting.
1007+
* while decrypting. Note that invalid-padding errors
1008+
* should be handled carefully; see the warning above.
9811009
* \return A cipher-specific error code on failure.
9821010
*/
9831011
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx,
9841012
unsigned char *output, size_t *olen);
9851013

1014+
/**
1015+
* \brief The generic cipher finalization function. If data still
1016+
* needs to be flushed from an incomplete block, the data
1017+
* contained in it is padded to the size of
1018+
* the last block, and written to the \p output buffer.
1019+
*
1020+
* \note This function is similar to mbedtls_cipher_finish().
1021+
* The only difference is that it reports invalid padding
1022+
* decryption differently, through the \p invalid_padding
1023+
* parameter rather than an error code.
1024+
* For encryption, and in modes without padding (including
1025+
* all authenticated modes), this function is identical
1026+
* to mbedtls_cipher_finish().
1027+
*
1028+
* \param[in,out] ctx The generic cipher context. This must be initialized and
1029+
* bound to a key.
1030+
* \param[out] output The buffer to write data to. This needs to be a writable
1031+
* buffer of at least block_size Bytes.
1032+
* \param[out] olen The length of the data written to the \p output buffer.
1033+
* This may not be \c NULL.
1034+
* Note that when decrypting in a mode with padding,
1035+
* the actual output length is sensitive and may be
1036+
* used to mount a padding oracle attack (see warning
1037+
* on mbedtls_cipher_finish()).
1038+
* \param[out] invalid_padding
1039+
* If this function returns \c 0 on decryption,
1040+
* \p *invalid_padding is \c 0 if the ciphertext was
1041+
* valid, and all-bits-one if the ciphertext had invalid
1042+
* padding.
1043+
* On encryption, or in a mode without padding (including
1044+
* all authenticated modes), \p *invalid_padding is \c 0
1045+
* on success.
1046+
* The value in \p *invalid_padding is unspecified if
1047+
* this function returns a nonzero status.
1048+
*
1049+
* \return \c 0 on success.
1050+
* Also \c 0 for decryption with invalid padding.
1051+
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
1052+
* parameter-verification failure.
1053+
* \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
1054+
* expecting a full block but not receiving one.
1055+
* \return A cipher-specific error code on failure.
1056+
*/
1057+
int mbedtls_cipher_finish_padded(mbedtls_cipher_context_t *ctx,
1058+
unsigned char *output, size_t *olen,
1059+
size_t *invalid_padding);
1060+
9861061
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
9871062
/**
9881063
* \brief This function writes a tag for AEAD ciphers.
9891064
* Currently supported with GCM and ChaCha20+Poly1305.
990-
* This must be called after mbedtls_cipher_finish().
1065+
* This must be called after mbedtls_cipher_finish()
1066+
* or mbedtls_cipher_finish_padded().
9911067
*
9921068
* \param ctx The generic cipher context. This must be initialized,
9931069
* bound to a key, and have just completed a cipher
@@ -1006,7 +1082,8 @@ int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx,
10061082
/**
10071083
* \brief This function checks the tag for AEAD ciphers.
10081084
* Currently supported with GCM and ChaCha20+Poly1305.
1009-
* This must be called after mbedtls_cipher_finish().
1085+
* This must be called after mbedtls_cipher_finish()
1086+
* or mbedtls_cipher_finish_padded().
10101087
*
10111088
* \param ctx The generic cipher context. This must be initialized.
10121089
* \param tag The buffer holding the tag. This must be a readable

thirdparty/mbedtls/include/mbedtls/mbedtls_config.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,19 @@
21502150
/**
21512151
* \def MBEDTLS_THREADING_ALT
21522152
*
2153-
* Provide your own alternate threading implementation.
2153+
* Provide your own alternate implementation of threading primitives
2154+
* for mutexes. If you enable this option:
2155+
*
2156+
* - Provide a header file `"threading_alt.h"`, defining the
2157+
* type `mbedtls_threading_mutex_t` of mutex objects.
2158+
*
2159+
* - Call the function mbedtls_threading_set_alt() in your application
2160+
* before calling any other library function (in particular before
2161+
* calling psa_crypto_init(), performing an asymmetric cryptography
2162+
* operation, or starting a TLS connection).
2163+
*
2164+
* See mbedtls/threading.h for more details, especially the documentation
2165+
* of mbedtls_threading_set_alt().
21542166
*
21552167
* Requires: MBEDTLS_THREADING_C
21562168
*

thirdparty/mbedtls/include/mbedtls/threading.h

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,45 @@ typedef struct mbedtls_threading_mutex_t {
5151
* mbedtls_threading_free_alt() must be called once in the main
5252
* thread after all other Mbed TLS functions.
5353
*
54-
* \note mutex_init() and mutex_free() don't return a status code.
55-
* If mutex_init() fails, it should leave its argument (the
56-
* mutex) in a state such that mutex_lock() will fail when
57-
* called with this argument.
54+
* \warning \p mutex_init and \p mutex_free don't return a status code.
55+
* If \p mutex_init fails, it should leave the mutex in
56+
* a state such that \p mutex_lock will reliably return
57+
* #MBEDTLS_ERR_THREADING_MUTEX_ERROR called on this mutex,
58+
* and \p mutex_free will do nothing.
5859
*
59-
* \param mutex_init the init function implementation
60-
* \param mutex_free the free function implementation
61-
* \param mutex_lock the lock function implementation
62-
* \param mutex_unlock the unlock function implementation
60+
* \param mutex_init The init function implementation. <br>
61+
* The behavior is undefined if the mutex is already
62+
* initialized and has not been destroyed.
63+
* On platforms where mutex initialization can fail,
64+
* since this function does not return a status code,
65+
* it must leave the mutex object in a safe state where
66+
* subsequent function calls will not cause undefined
67+
* behavior: after a call to \p mutex_init, the
68+
* function \p mutex_lock must either succeed or
69+
* fail with a nonzero status code, and the function
70+
* \p mutex_free must free any resources associated
71+
* with the mutex..
72+
* \param mutex_free The destroy function implementation. <br>
73+
* This function must free any resources associated
74+
* with the mutex object. <br>
75+
* This function must work reliably if \p mutex_init
76+
* has been called on the mutex and \p mutex_free
77+
* has not yet been called. <br>
78+
* The behavior is undefined if the mutex was not
79+
* initialized, if it has already been destroyed,
80+
* if it is currently locked, or if this function
81+
* is called concurrently from multiple threads.
82+
* \param mutex_lock The lock function implementation. <br>
83+
* This function must work reliably on any mutex
84+
* which is not currently locked and on which
85+
* \p mutex_init has already been called but
86+
* \p mutex_free has not been called yet. <br>
87+
* The behavior is undefined if the mutex was not
88+
* initialized, if it has already been destroyed, or if
89+
* it is currently locked by the calling thread.
90+
* \param mutex_unlock The unlock function implementation. <br>
91+
* The behavior is undefined if the mutex is not
92+
* currently locked by the calling thread.
6393
*/
6494
void mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_mutex_t *),
6595
void (*mutex_free)(mbedtls_threading_mutex_t *),

0 commit comments

Comments
 (0)