mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-17 11:43:37 +00:00
Merge pull request #1121 from gilles-peskine-arm/psa-buffers-test-poison
Memory poisoning function for Asan
This commit is contained in:
commit
dbbfdabfd8
4
ChangeLog.d/8060.txt
Normal file
4
ChangeLog.d/8060.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Features
|
||||
* The CCM and GCM modules no longer depend on MBEDTLS_CIPHER_C. People who
|
||||
use CCM and GCM but don't need the Cipher API can now disable
|
||||
MBEDTLS_CIPHER_C in order to save code size.
|
6
ChangeLog.d/8482.txt
Normal file
6
ChangeLog.d/8482.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Changes
|
||||
* PSA_WANT_ALG_CCM and PSA_WANT_ALG_CCM_STAR_NO_TAG are no more synonyms and
|
||||
they are now treated separately. This means that they should be
|
||||
individually enabled in order to enable respective support; also the
|
||||
corresponding MBEDTLS_PSA_ACCEL symbol should be defined in case
|
||||
acceleration is required.
|
6
ChangeLog.d/add-block-cipher-no-decrypt.txt
Normal file
6
ChangeLog.d/add-block-cipher-no-decrypt.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Features
|
||||
* Enable the new option MBEDTLS_BLOCK_CIPHER_NO_DECRYPT to omit
|
||||
the decryption direction of block ciphers (AES, ARIA, Camellia).
|
||||
This affects both the low-level modules and the high-level APIs
|
||||
(the cipher and PSA interfaces). This option is incompatible with modes
|
||||
that use the decryption direction (ECB in PSA, CBC, XTS, KW) and with DES.
|
3
ChangeLog.d/armv8-aesce.txt
Normal file
3
ChangeLog.d/armv8-aesce.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Features
|
||||
* Support use of Armv8-A Cryptographic Extensions for hardware acclerated
|
||||
AES when compiling for Thumb (T32) or 32-bit Arm (A32).
|
5
ChangeLog.d/gnutls_anti_replay_fail.txt
Normal file
5
ChangeLog.d/gnutls_anti_replay_fail.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Bugfix
|
||||
* Switch to milliseconds as the unit for ticket creation and reception time
|
||||
instead of seconds. That avoids rounding errors when computing the age of
|
||||
tickets compared to peer using a millisecond clock (observed with GnuTLS).
|
||||
Fixes #6623.
|
@ -325,6 +325,28 @@
|
||||
*/
|
||||
#define MBEDTLS_AES_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
*
|
||||
* Remove decryption operation for AES, ARIA and Camellia block cipher.
|
||||
*
|
||||
* \note This feature is incompatible with insecure block cipher,
|
||||
* MBEDTLS_DES_C, and cipher modes which always require decryption
|
||||
* operation, MBEDTLS_CIPHER_MODE_CBC, MBEDTLS_CIPHER_MODE_XTS and
|
||||
* MBEDTLS_NIST_KW_C. When #MBEDTLS_PSA_CRYPTO_CONFIG is enabled,
|
||||
* this feature is incompatible with following supported PSA equivalence,
|
||||
* PSA_WANT_ALG_ECB_NO_PADDING, PSA_WANT_ALG_CBC_NO_PADDING,
|
||||
* PSA_WANT_ALG_CBC_PKCS7 and PSA_WANT_KEY_TYPE_DES.
|
||||
*
|
||||
* Module: library/aes.c
|
||||
* library/aesce.c
|
||||
* library/aesni.c
|
||||
* library/aria.c
|
||||
* library/camellia.c
|
||||
* library/cipher.c
|
||||
*/
|
||||
#define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CIPHER_C
|
||||
*
|
||||
|
@ -155,6 +155,7 @@ MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief This function sets the decryption key.
|
||||
*
|
||||
@ -173,6 +174,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
/**
|
||||
@ -592,6 +594,7 @@ int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief Internal AES block decryption function. This is only
|
||||
* exposed to allow overriding it using see
|
||||
@ -607,6 +610,7 @@ MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
|
@ -98,6 +98,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief This function sets the decryption key.
|
||||
*
|
||||
@ -116,6 +117,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
||||
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/**
|
||||
* \brief This function performs an ARIA single-block encryption or
|
||||
|
@ -81,6 +81,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief Perform a CAMELLIA key schedule operation for decryption.
|
||||
*
|
||||
@ -96,6 +97,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
||||
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/**
|
||||
* \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
|
||||
|
@ -40,6 +40,10 @@
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
|
||||
#if !defined(MBEDTLS_CIPHER_C)
|
||||
#include "mbedtls/block_cipher.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_CCM_DECRYPT 0
|
||||
#define MBEDTLS_CCM_ENCRYPT 1
|
||||
#define MBEDTLS_CCM_STAR_DECRYPT 2
|
||||
@ -80,7 +84,11 @@ typedef struct mbedtls_ccm_context {
|
||||
#MBEDTLS_CCM_DECRYPT or
|
||||
#MBEDTLS_CCM_STAR_ENCRYPT or
|
||||
#MBEDTLS_CCM_STAR_DECRYPT. */
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
#else
|
||||
mbedtls_block_cipher_context_t MBEDTLS_PRIVATE(block_cipher_ctx); /*!< The cipher context used. */
|
||||
#endif
|
||||
int MBEDTLS_PRIVATE(state); /*!< Working value holding context's
|
||||
state. Used for chunked data input */
|
||||
}
|
||||
|
@ -171,6 +171,36 @@
|
||||
#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) && defined(MBEDTLS_PSA_CRYPTO_CONFIG)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_CBC_NO_PADDING cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_CBC_PKCS7)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_CBC_PKCS7 cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_ECB_NO_PADDING)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_ECB_NO_PADDING cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(PSA_WANT_KEY_TYPE_DES)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_KEY_TYPE_DES cannot be defined simultaneously"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_CIPHER_MODE_CBC cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_CIPHER_MODE_XTS cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_DES_C cannot be defined simultaneously"
|
||||
#endif
|
||||
#if defined(MBEDTLS_NIST_KW_C)
|
||||
#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_NIST_KW_C cannot be defined simultaneously"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
|
||||
#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
|
||||
#endif
|
||||
@ -306,19 +336,11 @@
|
||||
#error "MBEDTLS_CCM_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CCM_C) && !defined(MBEDTLS_CIPHER_C)
|
||||
#error "MBEDTLS_CCM_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) && ( \
|
||||
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) && !defined(MBEDTLS_ARIA_C) )
|
||||
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) && !defined(MBEDTLS_CIPHER_C)
|
||||
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C) && !defined(MBEDTLS_CHACHA20_C)
|
||||
#error "MBEDTLS_CHACHAPOLY_C defined, but not all prerequisites"
|
||||
#endif
|
||||
@ -763,9 +785,8 @@
|
||||
#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites (missing RNG)"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && \
|
||||
(defined(PSA_HAVE_SOFT_BLOCK_CIPHER) || defined(PSA_HAVE_SOFT_BLOCK_AEAD)) && \
|
||||
!defined(MBEDTLS_CIPHER_C)
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_HAVE_SOFT_BLOCK_MODE) && \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER) && !defined(MBEDTLS_CIPHER_C)
|
||||
#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
|
@ -480,7 +480,7 @@ static inline size_t mbedtls_cipher_info_get_key_bitlen(
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return info->MBEDTLS_PRIVATE(key_bitlen) << MBEDTLS_KEY_BITLEN_SHIFT;
|
||||
return ((size_t) info->MBEDTLS_PRIVATE(key_bitlen)) << MBEDTLS_KEY_BITLEN_SHIFT;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#ifndef MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
|
||||
#define MBEDTLS_CONFIG_ADJUST_LEGACY_CRYPTO_H
|
||||
|
||||
/* Temporary hack to pacify check_names.py.
|
||||
* (GCM and CCM still hard-depend on CIPHER_C for now.) */
|
||||
/* GCM_C and CCM_C can either depend on (in order of preference) CIPHER_C or
|
||||
* BLOCK_CIPHER_C. If the former is not defined, auto-enable the latter. */
|
||||
#if (defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)) && \
|
||||
!defined(MBEDTLS_CIPHER_C)
|
||||
#define MBEDTLS_BLOCK_CIPHER_C
|
||||
@ -311,6 +311,26 @@
|
||||
#define MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
|
||||
#endif
|
||||
|
||||
/* Some internal helpers to determine which keys are availble. */
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES))
|
||||
#define MBEDTLS_SSL_HAVE_AES
|
||||
#endif
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ARIA_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ARIA))
|
||||
#define MBEDTLS_SSL_HAVE_ARIA
|
||||
#endif
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CAMELLIA_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_CAMELLIA))
|
||||
#define MBEDTLS_SSL_HAVE_CAMELLIA
|
||||
#endif
|
||||
|
||||
/* Some internal helpers to determine which operation modes are availble. */
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CIPHER_MODE_CBC)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CBC_NO_PADDING))
|
||||
#define MBEDTLS_SSL_HAVE_CBC
|
||||
#endif
|
||||
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_GCM_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM))
|
||||
#define MBEDTLS_SSL_HAVE_GCM
|
||||
|
@ -847,11 +847,20 @@
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG 1
|
||||
#define MBEDTLS_CCM_C
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CCM */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CCM_STAR_NO_TAG)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CCM_STAR_NO_TAG) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG 1
|
||||
#define MBEDTLS_CCM_C
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CCM_STAR_NO_TAG */
|
||||
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_GCM) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
|
@ -25,9 +25,11 @@
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG 1
|
||||
#define PSA_WANT_ALG_CCM 1
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM_STAR_NO_TAG 1
|
||||
#define PSA_WANT_ALG_CCM_STAR_NO_TAG 1
|
||||
#endif /* MBEDTLS_CIPHER_C */
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
@ -247,8 +249,9 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) || \
|
||||
defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C)
|
||||
#if (defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) || \
|
||||
defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C)) && \
|
||||
defined(MBEDTLS_CIPHER_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1
|
||||
#define PSA_WANT_ALG_ECB_NO_PADDING 1
|
||||
#endif
|
||||
|
@ -120,7 +120,12 @@
|
||||
/* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
|
||||
#if !defined(MBEDTLS_PRINTF_MS_TIME)
|
||||
#include <inttypes.h>
|
||||
#if !defined(PRId64)
|
||||
#define MBEDTLS_PRINTF_MS_TIME MBEDTLS_PRINTF_LONGLONG
|
||||
#else
|
||||
#define MBEDTLS_PRINTF_MS_TIME PRId64
|
||||
#endif
|
||||
#endif /* MBEDTLS_PRINTF_MS_TIME */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -24,6 +24,10 @@
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
|
||||
#if !defined(MBEDTLS_CIPHER_C)
|
||||
#include "mbedtls/block_cipher.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBEDTLS_GCM_ENCRYPT 1
|
||||
@ -46,7 +50,11 @@ extern "C" {
|
||||
* \brief The GCM context structure.
|
||||
*/
|
||||
typedef struct mbedtls_gcm_context {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
#else
|
||||
mbedtls_block_cipher_context_t MBEDTLS_PRIVATE(block_cipher_ctx); /*!< The cipher context used. */
|
||||
#endif
|
||||
uint64_t MBEDTLS_PRIVATE(HL)[16]; /*!< Precalculated HTable low. */
|
||||
uint64_t MBEDTLS_PRIVATE(HH)[16]; /*!< Precalculated HTable high. */
|
||||
uint64_t MBEDTLS_PRIVATE(len); /*!< The total length of the encrypted data. */
|
||||
|
@ -2238,7 +2238,7 @@
|
||||
/**
|
||||
* \def MBEDTLS_AESCE_C
|
||||
*
|
||||
* Enable AES cryptographic extension support on 64-bit Arm.
|
||||
* Enable AES cryptographic extension support on Armv8.
|
||||
*
|
||||
* Module: library/aesce.c
|
||||
* Caller: library/aes.c
|
||||
@ -2249,13 +2249,15 @@
|
||||
* system, Armv8-A Cryptographic Extensions must be supported by
|
||||
* the CPU when this option is enabled.
|
||||
*
|
||||
* \note Minimum compiler versions for this feature are Clang 4.0,
|
||||
* armclang 6.6, GCC 6.0 or MSVC 2019 version 16.11.2.
|
||||
* \note Minimum compiler versions for this feature when targeting aarch64
|
||||
* are Clang 4.0; armclang 6.6; GCC 6.0; or MSVC 2019 version 16.11.2.
|
||||
* Minimum compiler versions for this feature when targeting 32-bit
|
||||
* Arm or Thumb are Clang 11.0; armclang 6.20; or GCC 6.0.
|
||||
*
|
||||
* \note \c CFLAGS must be set to a minimum of \c -march=armv8-a+crypto for
|
||||
* armclang <= 6.9
|
||||
*
|
||||
* This module adds support for the AES Armv8-A Cryptographic Extensions on Aarch64 systems.
|
||||
* This module adds support for the AES Armv8-A Cryptographic Extensions on Armv8 systems.
|
||||
*/
|
||||
#define MBEDTLS_AESCE_C
|
||||
|
||||
@ -2374,6 +2376,28 @@
|
||||
*/
|
||||
#define MBEDTLS_BASE64_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
*
|
||||
* Remove decryption operation for AES, ARIA and Camellia block cipher.
|
||||
*
|
||||
* \note This feature is incompatible with insecure block cipher,
|
||||
* MBEDTLS_DES_C, and cipher modes which always require decryption
|
||||
* operation, MBEDTLS_CIPHER_MODE_CBC, MBEDTLS_CIPHER_MODE_XTS and
|
||||
* MBEDTLS_NIST_KW_C. When #MBEDTLS_PSA_CRYPTO_CONFIG is enabled,
|
||||
* this feature is incompatible with following supported PSA equivalence,
|
||||
* PSA_WANT_ALG_ECB_NO_PADDING, PSA_WANT_ALG_CBC_NO_PADDING,
|
||||
* PSA_WANT_ALG_CBC_PKCS7 and PSA_WANT_KEY_TYPE_DES.
|
||||
*
|
||||
* Module: library/aes.c
|
||||
* library/aesce.c
|
||||
* library/aesni.c
|
||||
* library/aria.c
|
||||
* library/camellia.c
|
||||
* library/cipher.c
|
||||
*/
|
||||
//#define MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_BIGNUM_C
|
||||
*
|
||||
@ -4099,20 +4123,23 @@
|
||||
/**
|
||||
* \def MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE
|
||||
*
|
||||
* Maximum time difference in milliseconds tolerated between the age of a
|
||||
* ticket from the server and client point of view.
|
||||
* From the client point of view, the age of a ticket is the time difference
|
||||
* between the time when the client proposes to the server to use the ticket
|
||||
* (time of writing of the Pre-Shared Key Extension including the ticket) and
|
||||
* the time the client received the ticket from the server.
|
||||
* From the server point of view, the age of a ticket is the time difference
|
||||
* between the time when the server receives a proposition from the client
|
||||
* to use the ticket and the time when the ticket was created by the server.
|
||||
* The server age is expected to be always greater than the client one and
|
||||
* MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE defines the
|
||||
* maximum difference tolerated for the server to accept the ticket.
|
||||
* This is not used in TLS 1.2.
|
||||
* Maximum allowed ticket age difference in milliseconds tolerated between
|
||||
* server and client. Default value is 6000. This is not used in TLS 1.2.
|
||||
*
|
||||
* - The client ticket age is the time difference between the time when the
|
||||
* client proposes to the server to use the ticket and the time the client
|
||||
* received the ticket from the server.
|
||||
* - The server ticket age is the time difference between the time when the
|
||||
* server receives a proposition from the client to use the ticket and the
|
||||
* time when the ticket was created by the server.
|
||||
*
|
||||
* The ages might be different due to the client and server clocks not running
|
||||
* at the same pace. The typical accuracy of an RTC crystal is ±100 to ±20 parts
|
||||
* per million (360 to 72 milliseconds per hour). Default tolerance window is
|
||||
* 6s, thus in the worst case clients and servers must sync up their system time
|
||||
* every 6000/360/2~=8 hours.
|
||||
*
|
||||
* See section 8.3 of the TLS 1.3 specification(RFC 8446) for more information.
|
||||
*/
|
||||
//#define MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE 6000
|
||||
|
||||
|
@ -600,26 +600,6 @@
|
||||
|
||||
#define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
|
||||
|
||||
/* Some internal helpers to determine which keys are availble. */
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_AES_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_AES))
|
||||
#define MBEDTLS_SSL_HAVE_AES
|
||||
#endif
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CAMELLIA_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_CAMELLIA))
|
||||
#define MBEDTLS_SSL_HAVE_CAMELLIA
|
||||
#endif
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ARIA_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ARIA))
|
||||
#define MBEDTLS_SSL_HAVE_ARIA
|
||||
#endif
|
||||
|
||||
/* Some internal helpers to determine which operation modes are availble. */
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_CIPHER_MODE_CBC)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CBC_NO_PADDING))
|
||||
#define MBEDTLS_SSL_HAVE_CBC
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Size defines
|
||||
*/
|
||||
@ -1217,7 +1197,7 @@ struct mbedtls_ssl_session {
|
||||
mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(tls_version);
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
mbedtls_time_t MBEDTLS_PRIVATE(start); /*!< starting time */
|
||||
mbedtls_time_t MBEDTLS_PRIVATE(start); /*!< start time of current session */
|
||||
#endif
|
||||
int MBEDTLS_PRIVATE(ciphersuite); /*!< chosen ciphersuite */
|
||||
size_t MBEDTLS_PRIVATE(id_len); /*!< session id length */
|
||||
@ -1254,9 +1234,14 @@ struct mbedtls_ssl_session {
|
||||
char *MBEDTLS_PRIVATE(hostname); /*!< host name binded with tickets */
|
||||
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION && MBEDTLS_SSL_CLI_C */
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_CLI_C)
|
||||
mbedtls_time_t MBEDTLS_PRIVATE(ticket_received); /*!< time ticket was received */
|
||||
#endif /* MBEDTLS_HAVE_TIME && MBEDTLS_SSL_CLI_C */
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_reception_time); /*!< time when ticket was received. */
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_creation_time); /*!< time when ticket was created. */
|
||||
#endif
|
||||
#endif /* MBEDTLS_HAVE_TIME */
|
||||
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
|
||||
|
||||
|
@ -28,10 +28,14 @@ extern "C" {
|
||||
#include <pthread.h>
|
||||
typedef struct mbedtls_threading_mutex_t {
|
||||
pthread_mutex_t MBEDTLS_PRIVATE(mutex);
|
||||
/* is_valid is 0 after a failed init or a free, and nonzero after a
|
||||
* successful init. This field is not considered part of the public
|
||||
* API of Mbed TLS and may change without notice. */
|
||||
char MBEDTLS_PRIVATE(is_valid);
|
||||
|
||||
/* WARNING - state should only be accessed when holding the mutex lock in
|
||||
* tests/src/threading_helpers.c, otherwise corruption can occur.
|
||||
* state will be 0 after a failed init or a free, and nonzero after a
|
||||
* successful init. This field is for testing only and thus not considered
|
||||
* part of the public API of Mbed TLS and may change without notice.*/
|
||||
char MBEDTLS_PRIVATE(state);
|
||||
|
||||
} mbedtls_threading_mutex_t;
|
||||
#endif
|
||||
|
||||
|
@ -24,12 +24,6 @@
|
||||
#define PSA_WANT_ALG_ECDSA_ANY PSA_WANT_ALG_ECDSA
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_CCM_STAR_NO_TAG) && !defined(PSA_WANT_ALG_CCM)
|
||||
#define PSA_WANT_ALG_CCM PSA_WANT_ALG_CCM_STAR_NO_TAG
|
||||
#elif !defined(PSA_WANT_ALG_CCM_STAR_NO_TAG) && defined(PSA_WANT_ALG_CCM)
|
||||
#define PSA_WANT_ALG_CCM_STAR_NO_TAG PSA_WANT_ALG_CCM
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW
|
||||
#elif !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
|
||||
|
@ -23,9 +23,9 @@
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#if defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
|
||||
#if !((defined(MBEDTLS_ARCH_IS_ARM64) && defined(MBEDTLS_AESCE_C)) || \
|
||||
(defined(MBEDTLS_ARCH_IS_X64) && defined(MBEDTLS_AESNI_C)) || \
|
||||
(defined(MBEDTLS_ARCH_IS_X86) && defined(MBEDTLS_AESNI_C)))
|
||||
#if !((defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_AESCE_C)) || \
|
||||
(defined(MBEDTLS_ARCH_IS_X64) && defined(MBEDTLS_AESNI_C)) || \
|
||||
(defined(MBEDTLS_ARCH_IS_X86) && defined(MBEDTLS_AESNI_C)))
|
||||
#error "MBEDTLS_AES_USE_HARDWARE_ONLY defined, but not all prerequisites"
|
||||
#endif
|
||||
#endif
|
||||
@ -54,6 +54,16 @@
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
/*
|
||||
* This is a convenience shorthand macro to check if we need reverse S-box and
|
||||
* reverse tables. It's private and only defined in this file.
|
||||
*/
|
||||
#if (!defined(MBEDTLS_AES_DECRYPT_ALT) || \
|
||||
(!defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY))) && \
|
||||
!defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
#define MBEDTLS_AES_NEED_REVERSE_TABLES
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_AES_ALT)
|
||||
|
||||
#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)
|
||||
@ -389,7 +399,9 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
|
||||
* generate the forward and reverse S-boxes
|
||||
*/
|
||||
FSb[0x00] = 0x63;
|
||||
#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
|
||||
RSb[0x63] = 0x00;
|
||||
#endif
|
||||
|
||||
for (i = 1; i < 256; i++) {
|
||||
x = pow[255 - log[i]];
|
||||
@ -401,7 +413,9 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
|
||||
x ^= y ^ 0x63;
|
||||
|
||||
FSb[i] = x;
|
||||
#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
|
||||
RSb[x] = (unsigned char) i;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -423,10 +437,9 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
|
||||
FT3[i] = ROTL8(FT2[i]);
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
|
||||
#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
|
||||
x = RSb[i];
|
||||
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || \
|
||||
(!defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY))
|
||||
RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
|
||||
((uint32_t) MUL(0x09, x) << 8) ^
|
||||
((uint32_t) MUL(0x0D, x) << 16) ^
|
||||
@ -437,8 +450,7 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
|
||||
RT2[i] = ROTL8(RT1[i]);
|
||||
RT3[i] = ROTL8(RT2[i]);
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
#endif \
|
||||
/* !defined(MBEDTLS_AES_DECRYPT_ALT) || (!defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)) */
|
||||
#endif /* MBEDTLS_AES_NEED_REVERSE_TABLES */
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,7 +682,7 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
/*
|
||||
* AES key schedule (decryption)
|
||||
*/
|
||||
#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits)
|
||||
{
|
||||
@ -739,7 +751,7 @@ exit:
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_SETKEY_DEC_ALT */
|
||||
#endif /* !MBEDTLS_AES_SETKEY_DEC_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
static int mbedtls_aes_xts_decode_keys(const unsigned char *key,
|
||||
@ -928,7 +940,7 @@ int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
|
||||
/*
|
||||
* AES-ECB block decryption
|
||||
*/
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT)
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16])
|
||||
@ -985,7 +997,7 @@ int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
|
||||
#endif /* !MBEDTLS_AES_DECRYPT_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/* VIA Padlock and our intrinsics-based implementation of AESNI require
|
||||
* the round keys to be aligned on a 16-byte boundary. We take care of this
|
||||
@ -1040,13 +1052,15 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
|
||||
if (mode == MBEDTLS_AES_ENCRYPT) {
|
||||
return mbedtls_internal_aes_encrypt(ctx, input, output);
|
||||
} else {
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
return mbedtls_internal_aes_decrypt(ctx, input, output);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
|
||||
{
|
||||
return mbedtls_internal_aes_encrypt(ctx, input, output);
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
@ -1472,6 +1486,7 @@ exit:
|
||||
*
|
||||
* http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static const unsigned char aes_test_ecb_dec[][16] =
|
||||
{
|
||||
{ 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
|
||||
@ -1483,6 +1498,7 @@ static const unsigned char aes_test_ecb_dec[][16] =
|
||||
0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
static const unsigned char aes_test_ecb_enc[][16] =
|
||||
{
|
||||
@ -1864,7 +1880,7 @@ int mbedtls_aes_self_test(int verbose)
|
||||
*/
|
||||
{
|
||||
static const int num_tests =
|
||||
sizeof(aes_test_ecb_dec) / sizeof(*aes_test_ecb_dec);
|
||||
sizeof(aes_test_ecb_enc) / sizeof(*aes_test_ecb_enc);
|
||||
|
||||
for (i = 0; i < num_tests << 1; i++) {
|
||||
u = i >> 1;
|
||||
@ -1875,13 +1891,24 @@ int mbedtls_aes_self_test(int verbose)
|
||||
mbedtls_printf(" AES-ECB-%3u (%s): ", keybits,
|
||||
(mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
|
||||
}
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf("skipped\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(buf, 0, 16);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
ret = mbedtls_aes_setkey_dec(&ctx, key, keybits);
|
||||
aes_tests = aes_test_ecb_dec[u];
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
|
||||
aes_tests = aes_test_ecb_enc[u];
|
||||
}
|
||||
|
171
library/aesce.c
171
library/aesce.c
@ -5,8 +5,17 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#if defined(__aarch64__) && !defined(__ARM_FEATURE_CRYPTO) && \
|
||||
defined(__clang__) && __clang_major__ >= 4
|
||||
#if defined(__clang__) && (__clang_major__ >= 4)
|
||||
|
||||
/* Ideally, we would simply use MBEDTLS_ARCH_IS_ARMV8_A in the following #if,
|
||||
* but that is defined by build_info.h, and we need this block to happen first. */
|
||||
#if defined(__ARM_ARCH)
|
||||
#if __ARM_ARCH >= 8
|
||||
#define MBEDTLS_AESCE_ARCH_IS_ARMV8_A
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_AESCE_ARCH_IS_ARMV8_A) && !defined(__ARM_FEATURE_CRYPTO)
|
||||
/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
|
||||
*
|
||||
* The intrinsic declaration are guarded by predefined ACLE macros in clang:
|
||||
@ -27,6 +36,8 @@
|
||||
#define MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG
|
||||
#endif
|
||||
|
||||
#endif /* defined(__clang__) && (__clang_major__ >= 4) */
|
||||
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
|
||||
@ -34,12 +45,14 @@
|
||||
|
||||
#include "aesce.h"
|
||||
|
||||
#if defined(MBEDTLS_ARCH_IS_ARM64)
|
||||
#if defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(__ARM_NEON)
|
||||
|
||||
/* Compiler version checks. */
|
||||
#if defined(__clang__)
|
||||
# if __clang_major__ < 4
|
||||
# error "Minimum version of Clang for MBEDTLS_AESCE_C is 4.0."
|
||||
# if defined(MBEDTLS_ARCH_IS_ARM32) && (__clang_major__ < 11)
|
||||
# error "Minimum version of Clang for MBEDTLS_AESCE_C on 32-bit Arm or Thumb is 11.0."
|
||||
# elif defined(MBEDTLS_ARCH_IS_ARM64) && (__clang_major__ < 4)
|
||||
# error "Minimum version of Clang for MBEDTLS_AESCE_C on aarch64 is 4.0."
|
||||
# endif
|
||||
#elif defined(__GNUC__)
|
||||
# if __GNUC__ < 6
|
||||
@ -52,6 +65,15 @@
|
||||
# if _MSC_VER < 1929
|
||||
# error "Minimum version of MSVC for MBEDTLS_AESCE_C is 2019 version 16.11.2."
|
||||
# endif
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
# if defined(MBEDTLS_ARCH_IS_ARM32) && (__ARMCC_VERSION < 6200002)
|
||||
/* TODO: We haven't verified armclang for 32-bit Arm/Thumb prior to 6.20.
|
||||
* If someone verified that, please update this and document of
|
||||
* `MBEDTLS_AESCE_C` in `mbedtls_config.h`. */
|
||||
# error "Minimum version of armclang for MBEDTLS_AESCE_C on 32-bit Arm is 6.20."
|
||||
# elif defined(MBEDTLS_ARCH_IS_ARM64) && (__ARMCC_VERSION < 6060000)
|
||||
# error "Minimum version of armclang for MBEDTLS_AESCE_C on aarch64 is 6.6."
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __ARM_NEON
|
||||
@ -84,8 +106,19 @@
|
||||
|
||||
#if defined(__linux__) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
|
||||
|
||||
#include <asm/hwcap.h>
|
||||
#include <sys/auxv.h>
|
||||
#if !defined(HWCAP_NEON)
|
||||
#define HWCAP_NEON (1 << 12)
|
||||
#endif
|
||||
#if !defined(HWCAP2_AES)
|
||||
#define HWCAP2_AES (1 << 0)
|
||||
#endif
|
||||
#if !defined(HWCAP_AES)
|
||||
#define HWCAP_AES (1 << 3)
|
||||
#endif
|
||||
#if !defined(HWCAP_ASIMD)
|
||||
#define HWCAP_ASIMD (1 << 1)
|
||||
#endif
|
||||
|
||||
signed char mbedtls_aesce_has_support_result = -1;
|
||||
|
||||
@ -102,6 +135,16 @@ int mbedtls_aesce_has_support_impl(void)
|
||||
* once, but that is harmless.
|
||||
*/
|
||||
if (mbedtls_aesce_has_support_result == -1) {
|
||||
#if defined(MBEDTLS_ARCH_IS_ARM32)
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
unsigned long auxval2 = getauxval(AT_HWCAP2);
|
||||
if (((auxval & HWCAP_NEON) == HWCAP_NEON) &&
|
||||
((auxval2 & HWCAP2_AES) == HWCAP2_AES)) {
|
||||
mbedtls_aesce_has_support_result = 1;
|
||||
} else {
|
||||
mbedtls_aesce_has_support_result = 0;
|
||||
}
|
||||
#else
|
||||
unsigned long auxval = getauxval(AT_HWCAP);
|
||||
if ((auxval & (HWCAP_ASIMD | HWCAP_AES)) ==
|
||||
(HWCAP_ASIMD | HWCAP_AES)) {
|
||||
@ -109,6 +152,7 @@ int mbedtls_aesce_has_support_impl(void)
|
||||
} else {
|
||||
mbedtls_aesce_has_support_result = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return mbedtls_aesce_has_support_result;
|
||||
}
|
||||
@ -187,6 +231,7 @@ rounds_10:
|
||||
/* Two rounds of AESCE decryption */
|
||||
#define AESCE_DECRYPT_ROUND_X2 AESCE_DECRYPT_ROUND; AESCE_DECRYPT_ROUND
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static uint8x16_t aesce_decrypt_block(uint8x16_t block,
|
||||
unsigned char *keys,
|
||||
int rounds)
|
||||
@ -218,6 +263,7 @@ rounds_10:
|
||||
|
||||
return block;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* AES-ECB block en(de)cryption
|
||||
@ -230,10 +276,15 @@ int mbedtls_aesce_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
uint8x16_t block = vld1q_u8(&input[0]);
|
||||
unsigned char *keys = (unsigned char *) (ctx->buf + ctx->rk_offset);
|
||||
|
||||
if (mode == MBEDTLS_AES_ENCRYPT) {
|
||||
block = aesce_encrypt_block(block, keys, ctx->nr);
|
||||
} else {
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
block = aesce_decrypt_block(block, keys, ctx->nr);
|
||||
} else
|
||||
#else
|
||||
(void) mode;
|
||||
#endif
|
||||
{
|
||||
block = aesce_encrypt_block(block, keys, ctx->nr);
|
||||
}
|
||||
vst1q_u8(&output[0], block);
|
||||
|
||||
@ -243,6 +294,7 @@ int mbedtls_aesce_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
/*
|
||||
* Compute decryption round keys from encryption round keys
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
void mbedtls_aesce_inverse_key(unsigned char *invkey,
|
||||
const unsigned char *fwdkey,
|
||||
int nr)
|
||||
@ -257,6 +309,7 @@ void mbedtls_aesce_inverse_key(unsigned char *invkey,
|
||||
vst1q_u8(invkey + i * 16, vld1q_u8(fwdkey + j * 16));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t aes_rot_word(uint32_t word)
|
||||
{
|
||||
@ -300,7 +353,7 @@ static void aesce_setkey_enc(unsigned char *rk,
|
||||
rki + key_len_in_words < rko_end;
|
||||
rki += key_len_in_words) {
|
||||
|
||||
size_t iteration = (rki - (uint32_t *) rk) / key_len_in_words;
|
||||
size_t iteration = (size_t) (rki - (uint32_t *) rk) / key_len_in_words;
|
||||
uint32_t *rko;
|
||||
rko = rki + key_len_in_words;
|
||||
rko[0] = aes_rot_word(aes_sub_word(rki[key_len_in_words - 1]));
|
||||
@ -353,24 +406,91 @@ int mbedtls_aesce_setkey_enc(unsigned char *rk,
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
|
||||
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 5
|
||||
/* Some intrinsics are not available for GCC 5.X. */
|
||||
#define vreinterpretq_p64_u8(a) ((poly64x2_t) a)
|
||||
#define vreinterpretq_u8_p128(a) ((uint8x16_t) a)
|
||||
static inline poly64_t vget_low_p64(poly64x2_t __a)
|
||||
#if defined(MBEDTLS_ARCH_IS_ARM32)
|
||||
|
||||
#if defined(__clang__)
|
||||
/* On clang for A32/T32, work around some missing intrinsics and types which are listed in
|
||||
* [ACLE](https://arm-software.github.io/acle/neon_intrinsics/advsimd.html#polynomial-1)
|
||||
* These are only required for GCM.
|
||||
*/
|
||||
#define vreinterpretq_u64_p64(a) ((uint64x2_t) a)
|
||||
|
||||
typedef uint8x16_t poly128_t;
|
||||
|
||||
static inline poly128_t vmull_p64(poly64_t a, poly64_t b)
|
||||
{
|
||||
uint64x2_t tmp = (uint64x2_t) (__a);
|
||||
uint64x1_t lo = vcreate_u64(vgetq_lane_u64(tmp, 0));
|
||||
return (poly64_t) (lo);
|
||||
poly128_t r;
|
||||
asm ("vmull.p64 %[r], %[a], %[b]" : [r] "=w" (r) : [a] "w" (a), [b] "w" (b) :);
|
||||
return r;
|
||||
}
|
||||
#endif /* !__clang__ && __GNUC__ && __GNUC__ == 5*/
|
||||
|
||||
/* This is set to cause some more missing intrinsics to be defined below */
|
||||
#define COMMON_MISSING_INTRINSICS
|
||||
|
||||
static inline poly128_t vmull_high_p64(poly64x2_t a, poly64x2_t b)
|
||||
{
|
||||
return vmull_p64((poly64_t) (vget_high_u64((uint64x2_t) a)),
|
||||
(poly64_t) (vget_high_u64((uint64x2_t) b)));
|
||||
}
|
||||
|
||||
#endif /* defined(__clang__) */
|
||||
|
||||
static inline uint8x16_t vrbitq_u8(uint8x16_t x)
|
||||
{
|
||||
/* There is no vrbitq_u8 instruction in A32/T32, so provide
|
||||
* an equivalent non-Neon implementation. Reverse bit order in each
|
||||
* byte with 4x rbit, rev. */
|
||||
asm ("ldm %[p], { r2-r5 } \n\t"
|
||||
"rbit r2, r2 \n\t"
|
||||
"rev r2, r2 \n\t"
|
||||
"rbit r3, r3 \n\t"
|
||||
"rev r3, r3 \n\t"
|
||||
"rbit r4, r4 \n\t"
|
||||
"rev r4, r4 \n\t"
|
||||
"rbit r5, r5 \n\t"
|
||||
"rev r5, r5 \n\t"
|
||||
"stm %[p], { r2-r5 } \n\t"
|
||||
:
|
||||
/* Output: 16 bytes of memory pointed to by &x */
|
||||
"+m" (*(uint8_t(*)[16]) &x)
|
||||
:
|
||||
[p] "r" (&x)
|
||||
:
|
||||
"r2", "r3", "r4", "r5"
|
||||
);
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif /* defined(MBEDTLS_ARCH_IS_ARM32) */
|
||||
|
||||
#if defined(MBEDTLS_COMPILER_IS_GCC) && __GNUC__ == 5
|
||||
/* Some intrinsics are not available for GCC 5.X. */
|
||||
#define COMMON_MISSING_INTRINSICS
|
||||
#endif /* MBEDTLS_COMPILER_IS_GCC && __GNUC__ == 5 */
|
||||
|
||||
|
||||
#if defined(COMMON_MISSING_INTRINSICS)
|
||||
|
||||
/* Missing intrinsics common to both GCC 5, and Clang on 32-bit */
|
||||
|
||||
#define vreinterpretq_p64_u8(a) ((poly64x2_t) a)
|
||||
#define vreinterpretq_u8_p128(a) ((uint8x16_t) a)
|
||||
|
||||
static inline poly64x1_t vget_low_p64(poly64x2_t a)
|
||||
{
|
||||
uint64x1_t r = vget_low_u64(vreinterpretq_u64_p64(a));
|
||||
return (poly64x1_t) r;
|
||||
|
||||
}
|
||||
|
||||
#endif /* COMMON_MISSING_INTRINSICS */
|
||||
|
||||
/* vmull_p64/vmull_high_p64 wrappers.
|
||||
*
|
||||
* Older compilers miss some intrinsic functions for `poly*_t`. We use
|
||||
* uint8x16_t and uint8x16x3_t as input/output parameters.
|
||||
*/
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#if defined(MBEDTLS_COMPILER_IS_GCC)
|
||||
/* GCC reports incompatible type error without cast. GCC think poly64_t and
|
||||
* poly64x1_t are different, that is different with MSVC and Clang. */
|
||||
#define MBEDTLS_VMULL_P64(a, b) vmull_p64((poly64_t) a, (poly64_t) b)
|
||||
@ -379,14 +499,15 @@ static inline poly64_t vget_low_p64(poly64x2_t __a)
|
||||
* error with/without cast. And I think poly64_t and poly64x1_t are same, no
|
||||
* cast for clang also. */
|
||||
#define MBEDTLS_VMULL_P64(a, b) vmull_p64(a, b)
|
||||
#endif
|
||||
#endif /* MBEDTLS_COMPILER_IS_GCC */
|
||||
|
||||
static inline uint8x16_t pmull_low(uint8x16_t a, uint8x16_t b)
|
||||
{
|
||||
|
||||
return vreinterpretq_u8_p128(
|
||||
MBEDTLS_VMULL_P64(
|
||||
vget_low_p64(vreinterpretq_p64_u8(a)),
|
||||
vget_low_p64(vreinterpretq_p64_u8(b))
|
||||
(poly64_t) vget_low_p64(vreinterpretq_p64_u8(a)),
|
||||
(poly64_t) vget_low_p64(vreinterpretq_p64_u8(b))
|
||||
));
|
||||
}
|
||||
|
||||
@ -455,7 +576,7 @@ static inline uint8x16_t poly_mult_reduce(uint8x16x3_t input)
|
||||
/* use 'asm' as an optimisation barrier to prevent loading MODULO from
|
||||
* memory. It is for GNUC compatible compilers.
|
||||
*/
|
||||
asm ("" : "+w" (r));
|
||||
asm volatile ("" : "+w" (r));
|
||||
#endif
|
||||
uint8x16_t const MODULO = vreinterpretq_u8_u64(vshrq_n_u64(r, 64 - 8));
|
||||
uint8x16_t h, m, l; /* input high/middle/low 128b */
|
||||
@ -498,6 +619,6 @@ void mbedtls_aesce_gcm_mult(unsigned char c[16],
|
||||
#undef MBEDTLS_POP_TARGET_PRAGMA
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_ARCH_IS_ARM64 */
|
||||
#endif /* MBEDTLS_ARCH_IS_ARMV8_A */
|
||||
|
||||
#endif /* MBEDTLS_AESCE_C */
|
||||
|
@ -2,7 +2,7 @@
|
||||
* \file aesce.h
|
||||
*
|
||||
* \brief Support hardware AES acceleration on Armv8-A processors with
|
||||
* the Armv8-A Cryptographic Extension in AArch64 execution state.
|
||||
* the Armv8-A Cryptographic Extension.
|
||||
*
|
||||
* \warning These functions are only for internal use by other library
|
||||
* functions; you must not call them directly.
|
||||
@ -19,7 +19,7 @@
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
|
||||
#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_ARCH_IS_ARM64)
|
||||
#if defined(MBEDTLS_AESCE_C) && defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(__ARM_NEON)
|
||||
|
||||
#define MBEDTLS_AESCE_HAVE_CODE
|
||||
|
||||
@ -87,6 +87,7 @@ void mbedtls_aesce_gcm_mult(unsigned char c[16],
|
||||
const unsigned char b[16]);
|
||||
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief Internal round key inversion. This function computes
|
||||
* decryption round keys from the encryption round keys.
|
||||
@ -98,6 +99,7 @@ void mbedtls_aesce_gcm_mult(unsigned char c[16],
|
||||
void mbedtls_aesce_inverse_key(unsigned char *invkey,
|
||||
const unsigned char *fwdkey,
|
||||
int nr);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/**
|
||||
* \brief Internal key expansion for encryption
|
||||
@ -116,6 +118,12 @@ int mbedtls_aesce_setkey_enc(unsigned char *rk,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_AESCE_C && MBEDTLS_ARCH_IS_ARM64 */
|
||||
#else
|
||||
|
||||
#if defined(MBEDTLS_AES_USE_HARDWARE_ONLY) && defined(MBEDTLS_ARCH_IS_ARMV8_A)
|
||||
#error "AES hardware acceleration not supported on this platform"
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_AESCE_C && MBEDTLS_ARCH_IS_ARMV8_A && __ARM_NEON */
|
||||
|
||||
#endif /* MBEDTLS_AESCE_H */
|
||||
|
@ -94,14 +94,19 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
++rk;
|
||||
--nr;
|
||||
|
||||
if (mode == 0) {
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
while (nr != 0) {
|
||||
state = _mm_aesdec_si128(state, *rk);
|
||||
++rk;
|
||||
--nr;
|
||||
}
|
||||
state = _mm_aesdeclast_si128(state, *rk);
|
||||
} else {
|
||||
} else
|
||||
#else
|
||||
(void) mode;
|
||||
#endif
|
||||
{
|
||||
while (nr != 0) {
|
||||
state = _mm_aesenc_si128(state, *rk);
|
||||
++rk;
|
||||
@ -218,6 +223,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||
/*
|
||||
* Compute decryption round keys from encryption round keys
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||
const unsigned char *fwdkey, int nr)
|
||||
{
|
||||
@ -230,6 +236,7 @@ void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||
}
|
||||
*ik = *fk;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Key expansion, 128-bit case
|
||||
@ -465,6 +472,7 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
"jnz 1b \n\t"
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||
AESENCLAST(xmm1_xmm0) // last round
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
"jmp 3f \n\t"
|
||||
|
||||
"2: \n\t" // decryption loop
|
||||
@ -475,6 +483,7 @@ int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
"jnz 2b \n\t"
|
||||
"movdqu (%1), %%xmm1 \n\t" // load round key
|
||||
AESDECLAST(xmm1_xmm0) // last round
|
||||
#endif
|
||||
|
||||
"3: \n\t"
|
||||
"movdqu %%xmm0, (%4) \n\t" // export output
|
||||
@ -601,6 +610,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||
/*
|
||||
* Compute decryption round keys from encryption round keys
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||
const unsigned char *fwdkey, int nr)
|
||||
{
|
||||
@ -620,6 +630,7 @@ void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||
|
||||
memcpy(ik, fk, 16);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Key expansion, 128-bit case
|
||||
|
@ -119,6 +119,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||
const unsigned char a[16],
|
||||
const unsigned char b[16]);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/**
|
||||
* \brief Internal round key inversion. This function computes
|
||||
* decryption round keys from the encryption round keys.
|
||||
@ -133,6 +134,7 @@ void mbedtls_aesni_gcm_mult(unsigned char c[16],
|
||||
void mbedtls_aesni_inverse_key(unsigned char *invkey,
|
||||
const unsigned char *fwdkey,
|
||||
int nr);
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/**
|
||||
* \brief Internal key expansion for encryption
|
||||
@ -155,6 +157,6 @@ int mbedtls_aesni_setkey_enc(unsigned char *rk,
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_AESNI_HAVE_CODE */
|
||||
#endif /* MBEDTLS_AESNI_C */
|
||||
#endif /* MBEDTLS_AESNI_C && (MBEDTLS_ARCH_IS_X64 || MBEDTLS_ARCH_IS_X86) */
|
||||
|
||||
#endif /* MBEDTLS_AESNI_H */
|
||||
|
@ -413,6 +413,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
||||
/*
|
||||
* Set decryption key
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||
const unsigned char *key, unsigned int keybits)
|
||||
{
|
||||
@ -442,6 +443,7 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/*
|
||||
* Encrypt a block
|
||||
@ -872,12 +874,18 @@ int mbedtls_aria_self_test(int verbose)
|
||||
/* test ECB decryption */
|
||||
if (verbose) {
|
||||
mbedtls_printf(" ARIA-ECB-%d (dec): ", 128 + 64 * i);
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
mbedtls_printf("skipped\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
mbedtls_aria_setkey_dec(&ctx, aria_test1_ecb_key, 128 + 64 * i);
|
||||
mbedtls_aria_crypt_ecb(&ctx, aria_test1_ecb_ct[i], blk);
|
||||
ARIA_SELF_TEST_ASSERT(
|
||||
memcmp(blk, aria_test1_ecb_pt, MBEDTLS_ARIA_BLOCKSIZE)
|
||||
!= 0);
|
||||
#endif
|
||||
}
|
||||
if (verbose) {
|
||||
mbedtls_printf("\n");
|
||||
|
@ -116,7 +116,7 @@ int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen,
|
||||
*p++ = '=';
|
||||
}
|
||||
|
||||
*olen = p - dst;
|
||||
*olen = (size_t) (p - dst);
|
||||
*p = 0;
|
||||
|
||||
return 0;
|
||||
@ -225,7 +225,7 @@ int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,
|
||||
}
|
||||
}
|
||||
|
||||
*olen = p - dst;
|
||||
*olen = (size_t) (p - dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -701,7 +701,7 @@ int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix,
|
||||
}
|
||||
|
||||
*p++ = '\0';
|
||||
*olen = p - buf;
|
||||
*olen = (size_t) (p - buf);
|
||||
|
||||
cleanup:
|
||||
|
||||
|
@ -399,6 +399,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
||||
/*
|
||||
* Camellia key schedule (decryption)
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits)
|
||||
@ -444,6 +445,7 @@ exit:
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
|
||||
/*
|
||||
* Camellia-ECB block encryption/decryption
|
||||
@ -888,14 +890,26 @@ int mbedtls_camellia_self_test(int verbose)
|
||||
(v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (v == MBEDTLS_CAMELLIA_DECRYPT) {
|
||||
if (verbose != 0) {
|
||||
mbedtls_printf("skipped\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < CAMELLIA_TESTS_ECB; i++) {
|
||||
memcpy(key, camellia_test_ecb_key[u][i], 16 + 8 * u);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (v == MBEDTLS_CAMELLIA_DECRYPT) {
|
||||
mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64);
|
||||
memcpy(src, camellia_test_ecb_cipher[u][i], 16);
|
||||
memcpy(dst, camellia_test_ecb_plain[i], 16);
|
||||
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
|
||||
} else
|
||||
#endif
|
||||
{ /* MBEDTLS_CAMELLIA_ENCRYPT */
|
||||
mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64);
|
||||
memcpy(src, camellia_test_ecb_plain[i], 16);
|
||||
memcpy(dst, camellia_test_ecb_cipher[u][i], 16);
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
|
||||
#if !defined(MBEDTLS_CIPHER_C)
|
||||
#include "block_cipher_internal.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
@ -51,6 +55,8 @@ int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx,
|
||||
unsigned int keybits)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_values(cipher, keybits,
|
||||
@ -73,6 +79,17 @@ int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx,
|
||||
MBEDTLS_ENCRYPT)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
|
||||
|
||||
if ((ret = mbedtls_block_cipher_setup(&ctx->block_cipher_ctx, cipher)) != 0) {
|
||||
return MBEDTLS_ERR_CCM_BAD_INPUT;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_block_cipher_setkey(&ctx->block_cipher_ctx, key, keybits)) != 0) {
|
||||
return MBEDTLS_ERR_CCM_BAD_INPUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -85,7 +102,11 @@ void mbedtls_ccm_free(mbedtls_ccm_context *ctx)
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
mbedtls_cipher_free(&ctx->cipher_ctx);
|
||||
#else
|
||||
mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
|
||||
#endif
|
||||
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ccm_context));
|
||||
}
|
||||
|
||||
@ -104,12 +125,16 @@ static int mbedtls_ccm_crypt(mbedtls_ccm_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
size_t olen = 0;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char tmp_buf[16] = { 0 };
|
||||
|
||||
if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->ctr, 16, tmp_buf,
|
||||
&olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen = 0;
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->ctr, 16, tmp_buf, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->ctr, tmp_buf);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ctx->state |= CCM_STATE__ERROR;
|
||||
mbedtls_platform_zeroize(tmp_buf, sizeof(tmp_buf));
|
||||
return ret;
|
||||
@ -132,7 +157,10 @@ static int ccm_calculate_first_block_if_ready(mbedtls_ccm_context *ctx)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char i;
|
||||
size_t len_left, olen;
|
||||
size_t len_left;
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen;
|
||||
#endif
|
||||
|
||||
/* length calculation can be done only after both
|
||||
* mbedtls_ccm_starts() and mbedtls_ccm_set_lengths() have been executed
|
||||
@ -178,7 +206,12 @@ static int ccm_calculate_first_block_if_ready(mbedtls_ccm_context *ctx)
|
||||
}
|
||||
|
||||
/* Start CBC-MAC with first block*/
|
||||
if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ctx->state |= CCM_STATE__ERROR;
|
||||
return ret;
|
||||
}
|
||||
@ -258,7 +291,10 @@ int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx,
|
||||
size_t add_len)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t olen, use_len, offset;
|
||||
size_t use_len, offset;
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen;
|
||||
#endif
|
||||
|
||||
if (ctx->state & CCM_STATE__ERROR) {
|
||||
return MBEDTLS_ERR_CCM_BAD_INPUT;
|
||||
@ -298,8 +334,12 @@ int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx,
|
||||
add += use_len;
|
||||
|
||||
if (use_len + offset == 16 || ctx->processed == ctx->add_len) {
|
||||
if ((ret =
|
||||
mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ctx->state |= CCM_STATE__ERROR;
|
||||
return ret;
|
||||
}
|
||||
@ -322,7 +362,10 @@ int mbedtls_ccm_update(mbedtls_ccm_context *ctx,
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char i;
|
||||
size_t use_len, offset, olen;
|
||||
size_t use_len, offset;
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen;
|
||||
#endif
|
||||
|
||||
unsigned char local_output[16];
|
||||
|
||||
@ -360,8 +403,12 @@ int mbedtls_ccm_update(mbedtls_ccm_context *ctx,
|
||||
mbedtls_xor(ctx->y + offset, ctx->y + offset, input, use_len);
|
||||
|
||||
if (use_len + offset == 16 || ctx->processed == ctx->plaintext_len) {
|
||||
if ((ret =
|
||||
mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ctx->state |= CCM_STATE__ERROR;
|
||||
goto exit;
|
||||
}
|
||||
@ -391,8 +438,12 @@ int mbedtls_ccm_update(mbedtls_ccm_context *ctx,
|
||||
memcpy(output, local_output, use_len);
|
||||
|
||||
if (use_len + offset == 16 || ctx->processed == ctx->plaintext_len) {
|
||||
if ((ret =
|
||||
mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->y, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->y);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
ctx->state |= CCM_STATE__ERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
@ -310,6 +310,12 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
|
||||
if (ctx->cipher_info == NULL) {
|
||||
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
|
||||
}
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) &&
|
||||
MBEDTLS_DECRYPT == operation) {
|
||||
return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
if (ctx->psa_enabled == 1) {
|
||||
@ -377,6 +383,7 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
|
||||
ctx->key_bitlen = key_bitlen;
|
||||
ctx->operation = operation;
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/*
|
||||
* For OFB, CFB and CTR mode always use the encryption key schedule
|
||||
*/
|
||||
@ -392,6 +399,12 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
|
||||
return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_dec_func(ctx->cipher_ctx, key,
|
||||
ctx->key_bitlen);
|
||||
}
|
||||
#else
|
||||
if (operation == MBEDTLS_ENCRYPT || operation == MBEDTLS_DECRYPT) {
|
||||
return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key,
|
||||
ctx->key_bitlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
|
||||
}
|
||||
|
@ -226,11 +226,13 @@ static int aes_crypt_xts_wrap(void *ctx, mbedtls_operation_t operation,
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static int aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
{
|
||||
return mbedtls_aes_setkey_dec((mbedtls_aes_context *) ctx, key, key_bitlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
@ -279,7 +281,9 @@ static const mbedtls_cipher_base_t aes_info = {
|
||||
NULL,
|
||||
#endif
|
||||
aes_setkey_enc_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
aes_setkey_dec_wrap,
|
||||
#endif
|
||||
aes_ctx_alloc,
|
||||
aes_ctx_free
|
||||
};
|
||||
@ -591,7 +595,9 @@ static const mbedtls_cipher_base_t gcm_aes_info = {
|
||||
#endif
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
gcm_aes_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
gcm_aes_setkey_wrap,
|
||||
#endif
|
||||
gcm_ctx_alloc,
|
||||
gcm_ctx_free,
|
||||
#else
|
||||
@ -673,7 +679,9 @@ static const mbedtls_cipher_base_t ccm_aes_info = {
|
||||
#endif
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
ccm_aes_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
ccm_aes_setkey_wrap,
|
||||
#endif
|
||||
ccm_ctx_alloc,
|
||||
ccm_ctx_free,
|
||||
#else
|
||||
@ -799,11 +807,13 @@ static int camellia_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static int camellia_setkey_dec_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
{
|
||||
return mbedtls_camellia_setkey_dec((mbedtls_camellia_context *) ctx, key, key_bitlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int camellia_setkey_enc_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
@ -853,7 +863,9 @@ static const mbedtls_cipher_base_t camellia_info = {
|
||||
NULL,
|
||||
#endif
|
||||
camellia_setkey_enc_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
camellia_setkey_dec_wrap,
|
||||
#endif
|
||||
camellia_ctx_alloc,
|
||||
camellia_ctx_free
|
||||
};
|
||||
@ -1026,7 +1038,9 @@ static const mbedtls_cipher_base_t gcm_camellia_info = {
|
||||
NULL,
|
||||
#endif
|
||||
gcm_camellia_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
gcm_camellia_setkey_wrap,
|
||||
#endif
|
||||
gcm_ctx_alloc,
|
||||
gcm_ctx_free,
|
||||
};
|
||||
@ -1095,7 +1109,9 @@ static const mbedtls_cipher_base_t ccm_camellia_info = {
|
||||
NULL,
|
||||
#endif
|
||||
ccm_camellia_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
ccm_camellia_setkey_wrap,
|
||||
#endif
|
||||
ccm_ctx_alloc,
|
||||
ccm_ctx_free,
|
||||
};
|
||||
@ -1209,11 +1225,13 @@ static int aria_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off,
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static int aria_setkey_dec_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
{
|
||||
return mbedtls_aria_setkey_dec((mbedtls_aria_context *) ctx, key, key_bitlen);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int aria_setkey_enc_wrap(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen)
|
||||
@ -1263,7 +1281,9 @@ static const mbedtls_cipher_base_t aria_info = {
|
||||
NULL,
|
||||
#endif
|
||||
aria_setkey_enc_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
aria_setkey_dec_wrap,
|
||||
#endif
|
||||
aria_ctx_alloc,
|
||||
aria_ctx_free
|
||||
};
|
||||
@ -1436,7 +1456,9 @@ static const mbedtls_cipher_base_t gcm_aria_info = {
|
||||
NULL,
|
||||
#endif
|
||||
gcm_aria_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
gcm_aria_setkey_wrap,
|
||||
#endif
|
||||
gcm_ctx_alloc,
|
||||
gcm_ctx_free,
|
||||
};
|
||||
@ -1505,7 +1527,9 @@ static const mbedtls_cipher_base_t ccm_aria_info = {
|
||||
NULL,
|
||||
#endif
|
||||
ccm_aria_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
ccm_aria_setkey_wrap,
|
||||
#endif
|
||||
ccm_ctx_alloc,
|
||||
ccm_ctx_free,
|
||||
};
|
||||
@ -1925,7 +1949,9 @@ static const mbedtls_cipher_base_t chacha20_base_info = {
|
||||
chacha20_stream_wrap,
|
||||
#endif
|
||||
chacha20_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
chacha20_setkey_wrap,
|
||||
#endif
|
||||
chacha20_ctx_alloc,
|
||||
chacha20_ctx_free
|
||||
};
|
||||
@ -2000,7 +2026,9 @@ static const mbedtls_cipher_base_t chachapoly_base_info = {
|
||||
NULL,
|
||||
#endif
|
||||
chachapoly_setkey_wrap,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
chachapoly_setkey_wrap,
|
||||
#endif
|
||||
chachapoly_ctx_alloc,
|
||||
chachapoly_ctx_free
|
||||
};
|
||||
@ -2068,7 +2096,9 @@ static const mbedtls_cipher_base_t null_base_info = {
|
||||
null_crypt_stream,
|
||||
#endif
|
||||
null_setkey,
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
null_setkey,
|
||||
#endif
|
||||
null_ctx_alloc,
|
||||
null_ctx_free
|
||||
};
|
||||
|
@ -125,9 +125,11 @@ struct mbedtls_cipher_base_t {
|
||||
int (*setkey_enc_func)(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen);
|
||||
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
/** Set key for decryption purposes */
|
||||
int (*setkey_dec_func)(void *ctx, const unsigned char *key,
|
||||
unsigned int key_bitlen);
|
||||
#endif
|
||||
|
||||
/** Allocate a new context */
|
||||
void * (*ctx_alloc_func)(void);
|
||||
|
@ -23,6 +23,15 @@
|
||||
#include <arm_neon.h>
|
||||
#endif /* __ARM_NEON */
|
||||
|
||||
|
||||
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \
|
||||
&& !defined(__llvm__) && !defined(__INTEL_COMPILER)
|
||||
/* Defined if the compiler really is gcc and not clang, etc */
|
||||
#define MBEDTLS_COMPILER_IS_GCC
|
||||
#define MBEDTLS_GCC_VERSION \
|
||||
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
||||
#endif
|
||||
|
||||
/** Helper to define a function as static except when building invasive tests.
|
||||
*
|
||||
* If a function is only used inside its own source file and should be
|
||||
@ -169,7 +178,9 @@ inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned
|
||||
{
|
||||
size_t i = 0;
|
||||
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
||||
#if defined(__ARM_NEON)
|
||||
#if defined(__ARM_NEON) && \
|
||||
(!defined(MBEDTLS_COMPILER_IS_GCC) || \
|
||||
(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION >= 70300))
|
||||
for (; (i + 16) <= n; i += 16) {
|
||||
uint8x16_t v1 = vld1q_u8(a + i);
|
||||
uint8x16_t v2 = vld1q_u8(b + i);
|
||||
@ -324,12 +335,6 @@ static inline void mbedtls_xor_no_simd(unsigned char *r,
|
||||
#define MBEDTLS_ASSUME(x) do { } while (0)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \
|
||||
&& !defined(__llvm__) && !defined(__INTEL_COMPILER)
|
||||
/* Defined if the compiler really is gcc and not clang, etc */
|
||||
#define MBEDTLS_COMPILER_IS_GCC
|
||||
#endif
|
||||
|
||||
/* For gcc -Os, override with -O2 for a given function.
|
||||
*
|
||||
* This will not affect behaviour for other optimisation settings, e.g. -O0.
|
||||
|
@ -31,7 +31,7 @@
|
||||
* Disable -Wredundant-decls so that gcc does not warn about this. This is re-enabled
|
||||
* at the bottom of this file.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#if defined(MBEDTLS_COMPILER_IS_GCC) && (__GNUC__ > 4)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
||||
#endif
|
||||
@ -548,7 +548,7 @@ static inline mbedtls_ct_condition_t mbedtls_ct_bool_not(mbedtls_ct_condition_t
|
||||
return (mbedtls_ct_condition_t) (~x);
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if defined(MBEDTLS_COMPILER_IS_GCC) && (__GNUC__ > 4)
|
||||
/* Restore warnings for -Wredundant-decls on gcc */
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
@ -366,7 +366,7 @@ static void debug_print_line_by_line(const mbedtls_ssl_context *ssl, int level,
|
||||
start = text;
|
||||
for (cur = text; *cur != '\0'; cur++) {
|
||||
if (*cur == '\n') {
|
||||
size_t len = cur - start + 1;
|
||||
size_t len = (size_t) (cur - start) + 1;
|
||||
if (len > DEBUG_BUF_SIZE - 1) {
|
||||
len = DEBUG_BUF_SIZE - 1;
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ static int dhm_read_bignum(mbedtls_mpi *X,
|
||||
return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
n = ((*p)[0] << 8) | (*p)[1];
|
||||
n = MBEDTLS_GET_UINT16_BE(*p, 0);
|
||||
(*p) += 2;
|
||||
|
||||
if ((int) (end - *p) < n) {
|
||||
if ((size_t) (end - *p) < (size_t) n) {
|
||||
return MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ int mbedtls_dhm_make_params(mbedtls_dhm_context *ctx, int x_size,
|
||||
DHM_MPI_EXPORT(&ctx->G, n2);
|
||||
DHM_MPI_EXPORT(&ctx->GX, n3);
|
||||
|
||||
*olen = p - output;
|
||||
*olen = (size_t) (p - output);
|
||||
|
||||
cleanup:
|
||||
if (ret != 0 && ret > -128) {
|
||||
|
@ -363,7 +363,7 @@ static int ecdh_read_params_internal(mbedtls_ecdh_context_mbed *ctx,
|
||||
const unsigned char *end)
|
||||
{
|
||||
return mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, buf,
|
||||
end - *buf);
|
||||
(size_t) (end - *buf));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -379,7 +379,7 @@ int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx,
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_ecp_group_id grp_id;
|
||||
if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, end - *buf))
|
||||
if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, (size_t) (end - *buf)))
|
||||
!= 0) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ static int ecjpake_write_len_point(unsigned char **p,
|
||||
}
|
||||
|
||||
ret = mbedtls_ecp_point_write_binary(grp, P, pf,
|
||||
&len, *p + 4, end - (*p + 4));
|
||||
&len, *p + 4, (size_t) (end - (*p + 4)));
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -226,7 +226,7 @@ static int ecjpake_hash(const mbedtls_md_type_t md_type,
|
||||
|
||||
/* Compute hash */
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecjpake_compute_hash(md_type,
|
||||
buf, p - buf, hash));
|
||||
buf, (size_t) (p - buf), hash));
|
||||
|
||||
/* Turn it into an integer mod n */
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(h, hash,
|
||||
@ -269,7 +269,7 @@ static int ecjpake_zkp_read(const mbedtls_md_type_t md_type,
|
||||
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_read_point(grp, &V, p, end - *p));
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_read_point(grp, &V, p, (size_t) (end - *p)));
|
||||
|
||||
if (end < *p || (size_t) (end - *p) < 1) {
|
||||
ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
@ -346,7 +346,7 @@ static int ecjpake_zkp_write(const mbedtls_md_type_t md_type,
|
||||
|
||||
/* Write it out */
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_write_point(grp, &V,
|
||||
pf, &len, *p, end - *p));
|
||||
pf, &len, *p, (size_t) (end - *p)));
|
||||
*p += len;
|
||||
|
||||
len = mbedtls_mpi_size(&h); /* actually r */
|
||||
@ -392,7 +392,7 @@ static int ecjpake_kkp_read(const mbedtls_md_type_t md_type,
|
||||
* ECSchnorrZKP zkp;
|
||||
* } ECJPAKEKeyKP;
|
||||
*/
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_read_point(grp, X, p, end - *p));
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_read_point(grp, X, p, (size_t) (end - *p)));
|
||||
if (mbedtls_ecp_is_zero(X)) {
|
||||
ret = MBEDTLS_ERR_ECP_INVALID_KEY;
|
||||
goto cleanup;
|
||||
@ -431,7 +431,7 @@ static int ecjpake_kkp_write(const mbedtls_md_type_t md_type,
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_gen_keypair_base((mbedtls_ecp_group *) grp, G, x, X,
|
||||
f_rng, p_rng));
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_write_point(grp, X,
|
||||
pf, &len, *p, end - *p));
|
||||
pf, &len, *p, (size_t) (end - *p)));
|
||||
*p += len;
|
||||
|
||||
/* Generate and write proof */
|
||||
@ -504,7 +504,7 @@ static int ecjpake_kkpp_write(const mbedtls_md_type_t md_type,
|
||||
MBEDTLS_MPI_CHK(ecjpake_kkp_write(md_type, grp, pf, G, xm2, Xb, id,
|
||||
&p, end, f_rng, p_rng));
|
||||
|
||||
*olen = p - buf;
|
||||
*olen = (size_t) (p - buf);
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
@ -693,7 +693,7 @@ int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx,
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_write_group(&ctx->grp, &ec_len,
|
||||
p, end - p));
|
||||
p, (size_t) (end - p)));
|
||||
p += ec_len;
|
||||
}
|
||||
|
||||
@ -702,7 +702,7 @@ int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx,
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_tls_write_point(&ctx->grp, &Xm,
|
||||
ctx->point_format, &ec_len, p, end - p));
|
||||
ctx->point_format, &ec_len, p, (size_t) (end - p)));
|
||||
p += ec_len;
|
||||
|
||||
MBEDTLS_MPI_CHK(ecjpake_zkp_write(ctx->md_type, &ctx->grp,
|
||||
@ -710,7 +710,7 @@ int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx,
|
||||
&G, &xm, &Xm, ID_MINE,
|
||||
&p, end, f_rng, p_rng));
|
||||
|
||||
*olen = p - buf;
|
||||
*olen = (size_t) (p - buf);
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecp_point_free(&G);
|
||||
|
@ -88,7 +88,7 @@ static int getrandom_wrapper(void *buf, size_t buflen, unsigned int flags)
|
||||
memset(buf, 0, buflen);
|
||||
#endif
|
||||
#endif
|
||||
return syscall(SYS_getrandom, buf, buflen, flags);
|
||||
return (int) syscall(SYS_getrandom, buf, buflen, flags);
|
||||
}
|
||||
#endif /* SYS_getrandom */
|
||||
#endif /* __linux__ || __midipix__ */
|
||||
@ -102,7 +102,7 @@ static int getrandom_wrapper(void *buf, size_t buflen, unsigned int flags)
|
||||
#define HAVE_GETRANDOM
|
||||
static int getrandom_wrapper(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
return getrandom(buf, buflen, flags);
|
||||
return (int) getrandom(buf, buflen, flags);
|
||||
}
|
||||
#endif /* (__FreeBSD__ && __FreeBSD_version >= 1200000) ||
|
||||
(__DragonFly__ && __DragonFly_version >= 500700) */
|
||||
@ -156,7 +156,7 @@ int mbedtls_platform_entropy_poll(void *data,
|
||||
#if defined(HAVE_GETRANDOM)
|
||||
ret = getrandom_wrapper(output, len, 0);
|
||||
if (ret >= 0) {
|
||||
*olen = ret;
|
||||
*olen = (size_t) ret;
|
||||
return 0;
|
||||
} else if (errno != ENOSYS) {
|
||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
|
@ -25,6 +25,10 @@
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/constant_time.h"
|
||||
|
||||
#if !defined(MBEDTLS_CIPHER_C)
|
||||
#include "block_cipher_internal.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
@ -59,10 +63,16 @@ static int gcm_gen_table(mbedtls_gcm_context *ctx)
|
||||
uint64_t hi, lo;
|
||||
uint64_t vl, vh;
|
||||
unsigned char h[16];
|
||||
size_t olen = 0;
|
||||
|
||||
memset(h, 0, 16);
|
||||
if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, h, 16, h, &olen)) != 0) {
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen = 0;
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, h, 16, h, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, h, h);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -124,12 +134,14 @@ int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx,
|
||||
unsigned int keybits)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
||||
if (keybits != 128 && keybits != 192 && keybits != 256) {
|
||||
return MBEDTLS_ERR_GCM_BAD_INPUT;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_values(cipher, keybits,
|
||||
MBEDTLS_MODE_ECB);
|
||||
if (cipher_info == NULL) {
|
||||
@ -150,6 +162,17 @@ int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx,
|
||||
MBEDTLS_ENCRYPT)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
|
||||
|
||||
if ((ret = mbedtls_block_cipher_setup(&ctx->block_cipher_ctx, cipher)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_block_cipher_setkey(&ctx->block_cipher_ctx, key, keybits)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((ret = gcm_gen_table(ctx)) != 0) {
|
||||
return ret;
|
||||
@ -252,8 +275,11 @@ int mbedtls_gcm_starts(mbedtls_gcm_context *ctx,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char work_buf[16];
|
||||
const unsigned char *p;
|
||||
size_t use_len, olen = 0;
|
||||
size_t use_len;
|
||||
uint64_t iv_bits;
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen = 0;
|
||||
#endif
|
||||
|
||||
/* IV is limited to 2^64 bits, so 2^61 bytes */
|
||||
/* IV is not allowed to be zero length */
|
||||
@ -293,8 +319,13 @@ int mbedtls_gcm_starts(mbedtls_gcm_context *ctx,
|
||||
gcm_mult(ctx, ctx->y, ctx->y);
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16,
|
||||
ctx->base_ectr, &olen)) != 0) {
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->base_ectr);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -386,11 +417,15 @@ static int gcm_mask(mbedtls_gcm_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
size_t olen = 0;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ectr,
|
||||
&olen)) != 0) {
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
size_t olen = 0;
|
||||
ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ectr, &olen);
|
||||
#else
|
||||
ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ectr);
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
mbedtls_platform_zeroize(ectr, 16);
|
||||
return ret;
|
||||
}
|
||||
@ -614,7 +649,11 @@ void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
mbedtls_cipher_free(&ctx->cipher_ctx);
|
||||
#else
|
||||
mbedtls_block_cipher_free(&ctx->block_cipher_ctx);
|
||||
#endif
|
||||
mbedtls_platform_zeroize(ctx, sizeof(mbedtls_gcm_context));
|
||||
}
|
||||
|
||||
|
@ -69,29 +69,6 @@ static const unsigned char D_MESSAGE_CONSTANT_BYTES[D_CONST_LEN] = { 0x81, 0x81
|
||||
int (*mbedtls_lmots_sign_private_key_invalidated_hook)(unsigned char *) = NULL;
|
||||
#endif /* defined(MBEDTLS_TEST_HOOKS) */
|
||||
|
||||
void mbedtls_lms_unsigned_int_to_network_bytes(unsigned int val, size_t len,
|
||||
unsigned char *bytes)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
for (idx = 0; idx < len; idx++) {
|
||||
bytes[idx] = (val >> ((len - 1 - idx) * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int mbedtls_lms_network_bytes_to_unsigned_int(size_t len,
|
||||
const unsigned char *bytes)
|
||||
{
|
||||
size_t idx;
|
||||
unsigned int val = 0;
|
||||
|
||||
for (idx = 0; idx < len; idx++) {
|
||||
val |= ((unsigned int) bytes[idx]) << (8 * (len - 1 - idx));
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Calculate the checksum digits that are appended to the end of the LMOTS digit
|
||||
* string. See NIST SP800-208 section 3.1 or RFC8554 Algorithm 2 for details of
|
||||
* the checksum algorithm.
|
||||
@ -191,8 +168,7 @@ static int create_digit_array_with_checksum(const mbedtls_lmots_parameters_t *pa
|
||||
}
|
||||
|
||||
checksum = lmots_checksum_calculate(params, out);
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(checksum, CHECKSUM_LEN,
|
||||
out + MBEDTLS_LMOTS_N_HASH_LEN(params->type));
|
||||
MBEDTLS_PUT_UINT16_BE(checksum, out, MBEDTLS_LMOTS_N_HASH_LEN(params->type));
|
||||
|
||||
exit:
|
||||
psa_hash_abort(&op);
|
||||
@ -281,17 +257,13 @@ static int hash_digit_array(const mbedtls_lmots_parameters_t *params,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(i_digit_idx,
|
||||
I_DIGIT_IDX_LEN,
|
||||
i_digit_idx_bytes);
|
||||
MBEDTLS_PUT_UINT16_BE(i_digit_idx, i_digit_idx_bytes, 0);
|
||||
status = psa_hash_update(&op, i_digit_idx_bytes, I_DIGIT_IDX_LEN);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(j_hash_idx,
|
||||
J_HASH_IDX_LEN,
|
||||
j_hash_idx_bytes);
|
||||
j_hash_idx_bytes[0] = (uint8_t) j_hash_idx;
|
||||
status = psa_hash_update(&op, j_hash_idx_bytes, J_HASH_IDX_LEN);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
@ -425,11 +397,8 @@ int mbedtls_lmots_import_public_key(mbedtls_lmots_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
ctx->params.type =
|
||||
(mbedtls_lmots_algorithm_type_t) mbedtls_lms_network_bytes_to_unsigned_int(
|
||||
MBEDTLS_LMOTS_TYPE_LEN,
|
||||
key +
|
||||
MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
ctx->params.type = (mbedtls_lmots_algorithm_type_t)
|
||||
MBEDTLS_GET_UINT32_BE(key, MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
|
||||
if (key_len != MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type)) {
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
@ -464,9 +433,7 @@ int mbedtls_lmots_export_public_key(const mbedtls_lmots_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(ctx->params.type,
|
||||
MBEDTLS_LMOTS_TYPE_LEN,
|
||||
key + MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
MBEDTLS_PUT_UINT32_BE(ctx->params.type, key, MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
|
||||
memcpy(key + PUBLIC_KEY_I_KEY_ID_OFFSET,
|
||||
ctx->params.I_key_identifier,
|
||||
@ -559,9 +526,7 @@ int mbedtls_lmots_verify(const mbedtls_lmots_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
|
||||
if (mbedtls_lms_network_bytes_to_unsigned_int(MBEDTLS_LMOTS_TYPE_LEN,
|
||||
sig + MBEDTLS_LMOTS_SIG_TYPE_OFFSET) !=
|
||||
MBEDTLS_LMOTS_SHA256_N32_W8) {
|
||||
if (MBEDTLS_GET_UINT32_BE(sig, MBEDTLS_LMOTS_SIG_TYPE_OFFSET) != MBEDTLS_LMOTS_SHA256_N32_W8) {
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
|
||||
@ -607,7 +572,7 @@ int mbedtls_lmots_generate_private_key(mbedtls_lmots_private_t *ctx,
|
||||
size_t output_hash_len;
|
||||
unsigned int i_digit_idx;
|
||||
unsigned char i_digit_idx_bytes[2];
|
||||
unsigned char const_bytes[1];
|
||||
unsigned char const_bytes[1] = { 0xFF };
|
||||
|
||||
if (ctx->have_private_key) {
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
@ -623,12 +588,7 @@ int mbedtls_lmots_generate_private_key(mbedtls_lmots_private_t *ctx,
|
||||
I_key_identifier,
|
||||
sizeof(ctx->params.I_key_identifier));
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(q_leaf_identifier,
|
||||
MBEDTLS_LMOTS_Q_LEAF_ID_LEN,
|
||||
ctx->params.q_leaf_identifier);
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(0xFF, sizeof(const_bytes),
|
||||
const_bytes);
|
||||
MBEDTLS_PUT_UINT32_BE(q_leaf_identifier, ctx->params.q_leaf_identifier, 0);
|
||||
|
||||
for (i_digit_idx = 0;
|
||||
i_digit_idx < MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type);
|
||||
@ -652,8 +612,7 @@ int mbedtls_lmots_generate_private_key(mbedtls_lmots_private_t *ctx,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(i_digit_idx, I_DIGIT_IDX_LEN,
|
||||
i_digit_idx_bytes);
|
||||
MBEDTLS_PUT_UINT16_BE(i_digit_idx, i_digit_idx_bytes, 0);
|
||||
status = psa_hash_update(&op, i_digit_idx_bytes, I_DIGIT_IDX_LEN);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
@ -774,9 +733,7 @@ int mbedtls_lmots_sign(mbedtls_lmots_private_t *ctx,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(ctx->params.type,
|
||||
MBEDTLS_LMOTS_TYPE_LEN,
|
||||
sig + MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
MBEDTLS_PUT_UINT32_BE(ctx->params.type, sig, MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
|
||||
|
||||
/* Test hook to check if sig is being written to before we invalidate the
|
||||
* private key.
|
||||
|
@ -44,29 +44,6 @@ extern "C" {
|
||||
extern int (*mbedtls_lmots_sign_private_key_invalidated_hook)(unsigned char *);
|
||||
#endif /* defined(MBEDTLS_TEST_HOOKS) */
|
||||
|
||||
/**
|
||||
* \brief This function converts an unsigned int into a
|
||||
* network-byte-order (big endian) string.
|
||||
*
|
||||
* \param val The unsigned integer value
|
||||
* \param len The length of the string.
|
||||
* \param bytes The string to output into.
|
||||
*/
|
||||
void mbedtls_lms_unsigned_int_to_network_bytes(unsigned int val, size_t len,
|
||||
unsigned char *bytes);
|
||||
|
||||
/**
|
||||
* \brief This function converts a network-byte-order
|
||||
* (big endian) string into an unsigned integer.
|
||||
*
|
||||
* \param len The length of the string.
|
||||
* \param bytes The string.
|
||||
*
|
||||
* \return The corresponding LMS error code.
|
||||
*/
|
||||
unsigned int mbedtls_lms_network_bytes_to_unsigned_int(size_t len,
|
||||
const unsigned char *bytes);
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/**
|
||||
* \brief This function converts a \ref psa_status_t to a
|
||||
|
@ -112,7 +112,7 @@ static int create_merkle_leaf_value(const mbedtls_lms_parameters_t *params,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(r_node_idx, 4, r_node_idx_bytes);
|
||||
MBEDTLS_PUT_UINT32_BE(r_node_idx, r_node_idx_bytes, 0);
|
||||
status = psa_hash_update(&op, r_node_idx_bytes, 4);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
@ -186,7 +186,7 @@ static int create_merkle_internal_value(const mbedtls_lms_parameters_t *params,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(r_node_idx, 4, r_node_idx_bytes);
|
||||
MBEDTLS_PUT_UINT32_BE(r_node_idx, r_node_idx_bytes, 0);
|
||||
status = psa_hash_update(&op, r_node_idx_bytes, 4);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
@ -237,10 +237,7 @@ int mbedtls_lms_import_public_key(mbedtls_lms_public_t *ctx,
|
||||
mbedtls_lms_algorithm_type_t type;
|
||||
mbedtls_lmots_algorithm_type_t otstype;
|
||||
|
||||
type = (mbedtls_lms_algorithm_type_t) mbedtls_lms_network_bytes_to_unsigned_int(
|
||||
MBEDTLS_LMS_TYPE_LEN,
|
||||
key +
|
||||
PUBLIC_KEY_TYPE_OFFSET);
|
||||
type = (mbedtls_lms_algorithm_type_t) MBEDTLS_GET_UINT32_BE(key, PUBLIC_KEY_TYPE_OFFSET);
|
||||
if (type != MBEDTLS_LMS_SHA256_M32_H10) {
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -250,10 +247,8 @@ int mbedtls_lms_import_public_key(mbedtls_lms_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
otstype = (mbedtls_lmots_algorithm_type_t) mbedtls_lms_network_bytes_to_unsigned_int(
|
||||
MBEDTLS_LMOTS_TYPE_LEN,
|
||||
key +
|
||||
PUBLIC_KEY_OTSTYPE_OFFSET);
|
||||
otstype = (mbedtls_lmots_algorithm_type_t)
|
||||
MBEDTLS_GET_UINT32_BE(key, PUBLIC_KEY_OTSTYPE_OFFSET);
|
||||
if (otstype != MBEDTLS_LMOTS_SHA256_N32_W8) {
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
@ -282,12 +277,8 @@ int mbedtls_lms_export_public_key(const mbedtls_lms_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(
|
||||
ctx->params.type,
|
||||
MBEDTLS_LMS_TYPE_LEN, key + PUBLIC_KEY_TYPE_OFFSET);
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(ctx->params.otstype,
|
||||
MBEDTLS_LMOTS_TYPE_LEN,
|
||||
key + PUBLIC_KEY_OTSTYPE_OFFSET);
|
||||
MBEDTLS_PUT_UINT32_BE(ctx->params.type, key, PUBLIC_KEY_TYPE_OFFSET);
|
||||
MBEDTLS_PUT_UINT32_BE(ctx->params.otstype, key, PUBLIC_KEY_OTSTYPE_OFFSET);
|
||||
memcpy(key + PUBLIC_KEY_I_KEY_ID_OFFSET,
|
||||
ctx->params.I_key_identifier,
|
||||
MBEDTLS_LMOTS_I_KEY_ID_LEN);
|
||||
@ -339,9 +330,7 @@ int mbedtls_lms_verify(const mbedtls_lms_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
|
||||
if (mbedtls_lms_network_bytes_to_unsigned_int(MBEDTLS_LMOTS_TYPE_LEN,
|
||||
sig + SIG_OTS_SIG_OFFSET +
|
||||
MBEDTLS_LMOTS_SIG_TYPE_OFFSET)
|
||||
if (MBEDTLS_GET_UINT32_BE(sig, SIG_OTS_SIG_OFFSET + MBEDTLS_LMOTS_SIG_TYPE_OFFSET)
|
||||
!= MBEDTLS_LMOTS_SHA256_N32_W8) {
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
@ -350,15 +339,13 @@ int mbedtls_lms_verify(const mbedtls_lms_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
|
||||
if (mbedtls_lms_network_bytes_to_unsigned_int(MBEDTLS_LMS_TYPE_LEN,
|
||||
sig + SIG_TYPE_OFFSET(ctx->params.otstype))
|
||||
if (MBEDTLS_GET_UINT32_BE(sig, SIG_TYPE_OFFSET(ctx->params.otstype))
|
||||
!= MBEDTLS_LMS_SHA256_M32_H10) {
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
}
|
||||
|
||||
|
||||
q_leaf_identifier = mbedtls_lms_network_bytes_to_unsigned_int(
|
||||
MBEDTLS_LMOTS_Q_LEAF_ID_LEN, sig + SIG_Q_LEAF_ID_OFFSET);
|
||||
q_leaf_identifier = MBEDTLS_GET_UINT32_BE(sig, SIG_Q_LEAF_ID_OFFSET);
|
||||
|
||||
if (q_leaf_identifier >= MERKLE_TREE_LEAF_NODE_AM(ctx->params.type)) {
|
||||
return MBEDTLS_ERR_LMS_VERIFY_FAILED;
|
||||
@ -367,9 +354,7 @@ int mbedtls_lms_verify(const mbedtls_lms_public_t *ctx,
|
||||
memcpy(ots_params.I_key_identifier,
|
||||
ctx->params.I_key_identifier,
|
||||
MBEDTLS_LMOTS_I_KEY_ID_LEN);
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(q_leaf_identifier,
|
||||
MBEDTLS_LMOTS_Q_LEAF_ID_LEN,
|
||||
ots_params.q_leaf_identifier);
|
||||
MBEDTLS_PUT_UINT32_BE(q_leaf_identifier, ots_params.q_leaf_identifier, 0);
|
||||
ots_params.type = ctx->params.otstype;
|
||||
|
||||
ret = mbedtls_lmots_calculate_public_key_candidate(&ots_params,
|
||||
@ -505,7 +490,7 @@ static int get_merkle_path(mbedtls_lms_private_t *ctx,
|
||||
unsigned int height;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
tree = mbedtls_calloc(MERKLE_TREE_NODE_AM(ctx->params.type),
|
||||
tree = mbedtls_calloc((size_t) MERKLE_TREE_NODE_AM(ctx->params.type),
|
||||
node_bytes);
|
||||
if (tree == NULL) {
|
||||
return MBEDTLS_ERR_LMS_ALLOC_FAILED;
|
||||
@ -530,7 +515,7 @@ static int get_merkle_path(mbedtls_lms_private_t *ctx,
|
||||
|
||||
exit:
|
||||
mbedtls_zeroize_and_free(tree, node_bytes *
|
||||
MERKLE_TREE_NODE_AM(ctx->params.type));
|
||||
(size_t) MERKLE_TREE_NODE_AM(ctx->params.type));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -669,7 +654,7 @@ int mbedtls_lms_calculate_public_key(mbedtls_lms_public_t *ctx,
|
||||
return MBEDTLS_ERR_LMS_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
tree = mbedtls_calloc(MERKLE_TREE_NODE_AM(priv_ctx->params.type),
|
||||
tree = mbedtls_calloc((size_t) MERKLE_TREE_NODE_AM(priv_ctx->params.type),
|
||||
node_bytes);
|
||||
if (tree == NULL) {
|
||||
return MBEDTLS_ERR_LMS_ALLOC_FAILED;
|
||||
@ -692,7 +677,7 @@ int mbedtls_lms_calculate_public_key(mbedtls_lms_public_t *ctx,
|
||||
|
||||
exit:
|
||||
mbedtls_zeroize_and_free(tree, node_bytes *
|
||||
MERKLE_TREE_NODE_AM(priv_ctx->params.type));
|
||||
(size_t) MERKLE_TREE_NODE_AM(priv_ctx->params.type));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -753,12 +738,8 @@ int mbedtls_lms_sign(mbedtls_lms_private_t *ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(ctx->params.type,
|
||||
MBEDTLS_LMS_TYPE_LEN,
|
||||
sig + SIG_TYPE_OFFSET(ctx->params.otstype));
|
||||
mbedtls_lms_unsigned_int_to_network_bytes(q_leaf_identifier,
|
||||
MBEDTLS_LMOTS_Q_LEAF_ID_LEN,
|
||||
sig + SIG_Q_LEAF_ID_OFFSET);
|
||||
MBEDTLS_PUT_UINT32_BE(ctx->params.type, sig, SIG_TYPE_OFFSET(ctx->params.otstype));
|
||||
MBEDTLS_PUT_UINT32_BE(q_leaf_identifier, sig, SIG_Q_LEAF_ID_OFFSET);
|
||||
|
||||
ret = get_merkle_path(ctx,
|
||||
MERKLE_TREE_INTERNAL_NODE_AM(ctx->params.type) + q_leaf_identifier,
|
||||
|
@ -1129,7 +1129,7 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid,
|
||||
}
|
||||
}
|
||||
|
||||
encoded_len = out_ptr - oid->p;
|
||||
encoded_len = (size_t) (out_ptr - oid->p);
|
||||
resized_mem = mbedtls_calloc(encoded_len, 1);
|
||||
if (resized_mem == NULL) {
|
||||
ret = MBEDTLS_ERR_ASN1_ALLOC_FAILED;
|
||||
|
@ -96,6 +96,7 @@ int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/*
|
||||
* PadLock AES-CBC buffer en(de)cryption
|
||||
*/
|
||||
@ -149,6 +150,7 @@ int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#endif /* MBEDTLS_VIA_PADLOCK_HAVE_CODE */
|
||||
|
||||
|
@ -298,7 +298,7 @@ int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const
|
||||
if (*end == '\n') {
|
||||
end++;
|
||||
}
|
||||
*use_len = end - data;
|
||||
*use_len = (size_t) (end - data);
|
||||
|
||||
enc = 0;
|
||||
|
||||
@ -383,7 +383,7 @@ int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const
|
||||
return MBEDTLS_ERR_PEM_INVALID_DATA;
|
||||
}
|
||||
|
||||
ret = mbedtls_base64_decode(NULL, 0, &len, s1, s2 - s1);
|
||||
ret = mbedtls_base64_decode(NULL, 0, &len, s1, (size_t) (s2 - s1));
|
||||
|
||||
if (ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) {
|
||||
return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
|
||||
@ -393,7 +393,7 @@ int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const
|
||||
return MBEDTLS_ERR_PEM_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_base64_decode(buf, len, &len, s1, s2 - s1)) != 0) {
|
||||
if ((ret = mbedtls_base64_decode(buf, len, &len, s1, (size_t) (s2 - s1))) != 0) {
|
||||
mbedtls_zeroize_and_free(buf, len);
|
||||
return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret);
|
||||
}
|
||||
@ -508,7 +508,7 @@ int mbedtls_pem_write_buffer(const char *header, const char *footer,
|
||||
p += strlen(footer);
|
||||
|
||||
*p++ = '\0';
|
||||
*olen = p - buf;
|
||||
*olen = (size_t) (p - buf);
|
||||
|
||||
/* Clean any remaining data previously written to the buffer */
|
||||
memset(buf + *olen, 0, buf_len - *olen);
|
||||
|
@ -316,7 +316,7 @@ static int pkcs7_get_signer_info(unsigned char **p, unsigned char *end,
|
||||
goto out;
|
||||
}
|
||||
|
||||
signer->issuer_raw.len = *p - signer->issuer_raw.p;
|
||||
signer->issuer_raw.len = (size_t) (*p - signer->issuer_raw.p);
|
||||
|
||||
ret = mbedtls_x509_get_serial(p, end_issuer_and_sn, &signer->serial);
|
||||
if (ret != 0) {
|
||||
|
@ -928,7 +928,7 @@ int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
|
||||
ret = pk_use_ecparams(&alg_params, pk);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = pk_ecc_set_pubkey(pk, *p, end - *p);
|
||||
ret = pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p));
|
||||
*p += end - *p;
|
||||
}
|
||||
} else
|
||||
@ -1233,7 +1233,7 @@ static int pk_parse_key_sec1_der(mbedtls_pk_context *pk,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH);
|
||||
}
|
||||
|
||||
if ((ret = pk_ecc_set_pubkey(pk, p, end2 - p)) == 0) {
|
||||
if ((ret = pk_ecc_set_pubkey(pk, p, (size_t) (end2 - p))) == 0) {
|
||||
pubkey_done = 1;
|
||||
} else {
|
||||
/*
|
||||
|
@ -1849,6 +1849,8 @@ static psa_status_t psa_start_key_creation(
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
|
||||
slot->status = PSA_SLOT_OCCUPIED;
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
@ -6625,7 +6627,7 @@ static psa_status_t psa_tls12_prf_psk_to_ms_set_key(
|
||||
memcpy(cur, data, data_length);
|
||||
cur += data_length;
|
||||
|
||||
status = psa_tls12_prf_set_key(prf, pms, cur - pms);
|
||||
status = psa_tls12_prf_set_key(prf, pms, (size_t) (cur - pms));
|
||||
|
||||
mbedtls_zeroize_and_free(pms, pms_len);
|
||||
return status;
|
||||
|
@ -33,12 +33,19 @@
|
||||
*/
|
||||
int psa_can_do_hash(psa_algorithm_t hash_alg);
|
||||
|
||||
typedef enum {
|
||||
PSA_SLOT_EMPTY = 0,
|
||||
PSA_SLOT_OCCUPIED,
|
||||
} psa_key_slot_status_t;
|
||||
|
||||
/** The data structure representing a key slot, containing key material
|
||||
* and metadata for one key.
|
||||
*/
|
||||
typedef struct {
|
||||
psa_core_key_attributes_t attr;
|
||||
|
||||
psa_key_slot_status_t status;
|
||||
|
||||
/*
|
||||
* Number of locks on the key slot held by the library.
|
||||
*
|
||||
@ -88,7 +95,7 @@ typedef struct {
|
||||
*/
|
||||
static inline int psa_is_key_slot_occupied(const psa_key_slot_t *slot)
|
||||
{
|
||||
return slot->attr.type != 0;
|
||||
return slot->status == PSA_SLOT_OCCUPIED;
|
||||
}
|
||||
|
||||
/** Test whether a key slot is locked.
|
||||
|
@ -237,11 +237,20 @@ static psa_status_t psa_load_persistent_key_into_slot(psa_key_slot_t *slot)
|
||||
data = (psa_se_key_data_storage_t *) key_data;
|
||||
status = psa_copy_key_material_into_slot(
|
||||
slot, data->slot_number, sizeof(data->slot_number));
|
||||
|
||||
if (status == PSA_SUCCESS) {
|
||||
slot->status = PSA_SLOT_OCCUPIED;
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
|
||||
status = psa_copy_key_material_into_slot(slot, key_data, key_data_length);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
slot->status = PSA_SLOT_OCCUPIED;
|
||||
|
||||
exit:
|
||||
psa_free_persistent_key_data(key_data, key_data_length);
|
||||
@ -315,6 +324,7 @@ static psa_status_t psa_load_builtin_key_into_slot(psa_key_slot_t *slot)
|
||||
/* Copy actual key length and core attributes into the slot on success */
|
||||
slot->key.bytes = key_buffer_length;
|
||||
slot->attr = attributes.core;
|
||||
slot->status = PSA_SLOT_OCCUPIED;
|
||||
|
||||
exit:
|
||||
if (status != PSA_SUCCESS) {
|
||||
|
@ -98,14 +98,9 @@ static psa_status_t psa_its_read_file(psa_storage_uid_t uid,
|
||||
return PSA_ERROR_DATA_CORRUPT;
|
||||
}
|
||||
|
||||
p_info->size = (header.size[0] |
|
||||
header.size[1] << 8 |
|
||||
header.size[2] << 16 |
|
||||
header.size[3] << 24);
|
||||
p_info->flags = (header.flags[0] |
|
||||
header.flags[1] << 8 |
|
||||
header.flags[2] << 16 |
|
||||
header.flags[3] << 24);
|
||||
p_info->size = MBEDTLS_GET_UINT32_LE(header.size, 0);
|
||||
p_info->flags = MBEDTLS_GET_UINT32_LE(header.flags, 0);
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1620,12 +1620,12 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ilen - (p - buf) > output_max_len) {
|
||||
if (ilen - ((size_t) (p - buf)) > output_max_len) {
|
||||
ret = MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*olen = ilen - (p - buf);
|
||||
*olen = ilen - ((size_t) (p - buf));
|
||||
if (*olen != 0) {
|
||||
memcpy(output, p, *olen);
|
||||
}
|
||||
@ -2191,7 +2191,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
|
||||
return MBEDTLS_ERR_RSA_INVALID_PADDING;
|
||||
}
|
||||
|
||||
observed_salt_len = hash_start - p;
|
||||
observed_salt_len = (size_t) (hash_start - p);
|
||||
|
||||
if (expected_salt_len != MBEDTLS_RSA_SALT_LEN_ANY &&
|
||||
observed_salt_len != (size_t) expected_salt_len) {
|
||||
|
@ -155,7 +155,7 @@ static int ssl_write_alpn_ext(mbedtls_ssl_context *ssl,
|
||||
p += protocol_name_len;
|
||||
}
|
||||
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
|
||||
/* List length = *out_len - 2 (ext_type) - 2 (ext_len) - 2 (list_len) */
|
||||
MBEDTLS_PUT_UINT16_BE(*out_len - 6, buf, 4);
|
||||
@ -285,7 +285,7 @@ static int ssl_write_supported_groups_ext(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
/* Length of named_group_list */
|
||||
named_group_list_len = p - named_group_list;
|
||||
named_group_list_len = (size_t) (p - named_group_list);
|
||||
if (named_group_list_len == 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("No group available."));
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
@ -301,7 +301,7 @@ static int ssl_write_supported_groups_ext(mbedtls_ssl_context *ssl,
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "Supported groups extension",
|
||||
buf + 4, named_group_list_len + 2);
|
||||
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
mbedtls_ssl_tls13_set_hs_sent_ext_mask(
|
||||
@ -391,14 +391,14 @@ static int ssl_write_client_hello_cipher_suites(
|
||||
}
|
||||
|
||||
/* Write the cipher_suites length in number of bytes */
|
||||
cipher_suites_len = p - cipher_suites;
|
||||
cipher_suites_len = (size_t) (p - cipher_suites);
|
||||
MBEDTLS_PUT_UINT16_BE(cipher_suites_len, buf, 0);
|
||||
MBEDTLS_SSL_DEBUG_MSG(3,
|
||||
("client hello, got %" MBEDTLS_PRINTF_SIZET " cipher suites",
|
||||
cipher_suites_len/2));
|
||||
|
||||
/* Output the total length of cipher_suites field. */
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -679,7 +679,7 @@ static int ssl_write_client_hello_body(mbedtls_ssl_context *ssl,
|
||||
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED */
|
||||
|
||||
/* Write the length of the list of extensions. */
|
||||
extensions_len = p - p_extensions_len - 2;
|
||||
extensions_len = (size_t) (p - p_extensions_len) - 2;
|
||||
|
||||
if (extensions_len == 0) {
|
||||
p = p_extensions_len;
|
||||
@ -691,12 +691,7 @@ static int ssl_write_client_hello_body(mbedtls_ssl_context *ssl,
|
||||
p_extensions_len, extensions_len);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
MBEDTLS_SSL_PRINT_EXTS(
|
||||
3, MBEDTLS_SSL_HS_CLIENT_HELLO, handshake->sent_extensions);
|
||||
#endif
|
||||
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -756,10 +751,9 @@ static int ssl_prepare_client_hello(mbedtls_ssl_context *ssl)
|
||||
if (ssl->handshake->resume != 0 &&
|
||||
session_negotiate->tls_version == MBEDTLS_SSL_VERSION_TLS1_3 &&
|
||||
session_negotiate->ticket != NULL) {
|
||||
mbedtls_time_t now = mbedtls_time(NULL);
|
||||
uint64_t age = (uint64_t) (now - session_negotiate->ticket_received);
|
||||
if (session_negotiate->ticket_received > now ||
|
||||
age > session_negotiate->ticket_lifetime) {
|
||||
mbedtls_ms_time_t now = mbedtls_ms_time();
|
||||
mbedtls_ms_time_t age = now - session_negotiate->ticket_reception_time;
|
||||
if (age < 0 || age > session_negotiate->ticket_lifetime * 1000) {
|
||||
/* Without valid ticket, disable session resumption.*/
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
3, ("Ticket expired, disable session resumption"));
|
||||
@ -1007,6 +1001,11 @@ int mbedtls_ssl_write_client_hello(mbedtls_ssl_context *ssl)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
MBEDTLS_SSL_PRINT_EXTS(
|
||||
3, MBEDTLS_SSL_HS_CLIENT_HELLO, ssl->handshake->sent_extensions);
|
||||
#endif
|
||||
|
||||
cleanup:
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("<= write client hello"));
|
||||
|
@ -255,8 +255,7 @@ uint32_t mbedtls_ssl_get_extension_mask(unsigned int extension_type);
|
||||
#if defined(MBEDTLS_SSL_HAVE_CBC) && \
|
||||
(defined(MBEDTLS_SSL_HAVE_AES) || \
|
||||
defined(MBEDTLS_SSL_HAVE_CAMELLIA) || \
|
||||
defined(MBEDTLS_SSL_HAVE_ARIA) || \
|
||||
defined(MBEDTLS_DES_C))
|
||||
defined(MBEDTLS_SSL_HAVE_ARIA))
|
||||
#define MBEDTLS_SSL_SOME_SUITES_USE_CBC
|
||||
#endif
|
||||
|
||||
@ -1410,7 +1409,7 @@ int mbedtls_ssl_fetch_input(mbedtls_ssl_context *ssl, size_t nb_want);
|
||||
* Write handshake message header
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned hs_type,
|
||||
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned char hs_type,
|
||||
unsigned char **buf, size_t *buf_len);
|
||||
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
@ -2766,6 +2765,9 @@ int mbedtls_ssl_session_set_hostname(mbedtls_ssl_session *session,
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
|
||||
#define MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME (604800)
|
||||
|
||||
static inline unsigned int mbedtls_ssl_session_get_ticket_flags(
|
||||
mbedtls_ssl_session *session, unsigned int flags)
|
||||
{
|
||||
|
@ -848,7 +848,7 @@ static void ssl_extract_add_data_from_record(unsigned char *add_data,
|
||||
cur += 2;
|
||||
}
|
||||
|
||||
*add_data_len = cur - add_data;
|
||||
*add_data_len = (size_t) (cur - add_data);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_HAVE_AEAD)
|
||||
@ -1212,7 +1212,7 @@ hmac_failed_etm_disabled:
|
||||
iv, transform->ivlen,
|
||||
add_data, add_data_len,
|
||||
data, rec->data_len, /* src */
|
||||
data, rec->buf_len - (data - rec->buf), /* dst */
|
||||
data, rec->buf_len - (size_t) (data - rec->buf), /* dst */
|
||||
&rec->data_len,
|
||||
transform->taglen)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_auth_encrypt_ext", ret);
|
||||
@ -1635,12 +1635,13 @@ int mbedtls_ssl_decrypt_buf(mbedtls_ssl_context const *ssl,
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if ((ret = mbedtls_cipher_auth_decrypt_ext(&transform->cipher_ctx_dec,
|
||||
iv, transform->ivlen,
|
||||
add_data, add_data_len,
|
||||
data, rec->data_len + transform->taglen, /* src */
|
||||
data, rec->buf_len - (data - rec->buf), &olen, /* dst */
|
||||
transform->taglen)) != 0) {
|
||||
if ((ret = mbedtls_cipher_auth_decrypt_ext
|
||||
(&transform->cipher_ctx_dec,
|
||||
iv, transform->ivlen,
|
||||
add_data, add_data_len,
|
||||
data, rec->data_len + transform->taglen, /* src */
|
||||
data, rec->buf_len - (size_t) (data - rec->buf), &olen, /* dst */
|
||||
transform->taglen)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_auth_decrypt_ext", ret);
|
||||
|
||||
if (ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED) {
|
||||
@ -2228,7 +2229,7 @@ int mbedtls_ssl_fetch_input(mbedtls_ssl_context *ssl, size_t nb_want)
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("timer has expired"));
|
||||
ret = MBEDTLS_ERR_SSL_TIMEOUT;
|
||||
} else {
|
||||
len = in_buf_len - (ssl->in_hdr - ssl->in_buf);
|
||||
len = in_buf_len - (size_t) (ssl->in_hdr - ssl->in_buf);
|
||||
|
||||
if (mbedtls_ssl_is_handshake_over(ssl) == 0) {
|
||||
timeout = ssl->handshake->retransmit_timeout;
|
||||
@ -2592,7 +2593,7 @@ int mbedtls_ssl_flight_transmit(mbedtls_ssl_context *ssl)
|
||||
} else {
|
||||
const unsigned char * const p = ssl->handshake->cur_msg_p;
|
||||
const size_t hs_len = cur->len - 12;
|
||||
const size_t frag_off = p - (cur->p + 12);
|
||||
const size_t frag_off = (size_t) (p - (cur->p + 12));
|
||||
const size_t rem_len = hs_len - frag_off;
|
||||
size_t cur_hs_frag_len, max_hs_frag_len;
|
||||
|
||||
@ -2730,7 +2731,7 @@ void mbedtls_ssl_send_flight_completed(mbedtls_ssl_context *ssl)
|
||||
/*
|
||||
* Handshake layer functions
|
||||
*/
|
||||
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned hs_type,
|
||||
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned char hs_type,
|
||||
unsigned char **buf, size_t *buf_len)
|
||||
{
|
||||
/*
|
||||
@ -2969,9 +2970,9 @@ int mbedtls_ssl_write_record(mbedtls_ssl_context *ssl, int force_flush)
|
||||
mbedtls_record rec;
|
||||
|
||||
rec.buf = ssl->out_iv;
|
||||
rec.buf_len = out_buf_len - (ssl->out_iv - ssl->out_buf);
|
||||
rec.buf_len = out_buf_len - (size_t) (ssl->out_iv - ssl->out_buf);
|
||||
rec.data_len = ssl->out_msglen;
|
||||
rec.data_offset = ssl->out_msg - rec.buf;
|
||||
rec.data_offset = (size_t) (ssl->out_msg - rec.buf);
|
||||
|
||||
memcpy(&rec.ctr[0], ssl->out_ctr, sizeof(rec.ctr));
|
||||
mbedtls_ssl_write_version(rec.ver, ssl->conf->transport, tls_ver);
|
||||
@ -3096,16 +3097,12 @@ static int ssl_hs_is_proper_fragment(mbedtls_ssl_context *ssl)
|
||||
|
||||
static uint32_t ssl_get_hs_frag_len(mbedtls_ssl_context const *ssl)
|
||||
{
|
||||
return (ssl->in_msg[9] << 16) |
|
||||
(ssl->in_msg[10] << 8) |
|
||||
ssl->in_msg[11];
|
||||
return MBEDTLS_GET_UINT24_BE(ssl->in_msg, 9);
|
||||
}
|
||||
|
||||
static uint32_t ssl_get_hs_frag_off(mbedtls_ssl_context const *ssl)
|
||||
{
|
||||
return (ssl->in_msg[6] << 16) |
|
||||
(ssl->in_msg[7] << 8) |
|
||||
ssl->in_msg[8];
|
||||
return MBEDTLS_GET_UINT24_BE(ssl->in_msg, 6);
|
||||
}
|
||||
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
@ -3218,9 +3215,7 @@ static size_t ssl_get_reassembly_buffer_size(size_t msg_len,
|
||||
|
||||
static uint32_t ssl_get_hs_total_len(mbedtls_ssl_context const *ssl)
|
||||
{
|
||||
return (ssl->in_msg[1] << 16) |
|
||||
(ssl->in_msg[2] << 8) |
|
||||
ssl->in_msg[3];
|
||||
return MBEDTLS_GET_UINT24_BE(ssl->in_msg, 1);
|
||||
}
|
||||
|
||||
int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context *ssl)
|
||||
@ -3241,7 +3236,7 @@ int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context *ssl)
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned int recv_msg_seq = (ssl->in_msg[4] << 8) | ssl->in_msg[5];
|
||||
unsigned int recv_msg_seq = MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4);
|
||||
|
||||
if (ssl_check_hs_header(ssl) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("invalid handshake header"));
|
||||
@ -3594,7 +3589,7 @@ int mbedtls_ssl_check_dtls_clihlo_cookie(
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
*olen = p - obuf;
|
||||
*olen = (size_t) (p - obuf);
|
||||
|
||||
/* Go back and fill length fields */
|
||||
obuf[27] = (unsigned char) (*olen - 28);
|
||||
@ -3856,8 +3851,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context const *ssl,
|
||||
*/
|
||||
|
||||
rec->data_offset = rec_hdr_len_offset + rec_hdr_len_len;
|
||||
rec->data_len = ((size_t) buf[rec_hdr_len_offset + 0] << 8) |
|
||||
((size_t) buf[rec_hdr_len_offset + 1] << 0);
|
||||
rec->data_len = MBEDTLS_GET_UINT16_BE(buf, rec_hdr_len_offset);
|
||||
MBEDTLS_SSL_DEBUG_BUF(4, "input record header", buf, rec->data_offset);
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("input record: msgtype = %u, "
|
||||
@ -3885,7 +3879,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context const *ssl,
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
||||
rec_epoch = (rec->ctr[0] << 8) | rec->ctr[1];
|
||||
rec_epoch = MBEDTLS_GET_UINT16_BE(rec->ctr, 0);
|
||||
|
||||
/* Check that the datagram is large enough to contain a record
|
||||
* of the advertised length. */
|
||||
@ -3935,7 +3929,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context const *ssl,
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
static int ssl_check_client_reconnect(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
unsigned int rec_epoch = (ssl->in_ctr[0] << 8) | ssl->in_ctr[1];
|
||||
unsigned int rec_epoch = MBEDTLS_GET_UINT16_BE(ssl->in_ctr, 0);
|
||||
|
||||
/*
|
||||
* Check for an epoch 0 ClientHello. We can't use in_msg here to
|
||||
@ -4257,9 +4251,7 @@ static int ssl_load_buffered_message(mbedtls_ssl_context *ssl)
|
||||
hs_buf = &hs->buffering.hs[0];
|
||||
if ((hs_buf->is_valid == 1) && (hs_buf->is_complete == 1)) {
|
||||
/* Synthesize a record containing the buffered HS message. */
|
||||
size_t msg_len = (hs_buf->data[1] << 16) |
|
||||
(hs_buf->data[2] << 8) |
|
||||
hs_buf->data[3];
|
||||
size_t msg_len = MBEDTLS_GET_UINT24_BE(hs_buf->data, 1);
|
||||
|
||||
/* Double-check that we haven't accidentally buffered
|
||||
* a message that doesn't fit into the input buffer. */
|
||||
@ -4356,7 +4348,7 @@ static int ssl_buffer_message(mbedtls_ssl_context *ssl)
|
||||
case MBEDTLS_SSL_MSG_HANDSHAKE:
|
||||
{
|
||||
unsigned recv_msg_seq_offset;
|
||||
unsigned recv_msg_seq = (ssl->in_msg[4] << 8) | ssl->in_msg[5];
|
||||
unsigned recv_msg_seq = MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4);
|
||||
mbedtls_ssl_hs_buffer *hs_buf;
|
||||
size_t msg_len = ssl->in_hslen - 12;
|
||||
|
||||
|
@ -341,7 +341,7 @@ int mbedtls_ssl_ticket_write(void *p_ticket,
|
||||
|
||||
/* Dump session state */
|
||||
if ((ret = mbedtls_ssl_session_save(session,
|
||||
state, end - state,
|
||||
state, (size_t) (end - state),
|
||||
&clear_len)) != 0 ||
|
||||
(unsigned long) clear_len > 65535) {
|
||||
goto cleanup;
|
||||
@ -364,7 +364,7 @@ int mbedtls_ssl_ticket_write(void *p_ticket,
|
||||
/* Additional data: key name, IV and length */
|
||||
key_name, TICKET_ADD_DATA_LEN,
|
||||
state, clear_len,
|
||||
state, end - state, &ciph_len,
|
||||
state, (size_t) (end - state), &ciph_len,
|
||||
TICKET_AUTH_TAG_BYTES)) != 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@ -444,7 +444,7 @@ int mbedtls_ssl_ticket_parse(void *p_ticket,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
enc_len = (enc_len_p[0] << 8) | enc_len_p[1];
|
||||
enc_len = MBEDTLS_GET_UINT16_BE(enc_len_p, 0);
|
||||
|
||||
if (len != TICKET_MIN_LEN + enc_len) {
|
||||
ret = MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
@ -495,7 +495,31 @@ int mbedtls_ssl_ticket_parse(void *p_ticket,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
{
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
if (session->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
|
||||
/* Check for expiration */
|
||||
mbedtls_ms_time_t ticket_age = -1;
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
if (session->endpoint == MBEDTLS_SSL_IS_SERVER) {
|
||||
ticket_age = mbedtls_ms_time() - session->ticket_creation_time;
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
if (session->endpoint == MBEDTLS_SSL_IS_CLIENT) {
|
||||
ticket_age = mbedtls_ms_time() - session->ticket_reception_time;
|
||||
}
|
||||
#endif
|
||||
|
||||
mbedtls_ms_time_t ticket_lifetime = ctx->ticket_lifetime * 1000;
|
||||
|
||||
if (ticket_age < 0 || ticket_age > ticket_lifetime) {
|
||||
ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if (session->tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
|
||||
/* Check for expiration */
|
||||
mbedtls_time_t current_time = mbedtls_time(NULL);
|
||||
|
||||
@ -505,7 +529,8 @@ int mbedtls_ssl_ticket_parse(void *p_ticket,
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
#endif /* MBEDTLS_HAVE_TIME */
|
||||
|
||||
cleanup:
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
|
@ -2443,7 +2443,7 @@ mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
|
||||
*
|
||||
* struct {
|
||||
* opaque hostname<0..2^16-1>;
|
||||
* uint64 ticket_received;
|
||||
* uint64 ticket_reception_time;
|
||||
* uint32 ticket_lifetime;
|
||||
* opaque ticket<1..2^16-1>;
|
||||
* } ClientOnlyData;
|
||||
@ -2457,7 +2457,7 @@ mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
|
||||
* uint32 max_early_data_size;
|
||||
* select ( endpoint ) {
|
||||
* case client: ClientOnlyData;
|
||||
* case server: uint64 start_time;
|
||||
* case server: uint64 ticket_creation_time;
|
||||
* };
|
||||
* } serialized_session_tls13;
|
||||
*
|
||||
@ -2492,7 +2492,7 @@ static int ssl_tls13_session_save(const mbedtls_ssl_session *session,
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
needed += 8; /* start_time or ticket_received */
|
||||
needed += 8; /* ticket_creation_time or ticket_reception_time */
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
@ -2537,7 +2537,7 @@ static int ssl_tls13_session_save(const mbedtls_ssl_session *session,
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_SRV_C)
|
||||
if (session->endpoint == MBEDTLS_SSL_IS_SERVER) {
|
||||
MBEDTLS_PUT_UINT64_BE((uint64_t) session->start, p, 0);
|
||||
MBEDTLS_PUT_UINT64_BE((uint64_t) session->ticket_creation_time, p, 0);
|
||||
p += 8;
|
||||
}
|
||||
#endif /* MBEDTLS_HAVE_TIME */
|
||||
@ -2555,7 +2555,7 @@ static int ssl_tls13_session_save(const mbedtls_ssl_session *session,
|
||||
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
MBEDTLS_PUT_UINT64_BE((uint64_t) session->ticket_received, p, 0);
|
||||
MBEDTLS_PUT_UINT64_BE((uint64_t) session->ticket_reception_time, p, 0);
|
||||
p += 8;
|
||||
#endif
|
||||
MBEDTLS_PUT_UINT32_BE(session->ticket_lifetime, p, 0);
|
||||
@ -2616,7 +2616,7 @@ static int ssl_tls13_session_load(mbedtls_ssl_session *session,
|
||||
if (end - p < 8) {
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
session->start = MBEDTLS_GET_UINT64_BE(p, 0);
|
||||
session->ticket_creation_time = MBEDTLS_GET_UINT64_BE(p, 0);
|
||||
p += 8;
|
||||
}
|
||||
#endif /* MBEDTLS_HAVE_TIME */
|
||||
@ -2651,7 +2651,7 @@ static int ssl_tls13_session_load(mbedtls_ssl_session *session,
|
||||
if (end - p < 8) {
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
session->ticket_received = MBEDTLS_GET_UINT64_BE(p, 0);
|
||||
session->ticket_reception_time = MBEDTLS_GET_UINT64_BE(p, 0);
|
||||
p += 8;
|
||||
#endif
|
||||
if (end - p < 4) {
|
||||
@ -2715,132 +2715,185 @@ psa_status_t mbedtls_ssl_cipher_to_psa(mbedtls_cipher_type_t mbedtls_cipher_type
|
||||
psa_key_type_t *key_type,
|
||||
size_t *key_size)
|
||||
{
|
||||
#if !defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
(void) taglen;
|
||||
#endif
|
||||
switch (mbedtls_cipher_type) {
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_AES_128_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_AES_128_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_AES_128_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_AES_192_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_AES_192_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_AES_256_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_AES_256_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_AES_256_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_AES;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_ARIA_128_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_ARIA_128_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_ARIA_128_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_ARIA_192_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_ARIA_192_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_ARIA_256_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_ARIA_256_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_ARIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_ARIA_256_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_ARIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_128_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_128_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_128_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 128;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_192_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_192_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 192;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_CBC)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_256_CBC:
|
||||
*alg = PSA_ALG_CBC_NO_PADDING;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_CCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_256_CCM:
|
||||
*alg = taglen ? PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen) : PSA_ALG_CCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CAMELLIA) && defined(MBEDTLS_SSL_HAVE_GCM)
|
||||
case MBEDTLS_CIPHER_CAMELLIA_256_GCM:
|
||||
*alg = PSA_ALG_GCM;
|
||||
*key_type = PSA_KEY_TYPE_CAMELLIA;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_HAVE_CHACHAPOLY)
|
||||
case MBEDTLS_CIPHER_CHACHA20_POLY1305:
|
||||
*alg = PSA_ALG_CHACHA20_POLY1305;
|
||||
*key_type = PSA_KEY_TYPE_CHACHA20;
|
||||
*key_size = 256;
|
||||
break;
|
||||
#endif
|
||||
case MBEDTLS_CIPHER_NULL:
|
||||
*alg = MBEDTLS_SSL_NULL_CIPHER;
|
||||
*key_type = 0;
|
||||
@ -3755,7 +3808,7 @@ static int ssl_session_load(mbedtls_ssl_session *session,
|
||||
session->tls_version = (mbedtls_ssl_protocol_version) (0x0300 | *p++);
|
||||
|
||||
/* Dispatch according to TLS version. */
|
||||
remaining_len = (end - p);
|
||||
remaining_len = (size_t) (end - p);
|
||||
switch (session->tls_version) {
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
case MBEDTLS_SSL_VERSION_TLS1_2:
|
||||
@ -4466,7 +4519,7 @@ int mbedtls_ssl_context_save(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
used += 2 + ssl->transform->in_cid_len + ssl->transform->out_cid_len;
|
||||
used += 2U + ssl->transform->in_cid_len + ssl->transform->out_cid_len;
|
||||
if (used <= buf_len) {
|
||||
*p++ = ssl->transform->in_cid_len;
|
||||
memcpy(p, ssl->transform->in_cid, ssl->transform->in_cid_len);
|
||||
@ -4747,7 +4800,7 @@ static int ssl_context_load(mbedtls_ssl_context *ssl,
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
ssl->mtu = (p[0] << 8) | p[1];
|
||||
ssl->mtu = MBEDTLS_GET_UINT16_BE(p, 0);
|
||||
p += 2;
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
@ -5692,7 +5745,7 @@ int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt *cert,
|
||||
uint32_t *flags)
|
||||
{
|
||||
int ret = 0;
|
||||
int usage = 0;
|
||||
unsigned int usage = 0;
|
||||
const char *ext_oid;
|
||||
size_t ext_len;
|
||||
|
||||
@ -6795,7 +6848,7 @@ int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context *ssl, mbedtls_key_excha
|
||||
|
||||
/* Write length only when we know the actual value */
|
||||
if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx,
|
||||
p + 2, end - (p + 2), &len,
|
||||
p + 2, (size_t) (end - (p + 2)), &len,
|
||||
ssl->conf->f_rng, ssl->conf->p_rng)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_calc_secret", ret);
|
||||
return ret;
|
||||
@ -6812,7 +6865,7 @@ int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context *ssl, mbedtls_key_excha
|
||||
size_t zlen;
|
||||
|
||||
if ((ret = mbedtls_ecdh_calc_secret(&ssl->handshake->ecdh_ctx, &zlen,
|
||||
p + 2, end - (p + 2),
|
||||
p + 2, (size_t) (end - (p + 2)),
|
||||
ssl->conf->f_rng, ssl->conf->p_rng)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_calc_secret", ret);
|
||||
return ret;
|
||||
@ -6845,7 +6898,7 @@ int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context *ssl, mbedtls_key_excha
|
||||
memcpy(p, psk, psk_len);
|
||||
p += psk_len;
|
||||
|
||||
ssl->handshake->pmslen = p - ssl->handshake->premaster;
|
||||
ssl->handshake->pmslen = (size_t) (p - ssl->handshake->premaster);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -7103,7 +7156,7 @@ static int ssl_parse_certificate_chain(mbedtls_ssl_context *ssl,
|
||||
/*
|
||||
* Same message structure as in mbedtls_ssl_write_certificate()
|
||||
*/
|
||||
n = (ssl->in_msg[i+1] << 8) | ssl->in_msg[i+2];
|
||||
n = MBEDTLS_GET_UINT16_BE(ssl->in_msg, i + 1);
|
||||
|
||||
if (ssl->in_msg[i] != 0 ||
|
||||
ssl->in_hslen != n + 3 + mbedtls_ssl_hs_hdr_len(ssl)) {
|
||||
@ -7137,8 +7190,7 @@ static int ssl_parse_certificate_chain(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
/* Read length of the next CRT in the chain. */
|
||||
n = ((unsigned int) ssl->in_msg[i + 1] << 8)
|
||||
| (unsigned int) ssl->in_msg[i + 2];
|
||||
n = MBEDTLS_GET_UINT16_BE(ssl->in_msg, i + 1);
|
||||
i += 3;
|
||||
|
||||
if (n < 128 || i + n > ssl->in_hslen) {
|
||||
@ -7666,7 +7718,7 @@ static int ssl_calc_finished_tls_generic(mbedtls_ssl_context *ssl, void *ctx,
|
||||
unsigned char *padbuf, size_t hlen,
|
||||
unsigned char *buf, int from)
|
||||
{
|
||||
int len = 12;
|
||||
unsigned int len = 12;
|
||||
const char *sender;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status;
|
||||
@ -7866,7 +7918,8 @@ void mbedtls_ssl_handshake_wrapup(mbedtls_ssl_context *ssl)
|
||||
|
||||
int mbedtls_ssl_write_finished(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret, hash_len;
|
||||
int ret;
|
||||
unsigned int hash_len;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> write finished"));
|
||||
|
||||
@ -9038,7 +9091,7 @@ static int ssl_tls12_session_load(mbedtls_ssl_session *session,
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
session->ciphersuite = (p[0] << 8) | p[1];
|
||||
session->ciphersuite = MBEDTLS_GET_UINT16_BE(p, 0);
|
||||
p += 2;
|
||||
|
||||
session->id_len = *p++;
|
||||
@ -9074,7 +9127,7 @@ static int ssl_tls12_session_load(mbedtls_ssl_session *session,
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
cert_len = (p[0] << 16) | (p[1] << 8) | p[2];
|
||||
cert_len = MBEDTLS_GET_UINT24_BE(p, 0);
|
||||
p += 3;
|
||||
|
||||
if (cert_len != 0) {
|
||||
@ -9146,7 +9199,7 @@ static int ssl_tls12_session_load(mbedtls_ssl_session *session,
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
session->ticket_len = (p[0] << 16) | (p[1] << 8) | p[2];
|
||||
session->ticket_len = MBEDTLS_GET_UINT24_BE(p, 0);
|
||||
p += 3;
|
||||
|
||||
if (session->ticket_len != 0) {
|
||||
@ -9328,7 +9381,7 @@ int mbedtls_ssl_write_sig_alg_ext(mbedtls_ssl_context *ssl, unsigned char *buf,
|
||||
}
|
||||
|
||||
/* Length of supported_signature_algorithms */
|
||||
supported_sig_alg_len = p - supported_sig_alg;
|
||||
supported_sig_alg_len = (size_t) (p - supported_sig_alg);
|
||||
if (supported_sig_alg_len == 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("No signature algorithms defined."));
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
@ -9338,7 +9391,7 @@ int mbedtls_ssl_write_sig_alg_ext(mbedtls_ssl_context *ssl, unsigned char *buf,
|
||||
MBEDTLS_PUT_UINT16_BE(supported_sig_alg_len + 2, buf, 2);
|
||||
MBEDTLS_PUT_UINT16_BE(supported_sig_alg_len, buf, 4);
|
||||
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
mbedtls_ssl_tls13_set_hs_sent_ext_mask(ssl, MBEDTLS_TLS_EXT_SIG_ALG);
|
||||
|
@ -607,7 +607,7 @@ int mbedtls_ssl_tls12_write_client_hello_exts(mbedtls_ssl_context *ssl,
|
||||
p += ext_len;
|
||||
#endif
|
||||
|
||||
*out_len = p - buf;
|
||||
*out_len = (size_t) (p - buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -941,7 +941,7 @@ static int ssl_parse_alpn_ext(mbedtls_ssl_context *ssl,
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
|
||||
list_len = (buf[0] << 8) | buf[1];
|
||||
list_len = MBEDTLS_GET_UINT16_BE(buf, 0);
|
||||
if (list_len != len - 2) {
|
||||
mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR);
|
||||
@ -1304,8 +1304,7 @@ static int ssl_parse_server_hello(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
if (ssl->in_hslen > mbedtls_ssl_hs_hdr_len(ssl) + 39 + n) {
|
||||
ext_len = ((buf[38 + n] << 8)
|
||||
| (buf[39 + n]));
|
||||
ext_len = MBEDTLS_GET_UINT16_BE(buf, 38 + n);
|
||||
|
||||
if ((ext_len > 0 && ext_len < 4) ||
|
||||
ssl->in_hslen != mbedtls_ssl_hs_hdr_len(ssl) + 40 + n + ext_len) {
|
||||
@ -1326,7 +1325,7 @@ static int ssl_parse_server_hello(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
/* ciphersuite (used later) */
|
||||
i = (buf[35 + n] << 8) | buf[36 + n];
|
||||
i = (int) MBEDTLS_GET_UINT16_BE(buf, n + 35);
|
||||
|
||||
/*
|
||||
* Read and check compression
|
||||
@ -1447,10 +1446,8 @@ static int ssl_parse_server_hello(mbedtls_ssl_context *ssl)
|
||||
ext_len));
|
||||
|
||||
while (ext_len) {
|
||||
unsigned int ext_id = ((ext[0] << 8)
|
||||
| (ext[1]));
|
||||
unsigned int ext_size = ((ext[2] << 8)
|
||||
| (ext[3]));
|
||||
unsigned int ext_id = MBEDTLS_GET_UINT16_BE(ext, 0);
|
||||
unsigned int ext_size = MBEDTLS_GET_UINT16_BE(ext, 2);
|
||||
|
||||
if (ext_size + 4 > ext_len) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad server hello message"));
|
||||
@ -1741,9 +1738,8 @@ static int ssl_parse_server_ecdh_params(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
/* Next two bytes are the namedcurve value */
|
||||
tls_id = *(*p)++;
|
||||
tls_id <<= 8;
|
||||
tls_id |= *(*p)++;
|
||||
tls_id = MBEDTLS_GET_UINT16_BE(*p, 0);
|
||||
*p += 2;
|
||||
|
||||
/* Check it's a curve we offered */
|
||||
if (mbedtls_ssl_check_curve_tls_id(ssl, tls_id) != 0) {
|
||||
@ -1883,7 +1879,7 @@ static int ssl_parse_server_psk_hint(mbedtls_ssl_context *ssl,
|
||||
("bad server key exchange message (psk_identity_hint length)"));
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
len = (*p)[0] << 8 | (*p)[1];
|
||||
len = MBEDTLS_GET_UINT16_BE(*p, 0);
|
||||
*p += 2;
|
||||
|
||||
if (end - (*p) < len) {
|
||||
@ -2174,7 +2170,7 @@ start_processing:
|
||||
#endif
|
||||
p = ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl);
|
||||
end = ssl->in_msg + ssl->in_hslen;
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "server key exchange", p, end - p);
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "server key exchange", p, (size_t) (end - p));
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
||||
@ -2299,7 +2295,7 @@ start_processing:
|
||||
mbedtls_md_type_t md_alg = MBEDTLS_MD_NONE;
|
||||
mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
|
||||
unsigned char *params = ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl);
|
||||
size_t params_len = p - params;
|
||||
size_t params_len = (size_t) (p - params);
|
||||
void *rs_ctx = NULL;
|
||||
uint16_t sig_alg;
|
||||
|
||||
@ -2357,7 +2353,7 @@ start_processing:
|
||||
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR);
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
sig_len = (p[0] << 8) | p[1];
|
||||
sig_len = MBEDTLS_GET_UINT16_BE(p, 0);
|
||||
p += 2;
|
||||
|
||||
if (p != end - sig_len) {
|
||||
@ -2585,8 +2581,7 @@ static int ssl_parse_certificate_request(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
/* supported_signature_algorithms */
|
||||
sig_alg_len = ((buf[mbedtls_ssl_hs_hdr_len(ssl) + 1 + n] << 8)
|
||||
| (buf[mbedtls_ssl_hs_hdr_len(ssl) + 2 + n]));
|
||||
sig_alg_len = MBEDTLS_GET_UINT16_BE(buf, mbedtls_ssl_hs_hdr_len(ssl) + 1 + n);
|
||||
|
||||
/*
|
||||
* The furthest access in buf is in the loop few lines below:
|
||||
@ -2621,8 +2616,7 @@ static int ssl_parse_certificate_request(mbedtls_ssl_context *ssl)
|
||||
n += 2 + sig_alg_len;
|
||||
|
||||
/* certificate_authorities */
|
||||
dn_len = ((buf[mbedtls_ssl_hs_hdr_len(ssl) + 1 + n] << 8)
|
||||
| (buf[mbedtls_ssl_hs_hdr_len(ssl) + 2 + n]));
|
||||
dn_len = MBEDTLS_GET_UINT16_BE(buf, mbedtls_ssl_hs_hdr_len(ssl) + 1 + n);
|
||||
|
||||
n += dn_len;
|
||||
if (ssl->in_hslen != mbedtls_ssl_hs_hdr_len(ssl) + 3 + n) {
|
||||
@ -3252,9 +3246,9 @@ static int ssl_write_certificate_verify(mbedtls_ssl_context *ssl)
|
||||
size_t hashlen;
|
||||
void *rs_ctx = NULL;
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
size_t out_buf_len = ssl->out_buf_len - (ssl->out_msg - ssl->out_buf);
|
||||
size_t out_buf_len = ssl->out_buf_len - (size_t) (ssl->out_msg - ssl->out_buf);
|
||||
#else
|
||||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (ssl->out_msg - ssl->out_buf);
|
||||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (size_t) (ssl->out_msg - ssl->out_buf);
|
||||
#endif
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> write certificate verify"));
|
||||
@ -3421,10 +3415,9 @@ static int ssl_parse_new_session_ticket(mbedtls_ssl_context *ssl)
|
||||
|
||||
msg = ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl);
|
||||
|
||||
lifetime = (((uint32_t) msg[0]) << 24) | (msg[1] << 16) |
|
||||
(msg[2] << 8) | (msg[3]);
|
||||
lifetime = MBEDTLS_GET_UINT32_BE(msg, 0);
|
||||
|
||||
ticket_len = (msg[4] << 8) | (msg[5]);
|
||||
ticket_len = MBEDTLS_GET_UINT16_BE(msg, 4);
|
||||
|
||||
if (ticket_len + 6 + mbedtls_ssl_hs_hdr_len(ssl) != ssl->in_hslen) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad new session ticket message"));
|
||||
|
@ -192,7 +192,7 @@ static int ssl_parse_supported_groups_ext(mbedtls_ssl_context *ssl,
|
||||
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR);
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
list_size = ((buf[0] << 8) | (buf[1]));
|
||||
list_size = MBEDTLS_GET_UINT16_BE(buf, 0);
|
||||
if (list_size + 2 != len ||
|
||||
list_size % 2 != 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad client hello message"));
|
||||
@ -957,7 +957,7 @@ read_record_header:
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, message len.: %d",
|
||||
(ssl->in_len[0] << 8) | ssl->in_len[1]));
|
||||
MBEDTLS_GET_UINT16_BE(ssl->in_len, 0)));
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, protocol version: [%d:%d]",
|
||||
buf[1], buf[2]));
|
||||
@ -993,7 +993,7 @@ read_record_header:
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
msg_len = (ssl->in_len[0] << 8) | ssl->in_len[1];
|
||||
msg_len = MBEDTLS_GET_UINT16_BE(ssl->in_len, 0);
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) {
|
||||
@ -1251,8 +1251,7 @@ read_record_header:
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
ciph_offset = 35 + sess_len;
|
||||
|
||||
ciph_len = (buf[ciph_offset + 0] << 8)
|
||||
| (buf[ciph_offset + 1]);
|
||||
ciph_len = MBEDTLS_GET_UINT16_BE(buf, ciph_offset);
|
||||
|
||||
if (ciph_len < 2 ||
|
||||
ciph_len + 2 + ciph_offset + 1 > msg_len || /* 1 for comp. alg. len */
|
||||
@ -1300,8 +1299,7 @@ read_record_header:
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
|
||||
ext_len = (buf[ext_offset + 0] << 8)
|
||||
| (buf[ext_offset + 1]);
|
||||
ext_len = MBEDTLS_GET_UINT16_BE(buf, ext_offset);
|
||||
|
||||
if (msg_len != ext_offset + 2 + ext_len) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad client hello message"));
|
||||
@ -1325,8 +1323,8 @@ read_record_header:
|
||||
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR);
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
ext_id = ((ext[0] << 8) | (ext[1]));
|
||||
ext_size = ((ext[2] << 8) | (ext[3]));
|
||||
ext_id = MBEDTLS_GET_UINT16_BE(ext, 0);
|
||||
ext_size = MBEDTLS_GET_UINT16_BE(ext, 2);
|
||||
|
||||
if (ext_size + 4 > ext_len) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad client hello message"));
|
||||
@ -1858,7 +1856,7 @@ static void ssl_write_renegotiation_ext(mbedtls_ssl_context *ssl,
|
||||
*p++ = 0x00;
|
||||
}
|
||||
|
||||
*olen = p - buf;
|
||||
*olen = (size_t) (p - buf);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||
@ -1950,7 +1948,7 @@ static void ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context *ssl,
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
ret = mbedtls_psa_ecjpake_write_round(&ssl->handshake->psa_pake_ctx,
|
||||
p + 2, end - p - 2, &kkpp_len,
|
||||
p + 2, (size_t) (end - p - 2), &kkpp_len,
|
||||
MBEDTLS_ECJPAKE_ROUND_ONE);
|
||||
if (ret != 0) {
|
||||
psa_destroy_key(ssl->handshake->psa_pake_password);
|
||||
@ -1960,7 +1958,7 @@ static void ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
#else
|
||||
ret = mbedtls_ecjpake_write_round_one(&ssl->handshake->ecjpake_ctx,
|
||||
p + 2, end - p - 2, &kkpp_len,
|
||||
p + 2, (size_t) (end - p - 2), &kkpp_len,
|
||||
ssl->conf->f_rng, ssl->conf->p_rng);
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_write_round_one", ret);
|
||||
@ -2081,7 +2079,7 @@ static int ssl_write_hello_verify_request(mbedtls_ssl_context *ssl)
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "cookie sent", cookie_len_byte + 1, *cookie_len_byte);
|
||||
|
||||
ssl->out_msglen = p - ssl->out_msg;
|
||||
ssl->out_msglen = (size_t) (p - ssl->out_msg);
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST;
|
||||
|
||||
@ -2386,7 +2384,7 @@ static int ssl_write_server_hello(mbedtls_ssl_context *ssl)
|
||||
p += 2 + ext_len;
|
||||
}
|
||||
|
||||
ssl->out_msglen = p - buf;
|
||||
ssl->out_msglen = (size_t) (p - buf);
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO;
|
||||
|
||||
@ -2570,12 +2568,12 @@ static int ssl_write_certificate_request(mbedtls_ssl_context *ssl)
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "requested DN", p - dn_size, dn_size);
|
||||
|
||||
total_dn_size += 2 + dn_size;
|
||||
total_dn_size += (unsigned short) (2 + dn_size);
|
||||
crt = crt->next;
|
||||
}
|
||||
}
|
||||
|
||||
ssl->out_msglen = p - buf;
|
||||
ssl->out_msglen = (size_t) (p - buf);
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE_REQUEST;
|
||||
MBEDTLS_PUT_UINT16_BE(total_dn_size, ssl->out_msg, 4 + ct_len + sa_len);
|
||||
@ -2779,9 +2777,9 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context *ssl,
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
size_t out_buf_len = ssl->out_buf_len - (ssl->out_msg - ssl->out_buf);
|
||||
size_t out_buf_len = ssl->out_buf_len - (size_t) (ssl->out_msg - ssl->out_buf);
|
||||
#else
|
||||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (ssl->out_msg - ssl->out_buf);
|
||||
size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (size_t) (ssl->out_msg - ssl->out_buf);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -3086,7 +3084,7 @@ curve_matching_done:
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
size_t dig_signed_len = ssl->out_msg + ssl->out_msglen - dig_signed;
|
||||
size_t dig_signed_len = (size_t) (ssl->out_msg + ssl->out_msglen - dig_signed);
|
||||
size_t hashlen = 0;
|
||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
@ -3101,8 +3099,8 @@ curve_matching_done:
|
||||
mbedtls_pk_type_t sig_alg =
|
||||
mbedtls_ssl_get_ciphersuite_sig_pk_alg(ciphersuite_info);
|
||||
|
||||
unsigned int sig_hash =
|
||||
mbedtls_ssl_tls12_get_preferred_hash_for_sig_alg(
|
||||
unsigned char sig_hash =
|
||||
(unsigned char) mbedtls_ssl_tls12_get_preferred_hash_for_sig_alg(
|
||||
ssl, mbedtls_ssl_sig_from_pk_alg(sig_alg));
|
||||
|
||||
mbedtls_md_type_t md_alg = mbedtls_ssl_md_alg_from_hash(sig_hash);
|
||||
@ -3360,7 +3358,7 @@ static int ssl_parse_client_dh_public(mbedtls_ssl_context *ssl, unsigned char **
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
|
||||
n = ((*p)[0] << 8) | (*p)[1];
|
||||
n = MBEDTLS_GET_UINT16_BE(*p, 0);
|
||||
*p += 2;
|
||||
|
||||
if (*p + n > end) {
|
||||
@ -3593,7 +3591,7 @@ static int ssl_parse_client_psk_identity(mbedtls_ssl_context *ssl, unsigned char
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
|
||||
n = ((*p)[0] << 8) | (*p)[1];
|
||||
n = MBEDTLS_GET_UINT16_BE(*p, 0);
|
||||
*p += 2;
|
||||
|
||||
if (n == 0 || n > end - *p) {
|
||||
@ -3763,7 +3761,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
handshake->xxdh_psa_privkey = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
#else
|
||||
if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx,
|
||||
p, end - p)) != 0) {
|
||||
p, (size_t) (end - p))) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_read_public", ret);
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
@ -3976,7 +3974,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx,
|
||||
p, end - p)) != 0) {
|
||||
p, (size_t) (end - p))) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_read_public", ret);
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
@ -4005,7 +4003,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if ((ret = mbedtls_psa_ecjpake_read_round(
|
||||
&ssl->handshake->psa_pake_ctx, p, end - p,
|
||||
&ssl->handshake->psa_pake_ctx, p, (size_t) (end - p),
|
||||
MBEDTLS_ECJPAKE_ROUND_TWO)) != 0) {
|
||||
psa_destroy_key(ssl->handshake->psa_pake_password);
|
||||
psa_pake_abort(&ssl->handshake->psa_pake_ctx);
|
||||
@ -4015,7 +4013,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
#else
|
||||
ret = mbedtls_ecjpake_read_round_two(&ssl->handshake->ecjpake_ctx,
|
||||
p, end - p);
|
||||
p, (size_t) (end - p));
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_read_round_two", ret);
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
@ -4189,7 +4187,7 @@ static int ssl_parse_certificate_verify(mbedtls_ssl_context *ssl)
|
||||
return MBEDTLS_ERR_SSL_DECODE_ERROR;
|
||||
}
|
||||
|
||||
sig_len = (ssl->in_msg[i] << 8) | ssl->in_msg[i+1];
|
||||
sig_len = MBEDTLS_GET_UINT16_BE(ssl->in_msg, i);
|
||||
i += 2;
|
||||
|
||||
if (i + sig_len != ssl->in_hslen) {
|
||||
|
@ -931,28 +931,14 @@ int mbedtls_ssl_tls13_write_identities_of_pre_shared_key_ext(
|
||||
if (ssl_tls13_ticket_get_identity(
|
||||
ssl, &hash_alg, &identity, &identity_len) == 0) {
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
mbedtls_time_t now = mbedtls_time(NULL);
|
||||
mbedtls_ms_time_t now = mbedtls_ms_time();
|
||||
mbedtls_ssl_session *session = ssl->session_negotiate;
|
||||
/* The ticket age has been checked to be smaller than the
|
||||
* `ticket_lifetime` in ssl_prepare_client_hello() which is smaller than
|
||||
* 7 days (enforced in ssl_tls13_parse_new_session_ticket()) . Thus the
|
||||
* cast to `uint32_t` of the ticket age is safe. */
|
||||
uint32_t obfuscated_ticket_age =
|
||||
(uint32_t) (now - session->ticket_received);
|
||||
|
||||
/*
|
||||
* The ticket timestamp is in seconds but the ticket age is in
|
||||
* milliseconds. If the ticket was received at the end of a second and
|
||||
* re-used here just at the beginning of the next second, the computed
|
||||
* age `now - session->ticket_received` is equal to 1s thus 1000 ms
|
||||
* while the actual age could be just a few milliseconds or tens of
|
||||
* milliseconds. If the server has more accurate ticket timestamps
|
||||
* (typically timestamps in milliseconds), as part of the processing of
|
||||
* the ClientHello, it may compute a ticket lifetime smaller than the
|
||||
* one computed here and potentially reject the ticket. To avoid that,
|
||||
* remove one second to the ticket age if possible.
|
||||
*/
|
||||
if (obfuscated_ticket_age > 0) {
|
||||
obfuscated_ticket_age -= 1;
|
||||
}
|
||||
|
||||
obfuscated_ticket_age *= 1000;
|
||||
(uint32_t) (now - session->ticket_reception_time);
|
||||
obfuscated_ticket_age += session->ticket_age_add;
|
||||
|
||||
ret = ssl_tls13_write_identity(ssl, p, end,
|
||||
@ -2762,6 +2748,11 @@ static int ssl_tls13_parse_new_session_ticket(mbedtls_ssl_context *ssl,
|
||||
MBEDTLS_SSL_DEBUG_MSG(3,
|
||||
("ticket_lifetime: %u",
|
||||
(unsigned int) session->ticket_lifetime));
|
||||
if (session->ticket_lifetime >
|
||||
MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("ticket_lifetime exceeds 7 days."));
|
||||
return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER;
|
||||
}
|
||||
|
||||
session->ticket_age_add = MBEDTLS_GET_UINT32_BE(p, 4);
|
||||
MBEDTLS_SSL_DEBUG_MSG(3,
|
||||
@ -2837,7 +2828,7 @@ static int ssl_tls13_postprocess_new_session_ticket(mbedtls_ssl_context *ssl,
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
/* Store ticket creation time */
|
||||
session->ticket_received = mbedtls_time(NULL);
|
||||
session->ticket_reception_time = mbedtls_ms_time();
|
||||
#endif
|
||||
|
||||
ciphersuite_info = mbedtls_ssl_ciphersuite_from_id(session->ciphersuite);
|
||||
|
@ -111,9 +111,10 @@ static int ssl_tls13_offered_psks_check_identity_match_ticket(
|
||||
unsigned char *ticket_buffer;
|
||||
unsigned int key_exchanges;
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
mbedtls_time_t now;
|
||||
uint64_t age_in_s;
|
||||
int64_t age_diff_in_ms;
|
||||
mbedtls_ms_time_t now;
|
||||
mbedtls_ms_time_t server_age;
|
||||
uint32_t client_age;
|
||||
mbedtls_ms_time_t age_diff;
|
||||
#endif
|
||||
|
||||
((void) obfuscated_ticket_age);
|
||||
@ -190,17 +191,17 @@ static int ssl_tls13_offered_psks_check_identity_match_ticket(
|
||||
|
||||
ret = MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED;
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
now = mbedtls_time(NULL);
|
||||
now = mbedtls_ms_time();
|
||||
|
||||
if (now < session->start) {
|
||||
if (now < session->ticket_creation_time) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
3, ("Invalid ticket start time ( now=%" MBEDTLS_PRINTF_LONGLONG
|
||||
", start=%" MBEDTLS_PRINTF_LONGLONG " )",
|
||||
(long long) now, (long long) session->start));
|
||||
3, ("Invalid ticket creation time ( now = %" MBEDTLS_PRINTF_MS_TIME
|
||||
", creation_time = %" MBEDTLS_PRINTF_MS_TIME " )",
|
||||
now, session->ticket_creation_time));
|
||||
goto exit;
|
||||
}
|
||||
|
||||
age_in_s = (uint64_t) (now - session->start);
|
||||
server_age = now - session->ticket_creation_time;
|
||||
|
||||
/* RFC 8446 section 4.6.1
|
||||
*
|
||||
@ -211,12 +212,11 @@ static int ssl_tls13_offered_psks_check_identity_match_ticket(
|
||||
* Clients MUST NOT attempt to use tickets which have ages greater than
|
||||
* the "ticket_lifetime" value which was provided with the ticket.
|
||||
*
|
||||
* For time being, the age MUST be less than 604800 seconds (7 days).
|
||||
*/
|
||||
if (age_in_s > 604800) {
|
||||
if (server_age > MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME * 1000) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
3, ("Ticket age exceeds limitation ticket_age=%lu",
|
||||
(long unsigned int) age_in_s));
|
||||
3, ("Ticket age exceeds limitation ticket_age = %" MBEDTLS_PRINTF_MS_TIME,
|
||||
server_age));
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -227,18 +227,19 @@ static int ssl_tls13_offered_psks_check_identity_match_ticket(
|
||||
* ticket_age_add from PskIdentity.obfuscated_ticket_age modulo 2^32) is
|
||||
* within a small tolerance of the time since the ticket was issued.
|
||||
*
|
||||
* NOTE: When `now == session->start`, `age_diff_in_ms` may be negative
|
||||
* as the age units are different on the server (s) and in the
|
||||
* client (ms) side. Add a -1000 ms tolerance window to take this
|
||||
* into account.
|
||||
* NOTE: The typical accuracy of an RTC crystal is ±100 to ±20 parts per
|
||||
* million (360 to 72 milliseconds per hour). Default tolerance
|
||||
* window is 6s, thus in the worst case clients and servers must
|
||||
* sync up their system time every 6000/360/2~=8 hours.
|
||||
*/
|
||||
age_diff_in_ms = age_in_s * 1000;
|
||||
age_diff_in_ms -= (obfuscated_ticket_age - session->ticket_age_add);
|
||||
if (age_diff_in_ms <= -1000 ||
|
||||
age_diff_in_ms > MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE) {
|
||||
client_age = obfuscated_ticket_age - session->ticket_age_add;
|
||||
age_diff = server_age - (mbedtls_ms_time_t) client_age;
|
||||
if (age_diff < -MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE ||
|
||||
age_diff > MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(
|
||||
3, ("Ticket age outside tolerance window ( diff=%d )",
|
||||
(int) age_diff_in_ms));
|
||||
3, ("Ticket age outside tolerance window ( diff = %"
|
||||
MBEDTLS_PRINTF_MS_TIME ")",
|
||||
age_diff));
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -2877,7 +2878,7 @@ static int ssl_tls13_prepare_new_session_ticket(mbedtls_ssl_context *ssl,
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> prepare NewSessionTicket msg"));
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
session->start = mbedtls_time(NULL);
|
||||
session->ticket_creation_time = mbedtls_ms_time();
|
||||
#endif
|
||||
|
||||
/* Set ticket_flags depends on the advertised psk key exchange mode */
|
||||
@ -3024,8 +3025,8 @@ static int ssl_tls13_write_new_session_ticket_body(mbedtls_ssl_context *ssl,
|
||||
* MAY treat a ticket as valid for a shorter period of time than what
|
||||
* is stated in the ticket_lifetime.
|
||||
*/
|
||||
if (ticket_lifetime > 604800) {
|
||||
ticket_lifetime = 604800;
|
||||
if (ticket_lifetime > MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME) {
|
||||
ticket_lifetime = MBEDTLS_SSL_TLS1_3_MAX_ALLOWED_TICKET_LIFETIME;
|
||||
}
|
||||
MBEDTLS_PUT_UINT32_BE(ticket_lifetime, p, 0);
|
||||
MBEDTLS_SSL_DEBUG_MSG(3, ("ticket_lifetime: %u",
|
||||
|
@ -56,28 +56,27 @@ static void threading_mutex_init_pthread(mbedtls_threading_mutex_t *mutex)
|
||||
return;
|
||||
}
|
||||
|
||||
/* A nonzero value of is_valid indicates a successfully initialized
|
||||
* mutex. This is a workaround for not being able to return an error
|
||||
* code for this function. The lock/unlock functions return an error
|
||||
* if is_valid is nonzero. The Mbed TLS unit test code uses this field
|
||||
* to distinguish more states of the mutex; see
|
||||
* tests/src/threading_helpers for details. */
|
||||
mutex->is_valid = pthread_mutex_init(&mutex->mutex, NULL) == 0;
|
||||
/* One problem here is that calling lock on a pthread mutex without first
|
||||
* having initialised it is undefined behaviour. Obviously we cannot check
|
||||
* this here in a thread safe manner without a significant performance
|
||||
* hit, so state transitions are checked in tests only via the state
|
||||
* variable. Please make sure any new mutex that gets added is exercised in
|
||||
* tests; see tests/src/threading_helpers.c for more details. */
|
||||
(void) pthread_mutex_init(&mutex->mutex, NULL);
|
||||
}
|
||||
|
||||
static void threading_mutex_free_pthread(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
if (mutex == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void) pthread_mutex_destroy(&mutex->mutex);
|
||||
mutex->is_valid = 0;
|
||||
}
|
||||
|
||||
static int threading_mutex_lock_pthread(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
if (mutex == NULL) {
|
||||
return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ static int threading_mutex_lock_pthread(mbedtls_threading_mutex_t *mutex)
|
||||
|
||||
static int threading_mutex_unlock_pthread(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL || !mutex->is_valid) {
|
||||
if (mutex == NULL) {
|
||||
return MBEDTLS_ERR_THREADING_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ static int parse_attribute_value_string(const char *s,
|
||||
return MBEDTLS_ERR_X509_INVALID_NAME;
|
||||
}
|
||||
}
|
||||
*data_len = d - data;
|
||||
*data_len = (size_t) (d - data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -297,8 +297,8 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
|
||||
|
||||
while (c <= end) {
|
||||
if (in_attr_type && *c == '=') {
|
||||
if ((attr_descr = x509_attr_descr_from_name(s, c - s)) == NULL) {
|
||||
if ((mbedtls_oid_from_numeric_string(&oid, s, c - s)) != 0) {
|
||||
if ((attr_descr = x509_attr_descr_from_name(s, (size_t) (c - s))) == NULL) {
|
||||
if ((mbedtls_oid_from_numeric_string(&oid, s, (size_t) (c - s))) != 0) {
|
||||
return MBEDTLS_ERR_X509_INVALID_NAME;
|
||||
} else {
|
||||
numericoid = 1;
|
||||
@ -322,7 +322,7 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
|
||||
/* We know that c >= s (loop invariant) and c != s (in this
|
||||
* else branch), hence c - s - 1 >= 0. */
|
||||
parse_ret = parse_attribute_value_hex_der_encoded(
|
||||
s + 1, c - s - 1,
|
||||
s + 1, (size_t) (c - s) - 1,
|
||||
data, sizeof(data), &data_len, &tag);
|
||||
if (parse_ret != 0) {
|
||||
mbedtls_free(oid.p);
|
||||
|
@ -367,7 +367,7 @@ int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
crl->tbs.len = end - crl->tbs.p;
|
||||
crl->tbs.len = (size_t) (end - crl->tbs.p);
|
||||
|
||||
/*
|
||||
* Version ::= INTEGER OPTIONAL { v1(0), v2(1) }
|
||||
@ -411,7 +411,7 @@ int mbedtls_x509_crl_parse_der(mbedtls_x509_crl *chain,
|
||||
return ret;
|
||||
}
|
||||
|
||||
crl->issuer_raw.len = p - crl->issuer_raw.p;
|
||||
crl->issuer_raw.len = (size_t) (p - crl->issuer_raw.p);
|
||||
|
||||
/*
|
||||
* thisUpdate Time
|
||||
|
@ -1108,7 +1108,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
}
|
||||
|
||||
end = crt_end = p + len;
|
||||
crt->raw.len = crt_end - buf;
|
||||
crt->raw.len = (size_t) (crt_end - buf);
|
||||
if (make_copy != 0) {
|
||||
/* Create and populate a new buffer for the raw field. */
|
||||
crt->raw.p = p = mbedtls_calloc(1, crt->raw.len);
|
||||
@ -1138,7 +1138,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
crt->tbs.len = end - crt->tbs.p;
|
||||
crt->tbs.len = (size_t) (end - crt->tbs.p);
|
||||
|
||||
/*
|
||||
* Version ::= INTEGER { v1(0), v2(1), v3(2) }
|
||||
@ -1185,7 +1185,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
return ret;
|
||||
}
|
||||
|
||||
crt->issuer_raw.len = p - crt->issuer_raw.p;
|
||||
crt->issuer_raw.len = (size_t) (p - crt->issuer_raw.p);
|
||||
|
||||
/*
|
||||
* Validity ::= SEQUENCE {
|
||||
@ -1215,7 +1215,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
return ret;
|
||||
}
|
||||
|
||||
crt->subject_raw.len = p - crt->subject_raw.p;
|
||||
crt->subject_raw.len = (size_t) (p - crt->subject_raw.p);
|
||||
|
||||
/*
|
||||
* SubjectPublicKeyInfo
|
||||
@ -1225,7 +1225,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
mbedtls_x509_crt_free(crt);
|
||||
return ret;
|
||||
}
|
||||
crt->pk_raw.len = p - crt->pk_raw.p;
|
||||
crt->pk_raw.len = (size_t) (p - crt->pk_raw.p);
|
||||
|
||||
/*
|
||||
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
|
||||
|
@ -328,7 +328,7 @@ static int mbedtls_x509_csr_parse_der_internal(mbedtls_x509_csr *csr,
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
csr->cri.len = end - csr->cri.p;
|
||||
csr->cri.len = (size_t) (end - csr->cri.p);
|
||||
|
||||
/*
|
||||
* Version ::= INTEGER { v1(0) }
|
||||
@ -361,7 +361,7 @@ static int mbedtls_x509_csr_parse_der_internal(mbedtls_x509_csr *csr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
csr->subject_raw.len = p - csr->subject_raw.p;
|
||||
csr->subject_raw.len = (size_t) (p - csr->subject_raw.p);
|
||||
|
||||
/*
|
||||
* subjectPKInfo SubjectPublicKeyInfo
|
||||
|
@ -481,7 +481,7 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
*/
|
||||
MBEDTLS_ASN1_CHK_ADD(pub_len,
|
||||
mbedtls_pk_write_pubkey_der(ctx->subject_key,
|
||||
buf, c - buf));
|
||||
buf, (size_t) (c - buf)));
|
||||
c -= pub_len;
|
||||
len += pub_len;
|
||||
|
||||
|
@ -185,7 +185,7 @@ static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC));
|
||||
|
||||
MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_pk_write_pubkey_der(ctx->key,
|
||||
buf, c - buf));
|
||||
buf, (size_t) (c - buf)));
|
||||
c -= pub_len;
|
||||
len += pub_len;
|
||||
|
||||
@ -276,7 +276,7 @@ static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
|
||||
|
||||
/* Zero the unused bytes at the start of buf */
|
||||
memset(buf, 0, c2 - buf);
|
||||
memset(buf, 0, (size_t) (c2 - buf));
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
@ -44,6 +44,13 @@ int main(void)
|
||||
"MBEDTLS_CTR_DRBG_C and/or MBEDTLS_SHA1_C not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
|
||||
#elif defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_BLOCK_CIPHER_NO_DECRYPT defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
|
20
programs/psa/psa_hash_demo.sh
Executable file
20
programs/psa/psa_hash_demo.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright The Mbed TLS Contributors
|
||||
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
|
||||
. "${0%/*}/../demo_common.sh"
|
||||
|
||||
msg <<'EOF'
|
||||
This program demonstrates the use of the PSA cryptography interface to
|
||||
compute a SHA-256 hash of a test string using the one-shot API call
|
||||
and also using the multi-part operation API.
|
||||
EOF
|
||||
|
||||
depends_on MBEDTLS_PSA_CRYPTO_C PSA_WANT_ALG_SHA_256
|
||||
|
||||
program="${0%/*}"/psa_hash
|
||||
|
||||
"$program"
|
||||
|
||||
cleanup
|
@ -1419,22 +1419,29 @@ int dummy_ticket_parse(void *p_ticket, mbedtls_ssl_session *session,
|
||||
return MBEDTLS_ERR_SSL_INVALID_MAC;
|
||||
case 2:
|
||||
return MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED;
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
case 3:
|
||||
session->start = mbedtls_time(NULL) + 10;
|
||||
/* Creation time in the future. */
|
||||
session->ticket_creation_time = mbedtls_ms_time() + 1000;
|
||||
break;
|
||||
case 4:
|
||||
session->start = mbedtls_time(NULL) - 10 - 7 * 24 * 3600;
|
||||
/* Ticket has reached the end of lifetime. */
|
||||
session->ticket_creation_time = mbedtls_ms_time() -
|
||||
(7 * 24 * 3600 * 1000 + 1000);
|
||||
break;
|
||||
case 5:
|
||||
session->start = mbedtls_time(NULL) - 10;
|
||||
/* Ticket is valid, but client age is below the lower bound of the tolerance window. */
|
||||
session->ticket_age_add += MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE + 4 * 1000;
|
||||
/* Make sure the execution time does not affect the result */
|
||||
session->ticket_creation_time = mbedtls_ms_time();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
session->start = mbedtls_time(NULL);
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
session->ticket_age_add -= 1000;
|
||||
#endif
|
||||
/* Ticket is valid, but client age is beyond the upper bound of the tolerance window. */
|
||||
session->ticket_age_add -= MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE + 4 * 1000;
|
||||
/* Make sure the execution time does not affect the result */
|
||||
session->ticket_creation_time = mbedtls_ms_time();
|
||||
break;
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
case 7:
|
||||
session->ticket_flags = MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE;
|
||||
break;
|
||||
|
@ -435,6 +435,9 @@ int test_hooks_failure_detected(void)
|
||||
|
||||
void test_hooks_free(void)
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
mbedtls_test_mutex_usage_end();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_TEST_HOOKS */
|
||||
|
@ -28,10 +28,13 @@
|
||||
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/platform.h>
|
||||
#include <mbedtls/platform_util.h>
|
||||
#include "test/helpers.h"
|
||||
#include "test/macros.h"
|
||||
#include "test/memory.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -46,6 +49,12 @@
|
||||
*/
|
||||
volatile int false_but_the_compiler_does_not_know = 0;
|
||||
|
||||
/* Hide calls to calloc/free from static checkers such as
|
||||
* `gcc-12 -Wuse-after-free`, to avoid compile-time complaints about
|
||||
* code where we do mean to cause a runtime error. */
|
||||
void * (* volatile calloc_but_the_compiler_does_not_know)(size_t, size_t) = mbedtls_calloc;
|
||||
void(*volatile free_but_the_compiler_does_not_know)(void *) = mbedtls_free;
|
||||
|
||||
/* Set n bytes at the address p to all-bits-zero, in such a way that
|
||||
* the compiler should not know that p is all-bits-zero. */
|
||||
static void set_to_zero_but_the_compiler_does_not_know(volatile void *p, size_t n)
|
||||
@ -53,6 +62,15 @@ static void set_to_zero_but_the_compiler_does_not_know(volatile void *p, size_t
|
||||
memset((void *) p, false_but_the_compiler_does_not_know, n);
|
||||
}
|
||||
|
||||
/* Simulate an access to the given object, to avoid compiler optimizations
|
||||
* in code that prepares or consumes the object. */
|
||||
static void do_nothing_with_object(void *p)
|
||||
{
|
||||
(void) p;
|
||||
}
|
||||
void(*volatile do_nothing_with_object_but_the_compiler_does_not_know)(void *) =
|
||||
do_nothing_with_object;
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Test framework features */
|
||||
@ -98,9 +116,9 @@ void null_pointer_call(const char *name)
|
||||
void read_after_free(const char *name)
|
||||
{
|
||||
(void) name;
|
||||
volatile char *p = mbedtls_calloc(1, 1);
|
||||
volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
|
||||
*p = 'a';
|
||||
mbedtls_free((void *) p);
|
||||
free_but_the_compiler_does_not_know((void *) p);
|
||||
/* Undefined behavior (read after free) */
|
||||
mbedtls_printf("%u\n", (unsigned) *p);
|
||||
}
|
||||
@ -108,11 +126,11 @@ void read_after_free(const char *name)
|
||||
void double_free(const char *name)
|
||||
{
|
||||
(void) name;
|
||||
volatile char *p = mbedtls_calloc(1, 1);
|
||||
volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
|
||||
*p = 'a';
|
||||
mbedtls_free((void *) p);
|
||||
free_but_the_compiler_does_not_know((void *) p);
|
||||
/* Undefined behavior (double free) */
|
||||
mbedtls_free((void *) p);
|
||||
free_but_the_compiler_does_not_know((void *) p);
|
||||
}
|
||||
|
||||
void read_uninitialized_stack(const char *name)
|
||||
@ -132,11 +150,70 @@ void read_uninitialized_stack(const char *name)
|
||||
void memory_leak(const char *name)
|
||||
{
|
||||
(void) name;
|
||||
volatile char *p = mbedtls_calloc(1, 1);
|
||||
volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
|
||||
mbedtls_printf("%u\n", (unsigned) *p);
|
||||
/* Leak of a heap object */
|
||||
}
|
||||
|
||||
/* name = "test_memory_poison_%(start)_%(offset)_%(count)_%(direction)"
|
||||
* Poison a region starting at start from an 8-byte aligned origin,
|
||||
* encompassing count bytes. Access the region at offset from the start.
|
||||
* %(start), %(offset) and %(count) are decimal integers.
|
||||
* %(direction) is either the character 'r' for read or 'w' for write.
|
||||
*/
|
||||
void test_memory_poison(const char *name)
|
||||
{
|
||||
size_t start = 0, offset = 0, count = 0;
|
||||
char direction = 'r';
|
||||
if (sscanf(name,
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"_%c",
|
||||
&start, &offset, &count, &direction) != 4) {
|
||||
mbedtls_fprintf(stderr, "%s: Bad name format: %s\n", __func__, name);
|
||||
return;
|
||||
}
|
||||
|
||||
union {
|
||||
long long ll;
|
||||
unsigned char buf[32];
|
||||
} aligned;
|
||||
memset(aligned.buf, 'a', sizeof(aligned.buf));
|
||||
|
||||
if (start > sizeof(aligned.buf)) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: start=%" MBEDTLS_PRINTF_SIZET
|
||||
" > size=%" MBEDTLS_PRINTF_SIZET,
|
||||
__func__, start, sizeof(aligned.buf));
|
||||
return;
|
||||
}
|
||||
if (start + count > sizeof(aligned.buf)) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: start+count=%" MBEDTLS_PRINTF_SIZET
|
||||
" > size=%" MBEDTLS_PRINTF_SIZET,
|
||||
__func__, start + count, sizeof(aligned.buf));
|
||||
return;
|
||||
}
|
||||
if (offset >= count) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: offset=%" MBEDTLS_PRINTF_SIZET
|
||||
" >= count=%" MBEDTLS_PRINTF_SIZET,
|
||||
__func__, offset, count);
|
||||
return;
|
||||
}
|
||||
|
||||
MBEDTLS_TEST_MEMORY_POISON(aligned.buf + start, count);
|
||||
|
||||
if (direction == 'w') {
|
||||
aligned.buf[start + offset] = 'b';
|
||||
do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
|
||||
} else {
|
||||
do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
|
||||
mbedtls_printf("%u\n", (unsigned) aligned.buf[start + offset]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Threading */
|
||||
@ -285,6 +362,22 @@ metatest_t metatests[] = {
|
||||
{ "double_free", "asan", double_free },
|
||||
{ "read_uninitialized_stack", "msan", read_uninitialized_stack },
|
||||
{ "memory_leak", "asan", memory_leak },
|
||||
{ "test_memory_poison_0_0_8_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_0_8_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_7_8_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_7_8_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_0_1_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_0_1_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_1_2_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_0_1_2_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_0_8_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_0_8_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_7_8_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_7_8_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_0_1_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_0_1_w", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_1_2_r", "asan", test_memory_poison },
|
||||
{ "test_memory_poison_7_1_2_w", "asan", test_memory_poison },
|
||||
{ "mutex_lock_not_initialized", "pthread", mutex_lock_not_initialized },
|
||||
{ "mutex_unlock_not_initialized", "pthread", mutex_unlock_not_initialized },
|
||||
{ "mutex_free_not_initialized", "pthread", mutex_free_not_initialized },
|
||||
|
@ -18,3 +18,7 @@ mypy >= 0.780
|
||||
# for mypy and pylint under Python 3.5, and we also get something good enough
|
||||
# to run audit-validity-dates.py on Python >=3.6.
|
||||
cryptography # >= 35.0.0
|
||||
|
||||
# For building `tests/data_files/server9-bad-saltlen.crt` and check python
|
||||
# files.
|
||||
asn1crypto
|
||||
|
@ -180,6 +180,7 @@ EXCLUDE_FROM_FULL = frozenset([
|
||||
#pylint: disable=line-too-long
|
||||
'MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH', # interacts with CTR_DRBG_128_BIT_KEY
|
||||
'MBEDTLS_AES_USE_HARDWARE_ONLY', # hardware dependency
|
||||
'MBEDTLS_BLOCK_CIPHER_NO_DECRYPT', # incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES
|
||||
'MBEDTLS_CTR_DRBG_USE_128_BIT_KEY', # interacts with ENTROPY_FORCE_SHA256
|
||||
'MBEDTLS_DEPRECATED_REMOVED', # conflicts with deprecated options
|
||||
'MBEDTLS_DEPRECATED_WARNING', # conflicts with deprecated options
|
||||
|
@ -6,7 +6,8 @@
|
||||
#
|
||||
|
||||
import re
|
||||
from typing import Dict, FrozenSet, List, Optional
|
||||
from collections import OrderedDict
|
||||
from typing import FrozenSet, List, Optional
|
||||
|
||||
from . import macro_collector
|
||||
|
||||
@ -86,22 +87,31 @@ def automatic_dependencies(*expressions: str) -> List[str]:
|
||||
return sorted(psa_want_symbol(name) for name in used)
|
||||
|
||||
# Define set of regular expressions and dependencies to optionally append
|
||||
# extra dependencies for test case.
|
||||
AES_128BIT_ONLY_DEP_REGEX = r'AES\s(192|256)'
|
||||
AES_128BIT_ONLY_DEP = ["!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"]
|
||||
# extra dependencies for test case based on key description.
|
||||
|
||||
DEPENDENCY_FROM_KEY = {
|
||||
AES_128BIT_ONLY_DEP_REGEX: AES_128BIT_ONLY_DEP
|
||||
}#type: Dict[str, List[str]]
|
||||
def generate_key_dependencies(description: str) -> List[str]:
|
||||
"""Return additional dependencies based on pairs of REGEX and dependencies.
|
||||
# Skip AES test cases which require 192- or 256-bit key
|
||||
# if MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH defined
|
||||
AES_128BIT_ONLY_DEP_REGEX = re.compile(r'AES\s(192|256)')
|
||||
AES_128BIT_ONLY_DEP = ['!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH']
|
||||
# Skip AES/ARIA/CAMELLIA test cases which require decrypt operation in ECB mode
|
||||
# if MBEDTLS_BLOCK_CIPHER_NO_DECRYPT enabled.
|
||||
ECB_NO_PADDING_DEP_REGEX = re.compile(r'(AES|ARIA|CAMELLIA).*ECB_NO_PADDING')
|
||||
ECB_NO_PADDING_DEP = ['!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT']
|
||||
|
||||
DEPENDENCY_FROM_DESCRIPTION = OrderedDict()
|
||||
DEPENDENCY_FROM_DESCRIPTION[AES_128BIT_ONLY_DEP_REGEX] = AES_128BIT_ONLY_DEP
|
||||
DEPENDENCY_FROM_DESCRIPTION[ECB_NO_PADDING_DEP_REGEX] = ECB_NO_PADDING_DEP
|
||||
def generate_deps_from_description(
|
||||
description: str
|
||||
) -> List[str]:
|
||||
"""Return additional dependencies based on test case description and REGEX.
|
||||
"""
|
||||
deps = []
|
||||
for regex, dep in DEPENDENCY_FROM_KEY.items():
|
||||
dep_list = []
|
||||
for regex, deps in DEPENDENCY_FROM_DESCRIPTION.items():
|
||||
if re.search(regex, description):
|
||||
deps += dep
|
||||
dep_list += deps
|
||||
|
||||
return deps
|
||||
return dep_list
|
||||
|
||||
# A temporary hack: at the time of writing, not all dependency symbols
|
||||
# are implemented yet. Skip test cases for which the dependency symbols are
|
||||
|
@ -39,11 +39,11 @@ done
|
||||
GITIGNORES=$(find . -name ".gitignore")
|
||||
for GITIGNORE in $GITIGNORES; do
|
||||
if [ -n "$unrelease" ]; then
|
||||
sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^# //' $GITIGNORE
|
||||
sed -i '/###START_COMMENTED_GENERATED_FILES###/,/###END_COMMENTED_GENERATED_FILES###/s/^#//' $GITIGNORE
|
||||
sed -i 's/###START_COMMENTED_GENERATED_FILES###/###START_GENERATED_FILES###/' $GITIGNORE
|
||||
sed -i 's/###END_COMMENTED_GENERATED_FILES###/###END_GENERATED_FILES###/' $GITIGNORE
|
||||
else
|
||||
sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/# /' $GITIGNORE
|
||||
sed -i '/###START_GENERATED_FILES###/,/###END_GENERATED_FILES###/s/^/#/' $GITIGNORE
|
||||
sed -i 's/###START_GENERATED_FILES###/###START_COMMENTED_GENERATED_FILES###/' $GITIGNORE
|
||||
sed -i 's/###END_GENERATED_FILES###/###END_COMMENTED_GENERATED_FILES###/' $GITIGNORE
|
||||
fi
|
||||
|
@ -206,10 +206,8 @@ test-ca2.ku-%.crt: test-ca2.ku-%.crt.openssl.v3_ext $(test_ca_key_file_ec) test-
|
||||
$(OPENSSL) x509 -req -in test-ca2.req.sha256 -extfile $< \
|
||||
-signkey $(test_ca_key_file_ec) -days 3653 -out $@
|
||||
|
||||
all_final += test-ca2.ku-crl.crt \
|
||||
test-ca2.ku-crt.crt \
|
||||
test-ca2.ku-crt_crl.crt \
|
||||
test-ca2.ku-ds.crt
|
||||
all_final += test-ca2.ku-crl.crt test-ca2.ku-crt.crt test-ca2.ku-crt_crl.crt \
|
||||
test-ca2.ku-ds.crt
|
||||
|
||||
test-ca2-future.crt: $(test_ca_key_file_ec) test-ca2.req.sha256
|
||||
$(MBEDTLS_CERT_WRITE) is_ca=1 serial=13926223505202072808 request_file=test-ca2.req.sha256 selfsign=1 \
|
||||
@ -580,10 +578,6 @@ server9-with-ca.crt: server9.crt $(test_ca_crt)
|
||||
cat $^ > $@
|
||||
all_final += server9-with-ca.crt
|
||||
|
||||
# FIXME: This file needs special sequence. It should be update manually
|
||||
server9-bad-saltlen.crt: server9.csr $(test_ca_crt) $(test_ca_key_file_rsa)
|
||||
false
|
||||
|
||||
server9-bad-mgfhash.crt: server9.csr $(test_ca_crt) $(test_ca_key_file_rsa)
|
||||
$(OPENSSL) x509 -req -extfile $(cli_crt_extensions_file) -extensions cli-rsa \
|
||||
-passin "pass:$(test_ca_pwd_rsa)" -CA $(test_ca_crt) -CAkey $(test_ca_key_file_rsa) \
|
||||
@ -593,6 +587,16 @@ server9-bad-mgfhash.crt: server9.csr $(test_ca_crt) $(test_ca_key_file_rsa)
|
||||
-in $< -out $@
|
||||
all_final += server9-bad-mgfhash.crt
|
||||
|
||||
server9-bad-saltlen.crt: server9.csr $(test_ca_crt) $(test_ca_key_file_rsa) \
|
||||
opensslcnf/server9.crt.v3_ext \
|
||||
../scripts/generate_server9_bad_saltlen.py
|
||||
../scripts/generate_server9_bad_saltlen.py --ca-name test-ca \
|
||||
--ca-password $(test_ca_pwd_rsa) --csr server9.csr \
|
||||
--openssl-extfile opensslcnf/server9.crt.v3_ext \
|
||||
--anounce_saltlen 0xde --actual_saltlen 0x20 \
|
||||
--output $@
|
||||
all_final += server9-bad-saltlen.crt
|
||||
|
||||
# server10*
|
||||
|
||||
server10.crt: server10.key test-int-ca3.crt test-int-ca3.key
|
||||
@ -1545,9 +1549,9 @@ server6-ss-child.csr : server6.key
|
||||
all_intermediate += server6-ss-child.csr
|
||||
server6-ss-child.crt: server6-ss-child.csr server5-selfsigned.crt server5.key server6-ss-child.crt.openssl.v3_ext
|
||||
$(OPENSSL) x509 -req -CA server5-selfsigned.crt -CAkey server5.key \
|
||||
-extfile server6-ss-child.crt.openssl.v3_ext \
|
||||
-set_serial 0x53a2cb5822399474a7ec79ec \
|
||||
-days 3650 -sha256 -in $< -out $@
|
||||
-extfile server6-ss-child.crt.openssl.v3_ext \
|
||||
-set_serial 0x53a2cb5822399474a7ec79ec \
|
||||
-days 3650 -sha256 -in $< -out $@
|
||||
all_final += server6-ss-child.crt
|
||||
|
||||
|
||||
@ -1714,9 +1718,9 @@ crl.pem: $(test_ca_crt) $(test_ca_key_file_rsa) $(test_ca_config_file)
|
||||
$(OPENSSL) ca -gencrl -batch -cert $(test_ca_crt) -keyfile $(test_ca_key_file_rsa) -key $(test_ca_pwd_rsa) -config $(test_ca_server1_config_file) -md sha1 -crldays 3653 -out $@
|
||||
|
||||
crl-futureRevocationDate.pem: $(test_ca_crt) $(test_ca_key_file_rsa) \
|
||||
$(test_ca_config_file) \
|
||||
test-ca.server1.future-crl.db \
|
||||
test-ca.server1.future-crl.opensslconf
|
||||
$(test_ca_config_file) \
|
||||
test-ca.server1.future-crl.db \
|
||||
test-ca.server1.future-crl.opensslconf
|
||||
$(FAKETIME) -f '+10y' $(OPENSSL) ca -gencrl \
|
||||
-config test-ca.server1.future-crl.opensslconf -crldays 365 \
|
||||
-passin "pass:$(test_ca_pwd_rsa)" -out $@
|
||||
|
4
tests/data_files/opensslcnf/server9.crt.v3_ext
Normal file
4
tests/data_files/opensslcnf/server9.crt.v3_ext
Normal file
@ -0,0 +1,4 @@
|
||||
basicConstraints = CA:false
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid:always,issuer:always
|
||||
|
@ -537,6 +537,14 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_CCM_STAR_NO_TAG)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_CCM_STAR_NO_TAG)
|
||||
#undef MBEDTLS_PSA_ACCEL_ALG_CCM_STAR_NO_TAG
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_ALG_CCM_STAR_NO_TAG 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_CBC_MAC)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_CBC_MAC)
|
||||
#undef MBEDTLS_PSA_ACCEL_ALG_CBC_MAC
|
||||
|
@ -20,6 +20,21 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
#endif
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(address_sanitizer) /* clang -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
# endif
|
||||
# if __has_feature(memory_sanitizer) /* clang -fsanitize=memory */
|
||||
# define MBEDTLS_TEST_HAVE_MSAN
|
||||
# endif
|
||||
# if __has_feature(thread_sanitizer) /* clang -fsanitize=thread */
|
||||
# define MBEDTLS_TEST_HAVE_TSAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \
|
||||
defined(MBEDTLS_TEST_HOOKS)
|
||||
#define MBEDTLS_TEST_MUTEX_USAGE
|
||||
@ -240,10 +255,18 @@ int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b,
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
/** Permanently activate the mutex usage verification framework. See
|
||||
* threading_helpers.c for information. */
|
||||
/**
|
||||
* Activate the mutex usage verification framework. See threading_helpers.c for
|
||||
* information.
|
||||
* */
|
||||
void mbedtls_test_mutex_usage_init(void);
|
||||
|
||||
/**
|
||||
* Deactivate the mutex usage verification framework. See threading_helpers.c
|
||||
* for information.
|
||||
*/
|
||||
void mbedtls_test_mutex_usage_end(void);
|
||||
|
||||
/** Call this function after executing a test case to check for mutex usage
|
||||
* errors. */
|
||||
void mbedtls_test_mutex_usage_check(void);
|
||||
|
90
tests/include/test/memory.h
Normal file
90
tests/include/test/memory.h
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* \file memory.h
|
||||
*
|
||||
* \brief Helper macros and functions related to testing memory management.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef TEST_MEMORY_H
|
||||
#define TEST_MEMORY_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "mbedtls/platform.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
/** \def MBEDTLS_TEST_MEMORY_CAN_POISON
|
||||
*
|
||||
* This macro is defined if the tests are compiled with a method to mark
|
||||
* memory as poisoned, which can be used to enforce some memory access
|
||||
* policies.
|
||||
*
|
||||
* Currently, only Asan (Address Sanitizer) is supported.
|
||||
*/
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
# define MBEDTLS_TEST_MEMORY_CAN_POISON
|
||||
#endif
|
||||
|
||||
/** \def MBEDTLS_TEST_MEMORY_POISON(buf, size)
|
||||
*
|
||||
* Poison a memory area so that any attempt to read or write from it will
|
||||
* cause a runtime failure.
|
||||
*
|
||||
* Depending on the implementation, this may poison a few bytes beyond the
|
||||
* indicated region, but will never poison a separate object on the heap
|
||||
* or a separate object with more than the alignment of a long long.
|
||||
*
|
||||
* The behavior is undefined if any part of the memory area is invalid.
|
||||
*
|
||||
* This is a no-op in builds without a poisoning method.
|
||||
* See #MBEDTLS_TEST_MEMORY_CAN_POISON.
|
||||
*
|
||||
* \param buf Pointer to the beginning of the memory area to poison.
|
||||
* \param size Size of the memory area in bytes.
|
||||
*/
|
||||
|
||||
/** \def MBEDTLS_TEST_MEMORY_UNPOISON(buf, size)
|
||||
*
|
||||
* Undo the effect of #MBEDTLS_TEST_MEMORY_POISON.
|
||||
*
|
||||
* The behavior is undefined if any part of the memory area is invalid,
|
||||
* or if the memory area contains a mixture of poisoned and unpoisoned parts.
|
||||
*
|
||||
* This is a no-op in builds without a poisoning method.
|
||||
* See #MBEDTLS_TEST_MEMORY_CAN_POISON.
|
||||
*
|
||||
* \param buf Pointer to the beginning of the memory area to unpoison.
|
||||
* \param size Size of the memory area in bytes.
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
/** Poison a memory area so that any attempt to read or write from it will
|
||||
* cause a runtime failure.
|
||||
*
|
||||
* The behavior is undefined if any part of the memory area is invalid.
|
||||
*/
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \
|
||||
mbedtls_test_memory_poison(ptr, size)
|
||||
|
||||
/** Undo the effect of mbedtls_test_memory_poison().
|
||||
*
|
||||
* This is a no-op if the given area is entirely valid, unpoisoned memory.
|
||||
*
|
||||
* The behavior is undefined if any part of the memory area is invalid,
|
||||
* or if the memory area contains a mixture of poisoned and unpoisoned parts.
|
||||
*/
|
||||
void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \
|
||||
mbedtls_test_memory_unpoison(ptr, size)
|
||||
|
||||
#else /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) (ptr), (void) (size))
|
||||
#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) ((void) (ptr), (void) (size))
|
||||
#endif /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
|
||||
#endif /* TEST_MEMORY_H */
|
@ -46,12 +46,13 @@
|
||||
*
|
||||
* For simplicity's sake, stick to block ciphers with 16-byte blocks.
|
||||
*/
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER PSA_KEY_TYPE_AES
|
||||
#elif defined(MBEDTLS_ARIA_C)
|
||||
#elif defined(PSA_WANT_KEY_TYPE_ARIA)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER PSA_KEY_TYPE_ARIA
|
||||
#elif defined(MBEDTLS_CAMELLIA_C)
|
||||
#elif defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER PSA_KEY_TYPE_CAMELLIA
|
||||
#else
|
||||
#undef KNOWN_SUPPORTED_BLOCK_CIPHER
|
||||
#endif
|
||||
|
||||
@ -81,13 +82,13 @@
|
||||
*
|
||||
* This is used in some smoke tests.
|
||||
*/
|
||||
#if defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
#if defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(PSA_WANT_ALG_CTR)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER_ALG PSA_ALG_CTR
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER_ALG PSA_ALG_CBC_NO_PADDING
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(PSA_WANT_ALG_CFB)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER_ALG PSA_ALG_CFB
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(MBEDTLS_CIPHER_MODE_OFB)
|
||||
#elif defined(KNOWN_SUPPORTED_BLOCK_CIPHER) && defined(PSA_WANT_ALG_OFB)
|
||||
#define KNOWN_SUPPORTED_BLOCK_CIPHER_ALG PSA_ALG_OFB
|
||||
#else
|
||||
#undef KNOWN_SUPPORTED_BLOCK_CIPHER_ALG
|
||||
|
@ -86,7 +86,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, ticket authentication failed
|
||||
-S "key exchange mode: psk$" \
|
||||
-s "ticket is not authentic" \
|
||||
-S "ticket is expired" \
|
||||
-S "Invalid ticket start time" \
|
||||
-S "Invalid ticket creation time" \
|
||||
-S "Ticket age exceeds limitation" \
|
||||
-S "Ticket age outside tolerance window"
|
||||
|
||||
@ -105,7 +105,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, ticket expired." \
|
||||
-S "key exchange mode: psk$" \
|
||||
-S "ticket is not authentic" \
|
||||
-s "ticket is expired" \
|
||||
-S "Invalid ticket start time" \
|
||||
-S "Invalid ticket creation time" \
|
||||
-S "Ticket age exceeds limitation" \
|
||||
-S "Ticket age outside tolerance window"
|
||||
|
||||
@ -124,7 +124,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, invalid start time." \
|
||||
-S "key exchange mode: psk$" \
|
||||
-S "ticket is not authentic" \
|
||||
-S "ticket is expired" \
|
||||
-s "Invalid ticket start time" \
|
||||
-s "Invalid ticket creation time" \
|
||||
-S "Ticket age exceeds limitation" \
|
||||
-S "Ticket age outside tolerance window"
|
||||
|
||||
@ -143,7 +143,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, ticket expired. too old" \
|
||||
-S "key exchange mode: psk$" \
|
||||
-S "ticket is not authentic" \
|
||||
-S "ticket is expired" \
|
||||
-S "Invalid ticket start time" \
|
||||
-S "Invalid ticket creation time" \
|
||||
-s "Ticket age exceeds limitation" \
|
||||
-S "Ticket age outside tolerance window"
|
||||
|
||||
@ -162,7 +162,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, age outside tolerance window
|
||||
-S "key exchange mode: psk$" \
|
||||
-S "ticket is not authentic" \
|
||||
-S "ticket is expired" \
|
||||
-S "Invalid ticket start time" \
|
||||
-S "Invalid ticket creation time" \
|
||||
-S "Ticket age exceeds limitation" \
|
||||
-s "Ticket age outside tolerance window"
|
||||
|
||||
@ -181,7 +181,7 @@ run_test "TLS 1.3 m->m: Session resumption failure, age outside tolerance window
|
||||
-S "key exchange mode: psk$" \
|
||||
-S "ticket is not authentic" \
|
||||
-S "ticket is expired" \
|
||||
-S "Invalid ticket start time" \
|
||||
-S "Invalid ticket creation time" \
|
||||
-S "Ticket age exceeds limitation" \
|
||||
-s "Ticket age outside tolerance window"
|
||||
|
||||
|
@ -163,6 +163,9 @@ pre_initialize_variables () {
|
||||
# basic-build-test.sh as well.
|
||||
RELEASE_SEED=1
|
||||
|
||||
# Specify character collation for regular expressions and sorting with C locale
|
||||
export LC_COLLATE=C
|
||||
|
||||
: ${MBEDTLS_TEST_OUTCOME_FILE=}
|
||||
: ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
|
||||
export MBEDTLS_TEST_OUTCOME_FILE
|
||||
@ -397,13 +400,12 @@ armc6_build_test()
|
||||
FLAGS="$1"
|
||||
|
||||
msg "build: ARM Compiler 6 ($FLAGS)"
|
||||
make clean
|
||||
ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
|
||||
WARNING_CFLAGS='-Werror -xc -std=c99' make lib
|
||||
|
||||
msg "size: ARM Compiler 6 ($FLAGS)"
|
||||
"$ARMC6_FROMELF" -z library/*.o
|
||||
|
||||
make clean
|
||||
}
|
||||
|
||||
err_msg()
|
||||
@ -1044,13 +1046,15 @@ component_check_test_dependencies () {
|
||||
grep 'depends_on' \
|
||||
tests/suites/test_suite_psa*.data tests/suites/test_suite_psa*.function |
|
||||
grep -Eo '!?MBEDTLS_[^: ]*' |
|
||||
grep -v MBEDTLS_PSA_ |
|
||||
grep -v -e MBEDTLS_PSA_ -e MBEDTLS_TEST_ |
|
||||
sort -u > $found
|
||||
|
||||
# Expected ones with justification - keep in sorted order!
|
||||
# Expected ones with justification - keep in sorted order by ASCII table!
|
||||
rm -f $expected
|
||||
# No PSA equivalent - WANT_KEY_TYPE_AES means all sizes
|
||||
echo "!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" >> $expected
|
||||
# No PSA equivalent - used to skip decryption tests in PSA-ECB, CBC/XTS/NIST_KW/DES
|
||||
echo "!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT" >> $expected
|
||||
# This is used by import_rsa_made_up() in test_suite_psa_crypto in order
|
||||
# to build a fake RSA key of the wanted size based on
|
||||
# PSA_VENDOR_RSA_MAX_KEY_BITS. The legacy module is only used by
|
||||
@ -1541,9 +1545,7 @@ component_test_full_no_cipher () {
|
||||
# (currently ignored anyway because we completely disable PSA)
|
||||
scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
|
||||
# Disable features that depend on CIPHER_C
|
||||
scripts/config.py unset MBEDTLS_CCM_C
|
||||
scripts/config.py unset MBEDTLS_CMAC_C
|
||||
scripts/config.py unset MBEDTLS_GCM_C
|
||||
scripts/config.py unset MBEDTLS_NIST_KW_C
|
||||
scripts/config.py unset MBEDTLS_PKCS12_C
|
||||
scripts/config.py unset MBEDTLS_PKCS5_C
|
||||
@ -1556,7 +1558,6 @@ component_test_full_no_cipher () {
|
||||
scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
|
||||
scripts/config.py unset MBEDTLS_LMS_C
|
||||
scripts/config.py unset MBEDTLS_LMS_PRIVATE
|
||||
make CFLAGS='-DMBEDTLS_BLOCK_CIPHER_C'
|
||||
|
||||
msg "test: full no CIPHER no PSA_CRYPTO_C"
|
||||
make test
|
||||
@ -1582,9 +1583,7 @@ common_test_full_no_cipher_with_psa_crypto () {
|
||||
# on CIPHER_C so we disable them.
|
||||
# This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
|
||||
# so we keep them enabled.
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
|
||||
@ -1593,27 +1592,19 @@ common_test_full_no_cipher_with_psa_crypto () {
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_AES
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_CAMELLIA
|
||||
scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ARIA
|
||||
else
|
||||
# Don't pull in cipher via PSA mechanisms
|
||||
scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
|
||||
# Disable cipher modes/keys that make PSA depend on CIPHER_C.
|
||||
# Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
|
||||
scripts/config.py unset-all MBEDTLS_CIPHER_MODE
|
||||
scripts/config.py unset MBEDTLS_AES_C
|
||||
scripts/config.py unset MBEDTLS_DES_C
|
||||
scripts/config.py unset MBEDTLS_ARIA_C
|
||||
scripts/config.py unset MBEDTLS_CAMELLIA_C
|
||||
# Dependencies on AES_C
|
||||
scripts/config.py unset MBEDTLS_CTR_DRBG_C
|
||||
fi
|
||||
# The following modules directly depends on CIPHER_C
|
||||
scripts/config.py unset MBEDTLS_CCM_C
|
||||
scripts/config.py unset MBEDTLS_CMAC_C
|
||||
scripts/config.py unset MBEDTLS_GCM_C
|
||||
scripts/config.py unset MBEDTLS_NIST_KW_C
|
||||
scripts/config.py unset MBEDTLS_PKCS12_C
|
||||
scripts/config.py unset MBEDTLS_PKCS5_C
|
||||
@ -1635,6 +1626,59 @@ component_test_full_no_cipher_with_crypto_config() {
|
||||
common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
|
||||
}
|
||||
|
||||
component_test_full_no_ccm() {
|
||||
msg "build: full no PSA_WANT_ALG_CCM"
|
||||
|
||||
# Full config enables:
|
||||
# - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
|
||||
# - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
|
||||
scripts/config.py full
|
||||
|
||||
# Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
|
||||
# enabled, but not used from TLS since USE_PSA is set.
|
||||
# This is helpful to ensure that TLS tests below have proper dependencies.
|
||||
#
|
||||
# Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
|
||||
# PSA_WANT_ALG_CCM to be re-enabled.
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
|
||||
|
||||
make
|
||||
|
||||
msg "test: full no PSA_WANT_ALG_CCM"
|
||||
make test
|
||||
}
|
||||
|
||||
component_test_full_no_ccm_star_no_tag() {
|
||||
msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
|
||||
|
||||
# Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
|
||||
scripts/config.py full
|
||||
|
||||
# Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
|
||||
# other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
|
||||
# This basically disables all unauthenticated ciphers on the PSA side, while
|
||||
# keeping AEADs enabled.
|
||||
#
|
||||
# Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
|
||||
# PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
|
||||
|
||||
make
|
||||
|
||||
# Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
|
||||
not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
|
||||
|
||||
msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
|
||||
make test
|
||||
}
|
||||
|
||||
component_test_full_no_bignum () {
|
||||
msg "build: full minus bignum"
|
||||
scripts/config.py full
|
||||
@ -3649,6 +3693,9 @@ component_test_psa_crypto_config_accel_aead () {
|
||||
scripts/config.py unset MBEDTLS_CCM_C
|
||||
scripts/config.py unset MBEDTLS_CHACHAPOLY_C
|
||||
|
||||
# Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
|
||||
|
||||
# Build
|
||||
# -----
|
||||
|
||||
@ -3694,7 +3741,7 @@ component_test_psa_crypto_config_accel_cipher_aead () {
|
||||
msg "build: full config with accelerated cipher and AEAD"
|
||||
|
||||
loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
|
||||
ALG_OFB ALG_XTS ALG_STREAM_CIPHER \
|
||||
ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
|
||||
ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
|
||||
KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
|
||||
|
||||
@ -4057,8 +4104,7 @@ component_build_psa_accel_key_type_rsa_public_key() {
|
||||
|
||||
|
||||
support_build_tfm_armcc () {
|
||||
armc6_cc="$ARMC6_BIN_DIR/armclang"
|
||||
(check_tools "$armc6_cc" > /dev/null 2>&1)
|
||||
support_build_armcc
|
||||
}
|
||||
|
||||
component_build_tfm_armcc() {
|
||||
@ -4067,7 +4113,6 @@ component_build_tfm_armcc() {
|
||||
cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
|
||||
|
||||
msg "build: TF-M config, armclang armv7-m thumb2"
|
||||
make clean
|
||||
armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
|
||||
}
|
||||
|
||||
@ -4182,6 +4227,7 @@ component_build_aes_variations() {
|
||||
# aes.o has many #if defined(...) guards that intersect in complex ways.
|
||||
# Test that all the combinations build cleanly.
|
||||
|
||||
MBEDTLS_ROOT_DIR="$PWD"
|
||||
msg "build: aes.o for all combinations of relevant config options"
|
||||
|
||||
build_test_config_combos library/aes.o validate_aes_config_variations \
|
||||
@ -4189,6 +4235,23 @@ component_build_aes_variations() {
|
||||
"MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
|
||||
"MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
|
||||
"MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
|
||||
|
||||
cd "$MBEDTLS_ROOT_DIR"
|
||||
msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
|
||||
|
||||
# MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
|
||||
# manually set or unset those configurations to check
|
||||
# MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
|
||||
scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
|
||||
scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
|
||||
scripts/config.py unset MBEDTLS_DES_C
|
||||
scripts/config.py unset MBEDTLS_NIST_KW_C
|
||||
build_test_config_combos library/aes.o validate_aes_config_variations \
|
||||
"MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
|
||||
"MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
|
||||
"MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
|
||||
"MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
|
||||
}
|
||||
|
||||
component_test_no_platform () {
|
||||
@ -4589,6 +4652,63 @@ component_build_aes_aesce_armcc () {
|
||||
armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
|
||||
}
|
||||
|
||||
support_build_aes_armce() {
|
||||
# clang >= 4 is required to build with AES extensions
|
||||
ver="$(clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#')"
|
||||
[ "${ver}" -ge 11 ]
|
||||
}
|
||||
|
||||
component_build_aes_armce () {
|
||||
# Test variations of AES with Armv8 crypto extensions
|
||||
scripts/config.py set MBEDTLS_AESCE_C
|
||||
scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
|
||||
|
||||
msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
|
||||
|
||||
msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
|
||||
|
||||
msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
|
||||
|
||||
scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
|
||||
|
||||
msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
|
||||
|
||||
msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
|
||||
|
||||
msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
|
||||
|
||||
# test for presence of AES instructions
|
||||
scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
|
||||
msg "clang, test A32 crypto instructions built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
|
||||
grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
|
||||
msg "clang, test T32 crypto instructions built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
|
||||
grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
|
||||
msg "clang, test aarch64 crypto instructions built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
|
||||
grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
|
||||
|
||||
# test for absence of AES instructions
|
||||
scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
|
||||
scripts/config.py unset MBEDTLS_AESCE_C
|
||||
msg "clang, test A32 crypto instructions not built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
|
||||
not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
|
||||
msg "clang, test T32 crypto instructions not built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
|
||||
not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
|
||||
msg "clang, test aarch64 crypto instructions not built"
|
||||
make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
|
||||
not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
|
||||
}
|
||||
|
||||
support_build_sha_armce() {
|
||||
if command -v clang > /dev/null ; then
|
||||
# clang >= 4 is required to build with SHA extensions
|
||||
@ -4756,6 +4876,158 @@ component_test_aes_fewer_tables_and_rom_tables () {
|
||||
make test
|
||||
}
|
||||
|
||||
# helper for common_block_cipher_no_decrypt() which:
|
||||
# - enable/disable the list of config options passed from -s/-u respectively.
|
||||
# - build
|
||||
# - test for tests_suite_xxx
|
||||
# - selftest
|
||||
#
|
||||
# Usage: helper_block_cipher_no_decrypt_build_test
|
||||
# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
|
||||
# Options: -s set_opts the list of config options to enable
|
||||
# -u unset_opts the list of config options to disable
|
||||
# -c cflags the list of options passed to CFLAGS
|
||||
# -l ldflags the list of options passed to LDFLAGS
|
||||
helper_block_cipher_no_decrypt_build_test () {
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-s)
|
||||
shift; local set_opts="$1";;
|
||||
-u)
|
||||
shift; local unset_opts="$1";;
|
||||
-c)
|
||||
shift; local cflags="-Werror -Wall -Wextra $1";;
|
||||
-l)
|
||||
shift; local ldflags="$1";;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
set_opts="${set_opts:-}"
|
||||
unset_opts="${unset_opts:-}"
|
||||
cflags="${cflags:-}"
|
||||
ldflags="${ldflags:-}"
|
||||
|
||||
[ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
|
||||
[ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
|
||||
|
||||
msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
|
||||
make clean
|
||||
make CC=gcc CFLAGS="$cflags" LDFLAGS="$ldflags"
|
||||
|
||||
# Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
|
||||
not grep mbedtls_aes_setkey_dec library/aes.o
|
||||
not grep mbedtls_aria_setkey_dec library/aria.o
|
||||
not grep mbedtls_camellia_setkey_dec library/camellia.o
|
||||
# Make sure we don't have mbedtls_internal_aes_decrypt in AES
|
||||
not grep mbedtls_internal_aes_decrypt library/aes.o
|
||||
# Make sure we don't have mbedtls_aesni_inverse_key in AESNI
|
||||
not grep mbedtls_aesni_inverse_key library/aesni.o
|
||||
|
||||
msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
|
||||
make test
|
||||
|
||||
msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
|
||||
programs/test/selftest
|
||||
}
|
||||
|
||||
# This is a common configuration function used in:
|
||||
# - component_test_block_cipher_no_decrypt_aesni_legacy()
|
||||
# - component_test_block_cipher_no_decrypt_aesni_use_psa()
|
||||
# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
|
||||
# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
|
||||
# on x86.
|
||||
common_block_cipher_no_decrypt () {
|
||||
# test AESNI intrinsics
|
||||
helper_block_cipher_no_decrypt_build_test \
|
||||
-s "MBEDTLS_AESNI_C" \
|
||||
-c "-mpclmul -msse2 -maes"
|
||||
|
||||
# test AESNI assembly
|
||||
helper_block_cipher_no_decrypt_build_test \
|
||||
-s "MBEDTLS_AESNI_C" \
|
||||
-c "-mno-pclmul -mno-sse2 -mno-aes"
|
||||
|
||||
# test AES C implementation
|
||||
helper_block_cipher_no_decrypt_build_test \
|
||||
-u "MBEDTLS_AESNI_C"
|
||||
|
||||
# test AESNI intrinsics for i386 target
|
||||
helper_block_cipher_no_decrypt_build_test \
|
||||
-s "MBEDTLS_AESNI_C" \
|
||||
-c "-m32 -mpclmul -msse2 -maes" \
|
||||
-l "-m32"
|
||||
}
|
||||
|
||||
# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
|
||||
# usage: 0: no PSA crypto configuration
|
||||
# 1: use PSA crypto configuration
|
||||
config_block_cipher_no_decrypt () {
|
||||
use_psa=$1
|
||||
|
||||
scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
|
||||
scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
|
||||
scripts/config.py unset MBEDTLS_DES_C
|
||||
scripts/config.py unset MBEDTLS_NIST_KW_C
|
||||
|
||||
if [ "$use_psa" -eq 1 ]; then
|
||||
# Enable support for cryptographic mechanisms through the PSA API.
|
||||
# Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
|
||||
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||
scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
|
||||
fi
|
||||
}
|
||||
|
||||
component_test_block_cipher_no_decrypt_aesni () {
|
||||
config_block_cipher_no_decrypt 0
|
||||
common_block_cipher_no_decrypt
|
||||
}
|
||||
|
||||
component_test_block_cipher_no_decrypt_aesni_use_psa () {
|
||||
config_block_cipher_no_decrypt 1
|
||||
common_block_cipher_no_decrypt
|
||||
}
|
||||
|
||||
support_test_block_cipher_no_decrypt_aesce_armcc () {
|
||||
support_build_armcc
|
||||
}
|
||||
|
||||
component_test_block_cipher_no_decrypt_aesce_armcc () {
|
||||
scripts/config.py baremetal
|
||||
|
||||
# armc[56] don't support SHA-512 intrinsics
|
||||
scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
|
||||
|
||||
# Stop armclang warning about feature detection for A64_CRYPTO.
|
||||
# With this enabled, the library does build correctly under armclang,
|
||||
# but in baremetal builds (as tested here), feature detection is
|
||||
# unavailable, and the user is notified via a #warning. So enabling
|
||||
# this feature would prevent us from building with -Werror on
|
||||
# armclang. Tracked in #7198.
|
||||
scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
|
||||
scripts/config.py set MBEDTLS_HAVE_ASM
|
||||
|
||||
config_block_cipher_no_decrypt 1
|
||||
|
||||
# test AESCE baremetal build
|
||||
scripts/config.py set MBEDTLS_AESCE_C
|
||||
msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
|
||||
armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
|
||||
|
||||
# Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
|
||||
not grep mbedtls_aes_setkey_dec library/aes.o
|
||||
not grep mbedtls_aria_setkey_dec library/aria.o
|
||||
not grep mbedtls_camellia_setkey_dec library/camellia.o
|
||||
# Make sure we don't have mbedtls_internal_aes_decrypt in AES
|
||||
not grep mbedtls_internal_aes_decrypt library/aes.o
|
||||
# Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
|
||||
not grep mbedtls_aesce_inverse_key library/aesce.o
|
||||
not grep aesce_decrypt_block library/aesce.o
|
||||
}
|
||||
|
||||
component_test_ctr_drbg_aes_256_sha_256 () {
|
||||
msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
|
||||
scripts/config.py full
|
||||
@ -5210,6 +5482,9 @@ component_build_armcc () {
|
||||
# armc[56] don't support SHA-512 intrinsics
|
||||
scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
|
||||
|
||||
# older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
|
||||
scripts/config.py unset MBEDTLS_AESCE_C
|
||||
|
||||
# Stop armclang warning about feature detection for A64_CRYPTO.
|
||||
# With this enabled, the library does build correctly under armclang,
|
||||
# but in baremetal builds (as tested here), feature detection is
|
||||
@ -5225,8 +5500,6 @@ component_build_armcc () {
|
||||
msg "size: ARM Compiler 5"
|
||||
"$ARMC5_FROMELF" -z library/*.o
|
||||
|
||||
make clean
|
||||
|
||||
# Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
|
||||
|
||||
# ARM Compiler 6 - Target ARMv7-A
|
||||
@ -5244,14 +5517,18 @@ component_build_armcc () {
|
||||
# ARM Compiler 6 - Target ARMv8-M
|
||||
armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
|
||||
|
||||
# ARM Compiler 6 - Target ARMv8.2-A - AArch64
|
||||
armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
|
||||
|
||||
# ARM Compiler 6 - Target Cortex-M0 - no optimisation
|
||||
armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
|
||||
|
||||
# ARM Compiler 6 - Target Cortex-M0
|
||||
armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
|
||||
|
||||
# ARM Compiler 6 - Target ARMv8.2-A - AArch64
|
||||
#
|
||||
# Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
|
||||
# that we have in our CI
|
||||
scripts/config.py set MBEDTLS_AESCE_C
|
||||
armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
|
||||
}
|
||||
|
||||
support_build_armcc () {
|
||||
|
@ -12,9 +12,36 @@ import traceback
|
||||
import re
|
||||
import subprocess
|
||||
import os
|
||||
import typing
|
||||
|
||||
import check_test_cases
|
||||
|
||||
|
||||
# `ComponentOutcomes` is a named tuple which is defined as:
|
||||
# ComponentOutcomes(
|
||||
# successes = {
|
||||
# "<suite_case>",
|
||||
# ...
|
||||
# },
|
||||
# failures = {
|
||||
# "<suite_case>",
|
||||
# ...
|
||||
# }
|
||||
# )
|
||||
# suite_case = "<suite>;<case>"
|
||||
ComponentOutcomes = typing.NamedTuple('ComponentOutcomes',
|
||||
[('successes', typing.Set[str]),
|
||||
('failures', typing.Set[str])])
|
||||
|
||||
# `Outcomes` is a representation of the outcomes file,
|
||||
# which defined as:
|
||||
# Outcomes = {
|
||||
# "<component>": ComponentOutcomes,
|
||||
# ...
|
||||
# }
|
||||
Outcomes = typing.Dict[str, ComponentOutcomes]
|
||||
|
||||
|
||||
class Results:
|
||||
"""Process analysis results."""
|
||||
|
||||
@ -40,35 +67,12 @@ class Results:
|
||||
def _print_line(fmt, *args, **kwargs):
|
||||
sys.stderr.write((fmt + '\n').format(*args, **kwargs))
|
||||
|
||||
class TestCaseOutcomes:
|
||||
"""The outcomes of one test case across many configurations."""
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
def __init__(self):
|
||||
# Collect a list of witnesses of the test case succeeding or failing.
|
||||
# Currently we don't do anything with witnesses except count them.
|
||||
# The format of a witness is determined by the read_outcome_file
|
||||
# function; it's the platform and configuration joined by ';'.
|
||||
self.successes = []
|
||||
self.failures = []
|
||||
|
||||
def hits(self):
|
||||
"""Return the number of times a test case has been run.
|
||||
|
||||
This includes passes and failures, but not skips.
|
||||
"""
|
||||
return len(self.successes) + len(self.failures)
|
||||
|
||||
def execute_reference_driver_tests(results: Results, ref_component, driver_component, \
|
||||
outcome_file):
|
||||
def execute_reference_driver_tests(results: Results, ref_component: str, driver_component: str, \
|
||||
outcome_file: str) -> None:
|
||||
"""Run the tests specified in ref_component and driver_component. Results
|
||||
are stored in the output_file and they will be used for the following
|
||||
coverage analysis"""
|
||||
# If the outcome file already exists, we assume that the user wants to
|
||||
# perform the comparison analysis again without repeating the tests.
|
||||
if os.path.exists(outcome_file):
|
||||
results.info("Outcome file ({}) already exists. Tests will be skipped.", outcome_file)
|
||||
return
|
||||
results.new_section("Test {} and {}", ref_component, driver_component)
|
||||
|
||||
shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
|
||||
" " + ref_component + " " + driver_component
|
||||
@ -78,24 +82,28 @@ def execute_reference_driver_tests(results: Results, ref_component, driver_compo
|
||||
if ret_val != 0:
|
||||
results.error("failed to run reference/driver components")
|
||||
|
||||
def analyze_coverage(results, outcomes, allow_list, full_coverage):
|
||||
def analyze_coverage(results: Results, outcomes: Outcomes,
|
||||
allow_list: typing.List[str], full_coverage: bool) -> None:
|
||||
"""Check that all available test cases are executed at least once."""
|
||||
available = check_test_cases.collect_available_test_cases()
|
||||
for key in available:
|
||||
hits = outcomes[key].hits() if key in outcomes else 0
|
||||
if hits == 0 and key not in allow_list:
|
||||
for suite_case in available:
|
||||
hit = any(suite_case in comp_outcomes.successes or
|
||||
suite_case in comp_outcomes.failures
|
||||
for comp_outcomes in outcomes.values())
|
||||
|
||||
if not hit and suite_case not in allow_list:
|
||||
if full_coverage:
|
||||
results.error('Test case not executed: {}', key)
|
||||
results.error('Test case not executed: {}', suite_case)
|
||||
else:
|
||||
results.warning('Test case not executed: {}', key)
|
||||
elif hits != 0 and key in allow_list:
|
||||
results.warning('Test case not executed: {}', suite_case)
|
||||
elif hit and suite_case in allow_list:
|
||||
# Test Case should be removed from the allow list.
|
||||
if full_coverage:
|
||||
results.error('Allow listed test case was executed: {}', key)
|
||||
results.error('Allow listed test case was executed: {}', suite_case)
|
||||
else:
|
||||
results.warning('Allow listed test case was executed: {}', key)
|
||||
results.warning('Allow listed test case was executed: {}', suite_case)
|
||||
|
||||
def name_matches_pattern(name, str_or_re):
|
||||
def name_matches_pattern(name: str, str_or_re) -> bool:
|
||||
"""Check if name matches a pattern, that may be a string or regex.
|
||||
- If the pattern is a string, name must be equal to match.
|
||||
- If the pattern is a regex, name must fully match.
|
||||
@ -103,24 +111,34 @@ def name_matches_pattern(name, str_or_re):
|
||||
# The CI's python is too old for re.Pattern
|
||||
#if isinstance(str_or_re, re.Pattern):
|
||||
if not isinstance(str_or_re, str):
|
||||
return str_or_re.fullmatch(name)
|
||||
return str_or_re.fullmatch(name) is not None
|
||||
else:
|
||||
return str_or_re == name
|
||||
|
||||
def analyze_driver_vs_reference(results: Results, outcomes,
|
||||
component_ref, component_driver,
|
||||
ignored_suites, ignored_tests=None):
|
||||
"""Check that all tests executed in the reference component are also
|
||||
executed in the corresponding driver component.
|
||||
def analyze_driver_vs_reference(results: Results, outcomes: Outcomes,
|
||||
component_ref: str, component_driver: str,
|
||||
ignored_suites: typing.List[str], ignored_tests=None) -> None:
|
||||
"""Check that all tests passing in the reference component are also
|
||||
passing in the corresponding driver component.
|
||||
Skip:
|
||||
- full test suites provided in ignored_suites list
|
||||
- only some specific test inside a test suite, for which the corresponding
|
||||
output string is provided
|
||||
"""
|
||||
seen_reference_passing = False
|
||||
for key in outcomes:
|
||||
# key is like "test_suite_foo.bar;Description of test case"
|
||||
(full_test_suite, test_string) = key.split(';')
|
||||
ref_outcomes = outcomes.get("component_" + component_ref)
|
||||
driver_outcomes = outcomes.get("component_" + component_driver)
|
||||
|
||||
if ref_outcomes is None or driver_outcomes is None:
|
||||
results.error("required components are missing: bad outcome file?")
|
||||
return
|
||||
|
||||
if not ref_outcomes.successes:
|
||||
results.error("no passing test in reference component: bad outcome file?")
|
||||
return
|
||||
|
||||
for suite_case in ref_outcomes.successes:
|
||||
# suite_case is like "test_suite_foo.bar;Description of test case"
|
||||
(full_test_suite, test_string) = suite_case.split(';')
|
||||
test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
|
||||
|
||||
# Immediately skip fully-ignored test suites
|
||||
@ -136,67 +154,48 @@ def analyze_driver_vs_reference(results: Results, outcomes,
|
||||
if name_matches_pattern(test_string, str_or_re):
|
||||
ignored = True
|
||||
|
||||
# Search for tests that run in reference component and not in driver component
|
||||
driver_test_passed = False
|
||||
reference_test_passed = False
|
||||
for entry in outcomes[key].successes:
|
||||
if component_driver in entry:
|
||||
driver_test_passed = True
|
||||
if component_ref in entry:
|
||||
reference_test_passed = True
|
||||
seen_reference_passing = True
|
||||
if reference_test_passed and not driver_test_passed and not ignored:
|
||||
results.error("PASS -> SKIP/FAIL: {}", key)
|
||||
if ignored and driver_test_passed:
|
||||
results.error("uselessly ignored: {}", key)
|
||||
if not ignored and not suite_case in driver_outcomes.successes:
|
||||
results.error("PASS -> SKIP/FAIL: {}", suite_case)
|
||||
if ignored and suite_case in driver_outcomes.successes:
|
||||
results.error("uselessly ignored: {}", suite_case)
|
||||
|
||||
if not seen_reference_passing:
|
||||
results.error("no passing test in reference component: bad outcome file?")
|
||||
|
||||
def analyze_outcomes(results: Results, outcomes, args):
|
||||
def analyze_outcomes(results: Results, outcomes: Outcomes, args) -> None:
|
||||
"""Run all analyses on the given outcome collection."""
|
||||
analyze_coverage(results, outcomes, args['allow_list'],
|
||||
args['full_coverage'])
|
||||
|
||||
def read_outcome_file(outcome_file):
|
||||
def read_outcome_file(outcome_file: str) -> Outcomes:
|
||||
"""Parse an outcome file and return an outcome collection.
|
||||
|
||||
An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
|
||||
The keys are the test suite name and the test case description, separated
|
||||
by a semicolon.
|
||||
"""
|
||||
"""
|
||||
outcomes = {}
|
||||
with open(outcome_file, 'r', encoding='utf-8') as input_file:
|
||||
for line in input_file:
|
||||
(platform, config, suite, case, result, _cause) = line.split(';')
|
||||
key = ';'.join([suite, case])
|
||||
setup = ';'.join([platform, config])
|
||||
if key not in outcomes:
|
||||
outcomes[key] = TestCaseOutcomes()
|
||||
(_platform, component, suite, case, result, _cause) = line.split(';')
|
||||
# Note that `component` is not unique. If a test case passes on Linux
|
||||
# and fails on FreeBSD, it'll end up in both the successes set and
|
||||
# the failures set.
|
||||
suite_case = ';'.join([suite, case])
|
||||
if component not in outcomes:
|
||||
outcomes[component] = ComponentOutcomes(set(), set())
|
||||
if result == 'PASS':
|
||||
outcomes[key].successes.append(setup)
|
||||
outcomes[component].successes.add(suite_case)
|
||||
elif result == 'FAIL':
|
||||
outcomes[key].failures.append(setup)
|
||||
outcomes[component].failures.add(suite_case)
|
||||
|
||||
return outcomes
|
||||
|
||||
def do_analyze_coverage(results: Results, outcome_file, args):
|
||||
def do_analyze_coverage(results: Results, outcomes: Outcomes, args) -> None:
|
||||
"""Perform coverage analysis."""
|
||||
results.new_section("Analyze coverage")
|
||||
outcomes = read_outcome_file(outcome_file)
|
||||
analyze_outcomes(results, outcomes, args)
|
||||
|
||||
def do_analyze_driver_vs_reference(results: Results, outcome_file, args):
|
||||
def do_analyze_driver_vs_reference(results: Results, outcomes: Outcomes, args) -> None:
|
||||
"""Perform driver vs reference analyze."""
|
||||
results.new_section("Analyze driver {} vs reference {}",
|
||||
args['component_driver'], args['component_ref'])
|
||||
|
||||
execute_reference_driver_tests(results, args['component_ref'], \
|
||||
args['component_driver'], outcome_file)
|
||||
|
||||
ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
|
||||
|
||||
outcomes = read_outcome_file(outcome_file)
|
||||
|
||||
analyze_driver_vs_reference(results, outcomes,
|
||||
args['component_ref'], args['component_driver'],
|
||||
ignored_suites, args['ignored_tests'])
|
||||
@ -232,6 +231,12 @@ KNOWN_TASKS = {
|
||||
'psa_crypto_low_hash.generated', # testing the builtins
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -255,6 +260,12 @@ KNOWN_TASKS = {
|
||||
'test_suite_pem': [
|
||||
re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
|
||||
],
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# Following tests depend on AES_C/DES_C but are not about
|
||||
# them really, just need to know some error code is there.
|
||||
'test_suite_error': [
|
||||
@ -282,7 +293,7 @@ KNOWN_TASKS = {
|
||||
'test_suite_pkparse': [
|
||||
'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
|
||||
'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
|
||||
re.compile(r'Parse RSA Key .*\(PKCS#8 encrypted .*\)'),
|
||||
re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
|
||||
],
|
||||
}
|
||||
}
|
||||
@ -297,6 +308,12 @@ KNOWN_TASKS = {
|
||||
'ecdsa', 'ecdh', 'ecjpake',
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# This test wants a legacy function that takes f_rng, p_rng
|
||||
# arguments, and uses legacy ECDSA for that. The test is
|
||||
# really about the wrapper around the PSA RNG, not ECDSA.
|
||||
@ -330,6 +347,12 @@ KNOWN_TASKS = {
|
||||
'ecp', 'ecdsa', 'ecdh', 'ecjpake',
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# See ecp_light_only
|
||||
'test_suite_random': [
|
||||
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
||||
@ -363,6 +386,12 @@ KNOWN_TASKS = {
|
||||
'bignum.generated', 'bignum.misc',
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# See ecp_light_only
|
||||
'test_suite_random': [
|
||||
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
||||
@ -400,6 +429,12 @@ KNOWN_TASKS = {
|
||||
'bignum.generated', 'bignum.misc',
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# See ecp_light_only
|
||||
'test_suite_random': [
|
||||
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
||||
@ -431,7 +466,14 @@ KNOWN_TASKS = {
|
||||
'component_ref': 'test_psa_crypto_config_reference_ffdh',
|
||||
'component_driver': 'test_psa_crypto_config_accel_ffdh',
|
||||
'ignored_suites': ['dhm'],
|
||||
'ignored_tests': {}
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
}
|
||||
}
|
||||
},
|
||||
'analyze_driver_vs_reference_tfm_config': {
|
||||
@ -447,6 +489,12 @@ KNOWN_TASKS = {
|
||||
'bignum.generated', 'bignum.misc',
|
||||
],
|
||||
'ignored_tests': {
|
||||
'test_suite_platform': [
|
||||
# Incompatible with sanitizers (e.g. ASan). If the driver
|
||||
# component uses a sanitizer but the reference component
|
||||
# doesn't, we have a PASS vs SKIP mismatch.
|
||||
'Check mbedtls_calloc overallocation',
|
||||
],
|
||||
# See ecp_light_only
|
||||
'test_suite_random': [
|
||||
'PSA classic wrapper: ECDSA signature (SECP256R1)',
|
||||
@ -493,10 +541,31 @@ def main():
|
||||
|
||||
KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
|
||||
|
||||
# If the outcome file exists, parse it once and share the result
|
||||
# among tasks to improve performance.
|
||||
# Otherwise, it will be generated by execute_reference_driver_tests.
|
||||
if not os.path.exists(options.outcomes):
|
||||
if len(tasks_list) > 1:
|
||||
sys.stderr.write("mutiple tasks found, please provide a valid outcomes file.\n")
|
||||
sys.exit(2)
|
||||
|
||||
task_name = tasks_list[0]
|
||||
task = KNOWN_TASKS[task_name]
|
||||
if task['test_function'] != do_analyze_driver_vs_reference: # pylint: disable=comparison-with-callable
|
||||
sys.stderr.write("please provide valid outcomes file for {}.\n".format(task_name))
|
||||
sys.exit(2)
|
||||
|
||||
execute_reference_driver_tests(main_results,
|
||||
task['args']['component_ref'],
|
||||
task['args']['component_driver'],
|
||||
options.outcomes)
|
||||
|
||||
outcomes = read_outcome_file(options.outcomes)
|
||||
|
||||
for task in tasks_list:
|
||||
test_function = KNOWN_TASKS[task]['test_function']
|
||||
test_args = KNOWN_TASKS[task]['args']
|
||||
test_function(main_results, options.outcomes, test_args)
|
||||
test_function(main_results, outcomes, test_args)
|
||||
|
||||
main_results.info("Overall results: {} warnings and {} errors",
|
||||
main_results.warning_count, main_results.error_count)
|
||||
|
@ -496,7 +496,7 @@ class StorageFormat:
|
||||
key.alg.string, key.alg2.string,
|
||||
)
|
||||
dependencies = psa_information.finish_family_dependencies(dependencies, key.bits)
|
||||
dependencies += psa_information.generate_key_dependencies(key.description)
|
||||
dependencies += psa_information.generate_deps_from_description(key.description)
|
||||
dependencies = psa_information.fix_key_pair_dependencies(dependencies, 'BASIC')
|
||||
tc.set_dependencies(dependencies)
|
||||
tc.set_function('key_storage_' + verb)
|
||||
|
87
tests/scripts/generate_server9_bad_saltlen.py
Executable file
87
tests/scripts/generate_server9_bad_saltlen.py
Executable file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate server9-bad-saltlen.crt
|
||||
|
||||
Generate a certificate signed with RSA-PSS, with an incorrect salt length.
|
||||
"""
|
||||
|
||||
# Copyright The Mbed TLS Contributors
|
||||
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
|
||||
import subprocess
|
||||
import argparse
|
||||
from asn1crypto import pem, x509, core #type: ignore #pylint: disable=import-error
|
||||
|
||||
OPENSSL_RSA_PSS_CERT_COMMAND = r'''
|
||||
openssl x509 -req -CA {ca_name}.crt -CAkey {ca_name}.key -set_serial 24 {ca_password} \
|
||||
{openssl_extfile} -days 3650 -outform DER -in {csr} \
|
||||
-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:{anounce_saltlen} \
|
||||
-sigopt rsa_mgf1_md:sha256
|
||||
'''
|
||||
SIG_OPT = \
|
||||
r'-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:{saltlen} -sigopt rsa_mgf1_md:sha256'
|
||||
OPENSSL_RSA_PSS_DGST_COMMAND = r'''openssl dgst -sign {ca_name}.key {ca_password} \
|
||||
-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:{actual_saltlen} \
|
||||
-sigopt rsa_mgf1_md:sha256'''
|
||||
|
||||
|
||||
def auto_int(x):
|
||||
return int(x, 0)
|
||||
|
||||
|
||||
def build_argparser(parser):
|
||||
"""Build argument parser"""
|
||||
parser.description = __doc__
|
||||
parser.add_argument('--ca-name', type=str, required=True,
|
||||
help='Basename of CA files')
|
||||
parser.add_argument('--ca-password', type=str,
|
||||
required=True, help='CA key file password')
|
||||
parser.add_argument('--csr', type=str, required=True,
|
||||
help='CSR file for generating certificate')
|
||||
parser.add_argument('--openssl-extfile', type=str,
|
||||
required=True, help='X905 v3 extension config file')
|
||||
parser.add_argument('--anounce_saltlen', type=auto_int,
|
||||
required=True, help='Announced salt length')
|
||||
parser.add_argument('--actual_saltlen', type=auto_int,
|
||||
required=True, help='Actual salt length')
|
||||
parser.add_argument('--output', type=str, required=True)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
build_argparser(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
return generate(**vars(args))
|
||||
|
||||
def generate(**kwargs):
|
||||
"""Generate different salt length certificate file."""
|
||||
ca_password = kwargs.get('ca_password', '')
|
||||
if ca_password:
|
||||
kwargs['ca_password'] = r'-passin "pass:{ca_password}"'.format(
|
||||
**kwargs)
|
||||
else:
|
||||
kwargs['ca_password'] = ''
|
||||
extfile = kwargs.get('openssl_extfile', '')
|
||||
if extfile:
|
||||
kwargs['openssl_extfile'] = '-extfile {openssl_extfile}'.format(
|
||||
**kwargs)
|
||||
else:
|
||||
kwargs['openssl_extfile'] = ''
|
||||
|
||||
cmd = OPENSSL_RSA_PSS_CERT_COMMAND.format(**kwargs)
|
||||
der_bytes = subprocess.check_output(cmd, shell=True)
|
||||
target_certificate = x509.Certificate.load(der_bytes)
|
||||
|
||||
cmd = OPENSSL_RSA_PSS_DGST_COMMAND.format(**kwargs)
|
||||
#pylint: disable=unexpected-keyword-arg
|
||||
der_bytes = subprocess.check_output(cmd,
|
||||
input=target_certificate['tbs_certificate'].dump(),
|
||||
shell=True)
|
||||
|
||||
with open(kwargs.get('output'), 'wb') as f:
|
||||
target_certificate['signature_value'] = core.OctetBitString(der_bytes)
|
||||
f.write(pem.armor('CERTIFICATE', target_certificate.dump()))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1633,6 +1633,7 @@ exit:
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session,
|
||||
int ticket_len,
|
||||
const char *crt_file)
|
||||
@ -1729,6 +1730,7 @@ int mbedtls_test_ssl_tls12_populate_session(mbedtls_ssl_session *session,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session,
|
||||
@ -1750,16 +1752,16 @@ int mbedtls_test_ssl_tls13_populate_session(mbedtls_ssl_session *session,
|
||||
session->max_early_data_size = 0x87654321;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_SRV_C)
|
||||
if (session->endpoint == MBEDTLS_SSL_IS_SERVER) {
|
||||
session->start = mbedtls_time(NULL) - 42;
|
||||
session->ticket_creation_time = mbedtls_ms_time() - 42;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
if (session->endpoint == MBEDTLS_SSL_IS_CLIENT) {
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
session->ticket_received = mbedtls_time(NULL) - 40;
|
||||
session->ticket_reception_time = mbedtls_ms_time() - 40;
|
||||
#endif
|
||||
session->ticket_lifetime = 0xfedcba98;
|
||||
|
||||
|
54
tests/src/test_memory.c
Normal file
54
tests/src/test_memory.c
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* \file memory.c
|
||||
*
|
||||
* \brief Helper functions related to testing memory management.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <test/helpers.h>
|
||||
#include <test/macros.h>
|
||||
#include <test/memory.h>
|
||||
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
#include <sanitizer/asan_interface.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
static void align_for_asan(const unsigned char **p_ptr, size_t *p_size)
|
||||
{
|
||||
uintptr_t start = (uintptr_t) *p_ptr;
|
||||
uintptr_t end = start + (uintptr_t) *p_size;
|
||||
/* ASan can only poison regions with 8-byte alignment, and only poisons a
|
||||
* region if it's fully within the requested range. We want to poison the
|
||||
* whole requested region and don't mind a few extra bytes. Therefore,
|
||||
* align start down to an 8-byte boundary, and end up to an 8-byte
|
||||
* boundary. */
|
||||
start = start & ~(uintptr_t) 7;
|
||||
end = (end + 7) & ~(uintptr_t) 7;
|
||||
*p_ptr = (const unsigned char *) start;
|
||||
*p_size = end - start;
|
||||
}
|
||||
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
align_for_asan(&ptr, &size);
|
||||
__asan_poison_memory_region(ptr, size);
|
||||
}
|
||||
|
||||
void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
align_for_asan(&ptr, &size);
|
||||
__asan_unpoison_memory_region(ptr, size);
|
||||
}
|
||||
#endif /* Asan */
|
@ -58,15 +58,15 @@
|
||||
* indicate the exact location of the problematic call. To locate the error,
|
||||
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
|
||||
*/
|
||||
enum value_of_mutex_is_valid_field {
|
||||
/* Potential values for the is_valid field of mbedtls_threading_mutex_t.
|
||||
enum value_of_mutex_state_field {
|
||||
/* Potential values for the state field of mbedtls_threading_mutex_t.
|
||||
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
|
||||
* compatibility with threading_mutex_init_pthread() and
|
||||
* threading_mutex_free_pthread(). MUTEX_LOCKED could be any nonzero
|
||||
* value. */
|
||||
MUTEX_FREED = 0, //!< Set by threading_mutex_free_pthread
|
||||
MUTEX_IDLE = 1, //!< Set by threading_mutex_init_pthread and by our unlock
|
||||
MUTEX_LOCKED = 2, //!< Set by our lock
|
||||
MUTEX_FREED = 0, //! < Set by mbedtls_test_wrap_mutex_free
|
||||
MUTEX_IDLE = 1, //! < Set by mbedtls_test_wrap_mutex_init and by mbedtls_test_wrap_mutex_unlock
|
||||
MUTEX_LOCKED = 2, //! < Set by mbedtls_test_wrap_mutex_lock
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -77,10 +77,30 @@ typedef struct {
|
||||
} mutex_functions_t;
|
||||
static mutex_functions_t mutex_functions;
|
||||
|
||||
/** The total number of calls to mbedtls_mutex_init(), minus the total number
|
||||
* of calls to mbedtls_mutex_free().
|
||||
/**
|
||||
* The mutex used to guard live_mutexes below and access to the status variable
|
||||
* in every mbedtls_threading_mutex_t.
|
||||
* Note that we are not reporting any errors when locking and unlocking this
|
||||
* mutex. This is for a couple of reasons:
|
||||
*
|
||||
* Reset to 0 after each test case.
|
||||
* 1. We have no real way of reporting any errors with this mutex - we cannot
|
||||
* report it back to the caller, as the failure was not that of the mutex
|
||||
* passed in. We could fail the test, but again this would indicate a problem
|
||||
* with the test code that did not exist.
|
||||
*
|
||||
* 2. Any failure to lock is unlikely to be intermittent, and will thus not
|
||||
* give false test results - the overall result would be to turn off the
|
||||
* testing. This is not a situation that is likely to happen with normal
|
||||
* testing and we still have TSan to fall back on should this happen.
|
||||
*/
|
||||
mbedtls_threading_mutex_t mbedtls_test_mutex_mutex;
|
||||
|
||||
/**
|
||||
* The total number of calls to mbedtls_mutex_init(), minus the total number
|
||||
* of calls to mbedtls_mutex_free().
|
||||
*
|
||||
* Do not read or write without holding mbedtls_test_mutex_mutex (above). Reset
|
||||
* to 0 after each test case.
|
||||
*/
|
||||
static int live_mutexes;
|
||||
|
||||
@ -88,6 +108,7 @@ static void mbedtls_test_mutex_usage_error(mbedtls_threading_mutex_t *mutex,
|
||||
const char *msg)
|
||||
{
|
||||
(void) mutex;
|
||||
|
||||
if (mbedtls_test_info.mutex_usage_error == NULL) {
|
||||
mbedtls_test_info.mutex_usage_error = msg;
|
||||
}
|
||||
@ -101,76 +122,92 @@ static void mbedtls_test_mutex_usage_error(mbedtls_threading_mutex_t *mutex,
|
||||
static void mbedtls_test_wrap_mutex_init(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
mutex_functions.init(mutex);
|
||||
if (mutex->is_valid) {
|
||||
|
||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||
mutex->state = MUTEX_IDLE;
|
||||
++live_mutexes;
|
||||
|
||||
mutex_functions.unlock(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static void mbedtls_test_wrap_mutex_free(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
/* Do nothing. The underlying free function will reset is_valid
|
||||
* to 0. */
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without unlock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
if (mutex->is_valid) {
|
||||
--live_mutexes;
|
||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||
|
||||
switch (mutex->state) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
mutex->state = MUTEX_FREED;
|
||||
--live_mutexes;
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without unlock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
|
||||
mutex_functions.unlock(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
mutex_functions.free(mutex);
|
||||
}
|
||||
|
||||
static int mbedtls_test_wrap_mutex_lock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
/* Lock the passed in mutex first, so that the only way to change the state
|
||||
* is to hold the passed in and internal mutex - otherwise we create a race
|
||||
* condition. */
|
||||
int ret = mutex_functions.lock(mutex);
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "lock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
if (ret == 0) {
|
||||
mutex->is_valid = 2;
|
||||
}
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "double lock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||
switch (mutex->state) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "lock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
if (ret == 0) {
|
||||
mutex->state = MUTEX_LOCKED;
|
||||
}
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "double lock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
|
||||
mutex_functions.unlock(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mbedtls_test_wrap_mutex_unlock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
int ret = mutex_functions.unlock(mutex);
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
if (ret == 0) {
|
||||
mutex->is_valid = MUTEX_IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
/* Lock the internal mutex first and change state, so that the only way to
|
||||
* change the state is to hold the passed in and internal mutex - otherwise
|
||||
* we create a race condition. */
|
||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||
switch (mutex->state) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mutex->state = MUTEX_IDLE;
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
mutex_functions.unlock(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
return ret;
|
||||
return mutex_functions.unlock(mutex);
|
||||
}
|
||||
|
||||
void mbedtls_test_mutex_usage_init(void)
|
||||
@ -183,6 +220,8 @@ void mbedtls_test_mutex_usage_init(void)
|
||||
mbedtls_mutex_free = &mbedtls_test_wrap_mutex_free;
|
||||
mbedtls_mutex_lock = &mbedtls_test_wrap_mutex_lock;
|
||||
mbedtls_mutex_unlock = &mbedtls_test_wrap_mutex_unlock;
|
||||
|
||||
mutex_functions.init(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
|
||||
void mbedtls_test_mutex_usage_check(void)
|
||||
@ -207,4 +246,14 @@ void mbedtls_test_mutex_usage_check(void)
|
||||
mbedtls_test_info.mutex_usage_error = NULL;
|
||||
}
|
||||
|
||||
void mbedtls_test_mutex_usage_end(void)
|
||||
{
|
||||
mbedtls_mutex_init = mutex_functions.init;
|
||||
mbedtls_mutex_free = mutex_functions.free;
|
||||
mbedtls_mutex_lock = mutex_functions.lock;
|
||||
mbedtls_mutex_unlock = mutex_functions.unlock;
|
||||
|
||||
mutex_functions.free(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
||||
|
@ -240,28 +240,28 @@ requires_config_disabled() {
|
||||
}
|
||||
|
||||
requires_all_configs_enabled() {
|
||||
if ! $P_QUERY -all $*
|
||||
if ! $P_QUERY -all $* 2>&1 > /dev/null
|
||||
then
|
||||
SKIP_NEXT="YES"
|
||||
fi
|
||||
}
|
||||
|
||||
requires_all_configs_disabled() {
|
||||
if $P_QUERY -any $*
|
||||
if $P_QUERY -any $* 2>&1 > /dev/null
|
||||
then
|
||||
SKIP_NEXT="YES"
|
||||
fi
|
||||
}
|
||||
|
||||
requires_any_configs_enabled() {
|
||||
if ! $P_QUERY -any $*
|
||||
if ! $P_QUERY -any $* 2>&1 > /dev/null
|
||||
then
|
||||
SKIP_NEXT="YES"
|
||||
fi
|
||||
}
|
||||
|
||||
requires_any_configs_disabled() {
|
||||
if $P_QUERY -all $*
|
||||
if $P_QUERY -all $* 2>&1 > /dev/null
|
||||
then
|
||||
SKIP_NEXT="YES"
|
||||
fi
|
||||
@ -358,9 +358,18 @@ requires_protocol_version() {
|
||||
|
||||
# Space-separated list of ciphersuites supported by this build of
|
||||
# Mbed TLS.
|
||||
P_CIPHERSUITES=" $($P_CLI --help 2>/dev/null |
|
||||
grep 'TLS-\|TLS1-3' |
|
||||
tr -s ' \n' ' ')"
|
||||
P_CIPHERSUITES=""
|
||||
if [ "$LIST_TESTS" -eq 0 ]; then
|
||||
P_CIPHERSUITES=" $($P_CLI help_ciphersuites 2>/dev/null |
|
||||
grep 'TLS-\|TLS1-3' |
|
||||
tr -s ' \n' ' ')"
|
||||
|
||||
if [ -z "${P_CIPHERSUITES# }" ]; then
|
||||
echo >&2 "$0: fatal error: no cipher suites found!"
|
||||
exit 125
|
||||
fi
|
||||
fi
|
||||
|
||||
requires_ciphersuite_enabled() {
|
||||
case $P_CIPHERSUITES in
|
||||
*" $1 "*) :;;
|
||||
@ -2332,7 +2341,6 @@ run_test "Opaque key for server authentication: invalid alg: ecdh with RSA ke
|
||||
requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
|
||||
requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_CCM_C
|
||||
run_test "Opaque key for server authentication: invalid alg: ECDHE-ECDSA with ecdh" \
|
||||
"$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
|
||||
key_file=data_files/server5.key key_opaque_algs=ecdh,none \
|
||||
@ -2386,7 +2394,6 @@ run_test "Opaque keys for server authentication: EC keys with different algs,
|
||||
requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
|
||||
requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
|
||||
requires_hash_alg SHA_384
|
||||
requires_config_enabled MBEDTLS_CCM_C
|
||||
requires_config_disabled MBEDTLS_X509_REMOVE_INFO
|
||||
run_test "Opaque keys for server authentication: EC + RSA, force ECDHE-ECDSA" \
|
||||
"$P_SRV key_opaque=1 crt_file=data_files/server5.crt \
|
||||
@ -2566,7 +2573,6 @@ requires_config_enabled MBEDTLS_USE_PSA_CRYPTO
|
||||
requires_config_enabled MBEDTLS_X509_CRT_PARSE_C
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_384
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_config_disabled MBEDTLS_X509_REMOVE_INFO
|
||||
run_test "Opaque keys for server authentication: EC + RSA, force DHE-RSA" \
|
||||
"$P_SRV auth_mode=required key_opaque=1 crt_file=data_files/server5.crt \
|
||||
@ -9115,8 +9121,6 @@ run_test "SSL async private: renegotiation: server-initiated, decrypt" \
|
||||
|
||||
# Tests for ECC extensions (rfc 4492)
|
||||
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
run_test "Force a non ECC ciphersuite in the client side" \
|
||||
@ -9128,8 +9132,6 @@ run_test "Force a non ECC ciphersuite in the client side" \
|
||||
-S "found supported elliptic curves extension" \
|
||||
-S "found supported point formats extension"
|
||||
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
run_test "Force a non ECC ciphersuite in the server side" \
|
||||
@ -9139,8 +9141,6 @@ run_test "Force a non ECC ciphersuite in the server side" \
|
||||
-C "found supported_point_formats extension" \
|
||||
-S "server hello, supported_point_formats extension"
|
||||
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_hash_alg SHA_256
|
||||
run_test "Force an ECC ciphersuite in the client side" \
|
||||
"$P_SRV debug_level=3" \
|
||||
@ -9151,8 +9151,6 @@ run_test "Force an ECC ciphersuite in the client side" \
|
||||
-s "found supported elliptic curves extension" \
|
||||
-s "found supported point formats extension"
|
||||
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_hash_alg SHA_256
|
||||
run_test "Force an ECC ciphersuite in the server side" \
|
||||
"$P_SRV debug_level=3 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256" \
|
||||
@ -9677,8 +9675,6 @@ run_test "DTLS fragmenting: both (MTU=1024)" \
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: both (MTU=512)" \
|
||||
-p "$P_PXY mtu=512" \
|
||||
@ -9707,8 +9703,6 @@ run_test "DTLS fragmenting: both (MTU=512)" \
|
||||
not_with_valgrind
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU: auto-reduction (not valgrind)" \
|
||||
-p "$P_PXY mtu=508" \
|
||||
@ -9730,8 +9724,6 @@ run_test "DTLS fragmenting: proxy MTU: auto-reduction (not valgrind)" \
|
||||
only_with_valgrind
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)" \
|
||||
-p "$P_PXY mtu=508" \
|
||||
@ -9782,8 +9774,6 @@ run_test "DTLS fragmenting: proxy MTU, simple handshake (MTU=1024)" \
|
||||
not_with_valgrind # spurious autoreduction due to timeout
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, simple handshake (MTU=512)" \
|
||||
-p "$P_PXY mtu=512" \
|
||||
@ -9831,8 +9821,6 @@ run_test "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=1024)" \
|
||||
not_with_valgrind # spurious autoreduction due to timeout
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=512)" \
|
||||
-p "$P_PXY mtu=512" \
|
||||
@ -9866,8 +9854,6 @@ run_test "DTLS fragmenting: proxy MTU, simple handshake, nbio (MTU=512)" \
|
||||
not_with_valgrind # spurious autoreduction due to timeout
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, resumed handshake" \
|
||||
-p "$P_PXY mtu=1450" \
|
||||
@ -9895,7 +9881,6 @@ requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
|
||||
requires_config_enabled MBEDTLS_CHACHAPOLY_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
|
||||
-p "$P_PXY mtu=512" \
|
||||
@ -9909,7 +9894,7 @@ run_test "DTLS fragmenting: proxy MTU, ChachaPoly renego" \
|
||||
crt_file=data_files/server8_int-ca2.crt \
|
||||
key_file=data_files/server8.key \
|
||||
exchanges=2 renegotiation=1 renegotiate=1 \
|
||||
force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256 \
|
||||
force_ciphersuite=TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256 \
|
||||
hs_timeout=10000-60000 \
|
||||
mtu=512" \
|
||||
0 \
|
||||
@ -9925,8 +9910,6 @@ requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, AES-GCM renego" \
|
||||
-p "$P_PXY mtu=512" \
|
||||
@ -9956,8 +9939,6 @@ requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CCM_C
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, AES-CCM renego" \
|
||||
-p "$P_PXY mtu=1024" \
|
||||
@ -9987,8 +9968,6 @@ requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_config_enabled MBEDTLS_SSL_ENCRYPT_THEN_MAC
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, AES-CBC EtM renego" \
|
||||
@ -10019,8 +9998,6 @@ requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_hash_alg SHA_256
|
||||
requires_config_enabled MBEDTLS_SSL_RENEGOTIATION
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_CIPHER_MODE_CBC
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
|
||||
-p "$P_PXY mtu=1024" \
|
||||
@ -10046,8 +10023,6 @@ run_test "DTLS fragmenting: proxy MTU, AES-CBC non-EtM renego" \
|
||||
# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
client_needs_more_time 2
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU + 3d" \
|
||||
@ -10069,8 +10044,6 @@ run_test "DTLS fragmenting: proxy MTU + 3d" \
|
||||
# Forcing ciphersuite for this test to fit the MTU of 512 with full config.
|
||||
requires_config_enabled MBEDTLS_SSL_PROTO_DTLS
|
||||
requires_config_enabled MBEDTLS_RSA_C
|
||||
requires_config_enabled MBEDTLS_AES_C
|
||||
requires_config_enabled MBEDTLS_GCM_C
|
||||
client_needs_more_time 2
|
||||
requires_max_content_len 2048
|
||||
run_test "DTLS fragmenting: proxy MTU + 3d, nbio" \
|
||||
|
@ -772,6 +772,10 @@ int execute_tests(int argc, const char **argv)
|
||||
mbedtls_fprintf(stdout, " (%u / %u tests (%u skipped))\n",
|
||||
total_tests - total_errors, total_tests, total_skipped);
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
mbedtls_test_mutex_usage_end();
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
|
@ -6,6 +6,7 @@
|
||||
* master, enc and dec must be AES context objects. They don't need to
|
||||
* be initialized, and are left freed.
|
||||
*/
|
||||
#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
|
||||
static int test_copy(const data_t *key,
|
||||
mbedtls_aes_context *master,
|
||||
mbedtls_aes_context *enc,
|
||||
@ -55,6 +56,7 @@ exit:
|
||||
* with alternative implementations. */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
@ -86,7 +88,7 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
/* BEGIN_CASE depends_on:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
void aes_decrypt_ecb(data_t *key_str, data_t *src_str,
|
||||
data_t *dst, int setkey_result)
|
||||
{
|
||||
@ -523,7 +525,7 @@ void aes_misc_params()
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
/* BEGIN_CASE depends_on:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
void aes_ecb_copy_context(data_t *key)
|
||||
{
|
||||
/* We test context copying multiple times, with different alignments
|
||||
|
@ -86,7 +86,7 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
/* BEGIN_CASE depends_on:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
void aria_decrypt_ecb(data_t *key_str, data_t *src_str,
|
||||
data_t *expected_output, int setkey_result)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
/* BEGIN_CASE depends_on:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
||||
void camellia_decrypt_ecb(data_t *key_str, data_t *src_str,
|
||||
data_t *dst, int setkey_result)
|
||||
{
|
||||
|
@ -1595,47 +1595,47 @@ depends_on:MBEDTLS_AES_C
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_ENCRYPT:"00000000000000000000000000000000":"fffffffffffffffffffffffff8000000":"2ca8209d63274cd9a29bb74bcd77683a":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"db4f1aa530967d6732ce4715eb0ee24b":"ff000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"a81738252621dd180a34f3455b4baa2f":"ff800000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"77e2b508db7fd89234caf7939ee5621a":"ffc00000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #4
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"dc43be40be0e53712f7e2bf5ca707209":"6a118a874519e64e9963798a503f1d35":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #5
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"92beedab1895a94faa69b632e5cc47ce":"cb9fceec81286ca3e989bd979b0cb284":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #6
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"459264f4798f6a78bacb89c15ed3d601":"b26aeb1874e47ca8358ff22378f09144":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #7
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"b69418a85332240dc82492353956ae0c":"a303d940ded8f0baff6f75414cac5243":"00000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #8
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"71b5c08a1993e1362e4d0ce9b22b78d5":"c2dabd117f8a3ecabfbb11d12194d9d0":"00000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #9
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"e234cdca2606b81f29408d5f6da21206":"fff60a4740086b3b9c56195b98d91a7b":"00000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #10
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"ffffffffffffffff0000000000000000":"84be19e053635f09f2665e7bae85b42d":"00000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB Decrypt NIST KAT #11
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"ffffffffffffffff8000000000000000":"32cd652842926aea4aa6137bb2be2b5e":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Encrypt NIST KAT #1
|
||||
@ -1687,51 +1687,51 @@ depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_ENCRYPT:"fffffffffffffffffffffffffffe00000000000000000000":"00000000000000000000000000000000":"fd5548bcf3f42565f7efa94562528d46":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffff000000000000000":"bb2852c891c5947d2ed44032c421b85f":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffff800000000000000":"1b9f5fbd5e8a4264c0a85b80409afa5e":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffffc00000000000000":"30dab809f85a917fe924733f424ac589":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #4
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"61257134a518a0d57d9d244d45f6498cbc32f2bafc522d79":"cfe4d74002696ccf7d87b14a2f9cafc9":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #5
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"b0ab0a6a818baef2d11fa33eac947284fb7d748cfb75e570":"d2eafd86f63b109b91f5dbb3a3fb7e13":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #6
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"ee053aa011c8b428cdcc3636313c54d6a03cac01c71579d6":"9b9fdd1c5975655f539998b306a324af":"00000000000000000000000000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #7
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"275cfc0413d8ccb70513c3859b1d0f72":"1b077a6af4b7f98229de786d7516b639":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #8
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"c9b8135ff1b5adc413dfd053b21bd96d":"9c2d8842e5f48f57648205d39a239af1":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #9
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"4a3650c3371ce2eb35e389a171427440":"bff52510095f518ecca60af4205444bb":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #10
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"b2099795e88cc158fd75ea133d7e7fbe":"ffffffffffffffffffffc00000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #11
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"a6cae46fb6fadfe7a2c302a34242817b":"ffffffffffffffffffffe00000000000":0
|
||||
|
||||
AES-192-ECB Decrypt NIST KAT #12
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"026a7024d6a902e0b3ffccbaa910cc3f":"fffffffffffffffffffff00000000000":0
|
||||
|
||||
AES-256-ECB Encrypt NIST KAT #1
|
||||
@ -1783,51 +1783,51 @@ depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_ENCRYPT:"ffffffffffffffffffffffffffffffffffffe000000000000000000000000000":"00000000000000000000000000000000":"dcf4e129136c1a4b7a0f38935cc34b2b":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffffffffffffffffff00000000000000000":"edf61ae362e882ddc0167474a7a77f3a":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffffffffffffffffff80000000000000000":"6168b00ba7859e0970ecfd757efecf7c":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffffffffffffffffffc0000000000000000":"d1415447866230d28bb1ea18a4cdfd02":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #4
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"f8be9ba615c5a952cabbca24f68f8593039624d524c816acda2c9183bd917cb9":"a3944b95ca0b52043584ef02151926a8":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #5
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"797f8b3d176dac5b7e34a2d539c4ef367a16f8635f6264737591c5c07bf57a3e":"a74289fe73a4c123ca189ea1e1b49ad5":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #6
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"6838d40caf927749c13f0329d331f448e202c73ef52c5f73a37ca635d4c47707":"b91d4ea4488644b56cf0812fa7fcf5fc":"00000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #7
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"623a52fcea5d443e48d9181ab32c7421":"761c1fe41a18acf20d241650611d90f1":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #8
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"38f2c7ae10612415d27ca190d27da8b4":"8a560769d605868ad80d819bdba03771":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #9
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"1bc704f1bce135ceb810341b216d7abe":"91fbef2d15a97816060bee1feaa49afe":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #10
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"ddc6bf790c15760d8d9aeb6f9a75fd4e":"80000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #11
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"0a6bdc6d4c1e6280301fd8e97ddbe601":"c0000000000000000000000000000000":0
|
||||
|
||||
AES-256-ECB Decrypt NIST KAT #12
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_ecb:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"9b80eefb7ebe2d2b16247aa0efc72f5d":"e0000000000000000000000000000000":0
|
||||
|
||||
AES-128-ECB crypt Encrypt NIST KAT #1
|
||||
@ -1843,15 +1843,15 @@ depends_on:MBEDTLS_AES_C
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_ENCRYPT:"00000000000000000000000000000000":"":"ffffffffffffffc00000000000000000":"3a4d354f02bb5a5e47d39666867f246a":0:0
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"":"db4f1aa530967d6732ce4715eb0ee24b":"ff000000000000000000000000000000":0:0
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"b69418a85332240dc82492353956ae0c":"":"a303d940ded8f0baff6f75414cac5243":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"ffffffffffffffff8000000000000000":"":"32cd652842926aea4aa6137bb2be2b5e":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-192-ECB crypt Encrypt NIST KAT #1
|
||||
@ -1871,19 +1871,19 @@ depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_ENCRYPT:"fffffffffffffffffffffffffff800000000000000000000":"":"00000000000000000000000000000000":"8dd274bd0f1b58ae345d9e7233f9b8f3":0:0
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffff000000000000000":"":"bb2852c891c5947d2ed44032c421b85f":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"61257134a518a0d57d9d244d45f6498cbc32f2bafc522d79":"":"cfe4d74002696ccf7d87b14a2f9cafc9":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"":"275cfc0413d8ccb70513c3859b1d0f72":"1b077a6af4b7f98229de786d7516b639":0:0
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #4
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"":"b2099795e88cc158fd75ea133d7e7fbe":"ffffffffffffffffffffc00000000000":0:0
|
||||
|
||||
AES-256-ECB crypt Encrypt NIST KAT #1
|
||||
@ -1903,19 +1903,19 @@ depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_ENCRYPT:"ffffffffffffffffffffffffffffffffffff8000000000000000000000000000":"":"00000000000000000000000000000000":"45d089c36d5c5a4efc689e3b0de10dd5":0:0
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #1
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"fffffffffffffffffffffffffffffffffffffffffffffff00000000000000000":"":"edf61ae362e882ddc0167474a7a77f3a":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #2
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"f8be9ba615c5a952cabbca24f68f8593039624d524c816acda2c9183bd917cb9":"":"a3944b95ca0b52043584ef02151926a8":"00000000000000000000000000000000":0:0
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #3
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"":"623a52fcea5d443e48d9181ab32c7421":"761c1fe41a18acf20d241650611d90f1":0:0
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #4
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_AES_C:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"":"ddc6bf790c15760d8d9aeb6f9a75fd4e":"80000000000000000000000000000000":0:0
|
||||
|
||||
AES-128-CBC crypt Encrypt NIST KAT #1
|
||||
@ -2127,19 +2127,19 @@ depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_ENCRYPT:"00000000000000000000000000000000":"":"f34481ec3cc627bacd5dc3fb08f273e6":"0336763e966d92595a567cc9ce537f5e":0:1
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #1 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"":"3ad78e726c1ec02b7ebfe92b23d9ec34":"80000000000000000000000000000000":0:1
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #2 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"ffffc000000000000000000000000000":"":"df556a33438db87bc41b1752c55e5e49":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #3 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"10a58869d74be5a374cf867cfb473859":"":"6d251e6944b051e04eaa6fb4dbf78465":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-128-ECB crypt Decrypt NIST KAT #4 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_128_ECB:MBEDTLS_DECRYPT:"00000000000000000000000000000000":"":"0336763e966d92595a567cc9ce537f5e":"f34481ec3cc627bacd5dc3fb08f273e6":0:1
|
||||
|
||||
AES-192-ECB crypt Encrypt NIST KAT #1 PSA
|
||||
@ -2159,19 +2159,19 @@ depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_ENCRYPT:"000000000000000000000000000000000000000000000000":"":"1b077a6af4b7f98229de786d7516b639":"275cfc0413d8ccb70513c3859b1d0f72":0:1
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #1 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"":"6cd02513e8d4dc986b4afe087a60bd0c":"80000000000000000000000000000000":0:1
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #2 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"ffe000000000000000000000000000000000000000000000":"":"7ababc4b3f516c9aafb35f4140b548f9":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #3 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"e9f065d7c13573587f7875357dfbb16c53489f6a4bd0f7cd":"":"0956259c9cd5cfd0181cca53380cde06":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-192-ECB crypt Decrypt NIST KAT #4 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_192_ECB:MBEDTLS_DECRYPT:"000000000000000000000000000000000000000000000000":"":"275cfc0413d8ccb70513c3859b1d0f72":"1b077a6af4b7f98229de786d7516b639":0:1
|
||||
|
||||
AES-256-ECB crypt Encrypt NIST KAT #1 PSA
|
||||
@ -2191,19 +2191,19 @@ depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_ENCRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"":"014730f80ac625fe84f026c60bfd547d":"5c9d844ed46f9885085e5d6a4f94c7d7":0:1
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #1 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"":"ddc6bf790c15760d8d9aeb6f9a75fd4e":"80000000000000000000000000000000":0:1
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #2 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"ffe0000000000000000000000000000000000000000000000000000000000000":"":"d1ccb9b1337002cbac42c520b5d67722":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #3 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"c47b0294dbbbee0fec4757f22ffeee3587ca4730c3d33b691df38bab076bc558":"":"46f2fb342d6f0ab477476fc501242c5f":"00000000000000000000000000000000":0:1
|
||||
|
||||
AES-256-ECB crypt Decrypt NIST KAT #4 PSA
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
|
||||
depends_on:MBEDTLS_USE_PSA_CRYPTO:MBEDTLS_TEST_DEPRECATED:PSA_WANT_KEY_TYPE_AES:PSA_WANT_ALG_ECB_NO_PADDING:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
|
||||
test_vec_crypt:MBEDTLS_CIPHER_AES_256_ECB:MBEDTLS_DECRYPT:"0000000000000000000000000000000000000000000000000000000000000000":"":"5c9d844ed46f9885085e5d6a4f94c7d7":"014730f80ac625fe84f026c60bfd547d":0:1
|
||||
|
||||
AES-128-CCM*-NO-TAG crypt Encrypt NIST VPT AES-128 #15
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user