mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-07-30 16:26:33 +08:00
Merge remote-tracking branch 'development' into restricted-mbedtls-merge-public-20250916
Conflicts: * `tf-psa-crypto`: updated to the merge of `development` and `development-restricted`.
This commit is contained in:
commit
a1d6b2733b
@ -100,17 +100,6 @@ option(USE_SHARED_MBEDTLS_LIBRARY "Build Mbed TLS shared library." OFF)
|
||||
option(LINK_WITH_PTHREAD "Explicitly link Mbed TLS library to pthread." OFF)
|
||||
option(LINK_WITH_TRUSTED_STORAGE "Explicitly link Mbed TLS library to trusted_storage." OFF)
|
||||
|
||||
# Warning string - created as a list for compatibility with CMake 2.8
|
||||
set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n")
|
||||
set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n")
|
||||
set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n")
|
||||
|
||||
set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}"
|
||||
"${CTR_DRBG_128_BIT_KEY_WARN_L1}"
|
||||
"${CTR_DRBG_128_BIT_KEY_WARN_L2}"
|
||||
"${CTR_DRBG_128_BIT_KEY_WARN_L3}"
|
||||
"${WARNING_BORDER}")
|
||||
|
||||
# Python 3 is only needed here to check for configuration warnings.
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.15.0)
|
||||
set(Python3_FIND_STRATEGY LOCATION)
|
||||
@ -124,16 +113,6 @@ else()
|
||||
set(MBEDTLS_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
endif()
|
||||
endif()
|
||||
if(MBEDTLS_PYTHON_EXECUTABLE)
|
||||
|
||||
# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
|
||||
execute_process(COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/mbedtls_config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
|
||||
RESULT_VARIABLE result)
|
||||
if(${result} EQUAL 0)
|
||||
message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING})
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
# We now potentially need to link all executables against PThreads, if available
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
|
||||
3
ChangeLog.d/10285.txt
Normal file
3
ChangeLog.d/10285.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Removals
|
||||
* Removed all public key sample programs from the programs/pkey
|
||||
directory.
|
||||
5
ChangeLog.d/check_config.txt
Normal file
5
ChangeLog.d/check_config.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Removals
|
||||
* The header <mbedtls/check_config.h> no longer exists. Including it
|
||||
from a custom config file was no longer needed since Mbed TLS 3.0,
|
||||
and could lead to spurious errors. The checks that it performed are
|
||||
now done automatically when building the library.
|
||||
3
ChangeLog.d/fix-dependency-on-generated-files.txt
Normal file
3
ChangeLog.d/fix-dependency-on-generated-files.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* Fix potential CMake parallel build failure when building both the static
|
||||
and shared libraries.
|
||||
11
ChangeLog.d/remove-deprecated-items.txt
Normal file
11
ChangeLog.d/remove-deprecated-items.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Removals
|
||||
* Remove MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT. Now only the
|
||||
standard version (defined in RFC 9146) of DTLS connection ID is supported.
|
||||
* Remove mbedtls_ssl_conf_min_version(), mbedtls_ssl_conf_max_version(), and
|
||||
the associated constants MBEDTLS_SSL_MAJOR_VERSION_x and
|
||||
MBEDTLS_SSL_MINOR_VERSION_y. Use mbedtls_ssl_conf_min_tls_version() and
|
||||
mbedtls_ssl_conf_max_tls_version() with MBEDTLS_SSL_VERSION_TLS1_y instead.
|
||||
Note that the new names of the new constants use the TLS protocol versions,
|
||||
unlike the old constants whose names are based on internal encodings.
|
||||
* Remove mbedtls_ssl_conf_sig_hashes(). Use mbedtls_ssl_conf_sig_algs()
|
||||
instead.
|
||||
3
ChangeLog.d/remove_mbedtls_pk_type.txt
Normal file
3
ChangeLog.d/remove_mbedtls_pk_type.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Removals
|
||||
* Remove mbedtls_pk_type_t from the public interface and replace it with
|
||||
mbedtls_pk_sigalg_t.
|
||||
9
ChangeLog.d/runtime-version-interface.txt
Normal file
9
ChangeLog.d/runtime-version-interface.txt
Normal file
@ -0,0 +1,9 @@
|
||||
API changes
|
||||
* Change the signature of the runtime version information methods that took
|
||||
a char* as an argument to take zero arguments and return a const char*
|
||||
instead. This aligns us with the interface used in TF PSA Crypto 1.0.
|
||||
If you need to support linking against both Mbed TLS 3.x and 4.x, please
|
||||
use the build-time version macros or mbedtls_version_get_number() to
|
||||
determine the correct signature for mbedtls_version_get_string() and
|
||||
mbedtls_version_get_string_full() before calling them.
|
||||
Fixes issue #10308.
|
||||
3
ChangeLog.d/secp256k1-removal.txt
Normal file
3
ChangeLog.d/secp256k1-removal.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Removals
|
||||
* Support for secp192k1, secp192r1, secp224k1 and secp224r1 EC curves is
|
||||
removed from TLS.
|
||||
3
ChangeLog.d/static-ecdh-removal.txt
Normal file
3
ChangeLog.d/static-ecdh-removal.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Removals
|
||||
* Removed support for TLS 1.2 static ECDH key
|
||||
exchanges (ECDH-ECDSA and ECDH-RSA).
|
||||
7
ChangeLog.d/unify-errors.txt
Normal file
7
ChangeLog.d/unify-errors.txt
Normal file
@ -0,0 +1,7 @@
|
||||
API changes
|
||||
* Make the following error codes aliases of their PSA equivalents, where
|
||||
xxx is a module, e.g. X509 or SSL.
|
||||
MBEDTLS_ERR_xxx_BAD_INPUT_DATA -> PSA_ERROR_INVALID_ARGUMENT
|
||||
MBEDTLS_ERR_xxx_ALLOC_FAILED -> PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
MBEDTLS_ERR_xxx_BUFFER_TOO_SMALL -> PSA_ERROR_BUFFER_TOO_SMALL
|
||||
MBEDTLS_ERR_PKCS7_VERIFY_FAIL -> PSA_ERROR_INVALID_SIGNATURE
|
||||
3
ChangeLog.d/x509write_crt_set_serial_raw-alignment.txt
Normal file
3
ChangeLog.d/x509write_crt_set_serial_raw-alignment.txt
Normal file
@ -0,0 +1,3 @@
|
||||
API changes
|
||||
* Change the serial argument of the mbedtls_x509write_crt_set_serial_raw
|
||||
function to a const to align with the rest of the API.
|
||||
19
Makefile
19
Makefile
@ -26,7 +26,6 @@ endif
|
||||
.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
|
||||
|
||||
all: programs tests
|
||||
$(MAKE) post_build
|
||||
|
||||
no_test: programs
|
||||
|
||||
@ -146,24 +145,6 @@ uninstall:
|
||||
done
|
||||
endif
|
||||
|
||||
|
||||
WARNING_BORDER_LONG =**********************************************************************************\n
|
||||
CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n
|
||||
CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n
|
||||
CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n
|
||||
|
||||
CTR_DRBG_128_BIT_KEY_WARNING=\n$(WARNING_BORDER_LONG)$(CTR_DRBG_128_BIT_KEY_WARN_L1)$(CTR_DRBG_128_BIT_KEY_WARN_L2)$(CTR_DRBG_128_BIT_KEY_WARN_L3)$(WARNING_BORDER_LONG)
|
||||
|
||||
# Post build steps
|
||||
post_build:
|
||||
ifndef WINDOWS
|
||||
|
||||
# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
|
||||
-scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
|
||||
echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
|
||||
|
||||
endif
|
||||
|
||||
clean: clean_more_on_top
|
||||
$(MAKE) -C library clean
|
||||
$(MAKE) -C programs clean
|
||||
|
||||
@ -72,7 +72,13 @@ The following tools are required:
|
||||
Depending on your Python installation, you may need to invoke `python` instead of `python3`. To install the packages system-wide, omit the `--user` option.
|
||||
* A C compiler for the host platform, for some test data.
|
||||
|
||||
If you are cross-compiling, you must set the `CC` environment variable to a C compiler for the host platform when generating the configuration-independent files.
|
||||
The scripts that generate the configuration-independent files will look for a host C compiler in the following places (in order of preference):
|
||||
|
||||
1. The `HOSTCC` environment variable. This can be used if `CC` is pointing to a cross-compiler.
|
||||
2. The `CC` environment variable.
|
||||
3. An executable called `cc` in the current path.
|
||||
|
||||
Note: If you have multiple toolchains installed, it is recommended to set `CC` or `HOSTCC` to the intended host compiler before generating the files.
|
||||
|
||||
Any of the following methods are available to generate the configuration-independent files:
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
/* Other MBEDTLS_HAVE_XXX flags irrelevant for this configuration */
|
||||
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
|
||||
|
||||
/* Save RAM at the expense of ROM */
|
||||
|
||||
@ -48,7 +48,6 @@
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_ASN1_WRITE_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
|
||||
|
||||
@ -55,7 +55,6 @@
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_ASN1_WRITE_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_HMAC_DRBG_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_PK_C
|
||||
|
||||
@ -18,11 +18,20 @@ As a consequence, the functions `mbedtls_low_level_strerr()` and `mbedtls_high_l
|
||||
|
||||
Many legacy error codes have been removed in favor of PSA error codes. Generally, functions that returned a legacy error code in the table below in Mbed TLS 3.6 now return the PSA error code listed on the same row. Similarly, callbacks should apply the same changes to error code, unless there has been a relevant change to the callback's interface.
|
||||
|
||||
| Legacy constant (Mbed TLS 3.6) | PSA constant (Mbed TLS 4.0) |
|
||||
| ------------------------------ | --------------------------- |
|
||||
| Legacy constant (Mbed TLS 3.6) | PSA constant (Mbed TLS 4.0) |
|
||||
|-----------------------------------------|---------------------------------|
|
||||
| `MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED` | `PSA_ERROR_CORRUPTION_DETECTED` |
|
||||
| `MBEDTLS_ERR_ERROR_GENERIC_ERROR` | `PSA_ERROR_GENERIC_ERROR` |
|
||||
| `MBEDTLS_ERR_OID_BUF_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL`
|
||||
| `MBEDTLS_ERR_OID_NOT_FOUND` | `PSA_ERROR_NOT_SUPPORTED` |
|
||||
| `MBEDTLS_ERR_ERROR_GENERIC_ERROR` | `PSA_ERROR_GENERIC_ERROR` |
|
||||
| `MBEDTLS_ERR_NET_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
|
||||
| `MBEDTLS_ERR_OID_BUF_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
|
||||
| `MBEDTLS_ERR_OID_NOT_FOUND` | `PSA_ERROR_NOT_SUPPORTED` |
|
||||
| `MBEDTLS_ERR_PKCS7_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
|
||||
| `MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA` | `PSA_ERROR_INVALID_ARGUMENT` |
|
||||
| `MBEDTLS_ERR_PKCS7_VERIFY_FAIL` | `PSA_ERROR_INVALID_SIGNATURE` |
|
||||
| `MBEDTLS_ERR_SSL_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
|
||||
| `MBEDTLS_ERR_SSL_BAD_INPUT_DATA` | `PSA_ERROR_INVALID_ARGUMENT` |
|
||||
| `MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
|
||||
| `MBEDTLS_ERR_X509_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
|
||||
| `MBEDTLS_ERR_X509_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
|
||||
|
||||
See also the corresponding section in the TF-PSA-Crypto migration guide, which lists error codes from cryptography modules.
|
||||
|
||||
@ -118,8 +118,6 @@ Support description
|
||||
| MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED | n/a |
|
||||
| MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED | n/a |
|
||||
| MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED | n/a |
|
||||
| MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED | n/a |
|
||||
| MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED | n/a |
|
||||
| MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED | n/a |
|
||||
| | |
|
||||
| MBEDTLS_PSA_CRYPTO_C | no (1) |
|
||||
|
||||
@ -1,84 +1,83 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with Python 3.8
|
||||
# This file is autogenerated by pip-compile with Python 3.9
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile requirements.in
|
||||
# pip-compile docs/requirements.in
|
||||
#
|
||||
alabaster==0.7.13
|
||||
alabaster==0.7.16
|
||||
# via sphinx
|
||||
babel==2.15.0
|
||||
babel==2.17.0
|
||||
# via sphinx
|
||||
breathe==4.35.0
|
||||
# via -r requirements.in
|
||||
certifi==2024.7.4
|
||||
breathe==4.36.0
|
||||
# via -r docs/requirements.in
|
||||
certifi==2025.8.3
|
||||
# via requests
|
||||
charset-normalizer==3.3.2
|
||||
charset-normalizer==3.4.3
|
||||
# via requests
|
||||
click==8.1.7
|
||||
click==8.1.8
|
||||
# via readthedocs-cli
|
||||
docutils==0.20.1
|
||||
docutils==0.21.2
|
||||
# via
|
||||
# breathe
|
||||
# sphinx
|
||||
# sphinx-rtd-theme
|
||||
idna==3.7
|
||||
idna==3.10
|
||||
# via requests
|
||||
imagesize==1.4.1
|
||||
# via sphinx
|
||||
importlib-metadata==8.0.0
|
||||
importlib-metadata==8.7.0
|
||||
# via sphinx
|
||||
jinja2==3.1.4
|
||||
jinja2==3.1.6
|
||||
# via sphinx
|
||||
markdown-it-py==3.0.0
|
||||
# via rich
|
||||
markupsafe==2.1.5
|
||||
markupsafe==3.0.2
|
||||
# via jinja2
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
packaging==24.1
|
||||
packaging==25.0
|
||||
# via sphinx
|
||||
pygments==2.18.0
|
||||
pygments==2.19.2
|
||||
# via
|
||||
# rich
|
||||
# sphinx
|
||||
pytz==2024.1
|
||||
# via babel
|
||||
pyyaml==6.0.1
|
||||
pyyaml==6.0.2
|
||||
# via readthedocs-cli
|
||||
readthedocs-cli==4
|
||||
# via -r requirements.in
|
||||
requests==2.32.3
|
||||
readthedocs-cli==5
|
||||
# via -r docs/requirements.in
|
||||
requests==2.32.5
|
||||
# via
|
||||
# readthedocs-cli
|
||||
# sphinx
|
||||
rich==13.7.1
|
||||
rich==14.1.0
|
||||
# via readthedocs-cli
|
||||
snowballstemmer==2.2.0
|
||||
snowballstemmer==3.0.1
|
||||
# via sphinx
|
||||
sphinx==7.1.2
|
||||
sphinx==7.4.7
|
||||
# via
|
||||
# breathe
|
||||
# sphinx-rtd-theme
|
||||
# sphinxcontrib-jquery
|
||||
sphinx-rtd-theme==2.0.0
|
||||
# via -r requirements.in
|
||||
sphinxcontrib-applehelp==1.0.4
|
||||
sphinx-rtd-theme==3.0.2
|
||||
# via -r docs/requirements.in
|
||||
sphinxcontrib-applehelp==2.0.0
|
||||
# via sphinx
|
||||
sphinxcontrib-devhelp==1.0.2
|
||||
sphinxcontrib-devhelp==2.0.0
|
||||
# via sphinx
|
||||
sphinxcontrib-htmlhelp==2.0.1
|
||||
sphinxcontrib-htmlhelp==2.1.0
|
||||
# via sphinx
|
||||
sphinxcontrib-jquery==4.1
|
||||
# via sphinx-rtd-theme
|
||||
sphinxcontrib-jsmath==1.0.1
|
||||
# via sphinx
|
||||
sphinxcontrib-qthelp==1.0.3
|
||||
sphinxcontrib-qthelp==2.0.0
|
||||
# via sphinx
|
||||
sphinxcontrib-serializinghtml==1.1.5
|
||||
sphinxcontrib-serializinghtml==2.0.0
|
||||
# via sphinx
|
||||
typing-extensions==4.12.2
|
||||
# via rich
|
||||
urllib3==2.2.2
|
||||
# via requests
|
||||
zipp==3.19.2
|
||||
tomli==2.2.1
|
||||
# via sphinx
|
||||
urllib3==2.5.0
|
||||
# via
|
||||
# readthedocs-cli
|
||||
# requests
|
||||
zipp==3.23.0
|
||||
# via importlib-metadata
|
||||
|
||||
@ -8,6 +8,7 @@ EXTRACT_STATIC = YES
|
||||
CASE_SENSE_NAMES = NO
|
||||
INPUT = ../include input ../tf-psa-crypto/include ../tests/include/alt-dummy
|
||||
FILE_PATTERNS = *.h
|
||||
EXCLUDE = ../tf-psa-crypto/include/mbedtls/private
|
||||
RECURSIVE = YES
|
||||
EXCLUDE_SYMLINKS = YES
|
||||
SOURCE_BROWSER = YES
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit df3307f2b4fe512def60886024f7be8fd1523ccd
|
||||
Subproject commit d0d817541ae3f449b8cd51afc165668179659699
|
||||
@ -7,6 +7,12 @@ if(INSTALL_MBEDTLS_HEADERS)
|
||||
install(FILES ${headers}
|
||||
DESTINATION include/mbedtls
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
|
||||
|
||||
file(GLOB private_headers "mbedtls/private/*.h")
|
||||
|
||||
install(FILES ${private_headers}
|
||||
DESTINATION include/mbedtls/private
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
|
||||
endif(INSTALL_MBEDTLS_HEADERS)
|
||||
|
||||
# Make mbedtls_config.h available in an out-of-source build. ssl-opt.sh requires it.
|
||||
|
||||
@ -74,9 +74,9 @@
|
||||
*/
|
||||
#define MBEDTLS_CONFIG_FILES_READ
|
||||
|
||||
#include "mbedtls/config_adjust_x509.h"
|
||||
#include "mbedtls/private/config_adjust_x509.h"
|
||||
|
||||
#include "mbedtls/config_adjust_ssl.h"
|
||||
#include "mbedtls/private/config_adjust_ssl.h"
|
||||
|
||||
/* Indicate that all configuration symbols are set,
|
||||
* even the ones that are calculated programmatically.
|
||||
@ -85,6 +85,4 @@
|
||||
*/
|
||||
#define MBEDTLS_CONFIG_IS_FINALIZED
|
||||
|
||||
#include "mbedtls/check_config.h"
|
||||
|
||||
#endif /* MBEDTLS_BUILD_INFO_H */
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
#include "mbedtls/ssl.h"
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/private/ecp.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#define MBEDTLS_ERROR_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "mbedtls/error_common.h"
|
||||
#include "mbedtls/private/error_common.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@ -273,54 +273,6 @@
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
|
||||
*
|
||||
* Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS.
|
||||
*
|
||||
* Requires: MBEDTLS_ECDH_C or PSA_WANT_ALG_ECDH
|
||||
* MBEDTLS_ECDSA_C or PSA_WANT_ALG_ECDSA
|
||||
* MBEDTLS_X509_CRT_PARSE_C
|
||||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
||||
*
|
||||
* Enable the ECDH-RSA based ciphersuite modes in SSL / TLS.
|
||||
*
|
||||
* Requires: MBEDTLS_ECDH_C or PSA_WANT_ALG_ECDH
|
||||
* MBEDTLS_RSA_C
|
||||
* MBEDTLS_X509_CRT_PARSE_C
|
||||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
|
||||
*
|
||||
@ -533,28 +485,6 @@
|
||||
*/
|
||||
#define MBEDTLS_SSL_DTLS_CONNECTION_ID
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
|
||||
*
|
||||
* Defines whether RFC 9146 (default) or the legacy version
|
||||
* (version draft-ietf-tls-dtls-connection-id-05,
|
||||
* https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05)
|
||||
* is used.
|
||||
*
|
||||
* Set the value to 0 for the standard version, and
|
||||
* 1 for the legacy draft version.
|
||||
*
|
||||
* \deprecated Support for the legacy version of the DTLS
|
||||
* Connection ID feature is deprecated. Please
|
||||
* switch to the standardized version defined
|
||||
* in RFC 9146 enabled by utilizing
|
||||
* MBEDTLS_SSL_DTLS_CONNECTION_ID without use
|
||||
* of MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT.
|
||||
*
|
||||
* Requires: MBEDTLS_SSL_DTLS_CONNECTION_ID
|
||||
*/
|
||||
#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_DTLS_HELLO_VERIFY
|
||||
*
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
/** Failed to get an IP address for the given hostname. */
|
||||
#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
|
||||
/** Buffer is too small to hold the data. */
|
||||
#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
|
||||
#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL
|
||||
/** The context is invalid, eg because it was free()ed. */
|
||||
#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
|
||||
/** Polling the net context failed. */
|
||||
@ -147,11 +147,11 @@ int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *
|
||||
* can be NULL if client_ip is null
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_NET_SOCKET_FAILED,
|
||||
* MBEDTLS_ERR_NET_BIND_FAILED,
|
||||
* MBEDTLS_ERR_NET_ACCEPT_FAILED, or
|
||||
* MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,
|
||||
* MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
|
||||
* #MBEDTLS_ERR_NET_SOCKET_FAILED,
|
||||
* #MBEDTLS_ERR_NET_BIND_FAILED,
|
||||
* #MBEDTLS_ERR_NET_ACCEPT_FAILED, or
|
||||
* #PSA_ERROR_BUFFER_TOO_SMALL if buf_size is too small,
|
||||
* #MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
|
||||
* non-blocking and accept() would block.
|
||||
*/
|
||||
int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#define MBEDTLS_OID_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "mbedtls/asn1.h"
|
||||
|
||||
/*
|
||||
* Top level OID tuples
|
||||
|
||||
@ -55,9 +55,9 @@
|
||||
#define MBEDTLS_ERR_PKCS7_INVALID_CERT -0x5580 /**< The certificate tag or value is invalid or cannot be parsed. */
|
||||
#define MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE -0x5600 /**< Error parsing the signature */
|
||||
#define MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO -0x5680 /**< Error parsing the signer's info */
|
||||
#define MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA -0x5700 /**< Input invalid. */
|
||||
#define MBEDTLS_ERR_PKCS7_ALLOC_FAILED -0x5780 /**< Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_PKCS7_VERIFY_FAIL -0x5800 /**< Verification Failed */
|
||||
#define MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA PSA_ERROR_INVALID_ARGUMENT /**< Input invalid. */
|
||||
#define MBEDTLS_ERR_PKCS7_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY /**< Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_PKCS7_VERIFY_FAIL PSA_ERROR_INVALID_SIGNATURE /**< Verification Failed */
|
||||
#define MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID -0x5880 /**< The PKCS #7 date issued/expired dates are invalid */
|
||||
/* \} name */
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* \file mbedtls/config_adjust_ssl.h
|
||||
* \file mbedtls/private/config_adjust_ssl.h
|
||||
* \brief Adjust TLS configuration
|
||||
*
|
||||
* This is an internal header. Do not include it directly.
|
||||
@ -51,7 +51,6 @@
|
||||
#if !defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
#undef MBEDTLS_SSL_DTLS_ANTI_REPLAY
|
||||
#undef MBEDTLS_SSL_DTLS_CONNECTION_ID
|
||||
#undef MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
|
||||
#undef MBEDTLS_SSL_DTLS_HELLO_VERIFY
|
||||
#undef MBEDTLS_SSL_DTLS_SRTP
|
||||
#undef MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
|
||||
@ -65,8 +64,6 @@
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
|
||||
#endif
|
||||
|
||||
@ -79,7 +76,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
||||
(defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
||||
(defined(PSA_WANT_ALG_ECDH) || defined(PSA_WANT_ALG_ECDSA) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED))
|
||||
#define MBEDTLS_SSL_TLS1_2_SOME_ECC
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* \file mbedtls/config_adjust_x509.h
|
||||
* \file mbedtls/private/config_adjust_x509.h
|
||||
* \brief Adjust X.509 configuration
|
||||
*
|
||||
* This is an internal header. Do not include it directly.
|
||||
@ -14,8 +14,8 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/private/bignum.h"
|
||||
#include "mbedtls/private/ecp.h"
|
||||
|
||||
#include "mbedtls/ssl_ciphersuites.h"
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED)
|
||||
#include "mbedtls/ecdh.h"
|
||||
#include "mbedtls/private/ecdh.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
@ -44,7 +44,7 @@
|
||||
/** The requested feature is not available. */
|
||||
#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
|
||||
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA PSA_ERROR_INVALID_ARGUMENT
|
||||
/** Verification of the message MAC failed. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
|
||||
/** An invalid SSL record was received. */
|
||||
@ -105,7 +105,7 @@
|
||||
/** Cache entry not found */
|
||||
#define MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND -0x7E80
|
||||
/** Memory allocation failed */
|
||||
#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
|
||||
#define MBEDTLS_ERR_SSL_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
/** Hardware acceleration function returned with error */
|
||||
#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
|
||||
/** Hardware acceleration function skipped / left alone data */
|
||||
@ -129,7 +129,7 @@
|
||||
/** DTLS client must retry for hello verification */
|
||||
#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
|
||||
/** A buffer is too small to receive or write a message */
|
||||
#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
|
||||
#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL
|
||||
/* Error space gap */
|
||||
/** No data of requested type currently available on underlying transport. */
|
||||
#define MBEDTLS_ERR_SSL_WANT_READ -0x6900
|
||||
@ -229,10 +229,6 @@
|
||||
|
||||
/* Elliptic Curve Groups (ECDHE) */
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_NONE 0
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 0x0012
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 0x0013
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 0x0014
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 0x0015
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 0x0016
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 0x0017
|
||||
#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 0x0018
|
||||
@ -284,15 +280,6 @@
|
||||
* Various constants
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/* These are the high and low bytes of ProtocolVersion as defined by:
|
||||
* - RFC 5246: ProtocolVersion version = { 3, 3 }; // TLS v1.2
|
||||
* - RFC 8446: see section 4.2.1
|
||||
*/
|
||||
#define MBEDTLS_SSL_MAJOR_VERSION_3 3
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_4 4 /*!< TLS v1.3 */
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
|
||||
#define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
|
||||
@ -470,14 +457,6 @@
|
||||
|
||||
/** \} name SECTION: Module settings */
|
||||
|
||||
/*
|
||||
* Default to standard CID mode
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
|
||||
!defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT)
|
||||
#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Length of the verify data for secure renegotiation
|
||||
*/
|
||||
@ -649,11 +628,7 @@
|
||||
#define MBEDTLS_TLS_EXT_SIG_ALG_CERT 50 /* RFC 8446 TLS 1.3 */
|
||||
#define MBEDTLS_TLS_EXT_KEY_SHARE 51 /* RFC 8446 TLS 1.3 */
|
||||
|
||||
#if MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0
|
||||
#define MBEDTLS_TLS_EXT_CID 54 /* RFC 9146 DTLS 1.2 CID */
|
||||
#else
|
||||
#define MBEDTLS_TLS_EXT_CID 254 /* Pre-RFC 9146 DTLS 1.2 CID */
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
|
||||
|
||||
@ -684,9 +659,7 @@
|
||||
union mbedtls_ssl_premaster_secret {
|
||||
unsigned char dummy; /* Make the union non-empty even with SSL disabled */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
||||
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
|
||||
#endif
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
@ -891,7 +864,6 @@ typedef struct mbedtls_ssl_config mbedtls_ssl_config;
|
||||
/* Defined in library/ssl_misc.h */
|
||||
typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
|
||||
typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
|
||||
typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
|
||||
#endif
|
||||
@ -1506,10 +1478,6 @@ struct mbedtls_ssl_config {
|
||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
const int *MBEDTLS_PRIVATE(sig_hashes); /*!< allowed signature hashes */
|
||||
#endif
|
||||
const uint16_t *MBEDTLS_PRIVATE(sig_algs); /*!< allowed signature algorithms */
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
|
||||
@ -1942,7 +1910,7 @@ void mbedtls_ssl_init(mbedtls_ssl_context *ssl);
|
||||
* \param ssl SSL context
|
||||
* \param conf SSL configuration to use
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY if
|
||||
* memory allocation failed
|
||||
*/
|
||||
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl,
|
||||
@ -1954,7 +1922,7 @@ int mbedtls_ssl_setup(mbedtls_ssl_context *ssl,
|
||||
* pointers and data.
|
||||
*
|
||||
* \param ssl SSL context
|
||||
* \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED or
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY or
|
||||
MBEDTLS_ERR_SSL_HW_ACCEL_FAILED
|
||||
*/
|
||||
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl);
|
||||
@ -2609,14 +2577,14 @@ void mbedtls_ssl_conf_session_tickets_cb(mbedtls_ssl_config *conf,
|
||||
* milliseconds.
|
||||
*
|
||||
* \return 0 on success,
|
||||
* MBEDTLS_ERR_SSL_BAD_INPUT_DATA if an input is not valid.
|
||||
* #PSA_ERROR_INVALID_ARGUMENT if an input is not valid.
|
||||
*/
|
||||
static inline int mbedtls_ssl_session_get_ticket_creation_time(
|
||||
mbedtls_ssl_session *session, mbedtls_ms_time_t *ticket_creation_time)
|
||||
{
|
||||
if (session == NULL || ticket_creation_time == NULL ||
|
||||
session->MBEDTLS_PRIVATE(endpoint) != MBEDTLS_SSL_IS_SERVER) {
|
||||
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
*ticket_creation_time = session->MBEDTLS_PRIVATE(ticket_creation_time);
|
||||
@ -2967,8 +2935,8 @@ void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf,
|
||||
* \note An internal copy is made, so the info buffer can be reused.
|
||||
*
|
||||
* \return 0 on success,
|
||||
* MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
|
||||
* MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
|
||||
* #PSA_ERROR_INVALID_ARGUMENT if used on client,
|
||||
* #PSA_ERROR_INSUFFICIENT_MEMORY if out of memory.
|
||||
*/
|
||||
int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl,
|
||||
const unsigned char *info,
|
||||
@ -3205,8 +3173,8 @@ int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session
|
||||
* \param len The size of the serialized data in bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
|
||||
* \return #PSA_ERROR_INSUFFICIENT_MEMORY if memory allocation failed.
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if input data is invalid.
|
||||
* \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
|
||||
* was generated in a different version or configuration of
|
||||
* Mbed TLS.
|
||||
@ -3245,7 +3213,7 @@ int mbedtls_ssl_session_load(mbedtls_ssl_session *session,
|
||||
* tickets.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
|
||||
* \return #PSA_ERROR_BUFFER_TOO_SMALL if \p buf is too small.
|
||||
* \return #MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if the
|
||||
* MBEDTLS_SSL_SESSION_TICKETS configuration option is disabled
|
||||
* and the session is a TLS 1.3 session.
|
||||
@ -3378,7 +3346,7 @@ void mbedtls_ssl_conf_tls13_key_exchange_modes(mbedtls_ssl_config *conf,
|
||||
* record headers.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p len
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if \p len
|
||||
* is too large.
|
||||
*/
|
||||
int mbedtls_ssl_conf_cid(mbedtls_ssl_config *conf, size_t len,
|
||||
@ -3391,7 +3359,7 @@ int mbedtls_ssl_conf_cid(mbedtls_ssl_config *conf, size_t len,
|
||||
*
|
||||
* \note The restrictions are enforced for all certificates in the
|
||||
* chain. However, signatures in the handshake are not covered
|
||||
* by this setting but by \b mbedtls_ssl_conf_sig_hashes().
|
||||
* by this setting but by \b mbedtls_ssl_conf_sig_algs().
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param profile Profile to use
|
||||
@ -3525,7 +3493,7 @@ void mbedtls_ssl_conf_ca_cb(mbedtls_ssl_config *conf,
|
||||
* \param own_cert own public certificate chain
|
||||
* \param pk_key own private key
|
||||
*
|
||||
* \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
|
||||
* \return 0 on success or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *conf,
|
||||
mbedtls_x509_crt *own_cert,
|
||||
@ -3733,41 +3701,6 @@ void mbedtls_ssl_conf_groups(mbedtls_ssl_config *conf,
|
||||
const uint16_t *groups);
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED) && defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
/**
|
||||
* \brief Set the allowed hashes for signatures during the handshake.
|
||||
*
|
||||
* \note This only affects which hashes are offered and can be used
|
||||
* for signatures during the handshake. Hashes for message
|
||||
* authentication and the TLS PRF are controlled by the
|
||||
* ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
|
||||
* used for certificate signature are controlled by the
|
||||
* verification profile, see \c mbedtls_ssl_conf_cert_profile().
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_ssl_conf_sig_algs().
|
||||
*
|
||||
* \note This list should be ordered by decreasing preference
|
||||
* (preferred hash first).
|
||||
*
|
||||
* \note By default, all supported hashes whose length is at least
|
||||
* 256 bits are allowed. This is the same set as the default
|
||||
* for certificate verification
|
||||
* (#mbedtls_x509_crt_profile_default).
|
||||
* The preference order is currently unspecified and may
|
||||
* change in future versions.
|
||||
*
|
||||
* \note New minor versions of Mbed TLS may extend this list,
|
||||
* for example if new curves are added to the library.
|
||||
* New minor versions of Mbed TLS will not remove items
|
||||
* from this list unless serious security concerns require it.
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param hashes Ordered list of allowed signature hashes,
|
||||
* terminated by \c MBEDTLS_MD_NONE.
|
||||
*/
|
||||
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_sig_hashes(mbedtls_ssl_config *conf,
|
||||
const int *hashes);
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED && MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
|
||||
/**
|
||||
* \brief Configure allowed signature algorithms for use in TLS
|
||||
@ -3809,8 +3742,8 @@ void mbedtls_ssl_conf_sig_algs(mbedtls_ssl_config *conf,
|
||||
* #MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME
|
||||
* for more details.
|
||||
*
|
||||
* \return 0 if successful, #MBEDTLS_ERR_SSL_ALLOC_FAILED on
|
||||
* allocation failure, #MBEDTLS_ERR_SSL_BAD_INPUT_DATA on
|
||||
* \return 0 if successful, #PSA_ERROR_INSUFFICIENT_MEMORY on
|
||||
* allocation failure, #PSA_ERROR_INVALID_ARGUMENT on
|
||||
* too long input hostname.
|
||||
*
|
||||
* Hostname set to the one provided on success (cleared
|
||||
@ -3870,7 +3803,7 @@ const unsigned char *mbedtls_ssl_get_hs_sni(mbedtls_ssl_context *ssl,
|
||||
* \param own_cert own public certificate chain
|
||||
* \param pk_key own private key
|
||||
*
|
||||
* \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
|
||||
* \return 0 on success or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_ssl_set_hs_own_cert(mbedtls_ssl_context *ssl,
|
||||
mbedtls_x509_crt *own_cert,
|
||||
@ -3999,7 +3932,7 @@ int mbedtls_ssl_set_hs_ecjpake_password_opaque(mbedtls_ssl_context *ssl,
|
||||
* the lifetime of the table must be at least as long as the
|
||||
* lifetime of the SSL configuration structure.
|
||||
*
|
||||
* \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
|
||||
* \return 0 on success, or #PSA_ERROR_INVALID_ARGUMENT.
|
||||
*/
|
||||
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf,
|
||||
const char *const *protos);
|
||||
@ -4066,7 +3999,7 @@ void mbedtls_ssl_conf_srtp_mki_value_supported(mbedtls_ssl_config *conf,
|
||||
* (excluding the terminating MBEDTLS_TLS_SRTP_UNSET).
|
||||
*
|
||||
* \return 0 on success
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA when the list of
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT when the list of
|
||||
* protection profiles is incorrect.
|
||||
*/
|
||||
int mbedtls_ssl_conf_dtls_srtp_protection_profiles
|
||||
@ -4086,7 +4019,7 @@ int mbedtls_ssl_conf_dtls_srtp_protection_profiles
|
||||
* is ignored.
|
||||
*
|
||||
* \return 0 on success
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \return #MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
|
||||
*/
|
||||
int mbedtls_ssl_dtls_srtp_set_mki_value(mbedtls_ssl_context *ssl,
|
||||
@ -4114,28 +4047,6 @@ void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl
|
||||
mbedtls_dtls_srtp_info *dtls_srtp_info);
|
||||
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/**
|
||||
* \brief Set the maximum supported version sent from the client side
|
||||
* and/or accepted at the server side.
|
||||
*
|
||||
* See also the documentation of mbedtls_ssl_conf_min_version().
|
||||
*
|
||||
* \note This ignores ciphersuites from higher versions.
|
||||
*
|
||||
* \note This function is deprecated and has been replaced by
|
||||
* \c mbedtls_ssl_conf_max_tls_version().
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param major Major version number (#MBEDTLS_SSL_MAJOR_VERSION_3)
|
||||
* \param minor Minor version number
|
||||
* (#MBEDTLS_SSL_MINOR_VERSION_3 for (D)TLS 1.2,
|
||||
* #MBEDTLS_SSL_MINOR_VERSION_4 for TLS 1.3)
|
||||
*/
|
||||
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major,
|
||||
int minor);
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief Set the maximum supported version sent from the client side
|
||||
* and/or accepted at the server side.
|
||||
@ -4154,45 +4065,6 @@ static inline void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config *conf,
|
||||
conf->MBEDTLS_PRIVATE(max_tls_version) = tls_version;
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/**
|
||||
* \brief Set the minimum accepted SSL/TLS protocol version
|
||||
*
|
||||
* \note By default, all supported versions are accepted.
|
||||
* Future versions of the library may disable older
|
||||
* protocol versions by default if they become deprecated.
|
||||
*
|
||||
* \note The following versions are supported (if enabled at
|
||||
* compile time):
|
||||
* - (D)TLS 1.2: \p major = #MBEDTLS_SSL_MAJOR_VERSION_3,
|
||||
* \p minor = #MBEDTLS_SSL_MINOR_VERSION_3
|
||||
* - TLS 1.3: \p major = #MBEDTLS_SSL_MAJOR_VERSION_3,
|
||||
* \p minor = #MBEDTLS_SSL_MINOR_VERSION_4
|
||||
*
|
||||
* Note that the numbers in the constant names are the
|
||||
* TLS internal protocol numbers, and the minor versions
|
||||
* differ by one from the human-readable versions!
|
||||
*
|
||||
* \note Input outside of the SSL_MAX_XXXXX_VERSION and
|
||||
* SSL_MIN_XXXXX_VERSION range is ignored.
|
||||
*
|
||||
* \note After the handshake, you can call
|
||||
* mbedtls_ssl_get_version_number() to see what version was
|
||||
* negotiated.
|
||||
*
|
||||
* \note This function is deprecated and has been replaced by
|
||||
* \c mbedtls_ssl_conf_min_tls_version().
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param major Major version number (#MBEDTLS_SSL_MAJOR_VERSION_3)
|
||||
* \param minor Minor version number
|
||||
* (#MBEDTLS_SSL_MINOR_VERSION_3 for (D)TLS 1.2,
|
||||
* #MBEDTLS_SSL_MINOR_VERSION_4 for TLS 1.3)
|
||||
*/
|
||||
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major,
|
||||
int minor);
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief Set the minimum supported version sent from the client side
|
||||
* and/or accepted at the server side.
|
||||
@ -4292,7 +4164,7 @@ void mbedtls_ssl_conf_cert_req_ca_list(mbedtls_ssl_config *conf,
|
||||
* MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
|
||||
* MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
|
||||
*
|
||||
* \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
|
||||
* \return 0 if successful or #PSA_ERROR_INVALID_ARGUMENT
|
||||
*/
|
||||
int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code);
|
||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||
@ -5018,7 +4890,7 @@ int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len);
|
||||
* fragment length (either the built-in limit or the one set
|
||||
* or negotiated with the peer), then:
|
||||
* - with TLS, less bytes than requested are written.
|
||||
* - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
|
||||
* - with DTLS, #PSA_ERROR_INVALID_ARGUMENT is returned.
|
||||
* \c mbedtls_ssl_get_max_out_record_payload() may be used to
|
||||
* query the active maximum fragment length.
|
||||
*
|
||||
@ -5102,7 +4974,7 @@ int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl);
|
||||
* \param len maximum number of bytes to read
|
||||
*
|
||||
* \return The (positive) number of bytes read if successful.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if input data is invalid.
|
||||
* \return #MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA if it is not
|
||||
* possible to read early data for the SSL context \p ssl. Note
|
||||
* that this function is intended to be called for an SSL
|
||||
@ -5208,10 +5080,10 @@ int mbedtls_ssl_write_early_data(mbedtls_ssl_context *ssl,
|
||||
*
|
||||
* \param ssl The SSL context to query
|
||||
*
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if this function is called
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if this function is called
|
||||
* from the server-side.
|
||||
*
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if this function is called
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if this function is called
|
||||
* prior to completion of the handshake.
|
||||
*
|
||||
* \return #MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_INDICATED if the client
|
||||
@ -5260,7 +5132,7 @@ void mbedtls_ssl_free(mbedtls_ssl_context *ssl);
|
||||
*
|
||||
* \note This feature is currently only available under certain
|
||||
* conditions, see the documentation of the return value
|
||||
* #MBEDTLS_ERR_SSL_BAD_INPUT_DATA for details.
|
||||
* #PSA_ERROR_INVALID_ARGUMENT for details.
|
||||
*
|
||||
* \note When this function succeeds, it calls
|
||||
* mbedtls_ssl_session_reset() on \p ssl which as a result is
|
||||
@ -5285,15 +5157,15 @@ void mbedtls_ssl_free(mbedtls_ssl_context *ssl);
|
||||
* to determine the necessary size by calling this function
|
||||
* with \p buf set to \c NULL and \p buf_len to \c 0. However,
|
||||
* the value of \p olen is only guaranteed to be correct when
|
||||
* the function returns #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL or
|
||||
* the function returns #PSA_ERROR_BUFFER_TOO_SMALL or
|
||||
* \c 0. If the return value is different, then the value of
|
||||
* \p olen is undefined.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
|
||||
* \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed
|
||||
* \return #PSA_ERROR_BUFFER_TOO_SMALL if \p buf is too small.
|
||||
* \return #PSA_ERROR_INSUFFICIENT_MEMORY if memory allocation failed
|
||||
* while resetting the context.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if a handshake is in
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if a handshake is in
|
||||
* progress, or there is pending data for reading or sending,
|
||||
* or the connection does not use DTLS 1.2 with an AEAD
|
||||
* ciphersuite, or renegotiation is enabled.
|
||||
@ -5366,10 +5238,10 @@ int mbedtls_ssl_context_save(mbedtls_ssl_context *ssl,
|
||||
* \param len The size of the serialized data in bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
|
||||
* \return #PSA_ERROR_INSUFFICIENT_MEMORY if memory allocation failed.
|
||||
* \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
|
||||
* comes from a different Mbed TLS version or build.
|
||||
* \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if input data is invalid.
|
||||
*/
|
||||
int mbedtls_ssl_context_load(mbedtls_ssl_context *ssl,
|
||||
const unsigned char *buf,
|
||||
@ -5478,7 +5350,7 @@ int mbedtls_ssl_tls_prf(const mbedtls_tls_prf_types prf,
|
||||
* context_len are ignored and a 0-length context is used.
|
||||
*
|
||||
* \return 0 on success.
|
||||
* \return MBEDTLS_ERR_SSL_BAD_INPUT_DATA if the handshake is not yet completed.
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT if the handshake is not yet completed.
|
||||
* \return An SSL-specific error on failure.
|
||||
*/
|
||||
int mbedtls_ssl_export_keying_material(mbedtls_ssl_context *ssl,
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/private/cipher.h"
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -37,39 +37,23 @@ extern "C" {
|
||||
#define MBEDTLS_TLS_PSK_WITH_NULL_SHA256 0xB0 /**< Weak! */
|
||||
#define MBEDTLS_TLS_PSK_WITH_NULL_SHA384 0xB1 /**< Weak! */
|
||||
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A
|
||||
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036
|
||||
@ -81,20 +65,12 @@ extern "C" {
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 0xC048 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 0xC049 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 0xC04A /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 0xC04B /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 0xC04C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 0xC04D /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 0xC04E /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 0xC04F /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 0xC05C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 0xC05D /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 0xC05E /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 0xC05F /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 0xC060 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 0xC061 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 0xC062 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 0xC063 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256 0xC064 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384 0xC065 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256 0xC06A /**< TLS 1.2 */
|
||||
@ -104,21 +80,13 @@ extern "C" {
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC086 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC087 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC088 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC089 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08A /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08B /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08D /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC08E /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC08F /**< TLS 1.2 */
|
||||
@ -163,16 +131,12 @@ typedef enum {
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA,
|
||||
MBEDTLS_KEY_EXCHANGE_PSK,
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_PSK,
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
MBEDTLS_KEY_EXCHANGE_ECJPAKE,
|
||||
} mbedtls_key_exchange_type_t;
|
||||
|
||||
/* Key exchanges using a certificate */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
||||
#define MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED
|
||||
#endif
|
||||
|
||||
@ -220,18 +184,6 @@ typedef enum {
|
||||
#define MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED
|
||||
#endif
|
||||
|
||||
/* Key exchanges using ECDH */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
#define MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED
|
||||
#endif
|
||||
|
||||
/* Key exchanges that don't involve ephemeral keys */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED)
|
||||
#define MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED
|
||||
#endif
|
||||
|
||||
/* Key exchanges that involve ephemeral keys */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
|
||||
@ -254,8 +206,7 @@ typedef enum {
|
||||
#endif
|
||||
|
||||
/* TLS 1.2 key exchanges using ECDH or ECDHE*/
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED)
|
||||
#define MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_1_2_ENABLED
|
||||
#endif
|
||||
|
||||
|
||||
@ -32,23 +32,14 @@ extern "C" {
|
||||
unsigned int mbedtls_version_get_number(void);
|
||||
|
||||
/**
|
||||
* Get the version string ("x.y.z").
|
||||
*
|
||||
* \param string The string that will receive the value.
|
||||
* (Should be at least 9 bytes in size)
|
||||
* Get a pointer to the version string ("x.y.z").
|
||||
*/
|
||||
void mbedtls_version_get_string(char *string);
|
||||
const char *mbedtls_version_get_string(void);
|
||||
|
||||
/**
|
||||
* Get the full version string ("Mbed TLS x.y.z").
|
||||
*
|
||||
* \param string The string that will receive the value. The Mbed TLS version
|
||||
* string will use 18 bytes AT MOST including a terminating
|
||||
* null byte.
|
||||
* (So the buffer should be at least 18 bytes to receive this
|
||||
* version string).
|
||||
* Get a pointer to the full version string ("Mbed TLS x.y.z").
|
||||
*/
|
||||
void mbedtls_version_get_string_full(char *string);
|
||||
const char *mbedtls_version_get_string_full(void);
|
||||
|
||||
/**
|
||||
* \brief Check if support for a feature was compiled into this
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#include "mbedtls/pk.h"
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/private/rsa.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -74,11 +74,11 @@
|
||||
/** Input invalid. */
|
||||
#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800
|
||||
/** Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880
|
||||
#define MBEDTLS_ERR_X509_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
/** Read/write of file failed. */
|
||||
#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900
|
||||
/** Destination buffer is too small. */
|
||||
#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980
|
||||
#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL
|
||||
/** A fatal error occurred, eg the chain is too long or the vrfy callback failed. */
|
||||
#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000
|
||||
/** \} name X509 Error codes */
|
||||
|
||||
@ -82,7 +82,7 @@ typedef struct mbedtls_x509_crl {
|
||||
mbedtls_x509_buf MBEDTLS_PRIVATE(sig_oid2);
|
||||
mbedtls_x509_buf MBEDTLS_PRIVATE(sig);
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
|
||||
mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
mbedtls_pk_sigalg_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
|
||||
/** Next element in the linked list of CRL.
|
||||
* \p NULL indicates the end of the list.
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/x509_crl.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/private/bignum.h"
|
||||
|
||||
/**
|
||||
* \addtogroup x509_module
|
||||
@ -81,7 +81,7 @@ typedef struct mbedtls_x509_crt {
|
||||
|
||||
mbedtls_x509_buf MBEDTLS_PRIVATE(sig); /**< Signature: hash of the tbs part signed with the private key. */
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
|
||||
mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
mbedtls_pk_sigalg_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
|
||||
/** Next certificate in the linked list that constitutes the CA chain.
|
||||
* \p NULL indicates the end of the list.
|
||||
@ -234,7 +234,7 @@ mbedtls_x509write_cert;
|
||||
* \param ctx Certificate context to use
|
||||
* \param san_list List of SAN values
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*
|
||||
* \note "dnsName", "uniformResourceIdentifier", "IP address",
|
||||
* "otherName", and "DirectoryName", as defined in RFC 5280,
|
||||
@ -610,7 +610,7 @@ int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
|
||||
* other than fatal error, as a non-zero return code
|
||||
* immediately aborts the verification process. For fatal
|
||||
* errors, a specific error code should be used (different
|
||||
* from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
|
||||
* from #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
|
||||
* be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR
|
||||
* can be used if no better code is available.
|
||||
*
|
||||
@ -826,7 +826,7 @@ int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt,
|
||||
* that bit MAY be set.
|
||||
*
|
||||
* \return 0 is these uses of the certificate are allowed,
|
||||
* MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
|
||||
* #MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
|
||||
* is present but does not match the usage argument.
|
||||
*
|
||||
* \note You should only call this function on leaf certificates, on
|
||||
@ -845,7 +845,7 @@ int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt,
|
||||
* \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
|
||||
*
|
||||
* \return 0 if this use of the certificate is allowed,
|
||||
* MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
|
||||
* #MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
|
||||
*
|
||||
* \note Usually only makes sense on leaf certificates.
|
||||
*/
|
||||
@ -952,11 +952,11 @@ void mbedtls_x509write_crt_set_version(mbedtls_x509write_cert *ctx, int version)
|
||||
* input buffer
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_X509_BAD_INPUT_DATA if the provided input buffer
|
||||
* #MBEDTLS_ERR_X509_BAD_INPUT_DATA if the provided input buffer
|
||||
* is too big (longer than MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN)
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx,
|
||||
unsigned char *serial, size_t serial_len);
|
||||
const unsigned char *serial, size_t serial_len);
|
||||
|
||||
/**
|
||||
* \brief Set the validity period for a Certificate
|
||||
@ -1041,7 +1041,7 @@ void mbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert *ctx, mbedtls_md_ty
|
||||
* \param val value of the extension OCTET STRING
|
||||
* \param val_len length of the value data
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx,
|
||||
const char *oid, size_t oid_len,
|
||||
@ -1057,7 +1057,7 @@ int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx,
|
||||
* certificate (only for CA certificates, -1 is
|
||||
* unlimited)
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx,
|
||||
int is_ca, int max_pathlen);
|
||||
@ -1070,7 +1070,7 @@ int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx,
|
||||
*
|
||||
* \param ctx CRT context to use
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx);
|
||||
|
||||
@ -1081,7 +1081,7 @@ int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx
|
||||
*
|
||||
* \param ctx CRT context to use
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *ctx);
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
@ -1093,7 +1093,7 @@ int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *c
|
||||
* \param ctx CRT context to use
|
||||
* \param key_usage key usage flags to set
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx,
|
||||
unsigned int key_usage);
|
||||
@ -1106,7 +1106,7 @@ int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx,
|
||||
* \param exts extended key usage extensions to set, a sequence of
|
||||
* MBEDTLS_ASN1_OID objects
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx,
|
||||
const mbedtls_asn1_sequence *exts);
|
||||
@ -1118,7 +1118,7 @@ int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx,
|
||||
* \param ctx CRT context to use
|
||||
* \param ns_cert_type Netscape Cert Type flags to set
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert *ctx,
|
||||
unsigned char ns_cert_type);
|
||||
|
||||
@ -55,7 +55,7 @@ typedef struct mbedtls_x509_csr {
|
||||
mbedtls_x509_buf sig_oid;
|
||||
mbedtls_x509_buf MBEDTLS_PRIVATE(sig);
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
|
||||
mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
mbedtls_pk_sigalg_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
|
||||
}
|
||||
mbedtls_x509_csr;
|
||||
|
||||
@ -263,7 +263,7 @@ void mbedtls_x509write_csr_set_md_alg(mbedtls_x509write_csr *ctx, mbedtls_md_typ
|
||||
* \param ctx CSR context to use
|
||||
* \param key_usage key usage flags to set
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*
|
||||
* \note The <code>decipherOnly</code> flag from the Key Usage
|
||||
* extension is represented by bit 8 (i.e.
|
||||
@ -281,7 +281,7 @@ int mbedtls_x509write_csr_set_key_usage(mbedtls_x509write_csr *ctx, unsigned cha
|
||||
* \param ctx CSR context to use
|
||||
* \param san_list List of SAN values
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*
|
||||
* \note Only "dnsName", "uniformResourceIdentifier" and "otherName",
|
||||
* as defined in RFC 5280, are supported.
|
||||
@ -296,7 +296,7 @@ int mbedtls_x509write_csr_set_subject_alternative_name(mbedtls_x509write_csr *ct
|
||||
* \param ctx CSR context to use
|
||||
* \param ns_cert_type Netscape Cert Type flags to set
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx,
|
||||
unsigned char ns_cert_type);
|
||||
@ -312,7 +312,7 @@ int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx,
|
||||
* \param val value of the extension OCTET STRING
|
||||
* \param val_len length of the value data
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
|
||||
* \return 0 if successful, or a #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
*/
|
||||
int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr *ctx,
|
||||
const char *oid, size_t oid_len,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
set(src_x509
|
||||
error.c
|
||||
mbedtls_config.c
|
||||
pkcs7.c
|
||||
x509.c
|
||||
x509_create.c
|
||||
@ -84,10 +85,17 @@ if(GEN_FILES)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../framework/scripts/generate_ssl_debug_helpers.py
|
||||
${tls_error_headers}
|
||||
)
|
||||
else()
|
||||
link_to_source(error.c)
|
||||
link_to_source(version_features.c)
|
||||
link_to_source(ssl_debug_helpers_generated.c)
|
||||
|
||||
add_custom_target(${MBEDTLS_TARGET_PREFIX}mbedx509_generated_files_target
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/error.c
|
||||
)
|
||||
|
||||
add_custom_target(${MBEDTLS_TARGET_PREFIX}mbedtls_generated_files_target
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/ssl_debug_helpers_generated.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version_features.c
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
@ -165,6 +173,13 @@ if(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
target_compile_options(${mbedtls_static_target} PRIVATE ${LIBS_C_FLAGS})
|
||||
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
|
||||
target_link_libraries(${mbedtls_static_target} PUBLIC ${libs} ${mbedx509_static_target})
|
||||
|
||||
if(GEN_FILES)
|
||||
add_dependencies(${mbedx509_static_target}
|
||||
${MBEDTLS_TARGET_PREFIX}mbedx509_generated_files_target)
|
||||
add_dependencies(${mbedtls_static_target}
|
||||
${MBEDTLS_TARGET_PREFIX}mbedtls_generated_files_target)
|
||||
endif()
|
||||
endif(USE_STATIC_MBEDTLS_LIBRARY)
|
||||
|
||||
if(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
@ -179,6 +194,13 @@ if(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
target_compile_options(${mbedtls_target} PRIVATE ${LIBS_C_FLAGS})
|
||||
set_target_properties(${mbedtls_target} PROPERTIES VERSION 4.0.0 SOVERSION 21)
|
||||
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
|
||||
|
||||
if(GEN_FILES)
|
||||
add_dependencies(${mbedx509_target}
|
||||
${MBEDTLS_TARGET_PREFIX}mbedx509_generated_files_target)
|
||||
add_dependencies(${mbedtls_target}
|
||||
${MBEDTLS_TARGET_PREFIX}mbedtls_generated_files_target)
|
||||
endif()
|
||||
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
||||
|
||||
foreach(target IN LISTS target_libraries)
|
||||
|
||||
@ -121,6 +121,7 @@ LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
|
||||
OBJS_CRYPTO+=$(THIRDPARTY_CRYPTO_OBJECTS)
|
||||
|
||||
OBJS_X509= \
|
||||
mbedtls_config.o \
|
||||
x509.o \
|
||||
x509_create.o \
|
||||
x509_crl.o \
|
||||
|
||||
@ -45,7 +45,6 @@
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521)
|
||||
@ -56,19 +55,6 @@
|
||||
#endif /* not all curves accelerated */
|
||||
#endif /* some curve accelerated */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
|
||||
( !defined(MBEDTLS_CAN_ECDH) || \
|
||||
!defined(PSA_HAVE_ALG_ECDSA_SIGN) || \
|
||||
!defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||
#error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
||||
( !defined(MBEDTLS_CAN_ECDH) || !defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) || \
|
||||
!defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||
#error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
|
||||
!defined(MBEDTLS_CAN_ECDH)
|
||||
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
|
||||
@ -151,8 +137,6 @@
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
||||
!(defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) )
|
||||
@ -238,19 +222,6 @@
|
||||
#error "MBEDTLS_SSL_CID_OUT_LEN_MAX too large (max 255)"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && \
|
||||
!defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#elif defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequisites"
|
||||
13
library/mbedtls_config.c
Normal file
13
library/mbedtls_config.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Mbed TLS configuration checks
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <mbedtls/build_info.h>
|
||||
|
||||
/* Consistency checks in the configuration: check for incompatible options,
|
||||
* missing options when at least one of a set needs to be enabled, etc. */
|
||||
#include "mbedtls_check_config.h"
|
||||
@ -109,46 +109,6 @@ static const int ciphersuite_preference[] =
|
||||
/* The ECJPAKE suite */
|
||||
MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8,
|
||||
|
||||
/* All AES-256 suites */
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
|
||||
|
||||
/* All CAMELLIA-256 suites */
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384,
|
||||
|
||||
/* All ARIA-256 suites */
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384,
|
||||
|
||||
/* All AES-128 suites */
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
|
||||
|
||||
/* All CAMELLIA-128 suites */
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256,
|
||||
|
||||
/* All ARIA-128 suites */
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256,
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256,
|
||||
|
||||
/* The PSK suites */
|
||||
MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256,
|
||||
MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384,
|
||||
@ -178,8 +138,6 @@ static const int ciphersuite_preference[] =
|
||||
MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256,
|
||||
MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA,
|
||||
|
||||
MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA,
|
||||
MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA,
|
||||
MBEDTLS_TLS_PSK_WITH_NULL_SHA384,
|
||||
MBEDTLS_TLS_PSK_WITH_NULL_SHA256,
|
||||
MBEDTLS_TLS_PSK_WITH_NULL_SHA,
|
||||
@ -467,186 +425,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
|
||||
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_KEY_TYPE_AES */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256,
|
||||
"TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384,
|
||||
"TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256,
|
||||
"TLS-ECDH-RSA-WITH-CAMELLIA-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384,
|
||||
"TLS-ECDH-RSA-WITH-CAMELLIA-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_KEY_TYPE_CAMELLIA */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, "TLS-ECDH-RSA-WITH-NULL-SHA",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
MBEDTLS_CIPHERSUITE_WEAK,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_KEY_TYPE_AES */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256,
|
||||
"TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384,
|
||||
"TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256,
|
||||
"TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384,
|
||||
"TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
#endif /* PSA_WANT_KEY_TYPE_CAMELLIA */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, "TLS-ECDH-ECDSA-WITH-NULL-SHA",
|
||||
MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
MBEDTLS_CIPHERSUITE_WEAK,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
@ -898,41 +676,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
||||
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED)
|
||||
|
||||
#if (defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_ALG_SHA_384))
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384,
|
||||
"TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
defined(PSA_WANT_ALG_SHA_384))
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384,
|
||||
"TLS-ECDH-RSA-WITH-ARIA-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_ALG_SHA_256))
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256,
|
||||
"TLS-ECDH-RSA-WITH-ARIA-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
defined(PSA_WANT_ALG_SHA_256))
|
||||
{ MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256,
|
||||
"TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED)
|
||||
|
||||
#if (defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_ALG_SHA_384))
|
||||
@ -1024,41 +767,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
||||
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
|
||||
#if (defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_ALG_SHA_384))
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384,
|
||||
"TLS-ECDH-ECDSA-WITH-ARIA-256-GCM-SHA384",
|
||||
MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
defined(PSA_WANT_ALG_SHA_384))
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384,
|
||||
"TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384",
|
||||
MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_ALG_SHA_256))
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256,
|
||||
"TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256",
|
||||
MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
#if (defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
defined(PSA_WANT_ALG_SHA_256))
|
||||
{ MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256,
|
||||
"TLS-ECDH-ECDSA-WITH-ARIA-128-CBC-SHA256",
|
||||
MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
|
||||
0,
|
||||
MBEDTLS_SSL_VERSION_TLS1_2, MBEDTLS_SSL_VERSION_TLS1_2 },
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
|
||||
#endif /* PSA_WANT_KEY_TYPE_ARIA */
|
||||
|
||||
|
||||
@ -1203,10 +911,6 @@ mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg(const mbedtls_ssl_ciphe
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return MBEDTLS_PK_ECDSA;
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
return MBEDTLS_PK_ECKEY;
|
||||
|
||||
default:
|
||||
return MBEDTLS_PK_NONE;
|
||||
}
|
||||
@ -1222,10 +926,6 @@ psa_algorithm_t mbedtls_ssl_get_ciphersuite_sig_pk_psa_alg(const mbedtls_ssl_cip
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type((mbedtls_md_type_t) info->mac));
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
return PSA_ALG_ECDH;
|
||||
|
||||
default:
|
||||
return PSA_ALG_NONE;
|
||||
}
|
||||
@ -1238,10 +938,6 @@ psa_key_usage_t mbedtls_ssl_get_ciphersuite_sig_pk_psa_usage(const mbedtls_ssl_c
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return PSA_KEY_USAGE_SIGN_HASH;
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
return PSA_KEY_USAGE_DERIVE;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -1272,8 +968,6 @@ int mbedtls_ssl_ciphersuite_uses_ec(const mbedtls_ssl_ciphersuite_t *info)
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
|
||||
return 1;
|
||||
|
||||
|
||||
@ -41,12 +41,10 @@ static inline int mbedtls_ssl_ciphersuite_has_pfs(const mbedtls_ssl_ciphersuite_
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PFS_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
static inline int mbedtls_ssl_ciphersuite_no_pfs(const mbedtls_ssl_ciphersuite_t *info)
|
||||
{
|
||||
switch (info->MBEDTLS_PRIVATE(key_exchange)) {
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_PSK:
|
||||
return 1;
|
||||
|
||||
@ -54,28 +52,12 @@ static inline int mbedtls_ssl_ciphersuite_no_pfs(const mbedtls_ssl_ciphersuite_t
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED)
|
||||
static inline int mbedtls_ssl_ciphersuite_uses_ecdh(const mbedtls_ssl_ciphersuite_t *info)
|
||||
{
|
||||
switch (info->MBEDTLS_PRIVATE(key_exchange)) {
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
static inline int mbedtls_ssl_ciphersuite_cert_req_allowed(const mbedtls_ssl_ciphersuite_t *info)
|
||||
{
|
||||
switch (info->MBEDTLS_PRIVATE(key_exchange)) {
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return 1;
|
||||
|
||||
@ -87,9 +69,7 @@ static inline int mbedtls_ssl_ciphersuite_cert_req_allowed(const mbedtls_ssl_cip
|
||||
static inline int mbedtls_ssl_ciphersuite_uses_srv_cert(const mbedtls_ssl_ciphersuite_t *info)
|
||||
{
|
||||
switch (info->MBEDTLS_PRIVATE(key_exchange)) {
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return 1;
|
||||
|
||||
|
||||
@ -19,26 +19,26 @@
|
||||
#include "mbedtls/debug.h"
|
||||
#include "debug_internal.h"
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/private/cipher.h"
|
||||
|
||||
#include "psa/crypto.h"
|
||||
#include "psa_util_internal.h"
|
||||
extern const mbedtls_error_pair_t psa_to_ssl_errors[7];
|
||||
|
||||
#if defined(PSA_WANT_ALG_MD5)
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/private/md5.h"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/private/sha1.h"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/private/sha256.h"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_SHA_512)
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "mbedtls/private/sha512.h"
|
||||
#endif
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
@ -712,11 +712,6 @@ struct mbedtls_ssl_handshake_params {
|
||||
unsigned char retransmit_state; /*!< Retransmission state */
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
unsigned char group_list_heap_allocated;
|
||||
unsigned char sig_algs_heap_allocated;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
||||
uint8_t ecrs_enabled; /*!< Handshake supports EC restart? */
|
||||
enum { /* this complements ssl->state with info on intra-state operations */
|
||||
@ -2243,10 +2238,6 @@ static inline int mbedtls_ssl_tls12_named_group_is_ecdhe(uint16_t named_group)
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448 ||
|
||||
/* Below deprecated curves should be removed with notice to users */
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
|
||||
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
|
||||
@ -2309,15 +2300,6 @@ static inline int mbedtls_ssl_named_group_is_supported(uint16_t named_group)
|
||||
|
||||
/*
|
||||
* Return supported signature algorithms.
|
||||
*
|
||||
* In future, invocations can be changed to ssl->conf->sig_algs when
|
||||
* mbedtls_ssl_conf_sig_hashes() is deleted.
|
||||
*
|
||||
* ssl->handshake->sig_algs is either a translation of sig_hashes to IANA TLS
|
||||
* signature algorithm identifiers when mbedtls_ssl_conf_sig_hashes() has been
|
||||
* used, or a pointer to ssl->conf->sig_algs when mbedtls_ssl_conf_sig_algs() has
|
||||
* been more recently invoked.
|
||||
*
|
||||
*/
|
||||
static inline const void *mbedtls_ssl_get_sig_algs(
|
||||
const mbedtls_ssl_context *ssl)
|
||||
@ -2326,7 +2308,6 @@ static inline const void *mbedtls_ssl_get_sig_algs(
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
if (ssl->handshake != NULL &&
|
||||
ssl->handshake->sig_algs_heap_allocated == 1 &&
|
||||
ssl->handshake->sig_algs != NULL) {
|
||||
return ssl->handshake->sig_algs;
|
||||
}
|
||||
|
||||
@ -663,8 +663,7 @@ static void ssl_extract_add_data_from_record(unsigned char *add_data,
|
||||
unsigned char *cur = add_data;
|
||||
size_t ad_len_field = rec->data_len;
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
const unsigned char seq_num_placeholder[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
#endif
|
||||
|
||||
@ -680,8 +679,7 @@ static void ssl_extract_add_data_from_record(unsigned char *add_data,
|
||||
((void) tls_version);
|
||||
((void) taglen);
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
if (rec->cid_len != 0) {
|
||||
// seq_num_placeholder
|
||||
memcpy(cur, seq_num_placeholder, sizeof(seq_num_placeholder));
|
||||
@ -711,24 +709,7 @@ static void ssl_extract_add_data_from_record(unsigned char *add_data,
|
||||
memcpy(cur, rec->ver, sizeof(rec->ver));
|
||||
cur += sizeof(rec->ver);
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 1
|
||||
|
||||
if (rec->cid_len != 0) {
|
||||
// CID
|
||||
memcpy(cur, rec->cid, rec->cid_len);
|
||||
cur += rec->cid_len;
|
||||
|
||||
// cid_length
|
||||
*cur = rec->cid_len;
|
||||
cur++;
|
||||
|
||||
// length of inner plaintext
|
||||
MBEDTLS_PUT_UINT16_BE(ad_len_field, cur, 0);
|
||||
cur += 2;
|
||||
} else
|
||||
#elif defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
|
||||
if (rec->cid_len != 0) {
|
||||
// epoch + sequence number
|
||||
|
||||
@ -1066,73 +1066,6 @@ static int ssl_handshake_init(mbedtls_ssl_context *ssl)
|
||||
mbedtls_ssl_set_timer(ssl, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
/* Heap allocate and translate sig_hashes from internal hash identifiers to
|
||||
signature algorithms IANA identifiers. */
|
||||
if (mbedtls_ssl_conf_is_tls12_only(ssl->conf) &&
|
||||
ssl->conf->sig_hashes != NULL) {
|
||||
const int *md;
|
||||
const int *sig_hashes = ssl->conf->sig_hashes;
|
||||
size_t sig_algs_len = 0;
|
||||
uint16_t *p;
|
||||
|
||||
MBEDTLS_STATIC_ASSERT(MBEDTLS_SSL_MAX_SIG_ALG_LIST_LEN
|
||||
<= (SIZE_MAX - (2 * sizeof(uint16_t))),
|
||||
"MBEDTLS_SSL_MAX_SIG_ALG_LIST_LEN too big");
|
||||
|
||||
for (md = sig_hashes; *md != MBEDTLS_MD_NONE; md++) {
|
||||
if (mbedtls_ssl_hash_from_md_alg(*md) == MBEDTLS_SSL_HASH_NONE) {
|
||||
continue;
|
||||
}
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ALLOWED_ENABLED)
|
||||
sig_algs_len += sizeof(uint16_t);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
sig_algs_len += sizeof(uint16_t);
|
||||
#endif
|
||||
if (sig_algs_len > MBEDTLS_SSL_MAX_SIG_ALG_LIST_LEN) {
|
||||
return MBEDTLS_ERR_SSL_BAD_CONFIG;
|
||||
}
|
||||
}
|
||||
|
||||
if (sig_algs_len < MBEDTLS_SSL_MIN_SIG_ALG_LIST_LEN) {
|
||||
return MBEDTLS_ERR_SSL_BAD_CONFIG;
|
||||
}
|
||||
|
||||
ssl->handshake->sig_algs = mbedtls_calloc(1, sig_algs_len +
|
||||
sizeof(uint16_t));
|
||||
if (ssl->handshake->sig_algs == NULL) {
|
||||
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
p = (uint16_t *) ssl->handshake->sig_algs;
|
||||
for (md = sig_hashes; *md != MBEDTLS_MD_NONE; md++) {
|
||||
unsigned char hash = mbedtls_ssl_hash_from_md_alg(*md);
|
||||
if (hash == MBEDTLS_SSL_HASH_NONE) {
|
||||
continue;
|
||||
}
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDSA_CERT_REQ_ALLOWED_ENABLED)
|
||||
*p = ((hash << 8) | MBEDTLS_SSL_SIG_ECDSA);
|
||||
p++;
|
||||
#endif
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
*p = ((hash << 8) | MBEDTLS_SSL_SIG_RSA);
|
||||
p++;
|
||||
#endif
|
||||
}
|
||||
*p = MBEDTLS_TLS_SIG_NONE;
|
||||
ssl->handshake->sig_algs_heap_allocated = 1;
|
||||
} else
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
{
|
||||
ssl->handshake->sig_algs_heap_allocated = 0;
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1820,14 +1753,13 @@ static psa_status_t mbedtls_ssl_set_hs_ecjpake_password_common(
|
||||
size_t user_len = 0;
|
||||
const uint8_t *peer = NULL;
|
||||
size_t peer_len = 0;
|
||||
psa_pake_cs_set_algorithm(&cipher_suite, PSA_ALG_JPAKE);
|
||||
psa_pake_cs_set_algorithm(&cipher_suite, PSA_ALG_JPAKE(PSA_ALG_SHA_256));
|
||||
psa_pake_cs_set_primitive(&cipher_suite,
|
||||
PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC,
|
||||
PSA_ECC_FAMILY_SECP_R1,
|
||||
256));
|
||||
psa_pake_cs_set_hash(&cipher_suite, PSA_ALG_SHA_256);
|
||||
|
||||
status = psa_pake_setup(&ssl->handshake->psa_pake_ctx, &cipher_suite);
|
||||
status = psa_pake_setup(&ssl->handshake->psa_pake_ctx, pwd, &cipher_suite);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
@ -1854,11 +1786,6 @@ static psa_status_t mbedtls_ssl_set_hs_ecjpake_password_common(
|
||||
return status;
|
||||
}
|
||||
|
||||
status = psa_pake_set_password_key(&ssl->handshake->psa_pake_ctx, pwd);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
ssl->handshake->psa_pake_ctx_is_ok = 1;
|
||||
|
||||
return PSA_SUCCESS;
|
||||
@ -1881,7 +1808,7 @@ int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
|
||||
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE(PSA_ALG_SHA_256));
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
|
||||
|
||||
status = psa_import_key(&attributes, pw, pw_len,
|
||||
@ -2425,24 +2352,11 @@ psa_status_t mbedtls_ssl_cipher_to_psa(mbedtls_cipher_type_t mbedtls_cipher_type
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED) && defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
/*
|
||||
* Set allowed/preferred hashes for handshake signatures
|
||||
*/
|
||||
void mbedtls_ssl_conf_sig_hashes(mbedtls_ssl_config *conf,
|
||||
const int *hashes)
|
||||
{
|
||||
conf->sig_hashes = hashes;
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED && MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
|
||||
/* Configure allowed signature algorithms for handshake */
|
||||
void mbedtls_ssl_conf_sig_algs(mbedtls_ssl_config *conf,
|
||||
const uint16_t *sig_algs)
|
||||
{
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
conf->sig_hashes = NULL;
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
conf->sig_algs = sig_algs;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
@ -2638,18 +2552,6 @@ void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
|
||||
{
|
||||
conf->max_tls_version = (mbedtls_ssl_protocol_version) ((major << 8) | minor);
|
||||
}
|
||||
|
||||
void mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
|
||||
{
|
||||
conf->min_tls_version = (mbedtls_ssl_protocol_version) ((major << 8) | minor);
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
void mbedtls_ssl_conf_cert_req_ca_list(mbedtls_ssl_config *conf,
|
||||
char cert_req_ca_list)
|
||||
@ -4465,20 +4367,8 @@ void mbedtls_ssl_handshake_free(mbedtls_ssl_context *ssl)
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
if (ssl->handshake->group_list_heap_allocated) {
|
||||
mbedtls_free((void *) handshake->group_list);
|
||||
}
|
||||
handshake->group_list = NULL;
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
if (ssl->handshake->sig_algs_heap_allocated) {
|
||||
mbedtls_free((void *) handshake->sig_algs);
|
||||
}
|
||||
handshake->sig_algs = NULL;
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
@ -5898,15 +5788,6 @@ static const struct {
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||
{ 26, MBEDTLS_ECP_DP_BP256R1, PSA_ECC_FAMILY_BRAINPOOL_P_R1, 256 },
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_224)
|
||||
{ 21, MBEDTLS_ECP_DP_SECP224R1, PSA_ECC_FAMILY_SECP_R1, 224 },
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_192)
|
||||
{ 19, MBEDTLS_ECP_DP_SECP192R1, PSA_ECC_FAMILY_SECP_R1, 192 },
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_192)
|
||||
{ 18, MBEDTLS_ECP_DP_SECP192K1, PSA_ECC_FAMILY_SECP_K1, 192 },
|
||||
#endif
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||
{ 29, MBEDTLS_ECP_DP_CURVE25519, PSA_ECC_FAMILY_MONTGOMERY, 255 },
|
||||
#endif
|
||||
@ -5971,10 +5852,6 @@ static const struct {
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1, "secp256r1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1, "secp256k1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1, "brainpoolP256r1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1, "secp224r1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1, "secp224k1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1, "secp192r1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1, "secp192k1" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_X25519, "x25519" },
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_X448, "x448" },
|
||||
{ 0, NULL },
|
||||
@ -6508,8 +6385,28 @@ static int ssl_compute_master(mbedtls_ssl_handshake_params *handshake,
|
||||
return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
}
|
||||
|
||||
status = psa_pake_get_implicit_key(&handshake->psa_pake_ctx,
|
||||
&derivation);
|
||||
mbedtls_svc_key_id_t shared_key_id = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
|
||||
psa_key_attributes_t shared_key_attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_set_key_usage_flags(&shared_key_attributes, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_algorithm(&shared_key_attributes, alg);
|
||||
psa_set_key_type(&shared_key_attributes, PSA_KEY_TYPE_DERIVE);
|
||||
|
||||
status = psa_pake_get_shared_key(&handshake->psa_pake_ctx,
|
||||
&shared_key_attributes,
|
||||
&shared_key_id);
|
||||
|
||||
if (status != PSA_SUCCESS) {
|
||||
psa_key_derivation_abort(&derivation);
|
||||
return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
}
|
||||
|
||||
status = psa_key_derivation_input_key(&derivation,
|
||||
PSA_KEY_DERIVATION_INPUT_SECRET,
|
||||
shared_key_id);
|
||||
|
||||
psa_destroy_key(shared_key_id);
|
||||
|
||||
if (status != PSA_SUCCESS) {
|
||||
psa_key_derivation_abort(&derivation);
|
||||
return MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
@ -8726,11 +8623,6 @@ int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt *cert,
|
||||
usage = MBEDTLS_X509_KU_DIGITAL_SIGNATURE;
|
||||
break;
|
||||
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
usage = MBEDTLS_X509_KU_KEY_AGREEMENT;
|
||||
break;
|
||||
|
||||
/* Don't use default: we want warnings when adding new values */
|
||||
case MBEDTLS_KEY_EXCHANGE_NONE:
|
||||
case MBEDTLS_KEY_EXCHANGE_PSK:
|
||||
|
||||
@ -1732,71 +1732,6 @@ static int ssl_parse_server_psk_hint(mbedtls_ssl_context *ssl,
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_pk_context *peer_pk;
|
||||
|
||||
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
peer_pk = &ssl->handshake->peer_pubkey;
|
||||
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
if (ssl->session_negotiate->peer_cert == NULL) {
|
||||
/* Should never happen */
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("should never happen"));
|
||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||
}
|
||||
peer_pk = &ssl->session_negotiate->peer_cert->pk;
|
||||
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
|
||||
/* This is a public key, so it can't be opaque, so can_do() is a good
|
||||
* enough check to ensure pk_ec() is safe to use below. */
|
||||
if (!mbedtls_pk_can_do(peer_pk, MBEDTLS_PK_ECKEY)) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("server key not ECDH capable"));
|
||||
return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
uint16_t tls_id = 0;
|
||||
psa_key_type_t key_type = PSA_KEY_TYPE_NONE;
|
||||
mbedtls_ecp_group_id grp_id = mbedtls_pk_get_ec_group_id(peer_pk);
|
||||
|
||||
if (mbedtls_ssl_check_curve(ssl, grp_id) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("bad server certificate (ECDH curve)"));
|
||||
return MBEDTLS_ERR_SSL_BAD_CERTIFICATE;
|
||||
}
|
||||
|
||||
tls_id = mbedtls_ssl_get_tls_id_from_ecp_group_id(grp_id);
|
||||
if (tls_id == 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("ECC group %u not supported",
|
||||
grp_id));
|
||||
return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER;
|
||||
}
|
||||
|
||||
/* If the above conversion to TLS ID was fine, then also this one will be,
|
||||
so there is no need to check the return value here */
|
||||
mbedtls_ssl_get_psa_curve_info_from_tls_id(tls_id, &key_type,
|
||||
&ssl->handshake->xxdh_psa_bits);
|
||||
|
||||
ssl->handshake->xxdh_psa_type = key_type;
|
||||
|
||||
/* Store peer's public key in psa format. */
|
||||
memcpy(ssl->handshake->xxdh_psa_peerkey, peer_pk->pub_raw, peer_pk->pub_raw_len);
|
||||
ssl->handshake->xxdh_psa_peerkey_len = peer_pk->pub_raw_len;
|
||||
ret = 0;
|
||||
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
/* We don't need the peer's public key anymore. Free it,
|
||||
* so that more RAM is available for upcoming expensive
|
||||
* operations like ECDHE. */
|
||||
mbedtls_pk_free(peer_pk);
|
||||
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
static int ssl_parse_server_key_exchange(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
@ -1807,28 +1742,6 @@ static int ssl_parse_server_key_exchange(mbedtls_ssl_context *ssl)
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse server key exchange"));
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) {
|
||||
if ((ret = ssl_get_ecdh_params_from_cert(ssl)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "ssl_get_ecdh_params_from_cert", ret);
|
||||
mbedtls_ssl_send_alert_message(
|
||||
ssl,
|
||||
MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse server key exchange"));
|
||||
mbedtls_ssl_handshake_increment_state(ssl);
|
||||
return 0;
|
||||
}
|
||||
((void) p);
|
||||
((void) end);
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
||||
if (ssl->handshake->ecrs_enabled &&
|
||||
ssl->handshake->ecrs_state == ssl_ecrs_ske_start_processing) {
|
||||
@ -2380,13 +2293,9 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> write client key exchange"));
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) {
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA) {
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t destruction_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t key_attributes;
|
||||
@ -2460,9 +2369,7 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
} else
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK) {
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
@ -22,8 +22,7 @@
|
||||
|
||||
/* Define a local translating function to save code size by not using too many
|
||||
* arguments in each translating place. */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED)
|
||||
static int local_err_translation(psa_status_t status)
|
||||
{
|
||||
return psa_status_to_mbedtls(status, psa_to_ssl_errors,
|
||||
@ -34,7 +33,7 @@ static int local_err_translation(psa_status_t status)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/private/ecp.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
@ -2513,100 +2512,6 @@ static int ssl_write_certificate_request(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
|
||||
|
||||
#if (defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED))
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_pk_context *pk;
|
||||
mbedtls_pk_type_t pk_type;
|
||||
psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
unsigned char buf[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)];
|
||||
size_t key_len;
|
||||
|
||||
pk = mbedtls_ssl_own_key(ssl);
|
||||
|
||||
if (pk == NULL) {
|
||||
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
pk_type = mbedtls_pk_get_type(pk);
|
||||
|
||||
switch (pk_type) {
|
||||
case MBEDTLS_PK_OPAQUE:
|
||||
case MBEDTLS_PK_ECKEY:
|
||||
case MBEDTLS_PK_ECKEY_DH:
|
||||
case MBEDTLS_PK_ECDSA:
|
||||
if (!mbedtls_pk_can_do(pk, MBEDTLS_PK_ECKEY)) {
|
||||
return MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
/* Get the attributes of the key previously parsed by PK module in
|
||||
* order to extract its type and length (in bits). */
|
||||
status = psa_get_key_attributes(pk->priv_id, &key_attributes);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
goto exit;
|
||||
}
|
||||
ssl->handshake->xxdh_psa_type = psa_get_key_type(&key_attributes);
|
||||
ssl->handshake->xxdh_psa_bits = psa_get_key_bits(&key_attributes);
|
||||
|
||||
if (pk_type != MBEDTLS_PK_OPAQUE) {
|
||||
/* PK_ECKEY[_DH] and PK_ECDSA instead as parsed from the PK
|
||||
* module and only have ECDSA capabilities. Since we need
|
||||
* them for ECDH later, we export and then re-import them with
|
||||
* proper flags and algorithm. Of course We also set key's type
|
||||
* and bits that we just got above. */
|
||||
key_attributes = psa_key_attributes_init();
|
||||
psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_algorithm(&key_attributes, PSA_ALG_ECDH);
|
||||
psa_set_key_type(&key_attributes,
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(ssl->handshake->xxdh_psa_type));
|
||||
psa_set_key_bits(&key_attributes, ssl->handshake->xxdh_psa_bits);
|
||||
|
||||
status = psa_export_key(pk->priv_id, buf, sizeof(buf), &key_len);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
goto exit;
|
||||
}
|
||||
status = psa_import_key(&key_attributes, buf, key_len,
|
||||
&ssl->handshake->xxdh_psa_privkey);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ret = PSA_TO_MBEDTLS_ERR(status);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Set this key as owned by the TLS library: it will be its duty
|
||||
* to clear it exit. */
|
||||
ssl->handshake->xxdh_psa_privkey_is_external = 0;
|
||||
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opaque key is created by the user (externally from Mbed TLS)
|
||||
* so we assume it already has the right algorithm and flags
|
||||
* set. Just copy its ID as reference. */
|
||||
ssl->handshake->xxdh_psa_privkey = pk->priv_id;
|
||||
ssl->handshake->xxdh_psa_privkey_is_external = 1;
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH;
|
||||
}
|
||||
|
||||
exit:
|
||||
psa_reset_key_attributes(&key_attributes);
|
||||
mbedtls_platform_zeroize(buf, sizeof(buf));
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) && \
|
||||
defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
@ -2997,36 +2902,22 @@ static int ssl_write_server_key_exchange(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t signature_len = 0;
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
||||
ssl->handshake->ciphersuite_info;
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("=> write server key exchange"));
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED)
|
||||
/* Extract static ECDH parameters and abort if ServerKeyExchange
|
||||
* is not needed. */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
if (mbedtls_ssl_ciphersuite_no_pfs(ciphersuite_info)) {
|
||||
/* For suites involving ECDH, extract DH parameters
|
||||
* from certificate at this point. */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED)
|
||||
if (mbedtls_ssl_ciphersuite_uses_ecdh(ciphersuite_info)) {
|
||||
ret = ssl_get_ecdh_params_from_cert(ssl);
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "ssl_get_ecdh_params_from_cert", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_ECDH_ENABLED */
|
||||
|
||||
/* Key exchanges not involving ephemeral keys don't use
|
||||
* ServerKeyExchange, so end here. */
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write server key exchange"));
|
||||
mbedtls_ssl_handshake_increment_state(ssl);
|
||||
return 0;
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED) && \
|
||||
defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
@ -3210,13 +3101,9 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA ||
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) {
|
||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA) {
|
||||
size_t data_len = (size_t) (*p++);
|
||||
size_t buf_len = (size_t) (end - p);
|
||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||
@ -3279,9 +3166,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl)
|
||||
handshake->xxdh_psa_privkey = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
} else
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED ||
|
||||
MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
|
||||
MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
|
||||
if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK) {
|
||||
if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) {
|
||||
|
||||
@ -963,7 +963,7 @@ static int ssl_tls13_write_certificate_verify_body(mbedtls_ssl_context *ssl,
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF(3, "verify hash", verify_hash, verify_hash_len);
|
||||
|
||||
if ((ret = mbedtls_pk_sign_ext(pk_type, own_key,
|
||||
if ((ret = mbedtls_pk_sign_ext((mbedtls_pk_sigalg_t) pk_type, own_key,
|
||||
md_alg, verify_hash, verify_hash_len,
|
||||
p + 4, (size_t) (end - (p + 4)), &signature_len)) != 0) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("CertificateVerify signature failed with %s",
|
||||
@ -1144,7 +1144,8 @@ static int ssl_tls13_prepare_finished_message(mbedtls_ssl_context *ssl)
|
||||
ssl->handshake->state_local.finished_out.digest,
|
||||
sizeof(ssl->handshake->state_local.finished_out.
|
||||
digest),
|
||||
&ssl->handshake->state_local.finished_out.digest_len,
|
||||
&ssl->handshake->state_local.finished_out.
|
||||
digest_len,
|
||||
ssl->conf->endpoint);
|
||||
|
||||
if (ret != 0) {
|
||||
|
||||
@ -17,16 +17,14 @@ unsigned int mbedtls_version_get_number(void)
|
||||
return MBEDTLS_VERSION_NUMBER;
|
||||
}
|
||||
|
||||
void mbedtls_version_get_string(char *string)
|
||||
const char *mbedtls_version_get_string(void)
|
||||
{
|
||||
memcpy(string, MBEDTLS_VERSION_STRING,
|
||||
sizeof(MBEDTLS_VERSION_STRING));
|
||||
return MBEDTLS_VERSION_STRING;
|
||||
}
|
||||
|
||||
void mbedtls_version_get_string_full(char *string)
|
||||
const char *mbedtls_version_get_string_full(void)
|
||||
{
|
||||
memcpy(string, MBEDTLS_VERSION_STRING_FULL,
|
||||
sizeof(MBEDTLS_VERSION_STRING_FULL));
|
||||
return MBEDTLS_VERSION_STRING_FULL;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_VERSION_C */
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "mbedtls/oid.h"
|
||||
#include "x509_oid.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -716,7 +717,7 @@ int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x5
|
||||
* Get signature algorithm from alg OID and optional parameters
|
||||
*/
|
||||
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg)
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_sigalg_t *pk_alg)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
@ -725,7 +726,7 @@ int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
if (*pk_alg == MBEDTLS_PK_RSASSA_PSS) {
|
||||
if (*pk_alg == MBEDTLS_PK_SIGALG_RSA_PSS) {
|
||||
mbedtls_md_type_t mgf1_hash_id;
|
||||
int expected_salt_len;
|
||||
|
||||
@ -1038,7 +1039,7 @@ int mbedtls_x509_serial_gets(char *buf, size_t size, const mbedtls_x509_buf *ser
|
||||
* Helper for writing signature algorithms
|
||||
*/
|
||||
int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
|
||||
mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg)
|
||||
mbedtls_pk_sigalg_t pk_alg, mbedtls_md_type_t md_alg)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
char *p = buf;
|
||||
@ -1054,7 +1055,7 @@ int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *si
|
||||
MBEDTLS_X509_SAFE_SNPRINTF;
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
if (pk_alg == MBEDTLS_PK_RSASSA_PSS) {
|
||||
if (pk_alg == MBEDTLS_PK_SIGALG_RSA_PSS) {
|
||||
const char *name = md_type_to_string(md_alg);
|
||||
if (name != NULL) {
|
||||
ret = mbedtls_snprintf(p, n, " (%s)", name);
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "mbedtls/oid.h"
|
||||
#include "x509_oid.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
@ -645,7 +646,7 @@ 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,
|
||||
mbedtls_pk_type_t pk_alg)
|
||||
mbedtls_pk_sigalg_t pk_alg)
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
int write_null_par;
|
||||
@ -671,7 +672,7 @@ int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start,
|
||||
|
||||
// Write OID
|
||||
//
|
||||
if (pk_alg == MBEDTLS_PK_ECDSA) {
|
||||
if (pk_alg == MBEDTLS_PK_SIGALG_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
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include "x509_oid.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||
@ -187,9 +188,9 @@ static int x509_profile_check_md_alg(const mbedtls_x509_crt_profile *profile,
|
||||
* Return 0 if pk_alg is acceptable for this profile, -1 otherwise
|
||||
*/
|
||||
static int x509_profile_check_pk_alg(const mbedtls_x509_crt_profile *profile,
|
||||
mbedtls_pk_type_t pk_alg)
|
||||
mbedtls_pk_sigalg_t pk_alg)
|
||||
{
|
||||
if (pk_alg == MBEDTLS_PK_NONE) {
|
||||
if (pk_alg == MBEDTLS_PK_SIGALG_NONE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2060,7 +2061,7 @@ static int x509_crt_verifycrl(mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
|
||||
flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
|
||||
}
|
||||
|
||||
if (mbedtls_pk_verify_new(crl_list->sig_pk, &ca->pk,
|
||||
if (mbedtls_pk_verify_ext(crl_list->sig_pk, &ca->pk,
|
||||
crl_list->sig_md, hash, hash_length,
|
||||
crl_list->sig.p, crl_list->sig.len) != 0) {
|
||||
flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
|
||||
@ -2120,12 +2121,12 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child,
|
||||
}
|
||||
|
||||
/* Skip expensive computation on obvious mismatch */
|
||||
if (!mbedtls_pk_can_do(&parent->pk, child->sig_pk)) {
|
||||
if (!mbedtls_pk_can_do(&parent->pk, (mbedtls_pk_type_t) child->sig_pk)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA) {
|
||||
if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_SIGALG_ECDSA) {
|
||||
return mbedtls_pk_verify_restartable(&parent->pk,
|
||||
child->sig_md, hash, hash_len,
|
||||
child->sig.p, child->sig.len, &rs_ctx->pk);
|
||||
@ -2134,7 +2135,7 @@ static int x509_crt_check_signature(const mbedtls_x509_crt *child,
|
||||
(void) rs_ctx;
|
||||
#endif
|
||||
|
||||
return mbedtls_pk_verify_new(child->sig_pk, &parent->pk,
|
||||
return mbedtls_pk_verify_ext(child->sig_pk, &parent->pk,
|
||||
child->sig_md, hash, hash_len,
|
||||
child->sig.p, child->sig.len);
|
||||
}
|
||||
@ -3056,7 +3057,7 @@ static int x509_crt_verify_restartable_ca_cb(mbedtls_x509_crt *crt,
|
||||
/* Check the type and size of the key */
|
||||
pk_type = mbedtls_pk_get_type(&crt->pk);
|
||||
|
||||
if (x509_profile_check_pk_alg(profile, pk_type) != 0) {
|
||||
if (x509_profile_check_pk_alg(profile, (mbedtls_pk_sigalg_t) pk_type) != 0) {
|
||||
ee_flags |= MBEDTLS_X509_BADCERT_BAD_PK;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
#include "pk_internal.h"
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/private/rsa.h"
|
||||
#endif
|
||||
|
||||
int mbedtls_x509_get_name(unsigned char **p, const unsigned char *end,
|
||||
@ -35,7 +35,7 @@ int mbedtls_x509_get_rsassa_pss_params(const mbedtls_x509_buf *params,
|
||||
#endif
|
||||
int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig);
|
||||
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg);
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_sigalg_t *pk_alg);
|
||||
int mbedtls_x509_get_time(unsigned char **p, const unsigned char *end,
|
||||
mbedtls_x509_time *t);
|
||||
int mbedtls_x509_get_serial(unsigned char **p, const unsigned char *end,
|
||||
@ -44,7 +44,7 @@ int mbedtls_x509_get_ext(unsigned char **p, const unsigned char *end,
|
||||
mbedtls_x509_buf *ext, int tag);
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
|
||||
mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg);
|
||||
mbedtls_pk_sigalg_t pk_alg, mbedtls_md_type_t md_alg);
|
||||
#endif
|
||||
int mbedtls_x509_key_size_helper(char *buf, size_t buf_size, const char *name);
|
||||
int mbedtls_x509_set_extension(mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
|
||||
@ -57,7 +57,7 @@ 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,
|
||||
mbedtls_pk_type_t pk_alg);
|
||||
mbedtls_pk_sigalg_t pk_alg);
|
||||
int mbedtls_x509_get_ns_cert_type(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
unsigned char *ns_cert_type);
|
||||
|
||||
@ -381,7 +381,7 @@ FN_OID_GET_ATTR1(mbedtls_x509_oid_get_certificate_policies,
|
||||
typedef struct {
|
||||
mbedtls_x509_oid_descriptor_t descriptor;
|
||||
mbedtls_md_type_t md_alg;
|
||||
mbedtls_pk_type_t pk_alg;
|
||||
mbedtls_pk_sigalg_t pk_alg;
|
||||
} oid_sig_alg_t;
|
||||
|
||||
static const oid_sig_alg_t oid_sig_alg[] =
|
||||
@ -390,47 +390,47 @@ static const oid_sig_alg_t oid_sig_alg[] =
|
||||
#if defined(PSA_WANT_ALG_MD5)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_MD5, "md5WithRSAEncryption", "RSA with MD5"),
|
||||
MBEDTLS_MD_MD5, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_MD5, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_MD5 */
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA1, "sha-1WithRSAEncryption", "RSA with SHA1"),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#if defined(PSA_WANT_ALG_SHA_224)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA224, "sha224WithRSAEncryption",
|
||||
"RSA with SHA-224"),
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_224 */
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA256, "sha256WithRSAEncryption",
|
||||
"RSA with SHA-256"),
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA384, "sha384WithRSAEncryption",
|
||||
"RSA with SHA-384"),
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#if defined(PSA_WANT_ALG_SHA_512)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA512, "sha512WithRSAEncryption",
|
||||
"RSA with SHA-512"),
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_512 */
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_RSA_SHA_OBS, "sha-1WithRSAEncryption", "RSA with SHA1"),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_SIGALG_RSA_PKCS1V15,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
@ -438,43 +438,43 @@ static const oid_sig_alg_t oid_sig_alg[] =
|
||||
#if defined(PSA_WANT_ALG_SHA_1)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA1, "ecdsa-with-SHA1", "ECDSA with SHA1"),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_ECDSA,
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_SIGALG_ECDSA,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_1 */
|
||||
#if defined(PSA_WANT_ALG_SHA_224)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA224, "ecdsa-with-SHA224", "ECDSA with SHA224"),
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_ECDSA,
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_SIGALG_ECDSA,
|
||||
},
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_SHA_256)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA256, "ecdsa-with-SHA256", "ECDSA with SHA256"),
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_ECDSA,
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_SIGALG_ECDSA,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_256 */
|
||||
#if defined(PSA_WANT_ALG_SHA_384)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA384, "ecdsa-with-SHA384", "ECDSA with SHA384"),
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_ECDSA,
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_SIGALG_ECDSA,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_384 */
|
||||
#if defined(PSA_WANT_ALG_SHA_512)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA512, "ecdsa-with-SHA512", "ECDSA with SHA512"),
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_ECDSA,
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_SIGALG_ECDSA,
|
||||
},
|
||||
#endif /* PSA_WANT_ALG_SHA_512 */
|
||||
#endif /* PSA_HAVE_ALG_SOME_ECDSA */
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
{
|
||||
OID_DESCRIPTOR(MBEDTLS_OID_RSASSA_PSS, "RSASSA-PSS", "RSASSA-PSS"),
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_RSASSA_PSS,
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_SIGALG_RSA_PSS,
|
||||
},
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
{
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_NONE,
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_SIGALG_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
@ -494,14 +494,14 @@ FN_OID_GET_ATTR2(mbedtls_x509_oid_get_sig_alg,
|
||||
sig_alg,
|
||||
mbedtls_md_type_t,
|
||||
md_alg,
|
||||
mbedtls_pk_type_t,
|
||||
mbedtls_pk_sigalg_t,
|
||||
pk_alg)
|
||||
#endif /* MBEDTLS_X509_USE_C */
|
||||
#if defined(MBEDTLS_X509_CRT_WRITE_C) || defined(MBEDTLS_X509_CSR_WRITE_C)
|
||||
FN_OID_GET_OID_BY_ATTR2(mbedtls_x509_oid_get_oid_by_sig_alg,
|
||||
oid_sig_alg_t,
|
||||
oid_sig_alg,
|
||||
mbedtls_pk_type_t,
|
||||
mbedtls_pk_sigalg_t,
|
||||
pk_alg,
|
||||
mbedtls_md_type_t,
|
||||
md_alg)
|
||||
|
||||
@ -80,7 +80,7 @@ int mbedtls_x509_oid_get_attr_short_name(const mbedtls_asn1_buf *oid, const char
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_UNKNOWN_OID
|
||||
*/
|
||||
int mbedtls_x509_oid_get_sig_alg(const mbedtls_asn1_buf *oid,
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg);
|
||||
mbedtls_md_type_t *md_alg, mbedtls_pk_sigalg_t *pk_alg);
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
@ -106,7 +106,7 @@ int mbedtls_x509_oid_get_sig_alg_desc(const mbedtls_asn1_buf *oid, const char **
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_X509_UNKNOWN_OID
|
||||
*/
|
||||
int mbedtls_x509_oid_get_oid_by_sig_alg(mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
|
||||
int mbedtls_x509_oid_get_oid_by_sig_alg(mbedtls_pk_sigalg_t pk_alg, mbedtls_md_type_t md_alg,
|
||||
const char **oid, size_t *olen);
|
||||
#endif /* MBEDTLS_X509_CRT_WRITE_C || MBEDTLS_X509_CSR_WRITE_C */
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ int mbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert *ctx,
|
||||
}
|
||||
|
||||
int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx,
|
||||
unsigned char *serial, size_t serial_len)
|
||||
const unsigned char *serial, size_t serial_len)
|
||||
{
|
||||
if (serial_len > MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN) {
|
||||
return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
|
||||
@ -416,7 +416,7 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
return MBEDTLS_ERR_X509_INVALID_ALG;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_x509_oid_get_oid_by_sig_alg(pk_alg, ctx->md_alg,
|
||||
if ((ret = mbedtls_x509_oid_get_oid_by_sig_alg((mbedtls_pk_sigalg_t) pk_alg, ctx->md_alg,
|
||||
&sig_oid, &sig_oid_len)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -587,7 +587,8 @@ int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
|
||||
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, pk_alg));
|
||||
sig, sig_len,
|
||||
(mbedtls_pk_sigalg_t) pk_alg));
|
||||
|
||||
/*
|
||||
* Memory layout after this step:
|
||||
|
||||
@ -230,7 +230,7 @@ static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
|
||||
return MBEDTLS_ERR_X509_INVALID_ALG;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_x509_oid_get_oid_by_sig_alg(pk_alg, ctx->md_alg,
|
||||
if ((ret = mbedtls_x509_oid_get_oid_by_sig_alg((mbedtls_pk_sigalg_t) pk_alg, ctx->md_alg,
|
||||
&sig_oid, &sig_oid_len)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
@ -249,7 +249,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, pk_alg));
|
||||
sig, sig_len, (mbedtls_pk_sigalg_t) pk_alg));
|
||||
|
||||
/*
|
||||
* Compact the space between the CSR data and signature by moving the
|
||||
|
||||
5
programs/.gitignore
vendored
5
programs/.gitignore
vendored
@ -8,11 +8,6 @@
|
||||
hash/md5sum
|
||||
hash/sha1sum
|
||||
hash/sha2sum
|
||||
pkey/gen_key
|
||||
pkey/pk_sign
|
||||
pkey/pk_verify
|
||||
pkey/rsa_sign_pss
|
||||
pkey/rsa_verify_pss
|
||||
ssl/dtls_client
|
||||
ssl/dtls_server
|
||||
ssl/mini_client
|
||||
|
||||
@ -4,7 +4,7 @@ add_custom_target(${programs_target})
|
||||
if (NOT WIN32)
|
||||
add_subdirectory(fuzz)
|
||||
endif()
|
||||
add_subdirectory(pkey)
|
||||
|
||||
add_subdirectory(ssl)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(util)
|
||||
|
||||
@ -36,11 +36,6 @@ LOCAL_CFLAGS += -I$(FRAMEWORK)/tests/programs
|
||||
## Note: Variables cannot be used to define an apps path. This cannot be
|
||||
## substituted by the script generate_visualc_files.pl.
|
||||
APPS = \
|
||||
pkey/gen_key \
|
||||
pkey/pk_sign \
|
||||
pkey/pk_verify \
|
||||
pkey/rsa_sign_pss \
|
||||
pkey/rsa_verify_pss \
|
||||
../tf-psa-crypto/programs/psa/aead_demo \
|
||||
../tf-psa-crypto/programs/psa/crypto_examples \
|
||||
../tf-psa-crypto/programs/psa/hmac_demo \
|
||||
@ -136,26 +131,6 @@ test/query_config.c:
|
||||
echo " Gen $@"
|
||||
$(PERL) ../scripts/generate_query_config.pl
|
||||
|
||||
pkey/gen_key$(EXEXT): pkey/gen_key.c $(DEP)
|
||||
echo " CC pkey/gen_key.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/gen_key.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
pkey/pk_sign$(EXEXT): pkey/pk_sign.c $(DEP)
|
||||
echo " CC pkey/pk_sign.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_sign.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
pkey/pk_verify$(EXEXT): pkey/pk_verify.c $(DEP)
|
||||
echo " CC pkey/pk_verify.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_verify.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
pkey/rsa_sign_pss$(EXEXT): pkey/rsa_sign_pss.c $(DEP)
|
||||
echo " CC pkey/rsa_sign_pss.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_sign_pss.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
pkey/rsa_verify_pss$(EXEXT): pkey/rsa_verify_pss.c $(DEP)
|
||||
echo " CC pkey/rsa_verify_pss.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_verify_pss.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
../tf-psa-crypto/programs/psa/aead_demo$(EXEXT): ../tf-psa-crypto/programs/psa/aead_demo.c $(DEP)
|
||||
echo " CC psa/aead_demo.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@ -258,7 +233,7 @@ endif
|
||||
|
||||
test/metatest$(EXEXT): $(FRAMEWORK)/tests/programs/metatest.c $(DEP)
|
||||
echo " CC $(FRAMEWORK)/tests/programs/metatest.c"
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -I../library -I../tf-psa-crypto/core $(FRAMEWORK)/tests/programs/metatest.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -I../library -I../tf-psa-crypto/core -I../tf-psa-crypto/drivers/builtin/include -I../tf-psa-crypto/drivers/builtin/src $(FRAMEWORK)/tests/programs/metatest.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
test/query_config.o: test/query_config.c $(FRAMEWORK)/tests/programs/query_config.h $(DEP)
|
||||
echo " CC test/query_config.c"
|
||||
|
||||
@ -3,16 +3,6 @@ Mbed TLS sample programs
|
||||
|
||||
This subdirectory mostly contains sample programs that illustrate specific features of the library, as well as a few test and support programs.
|
||||
|
||||
### Generic public-key cryptography (`pk`) examples
|
||||
|
||||
* [`pkey/gen_key.c`](pkey/gen_key.c): generates a key for any of the supported public-key algorithms (RSA or ECC) and writes it to a file that can be used by the other pk sample programs.
|
||||
|
||||
* [`pkey/pk_sign.c`](pkey/pk_sign.c), [`pkey/pk_verify.c`](pkey/pk_verify.c): loads a PEM or DER private/public key file and uses the key to sign/verify a short string.
|
||||
|
||||
### ECDSA and RSA signature examples
|
||||
|
||||
* [`pkey/rsa_sign_pss.c`](pkey/rsa_sign_pss.c), [`pkey/rsa_verify_pss.c`](pkey/rsa_verify_pss.c): loads an RSA private/public key and uses it to sign/verify a short string with the RSASSA-PSS algorithm.
|
||||
|
||||
### SSL/TLS sample applications
|
||||
|
||||
* [`ssl/dtls_client.c`](ssl/dtls_client.c): a simple DTLS client program, which sends one datagram to the server and reads one datagram in response.
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "test/certs.h"
|
||||
#include "fuzz_common.h"
|
||||
#include <string.h>
|
||||
@ -78,12 +78,10 @@ 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) {
|
||||
@ -139,7 +137,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
}
|
||||
#endif
|
||||
//There may be other options to add :
|
||||
// mbedtls_ssl_conf_cert_profile, mbedtls_ssl_conf_sig_hashes
|
||||
// mbedtls_ssl_conf_cert_profile
|
||||
|
||||
if (mbedtls_ssl_setup(&ssl, &conf) != 0) {
|
||||
goto exit;
|
||||
@ -179,9 +177,7 @@ 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;
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
#include "fuzz_common.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "test/certs.h"
|
||||
|
||||
@ -61,12 +61,10 @@ 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) {
|
||||
@ -124,9 +122,7 @@ 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;
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "test/certs.h"
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/ssl_cookie.h"
|
||||
|
||||
@ -58,12 +58,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
mbedtls_ssl_config_init(&conf);
|
||||
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) {
|
||||
@ -166,9 +164,7 @@ 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;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/ssl_ticket.h"
|
||||
#include "test/certs.h"
|
||||
#include "fuzz_common.h"
|
||||
@ -67,12 +67,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
|
||||
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) {
|
||||
@ -194,19 +192,17 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
exit:
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_TICKET_C)
|
||||
mbedtls_ssl_ticket_free(&ticket_ctx);
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_TICKET_C */
|
||||
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
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_PEM_PARSE_C */
|
||||
mbedtls_ssl_free(&ssl);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif
|
||||
#else
|
||||
#else /* MBEDTLS_SSL_SRV_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */
|
||||
|
||||
@ -12,31 +12,27 @@ 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 !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
if (ret == 0) {
|
||||
ret = mbedtls_x509_crl_info((char *) buf, sizeof(buf) - 1, " ", &crl);
|
||||
}
|
||||
#else
|
||||
#else /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
((void) ret);
|
||||
((void) buf);
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_crl_free(&crl);
|
||||
#else
|
||||
#else /* MBEDTLS_X509_CRL_PARSE_C */
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif
|
||||
#endif /* MBEDTLS_X509_CRL_PARSE_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -12,12 +12,10 @@ 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 !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
if (ret == 0) {
|
||||
@ -28,15 +26,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
||||
((void) buf);
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_crt_free(&crt);
|
||||
#else
|
||||
#else /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -12,31 +12,27 @@ 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 !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
if (ret == 0) {
|
||||
ret = mbedtls_x509_csr_info((char *) buf, sizeof(buf) - 1, " ", &csr);
|
||||
}
|
||||
#else
|
||||
#else /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
((void) ret);
|
||||
((void) buf);
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
exit:
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
mbedtls_x509_csr_free(&csr);
|
||||
#else
|
||||
#else /* MBEDTLS_X509_CSR_PARSE_C */
|
||||
(void) Data;
|
||||
(void) Size;
|
||||
#endif
|
||||
#endif /* MBEDTLS_X509_CSR_PARSE_C */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
set(executables_mbedcrypto
|
||||
gen_key
|
||||
pk_sign
|
||||
pk_verify
|
||||
rsa_sign_pss
|
||||
rsa_verify_pss
|
||||
)
|
||||
add_dependencies(${programs_target} ${executables_mbedcrypto})
|
||||
|
||||
foreach(exe IN LISTS executables_mbedcrypto)
|
||||
add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
|
||||
set_base_compile_options(${exe})
|
||||
target_link_libraries(${exe} ${tfpsacrypto_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../framework/tests/include)
|
||||
endforeach()
|
||||
|
||||
install(TARGETS ${executables_mbedcrypto}
|
||||
DESTINATION "bin"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
@ -1,2 +0,0 @@
|
||||
P = FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF
|
||||
G = 02
|
||||
@ -1,482 +0,0 @@
|
||||
/*
|
||||
* Key generation application
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "tf-psa-crypto/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if !defined(MBEDTLS_PK_WRITE_C) || !defined(MBEDTLS_PEM_WRITE_C) || \
|
||||
!defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_BIGNUM_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_PK_WRITE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
||||
"MBEDTLS_PEM_WRITE_C and/or MBEDTLS_BIGNUM_C "
|
||||
"not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
#include <mbedtls/private/pk_private.h>
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
#include "mbedtls/ecdsa.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEV_RANDOM_THRESHOLD 32
|
||||
|
||||
static int dev_random_entropy_poll(void *data, unsigned char *output,
|
||||
size_t len, size_t *olen)
|
||||
{
|
||||
FILE *file;
|
||||
size_t ret, left = len;
|
||||
unsigned char *p = output;
|
||||
((void) data);
|
||||
|
||||
*olen = 0;
|
||||
|
||||
file = fopen("/dev/random", "rb");
|
||||
if (file == NULL) {
|
||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
}
|
||||
|
||||
while (left > 0) {
|
||||
/* /dev/random can return much less than requested. If so, try again */
|
||||
ret = fread(p, 1, left, file);
|
||||
if (ret == 0 && ferror(file)) {
|
||||
fclose(file);
|
||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
}
|
||||
|
||||
p += ret;
|
||||
left -= ret;
|
||||
sleep(1);
|
||||
}
|
||||
fclose(file);
|
||||
*olen = len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#define DFL_EC_CURVE mbedtls_ecp_curve_list()->grp_id
|
||||
#else
|
||||
#define DFL_EC_CURVE 0
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && defined(MBEDTLS_FS_IO)
|
||||
#define USAGE_DEV_RANDOM \
|
||||
" use_dev_random=0|1 default: 0\n"
|
||||
#else
|
||||
#define USAGE_DEV_RANDOM ""
|
||||
#endif /* !_WIN32 && MBEDTLS_FS_IO */
|
||||
|
||||
#define FORMAT_PEM 0
|
||||
#define FORMAT_DER 1
|
||||
|
||||
#define DFL_TYPE MBEDTLS_PK_RSA
|
||||
#define DFL_RSA_KEYSIZE 4096
|
||||
#define DFL_FILENAME "keyfile.key"
|
||||
#define DFL_FORMAT FORMAT_PEM
|
||||
#define DFL_USE_DEV_RANDOM 0
|
||||
|
||||
#define USAGE \
|
||||
"\n usage: gen_key param=<>...\n" \
|
||||
"\n acceptable parameters:\n" \
|
||||
" type=rsa|ec default: rsa\n" \
|
||||
" rsa_keysize=%%d default: 4096\n" \
|
||||
" ec_curve=%%s see below\n" \
|
||||
" filename=%%s default: keyfile.key\n" \
|
||||
" format=pem|der default: pem\n" \
|
||||
USAGE_DEV_RANDOM \
|
||||
"\n"
|
||||
|
||||
|
||||
/*
|
||||
* global options
|
||||
*/
|
||||
struct options {
|
||||
int type; /* the type of key to generate */
|
||||
int rsa_keysize; /* length of key in bits */
|
||||
int ec_curve; /* curve identifier for EC keys */
|
||||
const char *filename; /* filename of the key file */
|
||||
int format; /* the output format to use */
|
||||
int use_dev_random; /* use /dev/random as entropy source */
|
||||
} opt;
|
||||
|
||||
static int write_private_key(mbedtls_pk_context *key, const char *output_file)
|
||||
{
|
||||
int ret;
|
||||
FILE *f;
|
||||
unsigned char output_buf[16000];
|
||||
unsigned char *c = output_buf;
|
||||
size_t len = 0;
|
||||
|
||||
memset(output_buf, 0, 16000);
|
||||
if (opt.format == FORMAT_PEM) {
|
||||
if ((ret = mbedtls_pk_write_key_pem(key, output_buf, 16000)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
len = strlen((char *) output_buf);
|
||||
} else {
|
||||
if ((ret = mbedtls_pk_write_key_der(key, output_buf, 16000)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
len = ret;
|
||||
c = output_buf + sizeof(output_buf) - len;
|
||||
}
|
||||
|
||||
if ((f = fopen(output_file, "wb")) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fwrite(c, 1, len, f) != len) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
static int show_ecp_key(const mbedtls_ecp_keypair *ecp, int has_private)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
const mbedtls_ecp_curve_info *curve_info =
|
||||
mbedtls_ecp_curve_info_from_grp_id(
|
||||
mbedtls_ecp_keypair_get_group_id(ecp));
|
||||
mbedtls_printf("curve: %s\n", curve_info->name);
|
||||
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_group_init(&grp);
|
||||
mbedtls_mpi D;
|
||||
mbedtls_mpi_init(&D);
|
||||
mbedtls_ecp_point pt;
|
||||
mbedtls_ecp_point_init(&pt);
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_export(ecp, &grp,
|
||||
(has_private ? &D : NULL),
|
||||
&pt));
|
||||
|
||||
unsigned char point_bin[MBEDTLS_ECP_MAX_PT_LEN];
|
||||
size_t len = 0;
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_point_write_binary(
|
||||
&grp, &pt, MBEDTLS_ECP_PF_UNCOMPRESSED,
|
||||
&len, point_bin, sizeof(point_bin)));
|
||||
switch (mbedtls_ecp_get_type(&grp)) {
|
||||
case MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS:
|
||||
if ((len & 1) == 0 || point_bin[0] != 0x04) {
|
||||
/* Point in an unxepected format. This shouldn't happen. */
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&X, point_bin + 1, len / 2));
|
||||
MBEDTLS_MPI_CHK(
|
||||
mbedtls_mpi_read_binary(&Y, point_bin + 1 + len / 2, len / 2));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
mbedtls_mpi_write_file("Y_Q: ", &Y, 16, NULL);
|
||||
break;
|
||||
case MBEDTLS_ECP_TYPE_MONTGOMERY:
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&X, point_bin, len));
|
||||
mbedtls_mpi_write_file("X_Q: ", &X, 16, NULL);
|
||||
break;
|
||||
default:
|
||||
mbedtls_printf(
|
||||
"This program does not yet support listing coordinates for this curve type.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_private) {
|
||||
mbedtls_mpi_write_file("D: ", &D, 16, NULL);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
mbedtls_ecp_group_free(&grp);
|
||||
mbedtls_mpi_free(&D);
|
||||
mbedtls_ecp_point_free(&pt);
|
||||
mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_pk_context key;
|
||||
char buf[1024];
|
||||
int i;
|
||||
char *p, *q;
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
const char *pers = "gen_key";
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
const mbedtls_ecp_curve_info *curve_info;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set to sane values
|
||||
*/
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
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);
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_pk_init(&key);
|
||||
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);
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
mbedtls_printf(" available ec_curve values:\n");
|
||||
curve_info = mbedtls_ecp_curve_list();
|
||||
mbedtls_printf(" %s (default)\n", curve_info->name);
|
||||
while ((++curve_info)->name != NULL) {
|
||||
mbedtls_printf(" %s\n", curve_info->name);
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
goto exit;
|
||||
}
|
||||
|
||||
opt.type = DFL_TYPE;
|
||||
opt.rsa_keysize = DFL_RSA_KEYSIZE;
|
||||
opt.ec_curve = DFL_EC_CURVE;
|
||||
opt.filename = DFL_FILENAME;
|
||||
opt.format = DFL_FORMAT;
|
||||
opt.use_dev_random = DFL_USE_DEV_RANDOM;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
p = argv[i];
|
||||
if ((q = strchr(p, '=')) == NULL) {
|
||||
goto usage;
|
||||
}
|
||||
*q++ = '\0';
|
||||
|
||||
if (strcmp(p, "type") == 0) {
|
||||
if (strcmp(q, "rsa") == 0) {
|
||||
opt.type = MBEDTLS_PK_RSA;
|
||||
} else if (strcmp(q, "ec") == 0) {
|
||||
opt.type = MBEDTLS_PK_ECKEY;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
} else if (strcmp(p, "format") == 0) {
|
||||
if (strcmp(q, "pem") == 0) {
|
||||
opt.format = FORMAT_PEM;
|
||||
} else if (strcmp(q, "der") == 0) {
|
||||
opt.format = FORMAT_DER;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
} else if (strcmp(p, "rsa_keysize") == 0) {
|
||||
opt.rsa_keysize = atoi(q);
|
||||
if (opt.rsa_keysize < 1024 ||
|
||||
opt.rsa_keysize > MBEDTLS_MPI_MAX_BITS) {
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
else if (strcmp(p, "ec_curve") == 0) {
|
||||
if ((curve_info = mbedtls_ecp_curve_info_from_name(q)) == NULL) {
|
||||
goto usage;
|
||||
}
|
||||
opt.ec_curve = curve_info->grp_id;
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(p, "filename") == 0) {
|
||||
opt.filename = q;
|
||||
} else if (strcmp(p, "use_dev_random") == 0) {
|
||||
opt.use_dev_random = atoi(q);
|
||||
if (opt.use_dev_random < 0 || opt.use_dev_random > 1) {
|
||||
goto usage;
|
||||
}
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
#if !defined(_WIN32) && defined(MBEDTLS_FS_IO)
|
||||
if (opt.use_dev_random) {
|
||||
if ((ret = mbedtls_entropy_add_source(&entropy, dev_random_entropy_poll,
|
||||
NULL, DEV_RANDOM_THRESHOLD,
|
||||
MBEDTLS_ENTROPY_SOURCE_STRONG)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_entropy_add_source returned -0x%04x\n",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n Using /dev/random, so can take a long time! ");
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif /* !_WIN32 && MBEDTLS_FS_IO */
|
||||
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1.1. Generate the key
|
||||
*/
|
||||
mbedtls_printf("\n . Generating the private key ...");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_pk_setup(&key,
|
||||
mbedtls_pk_info_from_type((mbedtls_pk_type_t) opt.type))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_setup returned -0x%04x", (unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
|
||||
if (opt.type == MBEDTLS_PK_RSA) {
|
||||
ret = mbedtls_rsa_gen_key(mbedtls_pk_rsa(key), mbedtls_ctr_drbg_random, &ctr_drbg,
|
||||
opt.rsa_keysize, 65537);
|
||||
if (ret != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_rsa_gen_key returned -0x%04x",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (opt.type == MBEDTLS_PK_ECKEY) {
|
||||
ret = mbedtls_ecp_gen_key((mbedtls_ecp_group_id) opt.ec_curve,
|
||||
mbedtls_pk_ec(key),
|
||||
mbedtls_ctr_drbg_random, &ctr_drbg);
|
||||
if (ret != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ecp_gen_key returned -0x%04x",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
{
|
||||
mbedtls_printf(" failed\n ! key type not supported\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1.2 Print the key
|
||||
*/
|
||||
mbedtls_printf(" ok\n . Key information:\n");
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_RSA) {
|
||||
mbedtls_rsa_context *rsa = mbedtls_pk_rsa(key);
|
||||
|
||||
if ((ret = mbedtls_rsa_export(rsa, &N, &P, &Q, &D, &E)) != 0 ||
|
||||
(ret = mbedtls_rsa_export_crt(rsa, &DP, &DQ, &QP)) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export RSA parameters\n\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_mpi_write_file("N: ", &N, 16, NULL);
|
||||
mbedtls_mpi_write_file("E: ", &E, 16, NULL);
|
||||
mbedtls_mpi_write_file("D: ", &D, 16, NULL);
|
||||
mbedtls_mpi_write_file("P: ", &P, 16, NULL);
|
||||
mbedtls_mpi_write_file("Q: ", &Q, 16, NULL);
|
||||
mbedtls_mpi_write_file("DP: ", &DP, 16, NULL);
|
||||
mbedtls_mpi_write_file("DQ: ", &DQ, 16, NULL);
|
||||
mbedtls_mpi_write_file("QP: ", &QP, 16, NULL);
|
||||
} else
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
if (mbedtls_pk_get_type(&key) == MBEDTLS_PK_ECKEY) {
|
||||
if (show_ecp_key(mbedtls_pk_ec(key), 1) != 0) {
|
||||
mbedtls_printf(" failed\n ! could not export ECC parameters\n\n");
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
mbedtls_printf(" ! key type not supported\n");
|
||||
|
||||
/*
|
||||
* 1.3 Export key
|
||||
*/
|
||||
mbedtls_printf(" . Writing key to file...");
|
||||
|
||||
if ((ret = write_private_key(&key, opt.filename)) != 0) {
|
||||
mbedtls_printf(" failed\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf(" ok\n");
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
exit:
|
||||
|
||||
if (exit_code != MBEDTLS_EXIT_SUCCESS) {
|
||||
#ifdef MBEDTLS_ERROR_C
|
||||
mbedtls_printf("Error code: %d", ret);
|
||||
/* mbedtls_strerror(ret, buf, sizeof(buf));
|
||||
mbedtls_printf(" - %s\n", buf); */
|
||||
#else
|
||||
mbedtls_printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
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);
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
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 */
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* program viability conditions */
|
||||
@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Public key-based signature creation program
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "tf-psa-crypto/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
/* md.h is included this early since MD_CAN_XXX macros are defined there. */
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(PSA_WANT_ALG_SHA_256) || !defined(MBEDTLS_MD_C) || \
|
||||
!defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
|
||||
"PSA_WANT_ALG_SHA_256 and/or MBEDTLS_MD_C and/or "
|
||||
"MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_CTR_DRBG_C not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
#include <mbedtls/private/pk_private.h>
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
unsigned char hash[32];
|
||||
unsigned char buf[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
|
||||
char filename[512];
|
||||
const char *pers = "mbedtls_pk_sign";
|
||||
size_t olen = 0;
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
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");
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf("\n");
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Reading private key from '%s'", argv[1]);
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_pk_parse_keyfile(&pk, argv[1], "")) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not parse '%s'\n", argv[1]);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the SHA-256 hash of the input file,
|
||||
* then calculate the signature of the hash.
|
||||
*/
|
||||
mbedtls_printf("\n . Generating the SHA-256 signature");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_md_file(
|
||||
mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
|
||||
argv[2], hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not open or read %s\n\n", argv[2]);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256, hash, 0,
|
||||
buf, sizeof(buf), &olen)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_sign returned -0x%04x\n", (unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the signature into <filename>.sig
|
||||
*/
|
||||
mbedtls_snprintf(filename, sizeof(filename), "%s.sig", argv[2]);
|
||||
|
||||
if ((f = fopen(filename, "wb+")) == NULL) {
|
||||
mbedtls_printf(" failed\n ! Could not create %s\n\n", filename);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (fwrite(buf, 1, olen, f) != olen) {
|
||||
mbedtls_printf("failed\n ! fwrite failed\n\n");
|
||||
fclose(f);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
mbedtls_printf("\n . Done (created \"%s\")\n\n", filename);
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
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) {
|
||||
mbedtls_printf("Error code: %d", ret);
|
||||
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
|
||||
mbedtls_printf(" ! Last error was: %s\n", buf); */
|
||||
}
|
||||
#endif
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C &&
|
||||
PSA_WANT_ALG_SHA_256 && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO &&
|
||||
MBEDTLS_CTR_DRBG_C */
|
||||
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Public key-based signature verification program
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "tf-psa-crypto/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
/* md.h is included this early since MD_CAN_XXX macros are defined there. */
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_MD_C) || \
|
||||
!defined(PSA_WANT_ALG_SHA_256) || !defined(MBEDTLS_PK_PARSE_C) || \
|
||||
!defined(MBEDTLS_FS_IO)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_MD_C and/or "
|
||||
"PSA_WANT_ALG_SHA_256 and/or MBEDTLS_PK_PARSE_C and/or "
|
||||
"MBEDTLS_FS_IO not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
#include <mbedtls/private/pk_private.h>
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
size_t i;
|
||||
mbedtls_pk_context pk;
|
||||
unsigned char hash[32];
|
||||
unsigned char buf[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
|
||||
char filename[512];
|
||||
|
||||
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");
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf("\n");
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Reading public key from '%s'", argv[1]);
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_pk_parse_public_keyfile(&pk, argv[1])) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n",
|
||||
(unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the signature from the file
|
||||
*/
|
||||
mbedtls_snprintf(filename, sizeof(filename), "%s.sig", argv[2]);
|
||||
|
||||
if ((f = fopen(filename, "rb")) == NULL) {
|
||||
mbedtls_printf("\n ! Could not open %s\n\n", filename);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i = fread(buf, 1, sizeof(buf), f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
/*
|
||||
* Compute the SHA-256 hash of the input file and
|
||||
* verify the signature
|
||||
*/
|
||||
mbedtls_printf("\n . Verifying the SHA-256 signature");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_md_file(
|
||||
mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
|
||||
argv[2], hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not open or read %s\n\n", argv[2]);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256, hash, 0,
|
||||
buf, i)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_verify returned -0x%04x\n", (unsigned int) -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . OK (the signature is valid)\n\n");
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
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) {
|
||||
mbedtls_printf("Error code: %d", ret);
|
||||
/* mbedtls_strerror(ret, (char *) buf, sizeof(buf));
|
||||
mbedtls_printf(" ! Last error was: %s\n", buf); */
|
||||
}
|
||||
#endif
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C && PSA_WANT_ALG_SHA_256 &&
|
||||
MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */
|
||||
@ -1,8 +0,0 @@
|
||||
N = A1D46FBA2318F8DCEF16C280948B1CF27966B9B47225ED2989F8D74B45BD36049C0AAB5AD0FF003553BA843C8E12782FC5873BB89A3DC84B883D25666CD22BF3ACD5B675969F8BEBFBCAC93FDD927C7442B178B10D1DFF9398E52316AAE0AF74E594650BDC3C670241D418684593CDA1A7B9DC4F20D2FDC6F66344074003E211
|
||||
E = 010001
|
||||
D = 589552BB4F2F023ADDDD5586D0C8FD857512D82080436678D07F984A29D892D31F1F7000FC5A39A0F73E27D885E47249A4148C8A5653EF69F91F8F736BA9F84841C2D99CD8C24DE8B72B5C9BE0EDBE23F93D731749FEA9CFB4A48DD2B7F35A2703E74AA2D4DB7DE9CEEA7D763AF0ADA7AC176C4E9A22C4CDA65CEC0C65964401
|
||||
P = CD083568D2D46C44C40C1FA0101AF2155E59C70B08423112AF0C1202514BBA5210765E29FF13036F56C7495894D80CF8C3BAEE2839BACBB0B86F6A2965F60DB1
|
||||
Q = CA0EEEA5E710E8E9811A6B846399420E3AE4A4C16647E426DDF8BBBCB11CD3F35CE2E4B6BCAD07AE2C0EC2ECBFCC601B207CDD77B5673E16382B1130BF465261
|
||||
DP = 0D0E21C07BF434B4A83B116472C2147A11D8EB98A33CFBBCF1D275EF19D815941622435AAF3839B6C432CA53CE9E772CFBE1923A937A766FD93E96E6EDEC1DF1
|
||||
DQ = 269CEBE6305DFEE4809377F078C814E37B45AE6677114DFC4F76F5097E1F3031D592567AC55B9B98213B40ECD54A4D2361F5FAACA1B1F51F71E4690893C4F081
|
||||
QP = 97AC5BB885ABCA314375E9E4DB1BA4B2218C90619F61BD474F5785075ECA81750A735199A8C191FE2D3355E7CF601A70E5CABDE0E02C2538BB9FB4871540B3C1
|
||||
@ -1,2 +0,0 @@
|
||||
N = A1D46FBA2318F8DCEF16C280948B1CF27966B9B47225ED2989F8D74B45BD36049C0AAB5AD0FF003553BA843C8E12782FC5873BB89A3DC84B883D25666CD22BF3ACD5B675969F8BEBFBCAC93FDD927C7442B178B10D1DFF9398E52316AAE0AF74E594650BDC3C670241D418684593CDA1A7B9DC4F20D2FDC6F66344074003E211
|
||||
E = 010001
|
||||
@ -1,164 +0,0 @@
|
||||
/*
|
||||
* RSASSA-PSS/SHA-256 signature creation program
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "tf-psa-crypto/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
/* md.h is included this early since MD_CAN_XXX macros are defined there. */
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_RSA_C) || !defined(PSA_WANT_ALG_SHA_256) || \
|
||||
!defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_MD_C and/or MBEDTLS_ENTROPY_C and/or "
|
||||
"MBEDTLS_RSA_C and/or PSA_WANT_ALG_SHA_256 and/or "
|
||||
"MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_CTR_DRBG_C not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
#include <mbedtls/private/pk_private.h>
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
mbedtls_pk_context pk;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
unsigned char hash[32];
|
||||
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
|
||||
char filename[512];
|
||||
const char *pers = "rsa_sign_pss";
|
||||
size_t olen = 0;
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
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");
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf("\n");
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Seeding the random number generator...");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen(pers))) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Reading private key from '%s'", argv[1]);
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_pk_parse_keyfile(&pk, argv[1], "")) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not read key from '%s'\n", argv[1]);
|
||||
mbedtls_printf(" ! mbedtls_pk_parse_public_keyfile returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!mbedtls_pk_can_do(&pk, MBEDTLS_PK_RSA)) {
|
||||
mbedtls_printf(" failed\n ! Key is not an RSA key\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(pk),
|
||||
MBEDTLS_RSA_PKCS_V21,
|
||||
MBEDTLS_MD_SHA256)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Padding not supported\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the SHA-256 hash of the input file,
|
||||
* then calculate the RSA signature of the hash.
|
||||
*/
|
||||
mbedtls_printf("\n . Generating the RSA/SHA-256 signature");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_md_file(
|
||||
mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
|
||||
argv[2], hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not open or read %s\n\n", argv[2]);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_pk_sign(&pk, MBEDTLS_MD_SHA256, hash, 0,
|
||||
buf, sizeof(buf), &olen)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_sign returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the signature into <filename>.sig
|
||||
*/
|
||||
mbedtls_snprintf(filename, 512, "%s.sig", argv[2]);
|
||||
|
||||
if ((f = fopen(filename, "wb+")) == NULL) {
|
||||
mbedtls_printf(" failed\n ! Could not create %s\n\n", filename);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (fwrite(buf, 1, olen, f) != olen) {
|
||||
mbedtls_printf("failed\n ! fwrite failed\n\n");
|
||||
fclose(f);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
mbedtls_printf("\n . Done (created \"%s\")\n\n", filename);
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
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 */
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_RSA_C &&
|
||||
PSA_WANT_ALG_SHA_256 && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO &&
|
||||
MBEDTLS_CTR_DRBG_C */
|
||||
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* RSASSA-PSS/SHA-256 signature verification program
|
||||
*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||
|
||||
#include "tf-psa-crypto/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
/* md.h is included this early since MD_CAN_XXX macros are defined there. */
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_ENTROPY_C) || \
|
||||
!defined(MBEDTLS_RSA_C) || !defined(PSA_WANT_ALG_SHA_256) || \
|
||||
!defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_FS_IO) || \
|
||||
!defined(MBEDTLS_CTR_DRBG_C)
|
||||
int main(void)
|
||||
{
|
||||
mbedtls_printf("MBEDTLS_MD_C and/or MBEDTLS_ENTROPY_C and/or "
|
||||
"MBEDTLS_RSA_C and/or PSA_WANT_ALG_SHA_256 and/or "
|
||||
"MBEDTLS_PK_PARSE_C and/or MBEDTLS_FS_IO and/or "
|
||||
"MBEDTLS_CTR_DRBG_C not defined.\n");
|
||||
mbedtls_exit(0);
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/pem.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
#include <mbedtls/private/pk_private.h>
|
||||
#endif /* MBEDTLS_PK_HAVE_PRIVATE_HEADER */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int ret = 1;
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
size_t i;
|
||||
mbedtls_pk_context pk;
|
||||
unsigned char hash[32];
|
||||
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
|
||||
char filename[512];
|
||||
|
||||
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");
|
||||
|
||||
#if defined(_WIN32)
|
||||
mbedtls_printf("\n");
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . Reading public key from '%s'", argv[1]);
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_pk_parse_public_keyfile(&pk, argv[1])) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not read key from '%s'\n", argv[1]);
|
||||
mbedtls_printf(" ! mbedtls_pk_parse_public_keyfile returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!mbedtls_pk_can_do(&pk, MBEDTLS_PK_RSA)) {
|
||||
mbedtls_printf(" failed\n ! Key is not an RSA key\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(pk),
|
||||
MBEDTLS_RSA_PKCS_V21,
|
||||
MBEDTLS_MD_SHA256)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Invalid padding\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the RSA signature from the file
|
||||
*/
|
||||
mbedtls_snprintf(filename, 512, "%s.sig", argv[2]);
|
||||
|
||||
if ((f = fopen(filename, "rb")) == NULL) {
|
||||
mbedtls_printf("\n ! Could not open %s\n\n", filename);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
i = fread(buf, 1, MBEDTLS_MPI_MAX_SIZE, f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
/*
|
||||
* Compute the SHA-256 hash of the input file and
|
||||
* verify the signature
|
||||
*/
|
||||
mbedtls_printf("\n . Verifying the RSA/SHA-256 signature");
|
||||
fflush(stdout);
|
||||
|
||||
if ((ret = mbedtls_md_file(
|
||||
mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
|
||||
argv[2], hash)) != 0) {
|
||||
mbedtls_printf(" failed\n ! Could not open or read %s\n\n", argv[2]);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256, hash, 0,
|
||||
buf, i)) != 0) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_pk_verify returned %d\n\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_printf("\n . OK (the signature is valid)\n\n");
|
||||
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
|
||||
exit:
|
||||
mbedtls_pk_free(&pk);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && PSA_WANT_ALG_SHA_256 &&
|
||||
MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */
|
||||
@ -31,8 +31,8 @@ int main(void)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "test/certs.h"
|
||||
|
||||
@ -45,8 +45,8 @@ int main(void)
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_cookie.h"
|
||||
|
||||
@ -43,8 +43,8 @@ int main(void)
|
||||
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
@ -27,8 +27,8 @@ int main(void)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "test/certs.h"
|
||||
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
#include "mbedtls/private/pk_private.h"
|
||||
|
||||
#include "ssl_test_lib.h"
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_TEST_IMPOSSIBLE)
|
||||
int main(void)
|
||||
@ -145,7 +145,7 @@ int main(void)
|
||||
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
#define USAGE_IO ""
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#define USAGE_KEY_OPAQUE \
|
||||
" key_opaque=%%d Handle your private key as if it were opaque\n" \
|
||||
" default: 0 (disabled)\n"
|
||||
@ -172,7 +172,6 @@ int main(void)
|
||||
" psk=%%s default: \"\" (disabled)\n" \
|
||||
" The PSK values are in hex, without 0x.\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n"
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define USAGE_PSK_SLOT \
|
||||
" psk_opaque=%%d default: 0 (don't use opaque static PSK)\n" \
|
||||
" Enable this to store the PSK configured through command line\n" \
|
||||
@ -183,9 +182,6 @@ int main(void)
|
||||
" Note: This is to test integration of PSA-based opaque PSKs with\n" \
|
||||
" Mbed TLS only. Production systems are likely to configure Mbed TLS\n" \
|
||||
" with prepopulated key slots instead of importing raw key material.\n"
|
||||
#else
|
||||
#define USAGE_PSK_SLOT ""
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#define USAGE_PSK USAGE_PSK_RAW USAGE_PSK_SLOT
|
||||
#else
|
||||
#define USAGE_PSK ""
|
||||
@ -309,14 +305,9 @@ int main(void)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define USAGE_ECJPAKE \
|
||||
" ecjpake_pw=%%s default: none (disabled)\n" \
|
||||
" ecjpake_pw_opaque=%%d default: 0 (disabled)\n"
|
||||
#else /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#define USAGE_ECJPAKE \
|
||||
" ecjpake_pw=%%s default: none (disabled)\n"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#else /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
#define USAGE_ECJPAKE ""
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
@ -488,9 +479,7 @@ struct options {
|
||||
const char *crt_file; /* the file with the client certificate */
|
||||
const char *key_file; /* the file with the client key */
|
||||
int key_opaque; /* handle private key as if it were opaque */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int psk_opaque;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback; /* Use callback for trusted certificate list */
|
||||
#endif
|
||||
@ -498,9 +487,7 @@ struct options {
|
||||
const char *psk; /* the pre-shared key */
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
const char *ecjpake_pw; /* the EC J-PAKE password */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int ecjpake_pw_opaque; /* set to 1 to use the opaque method for setting the password */
|
||||
#endif
|
||||
int ec_max_ops; /* EC consecutive operations limit */
|
||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
@ -824,16 +811,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
const char *pers = "ssl_client2";
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
mbedtls_svc_key_id_t slot = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
psa_algorithm_t alg = 0;
|
||||
psa_key_attributes_t key_attributes;
|
||||
#endif
|
||||
psa_status_t status;
|
||||
#elif defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
psa_status_t status;
|
||||
#endif
|
||||
|
||||
rng_context_t rng;
|
||||
mbedtls_ssl_context ssl;
|
||||
@ -850,9 +833,7 @@ int main(int argc, char *argv[])
|
||||
mbedtls_x509_crt clicert;
|
||||
mbedtls_pk_context pkey;
|
||||
mbedtls_x509_crt_profile crt_profile_for_test = mbedtls_x509_crt_profile_default;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; /* invalid key slot */
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
char *p, *q;
|
||||
const int *list;
|
||||
@ -877,10 +858,9 @@ int main(int argc, char *argv[])
|
||||
MBEDTLS_TLS_SRTP_UNSET
|
||||
};
|
||||
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
mbedtls_svc_key_id_t ecjpake_pw_slot = MBEDTLS_SVC_KEY_ID_INIT; /* ecjpake password key slot */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
|
||||
@ -907,7 +887,6 @@ int main(int argc, char *argv[])
|
||||
memset((void *) alpn_list, 0, sizeof(alpn_list));
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
@ -915,7 +894,6 @@ int main(int argc, char *argv[])
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
mbedtls_test_enable_insecure_external_rng();
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
@ -942,17 +920,13 @@ int main(int argc, char *argv[])
|
||||
opt.key_opaque = DFL_KEY_OPAQUE;
|
||||
opt.key_pwd = DFL_KEY_PWD;
|
||||
opt.psk = DFL_PSK;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.psk_opaque = DFL_PSK_OPAQUE;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
opt.ca_callback = DFL_CA_CALLBACK;
|
||||
#endif
|
||||
opt.psk_identity = DFL_PSK_IDENTITY;
|
||||
opt.ecjpake_pw = DFL_ECJPAKE_PW;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.ecjpake_pw_opaque = DFL_ECJPAKE_PW_OPAQUE;
|
||||
#endif
|
||||
opt.ec_max_ops = DFL_EC_MAX_OPS;
|
||||
opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
@ -1127,7 +1101,7 @@ usage:
|
||||
} else if (strcmp(p, "key_pwd") == 0) {
|
||||
opt.key_pwd = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
else if (strcmp(p, "key_opaque") == 0) {
|
||||
opt.key_opaque = atoi(q);
|
||||
}
|
||||
@ -1151,12 +1125,9 @@ usage:
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
else if (strcmp(p, "psk") == 0) {
|
||||
opt.psk = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
else if (strcmp(p, "psk_opaque") == 0) {
|
||||
} else if (strcmp(p, "psk_opaque") == 0) {
|
||||
opt.psk_opaque = atoi(q);
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
else if (strcmp(p, "ca_callback") == 0) {
|
||||
opt.ca_callback = atoi(q);
|
||||
@ -1166,13 +1137,9 @@ usage:
|
||||
opt.psk_identity = q;
|
||||
} else if (strcmp(p, "ecjpake_pw") == 0) {
|
||||
opt.ecjpake_pw = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
else if (strcmp(p, "ecjpake_pw_opaque") == 0) {
|
||||
} else if (strcmp(p, "ecjpake_pw_opaque") == 0) {
|
||||
opt.ecjpake_pw_opaque = atoi(q);
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(p, "ec_max_ops") == 0) {
|
||||
} else if (strcmp(p, "ec_max_ops") == 0) {
|
||||
opt.ec_max_ops = atoi(q);
|
||||
} else if (strcmp(p, "force_ciphersuite") == 0) {
|
||||
opt.force_ciphersuite[0] = mbedtls_ssl_get_ciphersuite_id(q);
|
||||
@ -1500,7 +1467,6 @@ usage:
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.psk_opaque != 0) {
|
||||
if (opt.psk == NULL) {
|
||||
mbedtls_printf("psk_opaque set but no psk to be imported specified.\n");
|
||||
@ -1515,7 +1481,6 @@ usage:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (opt.force_ciphersuite[0] > 0) {
|
||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
|
||||
@ -1550,7 +1515,6 @@ usage:
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
if (opt.psk_opaque != 0) {
|
||||
/* Determine KDF algorithm the opaque PSK will be used in. */
|
||||
@ -1562,7 +1526,6 @@ usage:
|
||||
alg = PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA_256);
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
@ -1786,7 +1749,6 @@ usage:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.key_opaque != 0) {
|
||||
psa_algorithm_t psa_alg, psa_alg2 = PSA_ALG_NONE;
|
||||
psa_key_usage_t usage = 0;
|
||||
@ -1805,7 +1767,6 @@ usage:
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_printf(" ok (key type: %s)\n",
|
||||
strlen(opt.key_file) || strlen(opt.key_opaque_alg1) ?
|
||||
@ -2006,7 +1967,6 @@ usage:
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.psk_opaque != 0) {
|
||||
key_attributes = psa_key_attributes_init();
|
||||
psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_DERIVE);
|
||||
@ -2027,7 +1987,6 @@ usage:
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
if (psk_len > 0) {
|
||||
ret = mbedtls_ssl_conf_psk(&conf, psk, psk_len,
|
||||
(const unsigned char *) opt.psk_identity,
|
||||
@ -2098,12 +2057,11 @@ usage:
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
if (opt.ecjpake_pw != DFL_ECJPAKE_PW) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.ecjpake_pw_opaque != DFL_ECJPAKE_PW_OPAQUE) {
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE(PSA_ALG_SHA_256));
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
|
||||
|
||||
status = psa_import_key(&attributes,
|
||||
@ -2123,9 +2081,7 @@ usage:
|
||||
goto exit;
|
||||
}
|
||||
mbedtls_printf("using opaque password\n");
|
||||
} else
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
{
|
||||
} else {
|
||||
if ((ret = mbedtls_ssl_set_hs_ecjpake_password(&ssl,
|
||||
(const unsigned char *) opt.ecjpake_pw,
|
||||
strlen(opt.ecjpake_pw))) != 0) {
|
||||
@ -3206,13 +3162,10 @@ exit:
|
||||
mbedtls_x509_crt_free(&clicert);
|
||||
mbedtls_x509_crt_free(&cacert);
|
||||
mbedtls_pk_free(&pkey);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_destroy_key(key_slot);
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
if (opt.psk_opaque != 0) {
|
||||
/* This is ok even if the slot hasn't been
|
||||
* initialized (we might have jumed here
|
||||
@ -3229,11 +3182,9 @@ exit:
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED &&
|
||||
MBEDTLS_USE_PSA_CRYPTO */
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
/*
|
||||
* In case opaque keys it's the user responsibility to keep the key valid
|
||||
* for the duration of the handshake and destroy it at the end
|
||||
@ -3252,9 +3203,8 @@ exit:
|
||||
psa_destroy_key(ecjpake_pw_slot);
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED && MBEDTLS_USE_PSA_CRYPTO */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
const char *message = mbedtls_test_helper_is_psa_leaking();
|
||||
if (message) {
|
||||
if (ret == 0) {
|
||||
@ -3262,12 +3212,10 @@ exit:
|
||||
}
|
||||
mbedtls_printf("PSA memory leak detected: %s\n", message);
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
|
||||
/* For builds with MBEDTLS_TEST_USE_PSA_CRYPTO_RNG psa crypto
|
||||
* resources are freed by rng_free(). */
|
||||
#if (defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)) && \
|
||||
!defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
#if !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif
|
||||
|
||||
|
||||
@ -31,8 +31,8 @@ int main(void)
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "test/certs.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
|
||||
@ -38,8 +38,8 @@ int main(void)
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "test/certs.h"
|
||||
#include "mbedtls/x509.h"
|
||||
|
||||
|
||||
@ -38,8 +38,8 @@ int main(void)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
|
||||
@ -31,8 +31,8 @@ int main(void)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
|
||||
@ -53,9 +53,7 @@ int main(void)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
#endif
|
||||
|
||||
#include "mbedtls/pk.h"
|
||||
#if defined(MBEDTLS_PK_HAVE_PRIVATE_HEADER)
|
||||
@ -205,7 +203,7 @@ int main(void)
|
||||
#else
|
||||
#define USAGE_IO ""
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#define USAGE_KEY_OPAQUE \
|
||||
" key_opaque=%%d Handle your private keys as if they were opaque\n" \
|
||||
" default: 0 (disabled)\n"
|
||||
@ -248,7 +246,6 @@ int main(void)
|
||||
" The PSK values are in hex, without 0x.\n" \
|
||||
" id1,psk1[,id2,psk2[,...]]\n" \
|
||||
" psk_identity=%%s default: \"Client_identity\"\n"
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define USAGE_PSK_SLOT \
|
||||
" psk_opaque=%%d default: 0 (don't use opaque static PSK)\n" \
|
||||
" Enable this to store the PSK configured through command line\n" \
|
||||
@ -268,9 +265,6 @@ int main(void)
|
||||
" Note: This is to test integration of PSA-based opaque PSKs with\n" \
|
||||
" Mbed TLS only. Production systems are likely to configure Mbed TLS\n" \
|
||||
" with prepopulated key slots instead of importing raw key material.\n"
|
||||
#else
|
||||
#define USAGE_PSK_SLOT ""
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#define USAGE_PSK USAGE_PSK_RAW USAGE_PSK_SLOT
|
||||
#else
|
||||
#define USAGE_PSK ""
|
||||
@ -419,14 +413,9 @@ int main(void)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#define USAGE_ECJPAKE \
|
||||
" ecjpake_pw=%%s default: none (disabled)\n" \
|
||||
" ecjpake_pw_opaque=%%d default: 0 (disabled)\n"
|
||||
#else /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#define USAGE_ECJPAKE \
|
||||
" ecjpake_pw=%%s default: none (disabled)\n"
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#else /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
#define USAGE_ECJPAKE ""
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
@ -641,10 +630,8 @@ struct options {
|
||||
int async_private_delay1; /* number of times f_async_resume needs to be called for key 1, or -1 for no async */
|
||||
int async_private_delay2; /* number of times f_async_resume needs to be called for key 2, or -1 for no async */
|
||||
int async_private_error; /* inject error in async private callback */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int psk_opaque;
|
||||
int psk_list_opaque;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback; /* Use callback for trusted certificate list */
|
||||
#endif
|
||||
@ -652,9 +639,7 @@ struct options {
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
char *psk_list; /* list of PSK id/key pairs for callback */
|
||||
const char *ecjpake_pw; /* the EC J-PAKE password */
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int ecjpake_pw_opaque; /* set to 1 to use the opaque method for setting the password */
|
||||
#endif
|
||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
int tls13_kex_modes; /* supported TLS 1.3 key exchange modes */
|
||||
@ -962,9 +947,7 @@ struct _psk_entry {
|
||||
const char *name;
|
||||
size_t key_len;
|
||||
unsigned char key[MBEDTLS_PSK_MAX_LEN];
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_svc_key_id_t slot;
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
psk_entry *next;
|
||||
};
|
||||
|
||||
@ -976,7 +959,6 @@ static int psk_free(psk_entry *head)
|
||||
psk_entry *next;
|
||||
|
||||
while (head != NULL) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_status_t status;
|
||||
mbedtls_svc_key_id_t const slot = head->slot;
|
||||
|
||||
@ -986,7 +968,6 @@ static int psk_free(psk_entry *head)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
next = head->next;
|
||||
mbedtls_free(head);
|
||||
@ -1052,12 +1033,11 @@ static int psk_callback(void *p_info, mbedtls_ssl_context *ssl,
|
||||
while (cur != NULL) {
|
||||
if (name_len == strlen(cur->name) &&
|
||||
memcmp(name, cur->name, name_len) == 0) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(cur->slot) != 0) {
|
||||
return mbedtls_ssl_set_hs_psk_opaque(ssl, cur->slot);
|
||||
} else
|
||||
#endif
|
||||
return mbedtls_ssl_set_hs_psk(ssl, cur->key, cur->key_len);
|
||||
} else {
|
||||
return mbedtls_ssl_set_hs_psk(ssl, cur->key, cur->key_len);
|
||||
}
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
@ -1302,7 +1282,6 @@ static void ssl_async_cancel(mbedtls_ssl_context *ssl)
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
static psa_status_t psa_setup_psk_key_slot(mbedtls_svc_key_id_t *slot,
|
||||
psa_algorithm_t alg,
|
||||
@ -1326,7 +1305,6 @@ static psa_status_t psa_setup_psk_key_slot(mbedtls_svc_key_id_t *slot,
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
static int report_cid_usage(mbedtls_ssl_context *ssl,
|
||||
@ -1543,10 +1521,8 @@ int main(int argc, char *argv[])
|
||||
io_ctx_t io_ctx;
|
||||
unsigned char *buf = 0;
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_algorithm_t alg = 0;
|
||||
mbedtls_svc_key_id_t psk_slot = MBEDTLS_SVC_KEY_ID_INIT;
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
|
||||
size_t psk_len = 0;
|
||||
psk_entry *psk_info = NULL;
|
||||
@ -1574,10 +1550,8 @@ int main(int argc, char *argv[])
|
||||
mbedtls_x509_crt srvcert2;
|
||||
mbedtls_pk_context pkey2;
|
||||
mbedtls_x509_crt_profile crt_profile_for_test = mbedtls_x509_crt_profile_default;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
mbedtls_svc_key_id_t key_slot = MBEDTLS_SVC_KEY_ID_INIT; /* invalid key slot */
|
||||
mbedtls_svc_key_id_t key_slot2 = MBEDTLS_SVC_KEY_ID_INIT; /* invalid key slot */
|
||||
#endif
|
||||
int key_cert_init = 0, key_cert_init2 = 0;
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
@ -1609,10 +1583,9 @@ int main(int argc, char *argv[])
|
||||
unsigned char *context_buf = NULL;
|
||||
size_t context_buf_len = 0;
|
||||
#endif
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
mbedtls_svc_key_id_t ecjpake_pw_slot = MBEDTLS_SVC_KEY_ID_INIT; /* ecjpake password key slot */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO && MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
uint16_t sig_alg_list[SIG_ALG_LIST_SIZE];
|
||||
@ -1621,9 +1594,7 @@ int main(int argc, char *argv[])
|
||||
int i;
|
||||
char *p, *q;
|
||||
const int *list;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
psa_status_t status;
|
||||
#endif
|
||||
unsigned char eap_tls_keymaterial[16];
|
||||
unsigned char eap_tls_iv[8];
|
||||
const char *eap_tls_label = "client EAP encryption";
|
||||
@ -1684,7 +1655,6 @@ int main(int argc, char *argv[])
|
||||
mbedtls_ssl_cookie_init(&cookie_ctx);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
|
||||
@ -1692,7 +1662,6 @@ int main(int argc, char *argv[])
|
||||
ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
mbedtls_test_enable_insecure_external_rng();
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
@ -1731,19 +1700,15 @@ int main(int argc, char *argv[])
|
||||
opt.async_private_delay2 = DFL_ASYNC_PRIVATE_DELAY2;
|
||||
opt.async_private_error = DFL_ASYNC_PRIVATE_ERROR;
|
||||
opt.psk = DFL_PSK;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.psk_opaque = DFL_PSK_OPAQUE;
|
||||
opt.psk_list_opaque = DFL_PSK_LIST_OPAQUE;
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
opt.ca_callback = DFL_CA_CALLBACK;
|
||||
#endif
|
||||
opt.psk_identity = DFL_PSK_IDENTITY;
|
||||
opt.psk_list = DFL_PSK_LIST;
|
||||
opt.ecjpake_pw = DFL_ECJPAKE_PW;
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
opt.ecjpake_pw_opaque = DFL_ECJPAKE_PW_OPAQUE;
|
||||
#endif
|
||||
opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
opt.tls13_kex_modes = DFL_TLS1_3_KEX_MODES;
|
||||
@ -1924,7 +1889,7 @@ usage:
|
||||
} else if (strcmp(p, "key_pwd") == 0) {
|
||||
opt.key_pwd = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
else if (strcmp(p, "key_opaque") == 0) {
|
||||
opt.key_opaque = atoi(q);
|
||||
}
|
||||
@ -1972,14 +1937,11 @@ usage:
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
else if (strcmp(p, "psk") == 0) {
|
||||
opt.psk = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
else if (strcmp(p, "psk_opaque") == 0) {
|
||||
} else if (strcmp(p, "psk_opaque") == 0) {
|
||||
opt.psk_opaque = atoi(q);
|
||||
} else if (strcmp(p, "psk_list_opaque") == 0) {
|
||||
opt.psk_list_opaque = atoi(q);
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
else if (strcmp(p, "ca_callback") == 0) {
|
||||
opt.ca_callback = atoi(q);
|
||||
@ -1991,13 +1953,9 @@ usage:
|
||||
opt.psk_list = q;
|
||||
} else if (strcmp(p, "ecjpake_pw") == 0) {
|
||||
opt.ecjpake_pw = q;
|
||||
}
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
else if (strcmp(p, "ecjpake_pw_opaque") == 0) {
|
||||
} else if (strcmp(p, "ecjpake_pw_opaque") == 0) {
|
||||
opt.ecjpake_pw_opaque = atoi(q);
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(p, "force_ciphersuite") == 0) {
|
||||
} else if (strcmp(p, "force_ciphersuite") == 0) {
|
||||
opt.force_ciphersuite[0] = mbedtls_ssl_get_ciphersuite_id(q);
|
||||
|
||||
if (opt.force_ciphersuite[0] == 0) {
|
||||
@ -2367,7 +2325,6 @@ usage:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.psk_opaque != 0) {
|
||||
if (strlen(opt.psk) == 0) {
|
||||
mbedtls_printf("psk_opaque set but no psk to be imported specified.\n");
|
||||
@ -2397,7 +2354,6 @@ usage:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
if (opt.force_ciphersuite[0] > 0) {
|
||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
|
||||
@ -2427,7 +2383,6 @@ usage:
|
||||
opt.min_version = ciphersuite_info->min_tls_version;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
if (opt.psk_opaque != 0 || opt.psk_list_opaque != 0) {
|
||||
/* Determine KDF algorithm the opaque PSK will be used in. */
|
||||
@ -2439,7 +2394,6 @@ usage:
|
||||
alg = PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA_256);
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
@ -2732,7 +2686,6 @@ usage:
|
||||
#endif /* PSA_HAVE_ALG_SOME_ECDSA && PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT */
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.key_opaque != 0) {
|
||||
psa_algorithm_t psa_alg, psa_alg2 = PSA_ALG_NONE;
|
||||
psa_key_usage_t psa_usage = 0;
|
||||
@ -2768,7 +2721,6 @@ usage:
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_printf(" ok (key types: %s, %s)\n",
|
||||
key_cert_init ? mbedtls_pk_get_name(&pkey) : "none",
|
||||
@ -3182,7 +3134,6 @@ usage:
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
|
||||
if (strlen(opt.psk) != 0 && strlen(opt.psk_identity) != 0) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.psk_opaque != 0) {
|
||||
/* The algorithm has already been determined earlier. */
|
||||
status = psa_setup_psk_key_slot(&psk_slot, alg, psk, psk_len);
|
||||
@ -3199,7 +3150,6 @@ usage:
|
||||
goto exit;
|
||||
}
|
||||
} else
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
if (psk_len > 0) {
|
||||
ret = mbedtls_ssl_conf_psk(&conf, psk, psk_len,
|
||||
(const unsigned char *) opt.psk_identity,
|
||||
@ -3213,7 +3163,6 @@ usage:
|
||||
}
|
||||
|
||||
if (opt.psk_list != NULL) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.psk_list_opaque != 0) {
|
||||
psk_entry *cur_psk;
|
||||
for (cur_psk = psk_info; cur_psk != NULL; cur_psk = cur_psk->next) {
|
||||
@ -3227,7 +3176,6 @@ usage:
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
mbedtls_ssl_conf_psk_cb(&conf, psk_callback, psk_info);
|
||||
}
|
||||
@ -3384,12 +3332,11 @@ reset:
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
if (opt.ecjpake_pw != DFL_ECJPAKE_PW) {
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (opt.ecjpake_pw_opaque != DFL_ECJPAKE_PW_OPAQUE) {
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_JPAKE(PSA_ALG_SHA_256));
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_PASSWORD);
|
||||
|
||||
status = psa_import_key(&attributes,
|
||||
@ -3409,9 +3356,7 @@ reset:
|
||||
goto exit;
|
||||
}
|
||||
mbedtls_printf("using opaque password\n");
|
||||
} else
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
{
|
||||
} else {
|
||||
if ((ret = mbedtls_ssl_set_hs_ecjpake_password(&ssl,
|
||||
(const unsigned char *) opt.ecjpake_pw,
|
||||
strlen(opt.ecjpake_pw))) != 0) {
|
||||
@ -4253,11 +4198,9 @@ exit:
|
||||
mbedtls_pk_free(&pkey);
|
||||
mbedtls_x509_crt_free(&srvcert2);
|
||||
mbedtls_pk_free(&pkey2);
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
psa_destroy_key(key_slot);
|
||||
psa_destroy_key(key_slot2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
for (i = 0; (size_t) i < ssl_async_keys.slots_used; i++) {
|
||||
@ -4269,8 +4212,7 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
||||
if (opt.psk_opaque != 0) {
|
||||
/* This is ok even if the slot hasn't been
|
||||
* initialized (we might have jumed here
|
||||
@ -4284,11 +4226,9 @@ exit:
|
||||
(int) status);
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED &&
|
||||
MBEDTLS_USE_PSA_CRYPTO */
|
||||
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||
/*
|
||||
* In case opaque keys it's the user responsibility to keep the key valid
|
||||
* for the duration of the handshake and destroy it at the end
|
||||
@ -4307,9 +4247,8 @@ exit:
|
||||
psa_destroy_key(ecjpake_pw_slot);
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED && MBEDTLS_USE_PSA_CRYPTO */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
const char *message = mbedtls_test_helper_is_psa_leaking();
|
||||
if (message) {
|
||||
if (ret == 0) {
|
||||
@ -4317,12 +4256,10 @@ exit:
|
||||
}
|
||||
mbedtls_printf("PSA memory leak detected: %s\n", message);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For builds with MBEDTLS_TEST_USE_PSA_CRYPTO_RNG psa crypto
|
||||
* resources are freed by rng_free(). */
|
||||
#if (defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)) \
|
||||
&& !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
#if !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
mbedtls_psa_crypto_free();
|
||||
#endif
|
||||
|
||||
|
||||
@ -83,13 +83,11 @@ void rng_init(rng_context_t *rng)
|
||||
|
||||
int rng_seed(rng_context_t *rng, int reproducible, const char *pers)
|
||||
{
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
if (reproducible) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"MBEDTLS_USE_PSA_CRYPTO does not support reproducible mode.\n");
|
||||
"reproducible mode is not supported.\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#if defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
/* The PSA crypto RNG does its own seeding. */
|
||||
(void) rng;
|
||||
@ -217,7 +215,6 @@ int key_opaque_alg_parse(const char *arg, const char **alg1, const char **alg2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
int key_opaque_set_alg_usage(const char *alg1, const char *alg2,
|
||||
psa_algorithm_t *psa_alg1,
|
||||
psa_algorithm_t *psa_alg2,
|
||||
@ -301,7 +298,6 @@ int pk_wrap_as_opaque(mbedtls_pk_context *pk, psa_algorithm_t psa_alg, psa_algor
|
||||
return 0;
|
||||
}
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
int ca_callback(void *data, mbedtls_x509_crt const *child,
|
||||
@ -509,21 +505,6 @@ static const struct {
|
||||
#else
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1, "brainpoolP256r1", 0 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_224)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1, "secp224r1", 1 },
|
||||
#else
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1, "secp224r1", 0 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(PSA_WANT_ECC_SECP_R1_192)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1, "secp192r1", 1 },
|
||||
#else
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1, "secp192r1", 0 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(PSA_WANT_ECC_SECP_K1_192)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1, "secp192k1", 1 },
|
||||
#else
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1, "secp192k1", 0 },
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||
{ MBEDTLS_SSL_IANA_TLS_GROUP_X25519, "x25519", 1 },
|
||||
#else
|
||||
|
||||
@ -8,15 +8,15 @@
|
||||
#ifndef MBEDTLS_PROGRAMS_SSL_SSL_TEST_LIB_H
|
||||
#define MBEDTLS_PROGRAMS_SSL_SSL_TEST_LIB_H
|
||||
|
||||
#include "mbedtls/private/pk_private.h"
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/md.h"
|
||||
|
||||
#undef HAVE_RNG
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) && \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) || \
|
||||
defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG))
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
#define HAVE_RNG
|
||||
#elif defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C)
|
||||
#define HAVE_RNG
|
||||
@ -45,9 +45,9 @@
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/ssl_ciphersuites.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/hmac_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/private/hmac_drbg.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/debug.h"
|
||||
@ -55,10 +55,8 @@
|
||||
#include "mbedtls/base64.h"
|
||||
#include "test/certs.h"
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
#include "psa/crypto.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
#include "mbedtls/memory_buffer_alloc.h"
|
||||
@ -108,30 +106,7 @@ void my_debug(void *ctx, int level,
|
||||
mbedtls_time_t dummy_constant_time(mbedtls_time_t *time);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG)
|
||||
/* If MBEDTLS_TEST_USE_PSA_CRYPTO_RNG is defined, the SSL test programs will use
|
||||
* mbedtls_psa_get_random() rather than entropy+DRBG as a random generator.
|
||||
*
|
||||
* The constraints are:
|
||||
* - Without the entropy module, the PSA RNG is the only option.
|
||||
* - Without at least one of the DRBG modules, the PSA RNG is the only option.
|
||||
* - The PSA RNG does not support explicit seeding, so it is incompatible with
|
||||
* the reproducible mode used by test programs.
|
||||
* - For good overall test coverage, there should be at least one configuration
|
||||
* where the test programs use the PSA RNG while the PSA RNG is itself based
|
||||
* on entropy+DRBG, and at least one configuration where the test programs
|
||||
* do not use the PSA RNG even though it's there.
|
||||
*
|
||||
* A simple choice that meets the constraints is to use the PSA RNG whenever
|
||||
* MBEDTLS_USE_PSA_CRYPTO is enabled. There's no real technical reason the
|
||||
* choice to use the PSA RNG in the test programs and the choice to use
|
||||
* PSA crypto when TLS code needs crypto have to be tied together, but it
|
||||
* happens to be a good match. It's also a good match from an application
|
||||
* perspective: either PSA is preferred for TLS (both for crypto and for
|
||||
* random generation) or it isn't.
|
||||
*/
|
||||
#define MBEDTLS_TEST_USE_PSA_CRYPTO_RNG
|
||||
#endif
|
||||
|
||||
/** A context for random number generation (RNG).
|
||||
*/
|
||||
@ -213,7 +188,6 @@ int rng_get(void *p_rng, unsigned char *output, size_t output_len);
|
||||
*/
|
||||
int key_opaque_alg_parse(const char *arg, const char **alg1, const char **alg2);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
/** Parse given opaque key algorithms to obtain psa algs and usage
|
||||
* that will be passed to mbedtls_pk_wrap_as_opaque().
|
||||
*
|
||||
@ -259,9 +233,8 @@ int key_opaque_set_alg_usage(const char *alg1, const char *alg2,
|
||||
int pk_wrap_as_opaque(mbedtls_pk_context *pk, psa_algorithm_t psa_alg, psa_algorithm_t psa_alg2,
|
||||
psa_key_usage_t psa_usage, mbedtls_svc_key_id_t *key_id);
|
||||
#endif /* MBEDTLS_PK_C */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
/* The test implementation of the PSA external RNG is insecure. When
|
||||
* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled, before using any PSA crypto
|
||||
* function that makes use of an RNG, you must call
|
||||
|
||||
@ -56,6 +56,7 @@ if(GEN_FILES)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/include/psa/crypto_config.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/data_files/query_config.fmt
|
||||
${CMAKE_CURRENT_BINARY_DIR}/query_config.c
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_query_config.pl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/mbedtls_config.h
|
||||
@ -101,6 +102,10 @@ foreach(exe IN LISTS executables)
|
||||
target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endforeach()
|
||||
|
||||
target_include_directories(metatest
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/drivers/builtin/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/drivers/builtin/src)
|
||||
|
||||
install(TARGETS ${executables}
|
||||
DESTINATION "bin"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
|
||||
@ -18,10 +18,7 @@
|
||||
* linkage works, but that is all. */
|
||||
int main()
|
||||
{
|
||||
/* This version string is 18 bytes long, as advised by version.h. */
|
||||
char version[18];
|
||||
|
||||
mbedtls_version_get_string_full(version);
|
||||
const char *version = mbedtls_version_get_string_full();
|
||||
|
||||
mbedtls_printf("Built against %s\n", version);
|
||||
|
||||
|
||||
@ -37,5 +37,11 @@ find_package(MbedTLS REQUIRED)
|
||||
#
|
||||
|
||||
add_executable(cmake_package_install cmake_package_install.c)
|
||||
|
||||
string(REGEX MATCH "GNU" CMAKE_COMPILER_IS_GNU "${CMAKE_C_COMPILER_ID}")
|
||||
if(CMAKE_COMPILER_IS_GNU)
|
||||
target_compile_options(cmake_package_install PRIVATE -Wall -Werror)
|
||||
endif()
|
||||
|
||||
target_link_libraries(cmake_package_install
|
||||
MbedTLS::mbedtls MbedTLS::mbedx509 MbedTLS::tfpsacrypto)
|
||||
|
||||
@ -19,10 +19,7 @@
|
||||
* linkage works, but that is all. */
|
||||
int main()
|
||||
{
|
||||
/* This version string is 18 bytes long, as advised by version.h. */
|
||||
char version[18];
|
||||
|
||||
mbedtls_version_get_string_full(version);
|
||||
const char *version = mbedtls_version_get_string_full();
|
||||
|
||||
mbedtls_printf("Built against %s\n", version);
|
||||
|
||||
|
||||
@ -19,10 +19,7 @@
|
||||
* linkage works, but that is all. */
|
||||
int main()
|
||||
{
|
||||
/* This version string is 18 bytes long, as advised by version.h. */
|
||||
char version[18];
|
||||
|
||||
mbedtls_version_get_string_full(version);
|
||||
const char *version = mbedtls_version_get_string_full();
|
||||
|
||||
mbedtls_printf("Built against %s\n", version);
|
||||
|
||||
|
||||
@ -9,31 +9,31 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/hmac_drbg.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/ccm.h"
|
||||
#include "mbedtls/cmac.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "mbedtls/sha3.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/camellia.h"
|
||||
#include "mbedtls/aria.h"
|
||||
#include "mbedtls/chacha20.h"
|
||||
#include "mbedtls/poly1305.h"
|
||||
#include "mbedtls/chachapoly.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/hmac_drbg.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/private/gcm.h"
|
||||
#include "mbedtls/private/ccm.h"
|
||||
#include "mbedtls/private/cmac.h"
|
||||
#include "mbedtls/private/md5.h"
|
||||
#include "mbedtls/private/ripemd160.h"
|
||||
#include "mbedtls/private/sha1.h"
|
||||
#include "mbedtls/private/sha256.h"
|
||||
#include "mbedtls/private/sha512.h"
|
||||
#include "mbedtls/private/sha3.h"
|
||||
#include "mbedtls/private/aes.h"
|
||||
#include "mbedtls/private/camellia.h"
|
||||
#include "mbedtls/private/aria.h"
|
||||
#include "mbedtls/private/chacha20.h"
|
||||
#include "mbedtls/private/poly1305.h"
|
||||
#include "mbedtls/private/chachapoly.h"
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/private/bignum.h"
|
||||
#include "mbedtls/private/rsa.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/pkcs5.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/ecjpake.h"
|
||||
#include "mbedtls/private/pkcs5.h"
|
||||
#include "mbedtls/private/ecp.h"
|
||||
#include "mbedtls/private/ecjpake.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/nist_kw.h"
|
||||
#include "mbedtls/debug.h"
|
||||
@ -210,7 +210,7 @@ static int run_test_snprintf(void)
|
||||
* back.
|
||||
*/
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_PLATFORM_GET_ENTROPY_ALT)
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_PSA_DRIVER_GET_ENTROPY)
|
||||
static void dummy_entropy(unsigned char *output, size_t output_size)
|
||||
{
|
||||
srand(1);
|
||||
@ -239,7 +239,7 @@ static void create_entropy_seed_file(void)
|
||||
|
||||
static int mbedtls_entropy_self_test_wrapper(int verbose)
|
||||
{
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_PLATFORM_GET_ENTROPY_ALT)
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_PSA_DRIVER_GET_ENTROPY)
|
||||
create_entropy_seed_file();
|
||||
#endif
|
||||
return mbedtls_entropy_self_test(verbose);
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include <limits.h>
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
|
||||
@ -27,8 +27,8 @@ int main(void)
|
||||
}
|
||||
#else
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/x509.h"
|
||||
@ -152,14 +152,12 @@ 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:
|
||||
@ -446,9 +444,7 @@ 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 */
|
||||
|
||||
mbedtls_exit(exit_code);
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ int main(void)
|
||||
#else
|
||||
|
||||
#include "mbedtls/x509_csr.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/private/entropy.h"
|
||||
#include "mbedtls/private/ctr_drbg.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -162,14 +162,12 @@ int main(int argc, char *argv[])
|
||||
memset(buf, 0, sizeof(buf));
|
||||
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:
|
||||
@ -502,9 +500,7 @@ 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 */
|
||||
|
||||
cur = opt.san_list;
|
||||
while (cur != NULL) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user