mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge remote-tracking branch 'mbedtls-2.28' into calloc-also-zeroizes-2-28
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,5 +1,7 @@
|
||||
# Random seed file created by test scripts and sample programs
|
||||
seedfile
|
||||
# MBEDTLS_PSA_INJECT_ENTROPY seed file created by the test framework
|
||||
00000000ffffff52.psa_its
|
||||
|
||||
# CMake build artifacts:
|
||||
CMakeCache.txt
|
||||
@ -28,6 +30,9 @@ massif-*
|
||||
.project
|
||||
/.settings
|
||||
|
||||
# Unix-like build artifacts:
|
||||
*.o
|
||||
|
||||
# MSVC build artifacts:
|
||||
*.exe
|
||||
*.pdb
|
||||
@ -65,3 +70,6 @@ massif-*
|
||||
/TAGS
|
||||
/cscope*.out
|
||||
/tags
|
||||
|
||||
# Clangd compilation database
|
||||
compile_commands.json
|
||||
|
@ -12,7 +12,7 @@ build:
|
||||
python: "3.9"
|
||||
jobs:
|
||||
pre_build:
|
||||
- make apidoc
|
||||
- ./scripts/apidoc_full.sh
|
||||
- breathe-apidoc -o docs/api apidoc/xml
|
||||
|
||||
# Build documentation in the docs/ directory with Sphinx
|
||||
|
1
3rdparty/everest/.gitignore
vendored
1
3rdparty/everest/.gitignore
vendored
@ -1,2 +1 @@
|
||||
*.o
|
||||
Makefile
|
||||
|
@ -76,6 +76,6 @@ The following branches are currently maintained:
|
||||
- [`development`](https://github.com/Mbed-TLS/mbedtls/)
|
||||
- [`mbedtls-2.28`](https://github.com/Mbed-TLS/mbedtls/tree/mbedtls-2.28)
|
||||
maintained until at least the end of 2024, see
|
||||
<https://github.com/Mbed-TLS/mbedtls/releases/tag/v2.28.3>.
|
||||
<https://github.com/Mbed-TLS/mbedtls/releases/tag/v2.28.4>.
|
||||
|
||||
Users are urged to always use the latest version of a maintained branch.
|
||||
|
@ -135,6 +135,10 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
FORCE)
|
||||
endif()
|
||||
|
||||
# Make MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE into PATHs
|
||||
set(MBEDTLS_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS config file (overrides default).")
|
||||
set(MBEDTLS_USER_CONFIG_FILE "" CACHE FILEPATH "Mbed TLS user config file (appended to default).")
|
||||
|
||||
# Create a symbolic link from ${base_name} in the binary directory
|
||||
# to the corresponding path in the source directory.
|
||||
# Note: Copies the file(s) on Windows.
|
||||
@ -219,7 +223,9 @@ if(CMAKE_COMPILER_IS_CLANG)
|
||||
endif(CMAKE_COMPILER_IS_CLANG)
|
||||
|
||||
if(CMAKE_COMPILER_IS_IAR)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts -Ohz")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warn_about_c_style_casts")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-Ohz")
|
||||
set(CMAKE_C_FLAGS_DEBUG "--debug -On")
|
||||
endif(CMAKE_COMPILER_IS_IAR)
|
||||
|
||||
if(CMAKE_COMPILER_IS_MSVC)
|
||||
@ -242,7 +248,7 @@ if(MBEDTLS_FATAL_WARNINGS)
|
||||
endif(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU)
|
||||
|
||||
if (CMAKE_COMPILER_IS_IAR)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warning_are_errors")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --warnings_are_errors")
|
||||
endif(CMAKE_COMPILER_IS_IAR)
|
||||
endif(MBEDTLS_FATAL_WARNINGS)
|
||||
|
||||
@ -304,6 +310,20 @@ if(ENABLE_TESTING OR ENABLE_PROGRAMS)
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/everest/include)
|
||||
|
||||
# Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE
|
||||
if(MBEDTLS_CONFIG_FILE)
|
||||
target_compile_definitions(mbedtls_test
|
||||
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
|
||||
target_compile_definitions(mbedtls_test_helpers
|
||||
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
|
||||
endif()
|
||||
if(MBEDTLS_USER_CONFIG_FILE)
|
||||
target_compile_definitions(mbedtls_test
|
||||
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
|
||||
target_compile_definitions(mbedtls_test_helpers
|
||||
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_PROGRAMS)
|
||||
|
30
ChangeLog
30
ChangeLog
@ -1,5 +1,35 @@
|
||||
Mbed TLS ChangeLog (Sorted per branch, date)
|
||||
|
||||
= Mbed TLS 2.28.4 branch released 2023-08-04
|
||||
|
||||
Features
|
||||
* Allow MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE to be set by
|
||||
setting the CMake variable of the same name at configuration time.
|
||||
|
||||
Bugfix
|
||||
* Fix crypt_and_hash decryption fail when used with a stream cipher
|
||||
mode of operation, due to the input not being a multiple of the block
|
||||
size. Resolves #7417.
|
||||
* Fix a bug where mbedtls_x509_string_to_names() would return success
|
||||
when given a invalid name string, if it did not contain '=' or ','.
|
||||
* Fix missing PSA initialization in sample programs when
|
||||
MBEDTLS_USE_PSA_CRYPTO is enabled.
|
||||
* Fix clang and armclang compilation error when targeting certain Arm
|
||||
M-class CPUs (Cortex-M0, Cortex-M0+, Cortex-M1, Cortex-M23,
|
||||
SecurCore SC000). Fixes #1077.
|
||||
* Fixed an issue that caused compile errors when using CMake and the IAR
|
||||
toolchain.
|
||||
* Fix the build with MBEDTLS_PSA_INJECT_ENTROPY. Fixes #7516.
|
||||
* Fix builds on Windows with clang.
|
||||
* Fix compilation warnings in aes.c for certain combinations
|
||||
of configuration options.
|
||||
* Fix a compilation error on some platforms when including mbedtls/ssl.h
|
||||
with all TLS support disabled. Fixes #6628.
|
||||
|
||||
Changes
|
||||
* Update test data to avoid failures of unit tests after 2023-08-07, and
|
||||
update expiring certififcates in the certs module.
|
||||
|
||||
= Mbed TLS 2.28.3 branch released 2023-03-28
|
||||
|
||||
Features
|
||||
|
@ -21,6 +21,9 @@ We generally don't include changelog entries for:
|
||||
* Performance improvements, unless they are particularly significant.
|
||||
* Changes to parts of the code base that users don't interact with directly,
|
||||
such as test code and test data.
|
||||
* Fixes for compiler warnings. Releases typically contain a number of fixes
|
||||
of this kind, so we will only mention them in the Changelog if they are
|
||||
particularly significant.
|
||||
|
||||
Until Mbed TLS 2.24.0, we required changelog entries in more cases.
|
||||
Looking at older changelog entries is good practice for how to write a
|
||||
|
@ -0,0 +1,3 @@
|
||||
Features
|
||||
* The documentation of mbedtls_ecp_group now describes the optimized
|
||||
representation of A for some curves. Fixes #8045.
|
4
ChangeLog.d/x509-ec-algorithm-identifier-fix.txt
Normal file
4
ChangeLog.d/x509-ec-algorithm-identifier-fix.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* Fix x509 certificate generation to conform to RFC 5480 / RFC 5758 when
|
||||
using ECC key. The certificate was rejected by some crypto frameworks.
|
||||
Fixes #2924.
|
@ -48,7 +48,7 @@ You need the following tools to build the library with the provided makefiles:
|
||||
|
||||
* GNU Make or a build tool that CMake supports.
|
||||
* A C99 toolchain (compiler, linker, archiver). We actively test with GCC 5.4, Clang 3.8, IAR8 and Visual Studio 2013. More recent versions should work. Slightly older versions may work.
|
||||
* Python 3 to generate the test code.
|
||||
* Python 3.6 or later to generate the test code.
|
||||
* Perl to run the tests.
|
||||
|
||||
### Make
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define MBEDTLS_HAVE_TIME
|
||||
#define MBEDTLS_HAVE_TIME_DATE
|
||||
|
||||
/* Mbed Crypto feature support */
|
||||
/* Mbed TLS feature support */
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_CIPHER_MODE_CFB
|
||||
#define MBEDTLS_CIPHER_MODE_CTR
|
||||
@ -45,7 +45,7 @@
|
||||
#define MBEDTLS_USE_PSA_CRYPTO
|
||||
#define MBEDTLS_VERSION_FEATURES
|
||||
|
||||
/* Mbed Crypto modules */
|
||||
/* Mbed TLS modules */
|
||||
#define MBEDTLS_AES_C
|
||||
#define MBEDTLS_ARC4_C
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
|
@ -1,7 +1,9 @@
|
||||
Mbed Crypto storage specification
|
||||
Mbed TLS storage specification
|
||||
=================================
|
||||
|
||||
This document specifies how Mbed Crypto uses storage.
|
||||
This document specifies how Mbed TLS uses storage.
|
||||
Key storage was originally introduced in a product called Mbed Crypto, which was re-distributed via Mbed TLS and has since been merged into Mbed TLS.
|
||||
This document contains historical information both from before and after this merge.
|
||||
|
||||
Mbed Crypto may be upgraded on an existing device with the storage preserved. Therefore:
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Mbed Crypto driver interface test strategy
|
||||
# Mbed TLS driver interface test strategy
|
||||
|
||||
This document describes the test strategy for the driver interfaces in Mbed Crypto. Mbed Crypto has interfaces for secure element drivers, accelerator drivers and entropy drivers. This document is about testing Mbed Crypto itself; testing drivers is out of scope.
|
||||
This document describes the test strategy for the driver interfaces in Mbed TLS. Mbed TLS has interfaces for secure element drivers, accelerator drivers and entropy drivers. This document is about testing Mbed TLS itself; testing drivers is out of scope.
|
||||
|
||||
The driver interfaces are standardized through PSA Cryptography functional specifications.
|
||||
|
||||
@ -16,9 +16,9 @@ Drivers exposing this interface need to be registered at compile time by declari
|
||||
|
||||
#### Dynamic secure element driver interface
|
||||
|
||||
The dynamic secure element driver interface (SE interface for short) is defined by [`psa/crypto_se_driver.h`](../../../include/psa/crypto_se_driver.h). This is an interface between Mbed Crypto and one or more third-party drivers.
|
||||
The dynamic secure element driver interface (SE interface for short) is defined by [`psa/crypto_se_driver.h`](../../../include/psa/crypto_se_driver.h). This is an interface between Mbed TLS and one or more third-party drivers.
|
||||
|
||||
The SE interface consists of one function provided by Mbed Crypto (`psa_register_se_driver`) and many functions that drivers must implement. To make a driver usable by Mbed Crypto, the initialization code must call `psa_register_se_driver` with a structure that describes the driver. The structure mostly contains function pointers, pointing to the driver's methods. All calls to a driver function are triggered by a call to a PSA crypto API function.
|
||||
The SE interface consists of one function provided by Mbed TLS (`psa_register_se_driver`) and many functions that drivers must implement. To make a driver usable by Mbed TLS, the initialization code must call `psa_register_se_driver` with a structure that describes the driver. The structure mostly contains function pointers, pointing to the driver's methods. All calls to a driver function are triggered by a call to a PSA crypto API function.
|
||||
|
||||
### SE driver interface unit tests
|
||||
|
||||
@ -57,7 +57,7 @@ For each API function that can lead to a driver call (more precisely, for each d
|
||||
|
||||
#### SE driver outputs
|
||||
|
||||
For each API function that leads to a driver call, call it with parameters that cause a driver to be invoked and check how Mbed Crypto handles the outputs.
|
||||
For each API function that leads to a driver call, call it with parameters that cause a driver to be invoked and check how Mbed TLS handles the outputs.
|
||||
|
||||
* Correct outputs.
|
||||
* Incorrect outputs such as an invalid output length.
|
||||
|
@ -47,7 +47,7 @@ The PSA subsystem provides storage on top of the PSA trusted storage interface.
|
||||
* [Storage transaction file](#storage-transaction-resumption).
|
||||
* [Driver state files](#driver-state-files).
|
||||
|
||||
For a more detailed description, refer to the [Mbed Crypto storage specification](../mbed-crypto-storage-specification.md).
|
||||
For a more detailed description, refer to the [Mbed TLS storage specification](../mbed-crypto-storage-specification.md).
|
||||
|
||||
In addition, Mbed TLS includes an implementation of the PSA trusted storage interface on top of C stdio. This document addresses the test strategy for [PSA ITS over file](#psa-its-over-file) in a separate section below.
|
||||
|
||||
|
@ -30,17 +30,23 @@ Each test case has a description which succinctly describes for a human audience
|
||||
|
||||
#### SSL test case descriptions
|
||||
|
||||
Each test case in `ssl-opt.sh` has a description which succinctly describes for a human audience what the test does. The test description is the first parameter to `run_tests`.
|
||||
Each test case in `ssl-opt.sh` has a description which succinctly describes for a human audience what the test does. The test description is the first parameter to `run_test`.
|
||||
|
||||
The same rules and guidelines apply as for [unit test descriptions](#unit-test-descriptions). In addition, the description must be written on the same line as `run_test`, in double quotes, for the sake of `check_test_cases.py`.
|
||||
|
||||
### SSL cipher suite tests
|
||||
|
||||
Each test case in `compat.sh` has a description which succinctly describes for a human audience what the test does. The test description is `$TITLE` defined in `run_client`.
|
||||
|
||||
The same rules and guidelines apply as for [unit test descriptions](#unit-test-descriptions). In addition, failure cause in `compat.sh` is not classified as `ssl-opt.sh`, so the information of failed log files are followed as prompt.
|
||||
|
||||
## Running tests
|
||||
|
||||
### Outcome file
|
||||
|
||||
#### Generating an outcome file
|
||||
|
||||
Unit tests and `ssl-opt.sh` record the outcome of each test case in a **test outcome file**. This feature is enabled if the environment variable `MBEDTLS_TEST_OUTCOME_FILE` is set. Set it to the path of the desired file.
|
||||
Unit tests, `ssl-opt.sh` and `compat.sh` record the outcome of each test case in a **test outcome file**. This feature is enabled if the environment variable `MBEDTLS_TEST_OUTCOME_FILE` is set. Set it to the path of the desired file.
|
||||
|
||||
If you run `all.sh --outcome-file test-outcome.csv`, this collects the outcome of all the test cases in `test-outcome.csv`.
|
||||
|
||||
@ -52,7 +58,7 @@ The outcome file has 6 fields:
|
||||
|
||||
* **Platform**: a description of the platform, e.g. `Linux-x86_64` or `Linux-x86_64-gcc7-msan`.
|
||||
* **Configuration**: a unique description of the configuration (`config.h`).
|
||||
* **Test suite**: `test_suite_xxx` or `ssl-opt`.
|
||||
* **Test suite**: `test_suite_xxx`, `ssl-opt` or `compat`.
|
||||
* **Test case**: the description of the test case.
|
||||
* **Result**: one of `PASS`, `SKIP` or `FAIL`.
|
||||
* **Cause**: more information explaining the result.
|
||||
|
@ -22,73 +22,10 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage mbed TLS v2.28.3 source code documentation
|
||||
* @mainpage Mbed TLS v2.28.4 API Documentation
|
||||
*
|
||||
* This documentation describes the internal structure of mbed TLS. It was
|
||||
* This documentation describes the internal structure of Mbed TLS. It was
|
||||
* automatically generated from specially formatted comment blocks in
|
||||
* mbed TLS's source code using Doxygen. (See
|
||||
* http://www.stack.nl/~dimitri/doxygen/ for more information on Doxygen)
|
||||
*
|
||||
* mbed TLS has a simple setup: it provides the ingredients for an SSL/TLS
|
||||
* implementation. These ingredients are listed as modules in the
|
||||
* \ref mainpage_modules "Modules section". This "Modules section" introduces
|
||||
* the high-level module concepts used throughout this documentation.\n
|
||||
* Some examples of mbed TLS usage can be found in the \ref mainpage_examples
|
||||
* "Examples section".
|
||||
*
|
||||
* @section mainpage_modules Modules
|
||||
*
|
||||
* mbed TLS supports SSLv3 up to TLSv1.2 communication by providing the
|
||||
* following:
|
||||
* - TCP/IP communication functions: listen, connect, accept, read/write.
|
||||
* - SSL/TLS communication functions: init, handshake, read/write.
|
||||
* - X.509 functions: CRT, CRL and key handling
|
||||
* - Random number generation
|
||||
* - Hashing
|
||||
* - Encryption/decryption
|
||||
*
|
||||
* Above functions are split up neatly into logical interfaces. These can be
|
||||
* used separately to provide any of the above functions or to mix-and-match
|
||||
* into an SSL server/client solution that utilises a X.509 PKI. Examples of
|
||||
* such implementations are amply provided with the source code.
|
||||
*
|
||||
* Note that mbed TLS does not provide a control channel or (multiple) session
|
||||
* handling without additional work from the developer.
|
||||
*
|
||||
* @section mainpage_examples Examples
|
||||
*
|
||||
* Example server setup:
|
||||
*
|
||||
* \b Prerequisites:
|
||||
* - X.509 certificate and private key
|
||||
* - session handling functions
|
||||
*
|
||||
* \b Setup:
|
||||
* - Load your certificate and your private RSA key (X.509 interface)
|
||||
* - Setup the listening TCP socket (TCP/IP interface)
|
||||
* - Accept incoming client connection (TCP/IP interface)
|
||||
* - Initialise as an SSL-server (SSL/TLS interface)
|
||||
* - Set parameters, e.g. authentication, ciphers, CA-chain, key exchange
|
||||
* - Set callback functions RNG, IO, session handling
|
||||
* - Perform an SSL-handshake (SSL/TLS interface)
|
||||
* - Read/write data (SSL/TLS interface)
|
||||
* - Close and cleanup (all interfaces)
|
||||
*
|
||||
* Example client setup:
|
||||
*
|
||||
* \b Prerequisites:
|
||||
* - X.509 certificate and private key
|
||||
* - X.509 trusted CA certificates
|
||||
*
|
||||
* \b Setup:
|
||||
* - Load the trusted CA certificates (X.509 interface)
|
||||
* - Load your certificate and your private RSA key (X.509 interface)
|
||||
* - Setup a TCP/IP connection (TCP/IP interface)
|
||||
* - Initialise as an SSL-client (SSL/TLS interface)
|
||||
* - Set parameters, e.g. authentication mode, ciphers, CA-chain, session
|
||||
* - Set callback functions RNG, IO
|
||||
* - Perform an SSL-handshake (SSL/TLS interface)
|
||||
* - Verify the server certificate (SSL/TLS interface)
|
||||
* - Write/read data (SSL/TLS interface)
|
||||
* - Close and cleanup (all interfaces)
|
||||
* Mbed TLS's source code using Doxygen. (See
|
||||
* https://www.doxygen.nl for more information on Doxygen)
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
PROJECT_NAME = "mbed TLS v2.28.3"
|
||||
PROJECT_NAME = "mbed TLS v2.28.4"
|
||||
OUTPUT_DIRECTORY = ../apidoc/
|
||||
FULL_PATH_NAMES = NO
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
|
@ -274,10 +274,6 @@ int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
|
||||
* \brief This function performs an ARIA-CTR encryption or decryption
|
||||
* operation.
|
||||
*
|
||||
* This function performs the operation defined in the \p mode
|
||||
* parameter (encrypt/decrypt), on the input data buffer
|
||||
* defined in the \p input parameter.
|
||||
*
|
||||
* Due to the nature of CTR, you must use the same key schedule
|
||||
* for both encryption and decryption operations. Therefore, you
|
||||
* must use the context initialized with mbedtls_aria_setkey_enc()
|
||||
|
@ -453,7 +453,7 @@ void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq);
|
||||
* on a successful invocation.
|
||||
* \param end The end of the ASN.1 SEQUENCE container.
|
||||
* \param tag_must_mask A mask to be applied to the ASN.1 tags found within
|
||||
* the SEQUENCE before comparing to \p tag_must_value.
|
||||
* the SEQUENCE before comparing to \p tag_must_val.
|
||||
* \param tag_must_val The required value of each ASN.1 tag found in the
|
||||
* SEQUENCE, after masking with \p tag_must_mask.
|
||||
* Mismatching tags lead to an error.
|
||||
@ -462,7 +462,7 @@ void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq);
|
||||
* while a value of \c 0xFF for \p tag_must_mask means
|
||||
* that \p tag_must_val is the only allowed tag.
|
||||
* \param tag_may_mask A mask to be applied to the ASN.1 tags found within
|
||||
* the SEQUENCE before comparing to \p tag_may_value.
|
||||
* the SEQUENCE before comparing to \p tag_may_val.
|
||||
* \param tag_may_val The desired value of each ASN.1 tag found in the
|
||||
* SEQUENCE, after masking with \p tag_may_mask.
|
||||
* Mismatching tags will be silently ignored.
|
||||
|
@ -158,6 +158,27 @@ int mbedtls_asn1_write_algorithm_identifier(unsigned char **p,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len);
|
||||
|
||||
/**
|
||||
* \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
|
||||
*
|
||||
* \note This function works backwards in data buffer.
|
||||
*
|
||||
* \param p The reference to the current position pointer.
|
||||
* \param start The start of the buffer, for bounds-checking.
|
||||
* \param oid The OID of the algorithm to write.
|
||||
* \param oid_len The length of the algorithm's OID.
|
||||
* \param par_len The length of the parameters, which must be already written.
|
||||
* \param has_par If there are any parameters. If 0, par_len must be 0. If 1
|
||||
* and \p par_len is 0, NULL parameters are added.
|
||||
*
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_algorithm_identifier_ext(unsigned char **p,
|
||||
unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len, int has_par);
|
||||
|
||||
/**
|
||||
* \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
|
||||
* in ASN.1 format.
|
||||
|
@ -533,7 +533,7 @@ int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X,
|
||||
* \param X The destination MPI. This must point to an initialized MPI.
|
||||
* \param buf The input buffer. This must be a readable buffer of length
|
||||
* \p buflen Bytes.
|
||||
* \param buflen The length of the input buffer \p p in Bytes.
|
||||
* \param buflen The length of the input buffer \p buf in Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
@ -548,7 +548,7 @@ int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf,
|
||||
* \param X The destination MPI. This must point to an initialized MPI.
|
||||
* \param buf The input buffer. This must be a readable buffer of length
|
||||
* \p buflen Bytes.
|
||||
* \param buflen The length of the input buffer \p p in Bytes.
|
||||
* \param buflen The length of the input buffer \p buf in Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
@ -986,8 +986,8 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p N is less than
|
||||
* or equal to one.
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p has no modular inverse
|
||||
* with respect to \p N.
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p A has no modular
|
||||
* inverse with respect to \p N.
|
||||
*/
|
||||
int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *N);
|
||||
|
@ -677,6 +677,15 @@
|
||||
#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
|
||||
|
||||
#if defined(__thumb__) && !defined(__thumb2__)
|
||||
#if !defined(__ARMCC_VERSION) && !defined(__clang__) \
|
||||
&& !defined(__llvm__) && !defined(__INTEL_COMPILER)
|
||||
/*
|
||||
* Thumb 1 ISA. This code path has only been tested successfully on gcc;
|
||||
* it does not compile on clang or armclang.
|
||||
*
|
||||
* Other compilers which define __GNUC__ may not work. The above macro
|
||||
* attempts to exclude these untested compilers.
|
||||
*/
|
||||
|
||||
#define MULADDC_INIT \
|
||||
asm( \
|
||||
@ -731,6 +740,8 @@
|
||||
"r6", "r7", "r8", "r9", "cc" \
|
||||
);
|
||||
|
||||
#endif /* Compiler is gcc */
|
||||
|
||||
#elif (__ARM_ARCH >= 6) && \
|
||||
defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)
|
||||
|
||||
|
@ -231,7 +231,7 @@ int mbedtls_camellia_crypt_cfb128(mbedtls_camellia_context *ctx,
|
||||
* *note Due to the nature of CTR mode, you should use the same
|
||||
* key for both encryption and decryption. In particular, calls
|
||||
* to this function should be preceded by a key-schedule via
|
||||
* mbedtls_camellia_setkey_enc() regardless of whether \p mode
|
||||
* mbedtls_camellia_setkey_enc() regardless of whether the mode
|
||||
* is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
|
||||
*
|
||||
* \warning You must never reuse a nonce value with the same key. Doing so
|
||||
|
@ -427,7 +427,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(const mbedtls_ciphe
|
||||
const mbedtls_cipher_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief This function initializes a \p cipher_context as NONE.
|
||||
* \brief This function initializes a \p ctx as NONE.
|
||||
*
|
||||
* \param ctx The context to be initialized. This must not be \c NULL.
|
||||
*/
|
||||
@ -602,7 +602,7 @@ static inline const char *mbedtls_cipher_get_name(
|
||||
* \param ctx The context of the cipher. This must be initialized.
|
||||
*
|
||||
* \return The key length of the cipher in bits.
|
||||
* \return #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been
|
||||
* \return #MBEDTLS_KEY_LENGTH_NONE if \p ctx has not been
|
||||
* initialized.
|
||||
*/
|
||||
static inline int mbedtls_cipher_get_key_bitlen(
|
||||
@ -779,7 +779,7 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx,
|
||||
* \param ctx The generic cipher context. This must be initialized and
|
||||
* bound to a key.
|
||||
* \param output The buffer to write data to. This needs to be a writable
|
||||
* buffer of at least \p block_size Bytes.
|
||||
* buffer of at least block_size Bytes.
|
||||
* \param olen The length of the data written to the \p output buffer.
|
||||
* This may not be \c NULL.
|
||||
*
|
||||
|
@ -1490,8 +1490,8 @@
|
||||
* );
|
||||
* ```
|
||||
* The \c context value is initialized to 0 before the first call.
|
||||
* The function must fill the \c output buffer with \p output_size bytes
|
||||
* of random data and set \c *output_length to \p output_size.
|
||||
* The function must fill the \c output buffer with \c output_size bytes
|
||||
* of random data and set \c *output_length to \c output_size.
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C
|
||||
*
|
||||
|
@ -266,8 +266,9 @@ int mbedtls_ecdsa_sign_det(mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
* \param md_alg The hash algorithm used to hash the original data.
|
||||
* \param f_rng_blind The RNG function used for blinding. This must not be
|
||||
* \c NULL.
|
||||
* \param p_rng_blind The RNG context to be passed to \p f_rng. This may be
|
||||
* \c NULL if \p f_rng doesn't need a context parameter.
|
||||
* \param p_rng_blind The RNG context to be passed to \p f_rng_blind. This
|
||||
* may be \c NULL if \p f_rng_blind doesn't need
|
||||
* a context parameter.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
|
||||
@ -344,7 +345,7 @@ int mbedtls_ecdsa_verify(mbedtls_ecp_group *grp,
|
||||
* via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
|
||||
* \param md_alg The message digest that was used to hash the message.
|
||||
* \param hash The message hash to be signed. This must be a readable
|
||||
* buffer of length \p blen Bytes.
|
||||
* buffer of length \p hlen Bytes.
|
||||
* \param hlen The length of the hash \p hash in Bytes.
|
||||
* \param sig The buffer to which to write the signature. This must be a
|
||||
* writable buffer of length at least twice as large as the
|
||||
@ -386,7 +387,7 @@ int mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx,
|
||||
* via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
|
||||
* \param md_alg The message digest that was used to hash the message.
|
||||
* \param hash The message hash to be signed. This must be a readable
|
||||
* buffer of length \p blen Bytes.
|
||||
* buffer of length \p hlen Bytes.
|
||||
* \param hlen The length of the hash \p hash in Bytes.
|
||||
* \param sig The buffer to which to write the signature. This must be a
|
||||
* writable buffer of length at least twice as large as the
|
||||
@ -453,7 +454,7 @@ int mbedtls_ecdsa_write_signature_restartable(mbedtls_ecdsa_context *ctx,
|
||||
* and have a group and private key bound to it, for example
|
||||
* via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
|
||||
* \param hash The message hash to be signed. This must be a readable
|
||||
* buffer of length \p blen Bytes.
|
||||
* buffer of length \p hlen Bytes.
|
||||
* \param hlen The length of the hash \p hash in Bytes.
|
||||
* \param sig The buffer to which to write the signature. This must be a
|
||||
* writable buffer of length at least twice as large as the
|
||||
@ -490,7 +491,7 @@ int mbedtls_ecdsa_write_signature_det(mbedtls_ecdsa_context *ctx,
|
||||
* \param ctx The ECDSA context to use. This must be initialized
|
||||
* and have a group and public key bound to it.
|
||||
* \param hash The message hash that was signed. This must be a readable
|
||||
* buffer of length \p size Bytes.
|
||||
* buffer of length \p hlen Bytes.
|
||||
* \param hlen The size of the hash \p hash.
|
||||
* \param sig The signature to read and verify. This must be a readable
|
||||
* buffer of length \p slen Bytes.
|
||||
@ -520,7 +521,7 @@ int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context *ctx,
|
||||
* \param ctx The ECDSA context to use. This must be initialized
|
||||
* and have a group and public key bound to it.
|
||||
* \param hash The message hash that was signed. This must be a readable
|
||||
* buffer of length \p size Bytes.
|
||||
* buffer of length \p hlen Bytes.
|
||||
* \param hlen The size of the hash \p hash.
|
||||
* \param sig The signature to read and verify. This must be a readable
|
||||
* buffer of length \p slen Bytes.
|
||||
|
@ -42,6 +42,11 @@
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ECP error codes
|
||||
*/
|
||||
@ -236,6 +241,27 @@ mbedtls_ecp_point;
|
||||
* odd prime as mbedtls_ecp_mul() requires an odd number, and
|
||||
* mbedtls_ecdsa_sign() requires that it is prime for blinding purposes.
|
||||
*
|
||||
* The default implementation only initializes \p A without setting it to the
|
||||
* authentic value for curves with <code>A = -3</code>(SECP256R1, etc), in which
|
||||
* case you need to load \p A by yourself when using domain parameters directly,
|
||||
* for example:
|
||||
* \code
|
||||
* mbedtls_mpi_init(&A);
|
||||
* mbedtls_ecp_group_init(&grp);
|
||||
* CHECK_RETURN(mbedtls_ecp_group_load(&grp, grp_id));
|
||||
* if (mbedtls_ecp_group_a_is_minus_3(&grp)) {
|
||||
* CHECK_RETURN(mbedtls_mpi_sub_int(&A, &grp.P, 3));
|
||||
* } else {
|
||||
* CHECK_RETURN(mbedtls_mpi_copy(&A, &grp.A));
|
||||
* }
|
||||
*
|
||||
* do_something_with_a(&A);
|
||||
*
|
||||
* cleanup:
|
||||
* mbedtls_mpi_free(&A);
|
||||
* mbedtls_ecp_group_free(&grp);
|
||||
* \endcode
|
||||
*
|
||||
* For Montgomery curves, we do not store \p A, but <code>(A + 2) / 4</code>,
|
||||
* which is the quantity used in the formulas. Additionally, \p nbits is
|
||||
* not the size of \p N but the required size for private keys.
|
||||
@ -256,8 +282,11 @@ mbedtls_ecp_point;
|
||||
typedef struct mbedtls_ecp_group {
|
||||
mbedtls_ecp_group_id id; /*!< An internal group identifier. */
|
||||
mbedtls_mpi P; /*!< The prime modulus of the base field. */
|
||||
mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. For
|
||||
Montgomery curves: <code>(A + 2) / 4</code>. */
|
||||
mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. Note that
|
||||
\p A is not set to the authentic value in some cases.
|
||||
Refer to detailed description of ::mbedtls_ecp_group if
|
||||
using domain parameters in the structure.
|
||||
For Montgomery curves: <code>(A + 2) / 4</code>. */
|
||||
mbedtls_mpi B; /*!< For Short Weierstrass: \p B in the equation.
|
||||
For Montgomery curves: unused. */
|
||||
mbedtls_ecp_point G; /*!< The generator of the subgroup used. */
|
||||
@ -989,6 +1018,26 @@ int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx);
|
||||
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/**
|
||||
* \brief This function checks if domain parameter A of the curve is
|
||||
* \c -3.
|
||||
*
|
||||
* \note This function is only defined for short Weierstrass curves.
|
||||
* It may not be included in builds without any short
|
||||
* Weierstrass curve.
|
||||
*
|
||||
* \param grp The ECP group to use.
|
||||
* This must be initialized and have group parameters
|
||||
* set, for example through mbedtls_ecp_group_load().
|
||||
*
|
||||
* \return \c 1 if <code>A = -3</code>.
|
||||
* \return \c 0 Otherwise.
|
||||
*/
|
||||
static inline int mbedtls_ecp_group_a_is_minus_3(const mbedtls_ecp_group *grp)
|
||||
{
|
||||
return grp->A.p == NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief This function performs multiplication and addition of two
|
||||
* points by integers: \p R = \p m * \p P + \p n * \p Q
|
||||
@ -1081,7 +1130,7 @@ int mbedtls_ecp_muladd_restartable(
|
||||
*
|
||||
* It only checks that the point is non-zero, has
|
||||
* valid coordinates and lies on the curve. It does not verify
|
||||
* that it is indeed a multiple of \p G. This additional
|
||||
* that it is indeed a multiple of \c G. This additional
|
||||
* check is computationally more expensive, is not required
|
||||
* by standards, and should not be necessary if the group
|
||||
* used has a small cofactor. In particular, it is useless for
|
||||
@ -1106,7 +1155,7 @@ int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function checks that an \p mbedtls_mpi is a
|
||||
* \brief This function checks that an \c mbedtls_mpi is a
|
||||
* valid private key for this curve.
|
||||
*
|
||||
* \note This function uses bare components rather than an
|
||||
|
@ -186,8 +186,8 @@ void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx);
|
||||
* \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
|
||||
* #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \c entropy_len * 3 / 2
|
||||
* where \c entropy_len is the entropy length
|
||||
* described above.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
@ -316,8 +316,8 @@ int mbedtls_hmac_drbg_update_ret(mbedtls_hmac_drbg_context *ctx,
|
||||
* \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
|
||||
* #MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT - \c entropy_len
|
||||
* where \c entropy_len is the entropy length
|
||||
* (see mbedtls_hmac_drbg_set_entropy_len()).
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
|
@ -395,7 +395,7 @@ int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type);
|
||||
*
|
||||
* \return 0 on success (signature is valid),
|
||||
* #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
|
||||
* signature in sig but its length is less than \p siglen,
|
||||
* signature in \p sig but its length is less than \p sig_len,
|
||||
* or a specific error code.
|
||||
*
|
||||
* \note For RSA keys, the default padding type is PKCS#1 v1.5.
|
||||
@ -459,7 +459,7 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
|
||||
* #MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
|
||||
* used for this type of signatures,
|
||||
* #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
|
||||
* signature in sig but its length is less than \p siglen,
|
||||
* signature in \p sig but its length is less than \p sig_len,
|
||||
* or a specific error code.
|
||||
*
|
||||
* \note If hash_len is 0, then the length associated with md_alg
|
||||
|
@ -155,6 +155,8 @@ extern "C" {
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
|
||||
defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
|
||||
#undef mbedtls_free
|
||||
#undef mbedtls_calloc
|
||||
#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
|
||||
#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
|
||||
#else
|
||||
@ -176,6 +178,8 @@ int mbedtls_platform_set_calloc_free(void *(*calloc_func)(size_t, size_t),
|
||||
void (*free_func)(void *));
|
||||
#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
|
||||
#else /* !MBEDTLS_PLATFORM_MEMORY */
|
||||
#undef mbedtls_free
|
||||
#undef mbedtls_calloc
|
||||
#define mbedtls_free free
|
||||
#define mbedtls_calloc calloc
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
|
||||
@ -200,6 +204,7 @@ extern int (*mbedtls_fprintf)(FILE *stream, const char *format, ...);
|
||||
int mbedtls_platform_set_fprintf(int (*fprintf_func)(FILE *stream, const char *,
|
||||
...));
|
||||
#else
|
||||
#undef mbedtls_fprintf
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
|
||||
#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
|
||||
#else
|
||||
@ -224,6 +229,7 @@ extern int (*mbedtls_printf)(const char *format, ...);
|
||||
*/
|
||||
int mbedtls_platform_set_printf(int (*printf_func)(const char *, ...));
|
||||
#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
#undef mbedtls_printf
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
|
||||
#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
|
||||
#else
|
||||
@ -259,6 +265,7 @@ extern int (*mbedtls_snprintf)(char *s, size_t n, const char *format, ...);
|
||||
int mbedtls_platform_set_snprintf(int (*snprintf_func)(char *s, size_t n,
|
||||
const char *format, ...));
|
||||
#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
#undef mbedtls_snprintf
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
|
||||
#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
|
||||
#else
|
||||
@ -295,6 +302,7 @@ extern int (*mbedtls_vsnprintf)(char *s, size_t n, const char *format, va_list a
|
||||
int mbedtls_platform_set_vsnprintf(int (*vsnprintf_func)(char *s, size_t n,
|
||||
const char *format, va_list arg));
|
||||
#else /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */
|
||||
#undef mbedtls_vsnprintf
|
||||
#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO)
|
||||
#define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO
|
||||
#else
|
||||
@ -319,6 +327,7 @@ extern void (*mbedtls_exit)(int status);
|
||||
*/
|
||||
int mbedtls_platform_set_exit(void (*exit_func)(int status));
|
||||
#else
|
||||
#undef mbedtls_exit
|
||||
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
|
||||
#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
|
||||
#else
|
||||
@ -371,6 +380,8 @@ int mbedtls_platform_set_nv_seed(
|
||||
int (*nv_seed_write_func)(unsigned char *buf, size_t buf_len)
|
||||
);
|
||||
#else
|
||||
#undef mbedtls_nv_seed_read
|
||||
#undef mbedtls_nv_seed_write
|
||||
#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
|
||||
defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
|
||||
#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
|
||||
|
@ -260,15 +260,15 @@ int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx,
|
||||
* \brief This function completes an RSA context from
|
||||
* a set of imported core parameters.
|
||||
*
|
||||
* To setup an RSA public key, precisely \p N and \p E
|
||||
* To setup an RSA public key, precisely \c N and \c E
|
||||
* must have been imported.
|
||||
*
|
||||
* To setup an RSA private key, sufficient information must
|
||||
* be present for the other parameters to be derivable.
|
||||
*
|
||||
* The default implementation supports the following:
|
||||
* <ul><li>Derive \p P, \p Q from \p N, \p D, \p E.</li>
|
||||
* <li>Derive \p N, \p D from \p P, \p Q, \p E.</li></ul>
|
||||
* <ul><li>Derive \c P, \c Q from \c N, \c D, \c E.</li>
|
||||
* <li>Derive \c N, \c D from \c P, \c Q, \c E.</li></ul>
|
||||
* Alternative implementations need not support these.
|
||||
*
|
||||
* If this function runs successfully, it guarantees that
|
||||
@ -537,7 +537,7 @@ int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub,
|
||||
* \note This function does not handle message padding.
|
||||
*
|
||||
* \note Make sure to set \p input[0] = 0 or ensure that
|
||||
* input is smaller than \p N.
|
||||
* input is smaller than \c N.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
|
||||
@ -1109,8 +1109,8 @@ int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
|
||||
* verification using the mode from the context.
|
||||
*
|
||||
* \note For PKCS#1 v2.1 encoding, see comments on
|
||||
* mbedtls_rsa_rsassa_pss_verify() about \p md_alg and
|
||||
* \p hash_id.
|
||||
* mbedtls_rsa_rsassa_pss_verify() about \c md_alg and
|
||||
* \c hash_id.
|
||||
*
|
||||
* \deprecated It is deprecated and discouraged to call this function
|
||||
* in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
|
||||
|
@ -494,6 +494,7 @@
|
||||
|
||||
/* Dummy type used only for its size */
|
||||
union mbedtls_ssl_premaster_secret {
|
||||
unsigned char dummy; /* Make the union non-empty even with SSL disabled */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
|
||||
unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
|
||||
#endif
|
||||
@ -1746,10 +1747,10 @@ void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl,
|
||||
* \param own_cid The address of the readable buffer holding the CID we want
|
||||
* the peer to use when sending encrypted messages to us.
|
||||
* This may be \c NULL if \p own_cid_len is \c 0.
|
||||
* This parameter is unused if \p enabled is set to
|
||||
* This parameter is unused if \p enable is set to
|
||||
* MBEDTLS_SSL_CID_DISABLED.
|
||||
* \param own_cid_len The length of \p own_cid.
|
||||
* This parameter is unused if \p enabled is set to
|
||||
* This parameter is unused if \p enable is set to
|
||||
* MBEDTLS_SSL_CID_DISABLED.
|
||||
*
|
||||
* \note The value of \p own_cid_len must match the value of the
|
||||
@ -2573,8 +2574,8 @@ int mbedtls_ssl_session_load(mbedtls_ssl_session *session,
|
||||
*
|
||||
* \param session The session structure to be saved.
|
||||
* \param buf The buffer to write the serialized data to. It must be a
|
||||
* writeable buffer of at least \p len bytes, or may be \c
|
||||
* NULL if \p len is \c 0.
|
||||
* writeable buffer of at least \p buf_len bytes, or may be \c
|
||||
* NULL if \p buf_len is \c 0.
|
||||
* \param buf_len The number of bytes available for writing in \p buf.
|
||||
* \param olen The size in bytes of the data that has been or would have
|
||||
* been written. It must point to a valid \c size_t.
|
||||
@ -2659,7 +2660,7 @@ void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *conf,
|
||||
* record headers.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p own_cid_len
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p len
|
||||
* is too large.
|
||||
*/
|
||||
int mbedtls_ssl_conf_cid(mbedtls_ssl_config *conf, size_t len,
|
||||
|
@ -38,16 +38,16 @@
|
||||
*/
|
||||
#define MBEDTLS_VERSION_MAJOR 2
|
||||
#define MBEDTLS_VERSION_MINOR 28
|
||||
#define MBEDTLS_VERSION_PATCH 3
|
||||
#define MBEDTLS_VERSION_PATCH 4
|
||||
|
||||
/**
|
||||
* The single version number has the following structure:
|
||||
* MMNNPP00
|
||||
* Major version | Minor version | Patch version
|
||||
*/
|
||||
#define MBEDTLS_VERSION_NUMBER 0x021C0300
|
||||
#define MBEDTLS_VERSION_STRING "2.28.3"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.3"
|
||||
#define MBEDTLS_VERSION_NUMBER 0x021C0400
|
||||
#define MBEDTLS_VERSION_STRING "2.28.4"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.4"
|
||||
|
||||
#if defined(MBEDTLS_VERSION_C)
|
||||
|
||||
|
@ -361,7 +361,8 @@ int mbedtls_x509_write_names(unsigned char **p, unsigned char *start,
|
||||
mbedtls_asn1_named_data *first);
|
||||
int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
unsigned char *sig, size_t size);
|
||||
unsigned char *sig, size_t size,
|
||||
mbedtls_pk_type_t pk_alg);
|
||||
|
||||
#define MBEDTLS_X509_SAFE_SNPRINTF \
|
||||
do { \
|
||||
|
@ -509,7 +509,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path);
|
||||
* \param san_buf The buffer holding the raw data item of the subject
|
||||
* alternative name.
|
||||
* \param san The target structure to populate with the parsed presentation
|
||||
* of the subject alternative name encoded in \p san_raw.
|
||||
* of the subject alternative name encoded in \p san_buf.
|
||||
*
|
||||
* \note Only "dnsName" and "otherName" of type hardware_module_name
|
||||
* as defined in RFC 4180 is supported.
|
||||
@ -517,7 +517,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path);
|
||||
* \note This function should be called on a single raw data of
|
||||
* subject alternative name. For example, after successful
|
||||
* certificate parsing, one must iterate on every item in the
|
||||
* \p crt->subject_alt_names sequence, and pass it to
|
||||
* \c crt->subject_alt_names sequence, and pass it to
|
||||
* this function.
|
||||
*
|
||||
* \warning The target structure contains pointers to the raw data of the
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* This header declares alternative names for macro and functions.
|
||||
* New application code should not use these names.
|
||||
* These names may be removed in a future version of Mbed Crypto.
|
||||
* These names may be removed in a future version of Mbed TLS.
|
||||
*
|
||||
* \note This file may not be included directly. Applications must
|
||||
* include psa/crypto.h.
|
||||
|
@ -107,7 +107,7 @@ static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
|
||||
* indicates the slot number that contains it.
|
||||
* \retval #PSA_ERROR_NOT_PERMITTED
|
||||
* The caller is not permitted to query the slot number.
|
||||
* Mbed Crypto currently does not return this error.
|
||||
* Mbed TLS currently does not return this error.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The key is not located in a secure element.
|
||||
*/
|
||||
@ -219,7 +219,7 @@ void mbedtls_psa_crypto_free(void);
|
||||
* resource consumption related to the PSA keystore.
|
||||
*
|
||||
* \note The content of this structure is not part of the stable API and ABI
|
||||
* of Mbed Crypto and may change arbitrarily from version to version.
|
||||
* of Mbed TLS and may change arbitrarily from version to version.
|
||||
*/
|
||||
typedef struct mbedtls_psa_stats_s {
|
||||
/** Number of slots containing key material for a volatile key. */
|
||||
@ -248,7 +248,7 @@ typedef struct mbedtls_psa_stats_s {
|
||||
/** \brief Get statistics about
|
||||
* resource consumption related to the PSA keystore.
|
||||
*
|
||||
* \note When Mbed Crypto is built as part of a service, with isolation
|
||||
* \note When Mbed TLS is built as part of a service, with isolation
|
||||
* between the application and the keystore, the service may or
|
||||
* may not expose this function.
|
||||
*/
|
||||
|
@ -137,7 +137,7 @@ typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_location_t location);
|
||||
|
||||
#if defined(__DOXYGEN_ONLY__) || !defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||
/* Mbed Crypto with secure element support enabled defines this type in
|
||||
/* Mbed TLS with secure element support enabled defines this type in
|
||||
* crypto_types.h because it is also visible to applications through an
|
||||
* implementation-specific extension.
|
||||
* For the PSA Cryptography specification, this type is only visible
|
||||
@ -836,7 +836,7 @@ typedef enum {
|
||||
* and #PSA_ERROR_DOES_NOT_EXIST if the driver can determine that there
|
||||
* is no key with the specified slot number.
|
||||
*
|
||||
* This is an Mbed Crypto extension.
|
||||
* This is an Mbed TLS extension.
|
||||
*/
|
||||
PSA_KEY_CREATION_REGISTER,
|
||||
#endif
|
||||
|
@ -35,8 +35,8 @@
|
||||
* GCC and Clang initialize the whole structure to 0 (at the time of writing),
|
||||
* but MSVC and CompCert don't.
|
||||
*
|
||||
* In Mbed Crypto, multipart operation structures live independently from
|
||||
* the key. This allows Mbed Crypto to free the key objects when destroying
|
||||
* In Mbed TLS, multipart operation structures live independently from
|
||||
* the key. This allows Mbed TLS to free the key objects when destroying
|
||||
* a key slot. If a multipart operation needs to remember the key after
|
||||
* the setup function returns, the operation structure needs to contain a
|
||||
* copy of the key.
|
||||
|
@ -295,7 +295,7 @@ typedef uint32_t psa_key_id_t;
|
||||
typedef psa_key_id_t mbedtls_svc_key_id_t;
|
||||
|
||||
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
|
||||
/* Implementation-specific: The Mbed Cryptography library can be built as
|
||||
/* Implementation-specific: The Mbed TLS library can be built as
|
||||
* part of a multi-client service that exposes the PSA Cryptography API in each
|
||||
* client and encodes the client identity in the key identifier argument of
|
||||
* functions such as psa_open_key().
|
||||
@ -437,7 +437,7 @@ typedef struct psa_key_attributes_s psa_key_attributes_t;
|
||||
|
||||
#ifndef __DOXYGEN_ONLY__
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||
/* Mbed Crypto defines this type in crypto_types.h because it is also
|
||||
/* Mbed TLS defines this type in crypto_types.h because it is also
|
||||
* visible to applications through an implementation-specific extension.
|
||||
* For the PSA Cryptography specification, this type is only visible
|
||||
* via crypto_se_driver.h. */
|
||||
|
1
library/.gitignore
vendored
1
library/.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
*.o
|
||||
libmbed*
|
||||
*.sln
|
||||
*.vcxproj
|
||||
|
@ -204,15 +204,15 @@ endif(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
if(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_library(${mbedcrypto_target} SHARED ${src_crypto})
|
||||
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.28.3 SOVERSION 7)
|
||||
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.28.4 SOVERSION 7)
|
||||
target_link_libraries(${mbedcrypto_target} PUBLIC ${libs})
|
||||
|
||||
add_library(${mbedx509_target} SHARED ${src_x509})
|
||||
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.28.3 SOVERSION 1)
|
||||
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.28.4 SOVERSION 1)
|
||||
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
|
||||
|
||||
add_library(${mbedtls_target} SHARED ${src_tls})
|
||||
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.28.3 SOVERSION 14)
|
||||
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.28.4 SOVERSION 14)
|
||||
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
|
||||
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
|
||||
@ -229,6 +229,15 @@ foreach(target IN LISTS target_libraries)
|
||||
PRIVATE ${thirdparty_inc})
|
||||
target_compile_definitions(${target}
|
||||
PRIVATE ${thirdparty_def})
|
||||
# Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE
|
||||
if(MBEDTLS_CONFIG_FILE)
|
||||
target_compile_definitions(${target}
|
||||
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
|
||||
endif()
|
||||
if(MBEDTLS_USER_CONFIG_FILE)
|
||||
target_compile_definitions(${target}
|
||||
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
|
||||
endif()
|
||||
install(TARGETS ${target}
|
||||
DESTINATION ${LIB_INSTALL_DIR}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
|
||||
|
@ -19,7 +19,7 @@
|
||||
/*
|
||||
* The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
|
||||
*
|
||||
* http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf
|
||||
* https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf
|
||||
* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
|
||||
*/
|
||||
|
||||
@ -58,6 +58,8 @@ static int aes_padlock_ace = -1;
|
||||
/*
|
||||
* Forward S-box
|
||||
*/
|
||||
#if !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
static const unsigned char FSb[256] =
|
||||
{
|
||||
0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
|
||||
@ -93,6 +95,8 @@ static const unsigned char FSb[256] =
|
||||
0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
|
||||
0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
|
||||
};
|
||||
#endif /* !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_DEC_ALT) */
|
||||
|
||||
/*
|
||||
* Forward tables
|
||||
@ -164,6 +168,7 @@ static const unsigned char FSb[256] =
|
||||
V(C3, 41, 41, 82), V(B0, 99, 99, 29), V(77, 2D, 2D, 5A), V(11, 0F, 0F, 1E), \
|
||||
V(CB, B0, B0, 7B), V(FC, 54, 54, A8), V(D6, BB, BB, 6D), V(3A, 16, 16, 2C)
|
||||
|
||||
#if !defined(MBEDTLS_AES_ENCRYPT_ALT)
|
||||
#define V(a, b, c, d) 0x##a##b##c##d
|
||||
static const uint32_t FT0[256] = { FT };
|
||||
#undef V
|
||||
@ -184,8 +189,11 @@ static const uint32_t FT3[256] = { FT };
|
||||
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
|
||||
#endif /* !defined(MBEDTLS_AES_ENCRYPT_ALT) */
|
||||
|
||||
#undef FT
|
||||
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT)
|
||||
/*
|
||||
* Reverse S-box
|
||||
*/
|
||||
@ -224,6 +232,7 @@ static const unsigned char RSb[256] =
|
||||
0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
|
||||
0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
|
||||
};
|
||||
#endif /* defined(MBEDTLS_AES_DECRYPT_ALT)) */
|
||||
|
||||
/*
|
||||
* Reverse tables
|
||||
@ -295,6 +304,8 @@ static const unsigned char RSb[256] =
|
||||
V(71, 01, A8, 39), V(DE, B3, 0C, 08), V(9C, E4, B4, D8), V(90, C1, 56, 64), \
|
||||
V(61, 84, CB, 7B), V(70, B6, 32, D5), V(74, 5C, 6C, 48), V(42, 57, B8, D0)
|
||||
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
|
||||
#define V(a, b, c, d) 0x##a##b##c##d
|
||||
static const uint32_t RT0[256] = { RT };
|
||||
#undef V
|
||||
@ -315,8 +326,11 @@ static const uint32_t RT3[256] = { RT };
|
||||
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
|
||||
#endif /* !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT) */
|
||||
|
||||
#undef RT
|
||||
|
||||
#if !defined(MBEDTLS_AES_SETKEY_ENC_ALT)
|
||||
/*
|
||||
* Round constants
|
||||
*/
|
||||
@ -326,31 +340,44 @@ static const uint32_t RCON[10] =
|
||||
0x00000010, 0x00000020, 0x00000040, 0x00000080,
|
||||
0x0000001B, 0x00000036
|
||||
};
|
||||
#endif /* !defined(MBEDTLS_AES_SETKEY_ENC_ALT) */
|
||||
|
||||
#else /* MBEDTLS_AES_ROM_TABLES */
|
||||
|
||||
/*
|
||||
* Forward S-box & tables
|
||||
*/
|
||||
#if !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
static unsigned char FSb[256];
|
||||
#endif /* !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_DEC_ALT) */
|
||||
#if !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT)
|
||||
static uint32_t FT0[256];
|
||||
#if !defined(MBEDTLS_AES_FEWER_TABLES)
|
||||
static uint32_t FT1[256];
|
||||
static uint32_t FT2[256];
|
||||
static uint32_t FT3[256];
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
#endif /* !defined(MBEDTLS_AES_ENCRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_ENC_ALT) */
|
||||
|
||||
/*
|
||||
* Reverse S-box & tables
|
||||
*/
|
||||
#if !(defined(MBEDTLS_AES_SETKEY_ENC_ALT) && defined(MBEDTLS_AES_DECRYPT_ALT))
|
||||
static unsigned char RSb[256];
|
||||
#endif /* !(defined(MBEDTLS_AES_SETKEY_ENC_ALT) && defined(MBEDTLS_AES_DECRYPT_ALT)) */
|
||||
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
static uint32_t RT0[256];
|
||||
#if !defined(MBEDTLS_AES_FEWER_TABLES)
|
||||
static uint32_t RT1[256];
|
||||
static uint32_t RT2[256];
|
||||
static uint32_t RT3[256];
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
#endif /* !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT) */
|
||||
|
||||
#if !defined(MBEDTLS_AES_SETKEY_ENC_ALT)
|
||||
/*
|
||||
* Round constants
|
||||
*/
|
||||
@ -428,6 +455,7 @@ static void aes_gen_tables(void)
|
||||
|
||||
x = RSb[i];
|
||||
|
||||
#if !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
|
||||
RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
|
||||
((uint32_t) MUL(0x09, x) << 8) ^
|
||||
((uint32_t) MUL(0x0D, x) << 16) ^
|
||||
@ -438,9 +466,12 @@ static void aes_gen_tables(void)
|
||||
RT2[i] = ROTL8(RT1[i]);
|
||||
RT3[i] = ROTL8(RT2[i]);
|
||||
#endif /* !MBEDTLS_AES_FEWER_TABLES */
|
||||
#endif /* !defined(MBEDTLS_AES_DECRYPT_ALT) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT) */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !defined(MBEDTLS_AES_SETKEY_ENC_ALT) */
|
||||
|
||||
#undef ROTL8
|
||||
|
||||
#endif /* MBEDTLS_AES_ROM_TABLES */
|
||||
@ -521,6 +552,9 @@ void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
|
||||
(defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2)
|
||||
#define MAY_NEED_TO_ALIGN
|
||||
#endif
|
||||
|
||||
#if defined(MAY_NEED_TO_ALIGN) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_ENC_ALT)
|
||||
static unsigned mbedtls_aes_rk_offset(uint32_t *buf)
|
||||
{
|
||||
#if defined(MAY_NEED_TO_ALIGN)
|
||||
@ -557,6 +591,8 @@ static unsigned mbedtls_aes_rk_offset(uint32_t *buf)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* defined(MAY_NEED_TO_ALIGN) || !defined(MBEDTLS_AES_SETKEY_DEC_ALT) || \
|
||||
!defined(MBEDTLS_AES_SETKEY_ENC_ALT) */
|
||||
|
||||
/*
|
||||
* AES key schedule (encryption)
|
||||
|
@ -41,6 +41,8 @@
|
||||
#if MBEDTLS_AESNI_HAVE_CODE == 2
|
||||
#if !defined(_WIN32)
|
||||
#include <cpuid.h>
|
||||
#else
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
@ -194,15 +194,24 @@ int mbedtls_asn1_write_oid(unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_algorithm_identifier(unsigned char **p, unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len)
|
||||
{
|
||||
return mbedtls_asn1_write_algorithm_identifier_ext(p, start, oid, oid_len, par_len, 1);
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_algorithm_identifier_ext(unsigned char **p, unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len, int has_par)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
||||
if (has_par) {
|
||||
if (par_len == 0) {
|
||||
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_null(p, start));
|
||||
} else {
|
||||
len += par_len;
|
||||
}
|
||||
}
|
||||
|
||||
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid, oid_len));
|
||||
|
||||
|
104
library/certs.c
104
library/certs.c
@ -348,33 +348,33 @@
|
||||
#define TEST_CA_KEY_RSA_PEM \
|
||||
"-----BEGIN RSA PRIVATE KEY-----\r\n" \
|
||||
"Proc-Type: 4,ENCRYPTED\r\n" \
|
||||
"DEK-Info: DES-EDE3-CBC,A8A95B05D5B7206B\r\n" \
|
||||
"AES-128-CBC,781840E6B804AE83D2AF71127C4CE314\r\n" \
|
||||
"\r\n" \
|
||||
"9Qd9GeArejl1GDVh2lLV1bHt0cPtfbh5h/5zVpAVaFpqtSPMrElp50Rntn9et+JA\r\n" \
|
||||
"7VOyboR+Iy2t/HU4WvA687k3Bppe9GwKHjHhtl//8xFKwZr3Xb5yO5JUP8AUctQq\r\n" \
|
||||
"Nb8CLlZyuUC+52REAAthdWgsX+7dJO4yabzUcQ22Tp9JSD0hiL43BlkWYUNK3dAo\r\n" \
|
||||
"PZlmiptjnzVTjg1MxsBSydZinWOLBV8/JQgxSPo2yD4uEfig28qbvQ2wNIn0pnAb\r\n" \
|
||||
"GxnSAOazkongEGfvcjIIs+LZN9gXFhxcOh6kc4Q/c99B7QWETwLLkYgZ+z1a9VY9\r\n" \
|
||||
"gEU7CwCxYCD+h9hY6FPmsK0/lC4O7aeRKpYq00rPPxs6i7phiexg6ax6yTMmArQq\r\n" \
|
||||
"QmK3TAsJm8V/J5AWpLEV6jAFgRGymGGHnof0DXzVWZidrcZJWTNuGEX90nB3ee2w\r\n" \
|
||||
"PXJEFWKoD3K3aFcSLdHYr3mLGxP7H9ThQai9VsycxZKS5kwvBKQ//YMrmFfwPk8x\r\n" \
|
||||
"vTeY4KZMaUrveEel5tWZC94RSMKgxR6cyE1nBXyTQnDOGbfpNNgBKxyKbINWoOJU\r\n" \
|
||||
"WJZAwlsQn+QzCDwpri7+sV1mS3gBE6UY7aQmnmiiaC2V3Hbphxct/en5QsfDOt1X\r\n" \
|
||||
"JczSfpRWLlbPznZg8OQh/VgCMA58N5DjOzTIK7sJJ5r+94ZBTCpgAMbF588f0NTR\r\n" \
|
||||
"KCe4yrxGJR7X02M4nvD4IwOlpsQ8xQxZtOSgXv4LkxvdU9XJJKWZ/XNKJeWztxSe\r\n" \
|
||||
"Z1vdTc2YfsDBA2SEv33vxHx2g1vqtw8SjDRT2RaQSS0QuSaMJimdOX6mTOCBKk1J\r\n" \
|
||||
"9Q5mXTrER+/LnK0jEmXsBXWA5bqqVZIyahXSx4VYZ7l7w/PHiUDtDgyRhMMKi4n2\r\n" \
|
||||
"iQvQcWSQTjrpnlJbca1/DkpRt3YwrvJwdqb8asZU2VrNETh5x0QVefDRLFiVpif/\r\n" \
|
||||
"tUaeAe/P1F8OkS7OIZDs1SUbv/sD2vMbhNkUoCms3/PvNtdnvgL4F0zhaDpKCmlT\r\n" \
|
||||
"P8vx49E7v5CyRNmED9zZg4o3wmMqrQO93PtTug3Eu9oVx1zPQM1NVMyBa2+f29DL\r\n" \
|
||||
"1nuTCeXdo9+ni45xx+jAI4DCwrRdhJ9uzZyC6962H37H6D+5naNvClFR1s6li1Gb\r\n" \
|
||||
"nqPoiy/OBsEx9CaDGcqQBp5Wme/3XW+6z1ISOx+igwNTVCT14mHdBMbya0eIKft5\r\n" \
|
||||
"X+GnwtgEMyCYyyWuUct8g4RzErcY9+yW9Om5Hzpx4zOuW4NPZgPDTgK+t2RSL/Yq\r\n" \
|
||||
"rE1njrgeGYcVeG3f+OftH4s6fPbq7t1A5ZgUscbLMBqr9tK+OqygR4EgKBPsH6Cz\r\n" \
|
||||
"L6zlv/2RV0qAHvVuDJcIDIgwY5rJtINEm32rhOeFNJwZS5MNIC1czXZx5//ugX7l\r\n" \
|
||||
"I4sy5nbVhwSjtAk8Xg5dZbdTZ6mIrb7xqH+fdakZor1khG7bC2uIwibD3cSl2XkR\r\n" \
|
||||
"wN48lslbHnqqagr6Xm1nNOSVl8C/6kbJEsMpLhAezfRtGwvOucoaE+WbeUNolGde\r\n" \
|
||||
"P/eQiddSf0brnpiLJRh7qZrl9XuqYdpUqnoEdMAfotDOID8OtV7gt8a48ad8VPW2\r\n" \
|
||||
"etQ3xgGLbuYF9vR1km03TH5fwfly1hOlix0PtfQ+t9HG065vTtSEHYc/OyHwdy79\r\n" \
|
||||
"NCLX5RUrPh06E/XlKzMNVHAXqkwFnIwNzRLsOozeP1L7iZEZb9QMeiN5Org+btCO\r\n" \
|
||||
"bylXPB4YirfuE7GSJalWY/pq3FQtD33zTIKmNhXfVj3sbwGI/8D9XjaKUb8PODOB\r\n" \
|
||||
"skOalmx6RvYRvg0lmRxB3+T3wejIsrrDPweYqte9B6dVHIVG1ZmvoA6/wnKZZZeV\r\n" \
|
||||
"sjj8OpL3OwUBrjuGSknE9Rs6kCuSCbHOYVK8VzcZmCYpie0TFnb3Sk8M6vjfW+45\r\n" \
|
||||
"U7WUMlSAPxKH6lJDzWdwHqLvsVJwuNnaAaBXg9/8U/rzQEWuq8Ar3s8fw2Jg3F1G\r\n" \
|
||||
"L6N5ZAEfCz3Sa0N9WKafR/RSQj+rq8Z3w4POAafhbzk249uo5K8B1Z3cQwLxeXIl\r\n" \
|
||||
"UbRQz1TZy4oNTfQzCahYruPNyvwgTkfwAFFvbLAdaiJd2ZtLBoqYE64TYakYnvcC\r\n" \
|
||||
"itim1bmySIKoxlMfBGFmMuF03epT0pSx701jlGzGi0l0m16NEjoVxDwo5j93SmiM\r\n" \
|
||||
"sQdjC1lOGk2iCLkphIQqHFjFJYWjvh1UUIqWZf+ZWOOxlf4x9a1pUVj6FvtECxNB\r\n" \
|
||||
"/mA/m4Iq4LAuVXHE1MpHeq067lJ6wWlrsb2WVmiNGfQ2AC7fMtpcPuunBVT9NV1m\r\n" \
|
||||
"1rbDzIgLIWAzqz/cy3N8Q8vfxnrFtmNUyM191Zyq+YF14hIKWX9J1qR4LXwWAzVV\r\n" \
|
||||
"UrC8IL4pA2mtRkW4qFsB0EmHAxO/cedDTPjVFty5WSzhNuvYZxX45HAkGIfK6d21\r\n" \
|
||||
"7WHPhHG+zaaUTWMUVixB0IcKp6RecjYPFzBHS0YeX88Ue2cyT/90jMiQ9ssOgRrG\r\n" \
|
||||
"ZJRJvZAc3TSCnY9sNPYoGrJPiZuCnlUj3ENNurYVy12ai0WFxwnNUZjRUhDS6hjm\r\n" \
|
||||
"cDHD5TlI9MZ6M+Mb/Bw4Ig8HuTHOtQBYD9vhtXsG+B7H/j6cS+1umaKjrnG/kK4W\r\n" \
|
||||
"R6YXwM2faAi+DwgjjoMXSzRqSTF8PdTIWbAXo3bc2qsXPTMBA8PEp4nb5scHZ4Ts\r\n" \
|
||||
"EcBNp2jv0j4gBkRmGIab17cWMrlagjFy89DhqZUFwKdeZs+yJ92A5xstWxOUfpEP\r\n" \
|
||||
"90T/bsp1G5d7WW5fl2TRJvYJNDM+djkKIh0zCkduiZ36oVM6nDdbjmXqjQXopeSD\r\n" \
|
||||
"gtOourBRF8g99W0fW8QT+yPhP0Pkyz6EG8eQO6Zwh439xdoVwu9jUzQAPmZ0uNeR\r\n" \
|
||||
"xTXXihYyv72z27rInjLiIPXL25K9eDVLlcSR3RyG7YYgjdQAL2VJDLcBz5jox1uQ\r\n" \
|
||||
"0guoD5wmfu2FWLqYE7HeTYntdY53lCflwq0GHRMjrrsVpx+5VDQ6Yi47Ny9SWLcp\r\n" \
|
||||
"fPI3iBkXuGRWupzs6N4pQdSO0dU28KfpMM5QvFoLIn67brCHEQij4dgFrCTYEyBX\r\n" \
|
||||
"9+jiNImUFYUhAFuxvUbfZt4O/ABLIElvHLfJs1oYCmI/nWpvLFqXB5rnzPNfEi0H\r\n" \
|
||||
"PGGe1Hj/t+CJIp/6ios3yNy2QtXO754TZH2UVu51Ykyig5PFjZVoUkbRvHQYcWfU\r\n" \
|
||||
"-----END RSA PRIVATE KEY-----\r\n"
|
||||
/* END FILE */
|
||||
|
||||
@ -504,17 +504,17 @@
|
||||
#define TEST_SRV_CRT_EC_PEM \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIICHzCCAaWgAwIBAgIBCTAKBggqhkjOPQQDAjA+MQswCQYDVQQGEwJOTDERMA8G\r\n" \
|
||||
"A1UEChMIUG9sYXJTU0wxHDAaBgNVBAMTE1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n" \
|
||||
"MTMwOTI0MTU1MjA0WhcNMjMwOTIyMTU1MjA0WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
|
||||
"A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\r\n" \
|
||||
"A1UECgwIUG9sYXJTU0wxHDAaBgNVBAMME1BvbGFyc3NsIFRlc3QgRUMgQ0EwHhcN\r\n" \
|
||||
"MjMwNjE1MDMzNDE4WhcNMzMwNjEyMDMzNDE4WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \
|
||||
"A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDBZMBMGByqGSM49AgEG\r\n" \
|
||||
"CCqGSM49AwEHA0IABDfMVtl2CR5acj7HWS3/IG7ufPkGkXTQrRS192giWWKSTuUA\r\n" \
|
||||
"2CMR/+ov0jRdXRa9iojCa3cNVc2KKg76Aci07f+jgZ0wgZowCQYDVR0TBAIwADAd\r\n" \
|
||||
"BgNVHQ4EFgQUUGGlj9QH2deCAQzlZX+MY0anE74wbgYDVR0jBGcwZYAUnW0gJEkB\r\n" \
|
||||
"PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKEwhQb2xh\r\n" \
|
||||
"clNTTDEcMBoGA1UEAxMTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\r\n" \
|
||||
"CCqGSM49BAMCA2gAMGUCMQCaLFzXptui5WQN8LlO3ddh1hMxx6tzgLvT03MTVK2S\r\n" \
|
||||
"C12r0Lz3ri/moSEpNZWqPjkCMCE2f53GXcYLqyfyJR078c/xNSUU5+Xxl7VZ414V\r\n" \
|
||||
"fGa5kHvHARBPc8YAIVIqDvHH1Q==\r\n" \
|
||||
"PyvLeLUZvH4kydv7NnyhQqRAMD4xCzAJBgNVBAYTAk5MMREwDwYDVQQKDAhQb2xh\r\n" \
|
||||
"clNTTDEcMBoGA1UEAwwTUG9sYXJzc2wgVGVzdCBFQyBDQYIJAMFD4n5iQ8zoMAoG\r\n" \
|
||||
"CCqGSM49BAMCA2gAMGUCMAHFbGEzx8dZaUlIltT5s1QO9FvKmvFer4uRY3ntEy9S\r\n" \
|
||||
"k7DCCozM86WWLjfzbJ78bwIxAJYRPF1CzNEiXPHb9O46ZPHKo2S5x//g/54RowAK\r\n" \
|
||||
"uZz+hKPuMi6YY6cIm81jfeaSZQ==\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n"
|
||||
/* END FILE */
|
||||
|
||||
@ -525,16 +525,16 @@
|
||||
0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, \
|
||||
0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
|
||||
0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
|
||||
0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
|
||||
0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
|
||||
0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
|
||||
0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
|
||||
0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, \
|
||||
0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, \
|
||||
0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, \
|
||||
0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \
|
||||
0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
|
||||
0x32, 0x33, 0x30, 0x36, 0x31, 0x35, 0x30, 0x33, 0x33, 0x34, 0x31, 0x38, \
|
||||
0x5a, 0x17, 0x0d, 0x33, 0x33, 0x30, 0x36, 0x31, 0x32, 0x30, 0x33, 0x33, \
|
||||
0x34, 0x31, 0x38, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, \
|
||||
0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \
|
||||
0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
|
||||
0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, \
|
||||
0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \
|
||||
0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, \
|
||||
0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x59, \
|
||||
0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, \
|
||||
0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, \
|
||||
@ -552,21 +552,21 @@
|
||||
0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, \
|
||||
0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, \
|
||||
0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, \
|
||||
0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
|
||||
0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \
|
||||
0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, \
|
||||
0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
|
||||
0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \
|
||||
0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, \
|
||||
0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, \
|
||||
0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, 0x00, \
|
||||
0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, \
|
||||
0xe5, 0x64, 0x0d, 0xf0, 0xb9, 0x4e, 0xdd, 0xd7, 0x61, 0xd6, 0x13, 0x31, \
|
||||
0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, 0x54, 0xad, 0x92, \
|
||||
0x0b, 0x5d, 0xab, 0xd0, 0xbc, 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, \
|
||||
0x35, 0x95, 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, \
|
||||
0x5d, 0xc6, 0x0b, 0xab, 0x27, 0xf2, 0x25, 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, \
|
||||
0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, \
|
||||
0x7c, 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, \
|
||||
0x21, 0x52, 0x2a, 0x0e, 0xf1, 0xc7, 0xd5 \
|
||||
0x30, 0x65, 0x02, 0x30, 0x01, 0xc5, 0x6c, 0x61, 0x33, 0xc7, 0xc7, 0x59, \
|
||||
0x69, 0x49, 0x48, 0x96, 0xd4, 0xf9, 0xb3, 0x54, 0x0e, 0xf4, 0x5b, 0xca, \
|
||||
0x9a, 0xf1, 0x5e, 0xaf, 0x8b, 0x91, 0x63, 0x79, 0xed, 0x13, 0x2f, 0x52, \
|
||||
0x93, 0xb0, 0xc2, 0x0a, 0x8c, 0xcc, 0xf3, 0xa5, 0x96, 0x2e, 0x37, 0xf3, \
|
||||
0x6c, 0x9e, 0xfc, 0x6f, 0x02, 0x31, 0x00, 0x96, 0x11, 0x3c, 0x5d, 0x42, \
|
||||
0xcc, 0xd1, 0x22, 0x5c, 0xf1, 0xdb, 0xf4, 0xee, 0x3a, 0x64, 0xf1, 0xca, \
|
||||
0xa3, 0x64, 0xb9, 0xc7, 0xff, 0xe0, 0xff, 0x9e, 0x11, 0xa3, 0x00, 0x0a, \
|
||||
0xb9, 0x9c, 0xfe, 0x84, 0xa3, 0xee, 0x32, 0x2e, 0x98, 0x63, 0xa7, 0x08, \
|
||||
0x9b, 0xcd, 0x63, 0x7d, 0xe6, 0x92, 0x65 \
|
||||
}
|
||||
/* END FILE */
|
||||
|
||||
|
@ -263,40 +263,6 @@ unsigned mbedtls_ct_uint_if(unsigned condition,
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
/** Select between two sign values without branches.
|
||||
*
|
||||
* This is functionally equivalent to `condition ? if1 : if0` but uses only bit
|
||||
* operations in order to avoid branches.
|
||||
*
|
||||
* \note if1 and if0 must be either 1 or -1, otherwise the result
|
||||
* is undefined.
|
||||
*
|
||||
* \param condition Condition to test; must be either 0 or 1.
|
||||
* \param if1 The first sign; must be either +1 or -1.
|
||||
* \param if0 The second sign; must be either +1 or -1.
|
||||
*
|
||||
* \return \c if1 if \p condition is nonzero, otherwise \c if0.
|
||||
* */
|
||||
static int mbedtls_ct_cond_select_sign(unsigned char condition,
|
||||
int if1,
|
||||
int if0)
|
||||
{
|
||||
/* In order to avoid questions about what we can reasonably assume about
|
||||
* the representations of signed integers, move everything to unsigned
|
||||
* by taking advantage of the fact that if1 and if0 are either +1 or -1. */
|
||||
unsigned uif1 = if1 + 1;
|
||||
unsigned uif0 = if0 + 1;
|
||||
|
||||
/* condition was 0 or 1, mask is 0 or 2 as are uif1 and uif0 */
|
||||
const unsigned mask = condition << 1;
|
||||
|
||||
/* select uif1 or uif0 */
|
||||
unsigned ur = (uif0 & ~mask) | (uif1 & mask);
|
||||
|
||||
/* ur is now 0 or 2, convert back to -1 or +1 */
|
||||
return (int) ur - 1;
|
||||
}
|
||||
|
||||
void mbedtls_ct_mpi_uint_cond_assign(size_t n,
|
||||
mbedtls_mpi_uint *dest,
|
||||
const mbedtls_mpi_uint *src,
|
||||
@ -559,7 +525,7 @@ int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X,
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n));
|
||||
|
||||
X->s = mbedtls_ct_cond_select_sign(assign, Y->s, X->s);
|
||||
X->s = (int) mbedtls_ct_uint_if(assign, Y->s, X->s);
|
||||
|
||||
mbedtls_ct_mpi_uint_cond_assign(Y->n, X->p, Y->p, assign);
|
||||
|
||||
@ -599,8 +565,8 @@ int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X,
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_grow(Y, X->n));
|
||||
|
||||
s = X->s;
|
||||
X->s = mbedtls_ct_cond_select_sign(swap, Y->s, X->s);
|
||||
Y->s = mbedtls_ct_cond_select_sign(swap, s, Y->s);
|
||||
X->s = (int) mbedtls_ct_uint_if(swap, Y->s, X->s);
|
||||
Y->s = (int) mbedtls_ct_uint_if(swap, s, Y->s);
|
||||
|
||||
|
||||
for (i = 0; i < X->n; i++) {
|
||||
|
@ -19,7 +19,7 @@
|
||||
/*
|
||||
* The NIST SP 800-90 DRBGs are described in the following publication.
|
||||
*
|
||||
* http://csrc.nist.gov/publications/nistpubs/800-90/SP800-90revised_March2007.pdf
|
||||
* https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-90r.pdf
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
@ -30,6 +30,7 @@
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* DEBUG_BUF_SIZE must be at least 2 */
|
||||
#define DEBUG_BUF_SIZE 512
|
||||
|
||||
static int debug_threshold = 0;
|
||||
@ -69,6 +70,8 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
|
||||
char str[DEBUG_BUF_SIZE];
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
MBEDTLS_STATIC_ASSERT(DEBUG_BUF_SIZE >= 2, "DEBUG_BUF_SIZE too small");
|
||||
|
||||
if (NULL == ssl ||
|
||||
NULL == ssl->conf ||
|
||||
NULL == ssl->conf->f_dbg ||
|
||||
@ -80,10 +83,15 @@ void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
|
||||
ret = mbedtls_vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
|
||||
va_end(argp);
|
||||
|
||||
if (ret >= 0 && ret < DEBUG_BUF_SIZE - 1) {
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
} else {
|
||||
if (ret >= DEBUG_BUF_SIZE - 1) {
|
||||
ret = DEBUG_BUF_SIZE - 2;
|
||||
}
|
||||
}
|
||||
str[ret] = '\n';
|
||||
str[ret + 1] = '\0';
|
||||
}
|
||||
|
||||
debug_send_line(ssl, level, file, line, str);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
/*
|
||||
* References:
|
||||
*
|
||||
* SEC1 http://www.secg.org/index.php?action=secg,docs_secg
|
||||
* SEC1 https://www.secg.org/sec1-v2.pdf
|
||||
* RFC 4492
|
||||
*/
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
/*
|
||||
* References:
|
||||
*
|
||||
* SEC1 http://www.secg.org/index.php?action=secg,docs_secg
|
||||
* SEC1 https://www.secg.org/sec1-v2.pdf
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
@ -20,13 +20,15 @@
|
||||
/*
|
||||
* References:
|
||||
*
|
||||
* SEC1 http://www.secg.org/index.php?action=secg,docs_secg
|
||||
* SEC1 https://www.secg.org/sec1-v2.pdf
|
||||
* GECC = Guide to Elliptic Curve Cryptography - Hankerson, Menezes, Vanstone
|
||||
* FIPS 186-3 http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf
|
||||
* RFC 4492 for the related TLS structures and constants
|
||||
* - https://www.rfc-editor.org/rfc/rfc4492
|
||||
* RFC 7748 for the Curve448 and Curve25519 curve definitions
|
||||
* - https://www.rfc-editor.org/rfc/rfc7748
|
||||
*
|
||||
* [Curve25519] http://cr.yp.to/ecdh/curve25519-20060209.pdf
|
||||
* [Curve25519] https://cr.yp.to/ecdh/curve25519-20060209.pdf
|
||||
*
|
||||
* [2] CORON, Jean-S'ebastien. Resistance against differential power analysis
|
||||
* for elliptic curve cryptosystems. In : Cryptographic Hardware and
|
||||
@ -164,7 +166,7 @@ static int ecp_drbg_seed(ecp_drbg_context *ctx,
|
||||
unsigned char secret_bytes[MBEDTLS_ECP_MAX_BYTES];
|
||||
/* The list starts with strong hashes */
|
||||
const mbedtls_md_type_t md_type =
|
||||
(const mbedtls_md_type_t) (mbedtls_md_list()[0]);
|
||||
(mbedtls_md_type_t) (mbedtls_md_list()[0]);
|
||||
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(md_type);
|
||||
|
||||
if (secret_len > MBEDTLS_ECP_MAX_BYTES) {
|
||||
@ -2591,6 +2593,7 @@ static int ecp_mul_mxz(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
void *p_rng)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
int have_rng = 1;
|
||||
size_t i;
|
||||
unsigned char b;
|
||||
mbedtls_ecp_point RP;
|
||||
@ -2623,9 +2626,8 @@ static int ecp_mul_mxz(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
/* RP.X might be slightly larger than P, so reduce it */
|
||||
MOD_ADD(RP.X);
|
||||
|
||||
/* Randomize coordinates of the starting point */
|
||||
int have_rng = 1;
|
||||
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
|
||||
/* Derandomize coordinates of the starting point */
|
||||
if (f_rng == NULL) {
|
||||
have_rng = 0;
|
||||
}
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -90,6 +90,7 @@ static int wsa_init_done = 0;
|
||||
#include <errno.h>
|
||||
|
||||
#define IS_EINTR(ret) ((ret) == EINTR)
|
||||
#define SOCKET int
|
||||
|
||||
#endif /* ( _WIN32 || _WIN32_WCE ) && !EFIX64 && !EFI32 */
|
||||
|
||||
@ -494,13 +495,13 @@ int mbedtls_net_poll(mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout)
|
||||
FD_ZERO(&read_fds);
|
||||
if (rw & MBEDTLS_NET_POLL_READ) {
|
||||
rw &= ~MBEDTLS_NET_POLL_READ;
|
||||
FD_SET(fd, &read_fds);
|
||||
FD_SET((SOCKET) fd, &read_fds);
|
||||
}
|
||||
|
||||
FD_ZERO(&write_fds);
|
||||
if (rw & MBEDTLS_NET_POLL_WRITE) {
|
||||
rw &= ~MBEDTLS_NET_POLL_WRITE;
|
||||
FD_SET(fd, &write_fds);
|
||||
FD_SET((SOCKET) fd, &write_fds);
|
||||
}
|
||||
|
||||
if (rw != 0) {
|
||||
@ -608,7 +609,7 @@ int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf,
|
||||
}
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
FD_SET(fd, &read_fds);
|
||||
FD_SET((SOCKET) fd, &read_fds);
|
||||
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
|
@ -646,6 +646,7 @@ int mbedtls_pk_wrap_as_opaque(mbedtls_pk_context *pk,
|
||||
psa_key_type_t key_type;
|
||||
size_t bits;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t status;
|
||||
|
||||
/* export the private key material in the format PSA wants */
|
||||
if (mbedtls_pk_get_type(pk) != MBEDTLS_PK_ECKEY) {
|
||||
@ -668,7 +669,9 @@ int mbedtls_pk_wrap_as_opaque(mbedtls_pk_context *pk,
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_ECDSA(hash_alg));
|
||||
|
||||
/* import private key into PSA */
|
||||
if (PSA_SUCCESS != psa_import_key(&attributes, d, d_len, key)) {
|
||||
status = psa_import_key(&attributes, d, d_len, key);
|
||||
mbedtls_platform_zeroize(d, sizeof(d));
|
||||
if (status != PSA_SUCCESS) {
|
||||
return MBEDTLS_ERR_PK_HW_ACCEL_FAILED;
|
||||
}
|
||||
|
||||
|
@ -1235,6 +1235,8 @@ int mbedtls_pk_parse_key(mbedtls_pk_context *pk,
|
||||
mbedtls_pem_context pem;
|
||||
#endif
|
||||
|
||||
(void) pk_info;
|
||||
|
||||
PK_VALIDATE_RET(pk != NULL);
|
||||
if (keylen == 0) {
|
||||
return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
|
||||
|
@ -178,6 +178,11 @@ int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
||||
(void) p;
|
||||
(void) start;
|
||||
(void) key;
|
||||
(void) ret;
|
||||
|
||||
PK_VALIDATE_RET(p != NULL);
|
||||
PK_VALIDATE_RET(*p != NULL);
|
||||
PK_VALIDATE_RET(start != NULL);
|
||||
@ -313,6 +318,10 @@ int mbedtls_pk_write_key_der(mbedtls_pk_context *key, unsigned char *buf, size_t
|
||||
unsigned char *c;
|
||||
size_t len = 0;
|
||||
|
||||
(void) ret;
|
||||
(void) c;
|
||||
(void) key;
|
||||
|
||||
PK_VALIDATE_RET(key != NULL);
|
||||
if (size == 0) {
|
||||
return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
|
||||
|
@ -1472,6 +1472,7 @@ psa_status_t psa_export_public_key(mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot;
|
||||
|
||||
/* Reject a zero-length output buffer now, since this can never be a
|
||||
@ -1498,7 +1499,7 @@ psa_status_t psa_export_public_key(mbedtls_svc_key_id_t key,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
status = psa_driver_wrapper_export_public_key(
|
||||
@ -2406,6 +2407,7 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
|
||||
/* A context must be freshly initialized before it can be set up. */
|
||||
@ -2423,7 +2425,7 @@ static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -2594,6 +2596,7 @@ static psa_status_t psa_mac_compute_internal(mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot;
|
||||
uint8_t operation_mac_size = 0;
|
||||
|
||||
@ -2606,7 +2609,7 @@ static psa_status_t psa_mac_compute_internal(mbedtls_svc_key_id_t key,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -2732,6 +2735,7 @@ static psa_status_t psa_sign_internal(mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot;
|
||||
|
||||
*signature_length = 0;
|
||||
@ -2764,7 +2768,7 @@ static psa_status_t psa_sign_internal(mbedtls_svc_key_id_t key,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -3303,6 +3307,7 @@ static psa_status_t psa_cipher_setup(psa_cipher_operation_t *operation,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
psa_key_usage_t usage = (cipher_operation == MBEDTLS_ENCRYPT ?
|
||||
PSA_KEY_USAGE_ENCRYPT :
|
||||
@ -3338,7 +3343,7 @@ static psa_status_t psa_cipher_setup(psa_cipher_operation_t *operation,
|
||||
}
|
||||
operation->default_iv_length = PSA_CIPHER_IV_LENGTH(slot->attr.type, alg);
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -3561,6 +3566,7 @@ psa_status_t psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
uint8_t local_iv[PSA_CIPHER_IV_MAX_SIZE];
|
||||
size_t default_iv_length = 0;
|
||||
@ -3577,7 +3583,7 @@ psa_status_t psa_cipher_encrypt(mbedtls_svc_key_id_t key,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -3633,6 +3639,7 @@ psa_status_t psa_cipher_decrypt(mbedtls_svc_key_id_t key,
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
|
||||
if (!PSA_ALG_IS_CIPHER(alg)) {
|
||||
@ -3647,7 +3654,7 @@ psa_status_t psa_cipher_decrypt(mbedtls_svc_key_id_t key,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -4251,6 +4258,7 @@ static psa_status_t psa_generate_derived_key_internal(
|
||||
uint8_t *data = NULL;
|
||||
size_t bytes = PSA_BITS_TO_BYTES(bits);
|
||||
psa_status_t status;
|
||||
psa_key_attributes_t attributes;
|
||||
|
||||
if (!key_type_is_raw_bytes(slot->attr.type)) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
@ -4279,7 +4287,7 @@ static psa_status_t psa_generate_derived_key_internal(
|
||||
}
|
||||
|
||||
slot->attr.bits = (psa_key_bits_t) bits;
|
||||
psa_key_attributes_t attributes = {
|
||||
attributes = (psa_key_attributes_t) {
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
@ -4891,14 +4899,16 @@ static psa_status_t psa_key_agreement_raw_internal(psa_algorithm_t alg,
|
||||
size_t shared_secret_size,
|
||||
size_t *shared_secret_length)
|
||||
{
|
||||
mbedtls_ecp_keypair *ecp = NULL;
|
||||
psa_status_t status;
|
||||
|
||||
switch (alg) {
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
|
||||
case PSA_ALG_ECDH:
|
||||
if (!PSA_KEY_TYPE_IS_ECC_KEY_PAIR(private_key->attr.type)) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
mbedtls_ecp_keypair *ecp = NULL;
|
||||
psa_status_t status = mbedtls_psa_ecp_load_representation(
|
||||
status = mbedtls_psa_ecp_load_representation(
|
||||
private_key->attr.type,
|
||||
private_key->attr.bits,
|
||||
private_key->key.data,
|
||||
@ -4916,6 +4926,8 @@ static psa_status_t psa_key_agreement_raw_internal(psa_algorithm_t alg,
|
||||
return status;
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_ECDH */
|
||||
default:
|
||||
(void) ecp;
|
||||
(void) status;
|
||||
(void) private_key;
|
||||
(void) peer_key;
|
||||
(void) peer_key_length;
|
||||
@ -5011,6 +5023,7 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_slot_t *slot = NULL;
|
||||
size_t expected_length;
|
||||
|
||||
if (!PSA_ALG_IS_KEY_AGREEMENT(alg)) {
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
@ -5030,7 +5043,7 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
|
||||
* PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE() is exact so the point is moot.
|
||||
* If FFDH is implemented, PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE() can easily
|
||||
* be exact for it as well. */
|
||||
size_t expected_length =
|
||||
expected_length =
|
||||
PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(slot->attr.type, slot->attr.bits);
|
||||
if (output_size < expected_length) {
|
||||
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
@ -5066,6 +5079,10 @@ exit:
|
||||
/* Random generation */
|
||||
/****************************************************************/
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#endif
|
||||
|
||||
/** Initialize the PSA random generator.
|
||||
*/
|
||||
static void mbedtls_psa_random_init(mbedtls_psa_random_context_t *rng)
|
||||
@ -5200,8 +5217,6 @@ int mbedtls_psa_get_random(void *p_rng,
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
|
||||
psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
|
||||
size_t seed_size)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ extern "C" {
|
||||
/* Sanity check: a file size must fit in 32 bits. Allow a generous
|
||||
* 64kB of metadata. */
|
||||
#if PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000
|
||||
#error PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000
|
||||
#error "PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000"
|
||||
#endif
|
||||
|
||||
/** The maximum permitted persistent slot number.
|
||||
|
@ -53,12 +53,16 @@
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#define CHECK(code) if ((ret = (code)) != 0) { return ret; }
|
||||
#define CHECK(code) \
|
||||
do { \
|
||||
if ((ret = (code)) != 0) { \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_RANGE(min, max, val) \
|
||||
do \
|
||||
{ \
|
||||
if ((val) < (min) || (val) > (max)) \
|
||||
{ \
|
||||
do { \
|
||||
if ((val) < (min) || (val) > (max)) { \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -125,7 +125,7 @@ static const x509_attr_descriptor_t *x509_attr_descr_from_name(const char *name,
|
||||
|
||||
int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = MBEDTLS_ERR_X509_INVALID_NAME;
|
||||
const char *s = name, *c = s;
|
||||
const char *end = s + strlen(s);
|
||||
const char *oid = NULL;
|
||||
@ -177,6 +177,9 @@ int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *nam
|
||||
|
||||
s = c + 1;
|
||||
in_tag = 1;
|
||||
|
||||
/* Successfully parsed one name, update ret to success */
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
if (!in_tag && s != c + 1) {
|
||||
@ -282,9 +285,11 @@ int mbedtls_x509_write_names(unsigned char **p, unsigned char *start,
|
||||
|
||||
int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
unsigned char *sig, size_t size)
|
||||
unsigned char *sig, size_t size,
|
||||
mbedtls_pk_type_t pk_alg)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
int write_null_par;
|
||||
size_t len = 0;
|
||||
|
||||
if (*p < start || (size_t) (*p - start) < size) {
|
||||
@ -307,8 +312,19 @@ int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start,
|
||||
|
||||
// Write OID
|
||||
//
|
||||
MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_algorithm_identifier(p, start, oid,
|
||||
oid_len, 0));
|
||||
if (pk_alg == MBEDTLS_PK_ECDSA) {
|
||||
/*
|
||||
* The AlgorithmIdentifier's parameters field must be absent for DSA/ECDSA signature
|
||||
* algorithms, see https://www.rfc-editor.org/rfc/rfc5480#page-17 and
|
||||
* https://www.rfc-editor.org/rfc/rfc5758#section-3.
|
||||
*/
|
||||
write_null_par = 0;
|
||||
} else {
|
||||
write_null_par = 1;
|
||||
}
|
||||
MBEDTLS_ASN1_CHK_ADD(len,
|
||||
mbedtls_asn1_write_algorithm_identifier_ext(p, start, oid, oid_len,
|
||||
0, write_null_par));
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
@ -1945,15 +1945,18 @@ int mbedtls_x509_parse_subject_alt_name(const mbedtls_x509_buf *san_buf,
|
||||
}
|
||||
|
||||
#define PRINT_ITEM(i) \
|
||||
{ \
|
||||
do { \
|
||||
ret = mbedtls_snprintf(p, n, "%s" i, sep); \
|
||||
MBEDTLS_X509_SAFE_SNPRINTF; \
|
||||
sep = ", "; \
|
||||
}
|
||||
} while (0)
|
||||
|
||||
#define CERT_TYPE(type, name) \
|
||||
if (ns_cert_type & (type)) \
|
||||
PRINT_ITEM(name);
|
||||
do { \
|
||||
if (ns_cert_type & (type)) { \
|
||||
PRINT_ITEM(name); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int x509_info_cert_type(char **buf, size_t *size,
|
||||
unsigned char ns_cert_type)
|
||||
@ -1979,8 +1982,11 @@ static int x509_info_cert_type(char **buf, size_t *size,
|
||||
}
|
||||
|
||||
#define KEY_USAGE(code, name) \
|
||||
if (key_usage & (code)) \
|
||||
PRINT_ITEM(name);
|
||||
do { \
|
||||
if (key_usage & (code)) { \
|
||||
PRINT_ITEM(name); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int x509_info_key_usage(char **buf, size_t *size,
|
||||
unsigned int key_usage)
|
||||
|
@ -342,6 +342,7 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
size_t sub_len = 0, pub_len = 0, sig_and_oid_len = 0, sig_len;
|
||||
size_t len = 0;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
int write_sig_null_par;
|
||||
|
||||
/*
|
||||
* Prepare data to be signed at the end of the target buffer
|
||||
@ -433,9 +434,20 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
/*
|
||||
* Signature ::= AlgorithmIdentifier
|
||||
*/
|
||||
if (pk_alg == MBEDTLS_PK_ECDSA) {
|
||||
/*
|
||||
* The AlgorithmIdentifier's parameters field must be absent for DSA/ECDSA signature
|
||||
* algorithms, see https://www.rfc-editor.org/rfc/rfc5480#page-17 and
|
||||
* https://www.rfc-editor.org/rfc/rfc5758#section-3.
|
||||
*/
|
||||
write_sig_null_par = 0;
|
||||
} else {
|
||||
write_sig_null_par = 1;
|
||||
}
|
||||
MBEDTLS_ASN1_CHK_ADD(len,
|
||||
mbedtls_asn1_write_algorithm_identifier(&c, buf,
|
||||
sig_oid, strlen(sig_oid), 0));
|
||||
mbedtls_asn1_write_algorithm_identifier_ext(&c, buf,
|
||||
sig_oid, strlen(sig_oid),
|
||||
0, write_sig_null_par));
|
||||
|
||||
/*
|
||||
* Serial ::= INTEGER
|
||||
@ -492,8 +504,8 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
* into the CRT buffer. */
|
||||
c2 = buf + size;
|
||||
MBEDTLS_ASN1_CHK_ADD(sig_and_oid_len, mbedtls_x509_write_sig(&c2, c,
|
||||
sig_oid, sig_oid_len, sig,
|
||||
sig_len));
|
||||
sig_oid, sig_oid_len,
|
||||
sig, sig_len, pk_alg));
|
||||
|
||||
/*
|
||||
* Memory layout after this step:
|
||||
|
@ -265,7 +265,7 @@ static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
|
||||
c2 = buf + size;
|
||||
MBEDTLS_ASN1_CHK_ADD(sig_and_oid_len,
|
||||
mbedtls_x509_write_sig(&c2, buf + len, sig_oid, sig_oid_len,
|
||||
sig, sig_len));
|
||||
sig, sig_len, pk_alg));
|
||||
|
||||
/*
|
||||
* Compact the space between the CSR data and signature by moving the
|
||||
|
3
programs/.gitignore
vendored
3
programs/.gitignore
vendored
@ -5,9 +5,6 @@
|
||||
*.sln
|
||||
*.vcxproj
|
||||
|
||||
*.o
|
||||
*.exe
|
||||
|
||||
aes/crypt_and_hash
|
||||
hash/generic_sum
|
||||
hash/hello
|
||||
|
@ -92,6 +92,9 @@ int main(int argc, char *argv[])
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_cipher_context_t cipher_ctx;
|
||||
mbedtls_md_context_t md_ctx;
|
||||
mbedtls_cipher_mode_t cipher_mode;
|
||||
unsigned int cipher_block_size;
|
||||
unsigned char md_size;
|
||||
#if defined(_WIN32_WCE)
|
||||
long filesize, offset;
|
||||
#elif defined(_WIN32)
|
||||
@ -240,6 +243,9 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
md_size = mbedtls_md_get_size(md_info);
|
||||
cipher_block_size = mbedtls_cipher_get_block_size(&cipher_ctx);
|
||||
|
||||
if (mode == MODE_ENCRYPT) {
|
||||
/*
|
||||
* Generate the initialization vector as:
|
||||
@ -332,9 +338,9 @@ int main(int argc, char *argv[])
|
||||
/*
|
||||
* Encrypt and write the ciphertext.
|
||||
*/
|
||||
for (offset = 0; offset < filesize; offset += mbedtls_cipher_get_block_size(&cipher_ctx)) {
|
||||
ilen = ((unsigned int) filesize - offset > mbedtls_cipher_get_block_size(&cipher_ctx)) ?
|
||||
mbedtls_cipher_get_block_size(&cipher_ctx) : (unsigned int) (filesize - offset);
|
||||
for (offset = 0; offset < filesize; offset += cipher_block_size) {
|
||||
ilen = ((unsigned int) filesize - offset > cipher_block_size) ?
|
||||
cipher_block_size : (unsigned int) (filesize - offset);
|
||||
|
||||
if (fread(buffer, 1, ilen, fin) != ilen) {
|
||||
mbedtls_fprintf(stderr, "fread(%ld bytes) failed\n", (long) ilen);
|
||||
@ -379,8 +385,8 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (fwrite(digest, 1, mbedtls_md_get_size(md_info), fout) != mbedtls_md_get_size(md_info)) {
|
||||
mbedtls_fprintf(stderr, "fwrite(%d bytes) failed\n", mbedtls_md_get_size(md_info));
|
||||
if (fwrite(digest, 1, md_size, fout) != md_size) {
|
||||
mbedtls_fprintf(stderr, "fwrite(%d bytes) failed\n", md_size);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@ -395,12 +401,12 @@ int main(int argc, char *argv[])
|
||||
* N*16 .. (N+1)*16 - 1 Encrypted Block #N
|
||||
* (N+1)*16 .. (N+1)*16 + n Hash(ciphertext)
|
||||
*/
|
||||
if (filesize < 16 + mbedtls_md_get_size(md_info)) {
|
||||
if (filesize < 16 + md_size) {
|
||||
mbedtls_fprintf(stderr, "File too short to be encrypted.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_get_block_size(&cipher_ctx) == 0) {
|
||||
if (cipher_block_size == 0) {
|
||||
mbedtls_fprintf(stderr, "Invalid cipher block size: 0. \n");
|
||||
goto exit;
|
||||
}
|
||||
@ -408,18 +414,21 @@ int main(int argc, char *argv[])
|
||||
/*
|
||||
* Check the file size.
|
||||
*/
|
||||
if (cipher_info->mode != MBEDTLS_MODE_GCM &&
|
||||
((filesize - mbedtls_md_get_size(md_info)) %
|
||||
mbedtls_cipher_get_block_size(&cipher_ctx)) != 0) {
|
||||
cipher_mode = cipher_info->mode;
|
||||
if (cipher_mode != MBEDTLS_MODE_GCM &&
|
||||
cipher_mode != MBEDTLS_MODE_CTR &&
|
||||
cipher_mode != MBEDTLS_MODE_CFB &&
|
||||
cipher_mode != MBEDTLS_MODE_OFB &&
|
||||
((filesize - md_size) % cipher_block_size) != 0) {
|
||||
mbedtls_fprintf(stderr, "File content not a multiple of the block size (%u).\n",
|
||||
mbedtls_cipher_get_block_size(&cipher_ctx));
|
||||
cipher_block_size);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Subtract the IV + HMAC length.
|
||||
*/
|
||||
filesize -= (16 + mbedtls_md_get_size(md_info));
|
||||
filesize -= (16 + md_size);
|
||||
|
||||
/*
|
||||
* Read the IV and original filesize modulo 16.
|
||||
@ -481,13 +490,13 @@ int main(int argc, char *argv[])
|
||||
/*
|
||||
* Decrypt and write the plaintext.
|
||||
*/
|
||||
for (offset = 0; offset < filesize; offset += mbedtls_cipher_get_block_size(&cipher_ctx)) {
|
||||
ilen = ((unsigned int) filesize - offset > mbedtls_cipher_get_block_size(&cipher_ctx)) ?
|
||||
mbedtls_cipher_get_block_size(&cipher_ctx) : (unsigned int) (filesize - offset);
|
||||
for (offset = 0; offset < filesize; offset += cipher_block_size) {
|
||||
ilen = ((unsigned int) filesize - offset > cipher_block_size) ?
|
||||
cipher_block_size : (unsigned int) (filesize - offset);
|
||||
|
||||
if (fread(buffer, 1, ilen, fin) != ilen) {
|
||||
mbedtls_fprintf(stderr, "fread(%u bytes) failed\n",
|
||||
mbedtls_cipher_get_block_size(&cipher_ctx));
|
||||
cipher_block_size);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -515,14 +524,14 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (fread(buffer, 1, mbedtls_md_get_size(md_info), fin) != mbedtls_md_get_size(md_info)) {
|
||||
mbedtls_fprintf(stderr, "fread(%d bytes) failed\n", mbedtls_md_get_size(md_info));
|
||||
if (fread(buffer, 1, md_size, fin) != md_size) {
|
||||
mbedtls_fprintf(stderr, "fread(%d bytes) failed\n", md_size);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Use constant-time buffer comparison */
|
||||
diff = 0;
|
||||
for (i = 0; i < mbedtls_md_get_size(md_info); i++) {
|
||||
for (i = 0; i < md_size; i++) {
|
||||
diff |= digest[i] ^ buffer[i];
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ mbedtls_time_t dummy_constant_time(mbedtls_time_t *time)
|
||||
}
|
||||
#endif
|
||||
|
||||
void dummy_init()
|
||||
void dummy_init(void)
|
||||
{
|
||||
#if defined(MBEDTLS_PLATFORM_TIME_ALT)
|
||||
mbedtls_platform_set_time(dummy_constant_time);
|
||||
|
@ -19,7 +19,7 @@ typedef struct fuzzBufferOffset {
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
mbedtls_time_t dummy_constant_time(mbedtls_time_t *time);
|
||||
#endif
|
||||
void dummy_init();
|
||||
void dummy_init(void);
|
||||
|
||||
int dummy_send(void *ctx, const unsigned char *buf, size_t len);
|
||||
int fuzz_recv(void *ctx, unsigned char *buf, size_t len);
|
||||
|
@ -77,6 +77,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
goto exit;
|
||||
@ -184,6 +191,9 @@ exit:
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -61,6 +61,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
srand(1);
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
@ -119,6 +126,9 @@ exit:
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -74,6 +74,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_ssl_cookie_init(&cookie_ctx);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
goto exit;
|
||||
@ -152,9 +159,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
exit:
|
||||
mbedtls_ssl_cookie_free(&cookie_ctx);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_x509_crt_free(&srvcert);
|
||||
#endif
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -18,6 +18,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
}
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
ret = mbedtls_pk_parse_key(&pk, Data, Size, NULL, 0);
|
||||
if (ret == 0) {
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
@ -63,6 +71,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_pk_free(&pk);
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -9,6 +9,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_pk_context pk;
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
ret = mbedtls_pk_parse_public_key(&pk, Data, Size);
|
||||
if (ret == 0) {
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
@ -64,6 +70,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_pk_free(&pk);
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -89,6 +89,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_ssl_ticket_init(&ticket_ctx);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, dummy_entropy, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
goto exit;
|
||||
@ -195,8 +202,14 @@ exit:
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C)
|
||||
mbedtls_x509_crt_free(&srvcert);
|
||||
mbedtls_pk_free(&pkey);
|
||||
#endif
|
||||
mbedtls_ssl_free(&ssl);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif
|
||||
#else
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
|
@ -9,10 +9,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
unsigned char buf[4096];
|
||||
|
||||
mbedtls_x509_crl_init(&crl);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
ret = mbedtls_x509_crl_parse(&crl, Data, Size);
|
||||
if (ret == 0) {
|
||||
ret = mbedtls_x509_crl_info((char *) buf, sizeof(buf) - 1, " ", &crl);
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_crl_free(&crl);
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -9,10 +9,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
unsigned char buf[4096];
|
||||
|
||||
mbedtls_x509_crt_init(&crt);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
ret = mbedtls_x509_crt_parse(&crt, Data, Size);
|
||||
if (ret == 0) {
|
||||
ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt);
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_crt_free(&crt);
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -9,10 +9,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
unsigned char buf[4096];
|
||||
|
||||
mbedtls_x509_csr_init(&csr);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
ret = mbedtls_x509_csr_parse(&csr, Data, Size);
|
||||
if (ret == 0) {
|
||||
ret = mbedtls_x509_csr_info((char *) buf, sizeof(buf) - 1, " ", &csr);
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_csr_free(&csr);
|
||||
#else
|
||||
(void) Data;
|
||||
|
@ -18,34 +18,48 @@ int main(int argc, char **argv)
|
||||
FILE *fp;
|
||||
uint8_t *Data;
|
||||
size_t Size;
|
||||
const char *argv0 = argv[0] == NULL ? "PROGRAM_NAME" : argv[0];
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s REPRODUCER_FILE\n", argv0);
|
||||
return 1;
|
||||
}
|
||||
//opens the file, get its size, and reads it into a buffer
|
||||
fp = fopen(argv[1], "rb");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "%s: Error in fopen\n", argv0);
|
||||
perror(argv[1]);
|
||||
return 2;
|
||||
}
|
||||
if (fseek(fp, 0L, SEEK_END) != 0) {
|
||||
fprintf(stderr, "%s: Error in fseek(SEEK_END)\n", argv0);
|
||||
perror(argv[1]);
|
||||
fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
Size = ftell(fp);
|
||||
if (Size == (size_t) -1) {
|
||||
fprintf(stderr, "%s: Error in ftell\n", argv0);
|
||||
perror(argv[1]);
|
||||
fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
if (fseek(fp, 0L, SEEK_SET) != 0) {
|
||||
fprintf(stderr, "%s: Error in fseek(0)\n", argv0);
|
||||
perror(argv[1]);
|
||||
fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
Data = malloc(Size);
|
||||
if (Data == NULL) {
|
||||
fprintf(stderr, "%s: Could not allocate memory\n", argv0);
|
||||
perror(argv[1]);
|
||||
fclose(fp);
|
||||
return 2;
|
||||
}
|
||||
if (fread(Data, Size, 1, fp) != 1) {
|
||||
fprintf(stderr, "%s: Error in fread\n", argv0);
|
||||
perror(argv[1]);
|
||||
free(Data);
|
||||
fclose(fp);
|
||||
return 2;
|
||||
|
@ -204,6 +204,15 @@ int main(int argc, char *argv[])
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc < 2) {
|
||||
usage:
|
||||
mbedtls_printf(USAGE);
|
||||
@ -411,6 +420,9 @@ exit:
|
||||
mbedtls_pk_free(&key);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -91,6 +91,15 @@ int main(int argc, char *argv[])
|
||||
mbedtls_pk_init(&pk);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto cleanup;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
||||
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
|
||||
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
|
||||
@ -275,6 +284,9 @@ cleanup:
|
||||
#endif
|
||||
|
||||
mbedtls_pk_free(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_mpi_free(&N); mbedtls_mpi_free(&P); mbedtls_mpi_free(&Q);
|
||||
mbedtls_mpi_free(&D); mbedtls_mpi_free(&E); mbedtls_mpi_free(&DP);
|
||||
mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP);
|
||||
|
@ -205,6 +205,15 @@ int main(int argc, char *argv[])
|
||||
memset(buf, 0, sizeof(buf));
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_mpi_init(&N); mbedtls_mpi_init(&P); mbedtls_mpi_init(&Q);
|
||||
mbedtls_mpi_init(&D); mbedtls_mpi_init(&E); mbedtls_mpi_init(&DP);
|
||||
mbedtls_mpi_init(&DQ); mbedtls_mpi_init(&QP);
|
||||
@ -400,6 +409,9 @@ exit:
|
||||
mbedtls_mpi_free(&DQ); mbedtls_mpi_free(&QP);
|
||||
|
||||
mbedtls_pk_free(&key);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -71,6 +71,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
memset(result, 0, sizeof(result));
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 2) {
|
||||
mbedtls_printf("usage: mbedtls_pk_decrypt <key_file>\n");
|
||||
|
||||
@ -142,6 +151,9 @@ exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
|
||||
|
@ -67,6 +67,15 @@ int main(int argc, char *argv[])
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 3) {
|
||||
mbedtls_printf("usage: mbedtls_pk_encrypt <key_file> <string of max 100 characters>\n");
|
||||
|
||||
@ -144,6 +153,9 @@ exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
|
||||
|
@ -66,6 +66,15 @@ int main(int argc, char *argv[])
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 3) {
|
||||
mbedtls_printf("usage: mbedtls_pk_sign <key_file> <filename>\n");
|
||||
|
||||
@ -141,6 +150,9 @@ exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
|
||||
|
@ -58,6 +58,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 3) {
|
||||
mbedtls_printf("usage: mbedtls_pk_verify <key_file> <filename>\n");
|
||||
|
||||
@ -117,6 +126,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_ERROR_C)
|
||||
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
|
||||
|
@ -67,6 +67,15 @@ int main(int argc, char *argv[])
|
||||
mbedtls_pk_init(&pk);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 3) {
|
||||
mbedtls_printf("usage: rsa_sign_pss <key_file> <filename>\n");
|
||||
|
||||
@ -149,6 +158,9 @@ exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -61,6 +61,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
mbedtls_pk_init(&pk);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc != 3) {
|
||||
mbedtls_printf("usage: rsa_verify_pss <key_file> <filename>\n");
|
||||
|
||||
@ -127,6 +136,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -17,9 +17,27 @@
|
||||
|
||||
set -e -u
|
||||
|
||||
program="${0%/*}"/key_ladder_demo
|
||||
program_name="key_ladder_demo"
|
||||
program="${0%/*}/$program_name"
|
||||
files_to_clean=
|
||||
|
||||
if [ ! -e "$program" ]; then
|
||||
# Look for programs in the current directory and the directories above it
|
||||
for dir in "." ".." "../.."; do
|
||||
program="$dir/programs/psa/$program_name"
|
||||
if [ -e "$program" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ ! -e "$program" ]; then
|
||||
echo "Could not find $program_name executable"
|
||||
|
||||
echo "If building out-of-tree, this script must be run" \
|
||||
"from the project build directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
run () {
|
||||
echo
|
||||
echo "# $1"
|
||||
|
@ -113,11 +113,21 @@ int main(int argc, char *argv[])
|
||||
mbedtls_ssl_config_init(&conf);
|
||||
mbedtls_x509_crt_init(&cacert);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
@ -324,12 +334,14 @@ exit:
|
||||
#endif
|
||||
|
||||
mbedtls_net_free(&server_fd);
|
||||
|
||||
mbedtls_x509_crt_free(&cacert);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -124,6 +124,16 @@ int main(void)
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_debug_set_threshold(DEBUG_LEVEL);
|
||||
#endif
|
||||
@ -394,6 +404,9 @@ exit:
|
||||
#endif
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf(" Press Enter to exit this program.\n");
|
||||
|
@ -179,8 +179,16 @@ int main(void)
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
mbedtls_x509_crt_init(&ca);
|
||||
#endif
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers, strlen(pers)) != 0) {
|
||||
ret = ctr_drbg_seed_failed;
|
||||
@ -266,7 +274,6 @@ int main(void)
|
||||
|
||||
exit:
|
||||
mbedtls_net_free(&server_fd);
|
||||
|
||||
mbedtls_ssl_free(&ssl);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
@ -274,6 +281,9 @@ exit:
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
mbedtls_x509_crt_free(&ca);
|
||||
#endif
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_exit(ret);
|
||||
}
|
||||
|
@ -95,11 +95,21 @@ int main(void)
|
||||
mbedtls_ssl_config_init(&conf);
|
||||
mbedtls_x509_crt_init(&cacert);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
@ -274,12 +284,14 @@ exit:
|
||||
#endif
|
||||
|
||||
mbedtls_net_free(&server_fd);
|
||||
|
||||
mbedtls_x509_crt_free(&cacert);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -127,12 +128,12 @@ const char buf_ln_err[] = "Buffer does not have enough data to complete the pars
|
||||
/*
|
||||
* Basic printing functions
|
||||
*/
|
||||
void print_version()
|
||||
void print_version(void)
|
||||
{
|
||||
printf("%s v%d.%d\n", PROG_NAME, VER_MAJOR, VER_MINOR);
|
||||
}
|
||||
|
||||
void print_usage()
|
||||
void print_usage(void)
|
||||
{
|
||||
print_version();
|
||||
printf("\nThis program is used to deserialize an Mbed TLS SSL session from the base64 code provided\n"
|
||||
@ -181,7 +182,7 @@ void printf_err(const char *str, ...)
|
||||
/*
|
||||
* Exit from the program in case of error
|
||||
*/
|
||||
void error_exit()
|
||||
void error_exit(void)
|
||||
{
|
||||
if (NULL != b64_file) {
|
||||
fclose(b64_file);
|
||||
@ -939,6 +940,15 @@ int main(int argc, char *argv[])
|
||||
size_t ssl_max_len = SSL_INIT_LEN;
|
||||
size_t ssl_len = 0;
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
/* The 'b64_file' is opened when parsing arguments to check that the
|
||||
* file name is correct */
|
||||
parse_arguments(argc, argv);
|
||||
@ -1007,6 +1017,10 @@ int main(int argc, char *argv[])
|
||||
printf("Finished. No valid base64 code found\n");
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,15 @@ int main(void)
|
||||
mbedtls_x509_crt_init(&srvcert);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
||||
/*
|
||||
@ -369,13 +378,15 @@ int main(void)
|
||||
exit:
|
||||
mbedtls_net_free(&client_fd);
|
||||
mbedtls_net_free(&listen_fd);
|
||||
|
||||
mbedtls_x509_crt_free(&srvcert);
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" Press Enter to exit this program.\n");
|
||||
|
@ -366,6 +366,16 @@ int main(int argc, char *argv[])
|
||||
mbedtls_x509_crt_init(&clicert);
|
||||
mbedtls_pk_init(&pkey);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc < 2) {
|
||||
usage:
|
||||
@ -455,7 +465,6 @@ usage:
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
@ -792,6 +801,9 @@ exit:
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
@ -337,6 +337,16 @@ int main(void)
|
||||
*/
|
||||
mbedtls_entropy_init(&entropy);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
/*
|
||||
* 1. Load the certificates and private RSA key
|
||||
*/
|
||||
@ -477,14 +487,14 @@ exit:
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
mbedtls_ssl_config_free(&conf);
|
||||
|
||||
mbedtls_net_free(&listen_fd);
|
||||
|
||||
mbedtls_mutex_free(&debug_mutex);
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
mbedtls_memory_buffer_alloc_free();
|
||||
#endif
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" Press Enter to exit this program.\n");
|
||||
|
@ -109,6 +109,16 @@ int main(void)
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
mbedtls_debug_set_threshold(DEBUG_LEVEL);
|
||||
#endif
|
||||
@ -347,7 +357,6 @@ exit:
|
||||
|
||||
mbedtls_net_free(&client_fd);
|
||||
mbedtls_net_free(&listen_fd);
|
||||
|
||||
mbedtls_x509_crt_free(&srvcert);
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_ssl_free(&ssl);
|
||||
@ -357,6 +366,9 @@ exit:
|
||||
#endif
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" Press Enter to exit this program.\n");
|
||||
|
@ -20,8 +20,29 @@
|
||||
|
||||
set -e -u
|
||||
|
||||
program_name="dlopen"
|
||||
program_dir="${0%/*}"
|
||||
program="$program_dir/dlopen"
|
||||
program="$program_dir/$program_name"
|
||||
|
||||
if [ ! -e "$program" ]; then
|
||||
# Look for programs in the current directory and the directories above it
|
||||
for dir in "." ".." "../.."; do
|
||||
program_dir="$dir/programs/test"
|
||||
program="$program_dir/$program_name"
|
||||
if [ -e "$program" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ ! -e "$program" ]; then
|
||||
echo "Could not find $program_name program"
|
||||
|
||||
echo "Make sure that Mbed TLS is built as a shared library." \
|
||||
"If building out-of-tree, this script must be run" \
|
||||
"from the project build directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
top_dir="$program_dir/../.."
|
||||
library_dir="$top_dir/library"
|
||||
|
||||
|
@ -645,7 +645,7 @@ void delay_packet(packet *delay)
|
||||
memcpy(&prev[prev_len++], delay, sizeof(packet));
|
||||
}
|
||||
|
||||
int send_delayed()
|
||||
int send_delayed(void)
|
||||
{
|
||||
uint8_t offset;
|
||||
int ret;
|
||||
|
@ -157,6 +157,7 @@ int main(int argc, char *argv[])
|
||||
mbedtls_ssl_init(&ssl);
|
||||
mbedtls_ssl_config_init(&conf);
|
||||
mbedtls_x509_crt_init(&cacert);
|
||||
mbedtls_entropy_init(&entropy);
|
||||
#if defined(MBEDTLS_X509_CRL_PARSE_C)
|
||||
mbedtls_x509_crl_init(&cacrl);
|
||||
#else
|
||||
@ -165,6 +166,15 @@ int main(int argc, char *argv[])
|
||||
memset(&cacrl, 0, sizeof(mbedtls_x509_crl));
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
(int) status);
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (argc < 2) {
|
||||
usage:
|
||||
mbedtls_printf(USAGE);
|
||||
@ -342,7 +352,6 @@ usage:
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
@ -452,6 +461,9 @@ exit:
|
||||
#endif
|
||||
mbedtls_ctr_drbg_free(&ctr_drbg);
|
||||
mbedtls_entropy_free(&entropy);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf(" + Press Enter to exit this program.\n");
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user