mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-03-17 00:00:03 +08:00
Merge commit '029ba813cd7ac6f9f807e61521f003017fdb5805' into feature/update-dependencies
This commit is contained in:
@@ -1,5 +1,43 @@
|
||||
mbed TLS ChangeLog (Sorted per branch, date)
|
||||
|
||||
= mbed TLS 2.7.13 branch released 2020-01-15
|
||||
|
||||
Security
|
||||
* Fix side channel vulnerability in ECDSA. Our bignum implementation is not
|
||||
constant time/constant trace, so side channel attacks can retrieve the
|
||||
blinded value, factor it (as it is smaller than RSA keys and not guaranteed
|
||||
to have only large prime factors), and then, by brute force, recover the
|
||||
key. Reported by Alejandro Cabrera Aldaya and Billy Brumley.
|
||||
* Zeroize local variables in mbedtls_internal_aes_encrypt() and
|
||||
mbedtls_internal_aes_decrypt() before exiting the function. The value of
|
||||
these variables can be used to recover the last round key. To follow best
|
||||
practice and to limit the impact of buffer overread vulnerabilities (like
|
||||
Heartbleed) we need to zeroize them before exiting the function.
|
||||
Issue reported by Tuba Yavuz, Farhaan Fowze, Ken (Yihang) Bai,
|
||||
Grant Hernandez, and Kevin Butler (University of Florida) and
|
||||
Dave Tian (Purdue University).
|
||||
* Fix side channel vulnerability in ECDSA key generation. Obtaining precise
|
||||
timings on the comparison in the key generation enabled the attacker to
|
||||
learn leading bits of the ephemeral key used during ECDSA signatures and to
|
||||
recover the private key.
|
||||
* Catch failure of AES functions in mbedtls_ctr_drbg_random(). Uncaught
|
||||
failures could happen with alternative implementations of AES. Bug
|
||||
reported and fix proposed by Johan Uppman Bruce and Christoffer Lauri,
|
||||
Sectra.
|
||||
|
||||
Bugfix
|
||||
* Support mbedtls_hmac_drbg_set_entropy_len() and
|
||||
mbedtls_ctr_drbg_set_entropy_len() before the DRBG is seeded. Before,
|
||||
the initial seeding always reset the entropy length to the compile-time
|
||||
default.
|
||||
|
||||
Changes
|
||||
* Add unit tests for AES-GCM when called through mbedtls_cipher_auth_xxx()
|
||||
from the cipher abstraction layer. Fixes #2198.
|
||||
* Clarify how the interface of the CTR_DRBG and HMAC modules relates to
|
||||
NIST SP 800-90A. In particular CTR_DRBG requires an explicit nonce
|
||||
to achieve a 256-bit strength if MBEDTLS_ENTROPY_FORCE_SHA256 is set.
|
||||
|
||||
= mbed TLS 2.7.12 branch released 2019-09-06
|
||||
|
||||
Security
|
||||
|
||||
@@ -179,7 +179,7 @@ extern "C" {
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int s; /*!< integer sign */
|
||||
int s; /*!< Sign: -1 if the mpi is negative, 1 otherwise */
|
||||
size_t n; /*!< total # of limbs */
|
||||
mbedtls_mpi_uint *p; /*!< pointer to limbs */
|
||||
}
|
||||
@@ -484,6 +484,24 @@ int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
*/
|
||||
int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
|
||||
/**
|
||||
* \brief Check if an MPI is less than the other in constant time.
|
||||
*
|
||||
* \param X The left-hand MPI. This must point to an initialized MPI
|
||||
* with the same allocated length as Y.
|
||||
* \param Y The right-hand MPI. This must point to an initialized MPI
|
||||
* with the same allocated length as X.
|
||||
* \param ret The result of the comparison:
|
||||
* \c 1 if \p X is less than \p Y.
|
||||
* \c 0 if \p X is greater than or equal to \p Y.
|
||||
*
|
||||
* \return 0 on success.
|
||||
* \return MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the allocated length of
|
||||
* the two input MPIs is not the same.
|
||||
*/
|
||||
int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
|
||||
unsigned *ret );
|
||||
|
||||
/**
|
||||
* \brief Compare signed values
|
||||
*
|
||||
|
||||
@@ -260,6 +260,14 @@
|
||||
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BACKTRACE) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
#error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequesites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
#error "MBEDTLS_MEMORY_DEBUG defined, but not all prerequesites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
|
||||
#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
@@ -1884,6 +1884,10 @@
|
||||
*
|
||||
* Enable the CTR_DRBG AES-256-based random generator.
|
||||
*
|
||||
* \note This module only achieves a 256-bit security strength if
|
||||
* the generator is seeded with sufficient entropy.
|
||||
* See ctr_drbg.h for more details.
|
||||
*
|
||||
* Module: library/ctr_drbg.c
|
||||
* Caller:
|
||||
*
|
||||
|
||||
@@ -1,13 +1,38 @@
|
||||
/**
|
||||
* \file ctr_drbg.h
|
||||
*
|
||||
* \brief CTR_DRBG is based on AES-256, as defined in <em>NIST SP 800-90A:
|
||||
* Recommendation for Random Number Generation Using Deterministic
|
||||
* Random Bit Generators</em>.
|
||||
* \brief The CTR_DRBG pseudorandom generator.
|
||||
*
|
||||
* CTR_DRBG is a standardized way of building a PRNG from a block-cipher
|
||||
* in counter mode operation, as defined in <em>NIST SP 800-90A:
|
||||
* Recommendation for Random Number Generation Using Deterministic Random
|
||||
* Bit Generators</em>.
|
||||
*
|
||||
* The Mbed TLS implementation of CTR_DRBG uses AES-256
|
||||
* as the underlying block cipher, with a derivation function.
|
||||
* The initial seeding grabs #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes of entropy.
|
||||
* See the documentation of mbedtls_ctr_drbg_seed() for more details.
|
||||
*
|
||||
* Based on NIST SP 800-90A §10.2.1 table 3 and NIST SP 800-57 part 1 table 2,
|
||||
* here are the security strengths achieved in typical configuration:
|
||||
* - 256 bits under the default configuration of the library,
|
||||
* with #MBEDTLS_CTR_DRBG_ENTROPY_LEN set to 48 or more.
|
||||
* - 256 bits if #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set
|
||||
* to 32 or more and the DRBG is initialized with an explicit
|
||||
* nonce in the \c custom parameter to mbedtls_ctr_drbg_seed().
|
||||
* - 128 bits if #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
|
||||
* between 24 and 47 and the DRBG is not initialized with an explicit
|
||||
* nonce (see mbedtls_ctr_drbg_seed()).
|
||||
*
|
||||
* Note that the value of #MBEDTLS_CTR_DRBG_ENTROPY_LEN defaults to:
|
||||
* - \c 48 if the module \c MBEDTLS_SHA512_C is enabled and the symbol
|
||||
* \c MBEDTLS_ENTROPY_FORCE_SHA256 is not enabled at compile time.
|
||||
* This is the default configuration of the library.
|
||||
* - \c 32 if the module \c MBEDTLS_SHA512_C is disabled at compile time.
|
||||
* - \c 32 if \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled at compile time.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
|
||||
* Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@@ -59,21 +84,29 @@
|
||||
* \{
|
||||
*/
|
||||
|
||||
/** \def MBEDTLS_CTR_DRBG_ENTROPY_LEN
|
||||
*
|
||||
* \brief The amount of entropy used per seed by default, in bytes.
|
||||
*/
|
||||
#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
|
||||
#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
|
||||
/** This is 48 bytes because the entropy module uses SHA-512
|
||||
* (\c MBEDTLS_ENTROPY_FORCE_SHA256 is not set).
|
||||
*/
|
||||
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
|
||||
/**< The amount of entropy used per seed by default:
|
||||
* <ul><li>48 with SHA-512.</li>
|
||||
* <li>32 with SHA-256.</li></ul>
|
||||
|
||||
#else /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
|
||||
|
||||
/** This is 32 bytes because the entropy module uses SHA-256
|
||||
* (the SHA512 module is disabled or
|
||||
* \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled).
|
||||
*
|
||||
* \warning To achieve a 256-bit security strength, you must pass a nonce
|
||||
* to mbedtls_ctr_drbg_seed().
|
||||
*/
|
||||
#else
|
||||
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
|
||||
/**< Amount of entropy used per seed by default:
|
||||
* <ul><li>48 with SHA-512.</li>
|
||||
* <li>32 with SHA-256.</li></ul>
|
||||
*/
|
||||
#endif
|
||||
#endif
|
||||
#endif /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
|
||||
#endif /* !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) */
|
||||
|
||||
#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
|
||||
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
|
||||
@@ -92,7 +125,7 @@
|
||||
|
||||
#if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
|
||||
#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
|
||||
/**< The maximum size of seed or reseed buffer. */
|
||||
/**< The maximum size of seed or reseed buffer in bytes. */
|
||||
#endif
|
||||
|
||||
/* \} name SECTION: Module settings */
|
||||
@@ -150,17 +183,67 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
||||
* \brief This function seeds and sets up the CTR_DRBG
|
||||
* entropy source for future reseeds.
|
||||
*
|
||||
* \note Personalization data can be provided in addition to the more generic
|
||||
* entropy source, to make this instantiation as unique as possible.
|
||||
* A typical choice for the \p f_entropy and \p p_entropy parameters is
|
||||
* to use the entropy module:
|
||||
* - \p f_entropy is mbedtls_entropy_func();
|
||||
* - \p p_entropy is an instance of ::mbedtls_entropy_context initialized
|
||||
* with mbedtls_entropy_init() (which registers the platform's default
|
||||
* entropy sources).
|
||||
*
|
||||
* The entropy length is #MBEDTLS_CTR_DRBG_ENTROPY_LEN by default.
|
||||
* You can override it by calling mbedtls_ctr_drbg_set_entropy_len().
|
||||
*
|
||||
* You can provide a personalization string in addition to the
|
||||
* entropy source, to make this instantiation as unique as possible.
|
||||
*
|
||||
* \note The _seed_material_ value passed to the derivation
|
||||
* function in the CTR_DRBG Instantiate Process
|
||||
* described in NIST SP 800-90A §10.2.1.3.2
|
||||
* is the concatenation of the string obtained from
|
||||
* calling \p f_entropy and the \p custom string.
|
||||
* The origin of the nonce depends on the value of
|
||||
* the entropy length relative to the security strength.
|
||||
* - If the entropy length is at least 1.5 times the
|
||||
* security strength then the nonce is taken from the
|
||||
* string obtained with \p f_entropy.
|
||||
* - If the entropy length is less than the security
|
||||
* strength, then the nonce is taken from \p custom.
|
||||
* In this case, for compliance with SP 800-90A,
|
||||
* you must pass a unique value of \p custom at
|
||||
* each invocation. See SP 800-90A §8.6.7 for more
|
||||
* details.
|
||||
*/
|
||||
#if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
|
||||
/** \warning When #MBEDTLS_CTR_DRBG_ENTROPY_LEN is less than
|
||||
* 48, to achieve a 256-bit security strength,
|
||||
* you must pass a value of \p custom that is a nonce:
|
||||
* this value must never be repeated in subsequent
|
||||
* runs of the same application or on a different
|
||||
* device.
|
||||
*/
|
||||
#endif
|
||||
/**
|
||||
* \param ctx The CTR_DRBG context to seed.
|
||||
* It must have been initialized with
|
||||
* mbedtls_ctr_drbg_init().
|
||||
* After a successful call to mbedtls_ctr_drbg_seed(),
|
||||
* you may not call mbedtls_ctr_drbg_seed() again on
|
||||
* the same context unless you call
|
||||
* mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()
|
||||
* again first.
|
||||
* \param f_entropy The entropy callback, taking as arguments the
|
||||
* \p p_entropy context, the buffer to fill, and the
|
||||
length of the buffer.
|
||||
* \param p_entropy The entropy context.
|
||||
* \param custom Personalization data, that is device-specific
|
||||
identifiers. Can be NULL.
|
||||
* \param len The length of the personalization data.
|
||||
* length of the buffer.
|
||||
* \p f_entropy is always called with a buffer size
|
||||
* equal to the entropy length.
|
||||
* \param p_entropy The entropy context to pass to \p f_entropy.
|
||||
* \param custom The personalization string.
|
||||
* This can be \c NULL, in which case the personalization
|
||||
* string is empty regardless of the value of \p len.
|
||||
* \param len The length of the personalization string.
|
||||
* This must be at most
|
||||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
|
||||
* - #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
|
||||
*
|
||||
* \return \c 0 on success, or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
|
||||
@@ -183,7 +266,8 @@ void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
|
||||
* The default value is off.
|
||||
*
|
||||
* \note If enabled, entropy is gathered at the beginning of
|
||||
* every call to mbedtls_ctr_drbg_random_with_add().
|
||||
* every call to mbedtls_ctr_drbg_random_with_add()
|
||||
* or mbedtls_ctr_drbg_random().
|
||||
* Only use this if your entropy source has sufficient
|
||||
* throughput.
|
||||
*
|
||||
@@ -195,18 +279,29 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
|
||||
|
||||
/**
|
||||
* \brief This function sets the amount of entropy grabbed on each
|
||||
* seed or reseed. The default value is
|
||||
* #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
|
||||
* seed or reseed.
|
||||
*
|
||||
* The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
|
||||
*
|
||||
* \note The security strength of CTR_DRBG is bounded by the
|
||||
* entropy length. Thus \p len must be at least
|
||||
* 32 (in bytes) to achieve a 256-bit strength.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param len The amount of entropy to grab.
|
||||
* \param len The amount of entropy to grab, in bytes.
|
||||
* This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* \brief This function sets the reseed interval.
|
||||
* The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
|
||||
*
|
||||
* The reseed interval is the number of calls to mbedtls_ctr_drbg_random()
|
||||
* or mbedtls_ctr_drbg_random_with_add() after which the entropy function
|
||||
* is called again.
|
||||
*
|
||||
* The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param interval The reseed interval.
|
||||
@@ -219,8 +314,12 @@ void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
|
||||
* extracts data from the entropy source.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional Additional data to add to the state. Can be NULL.
|
||||
* \param additional Additional data to add to the state. Can be \c NULL.
|
||||
* \param len The length of the additional data.
|
||||
* This must be less than
|
||||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len
|
||||
* where \c entropy_len is the entropy length
|
||||
* configured for the context.
|
||||
*
|
||||
* \return \c 0 on success, or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
|
||||
@@ -232,7 +331,8 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
|
||||
* \brief This function updates the state of the CTR_DRBG context.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* \param additional The data to update the state with. This must not be
|
||||
* \c NULL unless \p add_len is \c 0.
|
||||
* \param add_len Length of \p additional in bytes. This must be at
|
||||
* most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
|
||||
*
|
||||
@@ -258,8 +358,10 @@ int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,
|
||||
* The remaining Bytes are silently discarded.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* \param add_len Length of \p additional data.
|
||||
* \param additional The data to update the state with. This must not be
|
||||
* \c NULL unless \p add_len is \c 0.
|
||||
* \param add_len Length of \p additional data. This must be at
|
||||
* most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
@@ -269,17 +371,26 @@ void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
|
||||
* \brief This function updates a CTR_DRBG instance with additional
|
||||
* data and uses it to generate random data.
|
||||
*
|
||||
* \note The function automatically reseeds if the reseed counter is exceeded.
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
* \param p_rng The CTR_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_ctr_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
* \param output_len The length of the buffer.
|
||||
* \param additional Additional data to update. Can be NULL.
|
||||
* \param add_len The length of the additional data.
|
||||
* \param output_len The length of the buffer in bytes.
|
||||
* \param additional Additional data to update. Can be \c NULL, in which
|
||||
* case the additional data is empty regardless of
|
||||
* the value of \p add_len.
|
||||
* \param add_len The length of the additional data
|
||||
* if \p additional is not \c NULL.
|
||||
* This must be less than #MBEDTLS_CTR_DRBG_MAX_INPUT
|
||||
* and less than
|
||||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len
|
||||
* where \c entropy_len is the entropy length
|
||||
* configured for the context.
|
||||
*
|
||||
* \return \c 0 on success, or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
@@ -289,15 +400,17 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
/**
|
||||
* \brief This function uses CTR_DRBG to generate random data.
|
||||
*
|
||||
* \note The function automatically reseeds if the reseed counter is exceeded.
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
*
|
||||
* \param p_rng The CTR_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_ctr_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
* \param output_len The length of the buffer.
|
||||
* \param output_len The length of the buffer in bytes.
|
||||
*
|
||||
* \return \c 0 on success, or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_random( void *p_rng,
|
||||
@@ -310,9 +423,9 @@ int mbedtls_ctr_drbg_random( void *p_rng,
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param path The name of the file.
|
||||
*
|
||||
* \return \c 0 on success,
|
||||
* #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on reseed
|
||||
* failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
|
||||
@@ -324,10 +437,12 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param path The name of the file.
|
||||
*
|
||||
* \return \c 0 on success,
|
||||
* #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
|
||||
* #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG on failure.
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
|
||||
* reseed failure.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if the existing
|
||||
* seed file is too large.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/**
|
||||
* \file hmac_drbg.h
|
||||
*
|
||||
* \brief HMAC_DRBG (NIST SP 800-90A)
|
||||
* \brief The HMAC_DRBG pseudorandom generator.
|
||||
*
|
||||
* This module implements the HMAC_DRBG pseudorandom generator described
|
||||
* in <em>NIST SP 800-90A: Recommendation for Random Number Generation Using
|
||||
* Deterministic Random Bit Generators</em>.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Copyright (C) 2006-2019, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@@ -104,38 +108,72 @@ typedef struct
|
||||
} mbedtls_hmac_drbg_context;
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG context initialization
|
||||
* Makes the context ready for mbedtls_hmac_drbg_seed(),
|
||||
* mbedtls_hmac_drbg_seed_buf() or
|
||||
* mbedtls_hmac_drbg_free().
|
||||
* \brief HMAC_DRBG context initialization.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be initialized
|
||||
* This function makes the context ready for mbedtls_hmac_drbg_seed(),
|
||||
* mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be initialized.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG initial seeding
|
||||
* Seed and setup entropy source for future reseeds.
|
||||
* \brief HMAC_DRBG initial seeding.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be seeded
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG
|
||||
* \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer
|
||||
* length)
|
||||
* \param p_entropy Entropy context
|
||||
* \param custom Personalization data (Device specific identifiers)
|
||||
* (Can be NULL)
|
||||
* \param len Length of personalization data
|
||||
* Set the initial seed and set up the entropy source for future reseeds.
|
||||
*
|
||||
* \note The "security strength" as defined by NIST is set to:
|
||||
* 128 bits if md_alg is SHA-1,
|
||||
* 192 bits if md_alg is SHA-224,
|
||||
* 256 bits if md_alg is SHA-256 or higher.
|
||||
* A typical choice for the \p f_entropy and \p p_entropy parameters is
|
||||
* to use the entropy module:
|
||||
* - \p f_entropy is mbedtls_entropy_func();
|
||||
* - \p p_entropy is an instance of ::mbedtls_entropy_context initialized
|
||||
* with mbedtls_entropy_init() (which registers the platform's default
|
||||
* entropy sources).
|
||||
*
|
||||
* You can provide a personalization string in addition to the
|
||||
* entropy source, to make this instantiation as unique as possible.
|
||||
*
|
||||
* \note By default, the security strength as defined by NIST is:
|
||||
* - 128 bits if \p md_info is SHA-1;
|
||||
* - 192 bits if \p md_info is SHA-224;
|
||||
* - 256 bits if \p md_info is SHA-256, SHA-384 or SHA-512.
|
||||
* Note that SHA-256 is just as efficient as SHA-224.
|
||||
* The security strength can be reduced if a smaller
|
||||
* entropy length is set with
|
||||
* mbedtls_hmac_drbg_set_entropy_len().
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
|
||||
* MBEDTLS_ERR_MD_ALLOC_FAILED, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED.
|
||||
* \note The default entropy length is the security strength
|
||||
* (converted from bits to bytes). You can override
|
||||
* it by calling mbedtls_hmac_drbg_set_entropy_len().
|
||||
*
|
||||
* \note During the initial seeding, this function calls
|
||||
* the entropy source to obtain a nonce
|
||||
* whose length is half the entropy length.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be seeded.
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG.
|
||||
* \param f_entropy The entropy callback, taking as arguments the
|
||||
* \p p_entropy context, the buffer to fill, and the
|
||||
* length of the buffer.
|
||||
* \p f_entropy is always called with a length that is
|
||||
* less than or equal to the entropy length.
|
||||
* \param p_entropy The entropy context to pass to \p f_entropy.
|
||||
* \param custom The personalization string.
|
||||
* This can be \c NULL, in which case the personalization
|
||||
* string is empty regardless of the value of \p len.
|
||||
* \param len The length of the personalization string.
|
||||
* This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT
|
||||
* and also at most
|
||||
* #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \p entropy_len * 3 / 2
|
||||
* where \p entropy_len is the entropy length
|
||||
* described above.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info is
|
||||
* invalid.
|
||||
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough
|
||||
* memory to allocate context data.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if the call to \p f_entropy failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t * md_info,
|
||||
@@ -146,66 +184,80 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
|
||||
/**
|
||||
* \brief Initilisation of simpified HMAC_DRBG (never reseeds).
|
||||
* (For use with deterministic ECDSA.)
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be initialised
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG
|
||||
* \param data Concatenation of entropy string and additional data
|
||||
* \param data_len Length of data in bytes
|
||||
* This function is meant for use in algorithms that need a pseudorandom
|
||||
* input such as deterministic ECDSA.
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
|
||||
* MBEDTLS_ERR_MD_ALLOC_FAILED.
|
||||
* \param ctx HMAC_DRBG context to be initialised.
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG.
|
||||
* \param data Concatenation of the initial entropy string and
|
||||
* the additional data.
|
||||
* \param data_len Length of \p data in bytes.
|
||||
*
|
||||
* \return \c 0 if successful. or
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info is
|
||||
* invalid.
|
||||
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough
|
||||
* memory to allocate context data.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t * md_info,
|
||||
const unsigned char *data, size_t data_len );
|
||||
|
||||
/**
|
||||
* \brief Enable / disable prediction resistance (Default: Off)
|
||||
* \brief This function turns prediction resistance on or off.
|
||||
* The default value is off.
|
||||
*
|
||||
* Note: If enabled, entropy is used for ctx->entropy_len before each call!
|
||||
* Only use this if you have ample supply of good entropy!
|
||||
* \note If enabled, entropy is gathered at the beginning of
|
||||
* every call to mbedtls_hmac_drbg_random_with_add()
|
||||
* or mbedtls_hmac_drbg_random().
|
||||
* Only use this if your entropy source has sufficient
|
||||
* throughput.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param resistance MBEDTLS_HMAC_DRBG_PR_ON or MBEDTLS_HMAC_DRBG_PR_OFF
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param resistance #MBEDTLS_HMAC_DRBG_PR_ON or #MBEDTLS_HMAC_DRBG_PR_OFF.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
|
||||
int resistance );
|
||||
|
||||
/**
|
||||
* \brief Set the amount of entropy grabbed on each reseed
|
||||
* (Default: given by the security strength, which
|
||||
* depends on the hash used, see \c mbedtls_hmac_drbg_init() )
|
||||
* \brief This function sets the amount of entropy grabbed on each
|
||||
* seed or reseed.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param len Amount of entropy to grab, in bytes
|
||||
* See the documentation of mbedtls_hmac_drbg_seed() for the default value.
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param len The amount of entropy to grab, in bytes.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* \brief Set the reseed interval
|
||||
* (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
|
||||
* \brief Set the reseed interval.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param interval Reseed interval
|
||||
* The reseed interval is the number of calls to mbedtls_hmac_drbg_random()
|
||||
* or mbedtls_hmac_drbg_random_with_add() after which the entropy function
|
||||
* is called again.
|
||||
*
|
||||
* The default value is #MBEDTLS_HMAC_DRBG_RESEED_INTERVAL.
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param interval The reseed interval.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
|
||||
int interval );
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG update state
|
||||
* \brief This function updates the state of the HMAC_DRBG context.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param additional Additional data to update state with, or NULL
|
||||
* \param add_len Length of additional data, or 0
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* If this is \c NULL, there is no additional data.
|
||||
* \param add_len Length of \p additional in bytes.
|
||||
* Unused if \p additional is \c NULL.
|
||||
*
|
||||
* \return \c 0 on success, or an error from the underlying
|
||||
* hash calculation.
|
||||
*
|
||||
* \note Additional data is optional, pass NULL and 0 as second
|
||||
* third argument if no additional data is being used.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t add_len );
|
||||
@@ -228,33 +280,52 @@ void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
|
||||
size_t add_len );
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG reseeding (extracts data from entropy source)
|
||||
* \brief This function reseeds the HMAC_DRBG context, that is
|
||||
* extracts data from the entropy source.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param additional Additional data to add to state (Can be NULL)
|
||||
* \param len Length of additional data
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param additional Additional data to add to the state.
|
||||
* If this is \c NULL, there is no additional data
|
||||
* and \p len should be \c 0.
|
||||
* \param len The length of the additional data.
|
||||
* This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT
|
||||
* and also at most
|
||||
* #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \p entropy_len
|
||||
* where \p entropy_len is the entropy length
|
||||
* (see mbedtls_hmac_drbg_set_entropy_len()).
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if a call to the entropy function failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t len );
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG generate random with additional update input
|
||||
* \brief This function updates an HMAC_DRBG instance with additional
|
||||
* data and uses it to generate random data.
|
||||
*
|
||||
* Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
* \param p_rng HMAC_DRBG context
|
||||
* \param output Buffer to fill
|
||||
* \param output_len Length of the buffer
|
||||
* \param additional Additional data to update with (can be NULL)
|
||||
* \param add_len Length of additional data (can be 0)
|
||||
* \param p_rng The HMAC_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_hmac_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
* \param output_len The length of the buffer in bytes.
|
||||
* This must be at most #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
|
||||
* \param additional Additional data to update with.
|
||||
* If this is \c NULL, there is no additional data
|
||||
* and \p add_len should be \c 0.
|
||||
* \param add_len The length of the additional data.
|
||||
* This must be at most #MBEDTLS_HMAC_DRBG_MAX_INPUT.
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG.
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if a call to the entropy source failed.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG if
|
||||
* \p output_len > #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if
|
||||
* \p add_len > #MBEDTLS_HMAC_DRBG_MAX_INPUT.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_random_with_add( void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
@@ -262,49 +333,59 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng,
|
||||
size_t add_len );
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG generate random
|
||||
* \brief This function uses HMAC_DRBG to generate random data.
|
||||
*
|
||||
* Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
* \param p_rng HMAC_DRBG context
|
||||
* \param output Buffer to fill
|
||||
* \param out_len Length of the buffer
|
||||
* \param p_rng The HMAC_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_hmac_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
* \param out_len The length of the buffer in bytes.
|
||||
* This must be at most #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if a call to the entropy source failed.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG if
|
||||
* \p out_len > #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
|
||||
|
||||
/**
|
||||
* \brief Free an HMAC_DRBG context
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to free.
|
||||
* \param ctx The HMAC_DRBG context to free.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
* \brief Write a seed file
|
||||
* \brief This function writes a seed file.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param path Name of the file
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param path The name of the file.
|
||||
*
|
||||
* \return 0 if successful, 1 on file error, or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR on file error.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED on reseed
|
||||
* failure.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
|
||||
|
||||
/**
|
||||
* \brief Read and update a seed file. Seed is added to this
|
||||
* instance
|
||||
* \brief This function reads and updates a seed file. The seed
|
||||
* is added to this instance.
|
||||
*
|
||||
* \param ctx HMAC_DRBG context
|
||||
* \param path Name of the file
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param path The name of the file.
|
||||
*
|
||||
* \return 0 if successful, 1 on file error,
|
||||
* MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR on file error.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED on
|
||||
* reseed failure.
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if the existing
|
||||
* seed file is too large.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
@@ -312,9 +393,10 @@ int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const ch
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
* \brief The HMAC_DRBG Checkup routine.
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
* \return \c 0 if successful.
|
||||
* \return \c 1 if the test failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_self_test( int verbose );
|
||||
#endif
|
||||
|
||||
@@ -761,6 +761,18 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
PUT_UINT32_LE( X2, output, 8 );
|
||||
PUT_UINT32_LE( X3, output, 12 );
|
||||
|
||||
mbedtls_zeroize( &X0, sizeof( X0 ) );
|
||||
mbedtls_zeroize( &X1, sizeof( X1 ) );
|
||||
mbedtls_zeroize( &X2, sizeof( X2 ) );
|
||||
mbedtls_zeroize( &X3, sizeof( X3 ) );
|
||||
|
||||
mbedtls_zeroize( &Y0, sizeof( Y0 ) );
|
||||
mbedtls_zeroize( &Y1, sizeof( Y1 ) );
|
||||
mbedtls_zeroize( &Y2, sizeof( Y2 ) );
|
||||
mbedtls_zeroize( &Y3, sizeof( Y3 ) );
|
||||
|
||||
mbedtls_zeroize( &RK, sizeof( RK ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_ENCRYPT_ALT */
|
||||
@@ -829,6 +841,18 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
PUT_UINT32_LE( X2, output, 8 );
|
||||
PUT_UINT32_LE( X3, output, 12 );
|
||||
|
||||
mbedtls_zeroize( &X0, sizeof( X0 ) );
|
||||
mbedtls_zeroize( &X1, sizeof( X1 ) );
|
||||
mbedtls_zeroize( &X2, sizeof( X2 ) );
|
||||
mbedtls_zeroize( &X3, sizeof( X3 ) );
|
||||
|
||||
mbedtls_zeroize( &Y0, sizeof( Y0 ) );
|
||||
mbedtls_zeroize( &Y1, sizeof( Y1 ) );
|
||||
mbedtls_zeroize( &Y2, sizeof( Y2 ) );
|
||||
mbedtls_zeroize( &Y3, sizeof( Y3 ) );
|
||||
|
||||
mbedtls_zeroize( &RK, sizeof( RK ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
|
||||
|
||||
@@ -919,6 +919,103 @@ int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/** Decide if an integer is less than the other, without branches.
|
||||
*
|
||||
* \param x First integer.
|
||||
* \param y Second integer.
|
||||
*
|
||||
* \return 1 if \p x is less than \p y, 0 otherwise
|
||||
*/
|
||||
static unsigned ct_lt_mpi_uint( const mbedtls_mpi_uint x,
|
||||
const mbedtls_mpi_uint y )
|
||||
{
|
||||
mbedtls_mpi_uint ret;
|
||||
mbedtls_mpi_uint cond;
|
||||
|
||||
/*
|
||||
* Check if the most significant bits (MSB) of the operands are different.
|
||||
*/
|
||||
cond = ( x ^ y );
|
||||
/*
|
||||
* If the MSB are the same then the difference x-y will be negative (and
|
||||
* have its MSB set to 1 during conversion to unsigned) if and only if x<y.
|
||||
*/
|
||||
ret = ( x - y ) & ~cond;
|
||||
/*
|
||||
* If the MSB are different, then the operand with the MSB of 1 is the
|
||||
* bigger. (That is if y has MSB of 1, then x<y is true and it is false if
|
||||
* the MSB of y is 0.)
|
||||
*/
|
||||
ret |= y & cond;
|
||||
|
||||
|
||||
ret = ret >> ( biL - 1 );
|
||||
|
||||
return (unsigned) ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare signed values in constant time
|
||||
*/
|
||||
int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
|
||||
unsigned *ret )
|
||||
{
|
||||
size_t i;
|
||||
/* The value of any of these variables is either 0 or 1 at all times. */
|
||||
unsigned cond, done, X_is_negative, Y_is_negative;
|
||||
|
||||
if( X->n != Y->n )
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
|
||||
/*
|
||||
* Set sign_N to 1 if N >= 0, 0 if N < 0.
|
||||
* We know that N->s == 1 if N >= 0 and N->s == -1 if N < 0.
|
||||
*/
|
||||
X_is_negative = ( X->s & 2 ) >> 1;
|
||||
Y_is_negative = ( Y->s & 2 ) >> 1;
|
||||
|
||||
/*
|
||||
* If the signs are different, then the positive operand is the bigger.
|
||||
* That is if X is negative (X_is_negative == 1), then X < Y is true and it
|
||||
* is false if X is positive (X_is_negative == 0).
|
||||
*/
|
||||
cond = ( X_is_negative ^ Y_is_negative );
|
||||
*ret = cond & X_is_negative;
|
||||
|
||||
/*
|
||||
* This is a constant-time function. We might have the result, but we still
|
||||
* need to go through the loop. Record if we have the result already.
|
||||
*/
|
||||
done = cond;
|
||||
|
||||
for( i = X->n; i > 0; i-- )
|
||||
{
|
||||
/*
|
||||
* If Y->p[i - 1] < X->p[i - 1] then X < Y is true if and only if both
|
||||
* X and Y are negative.
|
||||
*
|
||||
* Again even if we can make a decision, we just mark the result and
|
||||
* the fact that we are done and continue looping.
|
||||
*/
|
||||
cond = ct_lt_mpi_uint( Y->p[i - 1], X->p[i - 1] );
|
||||
*ret |= cond & ( 1 - done ) & X_is_negative;
|
||||
done |= cond;
|
||||
|
||||
/*
|
||||
* If X->p[i - 1] < Y->p[i - 1] then X < Y is true if and only if both
|
||||
* X and Y are positive.
|
||||
*
|
||||
* Again even if we can make a decision, we just mark the result and
|
||||
* the fact that we are done and continue looping.
|
||||
*/
|
||||
cond = ct_lt_mpi_uint( X->p[i - 1], Y->p[i - 1] );
|
||||
*ret |= cond & ( 1 - done ) & ( 1 - X_is_negative );
|
||||
done |= cond;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare signed values
|
||||
*/
|
||||
|
||||
@@ -66,56 +66,6 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx )
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Non-public function wrapped by mbedtls_ctr_drbg_seed(). Necessary to allow
|
||||
* NIST tests to succeed (which require known length fixed entropy)
|
||||
*/
|
||||
int mbedtls_ctr_drbg_seed_entropy_len(
|
||||
mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len,
|
||||
size_t entropy_len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE];
|
||||
|
||||
memset( key, 0, MBEDTLS_CTR_DRBG_KEYSIZE );
|
||||
|
||||
mbedtls_aes_init( &ctx->aes_ctx );
|
||||
|
||||
ctx->f_entropy = f_entropy;
|
||||
ctx->p_entropy = p_entropy;
|
||||
|
||||
ctx->entropy_len = entropy_len;
|
||||
ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL;
|
||||
|
||||
/*
|
||||
* Initialize with an empty key
|
||||
*/
|
||||
if( ( ret = mbedtls_aes_setkey_enc( &ctx->aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_ctr_drbg_reseed( ctx, custom, len ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len )
|
||||
{
|
||||
return( mbedtls_ctr_drbg_seed_entropy_len( ctx, f_entropy, p_entropy, custom, len,
|
||||
MBEDTLS_CTR_DRBG_ENTROPY_LEN ) );
|
||||
}
|
||||
|
||||
void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
@@ -386,6 +336,52 @@ exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len )
|
||||
{
|
||||
int ret;
|
||||
unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE];
|
||||
|
||||
memset( key, 0, MBEDTLS_CTR_DRBG_KEYSIZE );
|
||||
|
||||
mbedtls_aes_init( &ctx->aes_ctx );
|
||||
|
||||
ctx->f_entropy = f_entropy;
|
||||
ctx->p_entropy = p_entropy;
|
||||
|
||||
if( ctx->entropy_len == 0 )
|
||||
ctx->entropy_len = MBEDTLS_CTR_DRBG_ENTROPY_LEN;
|
||||
ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL;
|
||||
|
||||
/*
|
||||
* Initialize with an empty key
|
||||
*/
|
||||
if( ( ret = mbedtls_aes_setkey_enc( &ctx->aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_ctr_drbg_reseed( ctx, custom, len ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Backward compatibility wrapper */
|
||||
int mbedtls_ctr_drbg_seed_entropy_len(
|
||||
mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t), void *p_entropy,
|
||||
const unsigned char *custom, size_t len,
|
||||
size_t entropy_len )
|
||||
{
|
||||
mbedtls_ctr_drbg_set_entropy_len( ctx, entropy_len );
|
||||
return( mbedtls_ctr_drbg_seed( ctx, f_entropy, p_entropy, custom, len ) );
|
||||
}
|
||||
|
||||
int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
const unsigned char *additional, size_t add_len )
|
||||
@@ -457,7 +453,7 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
exit:
|
||||
mbedtls_zeroize( add_input, sizeof( add_input ) );
|
||||
mbedtls_zeroize( tmp, sizeof( tmp ) );
|
||||
return( 0 );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
int mbedtls_ctr_drbg_random( void *p_rng, unsigned char *output, size_t output_len )
|
||||
@@ -617,8 +613,11 @@ int mbedtls_ctr_drbg_self_test( int verbose )
|
||||
mbedtls_printf( " CTR_DRBG (PR = TRUE) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) );
|
||||
mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 );
|
||||
CHK( mbedtls_ctr_drbg_seed( &ctx,
|
||||
ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_pr,
|
||||
nonce_pers_pr, 16 ) );
|
||||
mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
|
||||
@@ -638,8 +637,11 @@ int mbedtls_ctr_drbg_self_test( int verbose )
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
|
||||
mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 );
|
||||
CHK( mbedtls_ctr_drbg_seed( &ctx,
|
||||
ctr_drbg_self_test_entropy,
|
||||
(void *) entropy_source_nopr,
|
||||
nonce_pers_nopr, 16 ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
|
||||
CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) );
|
||||
CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) );
|
||||
|
||||
@@ -153,6 +153,7 @@ static int ecdsa_sign_internal( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &e, &e, s ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &e, &e, &t ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &k, &k, &t ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &k, &k, &grp->N ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( s, &k, &grp->N ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( s, s, &e ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( s, s, &grp->N ) );
|
||||
|
||||
@@ -1957,6 +1957,7 @@ int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
|
||||
{
|
||||
/* SEC1 3.2.1: Generate d such that 1 <= n < N */
|
||||
int count = 0;
|
||||
unsigned cmp = 0;
|
||||
|
||||
/*
|
||||
* Match the procedure given in RFC 6979 (deterministic ECDSA):
|
||||
@@ -1981,9 +1982,14 @@ int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
|
||||
*/
|
||||
if( ++count > 30 )
|
||||
return( MBEDTLS_ERR_ECP_RANDOM_FAILED );
|
||||
|
||||
ret = mbedtls_mpi_lt_mpi_ct( d, &grp->N, &cmp );
|
||||
if( ret != 0 )
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
while( mbedtls_mpi_cmp_int( d, 1 ) < 0 ||
|
||||
mbedtls_mpi_cmp_mpi( d, &grp->N ) >= 0 );
|
||||
while( mbedtls_mpi_cmp_int( d, 1 ) < 0 || cmp != 1 );
|
||||
}
|
||||
#endif /* ECP_SHORTWEIERSTRASS */
|
||||
|
||||
|
||||
@@ -275,16 +275,19 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
|
||||
ctx->reseed_interval = MBEDTLS_HMAC_DRBG_RESEED_INTERVAL;
|
||||
|
||||
/*
|
||||
* See SP800-57 5.6.1 (p. 65-66) for the security strength provided by
|
||||
* each hash function, then according to SP800-90A rev1 10.1 table 2,
|
||||
* min_entropy_len (in bits) is security_strength.
|
||||
*
|
||||
* (This also matches the sizes used in the NIST test vectors.)
|
||||
*/
|
||||
ctx->entropy_len = md_size <= 20 ? 16 : /* 160-bits hash -> 128 bits */
|
||||
md_size <= 28 ? 24 : /* 224-bits hash -> 192 bits */
|
||||
32; /* better (256+) -> 256 bits */
|
||||
if( ctx->entropy_len == 0 )
|
||||
{
|
||||
/*
|
||||
* See SP800-57 5.6.1 (p. 65-66) for the security strength provided by
|
||||
* each hash function, then according to SP800-90A rev1 10.1 table 2,
|
||||
* min_entropy_len (in bits) is security_strength.
|
||||
*
|
||||
* (This also matches the sizes used in the NIST test vectors.)
|
||||
*/
|
||||
ctx->entropy_len = md_size <= 20 ? 16 : /* 160-bits hash -> 128 bits */
|
||||
md_size <= 28 ? 24 : /* 224-bits hash -> 192 bits */
|
||||
32; /* better (256+) -> 256 bits */
|
||||
}
|
||||
|
||||
if( ( ret = hmac_drbg_reseed_core( ctx, custom, len,
|
||||
1 /* add nonce */ ) ) != 0 )
|
||||
@@ -305,7 +308,7 @@ void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx
|
||||
}
|
||||
|
||||
/*
|
||||
* Set entropy length grabbed for reseeds
|
||||
* Set entropy length grabbed for seeding
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx, size_t len )
|
||||
{
|
||||
|
||||
@@ -560,13 +560,14 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||
|
||||
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||
mbedtls_exit(1);
|
||||
TIME_AND_TSC( "CTR_DRBG (NOPR)",
|
||||
if( mbedtls_ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
||||
mbedtls_exit(1) );
|
||||
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||
if( mbedtls_ctr_drbg_seed( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||
mbedtls_exit(1);
|
||||
mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_ON );
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_snprintf snprintf
|
||||
#define mbedtls_exit exit
|
||||
@@ -72,6 +74,87 @@
|
||||
#include "mbedtls/memory_buffer_alloc.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined MBEDTLS_SELF_TEST
|
||||
/* Sanity check for malloc. This is not expected to fail, and is rather
|
||||
* intended to display potentially useful information about the platform,
|
||||
* in particular the behavior of malloc(0). */
|
||||
static int calloc_self_test( int verbose )
|
||||
{
|
||||
int failures = 0;
|
||||
void *empty1 = mbedtls_calloc( 0, 1 );
|
||||
void *empty2 = mbedtls_calloc( 0, 1 );
|
||||
void *buffer1 = mbedtls_calloc( 1, 1 );
|
||||
void *buffer2 = mbedtls_calloc( 1, 1 );
|
||||
uintptr_t old_buffer1;
|
||||
|
||||
if( empty1 == NULL && empty2 == NULL )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
|
||||
}
|
||||
else if( empty1 == NULL || empty2 == NULL )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
|
||||
++failures;
|
||||
}
|
||||
else if( empty1 == empty2 )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
|
||||
}
|
||||
|
||||
if( buffer1 == NULL || buffer2 == NULL )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
|
||||
++failures;
|
||||
}
|
||||
else if( buffer1 == buffer2 )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
|
||||
++failures;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(1): passed\n" );
|
||||
}
|
||||
|
||||
old_buffer1 = (uintptr_t) buffer1;
|
||||
mbedtls_free( buffer1 );
|
||||
buffer1 = mbedtls_calloc( 1, 1 );
|
||||
if( buffer1 == NULL )
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
|
||||
++failures;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( verbose )
|
||||
mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
|
||||
(uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
|
||||
"same" : "different" );
|
||||
}
|
||||
|
||||
if( verbose )
|
||||
mbedtls_printf( "\n" );
|
||||
mbedtls_free( empty1 );
|
||||
mbedtls_free( empty2 );
|
||||
mbedtls_free( buffer1 );
|
||||
mbedtls_free( buffer2 );
|
||||
return( failures );
|
||||
}
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
||||
{
|
||||
int ret;
|
||||
@@ -168,6 +251,7 @@ typedef struct
|
||||
|
||||
const selftest_t selftests[] =
|
||||
{
|
||||
{"calloc", calloc_self_test},
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
{"md2", mbedtls_md2_self_test},
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
# MBEDTLS_ECP_DP_M221_ENABLED
|
||||
# MBEDTLS_ECP_DP_M383_ENABLED
|
||||
# MBEDTLS_ECP_DP_M511_ENABLED
|
||||
# MBEDTLS_MEMORY_BACKTRACE
|
||||
# MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
# MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
||||
# MBEDTLS_NO_PLATFORM_ENTROPY
|
||||
# MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
@@ -37,6 +39,8 @@
|
||||
# - this could be enabled if the respective tests were adapted
|
||||
# MBEDTLS_ZLIB_SUPPORT
|
||||
# MBEDTLS_PKCS11_C
|
||||
# MBEDTLS_NO_UDBL_DIVISION
|
||||
# MBEDTLS_NO_64BIT_MULTIPLICATION
|
||||
# and any symbol beginning _ALT
|
||||
#
|
||||
|
||||
@@ -86,6 +90,9 @@ MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
||||
MBEDTLS_ECP_DP_M221_ENABLED
|
||||
MBEDTLS_ECP_DP_M383_ENABLED
|
||||
MBEDTLS_ECP_DP_M511_ENABLED
|
||||
MBEDTLS_MEMORY_DEBUG
|
||||
MBEDTLS_MEMORY_BACKTRACE
|
||||
MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
||||
MBEDTLS_NO_PLATFORM_ENTROPY
|
||||
MBEDTLS_RSA_NO_CRT
|
||||
|
||||
39
Sources/mbedTLS/tests/configs/config-wrapper-malloc-0-null.h
Normal file
39
Sources/mbedTLS/tests/configs/config-wrapper-malloc-0-null.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* config.h wrapper that forces calloc(0) to return NULL.
|
||||
* Used for testing.
|
||||
*/
|
||||
/*
|
||||
* Copyright (C) 2019, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_CONFIG_H
|
||||
/* Don't #define MBEDTLS_CONFIG_H, let config.h do it. */
|
||||
|
||||
#include "mbedtls/config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
static inline void *custom_calloc( size_t nmemb, size_t size )
|
||||
{
|
||||
if( nmemb == 0 || size == 0 )
|
||||
return( NULL );
|
||||
return( calloc( nmemb, size ) );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_MEMORY
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC custom_calloc
|
||||
|
||||
#endif /* MBEDTLS_CONFIG_H */
|
||||
@@ -137,6 +137,9 @@ pre_initialize_variables () {
|
||||
export MAKEFLAGS="-j"
|
||||
fi
|
||||
|
||||
# CFLAGS and LDFLAGS for Asan builds that don't use CMake
|
||||
ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
|
||||
|
||||
# Gather the list of available components. These are the functions
|
||||
# defined in this script whose name starts with "component_".
|
||||
# Parse the script with sed, because in sh there is no way to list
|
||||
@@ -644,6 +647,22 @@ component_test_default_cmake_gcc_asan () {
|
||||
if_build_succeeded tests/compat.sh
|
||||
}
|
||||
|
||||
component_test_full_cmake_gcc_asan () {
|
||||
msg "build: full config, cmake, gcc, ASan"
|
||||
scripts/config.pl full
|
||||
CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
|
||||
make
|
||||
|
||||
msg "test: main suites (inc. selftests) (full config, ASan build)"
|
||||
make test
|
||||
|
||||
msg "test: ssl-opt.sh (full config, ASan build)"
|
||||
if_build_succeeded tests/ssl-opt.sh
|
||||
|
||||
msg "test: compat.sh (full config, ASan build)"
|
||||
if_build_succeeded tests/compat.sh
|
||||
}
|
||||
|
||||
component_test_ref_configs () {
|
||||
msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
|
||||
CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
|
||||
@@ -699,7 +718,6 @@ component_test_rsa_no_crt () {
|
||||
component_test_full_cmake_clang () {
|
||||
msg "build: cmake, full config, clang" # ~ 50s
|
||||
scripts/config.pl full
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
|
||||
CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
|
||||
make
|
||||
|
||||
@@ -771,7 +789,6 @@ component_test_no_platform () {
|
||||
scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT
|
||||
scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT
|
||||
scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
scripts/config.pl unset MBEDTLS_FS_IO
|
||||
# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
|
||||
# to re-enable platform integration features otherwise disabled in C99 builds
|
||||
@@ -812,6 +829,34 @@ component_build_no_sockets () {
|
||||
make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib
|
||||
}
|
||||
|
||||
component_test_memory_buffer_allocator_backtrace () {
|
||||
msg "build: default config with memory buffer allocator and backtrace enabled"
|
||||
scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
|
||||
scripts/config.pl set MBEDTLS_MEMORY_BACKTRACE
|
||||
scripts/config.pl set MBEDTLS_MEMORY_DEBUG
|
||||
CC=gcc cmake .
|
||||
make
|
||||
|
||||
msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
|
||||
make test
|
||||
}
|
||||
|
||||
component_test_memory_buffer_allocator () {
|
||||
msg "build: default config with memory buffer allocator"
|
||||
scripts/config.pl set MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
scripts/config.pl set MBEDTLS_PLATFORM_MEMORY
|
||||
CC=gcc cmake .
|
||||
make
|
||||
|
||||
msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
|
||||
make test
|
||||
|
||||
msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
|
||||
# MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
|
||||
if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
|
||||
}
|
||||
|
||||
component_test_no_max_fragment_length () {
|
||||
msg "build: default config except MFL extension (ASan build)" # ~ 30s
|
||||
scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
@@ -849,6 +894,21 @@ component_test_platform_calloc_macro () {
|
||||
make test
|
||||
}
|
||||
|
||||
component_test_malloc_0_null () {
|
||||
msg "build: malloc(0) returns NULL (ASan+UBSan build)"
|
||||
scripts/config.pl full
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' -O -Werror -Wall -Wextra -fsanitize=address,undefined" LDFLAGS='-fsanitize=address,undefined'
|
||||
|
||||
msg "test: malloc(0) returns NULL (ASan+UBSan build)"
|
||||
make test
|
||||
|
||||
msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
|
||||
# Just the calloc selftest. "make test" ran the others as part of the
|
||||
# test suites.
|
||||
if_build_succeeded programs/test/selftest calloc
|
||||
}
|
||||
|
||||
component_test_make_shared () {
|
||||
msg "build/test: make shared" # ~ 40s
|
||||
make SHARED=1 all check
|
||||
@@ -878,7 +938,7 @@ component_test_m32_o0 () {
|
||||
# Build once with -O0, to compile out the i386 specific inline assembly
|
||||
msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
|
||||
scripts/config.pl full
|
||||
make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
|
||||
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
|
||||
|
||||
msg "test: i386, make, gcc -O0 (ASan build)"
|
||||
make test
|
||||
@@ -894,10 +954,7 @@ component_test_m32_o1 () {
|
||||
# Build again with -O1, to compile in the i386 specific inline assembly
|
||||
msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
|
||||
scripts/config.pl full
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
||||
scripts/config.pl unset MBEDTLS_MEMORY_DEBUG
|
||||
make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' LDFLAGS='-m32'
|
||||
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
|
||||
|
||||
msg "test: i386, make, gcc -O1 (ASan build)"
|
||||
make test
|
||||
|
||||
@@ -93,7 +93,7 @@ for my $suite (@suites)
|
||||
$suite_cases_failed = () = $result =~ /.. FAILED/g;
|
||||
$suite_cases_skipped = () = $result =~ /.. ----/g;
|
||||
|
||||
if( $result =~ /PASSED/ ) {
|
||||
if( $? == 0 ) {
|
||||
print "PASS\n";
|
||||
if( $verbose > 2 ) {
|
||||
pad_print_center( 72, '-', "Begin $suite" );
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -72,7 +72,10 @@ void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
||||
add2_len = unhexify( add2, add2_string );
|
||||
|
||||
test_offset_idx = 0;
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
||||
mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx,
|
||||
mbedtls_test_entropy_func, entropy,
|
||||
add_init, add_init_len ) == 0 );
|
||||
mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
|
||||
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
||||
@@ -110,7 +113,10 @@ void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
|
||||
add2_len = unhexify( add2, add2_string );
|
||||
|
||||
test_offset_idx = 0;
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed_entropy_len( &ctx, mbedtls_test_entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
||||
mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx,
|
||||
mbedtls_test_entropy_func, entropy,
|
||||
add_init, add_init_len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, add_reseed, add_reseed_len ) == 0 );
|
||||
|
||||
@@ -16,8 +16,8 @@ memory_buffer_alloc_free_alloc:100:64:100:100:0:0:0:1:200:0
|
||||
Memory buffer alloc - Out of Memory test
|
||||
memory_buffer_alloc_oom_test:
|
||||
|
||||
Memory buffer small buffer
|
||||
memory_buffer_small_buffer:
|
||||
Memory buffer: heap too small (header verification should fail)
|
||||
memory_buffer_heap_too_small:
|
||||
|
||||
Memory buffer underalloc
|
||||
Memory buffer: attempt to allocate SIZE_MAX
|
||||
memory_buffer_underalloc:
|
||||
|
||||
@@ -29,7 +29,7 @@ void mbedtls_memory_buffer_alloc_self_test( )
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
/* BEGIN_CASE */
|
||||
void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
int d_bytes,
|
||||
int free_a, int free_b, int free_c,
|
||||
@@ -40,8 +40,11 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL, *ptr_d = NULL,
|
||||
*ptr_e = NULL, *ptr_f = NULL;
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
size_t reported_blocks;
|
||||
size_t allocated_bytes = 0, reported_bytes;
|
||||
size_t reported_bytes;
|
||||
#endif
|
||||
size_t allocated_bytes = 0;
|
||||
|
||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||
|
||||
@@ -79,8 +82,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
allocated_bytes += d_bytes * sizeof(char);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||
TEST_ASSERT( reported_bytes == allocated_bytes );
|
||||
#endif
|
||||
|
||||
if( free_a )
|
||||
{
|
||||
@@ -118,8 +123,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
allocated_bytes -= d_bytes * sizeof(char);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||
TEST_ASSERT( reported_bytes == allocated_bytes );
|
||||
#endif
|
||||
|
||||
if( e_bytes > 0 )
|
||||
{
|
||||
@@ -179,8 +186,10 @@ void memory_buffer_alloc_free_alloc( int a_bytes, int b_bytes, int c_bytes,
|
||||
ptr_f = NULL;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||
TEST_ASSERT( reported_bytes == 0 );
|
||||
#endif
|
||||
|
||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||
|
||||
@@ -189,12 +198,14 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
void memory_buffer_alloc_oom_test()
|
||||
/* BEGIN_CASE */
|
||||
void memory_buffer_alloc_oom_test( )
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char *ptr_a = NULL, *ptr_b = NULL, *ptr_c = NULL;
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
size_t reported_blocks, reported_bytes;
|
||||
#endif
|
||||
|
||||
(void)ptr_c;
|
||||
|
||||
@@ -211,8 +222,10 @@ void memory_buffer_alloc_oom_test()
|
||||
ptr_c = mbedtls_calloc( 431, sizeof(char) );
|
||||
TEST_ASSERT( ptr_c == NULL );
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||
TEST_ASSERT( reported_bytes >= 864 && reported_bytes <= sizeof(buf) );
|
||||
#endif
|
||||
|
||||
mbedtls_free( ptr_a );
|
||||
ptr_a = NULL;
|
||||
@@ -222,8 +235,10 @@ void memory_buffer_alloc_oom_test()
|
||||
ptr_b = NULL;
|
||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_DEBUG)
|
||||
mbedtls_memory_buffer_alloc_cur_get( &reported_bytes, &reported_blocks );
|
||||
TEST_ASSERT( reported_bytes == 0 );
|
||||
#endif
|
||||
|
||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() == 0 );
|
||||
|
||||
@@ -232,17 +247,20 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
void memory_buffer_small_buffer( )
|
||||
/* BEGIN_CASE */
|
||||
void memory_buffer_heap_too_small( )
|
||||
{
|
||||
unsigned char buf[1];
|
||||
|
||||
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
|
||||
/* With MBEDTLS_MEMORY_DEBUG enabled, this prints a message
|
||||
* "FATAL: verification of first header failed".
|
||||
*/
|
||||
TEST_ASSERT( mbedtls_memory_buffer_alloc_verify() != 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_MEMORY_DEBUG */
|
||||
/* BEGIN_CASE */
|
||||
void memory_buffer_underalloc( )
|
||||
{
|
||||
unsigned char buf[100];
|
||||
|
||||
@@ -157,6 +157,93 @@ mbedtls_mpi_cmp_mpi:10:"2":10:"-3":1
|
||||
Base test mbedtls_mpi_cmp_mpi (Mixed values) #6
|
||||
mbedtls_mpi_cmp_mpi:10:"-2":10:"31231231289798":-1
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct #1
|
||||
mbedtls_mpi_lt_mpi_ct:1:"2B5":1:"2B5":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct #2
|
||||
mbedtls_mpi_lt_mpi_ct:1:"2B5":1:"2B4":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct #3
|
||||
mbedtls_mpi_lt_mpi_ct:1:"2B5":1:"2B6":1:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Negative values) #1
|
||||
mbedtls_mpi_lt_mpi_ct:1:"-2":1:"-2":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Negative values) #2
|
||||
mbedtls_mpi_lt_mpi_ct:1:"-2":1:"-3":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Negative values) #3
|
||||
mbedtls_mpi_lt_mpi_ct:1:"-2":1:"-1":1:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Mixed values) #1
|
||||
mbedtls_mpi_lt_mpi_ct:1:"-3":1:"2":1:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Mixed values) #2
|
||||
mbedtls_mpi_lt_mpi_ct:1:"2":1:"-3":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Mixed values) #3
|
||||
mbedtls_mpi_lt_mpi_ct:2:"-2":2:"1C67967269C6":1:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (X is longer in storage)
|
||||
mbedtls_mpi_lt_mpi_ct:3:"2B5":2:"2B5":0:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (Y is longer in storage)
|
||||
mbedtls_mpi_lt_mpi_ct:3:"2B5":4:"2B5":0:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 64 bit) #1
|
||||
mbedtls_mpi_lt_mpi_ct:2:"7FFFFFFFFFFFFFFF":2:"FF":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 64 bit) #2
|
||||
mbedtls_mpi_lt_mpi_ct:2:"8000000000000000":2:"7FFFFFFFFFFFFFFF":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 64 bit) #3
|
||||
mbedtls_mpi_lt_mpi_ct:2:"8000000000000000":2:"1":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 64 bit) #4
|
||||
mbedtls_mpi_lt_mpi_ct:2:"8000000000000000":2:"0":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 64 bit) #5
|
||||
mbedtls_mpi_lt_mpi_ct:2:"FFFFFFFFFFFFFFFF":2:"FF":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 32 bit) #1
|
||||
mbedtls_mpi_lt_mpi_ct:1:"7FFFFFFF":1:"FF":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 32 bit) #2
|
||||
mbedtls_mpi_lt_mpi_ct:1:"80000000":1:"7FFFFFFF":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 32 bit) #3
|
||||
mbedtls_mpi_lt_mpi_ct:1:"80000000":1:"1":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 32 bit) #4
|
||||
mbedtls_mpi_lt_mpi_ct:1:"80000000":1:"0":0:0
|
||||
|
||||
Base test mbedtls_mpi_lt_mpi_ct (corner case - 32 bit) #5
|
||||
mbedtls_mpi_lt_mpi_ct:1:"FFFFFFFF":1:"FF":0:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (X<Y, zero vs non-zero MS limb)
|
||||
mbedtls_mpi_lt_mpi_ct:2:"0FFFFFFFFFFFFFFFF":2:"1FFFFFFFFFFFFFFFF":1:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (X>Y, equal MS limbs)
|
||||
mbedtls_mpi_lt_mpi_ct:2:"-EEFFFFFFFFFFFFFFF1":2:"-EEFFFFFFFFFFFFFFFF":0:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (X=Y)
|
||||
mbedtls_mpi_lt_mpi_ct:2:"EEFFFFFFFFFFFFFFFF":2:"EEFFFFFFFFFFFFFFFF":0:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (X=-Y)
|
||||
mbedtls_mpi_lt_mpi_ct:2:"-EEFFFFFFFFFFFFFFFF":2:"EEFFFFFFFFFFFFFFFF":1:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (Alternating limbs) #1
|
||||
mbedtls_mpi_lt_mpi_ct:2:"11FFFFFFFFFFFFFFFF":2:"FF1111111111111111":1:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (Alternating limbs) #2
|
||||
mbedtls_mpi_lt_mpi_ct:2:"FF1111111111111111":2:"11FFFFFFFFFFFFFFFF":0:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (Alternating limbs) #3
|
||||
mbedtls_mpi_lt_mpi_ct:2:"-11FFFFFFFFFFFFFFFF":2:"-FF1111111111111111":0:0
|
||||
|
||||
Multi-limb mbedtls_mpi_lt_mpi_ct (Alternating limbs) #4
|
||||
mbedtls_mpi_lt_mpi_ct:2:"-FF1111111111111111":2:"-11FFFFFFFFFFFFFFFF":1:0
|
||||
|
||||
Base test mbedtls_mpi_cmp_abs #1
|
||||
mbedtls_mpi_cmp_abs:10:"693":10:"693":0
|
||||
|
||||
|
||||
@@ -332,6 +332,31 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_lt_mpi_ct( int size_X, char * input_X,
|
||||
int size_Y, char * input_Y,
|
||||
int input_ret, int input_err )
|
||||
{
|
||||
unsigned ret;
|
||||
unsigned input_uret = input_ret;
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, input_Y ) == 0 );
|
||||
|
||||
mbedtls_mpi_grow( &X, size_X );
|
||||
mbedtls_mpi_grow( &Y, size_Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_lt_mpi_ct( &X, &Y, &ret ) == input_err );
|
||||
if( input_err == 0 )
|
||||
TEST_ASSERT( ret == input_uret );
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_mpi_cmp_abs( int radix_X, char *input_X, int radix_Y, char *input_Y,
|
||||
int input_A )
|
||||
|
||||
@@ -125,18 +125,18 @@ void pk_rsa_verify_test_vec( char *message_hex_string, int digest,
|
||||
int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[128];
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
int msg_len;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof(result_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
@@ -166,9 +166,9 @@ void pk_rsa_verify_ext_test_vec( char *message_hex_string, int digest,
|
||||
int pk_type, int mgf1_hash_id, int salt_len,
|
||||
int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[128];
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_pk_rsassa_pss_options pss_opts;
|
||||
@@ -178,9 +178,9 @@ void pk_rsa_verify_ext_test_vec( char *message_hex_string, int digest,
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
@@ -289,9 +289,9 @@ void pk_rsa_encrypt_test_vec( char *message_hex, int mod,
|
||||
int radix_E, char *input_E,
|
||||
char *result_hex, int ret )
|
||||
{
|
||||
unsigned char message[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char result[1000];
|
||||
unsigned char message[16];
|
||||
unsigned char output[300];
|
||||
unsigned char result[256];
|
||||
size_t msg_len, olen, res_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_rsa_context *rsa;
|
||||
@@ -332,9 +332,9 @@ void pk_rsa_decrypt_test_vec( char *cipher_hex, int mod,
|
||||
int radix_E, char *input_E,
|
||||
char *clear_hex, int ret )
|
||||
{
|
||||
unsigned char clear[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char cipher[1000];
|
||||
unsigned char clear[16];
|
||||
unsigned char output[256];
|
||||
unsigned char cipher[256];
|
||||
size_t clear_len, olen, cipher_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
@@ -463,8 +463,8 @@ void pk_rsa_alt( )
|
||||
mbedtls_rsa_context raw;
|
||||
mbedtls_pk_context rsa, alt;
|
||||
mbedtls_pk_debug_item dbg_items[10];
|
||||
unsigned char hash[50], sig[1000];
|
||||
unsigned char msg[50], ciph[1000], test[1000];
|
||||
unsigned char hash[50], sig[64];
|
||||
unsigned char msg[50], ciph[64], test[50];
|
||||
size_t sig_len, ciph_len, test_len;
|
||||
int ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *message_hex_string, char *seed,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
unsigned char message_str[125];
|
||||
unsigned char output[128];
|
||||
unsigned char output_str[257];
|
||||
unsigned char rnd_buf[109];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
@@ -28,9 +28,9 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -61,9 +61,9 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
|
||||
int hash, char *result_hex_str, char *seed,
|
||||
char *message_hex_string, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char output[128];
|
||||
unsigned char output_str[257];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -74,9 +74,9 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@@ -91,7 +91,9 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char *input_P,
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, &output_len,
|
||||
message_str, output, sizeof( output ) ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
@@ -261,11 +263,11 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
unsigned char message_str[114];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[128];
|
||||
unsigned char output_str[257];
|
||||
unsigned char rnd_buf[20];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
size_t msg_len;
|
||||
@@ -277,11 +279,10 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@@ -319,9 +320,9 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[114];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[128];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
mbedtls_mpi N, E;
|
||||
@@ -329,9 +330,9 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char *input_N, int radix_E,
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
@@ -14,10 +14,10 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *message_hex_string, char *seed,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
unsigned char message_str[87];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
unsigned char rnd_buf[20];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
@@ -28,9 +28,9 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char *input_N, int radix_E,
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -61,9 +61,9 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
||||
int hash, char *result_hex_str, char *seed,
|
||||
char *message_hex_string, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[256];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -75,9 +75,9 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
||||
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@@ -92,11 +92,12 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char *input_P,
|
||||
|
||||
unhexify( message_str, message_hex_string );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str, output, 1000 ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, &output_len,
|
||||
message_str, output, sizeof( output ) ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
hexify( output_str, output, ctx.len );
|
||||
|
||||
TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
|
||||
}
|
||||
|
||||
@@ -114,11 +115,11 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char rnd_buf[1000];
|
||||
unsigned char message_str[255];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
unsigned char rnd_buf[20];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_buf_info info;
|
||||
@@ -131,10 +132,10 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char *input_P, int radix_Q,
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@@ -174,9 +175,9 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *message_hex_string, char *salt,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[255];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
mbedtls_mpi N, E;
|
||||
@@ -184,9 +185,9 @@ void pkcs1_rsassa_pss_verify( int mod, int radix_N, char *input_N, int radix_E,
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -222,19 +223,18 @@ void pkcs1_rsassa_pss_verify_ext( int mod,
|
||||
int result_simple,
|
||||
int result_full )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[163];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len, hash_len;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, ctx_hash );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ mbedtls_rsa_pkcs1_encrypt:"4E636AF98E40F3ADCFCCB698F4E80B9F":MBEDTLS_RSA_PKCS_V1
|
||||
|
||||
RSA PKCS1 Decrypt #1 (Verify)
|
||||
depends_on:MBEDTLS_PKCS1_V15
|
||||
mbedtls_rsa_pkcs1_decrypt:"a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":1000:"4E636AF98E40F3ADCFCCB698F4E80B9F":0
|
||||
mbedtls_rsa_pkcs1_decrypt:"a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":32:"4E636AF98E40F3ADCFCCB698F4E80B9F":0
|
||||
|
||||
RSA PKCS1 Encrypt #2 (Data too large)
|
||||
depends_on:MBEDTLS_PKCS1_V15
|
||||
@@ -275,7 +275,7 @@ mbedtls_rsa_pkcs1_encrypt:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c
|
||||
|
||||
RSA PKCS1 Decrypt #2 (Data too small)
|
||||
depends_on:MBEDTLS_PKCS1_V15
|
||||
mbedtls_rsa_pkcs1_decrypt:"deadbeafcafedeadbeeffedcba9876":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":1000:"4E636AF98E40F3ADCFCCB698F4E80B9F":MBEDTLS_ERR_RSA_PRIVATE_FAILED + MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
mbedtls_rsa_pkcs1_decrypt:"deadbeafcafedeadbeeffedcba9876":MBEDTLS_RSA_PKCS_V15:2048:16:"e79a373182bfaa722eb035f772ad2a9464bd842de59432c18bbab3a7dfeae318c9b915ee487861ab665a40bd6cda560152578e8579016c929df99fea05b4d64efca1d543850bc8164b40d71ed7f3fa4105df0fb9b9ad2a18ce182c8a4f4f975bea9aa0b9a1438a27a28e97ac8330ef37383414d1bd64607d6979ac050424fd17":16:"c6749cbb0db8c5a177672d4728a8b22392b2fc4d3b8361d5c0d5055a1b4e46d821f757c24eef2a51c561941b93b3ace7340074c058c9bb48e7e7414f42c41da4cccb5c2ba91deb30c586b7fb18af12a52995592ad139d3be429add6547e044becedaf31fa3b39421e24ee034fbf367d11f6b8f88ee483d163b431e1654ad3e89":16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":32:"4E636AF98E40F3ADCFCCB698F4E80B9F":MBEDTLS_ERR_RSA_PRIVATE_FAILED + MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
RSA PKCS1 Encrypt #3 (Invalid padding mode)
|
||||
mbedtls_rsa_pkcs1_encrypt:"4E636AF98E40F3ADCFCCB698F4E80B9F":2:2048:16:"b38ac65c8141f7f5c96e14470e851936a67bf94cc6821a39ac12c05f7c0b06d9e6ddba2224703b02e25f31452f9c4a8417b62675fdc6df46b94813bc7b9769a892c482b830bfe0ad42e46668ace68903617faf6681f4babf1cc8e4b0420d3c7f61dc45434c6b54e2c3ee0fc07908509d79c9826e673bf8363255adb0add2401039a7bcd1b4ecf0fbe6ec8369d2da486eec59559dd1d54c9b24190965eafbdab203b35255765261cd0909acf93c3b8b8428cbb448de4715d1b813d0c94829c229543d391ce0adab5351f97a3810c1f73d7b1458b97daed4209c50e16d064d2d5bfda8c23893d755222793146d0a78c3d64f35549141486c3b0961a7b4c1a2034f":16:"3":"a42eda41e56235e666e7faaa77100197f657288a1bf183e4820f0c37ce2c456b960278d6003e0bbcd4be4a969f8e8fd9231e1f492414f00ed09844994c86ec32db7cde3bec7f0c3dbf6ae55baeb2712fa609f5fc3207a824eb3dace31849cd6a6084318523912bccb84cf42e3c6d6d1685131d69bb545acec827d2b0dfdd5568b7dcc4f5a11d6916583fefa689d367f8c9e1d95dcd2240895a9470b0c1730f97cd6e8546860bd254801769f54be96e16362ddcbf34d56035028890199e0f48db38642cb66a4181e028a6443a404fea284ce02b4614b683367d40874e505611d23142d49f06feea831d52d347b13610b413c4efc43a6de9f0b08d2a951dc503b6":MBEDTLS_ERR_RSA_INVALID_PADDING
|
||||
|
||||
@@ -23,10 +23,11 @@ void mbedtls_rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int dig
|
||||
char *input_Q, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
int msg_len;
|
||||
@@ -36,10 +37,10 @@ void mbedtls_rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int dig
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@@ -80,9 +81,9 @@ void mbedtls_rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int d
|
||||
int mod, int radix_N, char *input_N, int radix_E,
|
||||
char *input_E, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
int msg_len;
|
||||
|
||||
@@ -90,9 +91,9 @@ void mbedtls_rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int d
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -122,10 +123,10 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
||||
char *input_N, int radix_E, char *input_E,
|
||||
char *result_hex_str )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
int hash_len;
|
||||
@@ -135,10 +136,10 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@@ -167,8 +168,8 @@ void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
|
||||
if( padding_mode == MBEDTLS_RSA_PKCS_V15 )
|
||||
{
|
||||
int res;
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
res = mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx,
|
||||
&rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE,
|
||||
@@ -203,10 +204,10 @@ void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
|
||||
char *input_N, int radix_E, char *input_E,
|
||||
char *result_hex_str, int correct )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char hash_result[1000];
|
||||
unsigned char result_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char message_str[128];
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char result_str[256];
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t hash_len;
|
||||
|
||||
@@ -214,11 +215,10 @@ void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( hash_result, 0x00, 1000 );
|
||||
memset( result_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( result_str, 0x00, sizeof( result_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
@@ -276,9 +276,9 @@ void mbedtls_rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int
|
||||
int radix_N, char *input_N, int radix_E, char *input_E,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[256];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -289,9 +289,9 @@ void mbedtls_rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -324,9 +324,9 @@ void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
|
||||
int radix_E, char *input_E,
|
||||
char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[16];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t msg_len;
|
||||
|
||||
@@ -334,9 +334,9 @@ void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -369,9 +369,9 @@ void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int
|
||||
int radix_N, char *input_N, int radix_E, char *input_E,
|
||||
int max_output, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[256];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -381,10 +381,9 @@ void mbedtls_rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
|
||||
@@ -420,19 +419,18 @@ exit:
|
||||
void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *input_N,
|
||||
int radix_E, char *input_E, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[256];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
@@ -458,8 +456,8 @@ void mbedtls_rsa_public( char *message_hex_string, int mod, int radix_N, char *i
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx2 ) == 0 );
|
||||
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
TEST_ASSERT( mbedtls_rsa_public( &ctx2, message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
@@ -480,9 +478,9 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
||||
int radix_Q, char *input_Q, int radix_N, char *input_N,
|
||||
int radix_E, char *input_E, char *result_hex_str, int result )
|
||||
{
|
||||
unsigned char message_str[1000];
|
||||
unsigned char output[1000];
|
||||
unsigned char output_str[1000];
|
||||
unsigned char message_str[256];
|
||||
unsigned char output[256];
|
||||
unsigned char output_str[513];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_pseudo_info rnd_info;
|
||||
@@ -493,7 +491,7 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
memset( message_str, 0x00, 1000 );
|
||||
memset( message_str, 0x00, sizeof( message_str ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@@ -511,8 +509,8 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
||||
/* repeat three times to test updating of blinding values */
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, rnd_pseudo_rand, &rnd_info,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
@@ -531,8 +529,8 @@ void mbedtls_rsa_private( char *message_hex_string, int mod, int radix_P, char *
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx2 ) == 0 );
|
||||
|
||||
memset( output, 0x00, 1000 );
|
||||
memset( output_str, 0x00, 1000 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( output_str, 0x00, sizeof( output_str ) );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx2, rnd_pseudo_rand, &rnd_info,
|
||||
message_str, output ) == result );
|
||||
if( result == 0 )
|
||||
@@ -1197,11 +1195,11 @@ void mbedtls_rsa_export_raw( char *input_N, char *input_P,
|
||||
int successive )
|
||||
{
|
||||
/* Original raw buffers with which we set up the RSA context */
|
||||
unsigned char bufN[1000];
|
||||
unsigned char bufP[1000];
|
||||
unsigned char bufQ[1000];
|
||||
unsigned char bufD[1000];
|
||||
unsigned char bufE[1000];
|
||||
unsigned char bufN[256];
|
||||
unsigned char bufP[128];
|
||||
unsigned char bufQ[128];
|
||||
unsigned char bufD[256];
|
||||
unsigned char bufE[1];
|
||||
|
||||
size_t lenN = 0;
|
||||
size_t lenP = 0;
|
||||
@@ -1329,11 +1327,11 @@ void mbedtls_rsa_import_raw( char *input_N,
|
||||
int res_check,
|
||||
int res_complete )
|
||||
{
|
||||
unsigned char bufN[1000];
|
||||
unsigned char bufP[1000];
|
||||
unsigned char bufQ[1000];
|
||||
unsigned char bufD[1000];
|
||||
unsigned char bufE[1000];
|
||||
unsigned char bufN[256];
|
||||
unsigned char bufP[128];
|
||||
unsigned char bufQ[128];
|
||||
unsigned char bufD[256];
|
||||
unsigned char bufE[1];
|
||||
|
||||
/* Buffers used for encryption-decryption test */
|
||||
unsigned char *buf_orig = NULL;
|
||||
|
||||
Reference in New Issue
Block a user