mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-05-22 13:22:08 +00:00
Merge pull request #868 from ARMmbed/mbedtls-2.28.0rc0-pr
Mbedtls 2.28.0rc0 pr
This commit is contained in:
commit
8b3f26a5ac
|
@ -19,7 +19,7 @@ jobs:
|
||||||
language: python # Needed to get pip for Python 3
|
language: python # Needed to get pip for Python 3
|
||||||
python: 3.5 # version from Ubuntu 16.04
|
python: 3.5 # version from Ubuntu 16.04
|
||||||
install:
|
install:
|
||||||
- pip install mypy==0.780 pylint==2.4.4
|
- scripts/min_requirements.py
|
||||||
script:
|
script:
|
||||||
- tests/scripts/all.sh -k 'check_*'
|
- tests/scripts/all.sh -k 'check_*'
|
||||||
- tests/scripts/all.sh -k test_default_out_of_box
|
- tests/scripts/all.sh -k test_default_out_of_box
|
||||||
|
|
|
@ -48,8 +48,7 @@ The following branches are currently maintained:
|
||||||
|
|
||||||
- [master](https://github.com/ARMmbed/mbedtls/tree/master)
|
- [master](https://github.com/ARMmbed/mbedtls/tree/master)
|
||||||
- [`development`](https://github.com/ARMmbed/mbedtls/)
|
- [`development`](https://github.com/ARMmbed/mbedtls/)
|
||||||
- [`mbedtls-2.16`](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.16)
|
- [`mbedtls-2.28`](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.28)
|
||||||
maintained until at least the end of 2021, see
|
maintained until at least the end of 2024.
|
||||||
<https://tls.mbed.org/tech-updates/blog/announcing-lts-branch-mbedtls-2.16>
|
|
||||||
|
|
||||||
Users are urged to always use the latest version of a maintained branch.
|
Users are urged to always use the latest version of a maintained branch.
|
||||||
|
|
121
ChangeLog
121
ChangeLog
|
@ -1,5 +1,126 @@
|
||||||
mbed TLS ChangeLog (Sorted per branch, date)
|
mbed TLS ChangeLog (Sorted per branch, date)
|
||||||
|
|
||||||
|
= mbed TLS 2.28.0 branch released 2021-12-17
|
||||||
|
|
||||||
|
API changes
|
||||||
|
* Some fields of mbedtls_ssl_session and mbedtls_ssl_config are in a
|
||||||
|
different order. This only affects applications that define such
|
||||||
|
structures directly or serialize them.
|
||||||
|
|
||||||
|
Requirement changes
|
||||||
|
* Sign-magnitude and one's complement representations for signed integers are
|
||||||
|
not supported. Two's complement is the only supported representation.
|
||||||
|
|
||||||
|
Removals
|
||||||
|
* Remove config option MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES,
|
||||||
|
which allowed SHA-1 in the default TLS configuration for certificate
|
||||||
|
signing. It was intended to facilitate the transition in environments
|
||||||
|
with SHA-1 certificates. SHA-1 is considered a weak message digest and
|
||||||
|
its use constitutes a security risk.
|
||||||
|
* Remove the partial support for running unit tests via Greentea on Mbed OS,
|
||||||
|
which had been unmaintained since 2018.
|
||||||
|
|
||||||
|
Features
|
||||||
|
* The identifier of the CID TLS extension can be configured by defining
|
||||||
|
MBEDTLS_TLS_EXT_CID at compile time.
|
||||||
|
* Warn if errors from certain functions are ignored. This is currently
|
||||||
|
supported on GCC-like compilers and on MSVC and can be configured through
|
||||||
|
the macro MBEDTLS_CHECK_RETURN. The warnings are always enabled
|
||||||
|
(where supported) for critical functions where ignoring the return
|
||||||
|
value is almost always a bug. Enable the new configuration option
|
||||||
|
MBEDTLS_CHECK_RETURN_WARNING to get warnings for other functions. This
|
||||||
|
is currently implemented in the AES, DES and md modules, and will be
|
||||||
|
extended to other modules in the future.
|
||||||
|
* Add missing PSA macros declared by PSA Crypto API 1.0.0:
|
||||||
|
PSA_ALG_IS_SIGN_HASH, PSA_ALG_NONE, PSA_HASH_BLOCK_LENGTH, PSA_KEY_ID_NULL.
|
||||||
|
* Add new API mbedtls_ct_memcmp for constant time buffer comparison.
|
||||||
|
* Add PSA API definition for ARIA.
|
||||||
|
|
||||||
|
Security
|
||||||
|
* Zeroize several intermediate variables used to calculate the expected
|
||||||
|
value when verifying a MAC or AEAD tag. This hardens the library in
|
||||||
|
case the value leaks through a memory disclosure vulnerability. For
|
||||||
|
example, a memory disclosure vulnerability could have allowed a
|
||||||
|
man-in-the-middle to inject fake ciphertext into a DTLS connection.
|
||||||
|
* In psa_cipher_generate_iv() and psa_cipher_encrypt(), do not read back
|
||||||
|
from the output buffer. This fixes a potential policy bypass or decryption
|
||||||
|
oracle vulnerability if the output buffer is in memory that is shared with
|
||||||
|
an untrusted application.
|
||||||
|
* Fix a double-free that happened after mbedtls_ssl_set_session() or
|
||||||
|
mbedtls_ssl_get_session() failed with MBEDTLS_ERR_SSL_ALLOC_FAILED
|
||||||
|
(out of memory). After that, calling mbedtls_ssl_session_free()
|
||||||
|
and mbedtls_ssl_free() would cause an internal session buffer to
|
||||||
|
be free()'d twice.
|
||||||
|
|
||||||
|
Bugfix
|
||||||
|
* Stop using reserved identifiers as local variables. Fixes #4630.
|
||||||
|
* The GNU makefiles invoke python3 in preference to python except on Windows.
|
||||||
|
The check was accidentally not performed when cross-compiling for Windows
|
||||||
|
on Linux. Fix this. Fixes #4774.
|
||||||
|
* Prevent divide by zero if either of PSA_CIPHER_ENCRYPT_OUTPUT_SIZE() or
|
||||||
|
PSA_CIPHER_UPDATE_OUTPUT_SIZE() were called using an asymmetric key type.
|
||||||
|
* Fix a parameter set but unused in psa_crypto_cipher.c. Fixes #4935.
|
||||||
|
* Don't use the obsolete header path sys/fcntl.h in unit tests.
|
||||||
|
These header files cause compilation errors in musl.
|
||||||
|
Fixes #4969.
|
||||||
|
* Fix missing constraints on x86_64 and aarch64 assembly code
|
||||||
|
for bignum multiplication that broke some bignum operations with
|
||||||
|
(at least) Clang 12.
|
||||||
|
Fixes #4116, #4786, #4917, #4962.
|
||||||
|
* Fix mbedtls_cipher_crypt: AES-ECB when MBEDTLS_USE_PSA_CRYPTO is enabled.
|
||||||
|
* Failures of alternative implementations of AES or DES single-block
|
||||||
|
functions enabled with MBEDTLS_AES_ENCRYPT_ALT, MBEDTLS_AES_DECRYPT_ALT,
|
||||||
|
MBEDTLS_DES_CRYPT_ECB_ALT or MBEDTLS_DES3_CRYPT_ECB_ALT were ignored.
|
||||||
|
This does not concern the implementation provided with Mbed TLS,
|
||||||
|
where this function cannot fail, or full-module replacements with
|
||||||
|
MBEDTLS_AES_ALT or MBEDTLS_DES_ALT. Reported by Armelle Duboc in #1092.
|
||||||
|
* Some failures of HMAC operations were ignored. These failures could only
|
||||||
|
happen with an alternative implementation of the underlying hash module.
|
||||||
|
* Fix the error returned by psa_generate_key() for a public key. Fixes #4551.
|
||||||
|
* Fix the build of sample programs when neither MBEDTLS_ERROR_C nor
|
||||||
|
MBEDTLS_ERROR_STRERROR_DUMMY is enabled.
|
||||||
|
* Fix PSA_ALG_RSA_PSS verification accepting an arbitrary salt length.
|
||||||
|
This algorithm now accepts only the same salt length for verification
|
||||||
|
that it produces when signing, as documented. Use the new algorithm
|
||||||
|
PSA_ALG_RSA_PSS_ANY_SALT to accept any salt length. Fixes #4946.
|
||||||
|
* The existing predicate macro name PSA_ALG_IS_HASH_AND_SIGN is now reserved
|
||||||
|
for algorithm values that fully encode the hashing step, as per the PSA
|
||||||
|
Crypto API specification. This excludes PSA_ALG_RSA_PKCS1V15_SIGN_RAW and
|
||||||
|
PSA_ALG_ECDSA_ANY. The new predicate macro PSA_ALG_IS_SIGN_HASH covers
|
||||||
|
all algorithms that can be used with psa_{sign,verify}_hash(), including
|
||||||
|
these two.
|
||||||
|
* Fix issue in Makefile on Linux with SHARED=1, that caused shared libraries
|
||||||
|
not to list other shared libraries they need.
|
||||||
|
* Fix a bug in mbedtls_gcm_starts() when the bit length of the iv
|
||||||
|
exceeds 2^32. Fixes #4884.
|
||||||
|
* Fix an uninitialized variable warning in test_suite_ssl.function with GCC
|
||||||
|
version 11.
|
||||||
|
* Fix the build when no SHA2 module is included. Fixes #4930.
|
||||||
|
* Fix the build when only the bignum module is included. Fixes #4929.
|
||||||
|
* Fix a potential invalid pointer dereference and infinite loop bugs in
|
||||||
|
pkcs12 functions when the password is empty. Fix the documentation to
|
||||||
|
better describe the inputs to these functions and their possible values.
|
||||||
|
Fixes #5136.
|
||||||
|
* The key usage flags PSA_KEY_USAGE_SIGN_MESSAGE now allows the MAC
|
||||||
|
operations psa_mac_compute() and psa_mac_sign_setup().
|
||||||
|
* The key usage flags PSA_KEY_USAGE_VERIFY_MESSAGE now allows the MAC
|
||||||
|
operations psa_mac_verify() and psa_mac_verify_setup().
|
||||||
|
|
||||||
|
Changes
|
||||||
|
* Set config option MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE to be
|
||||||
|
disabled by default.
|
||||||
|
* Improve the performance of base64 constant-flow code. The result is still
|
||||||
|
slower than the original non-constant-flow implementation, but much faster
|
||||||
|
than the previous constant-flow implementation. Fixes #4814.
|
||||||
|
* Indicate in the error returned if the nonce length used with
|
||||||
|
ChaCha20-Poly1305 is invalid, and not just unsupported.
|
||||||
|
* The mbedcrypto library includes a new source code module constant_time.c,
|
||||||
|
containing various functions meant to resist timing side channel attacks.
|
||||||
|
This module does not have a separate configuration option, and functions
|
||||||
|
from this module will be included in the build as required. Currently
|
||||||
|
most of the interface of this module is private and may change at any
|
||||||
|
time.
|
||||||
|
|
||||||
= mbed TLS 2.27.0 branch released 2021-07-07
|
= mbed TLS 2.27.0 branch released 2021-07-07
|
||||||
|
|
||||||
API changes
|
API changes
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
Changes
|
|
||||||
* Improve the performance of base64 constant-flow code. The result is still
|
|
||||||
slower than the original non-constant-flow implementation, but much faster
|
|
||||||
than the previous constant-flow implementation. Fixes #4814.
|
|
|
@ -1,4 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix a bug in mbedtls_gcm_starts() when bits of iv are longer than 2^32.
|
|
||||||
* Fix #4884.
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
Changes
|
|
||||||
* Indicate in the error returned if the nonce length used with
|
|
||||||
ChaCha20-Poly1305 is invalid, and not just unsupported.
|
|
|
@ -1,17 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Failures of alternative implementations of AES or DES single-block
|
|
||||||
functions enabled with MBEDTLS_AES_ENCRYPT_ALT, MBEDTLS_AES_DECRYPT_ALT,
|
|
||||||
MBEDTLS_DES_CRYPT_ECB_ALT or MBEDTLS_DES3_CRYPT_ECB_ALT were ignored.
|
|
||||||
This does not concern the implementation provided with Mbed TLS,
|
|
||||||
where this function cannot fail, or full-module replacements with
|
|
||||||
MBEDTLS_AES_ALT or MBEDTLS_DES_ALT. Reported by Armelle Duboc in #1092.
|
|
||||||
|
|
||||||
Features
|
|
||||||
* Warn if errors from certain functions are ignored. This is currently
|
|
||||||
supported on GCC-like compilers and on MSVC and can be configured through
|
|
||||||
the macro MBEDTLS_CHECK_RETURN. The warnings are always enabled
|
|
||||||
(where supported) for critical functions where ignoring the return
|
|
||||||
value is almost always a bug. Enable the new configuration option
|
|
||||||
MBEDTLS_CHECK_RETURN_WARNING to get warnings for other functions. This
|
|
||||||
is currently implemented in the AES and DES modules, and will be extended
|
|
||||||
to other modules in the future.
|
|
|
@ -1,10 +0,0 @@
|
||||||
Changes
|
|
||||||
* The mbedcrypto library includes a new source code module constant_time.c,
|
|
||||||
containing various functions meant to resist timing side channel attacks.
|
|
||||||
This module does not have a separate configuration option, and functions
|
|
||||||
from this module will be included in the build as required. Currently
|
|
||||||
most of the interface of this module is private and may change at any
|
|
||||||
time.
|
|
||||||
|
|
||||||
Features
|
|
||||||
* Add new API mbedtls_ct_memcmp for constant time buffer comparison.
|
|
|
@ -1,5 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Don't use the obsolete header path sys/fcntl.h in unit tests.
|
|
||||||
These header files cause compilation errors in musl.
|
|
||||||
Fixes #4969.
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
Security
|
|
||||||
* In psa_cipher_generate_iv() and psa_cipher_encrypt(), do not read back
|
|
||||||
from the output buffer. This fixes a potential policy bypass or decryption
|
|
||||||
oracle vulnerability if the output buffer is in memory that is shared with
|
|
||||||
an untrusted application.
|
|
|
@ -1,4 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Prevent divide by zero if either of PSA_CIPHER_ENCRYPT_OUTPUT_SIZE() or
|
|
||||||
PSA_CIPHER_UPDATE_OUTPUT_SIZE() were called using an asymmetric key type.
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix mbedtls_cipher_crypt: AES-ECB when MBEDTLS_USE_PSA_CRYPTO is enabled.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix issue in Makefile on Linux with SHARED=1, that caused shared libraries
|
|
||||||
not to list other shared libraries they need.
|
|
|
@ -1,2 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix the error returned by psa_generate_key() for a public key. Fixes #4551.
|
|
|
@ -1,6 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix a double-free that happened after mbedtls_ssl_set_session() or
|
|
||||||
mbedtls_ssl_get_session() failed with MBEDTLS_ERR_SSL_ALLOC_FAILED
|
|
||||||
(out of memory). After that, calling mbedtls_ssl_session_free()
|
|
||||||
and mbedtls_ssl_free() would cause an internal session buffer to
|
|
||||||
be free()'d twice.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix an uninitialized variable warning in test_suite_ssl.function with GCC
|
|
||||||
version 11.
|
|
|
@ -1,2 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Stop using reserved identifiers as local variables. Fixes #4630.
|
|
|
@ -1,4 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* The GNU makefiles invoke python3 in preference to python except on Windows.
|
|
||||||
The check was accidentally not performed when cross-compiling for Windows
|
|
||||||
on Linux. Fix this. Fixes #4774.
|
|
|
@ -1,5 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix missing constraints on x86_64 and aarch64 assembly code
|
|
||||||
for bignum multiplication that broke some bignum operations with
|
|
||||||
(at least) Clang 12.
|
|
||||||
Fixes #4116, #4786, #4917, #4962.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix the build of sample programs when neither MBEDTLS_ERROR_C nor
|
|
||||||
MBEDTLS_ERROR_STRERROR_DUMMY is enabled.
|
|
|
@ -1,5 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix PSA_ALG_RSA_PSS verification accepting an arbitrary salt length.
|
|
||||||
This algorithm now accepts only the same salt length for verification
|
|
||||||
that it produces when signing, as documented. Use the new algorithm
|
|
||||||
PSA_ALG_RSA_PSS_ANY_SALT to accept any salt length. Fixes #4946.
|
|
|
@ -1,2 +0,0 @@
|
||||||
Bugfix
|
|
||||||
* Fix a parameter set but unused in psa_crypto_cipher.c. Fixes #4935.
|
|
|
@ -1,11 +0,0 @@
|
||||||
Features
|
|
||||||
* Add missing PSA macros declared by PSA Crypto API 1.0.0:
|
|
||||||
PSA_ALG_IS_SIGN_HASH, PSA_ALG_NONE, PSA_HASH_BLOCK_LENGTH, PSA_KEY_ID_NULL.
|
|
||||||
|
|
||||||
Bugfix
|
|
||||||
* The existing predicate macro name PSA_ALG_IS_HASH_AND_SIGN is now reserved
|
|
||||||
for algorithm values that fully encode the hashing step, as per the PSA
|
|
||||||
Crypto API specification. This excludes PSA_ALG_RSA_PKCS1V15_SIGN_RAW and
|
|
||||||
PSA_ALG_ECDSA_ANY. The new predicate macro PSA_ALG_IS_SIGN_HASH covers
|
|
||||||
all algorithms that can be used with psa_{sign,verify}_hash(), including
|
|
||||||
these two.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Removals
|
|
||||||
* Remove the partial support for running unit tests via Greentea on Mbed OS,
|
|
||||||
which had been unmaintained since 2018.
|
|
|
@ -1,10 +0,0 @@
|
||||||
Removals
|
|
||||||
* Remove config option MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES,
|
|
||||||
which allowed SHA-1 in the default TLS configuration for certificate
|
|
||||||
signing. It was intended to facilitate the transition in environments
|
|
||||||
with SHA-1 certificates. SHA-1 is considered a weak message digest and
|
|
||||||
its use constitutes a security risk.
|
|
||||||
|
|
||||||
Changes
|
|
||||||
* Set config option MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE to be
|
|
||||||
disabled by default.
|
|
|
@ -1,3 +0,0 @@
|
||||||
Features
|
|
||||||
* The identifier of the CID TLS extension can be configured by defining
|
|
||||||
MBEDTLS_TLS_EXT_CID at compile time.
|
|
|
@ -197,6 +197,14 @@ Mbed TLS can be ported to many different architectures, OS's and platforms. Befo
|
||||||
- [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on)
|
- [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on)
|
||||||
- [How do I configure Mbed TLS](https://tls.mbed.org/kb/compiling-and-building/how-do-i-configure-mbedtls)
|
- [How do I configure Mbed TLS](https://tls.mbed.org/kb/compiling-and-building/how-do-i-configure-mbedtls)
|
||||||
|
|
||||||
|
Mbed TLS is mostly written in portable C99; however, it has a few platform requirements that go beyond the standard, but are met by most modern architectures:
|
||||||
|
|
||||||
|
- Bytes must be 8 bits.
|
||||||
|
- All-bits-zero must be a valid representation of a null pointer.
|
||||||
|
- Signed integers must be represented using two's complement.
|
||||||
|
- `int` and `size_t` must be at least 32 bits wide.
|
||||||
|
- The types `uint8_t`, `uint16_t`, `uint32_t` and their signed equivalents must be available.
|
||||||
|
|
||||||
PSA cryptography API
|
PSA cryptography API
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mainpage mbed TLS v2.27.0 source code documentation
|
* @mainpage mbed TLS v2.28.0 source code documentation
|
||||||
*
|
*
|
||||||
* This documentation describes the internal structure of mbed TLS. It was
|
* This documentation describes the internal structure of mbed TLS. It was
|
||||||
* automatically generated from specially formatted comment blocks in
|
* automatically generated from specially formatted comment blocks in
|
||||||
|
|
|
@ -28,7 +28,7 @@ DOXYFILE_ENCODING = UTF-8
|
||||||
# identify the project. Note that if you do not use Doxywizard you need
|
# identify the project. Note that if you do not use Doxywizard you need
|
||||||
# to put quotes around the project name if it contains spaces.
|
# to put quotes around the project name if it contains spaces.
|
||||||
|
|
||||||
PROJECT_NAME = "mbed TLS v2.27.0"
|
PROJECT_NAME = "mbed TLS v2.28.0"
|
||||||
|
|
||||||
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
|
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
|
||||||
# This could be handy for archiving the generated documentation or
|
# This could be handy for archiving the generated documentation or
|
||||||
|
|
|
@ -74,9 +74,17 @@ struct mbedtls_cmac_context_t
|
||||||
#endif /* !MBEDTLS_CMAC_ALT */
|
#endif /* !MBEDTLS_CMAC_ALT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function sets the CMAC key, and prepares to authenticate
|
* \brief This function starts a new CMAC computation
|
||||||
|
* by setting the CMAC key, and preparing to authenticate
|
||||||
* the input data.
|
* the input data.
|
||||||
* Must be called with an initialized cipher context.
|
* It must be called with an initialized cipher context.
|
||||||
|
*
|
||||||
|
* Once this function has completed, data can be supplied
|
||||||
|
* to the CMAC computation by calling
|
||||||
|
* mbedtls_cipher_cmac_update().
|
||||||
|
*
|
||||||
|
* To start a CMAC computation using the same key as a previous
|
||||||
|
* CMAC computation, use mbedtls_cipher_cmac_finish().
|
||||||
*
|
*
|
||||||
* \note When the CMAC implementation is supplied by an alternate
|
* \note When the CMAC implementation is supplied by an alternate
|
||||||
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
||||||
|
@ -102,9 +110,15 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||||
* \brief This function feeds an input buffer into an ongoing CMAC
|
* \brief This function feeds an input buffer into an ongoing CMAC
|
||||||
* computation.
|
* computation.
|
||||||
*
|
*
|
||||||
* It is called between mbedtls_cipher_cmac_starts() or
|
* The CMAC computation must have previously been started
|
||||||
* mbedtls_cipher_cmac_reset(), and mbedtls_cipher_cmac_finish().
|
* by calling mbedtls_cipher_cmac_starts() or
|
||||||
* Can be called repeatedly.
|
* mbedtls_cipher_cmac_reset().
|
||||||
|
*
|
||||||
|
* Call this function as many times as needed to input the
|
||||||
|
* data to be authenticated.
|
||||||
|
* Once all of the required data has been input,
|
||||||
|
* call mbedtls_cipher_cmac_finish() to obtain the result
|
||||||
|
* of the CMAC operation.
|
||||||
*
|
*
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
* \param ctx The cipher context used for the CMAC operation.
|
||||||
* \param input The buffer holding the input data.
|
* \param input The buffer holding the input data.
|
||||||
|
@ -118,12 +132,13 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||||
const unsigned char *input, size_t ilen );
|
const unsigned char *input, size_t ilen );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function finishes the CMAC operation, and writes
|
* \brief This function finishes an ongoing CMAC operation, and
|
||||||
* the result to the output buffer.
|
* writes the result to the output buffer.
|
||||||
*
|
*
|
||||||
* It is called after mbedtls_cipher_cmac_update().
|
* It should be followed either by
|
||||||
* It can be followed by mbedtls_cipher_cmac_reset() and
|
* mbedtls_cipher_cmac_reset(), which starts another CMAC
|
||||||
* mbedtls_cipher_cmac_update(), or mbedtls_cipher_free().
|
* operation with the same key, or mbedtls_cipher_free(),
|
||||||
|
* which clears the cipher context.
|
||||||
*
|
*
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
* \param ctx The cipher context used for the CMAC operation.
|
||||||
* \param output The output buffer for the CMAC checksum result.
|
* \param output The output buffer for the CMAC checksum result.
|
||||||
|
@ -136,12 +151,14 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||||
unsigned char *output );
|
unsigned char *output );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function prepares the authentication of another
|
* \brief This function starts a new CMAC operation with the same
|
||||||
* message with the same key as the previous CMAC
|
* key as the previous one.
|
||||||
* operation.
|
|
||||||
*
|
*
|
||||||
* It is called after mbedtls_cipher_cmac_finish()
|
* It should be called after finishing the previous CMAC
|
||||||
* and before mbedtls_cipher_cmac_update().
|
* operation with mbedtls_cipher_cmac_finish().
|
||||||
|
* After calling this function,
|
||||||
|
* call mbedtls_cipher_cmac_update() to supply the new
|
||||||
|
* CMAC operation with data.
|
||||||
*
|
*
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
* \param ctx The cipher context used for the CMAC operation.
|
||||||
*
|
*
|
||||||
|
|
|
@ -93,6 +93,10 @@ extern "C" {
|
||||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
|
#if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
|
||||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
|
#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
|
||||||
#define MBEDTLS_ECDSA_C
|
#define MBEDTLS_ECDSA_C
|
||||||
|
#define MBEDTLS_ECP_C
|
||||||
|
#define MBEDTLS_BIGNUM_C
|
||||||
|
#define MBEDTLS_ASN1_PARSE_C
|
||||||
|
#define MBEDTLS_ASN1_WRITE_C
|
||||||
#endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDSA */
|
#endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDSA */
|
||||||
#endif /* PSA_WANT_ALG_ECDSA */
|
#endif /* PSA_WANT_ALG_ECDSA */
|
||||||
|
|
||||||
|
@ -235,6 +239,8 @@ extern "C" {
|
||||||
#define MBEDTLS_PK_PARSE_C
|
#define MBEDTLS_PK_PARSE_C
|
||||||
#define MBEDTLS_PK_WRITE_C
|
#define MBEDTLS_PK_WRITE_C
|
||||||
#define MBEDTLS_PK_C
|
#define MBEDTLS_PK_C
|
||||||
|
#define MBEDTLS_ASN1_PARSE_C
|
||||||
|
#define MBEDTLS_ASN1_WRITE_C
|
||||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR */
|
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR */
|
||||||
#endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR */
|
#endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR */
|
||||||
|
|
||||||
|
@ -247,6 +253,8 @@ extern "C" {
|
||||||
#define MBEDTLS_PK_PARSE_C
|
#define MBEDTLS_PK_PARSE_C
|
||||||
#define MBEDTLS_PK_WRITE_C
|
#define MBEDTLS_PK_WRITE_C
|
||||||
#define MBEDTLS_PK_C
|
#define MBEDTLS_PK_C
|
||||||
|
#define MBEDTLS_ASN1_PARSE_C
|
||||||
|
#define MBEDTLS_ASN1_WRITE_C
|
||||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY */
|
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY */
|
||||||
#endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */
|
#endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */
|
||||||
|
|
||||||
|
@ -435,10 +443,12 @@ extern "C" {
|
||||||
#endif /* PSA_WANT_ALG_GCM */
|
#endif /* PSA_WANT_ALG_GCM */
|
||||||
|
|
||||||
#if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
|
#if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
|
||||||
|
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305)
|
||||||
#if defined(PSA_WANT_KEY_TYPE_CHACHA20)
|
#if defined(PSA_WANT_KEY_TYPE_CHACHA20)
|
||||||
#define MBEDTLS_CHACHAPOLY_C
|
#define MBEDTLS_CHACHAPOLY_C
|
||||||
#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1
|
#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1
|
||||||
#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
|
#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
|
||||||
|
#endif /* !MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 */
|
||||||
#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
|
#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
|
||||||
|
|
||||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||||
|
|
|
@ -130,7 +130,7 @@ typedef struct mbedtls_entropy_context
|
||||||
* -1 after free. */
|
* -1 after free. */
|
||||||
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
||||||
mbedtls_sha512_context accumulator;
|
mbedtls_sha512_context accumulator;
|
||||||
#else
|
#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
|
||||||
mbedtls_sha256_context accumulator;
|
mbedtls_sha256_context accumulator;
|
||||||
#endif
|
#endif
|
||||||
int source_count; /* Number of entries used in source. */
|
int source_count; /* Number of entries used in source. */
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#else
|
#else
|
||||||
#include MBEDTLS_CONFIG_FILE
|
#include MBEDTLS_CONFIG_FILE
|
||||||
#endif
|
#endif
|
||||||
|
#include "mbedtls/platform_util.h"
|
||||||
|
|
||||||
/** The selected feature is not available. */
|
/** The selected feature is not available. */
|
||||||
#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
|
#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
|
||||||
|
@ -210,6 +211,7 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_
|
||||||
* failure.
|
* failure.
|
||||||
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
|
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
|
int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,6 +233,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure.
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_clone( mbedtls_md_context_t *dst,
|
int mbedtls_md_clone( mbedtls_md_context_t *dst,
|
||||||
const mbedtls_md_context_t *src );
|
const mbedtls_md_context_t *src );
|
||||||
|
|
||||||
|
@ -280,6 +283,7 @@ const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -298,6 +302,7 @@ int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
|
int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,6 +323,7 @@ int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, si
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
|
int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -338,6 +344,7 @@ int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
|
int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
|
||||||
unsigned char *output );
|
unsigned char *output );
|
||||||
|
|
||||||
|
@ -359,6 +366,7 @@ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, si
|
||||||
* the file pointed by \p path.
|
* the file pointed by \p path.
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
|
int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
|
||||||
unsigned char *output );
|
unsigned char *output );
|
||||||
#endif /* MBEDTLS_FS_IO */
|
#endif /* MBEDTLS_FS_IO */
|
||||||
|
@ -381,6 +389,7 @@ int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
|
int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
|
||||||
size_t keylen );
|
size_t keylen );
|
||||||
|
|
||||||
|
@ -403,6 +412,7 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
|
int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
|
||||||
size_t ilen );
|
size_t ilen );
|
||||||
|
|
||||||
|
@ -424,6 +434,7 @@ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *inpu
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
|
int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,6 +452,7 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -465,11 +477,13 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
|
int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
|
||||||
const unsigned char *input, size_t ilen,
|
const unsigned char *input, size_t ilen,
|
||||||
unsigned char *output );
|
unsigned char *output );
|
||||||
|
|
||||||
/* Internal use */
|
/* Internal use */
|
||||||
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
|
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -80,10 +80,12 @@ int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
|
||||||
* for cipher-based and mbedtls_md-based PBE's
|
* for cipher-based and mbedtls_md-based PBE's
|
||||||
*
|
*
|
||||||
* \param pbe_params an ASN1 buffer containing the pkcs-12 PbeParams structure
|
* \param pbe_params an ASN1 buffer containing the pkcs-12 PbeParams structure
|
||||||
* \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
|
* \param mode either #MBEDTLS_PKCS12_PBE_ENCRYPT or
|
||||||
|
* #MBEDTLS_PKCS12_PBE_DECRYPT
|
||||||
* \param cipher_type the cipher used
|
* \param cipher_type the cipher used
|
||||||
* \param md_type the mbedtls_md used
|
* \param md_type the mbedtls_md used
|
||||||
* \param pwd the password used (may be NULL if no password is used)
|
* \param pwd Latin1-encoded password used. This may only be \c NULL when
|
||||||
|
* \p pwdlen is 0. No null terminator should be used.
|
||||||
* \param pwdlen length of the password (may be 0)
|
* \param pwdlen length of the password (may be 0)
|
||||||
* \param input the input data
|
* \param input the input data
|
||||||
* \param len data length
|
* \param len data length
|
||||||
|
@ -104,18 +106,24 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
|
||||||
* to produce pseudo-random bits for a particular "purpose".
|
* to produce pseudo-random bits for a particular "purpose".
|
||||||
*
|
*
|
||||||
* Depending on the given id, this function can produce an
|
* Depending on the given id, this function can produce an
|
||||||
* encryption/decryption key, an nitialization vector or an
|
* encryption/decryption key, an initialization vector or an
|
||||||
* integrity key.
|
* integrity key.
|
||||||
*
|
*
|
||||||
* \param data buffer to store the derived data in
|
* \param data buffer to store the derived data in
|
||||||
* \param datalen length to fill
|
* \param datalen length of buffer to fill
|
||||||
* \param pwd password to use (may be NULL if no password is used)
|
* \param pwd The password to use. For compliance with PKCS#12 §B.1, this
|
||||||
* \param pwdlen length of the password (may be 0)
|
* should be a BMPString, i.e. a Unicode string where each
|
||||||
* \param salt salt buffer to use
|
* character is encoded as 2 bytes in big-endian order, with
|
||||||
* \param saltlen length of the salt
|
* no byte order mark and with a null terminator (i.e. the
|
||||||
|
* last two bytes should be 0x00 0x00).
|
||||||
|
* \param pwdlen length of the password (may be 0).
|
||||||
|
* \param salt Salt buffer to use This may only be \c NULL when
|
||||||
|
* \p saltlen is 0.
|
||||||
|
* \param saltlen length of the salt (may be zero)
|
||||||
* \param mbedtls_md mbedtls_md type to use during the derivation
|
* \param mbedtls_md mbedtls_md type to use during the derivation
|
||||||
* \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
|
* \param id id that describes the purpose (can be
|
||||||
* MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
|
* #MBEDTLS_PKCS12_DERIVE_KEY, #MBEDTLS_PKCS12_DERIVE_IV or
|
||||||
|
* #MBEDTLS_PKCS12_DERIVE_MAC_KEY)
|
||||||
* \param iterations number of iterations
|
* \param iterations number of iterations
|
||||||
*
|
*
|
||||||
* \return 0 if successful, or a MD, BIGNUM type error.
|
* \return 0 if successful, or a MD, BIGNUM type error.
|
||||||
|
|
|
@ -974,6 +974,10 @@ mbedtls_dtls_srtp_info;
|
||||||
*/
|
*/
|
||||||
struct mbedtls_ssl_session
|
struct mbedtls_ssl_session
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||||
|
unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
|
||||||
|
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME)
|
#if defined(MBEDTLS_HAVE_TIME)
|
||||||
mbedtls_time_t start; /*!< starting time */
|
mbedtls_time_t start; /*!< starting time */
|
||||||
#endif
|
#endif
|
||||||
|
@ -1002,10 +1006,6 @@ struct mbedtls_ssl_session
|
||||||
uint32_t ticket_lifetime; /*!< ticket lifetime hint */
|
uint32_t ticket_lifetime; /*!< ticket lifetime hint */
|
||||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
|
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
|
||||||
unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
|
|
||||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||||
int trunc_hmac; /*!< flag for truncated hmac activation */
|
int trunc_hmac; /*!< flag for truncated hmac activation */
|
||||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||||
|
@ -1020,7 +1020,98 @@ struct mbedtls_ssl_session
|
||||||
*/
|
*/
|
||||||
struct mbedtls_ssl_config
|
struct mbedtls_ssl_config
|
||||||
{
|
{
|
||||||
/* Group items by size (largest first) to minimize padding overhead */
|
/* Group items by size and reorder them to maximize usage of immediate offset access. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Numerical settings (char)
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned char max_major_ver; /*!< max. major version used */
|
||||||
|
unsigned char max_minor_ver; /*!< max. minor version used */
|
||||||
|
unsigned char min_major_ver; /*!< min. major version used */
|
||||||
|
unsigned char min_minor_ver; /*!< min. minor version used */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flags (could be bit-fields to save RAM, but separate bytes make
|
||||||
|
* the code smaller on architectures with an instruction for direct
|
||||||
|
* byte access).
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint8_t endpoint /*bool*/; /*!< 0: client, 1: server */
|
||||||
|
uint8_t transport /*bool*/; /*!< stream (TLS) or datagram (DTLS) */
|
||||||
|
uint8_t authmode /*2 bits*/; /*!< MBEDTLS_SSL_VERIFY_XXX */
|
||||||
|
/* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
|
||||||
|
uint8_t allow_legacy_renegotiation /*2 bits*/; /*!< MBEDTLS_LEGACY_XXX */
|
||||||
|
#if defined(MBEDTLS_ARC4_C)
|
||||||
|
uint8_t arc4_disabled /*bool*/; /*!< blacklist RC4 ciphersuites? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
||||||
|
uint8_t mfl_code /*3 bits*/; /*!< desired fragment length */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||||
|
uint8_t encrypt_then_mac /*bool*/; /*!< negotiate encrypt-then-mac? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
||||||
|
uint8_t extended_ms /*bool*/; /*!< negotiate extended master secret? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
||||||
|
uint8_t anti_replay /*bool*/; /*!< detect and prevent replay? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
|
||||||
|
uint8_t cbc_record_splitting /*bool*/; /*!< do cbc record splitting */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||||
|
uint8_t disable_renegotiation /*bool*/; /*!< disable renegotiation? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||||
|
uint8_t trunc_hmac /*bool*/; /*!< negotiate truncated hmac? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||||
|
uint8_t session_tickets /*bool*/; /*!< use session tickets? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
|
||||||
|
uint8_t fallback /*bool*/; /*!< is this a fallback? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_SRV_C)
|
||||||
|
uint8_t cert_req_ca_list /*bool*/; /*!< enable sending CA list in
|
||||||
|
Certificate Request messages? */
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||||
|
uint8_t ignore_unexpected_cid /*bool*/; /*!< Determines whether DTLS
|
||||||
|
* record with unexpected CID
|
||||||
|
* should lead to failure. */
|
||||||
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_SRTP)
|
||||||
|
uint8_t dtls_srtp_mki_support /*bool*/; /*!< support having mki_value
|
||||||
|
in the use_srtp extension? */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Numerical settings (int or larger)
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||||
|
uint32_t hs_timeout_min; /*!< initial value of the handshake
|
||||||
|
retransmission timeout (ms) */
|
||||||
|
uint32_t hs_timeout_max; /*!< maximum value of the handshake
|
||||||
|
retransmission timeout (ms) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||||
|
int renego_max_records; /*!< grace period for renegotiation */
|
||||||
|
unsigned char renego_period[8]; /*!< value of the record counters
|
||||||
|
that triggers renegotiation */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
|
||||||
|
unsigned int badmac_limit; /*!< limit of records with a bad MAC */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
|
||||||
|
unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pointers
|
* Pointers
|
||||||
|
@ -1174,91 +1265,6 @@ struct mbedtls_ssl_config
|
||||||
/*! number of supported profiles */
|
/*! number of supported profiles */
|
||||||
size_t dtls_srtp_profile_list_len;
|
size_t dtls_srtp_profile_list_len;
|
||||||
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
#endif /* MBEDTLS_SSL_DTLS_SRTP */
|
||||||
|
|
||||||
/*
|
|
||||||
* Numerical settings (int then char)
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
||||||
uint32_t hs_timeout_min; /*!< initial value of the handshake
|
|
||||||
retransmission timeout (ms) */
|
|
||||||
uint32_t hs_timeout_max; /*!< maximum value of the handshake
|
|
||||||
retransmission timeout (ms) */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
|
||||||
int renego_max_records; /*!< grace period for renegotiation */
|
|
||||||
unsigned char renego_period[8]; /*!< value of the record counters
|
|
||||||
that triggers renegotiation */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
|
|
||||||
unsigned int badmac_limit; /*!< limit of records with a bad MAC */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
|
|
||||||
unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned char max_major_ver; /*!< max. major version used */
|
|
||||||
unsigned char max_minor_ver; /*!< max. minor version used */
|
|
||||||
unsigned char min_major_ver; /*!< min. major version used */
|
|
||||||
unsigned char min_minor_ver; /*!< min. minor version used */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Flags (bitfields)
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned int endpoint : 1; /*!< 0: client, 1: server */
|
|
||||||
unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */
|
|
||||||
unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */
|
|
||||||
/* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
|
|
||||||
unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */
|
|
||||||
#if defined(MBEDTLS_ARC4_C)
|
|
||||||
unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
|
||||||
unsigned int mfl_code : 3; /*!< desired fragment length */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
|
||||||
unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
|
||||||
unsigned int extended_ms : 1; /*!< negotiate extended master secret? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
|
||||||
unsigned int anti_replay : 1; /*!< detect and prevent replay? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
|
|
||||||
unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
|
||||||
unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
|
||||||
unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
|
||||||
unsigned int session_tickets : 1; /*!< use session tickets? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
|
|
||||||
unsigned int fallback : 1; /*!< is this a fallback? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_SRV_C)
|
|
||||||
unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in
|
|
||||||
Certificate Request messages? */
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
|
||||||
unsigned int ignore_unexpected_cid : 1; /*!< Determines whether DTLS
|
|
||||||
* record with unexpected CID
|
|
||||||
* should lead to failure. */
|
|
||||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_SRTP)
|
|
||||||
unsigned int dtls_srtp_mki_support : 1; /* support having mki_value
|
|
||||||
in the use_srtp extension */
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mbedtls_ssl_context
|
struct mbedtls_ssl_context
|
||||||
|
|
|
@ -430,13 +430,63 @@ struct mbedtls_ssl_handshake_params
|
||||||
* Handshake specific crypto variables
|
* Handshake specific crypto variables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
uint8_t max_major_ver; /*!< max. major version client*/
|
||||||
|
uint8_t max_minor_ver; /*!< max. minor version client*/
|
||||||
|
uint8_t resume; /*!< session resume indicator*/
|
||||||
|
uint8_t cli_exts; /*!< client extension presence*/
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
|
defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
||||||
|
uint8_t sni_authmode; /*!< authmode from SNI callback */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||||
|
uint8_t new_session_ticket; /*!< use NewSessionTicket? */
|
||||||
|
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
||||||
|
uint8_t extended_ms; /*!< use Extended Master Secret? */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||||
|
uint8_t async_in_progress; /*!< an asynchronous operation is in progress */
|
||||||
|
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||||
|
unsigned char retransmit_state; /*!< Retransmission state */
|
||||||
|
#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 */
|
||||||
|
ssl_ecrs_none = 0, /*!< nothing going on (yet) */
|
||||||
|
ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */
|
||||||
|
ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */
|
||||||
|
ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
|
||||||
|
ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
|
||||||
|
} ecrs_state; /*!< current (or last) operation */
|
||||||
|
mbedtls_x509_crt *ecrs_peer_cert; /*!< The peer's CRT chain. */
|
||||||
|
size_t ecrs_n; /*!< place for saving a length */
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
||||||
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
||||||
mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
|
mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
size_t pmslen; /*!< premaster length */
|
||||||
|
|
||||||
|
mbedtls_ssl_ciphersuite_t const *ciphersuite_info;
|
||||||
|
|
||||||
|
void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
|
||||||
|
void (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *);
|
||||||
|
void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
|
||||||
|
mbedtls_ssl_tls_prf_cb *tls_prf;
|
||||||
|
|
||||||
#if defined(MBEDTLS_DHM_C)
|
#if defined(MBEDTLS_DHM_C)
|
||||||
mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
|
mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
|
/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
|
||||||
* to guards also being in ssl_srv.c and ssl_cli.c. There is a gap
|
* to guards also being in ssl_srv.c and ssl_cli.c. There is a gap
|
||||||
* in functionality that access to ecdh_ctx structure is needed for
|
* in functionality that access to ecdh_ctx structure is needed for
|
||||||
|
@ -461,10 +511,12 @@ struct mbedtls_ssl_handshake_params
|
||||||
size_t ecjpake_cache_len; /*!< Length of cached data */
|
size_t ecjpake_cache_len; /*!< Length of cached data */
|
||||||
#endif
|
#endif
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
||||||
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
||||||
const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
|
const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
psa_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
|
psa_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
|
||||||
|
@ -472,65 +524,26 @@ struct mbedtls_ssl_handshake_params
|
||||||
unsigned char *psk; /*!< PSK from the callback */
|
unsigned char *psk; /*!< PSK from the callback */
|
||||||
size_t psk_len; /*!< Length of PSK from callback */
|
size_t psk_len; /*!< Length of PSK from callback */
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
|
mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
|
||||||
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
||||||
int sni_authmode; /*!< authmode from SNI callback */
|
|
||||||
mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
|
mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
|
||||||
mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
|
mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
|
||||||
mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
|
mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
|
||||||
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
||||||
int ecrs_enabled; /*!< Handshake supports EC restart? */
|
|
||||||
mbedtls_x509_crt_restart_ctx ecrs_ctx; /*!< restart context */
|
mbedtls_x509_crt_restart_ctx ecrs_ctx; /*!< restart context */
|
||||||
enum { /* this complements ssl->state with info on intra-state operations */
|
|
||||||
ssl_ecrs_none = 0, /*!< nothing going on (yet) */
|
|
||||||
ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */
|
|
||||||
ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */
|
|
||||||
ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
|
|
||||||
ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
|
|
||||||
} ecrs_state; /*!< current (or last) operation */
|
|
||||||
mbedtls_x509_crt *ecrs_peer_cert; /*!< The peer's CRT chain. */
|
|
||||||
size_t ecrs_n; /*!< place for saving a length */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */
|
mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||||
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
|
||||||
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
|
||||||
|
|
||||||
unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
|
|
||||||
Srv: unused */
|
|
||||||
unsigned char verify_cookie_len; /*!< Cli: cookie length
|
|
||||||
Srv: flag for sending a cookie */
|
|
||||||
|
|
||||||
uint32_t retransmit_timeout; /*!< Current value of timeout */
|
|
||||||
unsigned char retransmit_state; /*!< Retransmission state */
|
|
||||||
mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
|
|
||||||
mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
|
|
||||||
unsigned char *cur_msg_p; /*!< Position in current message */
|
|
||||||
unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
|
|
||||||
flight being received */
|
|
||||||
mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
|
|
||||||
resending messages */
|
|
||||||
unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
|
|
||||||
for resending messages */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
|
||||||
/* The state of CID configuration in this handshake. */
|
|
||||||
|
|
||||||
uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension
|
|
||||||
* has been negotiated. Possible values are
|
|
||||||
* #MBEDTLS_SSL_CID_ENABLED and
|
|
||||||
* #MBEDTLS_SSL_CID_DISABLED. */
|
|
||||||
unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; /*! The peer's CID */
|
|
||||||
uint8_t peer_cid_len; /*!< The length of
|
|
||||||
* \c peer_cid. */
|
|
||||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
|
size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
|
||||||
|
@ -557,6 +570,37 @@ struct mbedtls_ssl_handshake_params
|
||||||
|
|
||||||
} buffering;
|
} buffering;
|
||||||
|
|
||||||
|
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
||||||
|
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
||||||
|
|
||||||
|
unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
|
||||||
|
Srv: unused */
|
||||||
|
unsigned char verify_cookie_len; /*!< Cli: cookie length
|
||||||
|
Srv: flag for sending a cookie */
|
||||||
|
|
||||||
|
uint32_t retransmit_timeout; /*!< Current value of timeout */
|
||||||
|
mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
|
||||||
|
mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
|
||||||
|
unsigned char *cur_msg_p; /*!< Position in current message */
|
||||||
|
unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
|
||||||
|
flight being received */
|
||||||
|
mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
|
||||||
|
resending messages */
|
||||||
|
unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
|
||||||
|
for resending messages */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||||
|
/* The state of CID configuration in this handshake. */
|
||||||
|
|
||||||
|
uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension
|
||||||
|
* has been negotiated. Possible values are
|
||||||
|
* #MBEDTLS_SSL_CID_ENABLED and
|
||||||
|
* #MBEDTLS_SSL_CID_DISABLED. */
|
||||||
|
unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ]; /*! The peer's CID */
|
||||||
|
uint8_t peer_cid_len; /*!< The length of
|
||||||
|
* \c peer_cid. */
|
||||||
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||||
|
|
||||||
uint16_t mtu; /*!< Handshake mtu, used to fragment outgoing messages */
|
uint16_t mtu; /*!< Handshake mtu, used to fragment outgoing messages */
|
||||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||||
|
|
||||||
|
@ -585,35 +629,10 @@ struct mbedtls_ssl_handshake_params
|
||||||
#endif
|
#endif
|
||||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||||
|
|
||||||
void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
|
|
||||||
void (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *);
|
|
||||||
void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
|
|
||||||
mbedtls_ssl_tls_prf_cb *tls_prf;
|
|
||||||
|
|
||||||
mbedtls_ssl_ciphersuite_t const *ciphersuite_info;
|
|
||||||
|
|
||||||
size_t pmslen; /*!< premaster length */
|
|
||||||
|
|
||||||
unsigned char randbytes[64]; /*!< random bytes */
|
unsigned char randbytes[64]; /*!< random bytes */
|
||||||
unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
|
unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
|
||||||
/*!< premaster secret */
|
/*!< premaster secret */
|
||||||
|
|
||||||
int resume; /*!< session resume indicator*/
|
|
||||||
int max_major_ver; /*!< max. major version client*/
|
|
||||||
int max_minor_ver; /*!< max. minor version client*/
|
|
||||||
int cli_exts; /*!< client extension presence*/
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
|
||||||
int new_session_ticket; /*!< use NewSessionTicket? */
|
|
||||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
|
|
||||||
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
|
||||||
int extended_ms; /*!< use Extended Master Secret? */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
|
||||||
unsigned int async_in_progress : 1; /*!< an asynchronous operation is in progress */
|
|
||||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||||
/** Asynchronous operation context. This field is meant for use by the
|
/** Asynchronous operation context. This field is meant for use by the
|
||||||
* asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
|
* asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
* Major, Minor, Patchlevel
|
* Major, Minor, Patchlevel
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_VERSION_MAJOR 2
|
#define MBEDTLS_VERSION_MAJOR 2
|
||||||
#define MBEDTLS_VERSION_MINOR 27
|
#define MBEDTLS_VERSION_MINOR 28
|
||||||
#define MBEDTLS_VERSION_PATCH 0
|
#define MBEDTLS_VERSION_PATCH 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,9 +45,9 @@
|
||||||
* MMNNPP00
|
* MMNNPP00
|
||||||
* Major version | Minor version | Patch version
|
* Major version | Minor version | Patch version
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_VERSION_NUMBER 0x021B0000
|
#define MBEDTLS_VERSION_NUMBER 0x021C0000
|
||||||
#define MBEDTLS_VERSION_STRING "2.27.0"
|
#define MBEDTLS_VERSION_STRING "2.28.0"
|
||||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.27.0"
|
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.0"
|
||||||
|
|
||||||
#if defined(MBEDTLS_VERSION_C)
|
#if defined(MBEDTLS_VERSION_C)
|
||||||
|
|
||||||
|
|
|
@ -159,10 +159,10 @@ static void psa_set_key_id( psa_key_attributes_t *attributes,
|
||||||
* the owner of a key.
|
* the owner of a key.
|
||||||
*
|
*
|
||||||
* \param[out] attributes The attribute structure to write to.
|
* \param[out] attributes The attribute structure to write to.
|
||||||
* \param owner_id The key owner identifier.
|
* \param owner The key owner identifier.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes,
|
static void mbedtls_set_key_owner_id( psa_key_attributes_t *attributes,
|
||||||
mbedtls_key_owner_id_t owner_id );
|
mbedtls_key_owner_id_t owner );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Set the location of a persistent key.
|
/** Set the location of a persistent key.
|
||||||
|
|
|
@ -76,17 +76,4 @@ typedef struct
|
||||||
|
|
||||||
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, {0}}
|
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, {0}}
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
|
|
||||||
*/
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
typedef mbedtls_psa_mac_operation_t mbedtls_transparent_test_driver_mac_operation_t;
|
|
||||||
typedef mbedtls_psa_mac_operation_t mbedtls_opaque_test_driver_mac_operation_t;
|
|
||||||
|
|
||||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT MBEDTLS_PSA_MAC_OPERATION_INIT
|
|
||||||
#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT MBEDTLS_PSA_MAC_OPERATION_INIT
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
|
#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
|
||||||
|
|
|
@ -65,25 +65,27 @@ typedef struct
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||||
#if defined(MBEDTLS_MD2_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
mbedtls_md2_context md2;
|
mbedtls_md2_context md2;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_MD4_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
mbedtls_md4_context md4;
|
mbedtls_md4_context md4;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_MD5_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
mbedtls_md5_context md5;
|
mbedtls_md5_context md5;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_RIPEMD160_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
mbedtls_ripemd160_context ripemd160;
|
mbedtls_ripemd160_context ripemd160;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_SHA1_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
mbedtls_sha1_context sha1;
|
mbedtls_sha1_context sha1;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_SHA256_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
mbedtls_sha256_context sha256;
|
mbedtls_sha256_context sha256;
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_SHA512_C)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
mbedtls_sha512_context sha512;
|
mbedtls_sha512_context sha512;
|
||||||
#endif
|
#endif
|
||||||
} ctx;
|
} ctx;
|
||||||
|
@ -121,29 +123,4 @@ typedef struct {
|
||||||
|
|
||||||
#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
|
#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
|
|
||||||
*/
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
typedef mbedtls_psa_hash_operation_t mbedtls_transparent_test_driver_hash_operation_t;
|
|
||||||
|
|
||||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT MBEDTLS_PSA_HASH_OPERATION_INIT
|
|
||||||
|
|
||||||
typedef mbedtls_psa_cipher_operation_t
|
|
||||||
mbedtls_transparent_test_driver_cipher_operation_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
unsigned int initialised : 1;
|
|
||||||
mbedtls_transparent_test_driver_cipher_operation_t ctx;
|
|
||||||
} mbedtls_opaque_test_driver_cipher_operation_t;
|
|
||||||
|
|
||||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
|
||||||
MBEDTLS_PSA_CIPHER_OPERATION_INIT
|
|
||||||
|
|
||||||
#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
|
||||||
{ 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT }
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */
|
#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
* of these types. */
|
* of these types. */
|
||||||
#include "crypto_types.h"
|
#include "crypto_types.h"
|
||||||
#include "crypto_values.h"
|
#include "crypto_values.h"
|
||||||
|
/* Include size definitions which are used to size some arrays in operation
|
||||||
|
* structures. */
|
||||||
|
#include <psa/crypto_sizes.h>
|
||||||
|
|
||||||
/** For encrypt-decrypt functions, whether the operation is an encryption
|
/** For encrypt-decrypt functions, whether the operation is an encryption
|
||||||
* or a decryption. */
|
* or a decryption. */
|
||||||
|
|
|
@ -36,11 +36,42 @@
|
||||||
|
|
||||||
#include "psa/crypto_driver_common.h"
|
#include "psa/crypto_driver_common.h"
|
||||||
|
|
||||||
|
/* Include the context structure definitions for the Mbed TLS software drivers */
|
||||||
|
#include "psa/crypto_builtin_composites.h"
|
||||||
|
|
||||||
/* Include the context structure definitions for those drivers that were
|
/* Include the context structure definitions for those drivers that were
|
||||||
* declared during the autogeneration process. */
|
* declared during the autogeneration process. */
|
||||||
|
|
||||||
/* Include the context structure definitions for the Mbed TLS software drivers */
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
#include "psa/crypto_builtin_composites.h"
|
#include <libtestdriver1/include/psa/crypto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||||
|
typedef libtestdriver1_mbedtls_psa_mac_operation_t
|
||||||
|
mbedtls_transparent_test_driver_mac_operation_t;
|
||||||
|
typedef libtestdriver1_mbedtls_psa_mac_operation_t
|
||||||
|
mbedtls_opaque_test_driver_mac_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT \
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||||
|
#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT \
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||||
|
|
||||||
|
#else
|
||||||
|
typedef mbedtls_psa_mac_operation_t
|
||||||
|
mbedtls_transparent_test_driver_mac_operation_t;
|
||||||
|
typedef mbedtls_psa_mac_operation_t
|
||||||
|
mbedtls_opaque_test_driver_mac_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT \
|
||||||
|
MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||||
|
#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT \
|
||||||
|
MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 */
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
|
||||||
/* Define the context to be used for an operation that is executed through the
|
/* Define the context to be used for an operation that is executed through the
|
||||||
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
||||||
|
|
|
@ -35,11 +35,59 @@
|
||||||
|
|
||||||
#include "psa/crypto_driver_common.h"
|
#include "psa/crypto_driver_common.h"
|
||||||
|
|
||||||
|
/* Include the context structure definitions for the Mbed TLS software drivers */
|
||||||
|
#include "psa/crypto_builtin_primitives.h"
|
||||||
|
|
||||||
/* Include the context structure definitions for those drivers that were
|
/* Include the context structure definitions for those drivers that were
|
||||||
* declared during the autogeneration process. */
|
* declared during the autogeneration process. */
|
||||||
|
|
||||||
/* Include the context structure definitions for the Mbed TLS software drivers */
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
#include "psa/crypto_builtin_primitives.h"
|
#include <libtestdriver1/include/psa/crypto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
typedef libtestdriver1_mbedtls_psa_cipher_operation_t
|
||||||
|
mbedtls_transparent_test_driver_cipher_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_CIPHER_OPERATION_INIT
|
||||||
|
#else
|
||||||
|
typedef mbedtls_psa_cipher_operation_t
|
||||||
|
mbedtls_transparent_test_driver_cipher_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
||||||
|
MBEDTLS_PSA_CIPHER_OPERATION_INIT
|
||||||
|
#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 &&
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
typedef libtestdriver1_mbedtls_psa_hash_operation_t
|
||||||
|
mbedtls_transparent_test_driver_hash_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT \
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_HASH_OPERATION_INIT
|
||||||
|
#else
|
||||||
|
typedef mbedtls_psa_hash_operation_t
|
||||||
|
mbedtls_transparent_test_driver_hash_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT \
|
||||||
|
MBEDTLS_PSA_HASH_OPERATION_INIT
|
||||||
|
#endif /* MBEDTLS_TEST_LIBTESTDRIVER1 &&
|
||||||
|
LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int initialised : 1;
|
||||||
|
mbedtls_transparent_test_driver_cipher_operation_t ctx;
|
||||||
|
} mbedtls_opaque_test_driver_cipher_operation_t;
|
||||||
|
|
||||||
|
#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
||||||
|
{ 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT }
|
||||||
|
|
||||||
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
|
||||||
/* Define the context to be used for an operation that is executed through the
|
/* Define the context to be used for an operation that is executed through the
|
||||||
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "mbedtls/platform_util.h"
|
#include "mbedtls/platform_util.h"
|
||||||
|
|
||||||
|
#include "crypto_types.h"
|
||||||
#include "crypto_compat.h"
|
#include "crypto_compat.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -129,7 +129,7 @@
|
||||||
/* Note: for HMAC-SHA-3, the block size is 144 bytes for HMAC-SHA3-226,
|
/* Note: for HMAC-SHA-3, the block size is 144 bytes for HMAC-SHA3-226,
|
||||||
* 136 bytes for HMAC-SHA3-256, 104 bytes for SHA3-384, 72 bytes for
|
* 136 bytes for HMAC-SHA3-256, 104 bytes for SHA3-384, 72 bytes for
|
||||||
* HMAC-SHA3-512. */
|
* HMAC-SHA3-512. */
|
||||||
#if defined(MBEDTLS_SHA512_C)
|
#if defined(PSA_WANT_ALG_SHA_512) || defined(PSA_WANT_ALG_SHA_384)
|
||||||
#define PSA_HASH_MAX_SIZE 64
|
#define PSA_HASH_MAX_SIZE 64
|
||||||
#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128
|
#define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -175,9 +175,6 @@ typedef struct
|
||||||
{
|
{
|
||||||
uint8_t *info;
|
uint8_t *info;
|
||||||
size_t info_length;
|
size_t info_length;
|
||||||
psa_mac_operation_t hmac;
|
|
||||||
uint8_t prk[PSA_HASH_MAX_SIZE];
|
|
||||||
uint8_t output_block[PSA_HASH_MAX_SIZE];
|
|
||||||
#if PSA_HASH_MAX_SIZE > 0xff
|
#if PSA_HASH_MAX_SIZE > 0xff
|
||||||
#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"
|
#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"
|
||||||
#endif
|
#endif
|
||||||
|
@ -185,6 +182,9 @@ typedef struct
|
||||||
uint8_t block_number;
|
uint8_t block_number;
|
||||||
unsigned int state : 2;
|
unsigned int state : 2;
|
||||||
unsigned int info_set : 1;
|
unsigned int info_set : 1;
|
||||||
|
uint8_t output_block[PSA_HASH_MAX_SIZE];
|
||||||
|
uint8_t prk[PSA_HASH_MAX_SIZE];
|
||||||
|
struct psa_mac_operation_s hmac;
|
||||||
} psa_hkdf_key_derivation_t;
|
} psa_hkdf_key_derivation_t;
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF */
|
||||||
|
|
||||||
|
|
|
@ -203,15 +203,15 @@ endif(USE_STATIC_MBEDTLS_LIBRARY)
|
||||||
|
|
||||||
if(USE_SHARED_MBEDTLS_LIBRARY)
|
if(USE_SHARED_MBEDTLS_LIBRARY)
|
||||||
add_library(${mbedcrypto_target} SHARED ${src_crypto})
|
add_library(${mbedcrypto_target} SHARED ${src_crypto})
|
||||||
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.27.0 SOVERSION 7)
|
set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.28.0 SOVERSION 7)
|
||||||
target_link_libraries(${mbedcrypto_target} PUBLIC ${libs})
|
target_link_libraries(${mbedcrypto_target} PUBLIC ${libs})
|
||||||
|
|
||||||
add_library(${mbedx509_target} SHARED ${src_x509})
|
add_library(${mbedx509_target} SHARED ${src_x509})
|
||||||
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.27.0 SOVERSION 1)
|
set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.28.0 SOVERSION 1)
|
||||||
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
|
target_link_libraries(${mbedx509_target} PUBLIC ${libs} ${mbedcrypto_target})
|
||||||
|
|
||||||
add_library(${mbedtls_target} SHARED ${src_tls})
|
add_library(${mbedtls_target} SHARED ${src_tls})
|
||||||
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.27.0 SOVERSION 13)
|
set_target_properties(${mbedtls_target} PROPERTIES VERSION 2.28.0 SOVERSION 14)
|
||||||
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
|
target_link_libraries(${mbedtls_target} PUBLIC ${libs} ${mbedx509_target})
|
||||||
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ LOCAL_CFLAGS += -fPIC -fpic
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SOEXT_TLS=so.13
|
SOEXT_TLS=so.14
|
||||||
SOEXT_X509=so.1
|
SOEXT_X509=so.1
|
||||||
SOEXT_CRYPTO=so.7
|
SOEXT_CRYPTO=so.7
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#if defined(MBEDTLS_BASE64_C)
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
|
||||||
#include "mbedtls/base64.h"
|
#include "mbedtls/base64.h"
|
||||||
#include "base64_invasive.h"
|
#include "constant_time_internal.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -38,41 +38,6 @@
|
||||||
|
|
||||||
#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */
|
#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */
|
||||||
|
|
||||||
/* Return 0xff if low <= c <= high, 0 otherwise.
|
|
||||||
*
|
|
||||||
* Constant flow with respect to c.
|
|
||||||
*/
|
|
||||||
MBEDTLS_STATIC_TESTABLE
|
|
||||||
unsigned char mbedtls_base64_mask_of_range( unsigned char low,
|
|
||||||
unsigned char high,
|
|
||||||
unsigned char c )
|
|
||||||
{
|
|
||||||
/* low_mask is: 0 if low <= c, 0x...ff if low > c */
|
|
||||||
unsigned low_mask = ( (unsigned) c - low ) >> 8;
|
|
||||||
/* high_mask is: 0 if c <= high, 0x...ff if c > high */
|
|
||||||
unsigned high_mask = ( (unsigned) high - c ) >> 8;
|
|
||||||
return( ~( low_mask | high_mask ) & 0xff );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Given a value in the range 0..63, return the corresponding Base64 digit.
|
|
||||||
* The implementation assumes that letters are consecutive (e.g. ASCII
|
|
||||||
* but not EBCDIC).
|
|
||||||
*/
|
|
||||||
MBEDTLS_STATIC_TESTABLE
|
|
||||||
unsigned char mbedtls_base64_enc_char( unsigned char val )
|
|
||||||
{
|
|
||||||
unsigned char digit = 0;
|
|
||||||
/* For each range of values, if val is in that range, mask digit with
|
|
||||||
* the corresponding value. Since val can only be in a single range,
|
|
||||||
* only at most one masking will change digit. */
|
|
||||||
digit |= mbedtls_base64_mask_of_range( 0, 25, val ) & ( 'A' + val );
|
|
||||||
digit |= mbedtls_base64_mask_of_range( 26, 51, val ) & ( 'a' + val - 26 );
|
|
||||||
digit |= mbedtls_base64_mask_of_range( 52, 61, val ) & ( '0' + val - 52 );
|
|
||||||
digit |= mbedtls_base64_mask_of_range( 62, 62, val ) & '+';
|
|
||||||
digit |= mbedtls_base64_mask_of_range( 63, 63, val ) & '/';
|
|
||||||
return( digit );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encode a buffer into base64 format
|
* Encode a buffer into base64 format
|
||||||
*/
|
*/
|
||||||
|
@ -113,12 +78,12 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
C2 = *src++;
|
C2 = *src++;
|
||||||
C3 = *src++;
|
C3 = *src++;
|
||||||
|
|
||||||
*p++ = mbedtls_base64_enc_char( ( C1 >> 2 ) & 0x3F );
|
*p++ = mbedtls_ct_base64_enc_char( ( C1 >> 2 ) & 0x3F );
|
||||||
*p++ = mbedtls_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) )
|
*p++ = mbedtls_ct_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) )
|
||||||
& 0x3F );
|
& 0x3F );
|
||||||
*p++ = mbedtls_base64_enc_char( ( ( ( C2 & 15 ) << 2 ) + ( C3 >> 6 ) )
|
*p++ = mbedtls_ct_base64_enc_char( ( ( ( C2 & 15 ) << 2 ) + ( C3 >> 6 ) )
|
||||||
& 0x3F );
|
& 0x3F );
|
||||||
*p++ = mbedtls_base64_enc_char( C3 & 0x3F );
|
*p++ = mbedtls_ct_base64_enc_char( C3 & 0x3F );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i < slen )
|
if( i < slen )
|
||||||
|
@ -126,12 +91,12 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
C1 = *src++;
|
C1 = *src++;
|
||||||
C2 = ( ( i + 1 ) < slen ) ? *src++ : 0;
|
C2 = ( ( i + 1 ) < slen ) ? *src++ : 0;
|
||||||
|
|
||||||
*p++ = mbedtls_base64_enc_char( ( C1 >> 2 ) & 0x3F );
|
*p++ = mbedtls_ct_base64_enc_char( ( C1 >> 2 ) & 0x3F );
|
||||||
*p++ = mbedtls_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) )
|
*p++ = mbedtls_ct_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) )
|
||||||
& 0x3F );
|
& 0x3F );
|
||||||
|
|
||||||
if( ( i + 1 ) < slen )
|
if( ( i + 1 ) < slen )
|
||||||
*p++ = mbedtls_base64_enc_char( ( ( C2 & 15 ) << 2 ) & 0x3F );
|
*p++ = mbedtls_ct_base64_enc_char( ( ( C2 & 15 ) << 2 ) & 0x3F );
|
||||||
else *p++ = '=';
|
else *p++ = '=';
|
||||||
|
|
||||||
*p++ = '=';
|
*p++ = '=';
|
||||||
|
@ -143,35 +108,6 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a Base64 digit, return its value.
|
|
||||||
* If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'),
|
|
||||||
* return -1.
|
|
||||||
*
|
|
||||||
* The implementation assumes that letters are consecutive (e.g. ASCII
|
|
||||||
* but not EBCDIC).
|
|
||||||
*
|
|
||||||
* The implementation is constant-flow (no branch or memory access depending
|
|
||||||
* on the value of c) unless the compiler inlines and optimizes a specific
|
|
||||||
* access.
|
|
||||||
*/
|
|
||||||
MBEDTLS_STATIC_TESTABLE
|
|
||||||
signed char mbedtls_base64_dec_value( unsigned char c )
|
|
||||||
{
|
|
||||||
unsigned char val = 0;
|
|
||||||
/* For each range of digits, if c is in that range, mask val with
|
|
||||||
* the corresponding value. Since c can only be in a single range,
|
|
||||||
* only at most one masking will change val. Set val to one plus
|
|
||||||
* the desired value so that it stays 0 if c is in none of the ranges. */
|
|
||||||
val |= mbedtls_base64_mask_of_range( 'A', 'Z', c ) & ( c - 'A' + 0 + 1 );
|
|
||||||
val |= mbedtls_base64_mask_of_range( 'a', 'z', c ) & ( c - 'a' + 26 + 1 );
|
|
||||||
val |= mbedtls_base64_mask_of_range( '0', '9', c ) & ( c - '0' + 52 + 1 );
|
|
||||||
val |= mbedtls_base64_mask_of_range( '+', '+', c ) & ( c - '+' + 62 + 1 );
|
|
||||||
val |= mbedtls_base64_mask_of_range( '/', '/', c ) & ( c - '/' + 63 + 1 );
|
|
||||||
/* At this point, val is 0 if c is an invalid digit and v+1 if c is
|
|
||||||
* a digit with the value v. */
|
|
||||||
return( val - 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decode a base64-formatted buffer
|
* Decode a base64-formatted buffer
|
||||||
*/
|
*/
|
||||||
|
@ -224,7 +160,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
{
|
{
|
||||||
if( equals != 0 )
|
if( equals != 0 )
|
||||||
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
if( mbedtls_base64_dec_value( src[i] ) < 0 )
|
if( mbedtls_ct_base64_dec_value( src[i] ) < 0 )
|
||||||
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
|
@ -259,7 +195,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
if( *src == '=' )
|
if( *src == '=' )
|
||||||
++equals;
|
++equals;
|
||||||
else
|
else
|
||||||
x |= mbedtls_base64_dec_value( *src );
|
x |= mbedtls_ct_base64_dec_value( *src );
|
||||||
|
|
||||||
if( ++accumulated_digits == 4 )
|
if( ++accumulated_digits == 4 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
/**
|
|
||||||
* \file base_invasive.h
|
|
||||||
*
|
|
||||||
* \brief Base64 module: interfaces for invasive testing only.
|
|
||||||
*
|
|
||||||
* The interfaces in this file are intended for testing purposes only.
|
|
||||||
* They SHOULD NOT be made available in library integrations except when
|
|
||||||
* building the library for testing.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright The Mbed TLS Contributors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
#ifndef MBEDTLS_BASE64_INVASIVE_H
|
|
||||||
#define MBEDTLS_BASE64_INVASIVE_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_TEST_HOOKS)
|
|
||||||
/* Return 0xff if low <= c <= high, 0 otherwise.
|
|
||||||
*
|
|
||||||
* Constant flow with respect to c.
|
|
||||||
*/
|
|
||||||
unsigned char mbedtls_base64_mask_of_range( unsigned char low,
|
|
||||||
unsigned char high,
|
|
||||||
unsigned char c );
|
|
||||||
|
|
||||||
/* Given a value in the range 0..63, return the corresponding Base64 digit.
|
|
||||||
*
|
|
||||||
* Operates in constant time (no branches or memory access depending on val).
|
|
||||||
*/
|
|
||||||
unsigned char mbedtls_base64_enc_char( unsigned char val );
|
|
||||||
|
|
||||||
/* Given a Base64 digit, return its value.
|
|
||||||
* If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'),
|
|
||||||
* return -1.
|
|
||||||
*
|
|
||||||
* Operates in constant time (no branches or memory access depending on c).
|
|
||||||
*/
|
|
||||||
signed char mbedtls_base64_dec_value( unsigned char c );
|
|
||||||
#endif /* MBEDTLS_TEST_HOOKS */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_BASE64_INVASIVE_H */
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "mbedtls/error.h"
|
#include "mbedtls/error.h"
|
||||||
#include "constant_time_internal.h"
|
#include "constant_time_internal.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_C)
|
#if defined(MBEDTLS_PLATFORM_C)
|
||||||
|
|
|
@ -1125,6 +1125,12 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||||
|
|
||||||
|
/* Status to return on a non-authenticated algorithm. It would make sense
|
||||||
|
* to return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT or perhaps
|
||||||
|
* MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, but at the time I write this our
|
||||||
|
* unit tests assume 0. */
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
#if defined(MBEDTLS_GCM_C)
|
#if defined(MBEDTLS_GCM_C)
|
||||||
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
||||||
{
|
{
|
||||||
|
@ -1140,9 +1146,10 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
||||||
|
|
||||||
/* Check the tag in "constant-time" */
|
/* Check the tag in "constant-time" */
|
||||||
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
||||||
return( MBEDTLS_ERR_CIPHER_AUTH_FAILED );
|
{
|
||||||
|
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
||||||
return( 0 );
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_GCM_C */
|
#endif /* MBEDTLS_GCM_C */
|
||||||
|
|
||||||
|
@ -1162,13 +1169,16 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
||||||
|
|
||||||
/* Check the tag in "constant-time" */
|
/* Check the tag in "constant-time" */
|
||||||
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
||||||
return( MBEDTLS_ERR_CIPHER_AUTH_FAILED );
|
{
|
||||||
|
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
||||||
return( 0 );
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_CHACHAPOLY_C */
|
#endif /* MBEDTLS_CHACHAPOLY_C */
|
||||||
|
|
||||||
return( 0 );
|
exit:
|
||||||
|
mbedtls_platform_zeroize( check_tag, tag_len );
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@
|
||||||
#include "mbedtls/rsa.h"
|
#include "mbedtls/rsa.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
#include "constant_time_invasive.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int mbedtls_ct_memcmp( const void *a,
|
int mbedtls_ct_memcmp( const void *a,
|
||||||
|
@ -150,6 +154,26 @@ size_t mbedtls_ct_size_mask_ge( size_t x,
|
||||||
|
|
||||||
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
|
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
|
||||||
|
/* Return 0xff if low <= c <= high, 0 otherwise.
|
||||||
|
*
|
||||||
|
* Constant flow with respect to c.
|
||||||
|
*/
|
||||||
|
MBEDTLS_STATIC_TESTABLE
|
||||||
|
unsigned char mbedtls_ct_uchar_mask_of_range( unsigned char low,
|
||||||
|
unsigned char high,
|
||||||
|
unsigned char c )
|
||||||
|
{
|
||||||
|
/* low_mask is: 0 if low <= c, 0x...ff if low > c */
|
||||||
|
unsigned low_mask = ( (unsigned) c - low ) >> 8;
|
||||||
|
/* high_mask is: 0 if c <= high, 0x...ff if c > high */
|
||||||
|
unsigned high_mask = ( (unsigned) high - c ) >> 8;
|
||||||
|
return( ~( low_mask | high_mask ) & 0xff );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_BASE64_C */
|
||||||
|
|
||||||
unsigned mbedtls_ct_size_bool_eq( size_t x,
|
unsigned mbedtls_ct_size_bool_eq( size_t x,
|
||||||
size_t y )
|
size_t y )
|
||||||
{
|
{
|
||||||
|
@ -301,6 +325,41 @@ void mbedtls_ct_mpi_uint_cond_assign( size_t n,
|
||||||
|
|
||||||
#endif /* MBEDTLS_BIGNUM_C */
|
#endif /* MBEDTLS_BIGNUM_C */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
|
||||||
|
unsigned char mbedtls_ct_base64_enc_char( unsigned char value )
|
||||||
|
{
|
||||||
|
unsigned char digit = 0;
|
||||||
|
/* For each range of values, if value is in that range, mask digit with
|
||||||
|
* the corresponding value. Since value can only be in a single range,
|
||||||
|
* only at most one masking will change digit. */
|
||||||
|
digit |= mbedtls_ct_uchar_mask_of_range( 0, 25, value ) & ( 'A' + value );
|
||||||
|
digit |= mbedtls_ct_uchar_mask_of_range( 26, 51, value ) & ( 'a' + value - 26 );
|
||||||
|
digit |= mbedtls_ct_uchar_mask_of_range( 52, 61, value ) & ( '0' + value - 52 );
|
||||||
|
digit |= mbedtls_ct_uchar_mask_of_range( 62, 62, value ) & '+';
|
||||||
|
digit |= mbedtls_ct_uchar_mask_of_range( 63, 63, value ) & '/';
|
||||||
|
return( digit );
|
||||||
|
}
|
||||||
|
|
||||||
|
signed char mbedtls_ct_base64_dec_value( unsigned char c )
|
||||||
|
{
|
||||||
|
unsigned char val = 0;
|
||||||
|
/* For each range of digits, if c is in that range, mask val with
|
||||||
|
* the corresponding value. Since c can only be in a single range,
|
||||||
|
* only at most one masking will change val. Set val to one plus
|
||||||
|
* the desired value so that it stays 0 if c is in none of the ranges. */
|
||||||
|
val |= mbedtls_ct_uchar_mask_of_range( 'A', 'Z', c ) & ( c - 'A' + 0 + 1 );
|
||||||
|
val |= mbedtls_ct_uchar_mask_of_range( 'a', 'z', c ) & ( c - 'a' + 26 + 1 );
|
||||||
|
val |= mbedtls_ct_uchar_mask_of_range( '0', '9', c ) & ( c - '0' + 52 + 1 );
|
||||||
|
val |= mbedtls_ct_uchar_mask_of_range( '+', '+', c ) & ( c - '+' + 62 + 1 );
|
||||||
|
val |= mbedtls_ct_uchar_mask_of_range( '/', '/', c ) & ( c - '/' + 63 + 1 );
|
||||||
|
/* At this point, val is 0 if c is an invalid digit and v+1 if c is
|
||||||
|
* a digit with the value v. */
|
||||||
|
return( val - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_BASE64_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
|
#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT)
|
||||||
|
|
||||||
/** Shift some data towards the left inside a buffer.
|
/** Shift some data towards the left inside a buffer.
|
||||||
|
|
|
@ -167,6 +167,35 @@ void mbedtls_ct_mpi_uint_cond_assign( size_t n,
|
||||||
|
|
||||||
#endif /* MBEDTLS_BIGNUM_C */
|
#endif /* MBEDTLS_BIGNUM_C */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
|
||||||
|
/** Given a value in the range 0..63, return the corresponding Base64 digit.
|
||||||
|
*
|
||||||
|
* The implementation assumes that letters are consecutive (e.g. ASCII
|
||||||
|
* but not EBCDIC).
|
||||||
|
*
|
||||||
|
* \param value A value in the range 0..63.
|
||||||
|
*
|
||||||
|
* \return A base64 digit converted from \p value.
|
||||||
|
*/
|
||||||
|
unsigned char mbedtls_ct_base64_enc_char( unsigned char value );
|
||||||
|
|
||||||
|
/** Given a Base64 digit, return its value.
|
||||||
|
*
|
||||||
|
* If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'),
|
||||||
|
* return -1.
|
||||||
|
*
|
||||||
|
* The implementation assumes that letters are consecutive (e.g. ASCII
|
||||||
|
* but not EBCDIC).
|
||||||
|
*
|
||||||
|
* \param c A base64 digit.
|
||||||
|
*
|
||||||
|
* \return The value of the base64 digit \p c.
|
||||||
|
*/
|
||||||
|
signed char mbedtls_ct_base64_dec_value( unsigned char c );
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_BASE64_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
|
||||||
|
|
||||||
/** Conditional memcpy without branches.
|
/** Conditional memcpy without branches.
|
||||||
|
|
51
library/constant_time_invasive.h
Normal file
51
library/constant_time_invasive.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
* \file constant_time_invasive.h
|
||||||
|
*
|
||||||
|
* \brief Constant-time module: interfaces for invasive testing only.
|
||||||
|
*
|
||||||
|
* The interfaces in this file are intended for testing purposes only.
|
||||||
|
* They SHOULD NOT be made available in library integrations except when
|
||||||
|
* building the library for testing.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright The Mbed TLS Contributors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MBEDTLS_CONSTANT_TIME_INVASIVE_H
|
||||||
|
#define MBEDTLS_CONSTANT_TIME_INVASIVE_H
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_HOOKS)
|
||||||
|
|
||||||
|
/** Turn a value into a mask:
|
||||||
|
* - if \p low <= \p c <= \p high,
|
||||||
|
* return the all-bits 1 mask, aka (unsigned) -1
|
||||||
|
* - otherwise, return the all-bits 0 mask, aka 0
|
||||||
|
*
|
||||||
|
* \param low The value to analyze.
|
||||||
|
* \param high The value to analyze.
|
||||||
|
* \param c The value to analyze.
|
||||||
|
*
|
||||||
|
* \return All-bits-one if \p low <= \p c <= \p high, otherwise zero.
|
||||||
|
*/
|
||||||
|
unsigned char mbedtls_ct_uchar_mask_of_range( unsigned char low,
|
||||||
|
unsigned char high,
|
||||||
|
unsigned char c );
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_TEST_HOOKS */
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_CONSTANT_TIME_INVASIVE_H */
|
|
@ -179,6 +179,9 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
|
||||||
mbedtls_cipher_context_t cipher_ctx;
|
mbedtls_cipher_context_t cipher_ctx;
|
||||||
size_t olen = 0;
|
size_t olen = 0;
|
||||||
|
|
||||||
|
if( pwd == NULL && pwdlen != 0 )
|
||||||
|
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
||||||
|
|
||||||
cipher_info = mbedtls_cipher_info_from_type( cipher_type );
|
cipher_info = mbedtls_cipher_info_from_type( cipher_type );
|
||||||
if( cipher_info == NULL )
|
if( cipher_info == NULL )
|
||||||
return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE );
|
||||||
|
@ -231,6 +234,8 @@ static void pkcs12_fill_buffer( unsigned char *data, size_t data_len,
|
||||||
unsigned char *p = data;
|
unsigned char *p = data;
|
||||||
size_t use_len;
|
size_t use_len;
|
||||||
|
|
||||||
|
if( filler != NULL && fill_len != 0 )
|
||||||
|
{
|
||||||
while( data_len > 0 )
|
while( data_len > 0 )
|
||||||
{
|
{
|
||||||
use_len = ( data_len > fill_len ) ? fill_len : data_len;
|
use_len = ( data_len > fill_len ) ? fill_len : data_len;
|
||||||
|
@ -239,6 +244,15 @@ static void pkcs12_fill_buffer( unsigned char *data, size_t data_len,
|
||||||
data_len -= use_len;
|
data_len -= use_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If either of the above are not true then clearly there is nothing
|
||||||
|
* that this function can do. The function should *not* be called
|
||||||
|
* under either of those circumstances, as you could end up with an
|
||||||
|
* incorrect output but for safety's sake, leaving the check in as
|
||||||
|
* otherwise we could end up with memory corruption.*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
const unsigned char *pwd, size_t pwdlen,
|
const unsigned char *pwd, size_t pwdlen,
|
||||||
|
@ -253,6 +267,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
unsigned char hash_output[MBEDTLS_MD_MAX_SIZE];
|
unsigned char hash_output[MBEDTLS_MD_MAX_SIZE];
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
int use_password = 0;
|
||||||
|
int use_salt = 0;
|
||||||
|
|
||||||
size_t hlen, use_len, v, i;
|
size_t hlen, use_len, v, i;
|
||||||
|
|
||||||
|
@ -263,6 +279,15 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
if( datalen > 128 || pwdlen > 64 || saltlen > 64 )
|
if( datalen > 128 || pwdlen > 64 || saltlen > 64 )
|
||||||
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
if( pwd == NULL && pwdlen != 0 )
|
||||||
|
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
if( salt == NULL && saltlen != 0 )
|
||||||
|
return( MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
use_password = ( pwd && pwdlen != 0 );
|
||||||
|
use_salt = ( salt && saltlen != 0 );
|
||||||
|
|
||||||
md_info = mbedtls_md_info_from_type( md_type );
|
md_info = mbedtls_md_info_from_type( md_type );
|
||||||
if( md_info == NULL )
|
if( md_info == NULL )
|
||||||
return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE );
|
||||||
|
@ -280,8 +305,15 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
|
|
||||||
memset( diversifier, (unsigned char) id, v );
|
memset( diversifier, (unsigned char) id, v );
|
||||||
|
|
||||||
|
if( use_salt != 0 )
|
||||||
|
{
|
||||||
pkcs12_fill_buffer( salt_block, v, salt, saltlen );
|
pkcs12_fill_buffer( salt_block, v, salt, saltlen );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( use_password != 0 )
|
||||||
|
{
|
||||||
pkcs12_fill_buffer( pwd_block, v, pwd, pwdlen );
|
pkcs12_fill_buffer( pwd_block, v, pwd, pwdlen );
|
||||||
|
}
|
||||||
|
|
||||||
p = data;
|
p = data;
|
||||||
while( datalen > 0 )
|
while( datalen > 0 )
|
||||||
|
@ -293,11 +325,17 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
if( ( ret = mbedtls_md_update( &md_ctx, diversifier, v ) ) != 0 )
|
if( ( ret = mbedtls_md_update( &md_ctx, diversifier, v ) ) != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
if( use_salt != 0 )
|
||||||
|
{
|
||||||
if( ( ret = mbedtls_md_update( &md_ctx, salt_block, v )) != 0 )
|
if( ( ret = mbedtls_md_update( &md_ctx, salt_block, v )) != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( use_password != 0)
|
||||||
|
{
|
||||||
if( ( ret = mbedtls_md_update( &md_ctx, pwd_block, v )) != 0 )
|
if( ( ret = mbedtls_md_update( &md_ctx, pwd_block, v )) != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( ( ret = mbedtls_md_finish( &md_ctx, hash_output ) ) != 0 )
|
if( ( ret = mbedtls_md_finish( &md_ctx, hash_output ) ) != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -325,6 +363,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
if( ++hash_block[i - 1] != 0 )
|
if( ++hash_block[i - 1] != 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if( use_salt != 0 )
|
||||||
|
{
|
||||||
// salt_block += B
|
// salt_block += B
|
||||||
c = 0;
|
c = 0;
|
||||||
for( i = v; i > 0; i-- )
|
for( i = v; i > 0; i-- )
|
||||||
|
@ -333,7 +373,10 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
c = MBEDTLS_BYTE_1( j );
|
c = MBEDTLS_BYTE_1( j );
|
||||||
salt_block[i - 1] = MBEDTLS_BYTE_0( j );
|
salt_block[i - 1] = MBEDTLS_BYTE_0( j );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( use_password != 0 )
|
||||||
|
{
|
||||||
// pwd_block += B
|
// pwd_block += B
|
||||||
c = 0;
|
c = 0;
|
||||||
for( i = v; i > 0; i-- )
|
for( i = v; i > 0; i-- )
|
||||||
|
@ -343,6 +386,7 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
||||||
pwd_block[i - 1] = MBEDTLS_BYTE_0( j );
|
pwd_block[i - 1] = MBEDTLS_BYTE_0( j );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
|
|
@ -108,9 +108,9 @@ static int key_type_is_raw_bytes( psa_key_type_t type )
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
mbedtls_psa_random_context_t rng;
|
|
||||||
unsigned initialized : 1;
|
unsigned initialized : 1;
|
||||||
unsigned rng_state : 2;
|
unsigned rng_state : 2;
|
||||||
|
mbedtls_psa_random_context_t rng;
|
||||||
} psa_global_data_t;
|
} psa_global_data_t;
|
||||||
|
|
||||||
static psa_global_data_t global_data;
|
static psa_global_data_t global_data;
|
||||||
|
@ -385,15 +385,11 @@ psa_status_t mbedtls_to_psa_error( int ret )
|
||||||
/* Key management */
|
/* Key management */
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
/* For now the MBEDTLS_PSA_ACCEL_ guards are also used here since the
|
|
||||||
* current test driver in key_management.c is using this function
|
|
||||||
* when accelerators are used for ECC key pair and public key.
|
|
||||||
* Once that dependency is resolved these guards can be removed.
|
|
||||||
*/
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
|
||||||
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
||||||
size_t bits,
|
size_t bits,
|
||||||
int bits_is_sloppy )
|
int bits_is_sloppy )
|
||||||
|
@ -489,9 +485,10 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
||||||
return( MBEDTLS_ECP_DP_NONE );
|
return( MBEDTLS_ECP_DP_NONE );
|
||||||
}
|
}
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) ||
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) ||
|
||||||
* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) ||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
|
||||||
* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) */
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) ||
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) */
|
||||||
|
|
||||||
static psa_status_t validate_unstructured_key_bit_size( psa_key_type_t type,
|
static psa_status_t validate_unstructured_key_bit_size( psa_key_type_t type,
|
||||||
size_t bits )
|
size_t bits )
|
||||||
|
@ -2232,7 +2229,7 @@ psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
|
||||||
const uint8_t *hash,
|
const uint8_t *hash,
|
||||||
size_t hash_length )
|
size_t hash_length )
|
||||||
{
|
{
|
||||||
uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE];
|
uint8_t actual_hash[PSA_HASH_MAX_SIZE];
|
||||||
size_t actual_hash_length;
|
size_t actual_hash_length;
|
||||||
psa_status_t status = psa_hash_finish(
|
psa_status_t status = psa_hash_finish(
|
||||||
operation,
|
operation,
|
||||||
|
@ -2252,6 +2249,7 @@ psa_status_t psa_hash_verify( psa_hash_operation_t *operation,
|
||||||
status = PSA_ERROR_INVALID_SIGNATURE;
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
mbedtls_platform_zeroize( actual_hash, sizeof( actual_hash ) );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
psa_hash_abort(operation);
|
psa_hash_abort(operation);
|
||||||
|
|
||||||
|
@ -2275,7 +2273,7 @@ psa_status_t psa_hash_compare( psa_algorithm_t alg,
|
||||||
const uint8_t *input, size_t input_length,
|
const uint8_t *input, size_t input_length,
|
||||||
const uint8_t *hash, size_t hash_length )
|
const uint8_t *hash, size_t hash_length )
|
||||||
{
|
{
|
||||||
uint8_t actual_hash[MBEDTLS_MD_MAX_SIZE];
|
uint8_t actual_hash[PSA_HASH_MAX_SIZE];
|
||||||
size_t actual_hash_length;
|
size_t actual_hash_length;
|
||||||
|
|
||||||
if( !PSA_ALG_IS_HASH( alg ) )
|
if( !PSA_ALG_IS_HASH( alg ) )
|
||||||
|
@ -2286,12 +2284,18 @@ psa_status_t psa_hash_compare( psa_algorithm_t alg,
|
||||||
actual_hash, sizeof(actual_hash),
|
actual_hash, sizeof(actual_hash),
|
||||||
&actual_hash_length );
|
&actual_hash_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return( status );
|
goto exit;
|
||||||
if( actual_hash_length != hash_length )
|
if( actual_hash_length != hash_length )
|
||||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
{
|
||||||
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if( mbedtls_psa_safer_memcmp( hash, actual_hash, actual_hash_length ) != 0 )
|
if( mbedtls_psa_safer_memcmp( hash, actual_hash, actual_hash_length ) != 0 )
|
||||||
return( PSA_ERROR_INVALID_SIGNATURE );
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
return( PSA_SUCCESS );
|
|
||||||
|
exit:
|
||||||
|
mbedtls_platform_zeroize( actual_hash, sizeof( actual_hash ) );
|
||||||
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_hash_clone( const psa_hash_operation_t *source_operation,
|
psa_status_t psa_hash_clone( const psa_hash_operation_t *source_operation,
|
||||||
|
@ -2948,8 +2952,7 @@ psa_status_t psa_sign_hash_builtin(
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
||||||
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
|
||||||
{
|
{
|
||||||
if( PSA_ALG_IS_ECDSA( alg ) )
|
if( PSA_ALG_IS_ECDSA( alg ) )
|
||||||
{
|
{
|
||||||
|
@ -3019,8 +3022,7 @@ psa_status_t psa_verify_hash_builtin(
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
||||||
if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
|
||||||
{
|
{
|
||||||
if( PSA_ALG_IS_ECDSA( alg ) )
|
if( PSA_ALG_IS_ECDSA( alg ) )
|
||||||
{
|
{
|
||||||
|
@ -3109,10 +3111,10 @@ psa_status_t psa_asymmetric_encrypt( mbedtls_svc_key_id_t key,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
|
||||||
if( PSA_KEY_TYPE_IS_RSA( slot->attr.type ) )
|
if( PSA_KEY_TYPE_IS_RSA( slot->attr.type ) )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
mbedtls_rsa_context *rsa = NULL;
|
mbedtls_rsa_context *rsa = NULL;
|
||||||
status = mbedtls_psa_rsa_load_representation( slot->attr.type,
|
status = mbedtls_psa_rsa_load_representation( slot->attr.type,
|
||||||
slot->key.data,
|
slot->key.data,
|
||||||
|
@ -3126,9 +3128,11 @@ psa_status_t psa_asymmetric_encrypt( mbedtls_svc_key_id_t key,
|
||||||
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
goto rsa_exit;
|
goto rsa_exit;
|
||||||
}
|
}
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT)
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
||||||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
||||||
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT)
|
||||||
status = mbedtls_to_psa_error(
|
status = mbedtls_to_psa_error(
|
||||||
mbedtls_rsa_pkcs1_encrypt( rsa,
|
mbedtls_rsa_pkcs1_encrypt( rsa,
|
||||||
mbedtls_psa_get_random,
|
mbedtls_psa_get_random,
|
||||||
|
@ -3137,12 +3141,14 @@ psa_status_t psa_asymmetric_encrypt( mbedtls_svc_key_id_t key,
|
||||||
input_length,
|
input_length,
|
||||||
input,
|
input,
|
||||||
output ) );
|
output ) );
|
||||||
|
#else
|
||||||
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT */
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
|
||||||
if( PSA_ALG_IS_RSA_OAEP( alg ) )
|
if( PSA_ALG_IS_RSA_OAEP( alg ) )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
psa_rsa_oaep_set_padding_mode( alg, rsa );
|
psa_rsa_oaep_set_padding_mode( alg, rsa );
|
||||||
status = mbedtls_to_psa_error(
|
status = mbedtls_to_psa_error(
|
||||||
mbedtls_rsa_rsaes_oaep_encrypt( rsa,
|
mbedtls_rsa_rsaes_oaep_encrypt( rsa,
|
||||||
|
@ -3153,23 +3159,26 @@ psa_status_t psa_asymmetric_encrypt( mbedtls_svc_key_id_t key,
|
||||||
input_length,
|
input_length,
|
||||||
input,
|
input,
|
||||||
output ) );
|
output ) );
|
||||||
|
#else
|
||||||
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP */
|
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
goto rsa_exit;
|
|
||||||
}
|
}
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
rsa_exit:
|
rsa_exit:
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
*output_length = mbedtls_rsa_get_len( rsa );
|
*output_length = mbedtls_rsa_get_len( rsa );
|
||||||
|
|
||||||
mbedtls_rsa_free( rsa );
|
mbedtls_rsa_free( rsa );
|
||||||
mbedtls_free( rsa );
|
mbedtls_free( rsa );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
@ -3215,10 +3224,10 @@ psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
|
||||||
if( slot->attr.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
if( slot->attr.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
mbedtls_rsa_context *rsa = NULL;
|
mbedtls_rsa_context *rsa = NULL;
|
||||||
status = mbedtls_psa_rsa_load_representation( slot->attr.type,
|
status = mbedtls_psa_rsa_load_representation( slot->attr.type,
|
||||||
slot->key.data,
|
slot->key.data,
|
||||||
|
@ -3232,10 +3241,12 @@ psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key,
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
goto rsa_exit;
|
goto rsa_exit;
|
||||||
}
|
}
|
||||||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
||||||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT)
|
|
||||||
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
if( alg == PSA_ALG_RSA_PKCS1V15_CRYPT )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT)
|
||||||
status = mbedtls_to_psa_error(
|
status = mbedtls_to_psa_error(
|
||||||
mbedtls_rsa_pkcs1_decrypt( rsa,
|
mbedtls_rsa_pkcs1_decrypt( rsa,
|
||||||
mbedtls_psa_get_random,
|
mbedtls_psa_get_random,
|
||||||
|
@ -3245,12 +3256,14 @@ psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key,
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
output_size ) );
|
output_size ) );
|
||||||
|
#else
|
||||||
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT */
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
|
||||||
if( PSA_ALG_IS_RSA_OAEP( alg ) )
|
if( PSA_ALG_IS_RSA_OAEP( alg ) )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
psa_rsa_oaep_set_padding_mode( alg, rsa );
|
psa_rsa_oaep_set_padding_mode( alg, rsa );
|
||||||
status = mbedtls_to_psa_error(
|
status = mbedtls_to_psa_error(
|
||||||
mbedtls_rsa_rsaes_oaep_decrypt( rsa,
|
mbedtls_rsa_rsaes_oaep_decrypt( rsa,
|
||||||
|
@ -3262,20 +3275,24 @@ psa_status_t psa_asymmetric_decrypt( mbedtls_svc_key_id_t key,
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
output_size ) );
|
output_size ) );
|
||||||
|
#else
|
||||||
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP */
|
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
|
||||||
rsa_exit:
|
rsa_exit:
|
||||||
mbedtls_rsa_free( rsa );
|
mbedtls_rsa_free( rsa );
|
||||||
mbedtls_free( rsa );
|
mbedtls_free( rsa );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
@ -5340,11 +5357,9 @@ void mbedtls_psa_crypto_free( void )
|
||||||
* In particular, this sets all state indicator to the value
|
* In particular, this sets all state indicator to the value
|
||||||
* indicating "uninitialized". */
|
* indicating "uninitialized". */
|
||||||
mbedtls_platform_zeroize( &global_data, sizeof( global_data ) );
|
mbedtls_platform_zeroize( &global_data, sizeof( global_data ) );
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
|
||||||
/* Unregister all secure element drivers, so that we restart from
|
/* Terminate drivers */
|
||||||
* a pristine state. */
|
psa_driver_wrapper_free( );
|
||||||
psa_unregister_all_se_drivers( );
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
|
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
|
||||||
|
@ -5393,11 +5408,10 @@ psa_status_t psa_crypto_init( void )
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
/* Init drivers */
|
||||||
status = psa_init_all_se_drivers( );
|
status = psa_driver_wrapper_init( );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
|
#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
|
||||||
status = psa_crypto_load_transaction( );
|
status = psa_crypto_load_transaction( );
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
psa_algorithm_t core_alg;
|
||||||
|
uint8_t tag_length;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||||
|
@ -45,11 +47,9 @@ typedef struct
|
||||||
mbedtls_chachapoly_context chachapoly;
|
mbedtls_chachapoly_context chachapoly;
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||||
} ctx;
|
} ctx;
|
||||||
psa_algorithm_t core_alg;
|
|
||||||
uint8_t tag_length;
|
|
||||||
} aead_operation_t;
|
} aead_operation_t;
|
||||||
|
|
||||||
#define AEAD_OPERATION_INIT {{0}, 0, 0}
|
#define AEAD_OPERATION_INIT {0, 0, {0}}
|
||||||
|
|
||||||
static void psa_aead_abort_internal( aead_operation_t *operation )
|
static void psa_aead_abort_internal( aead_operation_t *operation )
|
||||||
{
|
{
|
||||||
|
@ -151,6 +151,8 @@ static psa_status_t psa_aead_setup(
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
(void) status;
|
||||||
|
(void) key_buffer;
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +254,11 @@ psa_status_t mbedtls_psa_aead_encrypt(
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||||
{
|
{
|
||||||
(void) tag;
|
(void) tag;
|
||||||
|
(void) nonce;
|
||||||
|
(void) nonce_length;
|
||||||
|
(void) additional_data;
|
||||||
|
(void) additional_data_length;
|
||||||
|
(void) plaintext;
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,6 +374,11 @@ psa_status_t mbedtls_psa_aead_decrypt(
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||||
{
|
{
|
||||||
|
(void) nonce;
|
||||||
|
(void) nonce_length;
|
||||||
|
(void) additional_data;
|
||||||
|
(void) additional_data_length;
|
||||||
|
(void) plaintext;
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,30 +31,6 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DES) ) )
|
|
||||||
#define BUILTIN_KEY_TYPE_DES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING) ) )
|
|
||||||
#define BUILTIN_ALG_CBC_NO_PADDING 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7) ) )
|
|
||||||
#define BUILTIN_ALG_CBC_PKCS7 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20) ) )
|
|
||||||
#define BUILTIN_KEY_TYPE_CHACHA20 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
|
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
psa_key_type_t key_type,
|
psa_key_type_t key_type,
|
||||||
|
@ -150,9 +126,9 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
|
||||||
(int) key_bits, mode ) );
|
(int) key_bits, mode ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_CIPHER) || defined(PSA_CRYPTO_DRIVER_TEST)
|
#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
|
||||||
static psa_status_t cipher_setup(
|
static psa_status_t psa_cipher_setup(
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
|
@ -179,7 +155,7 @@ static psa_status_t cipher_setup(
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_DES)
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES)
|
||||||
if( key_type == PSA_KEY_TYPE_DES && key_bits == 128 )
|
if( key_type == PSA_KEY_TYPE_DES && key_bits == 128 )
|
||||||
{
|
{
|
||||||
/* Two-key Triple-DES is 3-key Triple-DES with K1=K3 */
|
/* Two-key Triple-DES is 3-key Triple-DES with K1=K3 */
|
||||||
|
@ -199,8 +175,8 @@ static psa_status_t cipher_setup(
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_CBC_NO_PADDING) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
|
||||||
defined(BUILTIN_ALG_CBC_PKCS7)
|
defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7)
|
||||||
switch( alg )
|
switch( alg )
|
||||||
{
|
{
|
||||||
case PSA_ALG_CBC_NO_PADDING:
|
case PSA_ALG_CBC_NO_PADDING:
|
||||||
|
@ -218,7 +194,8 @@ static psa_status_t cipher_setup(
|
||||||
}
|
}
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
#endif /* BUILTIN_ALG_CBC_NO_PADDING || BUILTIN_ALG_CBC_PKCS7 */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING ||
|
||||||
|
MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 */
|
||||||
|
|
||||||
operation->block_length = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
|
operation->block_length = ( PSA_ALG_IS_STREAM_CIPHER( alg ) ? 1 :
|
||||||
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
|
PSA_BLOCK_CIPHER_BLOCK_LENGTH( key_type ) );
|
||||||
|
@ -228,29 +205,30 @@ exit:
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_encrypt_setup(
|
psa_status_t mbedtls_psa_cipher_encrypt_setup(
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg )
|
psa_algorithm_t alg )
|
||||||
{
|
{
|
||||||
return( cipher_setup( operation, attributes,
|
return( psa_cipher_setup( operation, attributes,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
alg, MBEDTLS_ENCRYPT ) );
|
alg, MBEDTLS_ENCRYPT ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_decrypt_setup(
|
psa_status_t mbedtls_psa_cipher_decrypt_setup(
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg )
|
psa_algorithm_t alg )
|
||||||
{
|
{
|
||||||
return( cipher_setup( operation, attributes,
|
return( psa_cipher_setup( operation, attributes,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
alg, MBEDTLS_DECRYPT ) );
|
alg, MBEDTLS_DECRYPT ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_set_iv( mbedtls_psa_cipher_operation_t *operation,
|
psa_status_t mbedtls_psa_cipher_set_iv(
|
||||||
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
const uint8_t *iv, size_t iv_length )
|
const uint8_t *iv, size_t iv_length )
|
||||||
{
|
{
|
||||||
if( iv_length != operation->iv_length )
|
if( iv_length != operation->iv_length )
|
||||||
|
@ -365,12 +343,10 @@ exit:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation,
|
psa_status_t mbedtls_psa_cipher_update(
|
||||||
const uint8_t *input,
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
size_t input_length,
|
const uint8_t *input, size_t input_length,
|
||||||
uint8_t *output,
|
uint8_t *output, size_t output_size, size_t *output_length )
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
size_t expected_output_size;
|
size_t expected_output_size;
|
||||||
|
@ -417,10 +393,9 @@ static psa_status_t cipher_update( mbedtls_psa_cipher_operation_t *operation,
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_finish( mbedtls_psa_cipher_operation_t *operation,
|
psa_status_t mbedtls_psa_cipher_finish(
|
||||||
uint8_t *output,
|
mbedtls_psa_cipher_operation_t *operation,
|
||||||
size_t output_size,
|
uint8_t *output, size_t output_size, size_t *output_length )
|
||||||
size_t *output_length )
|
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
|
||||||
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
|
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
|
||||||
|
@ -456,7 +431,8 @@ exit:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_abort( mbedtls_psa_cipher_operation_t *operation )
|
psa_status_t mbedtls_psa_cipher_abort(
|
||||||
|
mbedtls_psa_cipher_operation_t *operation )
|
||||||
{
|
{
|
||||||
/* Sanity check (shouldn't happen: operation->alg should
|
/* Sanity check (shouldn't happen: operation->alg should
|
||||||
* always have been initialized to a valid value). */
|
* always have been initialized to a valid value). */
|
||||||
|
@ -468,7 +444,7 @@ static psa_status_t cipher_abort( mbedtls_psa_cipher_operation_t *operation )
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes,
|
psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
@ -484,24 +460,25 @@ static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes,
|
||||||
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
||||||
size_t update_output_length, finish_output_length;
|
size_t update_output_length, finish_output_length;
|
||||||
|
|
||||||
status = cipher_encrypt_setup( &operation, attributes,
|
status = mbedtls_psa_cipher_encrypt_setup( &operation, attributes,
|
||||||
key_buffer, key_buffer_size, alg );
|
key_buffer, key_buffer_size,
|
||||||
|
alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( iv_length > 0 )
|
if( iv_length > 0 )
|
||||||
{
|
{
|
||||||
status = cipher_set_iv( &operation, iv, iv_length );
|
status = mbedtls_psa_cipher_set_iv( &operation, iv, iv_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = cipher_update( &operation, input, input_length,
|
status = mbedtls_psa_cipher_update( &operation, input, input_length,
|
||||||
output, output_size, &update_output_length );
|
output, output_size, &update_output_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
status = cipher_finish( &operation, output + update_output_length,
|
status = mbedtls_psa_cipher_finish( &operation, output + update_output_length,
|
||||||
output_size - update_output_length,
|
output_size - update_output_length,
|
||||||
&finish_output_length );
|
&finish_output_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
|
@ -511,13 +488,15 @@ static psa_status_t cipher_encrypt( const psa_key_attributes_t *attributes,
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
status = cipher_abort( &operation );
|
status = mbedtls_psa_cipher_abort( &operation );
|
||||||
else
|
else
|
||||||
cipher_abort( &operation );
|
mbedtls_psa_cipher_abort( &operation );
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t cipher_decrypt( const psa_key_attributes_t *attributes,
|
psa_status_t mbedtls_psa_cipher_decrypt(
|
||||||
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
|
@ -531,19 +510,21 @@ static psa_status_t cipher_decrypt( const psa_key_attributes_t *attributes,
|
||||||
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
mbedtls_psa_cipher_operation_t operation = MBEDTLS_PSA_CIPHER_OPERATION_INIT;
|
||||||
size_t olength, accumulated_length;
|
size_t olength, accumulated_length;
|
||||||
|
|
||||||
status = cipher_decrypt_setup( &operation, attributes,
|
status = mbedtls_psa_cipher_decrypt_setup( &operation, attributes,
|
||||||
key_buffer, key_buffer_size, alg );
|
key_buffer, key_buffer_size,
|
||||||
|
alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if( operation.iv_length > 0 )
|
if( operation.iv_length > 0 )
|
||||||
{
|
{
|
||||||
status = cipher_set_iv( &operation, input, operation.iv_length );
|
status = mbedtls_psa_cipher_set_iv( &operation,
|
||||||
|
input, operation.iv_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = cipher_update( &operation, input + operation.iv_length,
|
status = mbedtls_psa_cipher_update( &operation, input + operation.iv_length,
|
||||||
input_length - operation.iv_length,
|
input_length - operation.iv_length,
|
||||||
output, output_size, &olength );
|
output, output_size, &olength );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
|
@ -551,8 +532,9 @@ static psa_status_t cipher_decrypt( const psa_key_attributes_t *attributes,
|
||||||
|
|
||||||
accumulated_length = olength;
|
accumulated_length = olength;
|
||||||
|
|
||||||
status = cipher_finish( &operation, output + accumulated_length,
|
status = mbedtls_psa_cipher_finish( &operation, output + accumulated_length,
|
||||||
output_size - accumulated_length, &olength );
|
output_size - accumulated_length,
|
||||||
|
&olength );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
@ -560,185 +542,12 @@ static psa_status_t cipher_decrypt( const psa_key_attributes_t *attributes,
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if ( status == PSA_SUCCESS )
|
if ( status == PSA_SUCCESS )
|
||||||
status = cipher_abort( &operation );
|
status = mbedtls_psa_cipher_abort( &operation );
|
||||||
else
|
else
|
||||||
cipher_abort( &operation );
|
mbedtls_psa_cipher_abort( &operation );
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_CIPHER || PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
|
||||||
psa_status_t mbedtls_psa_cipher_encrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( cipher_encrypt_setup(
|
|
||||||
operation, attributes, key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_decrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( cipher_decrypt_setup(
|
|
||||||
operation, attributes, key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_set_iv( mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *iv,
|
|
||||||
size_t iv_length )
|
|
||||||
{
|
|
||||||
return( cipher_set_iv( operation, iv, iv_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_update( mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_update( operation, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_finish( mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_finish( operation, output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_abort( mbedtls_psa_cipher_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( cipher_abort( operation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_encrypt( const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *iv,
|
|
||||||
size_t iv_length,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
|
||||||
alg, iv, iv_length, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_cipher_decrypt( const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_decrypt( attributes, key_buffer, key_buffer_size,
|
|
||||||
alg, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
|
#endif /* MBEDTLS_PSA_BUILTIN_CIPHER */
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_encrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( cipher_encrypt_setup(
|
|
||||||
operation, attributes, key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_decrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( cipher_decrypt_setup(
|
|
||||||
operation, attributes, key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_set_iv(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *iv, size_t iv_length )
|
|
||||||
{
|
|
||||||
return( cipher_set_iv( operation, iv, iv_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_update(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *input, size_t input_length,
|
|
||||||
uint8_t *output, size_t output_size, size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_update( operation, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_finish(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
uint8_t *output, size_t output_size, size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_finish( operation, output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_abort(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( cipher_abort( operation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_encrypt(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *iv,
|
|
||||||
size_t iv_length,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_encrypt( attributes, key_buffer, key_buffer_size,
|
|
||||||
alg, iv, iv_length, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_decrypt(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length )
|
|
||||||
{
|
|
||||||
return( cipher_decrypt( attributes, key_buffer, key_buffer_size,
|
|
||||||
alg, input, input_length,
|
|
||||||
output, output_size, output_length ) );
|
|
||||||
}
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
|
@ -302,62 +302,4 @@ psa_status_t mbedtls_psa_cipher_decrypt( const psa_key_attributes_t *attributes,
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length );
|
size_t *output_length );
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_encrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_decrypt_setup(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_set_iv(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *iv, size_t iv_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_update(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
const uint8_t *input, size_t input_length,
|
|
||||||
uint8_t *output, size_t output_size, size_t *output_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_finish(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation,
|
|
||||||
uint8_t *output, size_t output_size, size_t *output_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_abort(
|
|
||||||
mbedtls_psa_cipher_operation_t *operation );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_encrypt(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *iv,
|
|
||||||
size_t iv_length,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_cipher_decrypt(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *output,
|
|
||||||
size_t output_size,
|
|
||||||
size_t *output_length );
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_CIPHER_H */
|
#endif /* PSA_CRYPTO_CIPHER_H */
|
||||||
|
|
|
@ -66,6 +66,44 @@
|
||||||
#include "psa_crypto_se.h"
|
#include "psa_crypto_se.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
psa_status_t psa_driver_wrapper_init( void )
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||||
|
status = psa_init_all_se_drivers( );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
return( status );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
status = mbedtls_test_transparent_init( );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
return( status );
|
||||||
|
|
||||||
|
status = mbedtls_test_opaque_init( );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
return( status );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
(void) status;
|
||||||
|
return( PSA_SUCCESS );
|
||||||
|
}
|
||||||
|
|
||||||
|
void psa_driver_wrapper_free( void )
|
||||||
|
{
|
||||||
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||||
|
/* Unregister all secure element drivers, so that we restart from
|
||||||
|
* a pristine state. */
|
||||||
|
psa_unregister_all_se_drivers( );
|
||||||
|
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||||
|
|
||||||
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||||
|
mbedtls_test_transparent_free( );
|
||||||
|
mbedtls_test_opaque_free( );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Start delegation functions */
|
/* Start delegation functions */
|
||||||
psa_status_t psa_driver_wrapper_sign_message(
|
psa_status_t psa_driver_wrapper_sign_message(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
|
@ -972,6 +1010,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
|
||||||
default:
|
default:
|
||||||
/* Key is declared with a lifetime not known to us */
|
/* Key is declared with a lifetime not known to us */
|
||||||
(void)status;
|
(void)status;
|
||||||
|
(void)operation;
|
||||||
(void)key_buffer;
|
(void)key_buffer;
|
||||||
(void)key_buffer_size;
|
(void)key_buffer_size;
|
||||||
(void)alg;
|
(void)alg;
|
||||||
|
@ -1043,6 +1082,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
|
||||||
default:
|
default:
|
||||||
/* Key is declared with a lifetime not known to us */
|
/* Key is declared with a lifetime not known to us */
|
||||||
(void)status;
|
(void)status;
|
||||||
|
(void)operation;
|
||||||
(void)key_buffer;
|
(void)key_buffer;
|
||||||
(void)key_buffer_size;
|
(void)key_buffer_size;
|
||||||
(void)alg;
|
(void)alg;
|
||||||
|
@ -1614,6 +1654,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
|
||||||
default:
|
default:
|
||||||
/* Key is declared with a lifetime not known to us */
|
/* Key is declared with a lifetime not known to us */
|
||||||
(void) status;
|
(void) status;
|
||||||
|
(void) operation;
|
||||||
(void) key_buffer;
|
(void) key_buffer;
|
||||||
(void) key_buffer_size;
|
(void) key_buffer_size;
|
||||||
(void) alg;
|
(void) alg;
|
||||||
|
@ -1685,6 +1726,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
|
||||||
default:
|
default:
|
||||||
/* Key is declared with a lifetime not known to us */
|
/* Key is declared with a lifetime not known to us */
|
||||||
(void) status;
|
(void) status;
|
||||||
|
(void) operation;
|
||||||
(void) key_buffer;
|
(void) key_buffer;
|
||||||
(void) key_buffer_size;
|
(void) key_buffer_size;
|
||||||
(void) alg;
|
(void) alg;
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
#include "psa/crypto.h"
|
#include "psa/crypto.h"
|
||||||
#include "psa/crypto_driver_common.h"
|
#include "psa/crypto_driver_common.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialization and termination functions
|
||||||
|
*/
|
||||||
|
psa_status_t psa_driver_wrapper_init( void );
|
||||||
|
void psa_driver_wrapper_free( void );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Signature functions
|
* Signature functions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,36 +40,10 @@
|
||||||
#include <mbedtls/ecp.h>
|
#include <mbedtls/ecp.h>
|
||||||
#include <mbedtls/error.h>
|
#include <mbedtls/error.h>
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) ) )
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||||
#define BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) || \
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) ) )
|
|
||||||
#define BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) && \
|
|
||||||
defined(MBEDTLS_ECDSA_C) ) )
|
|
||||||
#define BUILTIN_ALG_ECDSA 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) && \
|
|
||||||
defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECDSA_DETERMINISTIC) ) )
|
|
||||||
#define BUILTIN_ALG_DETERMINISTIC_ECDSA 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
|
||||||
defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
|
|
||||||
defined(BUILTIN_ALG_ECDSA) || \
|
|
||||||
defined(BUILTIN_ALG_DETERMINISTIC_ECDSA) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
|
defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
|
||||||
psa_status_t mbedtls_psa_ecp_load_representation(
|
psa_status_t mbedtls_psa_ecp_load_representation(
|
||||||
psa_key_type_t type, size_t curve_bits,
|
psa_key_type_t type, size_t curve_bits,
|
||||||
|
@ -181,16 +155,16 @@ exit:
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
||||||
* defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) ||
|
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) ||
|
||||||
* defined(BUILTIN_ALG_ECDSA) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
|
||||||
* defined(BUILTIN_ALG_DETERMINISTIC_ECDSA) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) */
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
|
|
||||||
static psa_status_t ecp_import_key(
|
psa_status_t mbedtls_psa_ecp_import_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *data, size_t data_length,
|
const uint8_t *data, size_t data_length,
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
|
@ -281,7 +255,7 @@ psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t ecp_export_public_key(
|
psa_status_t mbedtls_psa_ecp_export_public_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
uint8_t *data, size_t data_size, size_t *data_length )
|
||||||
|
@ -305,11 +279,11 @@ static psa_status_t ecp_export_public_key(
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
||||||
* defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */
|
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||||
static psa_status_t ecp_generate_key(
|
psa_status_t mbedtls_psa_ecp_generate_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
||||||
{
|
{
|
||||||
|
@ -351,15 +325,15 @@ static psa_status_t ecp_generate_key(
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
/* ECDSA sign/verify */
|
/* ECDSA sign/verify */
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_ECDSA) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||||
defined(BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||||
static psa_status_t ecdsa_sign_hash(
|
psa_status_t mbedtls_psa_ecdsa_sign_hash(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
|
@ -391,7 +365,7 @@ static psa_status_t ecdsa_sign_hash(
|
||||||
|
|
||||||
if( PSA_ALG_ECDSA_IS_DETERMINISTIC( alg ) )
|
if( PSA_ALG_ECDSA_IS_DETERMINISTIC( alg ) )
|
||||||
{
|
{
|
||||||
#if defined(BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||||
psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg );
|
psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg );
|
||||||
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg );
|
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg );
|
||||||
mbedtls_md_type_t md_alg = mbedtls_md_get_type( md_info );
|
mbedtls_md_type_t md_alg = mbedtls_md_get_type( md_info );
|
||||||
|
@ -404,7 +378,7 @@ static psa_status_t ecdsa_sign_hash(
|
||||||
#else
|
#else
|
||||||
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
#endif /* defined(BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -433,7 +407,7 @@ cleanup:
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t ecdsa_verify_hash(
|
psa_status_t mbedtls_psa_ecdsa_verify_hash(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
|
@ -492,177 +466,7 @@ cleanup:
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(BUILTIN_ALG_ECDSA) || \
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||||
* defined(BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_ecp_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits )
|
|
||||||
{
|
|
||||||
return( ecp_import_key( attributes, data, data_length,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length, bits ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_ecp_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
|
||||||
{
|
|
||||||
return( ecp_export_public_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
data, data_size, data_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
|
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
|
||||||
psa_status_t mbedtls_psa_ecp_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
|
||||||
{
|
|
||||||
return( ecp_generate_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length ) );
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_ecdsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
|
||||||
{
|
|
||||||
|
|
||||||
return( ecdsa_sign_hash( attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_size, signature_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_ecdsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length )
|
|
||||||
{
|
|
||||||
return( ecdsa_verify_hash( attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
|
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits )
|
|
||||||
{
|
|
||||||
return( ecp_import_key( attributes, data, data_length,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length, bits ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
|
||||||
{
|
|
||||||
return( ecp_export_public_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
data, data_size, data_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) ||
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) && \
|
|
||||||
defined(MBEDTLS_GENPRIME)
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
|
||||||
{
|
|
||||||
return( ecp_generate_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length ) );
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) &&
|
|
||||||
defined(MBEDTLS_GENPRIME) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecdsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
|
||||||
{
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDSA_C)
|
|
||||||
return( ecdsa_sign_hash( attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_size, signature_length ) );
|
|
||||||
#else
|
|
||||||
(void)attributes;
|
|
||||||
(void)key_buffer;
|
|
||||||
(void)key_buffer_size;
|
|
||||||
(void)alg;
|
|
||||||
(void)hash;
|
|
||||||
(void)hash_length;
|
|
||||||
(void)signature;
|
|
||||||
(void)signature_size;
|
|
||||||
(void)signature_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecdsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_ECDSA_C)
|
|
||||||
return( ecdsa_verify_hash( attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_length ) );
|
|
||||||
#else
|
|
||||||
(void)attributes;
|
|
||||||
(void)key_buffer;
|
|
||||||
(void)key_buffer_size;
|
|
||||||
(void)alg;
|
|
||||||
(void)hash;
|
|
||||||
(void)hash_length;
|
|
||||||
(void)signature;
|
|
||||||
(void)signature_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA) ||
|
|
||||||
* defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA) */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
|
@ -218,39 +218,5 @@ psa_status_t mbedtls_psa_ecdsa_verify_hash(
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
const uint8_t *signature, size_t signature_length );
|
const uint8_t *signature, size_t signature_length );
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecp_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecdsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_ecdsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length );
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_ECP_H */
|
#endif /* PSA_CRYPTO_ECP_H */
|
||||||
|
|
|
@ -29,45 +29,6 @@
|
||||||
#include <mbedtls/error.h>
|
#include <mbedtls/error.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Use builtin defines specific to this compilation unit, since the test driver
|
|
||||||
* relies on the software driver. */
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD2) ) )
|
|
||||||
#define BUILTIN_ALG_MD2 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD4) ) )
|
|
||||||
#define BUILTIN_ALG_MD4 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_MD5) ) )
|
|
||||||
#define BUILTIN_ALG_MD5 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) ) )
|
|
||||||
#define BUILTIN_ALG_RIPEMD160 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) ) )
|
|
||||||
#define BUILTIN_ALG_SHA_1 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) ) )
|
|
||||||
#define BUILTIN_ALG_SHA_224 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) ) )
|
|
||||||
#define BUILTIN_ALG_SHA_256 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) ) )
|
|
||||||
#define BUILTIN_ALG_SHA_384 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) ) )
|
|
||||||
#define BUILTIN_ALG_SHA_512 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
|
||||||
|
@ -121,10 +82,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_psa( psa_algorithm_t alg )
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
|
||||||
|
|
||||||
/* Implement the PSA driver hash interface on top of mbed TLS if either the
|
#if defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
* software driver or the test driver requires it. */
|
psa_status_t mbedtls_psa_hash_abort(
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_HASH) || defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
static psa_status_t hash_abort(
|
|
||||||
mbedtls_psa_hash_operation_t *operation )
|
mbedtls_psa_hash_operation_t *operation )
|
||||||
{
|
{
|
||||||
switch( operation->alg )
|
switch( operation->alg )
|
||||||
|
@ -134,47 +93,47 @@ static psa_status_t hash_abort(
|
||||||
* in use. It's ok to call abort on such an object, and there's
|
* in use. It's ok to call abort on such an object, and there's
|
||||||
* nothing to do. */
|
* nothing to do. */
|
||||||
break;
|
break;
|
||||||
#if defined(BUILTIN_ALG_MD2)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
case PSA_ALG_MD2:
|
case PSA_ALG_MD2:
|
||||||
mbedtls_md2_free( &operation->ctx.md2 );
|
mbedtls_md2_free( &operation->ctx.md2 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD4)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
case PSA_ALG_MD4:
|
case PSA_ALG_MD4:
|
||||||
mbedtls_md4_free( &operation->ctx.md4 );
|
mbedtls_md4_free( &operation->ctx.md4 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD5)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
case PSA_ALG_MD5:
|
case PSA_ALG_MD5:
|
||||||
mbedtls_md5_free( &operation->ctx.md5 );
|
mbedtls_md5_free( &operation->ctx.md5 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_RIPEMD160)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
case PSA_ALG_RIPEMD160:
|
case PSA_ALG_RIPEMD160:
|
||||||
mbedtls_ripemd160_free( &operation->ctx.ripemd160 );
|
mbedtls_ripemd160_free( &operation->ctx.ripemd160 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_1)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
mbedtls_sha1_free( &operation->ctx.sha1 );
|
mbedtls_sha1_free( &operation->ctx.sha1 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_224)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
mbedtls_sha256_free( &operation->ctx.sha256 );
|
mbedtls_sha256_free( &operation->ctx.sha256 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_256)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
mbedtls_sha256_free( &operation->ctx.sha256 );
|
mbedtls_sha256_free( &operation->ctx.sha256 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_384)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
mbedtls_sha512_free( &operation->ctx.sha512 );
|
mbedtls_sha512_free( &operation->ctx.sha512 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_512)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
mbedtls_sha512_free( &operation->ctx.sha512 );
|
mbedtls_sha512_free( &operation->ctx.sha512 );
|
||||||
break;
|
break;
|
||||||
|
@ -186,7 +145,7 @@ static psa_status_t hash_abort(
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t hash_setup(
|
psa_status_t mbedtls_psa_hash_setup(
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
mbedtls_psa_hash_operation_t *operation,
|
||||||
psa_algorithm_t alg )
|
psa_algorithm_t alg )
|
||||||
{
|
{
|
||||||
|
@ -200,55 +159,55 @@ static psa_status_t hash_setup(
|
||||||
|
|
||||||
switch( alg )
|
switch( alg )
|
||||||
{
|
{
|
||||||
#if defined(BUILTIN_ALG_MD2)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
case PSA_ALG_MD2:
|
case PSA_ALG_MD2:
|
||||||
mbedtls_md2_init( &operation->ctx.md2 );
|
mbedtls_md2_init( &operation->ctx.md2 );
|
||||||
ret = mbedtls_md2_starts_ret( &operation->ctx.md2 );
|
ret = mbedtls_md2_starts_ret( &operation->ctx.md2 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD4)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
case PSA_ALG_MD4:
|
case PSA_ALG_MD4:
|
||||||
mbedtls_md4_init( &operation->ctx.md4 );
|
mbedtls_md4_init( &operation->ctx.md4 );
|
||||||
ret = mbedtls_md4_starts_ret( &operation->ctx.md4 );
|
ret = mbedtls_md4_starts_ret( &operation->ctx.md4 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD5)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
case PSA_ALG_MD5:
|
case PSA_ALG_MD5:
|
||||||
mbedtls_md5_init( &operation->ctx.md5 );
|
mbedtls_md5_init( &operation->ctx.md5 );
|
||||||
ret = mbedtls_md5_starts_ret( &operation->ctx.md5 );
|
ret = mbedtls_md5_starts_ret( &operation->ctx.md5 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_RIPEMD160)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
case PSA_ALG_RIPEMD160:
|
case PSA_ALG_RIPEMD160:
|
||||||
mbedtls_ripemd160_init( &operation->ctx.ripemd160 );
|
mbedtls_ripemd160_init( &operation->ctx.ripemd160 );
|
||||||
ret = mbedtls_ripemd160_starts_ret( &operation->ctx.ripemd160 );
|
ret = mbedtls_ripemd160_starts_ret( &operation->ctx.ripemd160 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_1)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
mbedtls_sha1_init( &operation->ctx.sha1 );
|
mbedtls_sha1_init( &operation->ctx.sha1 );
|
||||||
ret = mbedtls_sha1_starts_ret( &operation->ctx.sha1 );
|
ret = mbedtls_sha1_starts_ret( &operation->ctx.sha1 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_224)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
mbedtls_sha256_init( &operation->ctx.sha256 );
|
mbedtls_sha256_init( &operation->ctx.sha256 );
|
||||||
ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 1 );
|
ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 1 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_256)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
mbedtls_sha256_init( &operation->ctx.sha256 );
|
mbedtls_sha256_init( &operation->ctx.sha256 );
|
||||||
ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 0 );
|
ret = mbedtls_sha256_starts_ret( &operation->ctx.sha256, 0 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_384)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
mbedtls_sha512_init( &operation->ctx.sha512 );
|
mbedtls_sha512_init( &operation->ctx.sha512 );
|
||||||
ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 1 );
|
ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 1 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_512)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
mbedtls_sha512_init( &operation->ctx.sha512 );
|
mbedtls_sha512_init( &operation->ctx.sha512 );
|
||||||
ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 0 );
|
ret = mbedtls_sha512_starts_ret( &operation->ctx.sha512, 0 );
|
||||||
|
@ -262,11 +221,11 @@ static psa_status_t hash_setup(
|
||||||
if( ret == 0 )
|
if( ret == 0 )
|
||||||
operation->alg = alg;
|
operation->alg = alg;
|
||||||
else
|
else
|
||||||
hash_abort( operation );
|
mbedtls_psa_hash_abort( operation );
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t hash_clone(
|
psa_status_t mbedtls_psa_hash_clone(
|
||||||
const mbedtls_psa_hash_operation_t *source_operation,
|
const mbedtls_psa_hash_operation_t *source_operation,
|
||||||
mbedtls_psa_hash_operation_t *target_operation )
|
mbedtls_psa_hash_operation_t *target_operation )
|
||||||
{
|
{
|
||||||
|
@ -274,55 +233,55 @@ static psa_status_t hash_clone(
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
#if defined(BUILTIN_ALG_MD2)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
case PSA_ALG_MD2:
|
case PSA_ALG_MD2:
|
||||||
mbedtls_md2_clone( &target_operation->ctx.md2,
|
mbedtls_md2_clone( &target_operation->ctx.md2,
|
||||||
&source_operation->ctx.md2 );
|
&source_operation->ctx.md2 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD4)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
case PSA_ALG_MD4:
|
case PSA_ALG_MD4:
|
||||||
mbedtls_md4_clone( &target_operation->ctx.md4,
|
mbedtls_md4_clone( &target_operation->ctx.md4,
|
||||||
&source_operation->ctx.md4 );
|
&source_operation->ctx.md4 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD5)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
case PSA_ALG_MD5:
|
case PSA_ALG_MD5:
|
||||||
mbedtls_md5_clone( &target_operation->ctx.md5,
|
mbedtls_md5_clone( &target_operation->ctx.md5,
|
||||||
&source_operation->ctx.md5 );
|
&source_operation->ctx.md5 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_RIPEMD160)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
case PSA_ALG_RIPEMD160:
|
case PSA_ALG_RIPEMD160:
|
||||||
mbedtls_ripemd160_clone( &target_operation->ctx.ripemd160,
|
mbedtls_ripemd160_clone( &target_operation->ctx.ripemd160,
|
||||||
&source_operation->ctx.ripemd160 );
|
&source_operation->ctx.ripemd160 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_1)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
mbedtls_sha1_clone( &target_operation->ctx.sha1,
|
mbedtls_sha1_clone( &target_operation->ctx.sha1,
|
||||||
&source_operation->ctx.sha1 );
|
&source_operation->ctx.sha1 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_224)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
mbedtls_sha256_clone( &target_operation->ctx.sha256,
|
mbedtls_sha256_clone( &target_operation->ctx.sha256,
|
||||||
&source_operation->ctx.sha256 );
|
&source_operation->ctx.sha256 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_256)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
mbedtls_sha256_clone( &target_operation->ctx.sha256,
|
mbedtls_sha256_clone( &target_operation->ctx.sha256,
|
||||||
&source_operation->ctx.sha256 );
|
&source_operation->ctx.sha256 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_384)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
mbedtls_sha512_clone( &target_operation->ctx.sha512,
|
mbedtls_sha512_clone( &target_operation->ctx.sha512,
|
||||||
&source_operation->ctx.sha512 );
|
&source_operation->ctx.sha512 );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_512)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
mbedtls_sha512_clone( &target_operation->ctx.sha512,
|
mbedtls_sha512_clone( &target_operation->ctx.sha512,
|
||||||
&source_operation->ctx.sha512 );
|
&source_operation->ctx.sha512 );
|
||||||
|
@ -338,7 +297,7 @@ static psa_status_t hash_clone(
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t hash_update(
|
psa_status_t mbedtls_psa_hash_update(
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
mbedtls_psa_hash_operation_t *operation,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length )
|
size_t input_length )
|
||||||
|
@ -347,55 +306,55 @@ static psa_status_t hash_update(
|
||||||
|
|
||||||
switch( operation->alg )
|
switch( operation->alg )
|
||||||
{
|
{
|
||||||
#if defined(BUILTIN_ALG_MD2)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
case PSA_ALG_MD2:
|
case PSA_ALG_MD2:
|
||||||
ret = mbedtls_md2_update_ret( &operation->ctx.md2,
|
ret = mbedtls_md2_update_ret( &operation->ctx.md2,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD4)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
case PSA_ALG_MD4:
|
case PSA_ALG_MD4:
|
||||||
ret = mbedtls_md4_update_ret( &operation->ctx.md4,
|
ret = mbedtls_md4_update_ret( &operation->ctx.md4,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD5)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
case PSA_ALG_MD5:
|
case PSA_ALG_MD5:
|
||||||
ret = mbedtls_md5_update_ret( &operation->ctx.md5,
|
ret = mbedtls_md5_update_ret( &operation->ctx.md5,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_RIPEMD160)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
case PSA_ALG_RIPEMD160:
|
case PSA_ALG_RIPEMD160:
|
||||||
ret = mbedtls_ripemd160_update_ret( &operation->ctx.ripemd160,
|
ret = mbedtls_ripemd160_update_ret( &operation->ctx.ripemd160,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_1)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
ret = mbedtls_sha1_update_ret( &operation->ctx.sha1,
|
ret = mbedtls_sha1_update_ret( &operation->ctx.sha1,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_224)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
ret = mbedtls_sha256_update_ret( &operation->ctx.sha256,
|
ret = mbedtls_sha256_update_ret( &operation->ctx.sha256,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_256)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
ret = mbedtls_sha256_update_ret( &operation->ctx.sha256,
|
ret = mbedtls_sha256_update_ret( &operation->ctx.sha256,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_384)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
ret = mbedtls_sha512_update_ret( &operation->ctx.sha512,
|
ret = mbedtls_sha512_update_ret( &operation->ctx.sha512,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_512)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
ret = mbedtls_sha512_update_ret( &operation->ctx.sha512,
|
ret = mbedtls_sha512_update_ret( &operation->ctx.sha512,
|
||||||
input, input_length );
|
input, input_length );
|
||||||
|
@ -410,7 +369,7 @@ static psa_status_t hash_update(
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t hash_finish(
|
psa_status_t mbedtls_psa_hash_finish(
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
mbedtls_psa_hash_operation_t *operation,
|
||||||
uint8_t *hash,
|
uint8_t *hash,
|
||||||
size_t hash_size,
|
size_t hash_size,
|
||||||
|
@ -437,47 +396,47 @@ static psa_status_t hash_finish(
|
||||||
|
|
||||||
switch( operation->alg )
|
switch( operation->alg )
|
||||||
{
|
{
|
||||||
#if defined(BUILTIN_ALG_MD2)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||||
case PSA_ALG_MD2:
|
case PSA_ALG_MD2:
|
||||||
ret = mbedtls_md2_finish_ret( &operation->ctx.md2, hash );
|
ret = mbedtls_md2_finish_ret( &operation->ctx.md2, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD4)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||||
case PSA_ALG_MD4:
|
case PSA_ALG_MD4:
|
||||||
ret = mbedtls_md4_finish_ret( &operation->ctx.md4, hash );
|
ret = mbedtls_md4_finish_ret( &operation->ctx.md4, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_MD5)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||||
case PSA_ALG_MD5:
|
case PSA_ALG_MD5:
|
||||||
ret = mbedtls_md5_finish_ret( &operation->ctx.md5, hash );
|
ret = mbedtls_md5_finish_ret( &operation->ctx.md5, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_RIPEMD160)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||||
case PSA_ALG_RIPEMD160:
|
case PSA_ALG_RIPEMD160:
|
||||||
ret = mbedtls_ripemd160_finish_ret( &operation->ctx.ripemd160, hash );
|
ret = mbedtls_ripemd160_finish_ret( &operation->ctx.ripemd160, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_1)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
ret = mbedtls_sha1_finish_ret( &operation->ctx.sha1, hash );
|
ret = mbedtls_sha1_finish_ret( &operation->ctx.sha1, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_224)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash );
|
ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_256)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256)
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash );
|
ret = mbedtls_sha256_finish_ret( &operation->ctx.sha256, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_384)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash );
|
ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash );
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(BUILTIN_ALG_SHA_512)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash );
|
ret = mbedtls_sha512_finish_ret( &operation->ctx.sha512, hash );
|
||||||
break;
|
break;
|
||||||
|
@ -494,7 +453,7 @@ exit:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t hash_compute(
|
psa_status_t mbedtls_psa_hash_compute(
|
||||||
psa_algorithm_t alg,
|
psa_algorithm_t alg,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
|
@ -507,191 +466,24 @@ static psa_status_t hash_compute(
|
||||||
psa_status_t abort_status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t abort_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
*hash_length = hash_size;
|
*hash_length = hash_size;
|
||||||
status = hash_setup( &operation, alg );
|
status = mbedtls_psa_hash_setup( &operation, alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
status = hash_update( &operation, input, input_length );
|
status = mbedtls_psa_hash_update( &operation, input, input_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
status = hash_finish( &operation, hash, hash_size, hash_length );
|
status = mbedtls_psa_hash_finish( &operation, hash, hash_size, hash_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
abort_status = hash_abort( &operation );
|
abort_status = mbedtls_psa_hash_abort( &operation );
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
return( abort_status );
|
return( abort_status );
|
||||||
else
|
else
|
||||||
return( status );
|
return( status );
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_HASH || PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_HASH)
|
|
||||||
psa_status_t mbedtls_psa_hash_compute(
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length)
|
|
||||||
{
|
|
||||||
return( hash_compute( alg, input, input_length,
|
|
||||||
hash, hash_size, hash_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_hash_setup(
|
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( hash_setup( operation, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_hash_clone(
|
|
||||||
const mbedtls_psa_hash_operation_t *source_operation,
|
|
||||||
mbedtls_psa_hash_operation_t *target_operation )
|
|
||||||
{
|
|
||||||
return( hash_clone( source_operation, target_operation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_hash_update(
|
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length )
|
|
||||||
{
|
|
||||||
return( hash_update( operation, input, input_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_hash_finish(
|
|
||||||
mbedtls_psa_hash_operation_t *operation,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length )
|
|
||||||
{
|
|
||||||
return( hash_finish( operation, hash, hash_size, hash_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_hash_abort(
|
|
||||||
mbedtls_psa_hash_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( hash_abort( operation ) );
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_HASH */
|
#endif /* MBEDTLS_PSA_BUILTIN_HASH */
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
static int is_hash_accelerated( psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
switch( alg )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD2)
|
|
||||||
case PSA_ALG_MD2:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD4)
|
|
||||||
case PSA_ALG_MD4:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
|
|
||||||
case PSA_ALG_MD5:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
|
|
||||||
case PSA_ALG_RIPEMD160:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
|
|
||||||
case PSA_ALG_SHA_1:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
|
|
||||||
case PSA_ALG_SHA_224:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
|
||||||
case PSA_ALG_SHA_256:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
|
||||||
case PSA_ALG_SHA_384:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
|
|
||||||
case PSA_ALG_SHA_512:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_compute(
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length)
|
|
||||||
{
|
|
||||||
if( is_hash_accelerated( alg ) )
|
|
||||||
return( hash_compute( alg, input, input_length,
|
|
||||||
hash, hash_size, hash_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_setup(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
if( is_hash_accelerated( alg ) )
|
|
||||||
return( hash_setup( operation, alg ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_clone(
|
|
||||||
const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation )
|
|
||||||
{
|
|
||||||
if( is_hash_accelerated( source_operation->alg ) )
|
|
||||||
return( hash_clone( source_operation, target_operation ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_update(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length )
|
|
||||||
{
|
|
||||||
if( is_hash_accelerated( operation->alg ) )
|
|
||||||
return( hash_update( operation, input, input_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_finish(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length )
|
|
||||||
{
|
|
||||||
if( is_hash_accelerated( operation->alg ) )
|
|
||||||
return( hash_finish( operation, hash, hash_size, hash_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_abort(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( hash_abort( operation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
|
@ -231,42 +231,4 @@ psa_status_t mbedtls_psa_hash_finish(
|
||||||
psa_status_t mbedtls_psa_hash_abort(
|
psa_status_t mbedtls_psa_hash_abort(
|
||||||
mbedtls_psa_hash_operation_t *operation );
|
mbedtls_psa_hash_operation_t *operation );
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_compute(
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length);
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_setup(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_clone(
|
|
||||||
const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_update(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_finish(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
|
||||||
uint8_t *hash,
|
|
||||||
size_t hash_size,
|
|
||||||
size_t *hash_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_hash_abort(
|
|
||||||
mbedtls_transparent_test_driver_hash_operation_t *operation );
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_HASH_H */
|
#endif /* PSA_CRYPTO_HASH_H */
|
||||||
|
|
|
@ -30,18 +30,7 @@
|
||||||
#include <mbedtls/error.h>
|
#include <mbedtls/error.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Use builtin defines specific to this compilation unit, since the test driver
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
* relies on the software driver. */
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) ) )
|
|
||||||
#define BUILTIN_ALG_CMAC 1
|
|
||||||
#endif
|
|
||||||
#if( defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_HMAC) ) )
|
|
||||||
#define BUILTIN_ALG_HMAC 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
|
||||||
static psa_status_t psa_hmac_abort_internal(
|
static psa_status_t psa_hmac_abort_internal(
|
||||||
mbedtls_psa_hmac_operation_t *hmac )
|
mbedtls_psa_hmac_operation_t *hmac )
|
||||||
{
|
{
|
||||||
|
@ -127,7 +116,7 @@ static psa_status_t psa_hmac_finish_internal(
|
||||||
uint8_t *mac,
|
uint8_t *mac,
|
||||||
size_t mac_size )
|
size_t mac_size )
|
||||||
{
|
{
|
||||||
uint8_t tmp[MBEDTLS_MD_MAX_SIZE];
|
uint8_t tmp[PSA_HASH_MAX_SIZE];
|
||||||
psa_algorithm_t hash_alg = hmac->alg;
|
psa_algorithm_t hash_alg = hmac->alg;
|
||||||
size_t hash_size = 0;
|
size_t hash_size = 0;
|
||||||
size_t block_size = PSA_HASH_BLOCK_LENGTH( hash_alg );
|
size_t block_size = PSA_HASH_BLOCK_LENGTH( hash_alg );
|
||||||
|
@ -160,9 +149,9 @@ exit:
|
||||||
mbedtls_platform_zeroize( tmp, hash_size );
|
mbedtls_platform_zeroize( tmp, hash_size );
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation,
|
static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer )
|
const uint8_t *key_buffer )
|
||||||
|
@ -198,11 +187,10 @@ static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
exit:
|
exit:
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
|
|
||||||
/* Implement the PSA driver MAC interface on top of mbed TLS if either the
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
|
||||||
* software driver or the test driver requires it. */
|
defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
#if defined(BUILTIN_ALG_HMAC) || defined(BUILTIN_ALG_CMAC)
|
|
||||||
|
|
||||||
/* Initialize this driver's MAC operation structure. Once this function has been
|
/* Initialize this driver's MAC operation structure. Once this function has been
|
||||||
* called, mbedtls_psa_mac_abort can run and will do the right thing. */
|
* called, mbedtls_psa_mac_abort can run and will do the right thing. */
|
||||||
|
@ -214,15 +202,15 @@ static psa_status_t mac_init(
|
||||||
|
|
||||||
operation->alg = alg;
|
operation->alg = alg;
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
||||||
{
|
{
|
||||||
mbedtls_cipher_init( &operation->ctx.cmac );
|
mbedtls_cipher_init( &operation->ctx.cmac );
|
||||||
status = PSA_SUCCESS;
|
status = PSA_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
||||||
{
|
{
|
||||||
/* We'll set up the hash operation later in psa_hmac_setup_internal. */
|
/* We'll set up the hash operation later in psa_hmac_setup_internal. */
|
||||||
|
@ -230,8 +218,9 @@ static psa_status_t mac_init(
|
||||||
status = PSA_SUCCESS;
|
status = PSA_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
|
(void) operation;
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +229,7 @@ static psa_status_t mac_init(
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation )
|
psa_status_t mbedtls_psa_mac_abort( mbedtls_psa_mac_operation_t *operation )
|
||||||
{
|
{
|
||||||
if( operation->alg == 0 )
|
if( operation->alg == 0 )
|
||||||
{
|
{
|
||||||
|
@ -250,20 +239,20 @@ static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation )
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
||||||
{
|
{
|
||||||
mbedtls_cipher_free( &operation->ctx.cmac );
|
mbedtls_cipher_free( &operation->ctx.cmac );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
||||||
{
|
{
|
||||||
psa_hmac_abort_internal( &operation->ctx.hmac );
|
psa_hmac_abort_internal( &operation->ctx.hmac );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
/* Sanity check (shouldn't happen: operation->alg should
|
/* Sanity check (shouldn't happen: operation->alg should
|
||||||
* always have been initialized to a valid value). */
|
* always have been initialized to a valid value). */
|
||||||
|
@ -283,7 +272,7 @@ bad_state:
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
|
static psa_status_t psa_mac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
|
@ -299,7 +288,7 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return( status );
|
return( status );
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
if( PSA_ALG_FULL_LENGTH_MAC( alg ) == PSA_ALG_CMAC )
|
if( PSA_ALG_FULL_LENGTH_MAC( alg ) == PSA_ALG_CMAC )
|
||||||
{
|
{
|
||||||
/* Key buffer size for CMAC is dictated by the key bits set on the
|
/* Key buffer size for CMAC is dictated by the key bits set on the
|
||||||
|
@ -308,8 +297,8 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
status = cmac_setup( operation, attributes, key_buffer );
|
status = cmac_setup( operation, attributes, key_buffer );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
if( PSA_ALG_IS_HMAC( alg ) )
|
if( PSA_ALG_IS_HMAC( alg ) )
|
||||||
{
|
{
|
||||||
status = psa_hmac_setup_internal( &operation->ctx.hmac,
|
status = psa_hmac_setup_internal( &operation->ctx.hmac,
|
||||||
|
@ -318,7 +307,7 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
PSA_ALG_HMAC_GET_HASH( alg ) );
|
PSA_ALG_HMAC_GET_HASH( alg ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
(void) attributes;
|
(void) attributes;
|
||||||
(void) key_buffer;
|
(void) key_buffer;
|
||||||
|
@ -327,12 +316,34 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
|
||||||
}
|
}
|
||||||
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
mac_abort( operation );
|
mbedtls_psa_mac_abort( operation );
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_update(
|
psa_status_t mbedtls_psa_mac_sign_setup(
|
||||||
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes,
|
||||||
|
const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size,
|
||||||
|
psa_algorithm_t alg )
|
||||||
|
{
|
||||||
|
return( psa_mac_setup( operation, attributes,
|
||||||
|
key_buffer, key_buffer_size, alg ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t mbedtls_psa_mac_verify_setup(
|
||||||
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
|
const psa_key_attributes_t *attributes,
|
||||||
|
const uint8_t *key_buffer,
|
||||||
|
size_t key_buffer_size,
|
||||||
|
psa_algorithm_t alg )
|
||||||
|
{
|
||||||
|
return( psa_mac_setup( operation, attributes,
|
||||||
|
key_buffer, key_buffer_size, alg ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t mbedtls_psa_mac_update(
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
const uint8_t *input,
|
const uint8_t *input,
|
||||||
size_t input_length )
|
size_t input_length )
|
||||||
|
@ -340,7 +351,7 @@ static psa_status_t mac_update(
|
||||||
if( operation->alg == 0 )
|
if( operation->alg == 0 )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
||||||
{
|
{
|
||||||
return( mbedtls_to_psa_error(
|
return( mbedtls_to_psa_error(
|
||||||
|
@ -348,15 +359,15 @@ static psa_status_t mac_update(
|
||||||
input, input_length ) ) );
|
input, input_length ) ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
||||||
{
|
{
|
||||||
return( psa_hmac_update_internal( &operation->ctx.hmac,
|
return( psa_hmac_update_internal( &operation->ctx.hmac,
|
||||||
input, input_length ) );
|
input, input_length ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
/* This shouldn't happen if `operation` was initialized by
|
/* This shouldn't happen if `operation` was initialized by
|
||||||
* a setup function. */
|
* a setup function. */
|
||||||
|
@ -366,11 +377,11 @@ static psa_status_t mac_update(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation,
|
static psa_status_t psa_mac_finish_internal(
|
||||||
uint8_t *mac,
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
size_t mac_size )
|
uint8_t *mac, size_t mac_size )
|
||||||
{
|
{
|
||||||
#if defined(BUILTIN_ALG_CMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC)
|
||||||
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
if( PSA_ALG_FULL_LENGTH_MAC( operation->alg ) == PSA_ALG_CMAC )
|
||||||
{
|
{
|
||||||
uint8_t tmp[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE];
|
uint8_t tmp[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE];
|
||||||
|
@ -381,15 +392,15 @@ static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation,
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( mbedtls_to_psa_error( ret ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
#if defined(BUILTIN_ALG_HMAC)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||||
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
if( PSA_ALG_IS_HMAC( operation->alg ) )
|
||||||
{
|
{
|
||||||
return( psa_hmac_finish_internal( &operation->ctx.hmac,
|
return( psa_hmac_finish_internal( &operation->ctx.hmac,
|
||||||
mac, mac_size ) );
|
mac, mac_size ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
/* This shouldn't happen if `operation` was initialized by
|
/* This shouldn't happen if `operation` was initialized by
|
||||||
* a setup function. */
|
* a setup function. */
|
||||||
|
@ -400,7 +411,7 @@ static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_sign_finish(
|
psa_status_t mbedtls_psa_mac_sign_finish(
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
uint8_t *mac,
|
uint8_t *mac,
|
||||||
size_t mac_size,
|
size_t mac_size,
|
||||||
|
@ -411,15 +422,14 @@ static psa_status_t mac_sign_finish(
|
||||||
if( operation->alg == 0 )
|
if( operation->alg == 0 )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
status = mac_finish_internal( operation, mac, mac_size );
|
status = psa_mac_finish_internal( operation, mac, mac_size );
|
||||||
|
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
*mac_length = mac_size;
|
*mac_length = mac_size;
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_verify_finish(
|
psa_status_t mbedtls_psa_mac_verify_finish(
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
const uint8_t *mac,
|
const uint8_t *mac,
|
||||||
size_t mac_length )
|
size_t mac_length )
|
||||||
|
@ -434,7 +444,7 @@ static psa_status_t mac_verify_finish(
|
||||||
if( mac_length > sizeof( actual_mac ) )
|
if( mac_length > sizeof( actual_mac ) )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
status = mac_finish_internal( operation, actual_mac, mac_length );
|
status = psa_mac_finish_internal( operation, actual_mac, mac_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -447,7 +457,7 @@ cleanup:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t mac_compute(
|
psa_status_t mbedtls_psa_mac_compute(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer,
|
const uint8_t *key_buffer,
|
||||||
size_t key_buffer_size,
|
size_t key_buffer_size,
|
||||||
|
@ -461,7 +471,7 @@ static psa_status_t mac_compute(
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
mbedtls_psa_mac_operation_t operation = MBEDTLS_PSA_MAC_OPERATION_INIT;
|
mbedtls_psa_mac_operation_t operation = MBEDTLS_PSA_MAC_OPERATION_INIT;
|
||||||
|
|
||||||
status = mac_setup( &operation,
|
status = psa_mac_setup( &operation,
|
||||||
attributes, key_buffer, key_buffer_size,
|
attributes, key_buffer, key_buffer_size,
|
||||||
alg );
|
alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
|
@ -469,306 +479,21 @@ static psa_status_t mac_compute(
|
||||||
|
|
||||||
if( input_length > 0 )
|
if( input_length > 0 )
|
||||||
{
|
{
|
||||||
status = mac_update( &operation, input, input_length );
|
status = mbedtls_psa_mac_update( &operation, input, input_length );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = mac_finish_internal( &operation, mac, mac_size );
|
status = psa_mac_finish_internal( &operation, mac, mac_size );
|
||||||
if( status == PSA_SUCCESS )
|
if( status == PSA_SUCCESS )
|
||||||
*mac_length = mac_size;
|
*mac_length = mac_size;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mac_abort( &operation );
|
mbedtls_psa_mac_abort( &operation );
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* BUILTIN_ALG_HMAC || BUILTIN_ALG_CMAC */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC || MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_MAC)
|
|
||||||
psa_status_t mbedtls_psa_mac_compute(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
|
|
||||||
input, input_length,
|
|
||||||
mac, mac_size, mac_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_sign_setup(
|
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( mac_setup( operation, attributes,
|
|
||||||
key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_verify_setup(
|
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
return( mac_setup( operation, attributes,
|
|
||||||
key_buffer, key_buffer_size, alg ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_update(
|
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length )
|
|
||||||
{
|
|
||||||
return( mac_update( operation, input, input_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_sign_finish(
|
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_verify_finish(
|
|
||||||
mbedtls_psa_mac_operation_t *operation,
|
|
||||||
const uint8_t *mac,
|
|
||||||
size_t mac_length )
|
|
||||||
{
|
|
||||||
return( mac_verify_finish( operation, mac, mac_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_mac_abort(
|
|
||||||
mbedtls_psa_mac_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( mac_abort( operation ) );
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_MAC */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
static int is_mac_accelerated( psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
|
|
||||||
if( PSA_ALG_IS_HMAC( alg ) )
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch( PSA_ALG_FULL_LENGTH_MAC( alg ) )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)
|
|
||||||
case PSA_ALG_CMAC:
|
|
||||||
return( 1 );
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_compute(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( alg ) )
|
|
||||||
return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
|
|
||||||
input, input_length,
|
|
||||||
mac, mac_size, mac_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_sign_setup(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( alg ) )
|
|
||||||
return( mac_setup( operation, attributes,
|
|
||||||
key_buffer, key_buffer_size, alg ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_verify_setup(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( alg ) )
|
|
||||||
return( mac_setup( operation, attributes,
|
|
||||||
key_buffer, key_buffer_size, alg ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_update(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( operation->alg ) )
|
|
||||||
return( mac_update( operation, input, input_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_sign_finish(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( operation->alg ) )
|
|
||||||
return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_verify_finish(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *mac,
|
|
||||||
size_t mac_length )
|
|
||||||
{
|
|
||||||
if( is_mac_accelerated( operation->alg ) )
|
|
||||||
return( mac_verify_finish( operation, mac, mac_length ) );
|
|
||||||
else
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_abort(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation )
|
|
||||||
{
|
|
||||||
return( mac_abort( operation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_compute(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) attributes;
|
|
||||||
(void) key_buffer;
|
|
||||||
(void) key_buffer_size;
|
|
||||||
(void) alg;
|
|
||||||
(void) input;
|
|
||||||
(void) input_length;
|
|
||||||
(void) mac;
|
|
||||||
(void) mac_size;
|
|
||||||
(void) mac_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_sign_setup(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
(void) attributes;
|
|
||||||
(void) key_buffer;
|
|
||||||
(void) key_buffer_size;
|
|
||||||
(void) alg;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_verify_setup(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
(void) attributes;
|
|
||||||
(void) key_buffer;
|
|
||||||
(void) key_buffer_size;
|
|
||||||
(void) alg;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_update(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
(void) input;
|
|
||||||
(void) input_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_sign_finish(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
(void) mac;
|
|
||||||
(void) mac_size;
|
|
||||||
(void) mac_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_verify_finish(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *mac,
|
|
||||||
size_t mac_length )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
(void) mac;
|
|
||||||
(void) mac_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_abort(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation )
|
|
||||||
{
|
|
||||||
/* Opaque driver testing is not implemented yet through this mechanism. */
|
|
||||||
(void) operation;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
|
@ -273,100 +273,4 @@ psa_status_t mbedtls_psa_mac_verify_finish(
|
||||||
psa_status_t mbedtls_psa_mac_abort(
|
psa_status_t mbedtls_psa_mac_abort(
|
||||||
mbedtls_psa_mac_operation_t *operation );
|
mbedtls_psa_mac_operation_t *operation );
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_compute(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_sign_setup(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_verify_setup(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_update(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_sign_finish(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_verify_finish(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *mac,
|
|
||||||
size_t mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_mac_abort(
|
|
||||||
mbedtls_transparent_test_driver_mac_operation_t *operation );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_compute(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_sign_setup(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_verify_setup(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer,
|
|
||||||
size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_update(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *input,
|
|
||||||
size_t input_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_sign_finish(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
uint8_t *mac,
|
|
||||||
size_t mac_size,
|
|
||||||
size_t *mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_verify_finish(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
|
||||||
const uint8_t *mac,
|
|
||||||
size_t mac_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_opaque_test_driver_mac_abort(
|
|
||||||
mbedtls_opaque_test_driver_mac_operation_t *operation );
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_MAC_H */
|
#endif /* PSA_CRYPTO_MAC_H */
|
||||||
|
|
|
@ -41,38 +41,12 @@
|
||||||
#include <mbedtls/pk.h>
|
#include <mbedtls/pk.h>
|
||||||
#include <mbedtls/pk_internal.h>
|
#include <mbedtls/pk_internal.h>
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) ) )
|
|
||||||
#define BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) ) )
|
|
||||||
#define BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) && \
|
|
||||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V15) ) )
|
|
||||||
#define BUILTIN_ALG_RSA_PKCS1V15_SIGN 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
|
|
||||||
( defined(PSA_CRYPTO_DRIVER_TEST) && \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) && \
|
|
||||||
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) ) )
|
|
||||||
#define BUILTIN_ALG_RSA_PSS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) || \
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
|
||||||
defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||||
defined(BUILTIN_ALG_RSA_PSS) || \
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
|
||||||
defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
|
||||||
/* Mbed TLS doesn't support non-byte-aligned key sizes (i.e. key sizes
|
/* Mbed TLS doesn't support non-byte-aligned key sizes (i.e. key sizes
|
||||||
* that are not a multiple of 8) well. For example, there is only
|
* that are not a multiple of 8) well. For example, there is only
|
||||||
|
@ -147,15 +121,15 @@ exit:
|
||||||
}
|
}
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) ||
|
||||||
* defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
|
||||||
* defined(BUILTIN_ALG_RSA_PSS) ||
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) ||
|
||||||
* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) ||
|
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) ||
|
||||||
* defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */
|
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
|
||||||
static psa_status_t rsa_import_key(
|
psa_status_t mbedtls_psa_rsa_import_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *data, size_t data_length,
|
const uint8_t *data, size_t data_length,
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
|
@ -247,7 +221,7 @@ psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type,
|
||||||
#endif /* MBEDTLS_PK_WRITE_C */
|
#endif /* MBEDTLS_PK_WRITE_C */
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t rsa_export_public_key(
|
psa_status_t mbedtls_psa_rsa_export_public_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
uint8_t *data, size_t data_size, size_t *data_length )
|
||||||
|
@ -271,10 +245,10 @@ static psa_status_t rsa_export_public_key(
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) ||
|
||||||
* defined(BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */
|
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */
|
||||||
|
|
||||||
#if defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR) && \
|
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) && \
|
||||||
defined(MBEDTLS_GENPRIME)
|
defined(MBEDTLS_GENPRIME)
|
||||||
static psa_status_t psa_rsa_read_exponent( const uint8_t *domain_parameters,
|
static psa_status_t psa_rsa_read_exponent( const uint8_t *domain_parameters,
|
||||||
size_t domain_parameters_size,
|
size_t domain_parameters_size,
|
||||||
|
@ -302,7 +276,7 @@ static psa_status_t psa_rsa_read_exponent( const uint8_t *domain_parameters,
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t rsa_generate_key(
|
psa_status_t mbedtls_psa_rsa_generate_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
||||||
{
|
{
|
||||||
|
@ -333,14 +307,15 @@ static psa_status_t rsa_generate_key(
|
||||||
|
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
#endif /* defined(BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||||
* defined(MBEDTLS_GENPRIME) */
|
* defined(MBEDTLS_GENPRIME) */
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
/* Sign/verify hashes */
|
/* Sign/verify hashes */
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) || defined(BUILTIN_ALG_RSA_PSS)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||||
|
|
||||||
/* Decode the hash algorithm from alg and store the mbedtls encoding in
|
/* Decode the hash algorithm from alg and store the mbedtls encoding in
|
||||||
* md_alg. Verify that the hash length is acceptable. */
|
* md_alg. Verify that the hash length is acceptable. */
|
||||||
|
@ -372,7 +347,7 @@ static psa_status_t psa_rsa_decode_md_type( psa_algorithm_t alg,
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
static psa_status_t rsa_sign_hash(
|
psa_status_t mbedtls_psa_rsa_sign_hash(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
|
@ -400,7 +375,7 @@ static psa_status_t rsa_sign_hash(
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN)
|
||||||
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
|
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
|
||||||
{
|
{
|
||||||
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
|
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
|
||||||
|
@ -415,8 +390,8 @@ static psa_status_t rsa_sign_hash(
|
||||||
signature );
|
signature );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN */
|
||||||
#if defined(BUILTIN_ALG_RSA_PSS)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||||
if( PSA_ALG_IS_RSA_PSS( alg ) )
|
if( PSA_ALG_IS_RSA_PSS( alg ) )
|
||||||
{
|
{
|
||||||
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
|
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
|
||||||
|
@ -430,7 +405,7 @@ static psa_status_t rsa_sign_hash(
|
||||||
signature );
|
signature );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_RSA_PSS */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS */
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -447,7 +422,7 @@ exit:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_RSA_PSS)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||||
static int rsa_pss_expected_salt_len( psa_algorithm_t alg,
|
static int rsa_pss_expected_salt_len( psa_algorithm_t alg,
|
||||||
const mbedtls_rsa_context *rsa,
|
const mbedtls_rsa_context *rsa,
|
||||||
size_t hash_length )
|
size_t hash_length )
|
||||||
|
@ -466,9 +441,9 @@ static int rsa_pss_expected_salt_len( psa_algorithm_t alg,
|
||||||
else
|
else
|
||||||
return( room );
|
return( room );
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS */
|
||||||
|
|
||||||
static psa_status_t rsa_verify_hash(
|
psa_status_t mbedtls_psa_rsa_verify_hash(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
|
@ -496,7 +471,7 @@ static psa_status_t rsa_verify_hash(
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN)
|
||||||
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
|
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
|
||||||
{
|
{
|
||||||
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
|
mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
|
||||||
|
@ -511,8 +486,8 @@ static psa_status_t rsa_verify_hash(
|
||||||
signature );
|
signature );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN */
|
||||||
#if defined(BUILTIN_ALG_RSA_PSS)
|
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||||
if( PSA_ALG_IS_RSA_PSS( alg ) )
|
if( PSA_ALG_IS_RSA_PSS( alg ) )
|
||||||
{
|
{
|
||||||
int slen = rsa_pss_expected_salt_len( alg, rsa, hash_length );
|
int slen = rsa_pss_expected_salt_len( alg, rsa, hash_length );
|
||||||
|
@ -529,7 +504,7 @@ static psa_status_t rsa_verify_hash(
|
||||||
signature );
|
signature );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_RSA_PSS */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS */
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -549,176 +524,7 @@ exit:
|
||||||
return( status );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
|
|
||||||
* defined(BUILTIN_ALG_RSA_PSS) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_rsa_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits )
|
|
||||||
{
|
|
||||||
return( rsa_import_key( attributes, data, data_length,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length, bits ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_rsa_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
|
||||||
{
|
|
||||||
return( rsa_export_public_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
data, data_size, data_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) ||
|
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) && \
|
|
||||||
defined(MBEDTLS_GENPRIME)
|
|
||||||
psa_status_t mbedtls_psa_rsa_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
|
||||||
{
|
|
||||||
return( rsa_generate_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length ) );
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
|
||||||
* defined(MBEDTLS_GENPRIME) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
|
||||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
|
||||||
psa_status_t mbedtls_psa_rsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
|
||||||
{
|
|
||||||
return( rsa_sign_hash(
|
|
||||||
attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_size, signature_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_psa_rsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length )
|
|
||||||
{
|
|
||||||
return( rsa_verify_hash(
|
|
||||||
attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_length ) );
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
|
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) ||
|
||||||
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */
|
* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) */
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits )
|
|
||||||
{
|
|
||||||
return( rsa_import_key( attributes, data, data_length,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length, bits ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length )
|
|
||||||
{
|
|
||||||
return( rsa_export_public_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
data, data_size, data_length ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) ||
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR)
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
|
||||||
{
|
|
||||||
return( rsa_generate_key( attributes, key_buffer, key_buffer_size,
|
|
||||||
key_buffer_length ) );
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_RSA_C) && \
|
|
||||||
(defined(MBEDTLS_PKCS1_V15) || defined(MBEDTLS_PKCS1_V21))
|
|
||||||
return( rsa_sign_hash(
|
|
||||||
attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_size, signature_length ) );
|
|
||||||
#else
|
|
||||||
(void)attributes;
|
|
||||||
(void)key_buffer;
|
|
||||||
(void)key_buffer_size;
|
|
||||||
(void)alg;
|
|
||||||
(void)hash;
|
|
||||||
(void)hash_length;
|
|
||||||
(void)signature;
|
|
||||||
(void)signature_size;
|
|
||||||
(void)signature_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length )
|
|
||||||
{
|
|
||||||
#if defined(MBEDTLS_RSA_C) && \
|
|
||||||
(defined(MBEDTLS_PKCS1_V15) || defined(MBEDTLS_PKCS1_V21))
|
|
||||||
return( rsa_verify_hash(
|
|
||||||
attributes,
|
|
||||||
key_buffer, key_buffer_size,
|
|
||||||
alg, hash, hash_length,
|
|
||||||
signature, signature_length ) );
|
|
||||||
#else
|
|
||||||
(void)attributes;
|
|
||||||
(void)key_buffer;
|
|
||||||
(void)key_buffer_size;
|
|
||||||
(void)alg;
|
|
||||||
(void)hash;
|
|
||||||
(void)hash_length;
|
|
||||||
(void)signature;
|
|
||||||
(void)signature_length;
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN) ||
|
|
||||||
* defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS) */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||||
|
|
|
@ -212,39 +212,4 @@ psa_status_t mbedtls_psa_rsa_verify_hash(
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
||||||
const uint8_t *signature, size_t signature_length );
|
const uint8_t *signature, size_t signature_length );
|
||||||
|
|
||||||
/*
|
|
||||||
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_import_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *data, size_t data_length,
|
|
||||||
uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
size_t *key_buffer_length, size_t *bits );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_export_public_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
uint8_t *data, size_t data_size, size_t *data_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_generate_key(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
uint8_t *key, size_t key_size, size_t *key_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_sign_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
uint8_t *signature, size_t signature_size, size_t *signature_length );
|
|
||||||
|
|
||||||
psa_status_t mbedtls_transparent_test_driver_rsa_verify_hash(
|
|
||||||
const psa_key_attributes_t *attributes,
|
|
||||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
||||||
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
|
||||||
const uint8_t *signature, size_t signature_length );
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_RSA_H */
|
#endif /* PSA_CRYPTO_RSA_H */
|
||||||
|
|
|
@ -1942,9 +1942,13 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
||||||
memcpy( sig, sig_try, ctx->len );
|
memcpy( sig, sig_try, ctx->len );
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
mbedtls_platform_zeroize( sig_try, ctx->len );
|
||||||
|
mbedtls_platform_zeroize( verif, ctx->len );
|
||||||
mbedtls_free( sig_try );
|
mbedtls_free( sig_try );
|
||||||
mbedtls_free( verif );
|
mbedtls_free( verif );
|
||||||
|
|
||||||
|
if( ret != 0 )
|
||||||
|
memset( sig, '!', ctx->len );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PKCS1_V15 */
|
#endif /* MBEDTLS_PKCS1_V15 */
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
#include "mbedtls/psa_util.h"
|
#include "mbedtls/psa_util.h"
|
||||||
|
#include "psa/crypto.h"
|
||||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -3242,7 +3243,11 @@ start_processing:
|
||||||
if( mbedtls_ssl_ciphersuite_uses_server_signature( ciphersuite_info ) )
|
if( mbedtls_ssl_ciphersuite_uses_server_signature( ciphersuite_info ) )
|
||||||
{
|
{
|
||||||
size_t sig_len, hashlen;
|
size_t sig_len, hashlen;
|
||||||
unsigned char hash[64];
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
unsigned char hash[PSA_HASH_MAX_SIZE];
|
||||||
|
#else
|
||||||
|
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||||
|
#endif
|
||||||
mbedtls_md_type_t md_alg = MBEDTLS_MD_NONE;
|
mbedtls_md_type_t md_alg = MBEDTLS_MD_NONE;
|
||||||
mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
|
mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE;
|
||||||
unsigned char *params = ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl );
|
unsigned char *params = ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl );
|
||||||
|
|
|
@ -218,15 +218,20 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
||||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR,
|
{
|
||||||
MBEDTLS_ERR_THREADING_MUTEX_ERROR ) );
|
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR,
|
||||||
|
MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
return( ret );
|
goto exit;
|
||||||
|
|
||||||
if( mbedtls_ct_memcmp( cookie + 4, ref_hmac, sizeof( ref_hmac ) ) != 0 )
|
if( mbedtls_ct_memcmp( cookie + 4, ref_hmac, sizeof( ref_hmac ) ) != 0 )
|
||||||
return( -1 );
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME)
|
#if defined(MBEDTLS_HAVE_TIME)
|
||||||
cur_time = (unsigned long) mbedtls_time( NULL );
|
cur_time = (unsigned long) mbedtls_time( NULL );
|
||||||
|
@ -240,8 +245,13 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
|
||||||
( (unsigned long) cookie[3] );
|
( (unsigned long) cookie[3] );
|
||||||
|
|
||||||
if( ctx->timeout != 0 && cur_time - cookie_time > ctx->timeout )
|
if( ctx->timeout != 0 && cur_time - cookie_time > ctx->timeout )
|
||||||
return( -1 );
|
{
|
||||||
|
ret = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
return( 0 );
|
exit:
|
||||||
|
mbedtls_platform_zeroize( ref_hmac, sizeof( ref_hmac ) );
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_COOKIE_C */
|
#endif /* MBEDTLS_SSL_COOKIE_C */
|
||||||
|
|
|
@ -474,7 +474,7 @@ static void ssl_extract_add_data_from_record( unsigned char* add_data,
|
||||||
/*
|
/*
|
||||||
* SSLv3.0 MAC functions
|
* SSLv3.0 MAC functions
|
||||||
*/
|
*/
|
||||||
static void ssl_mac( mbedtls_md_context_t *md_ctx,
|
static int ssl_mac( mbedtls_md_context_t *md_ctx,
|
||||||
const unsigned char *secret,
|
const unsigned char *secret,
|
||||||
const unsigned char *buf, size_t len,
|
const unsigned char *buf, size_t len,
|
||||||
const unsigned char *ctr, int type,
|
const unsigned char *ctr, int type,
|
||||||
|
@ -485,6 +485,7 @@ static void ssl_mac( mbedtls_md_context_t *md_ctx,
|
||||||
int padlen;
|
int padlen;
|
||||||
int md_size = mbedtls_md_get_size( md_ctx->md_info );
|
int md_size = mbedtls_md_get_size( md_ctx->md_info );
|
||||||
int md_type = mbedtls_md_get_type( md_ctx->md_info );
|
int md_type = mbedtls_md_get_type( md_ctx->md_info );
|
||||||
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
/* Only MD5 and SHA-1 supported */
|
/* Only MD5 and SHA-1 supported */
|
||||||
if( md_type == MBEDTLS_MD_MD5 )
|
if( md_type == MBEDTLS_MD_MD5 )
|
||||||
|
@ -497,19 +498,43 @@ static void ssl_mac( mbedtls_md_context_t *md_ctx,
|
||||||
MBEDTLS_PUT_UINT16_BE( len, header, 9);
|
MBEDTLS_PUT_UINT16_BE( len, header, 9);
|
||||||
|
|
||||||
memset( padding, 0x36, padlen );
|
memset( padding, 0x36, padlen );
|
||||||
mbedtls_md_starts( md_ctx );
|
ret = mbedtls_md_starts( md_ctx );
|
||||||
mbedtls_md_update( md_ctx, secret, md_size );
|
if( ret != 0 )
|
||||||
mbedtls_md_update( md_ctx, padding, padlen );
|
return( ret );
|
||||||
mbedtls_md_update( md_ctx, header, 11 );
|
ret = mbedtls_md_update( md_ctx, secret, md_size );
|
||||||
mbedtls_md_update( md_ctx, buf, len );
|
if( ret != 0 )
|
||||||
mbedtls_md_finish( md_ctx, out );
|
return( ret );
|
||||||
|
ret = mbedtls_md_update( md_ctx, padding, padlen );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_update( md_ctx, header, 11 );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_update( md_ctx, buf, len );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_finish( md_ctx, out );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
memset( padding, 0x5C, padlen );
|
memset( padding, 0x5C, padlen );
|
||||||
mbedtls_md_starts( md_ctx );
|
ret = mbedtls_md_starts( md_ctx );
|
||||||
mbedtls_md_update( md_ctx, secret, md_size );
|
if( ret != 0 )
|
||||||
mbedtls_md_update( md_ctx, padding, padlen );
|
return( ret );
|
||||||
mbedtls_md_update( md_ctx, out, md_size );
|
ret = mbedtls_md_update( md_ctx, secret, md_size );
|
||||||
mbedtls_md_finish( md_ctx, out );
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_update( md_ctx, padding, padlen );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_update( md_ctx, out, md_size );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_md_finish( md_ctx, out );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||||
|
|
||||||
|
@ -714,9 +739,17 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
||||||
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||||
{
|
{
|
||||||
unsigned char mac[SSL3_MAC_MAX_BYTES];
|
unsigned char mac[SSL3_MAC_MAX_BYTES];
|
||||||
ssl_mac( &transform->md_ctx_enc, transform->mac_enc,
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
|
ret = ssl_mac( &transform->md_ctx_enc, transform->mac_enc,
|
||||||
data, rec->data_len, rec->ctr, rec->type, mac );
|
data, rec->data_len, rec->ctr, rec->type, mac );
|
||||||
|
if( ret == 0 )
|
||||||
memcpy( data + rec->data_len, mac, transform->maclen );
|
memcpy( data + rec->data_len, mac, transform->maclen );
|
||||||
|
mbedtls_platform_zeroize( mac, transform->maclen );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_mac", ret );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -725,18 +758,35 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
||||||
if( transform->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
if( transform->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||||
{
|
{
|
||||||
unsigned char mac[MBEDTLS_SSL_MAC_ADD];
|
unsigned char mac[MBEDTLS_SSL_MAC_ADD];
|
||||||
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
ssl_extract_add_data_from_record( add_data, &add_data_len, rec,
|
ssl_extract_add_data_from_record( add_data, &add_data_len, rec,
|
||||||
transform->minor_ver );
|
transform->minor_ver );
|
||||||
|
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_enc, add_data,
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_enc,
|
||||||
add_data_len );
|
add_data, add_data_len );
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_enc,
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_disabled;
|
||||||
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_enc,
|
||||||
data, rec->data_len );
|
data, rec->data_len );
|
||||||
mbedtls_md_hmac_finish( &transform->md_ctx_enc, mac );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_reset( &transform->md_ctx_enc );
|
goto hmac_failed_etm_disabled;
|
||||||
|
ret = mbedtls_md_hmac_finish( &transform->md_ctx_enc, mac );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_disabled;
|
||||||
|
ret = mbedtls_md_hmac_reset( &transform->md_ctx_enc );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_disabled;
|
||||||
|
|
||||||
memcpy( data + rec->data_len, mac, transform->maclen );
|
memcpy( data + rec->data_len, mac, transform->maclen );
|
||||||
|
|
||||||
|
hmac_failed_etm_disabled:
|
||||||
|
mbedtls_platform_zeroize( mac, transform->maclen );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_md_hmac_xxx", ret );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -1009,18 +1059,34 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
||||||
MBEDTLS_SSL_DEBUG_BUF( 4, "MAC'd meta-data", add_data,
|
MBEDTLS_SSL_DEBUG_BUF( 4, "MAC'd meta-data", add_data,
|
||||||
add_data_len );
|
add_data_len );
|
||||||
|
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_enc, add_data,
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_enc, add_data,
|
||||||
add_data_len );
|
add_data_len );
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_enc,
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_enc,
|
||||||
data, rec->data_len );
|
data, rec->data_len );
|
||||||
mbedtls_md_hmac_finish( &transform->md_ctx_enc, mac );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_reset( &transform->md_ctx_enc );
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_finish( &transform->md_ctx_enc, mac );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_reset( &transform->md_ctx_enc );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
|
||||||
memcpy( data + rec->data_len, mac, transform->maclen );
|
memcpy( data + rec->data_len, mac, transform->maclen );
|
||||||
|
|
||||||
rec->data_len += transform->maclen;
|
rec->data_len += transform->maclen;
|
||||||
post_avail -= transform->maclen;
|
post_avail -= transform->maclen;
|
||||||
auth_done++;
|
auth_done++;
|
||||||
|
|
||||||
|
hmac_failed_etm_enabled:
|
||||||
|
mbedtls_platform_zeroize( mac, transform->maclen );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "HMAC calculation failed", ret );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
|
#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
|
||||||
}
|
}
|
||||||
|
@ -1292,12 +1358,20 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||||
/* Calculate expected MAC. */
|
/* Calculate expected MAC. */
|
||||||
MBEDTLS_SSL_DEBUG_BUF( 4, "MAC'd meta-data", add_data,
|
MBEDTLS_SSL_DEBUG_BUF( 4, "MAC'd meta-data", add_data,
|
||||||
add_data_len );
|
add_data_len );
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_dec, add_data,
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_dec, add_data,
|
||||||
add_data_len );
|
add_data_len );
|
||||||
mbedtls_md_hmac_update( &transform->md_ctx_dec,
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_update( &transform->md_ctx_dec,
|
||||||
data, rec->data_len );
|
data, rec->data_len );
|
||||||
mbedtls_md_hmac_finish( &transform->md_ctx_dec, mac_expect );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_reset( &transform->md_ctx_dec );
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_finish( &transform->md_ctx_dec, mac_expect );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
ret = mbedtls_md_hmac_reset( &transform->md_ctx_dec );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_BUF( 4, "message mac", data + rec->data_len,
|
MBEDTLS_SSL_DEBUG_BUF( 4, "message mac", data + rec->data_len,
|
||||||
transform->maclen );
|
transform->maclen );
|
||||||
|
@ -1309,9 +1383,19 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||||
transform->maclen ) != 0 )
|
transform->maclen ) != 0 )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "message mac does not match" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "message mac does not match" ) );
|
||||||
return( MBEDTLS_ERR_SSL_INVALID_MAC );
|
ret = MBEDTLS_ERR_SSL_INVALID_MAC;
|
||||||
|
goto hmac_failed_etm_enabled;
|
||||||
}
|
}
|
||||||
auth_done++;
|
auth_done++;
|
||||||
|
|
||||||
|
hmac_failed_etm_enabled:
|
||||||
|
mbedtls_platform_zeroize( mac_expect, transform->maclen );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
if( ret != MBEDTLS_ERR_SSL_INVALID_MAC )
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_hmac_xxx", ret );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
|
#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
|
||||||
|
|
||||||
|
@ -1529,11 +1613,16 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||||
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
if( transform->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||||
{
|
{
|
||||||
ssl_mac( &transform->md_ctx_dec,
|
ret = ssl_mac( &transform->md_ctx_dec,
|
||||||
transform->mac_dec,
|
transform->mac_dec,
|
||||||
data, rec->data_len,
|
data, rec->data_len,
|
||||||
rec->ctr, rec->type,
|
rec->ctr, rec->type,
|
||||||
mac_expect );
|
mac_expect );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_mac", ret );
|
||||||
|
goto hmac_failed_etm_disabled;
|
||||||
|
}
|
||||||
memcpy( mac_peer, data + rec->data_len, transform->maclen );
|
memcpy( mac_peer, data + rec->data_len, transform->maclen );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1562,7 +1651,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ct_hmac", ret );
|
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ct_hmac", ret );
|
||||||
return( ret );
|
goto hmac_failed_etm_disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_ct_memcpy_offset( mac_peer, data,
|
mbedtls_ct_memcpy_offset( mac_peer, data,
|
||||||
|
@ -1592,6 +1681,12 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||||
correct = 0;
|
correct = 0;
|
||||||
}
|
}
|
||||||
auth_done++;
|
auth_done++;
|
||||||
|
|
||||||
|
hmac_failed_etm_disabled:
|
||||||
|
mbedtls_platform_zeroize( mac_peer, transform->maclen );
|
||||||
|
mbedtls_platform_zeroize( mac_expect, transform->maclen );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -3467,7 +3467,11 @@ curve_matching_done:
|
||||||
{
|
{
|
||||||
size_t dig_signed_len = ssl->out_msg + ssl->out_msglen - dig_signed;
|
size_t dig_signed_len = ssl->out_msg + ssl->out_msglen - dig_signed;
|
||||||
size_t hashlen = 0;
|
size_t hashlen = 0;
|
||||||
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||||
|
unsigned char hash[PSA_HASH_MAX_SIZE];
|
||||||
|
#else
|
||||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||||
|
#endif
|
||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -446,19 +446,37 @@ static int tls1_prf( const unsigned char *secret, size_t slen,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_starts( &md_ctx, S1, hs );
|
ret = mbedtls_md_hmac_starts( &md_ctx, S1, hs );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp + 20, nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, 4 + tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp + 20, nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, 4 + tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
for( i = 0; i < dlen; i += 16 )
|
for( i = 0; i < dlen; i += 16 )
|
||||||
{
|
{
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, 4 + tmp, 16 + nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, h_i );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, 4 + tmp, 16 + nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, h_i );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, 4 + tmp, 16 );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, 4 + tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, 4 + tmp, 16 );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, 4 + tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
k = ( i + 16 > dlen ) ? dlen % 16 : 16;
|
k = ( i + 16 > dlen ) ? dlen % 16 : 16;
|
||||||
|
|
||||||
|
@ -482,19 +500,37 @@ static int tls1_prf( const unsigned char *secret, size_t slen,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_starts( &md_ctx, S2, hs );
|
ret = mbedtls_md_hmac_starts( &md_ctx, S2, hs );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp + 20, nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp + 20, nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
for( i = 0; i < dlen; i += 20 )
|
for( i = 0; i < dlen; i += 20 )
|
||||||
{
|
{
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp, 20 + nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, h_i );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp, 20 + nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, h_i );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp, 20 );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp, 20 );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
k = ( i + 20 > dlen ) ? dlen % 20 : 20;
|
k = ( i + 20 > dlen ) ? dlen % 20 : 20;
|
||||||
|
|
||||||
|
@ -684,19 +720,37 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
|
||||||
if ( ( ret = mbedtls_md_setup( &md_ctx, md_info, 1 ) ) != 0 )
|
if ( ( ret = mbedtls_md_setup( &md_ctx, md_info, 1 ) ) != 0 )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
mbedtls_md_hmac_starts( &md_ctx, secret, slen );
|
ret = mbedtls_md_hmac_starts( &md_ctx, secret, slen );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp + md_len, nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp + md_len, nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
for( i = 0; i < dlen; i += md_len )
|
for( i = 0; i < dlen; i += md_len )
|
||||||
{
|
{
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp, md_len + nb );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, h_i );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp, md_len + nb );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, h_i );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
mbedtls_md_hmac_reset ( &md_ctx );
|
ret = mbedtls_md_hmac_reset ( &md_ctx );
|
||||||
mbedtls_md_hmac_update( &md_ctx, tmp, md_len );
|
if( ret != 0 )
|
||||||
mbedtls_md_hmac_finish( &md_ctx, tmp );
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_update( &md_ctx, tmp, md_len );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
ret = mbedtls_md_hmac_finish( &md_ctx, tmp );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto exit;
|
||||||
|
|
||||||
k = ( i + md_len > dlen ) ? dlen % md_len : md_len;
|
k = ( i + md_len > dlen ) ? dlen % md_len : md_len;
|
||||||
|
|
||||||
|
@ -1236,8 +1290,14 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform,
|
||||||
For AEAD-based ciphersuites, there is nothing to do here. */
|
For AEAD-based ciphersuites, there is nothing to do here. */
|
||||||
if( mac_key_len != 0 )
|
if( mac_key_len != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_md_hmac_starts( &transform->md_ctx_enc, mac_enc, mac_key_len );
|
ret = mbedtls_md_hmac_starts( &transform->md_ctx_enc,
|
||||||
mbedtls_md_hmac_starts( &transform->md_ctx_dec, mac_dec, mac_key_len );
|
mac_enc, mac_key_len );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto end;
|
||||||
|
ret = mbedtls_md_hmac_starts( &transform->md_ctx_dec,
|
||||||
|
mac_dec, mac_key_len );
|
||||||
|
if( ret != 0 )
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3575,22 +3635,6 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse finished" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse finished" ) );
|
||||||
|
|
||||||
ssl->handshake->calc_finished( ssl, buf, ssl->conf->endpoint ^ 1 );
|
|
||||||
|
|
||||||
if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret );
|
|
||||||
return( ret );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
|
||||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
|
||||||
MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE );
|
|
||||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* There is currently no ciphersuite using another length with TLS 1.2 */
|
/* There is currently no ciphersuite using another length with TLS 1.2 */
|
||||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||||
|
@ -3599,13 +3643,31 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
||||||
#endif
|
#endif
|
||||||
hash_len = 12;
|
hash_len = 12;
|
||||||
|
|
||||||
|
ssl->handshake->calc_finished( ssl, buf, ssl->conf->endpoint ^ 1 );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_ssl_read_record( ssl, 1 ) ) != 0 )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_read_record", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
||||||
|
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||||
|
MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE );
|
||||||
|
ret = MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( ssl->in_msg[0] != MBEDTLS_SSL_HS_FINISHED ||
|
if( ssl->in_msg[0] != MBEDTLS_SSL_HS_FINISHED ||
|
||||||
ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) + hash_len )
|
ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) + hash_len )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
||||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||||
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR );
|
MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR );
|
||||||
return( MBEDTLS_ERR_SSL_BAD_HS_FINISHED );
|
ret = MBEDTLS_ERR_SSL_BAD_HS_FINISHED;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mbedtls_ct_memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ),
|
if( mbedtls_ct_memcmp( ssl->in_msg + mbedtls_ssl_hs_hdr_len( ssl ),
|
||||||
|
@ -3614,7 +3676,8 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad finished message" ) );
|
||||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||||
MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR );
|
MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR );
|
||||||
return( MBEDTLS_ERR_SSL_BAD_HS_FINISHED );
|
ret = MBEDTLS_ERR_SSL_BAD_HS_FINISHED;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||||
|
@ -3643,7 +3706,9 @@ int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse finished" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse finished" ) );
|
||||||
|
|
||||||
return( 0 );
|
exit:
|
||||||
|
mbedtls_platform_zeroize( buf, hash_len );
|
||||||
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake )
|
static void ssl_handshake_params_init( mbedtls_ssl_handshake_params *handshake )
|
||||||
|
@ -7533,7 +7598,7 @@ int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( status = psa_hash_finish( &hash_operation, hash, MBEDTLS_MD_MAX_SIZE,
|
if( ( status = psa_hash_finish( &hash_operation, hash, PSA_HASH_MAX_SIZE,
|
||||||
hashlen ) ) != PSA_SUCCESS )
|
hashlen ) ) != PSA_SUCCESS )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_RET( 1, "psa_hash_finish", status );
|
MBEDTLS_SSL_DEBUG_RET( 1, "psa_hash_finish", status );
|
||||||
|
|
|
@ -281,10 +281,27 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
p = argv[2];
|
p = argv[2];
|
||||||
|
|
||||||
mbedtls_md_starts( &md_ctx );
|
if( mbedtls_md_starts( &md_ctx ) != 0 )
|
||||||
mbedtls_md_update( &md_ctx, buffer, 8 );
|
{
|
||||||
mbedtls_md_update( &md_ctx, (unsigned char *) p, strlen( p ) );
|
mbedtls_fprintf( stderr, "mbedtls_md_starts() returned error\n" );
|
||||||
mbedtls_md_finish( &md_ctx, digest );
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, buffer, 8 ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, ( unsigned char * ) p, strlen( p ) )
|
||||||
|
!= 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_finish( &md_ctx, digest ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy( IV, digest, 16 );
|
memcpy( IV, digest, 16 );
|
||||||
|
|
||||||
|
@ -306,10 +323,30 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
for( i = 0; i < 8192; i++ )
|
for( i = 0; i < 8192; i++ )
|
||||||
{
|
{
|
||||||
mbedtls_md_starts( &md_ctx );
|
if( mbedtls_md_starts( &md_ctx ) != 0 )
|
||||||
mbedtls_md_update( &md_ctx, digest, 32 );
|
{
|
||||||
mbedtls_md_update( &md_ctx, key, keylen );
|
mbedtls_fprintf( stderr,
|
||||||
mbedtls_md_finish( &md_ctx, digest );
|
"mbedtls_md_starts() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, digest, 32 ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr,
|
||||||
|
"mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, key, keylen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr,
|
||||||
|
"mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_finish( &md_ctx, digest ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr,
|
||||||
|
"mbedtls_md_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +367,11 @@ int main( int argc, char *argv[] )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_starts( &md_ctx, digest, 32 );
|
if( mbedtls_md_hmac_starts( &md_ctx, digest, 32 ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_starts() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypt and write the ciphertext.
|
* Encrypt and write the ciphertext.
|
||||||
|
@ -352,7 +393,11 @@ int main( int argc, char *argv[] )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_update( &md_ctx, output, olen );
|
if( mbedtls_md_hmac_update( &md_ctx, output, olen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( fwrite( output, 1, olen, fout ) != olen )
|
if( fwrite( output, 1, olen, fout ) != olen )
|
||||||
{
|
{
|
||||||
|
@ -366,7 +411,11 @@ int main( int argc, char *argv[] )
|
||||||
mbedtls_fprintf( stderr, "mbedtls_cipher_finish() returned error\n" );
|
mbedtls_fprintf( stderr, "mbedtls_cipher_finish() returned error\n" );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
mbedtls_md_hmac_update( &md_ctx, output, olen );
|
if( mbedtls_md_hmac_update( &md_ctx, output, olen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( fwrite( output, 1, olen, fout ) != olen )
|
if( fwrite( output, 1, olen, fout ) != olen )
|
||||||
{
|
{
|
||||||
|
@ -377,7 +426,11 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* Finally write the HMAC.
|
* Finally write the HMAC.
|
||||||
*/
|
*/
|
||||||
mbedtls_md_hmac_finish( &md_ctx, digest );
|
if( mbedtls_md_hmac_finish( &md_ctx, digest ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( fwrite( digest, 1, mbedtls_md_get_size( md_info ), fout ) != mbedtls_md_get_size( md_info ) )
|
if( fwrite( digest, 1, mbedtls_md_get_size( md_info ), fout ) != mbedtls_md_get_size( md_info ) )
|
||||||
{
|
{
|
||||||
|
@ -446,10 +499,26 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
for( i = 0; i < 8192; i++ )
|
for( i = 0; i < 8192; i++ )
|
||||||
{
|
{
|
||||||
mbedtls_md_starts( &md_ctx );
|
if( mbedtls_md_starts( &md_ctx ) != 0 )
|
||||||
mbedtls_md_update( &md_ctx, digest, 32 );
|
{
|
||||||
mbedtls_md_update( &md_ctx, key, keylen );
|
mbedtls_fprintf( stderr, "mbedtls_md_starts() returned error\n" );
|
||||||
mbedtls_md_finish( &md_ctx, digest );
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, digest, 32 ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_update( &md_ctx, key, keylen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if( mbedtls_md_finish( &md_ctx, digest ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen,
|
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen,
|
||||||
|
@ -471,7 +540,11 @@ int main( int argc, char *argv[] )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_starts( &md_ctx, digest, 32 );
|
if( mbedtls_md_hmac_starts( &md_ctx, digest, 32 ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_starts() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decrypt and write the plaintext.
|
* Decrypt and write the plaintext.
|
||||||
|
@ -488,7 +561,11 @@ int main( int argc, char *argv[] )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_md_hmac_update( &md_ctx, buffer, ilen );
|
if( mbedtls_md_hmac_update( &md_ctx, buffer, ilen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_update() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if( mbedtls_cipher_update( &cipher_ctx, buffer, ilen, output,
|
if( mbedtls_cipher_update( &cipher_ctx, buffer, ilen, output,
|
||||||
&olen ) != 0 )
|
&olen ) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -506,7 +583,11 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* Verify the message authentication code.
|
* Verify the message authentication code.
|
||||||
*/
|
*/
|
||||||
mbedtls_md_hmac_finish( &md_ctx, digest );
|
if( mbedtls_md_hmac_finish( &md_ctx, digest ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_md_hmac_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( fread( buffer, 1, mbedtls_md_get_size( md_info ), fin ) != mbedtls_md_get_size( md_info ) )
|
if( fread( buffer, 1, mbedtls_md_get_size( md_info ), fin ) != mbedtls_md_get_size( md_info ) )
|
||||||
{
|
{
|
||||||
|
@ -529,7 +610,11 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* Write the final block of data
|
* Write the final block of data
|
||||||
*/
|
*/
|
||||||
mbedtls_cipher_finish( &cipher_ctx, output, &olen );
|
if( mbedtls_cipher_finish( &cipher_ctx, output, &olen ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_fprintf( stderr, "mbedtls_cipher_finish() returned error\n" );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( fwrite( output, 1, olen, fout ) != olen )
|
if( fwrite( output, 1, olen, fout ) != olen )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -426,9 +426,9 @@ int main( void )
|
||||||
" arc4=%%d default: (library default: 0)\n" \
|
" arc4=%%d default: (library default: 0)\n" \
|
||||||
" allow_sha1=%%d default: 0\n" \
|
" allow_sha1=%%d default: 0\n" \
|
||||||
" min_version=%%s default: (library default: tls1)\n" \
|
" min_version=%%s default: (library default: tls1)\n" \
|
||||||
" max_version=%%s default: (library default: tls1_2)\n" \
|
" max_version=%%s default: (library default: tls12)\n" \
|
||||||
" force_version=%%s default: \"\" (none)\n" \
|
" force_version=%%s default: \"\" (none)\n" \
|
||||||
" options: ssl3, tls1, tls1_1, tls1_2, dtls1, dtls1_2\n" \
|
" options: ssl3, tls1, tls1_1, tls12, dtls1, dtls12\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
" force_ciphersuite=<name> default: all enabled\n"\
|
" force_ciphersuite=<name> default: all enabled\n"\
|
||||||
" query_config=<name> return 0 if the specified\n" \
|
" query_config=<name> return 0 if the specified\n" \
|
||||||
|
@ -1107,8 +1107,8 @@ int main( int argc, char *argv[] )
|
||||||
else if( strcmp( q, "tls1_1" ) == 0 ||
|
else if( strcmp( q, "tls1_1" ) == 0 ||
|
||||||
strcmp( q, "dtls1" ) == 0 )
|
strcmp( q, "dtls1" ) == 0 )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 ||
|
else if( strcmp( q, "tls12" ) == 0 ||
|
||||||
strcmp( q, "dtls1_2" ) == 0 )
|
strcmp( q, "dtls12" ) == 0 )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
else
|
else
|
||||||
goto usage;
|
goto usage;
|
||||||
|
@ -1122,8 +1122,8 @@ int main( int argc, char *argv[] )
|
||||||
else if( strcmp( q, "tls1_1" ) == 0 ||
|
else if( strcmp( q, "tls1_1" ) == 0 ||
|
||||||
strcmp( q, "dtls1" ) == 0 )
|
strcmp( q, "dtls1" ) == 0 )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 ||
|
else if( strcmp( q, "tls12" ) == 0 ||
|
||||||
strcmp( q, "dtls1_2" ) == 0 )
|
strcmp( q, "dtls12" ) == 0 )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
else
|
else
|
||||||
goto usage;
|
goto usage;
|
||||||
|
@ -1163,7 +1163,7 @@ int main( int argc, char *argv[] )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
}
|
}
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 )
|
else if( strcmp( q, "tls12" ) == 0 )
|
||||||
{
|
{
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
|
@ -1174,7 +1174,7 @@ int main( int argc, char *argv[] )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
opt.transport = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
|
opt.transport = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
|
||||||
}
|
}
|
||||||
else if( strcmp( q, "dtls1_2" ) == 0 )
|
else if( strcmp( q, "dtls12" ) == 0 )
|
||||||
{
|
{
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#else
|
#else
|
||||||
#include MBEDTLS_CONFIG_FILE
|
#include MBEDTLS_CONFIG_FILE
|
||||||
#endif
|
#endif
|
||||||
|
#include "mbedtls/debug.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -164,6 +165,7 @@ void printf_dbg( const char *str, ... )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MBEDTLS_PRINTF_ATTRIBUTE( 1, 2 )
|
||||||
void printf_err( const char *str, ... )
|
void printf_err( const char *str, ... )
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -222,6 +224,12 @@ void parse_arguments( int argc, char *argv[] )
|
||||||
error_exit();
|
error_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( NULL != b64_file )
|
||||||
|
{
|
||||||
|
printf_err( "Cannot specify more than one file with -f\n" );
|
||||||
|
error_exit( );
|
||||||
|
}
|
||||||
|
|
||||||
if( ( b64_file = fopen( argv[i], "r" )) == NULL )
|
if( ( b64_file = fopen( argv[i], "r" )) == NULL )
|
||||||
{
|
{
|
||||||
printf_err( "Cannot find file \"%s\"\n", argv[i] );
|
printf_err( "Cannot find file \"%s\"\n", argv[i] );
|
||||||
|
@ -464,7 +472,8 @@ size_t read_next_b64_code( uint8_t **b64, size_t *max_len )
|
||||||
}
|
}
|
||||||
else if( len > *max_len )
|
else if( len > *max_len )
|
||||||
{
|
{
|
||||||
printf_err( "The code found is too large by %u bytes.\n", len - *max_len );
|
printf_err( "The code found is too large by %" MBEDTLS_PRINTF_SIZET " bytes.\n",
|
||||||
|
len - *max_len );
|
||||||
len = pad = 0;
|
len = pad = 0;
|
||||||
}
|
}
|
||||||
else if( len % 4 != 0 )
|
else if( len % 4 != 0 )
|
||||||
|
|
|
@ -507,12 +507,12 @@ int main( void )
|
||||||
" arc4=%%d default: (library default: 0)\n" \
|
" arc4=%%d default: (library default: 0)\n" \
|
||||||
" allow_sha1=%%d default: 0\n" \
|
" allow_sha1=%%d default: 0\n" \
|
||||||
" min_version=%%s default: (library default: tls1)\n" \
|
" min_version=%%s default: (library default: tls1)\n" \
|
||||||
" max_version=%%s default: (library default: tls1_2)\n" \
|
" max_version=%%s default: (library default: tls12)\n" \
|
||||||
" force_version=%%s default: \"\" (none)\n" \
|
" force_version=%%s default: \"\" (none)\n" \
|
||||||
" options: ssl3, tls1, tls1_1, tls1_2, dtls1, dtls1_2\n" \
|
" options: ssl3, tls1, tls1_1, tls12, dtls1, dtls12\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
" version_suites=a,b,c,d per-version ciphersuites\n" \
|
" version_suites=a,b,c,d per-version ciphersuites\n" \
|
||||||
" in order from ssl3 to tls1_2\n" \
|
" in order from ssl3 to tls12\n" \
|
||||||
" default: all enabled\n" \
|
" default: all enabled\n" \
|
||||||
" force_ciphersuite=<name> default: all enabled\n" \
|
" force_ciphersuite=<name> default: all enabled\n" \
|
||||||
" query_config=<name> return 0 if the specified\n" \
|
" query_config=<name> return 0 if the specified\n" \
|
||||||
|
@ -1741,8 +1741,8 @@ int main( int argc, char *argv[] )
|
||||||
else if( strcmp( q, "tls1_1" ) == 0 ||
|
else if( strcmp( q, "tls1_1" ) == 0 ||
|
||||||
strcmp( q, "dtls1" ) == 0 )
|
strcmp( q, "dtls1" ) == 0 )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 ||
|
else if( strcmp( q, "tls12" ) == 0 ||
|
||||||
strcmp( q, "dtls1_2" ) == 0 )
|
strcmp( q, "dtls12" ) == 0 )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
else
|
else
|
||||||
goto usage;
|
goto usage;
|
||||||
|
@ -1756,8 +1756,8 @@ int main( int argc, char *argv[] )
|
||||||
else if( strcmp( q, "tls1_1" ) == 0 ||
|
else if( strcmp( q, "tls1_1" ) == 0 ||
|
||||||
strcmp( q, "dtls1" ) == 0 )
|
strcmp( q, "dtls1" ) == 0 )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 ||
|
else if( strcmp( q, "tls12" ) == 0 ||
|
||||||
strcmp( q, "dtls1_2" ) == 0 )
|
strcmp( q, "dtls12" ) == 0 )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
else
|
else
|
||||||
goto usage;
|
goto usage;
|
||||||
|
@ -1797,7 +1797,7 @@ int main( int argc, char *argv[] )
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
}
|
}
|
||||||
else if( strcmp( q, "tls1_2" ) == 0 )
|
else if( strcmp( q, "tls12" ) == 0 )
|
||||||
{
|
{
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
|
@ -1808,7 +1808,7 @@ int main( int argc, char *argv[] )
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_2;
|
||||||
opt.transport = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
|
opt.transport = MBEDTLS_SSL_TRANSPORT_DATAGRAM;
|
||||||
}
|
}
|
||||||
else if( strcmp( q, "dtls1_2" ) == 0 )
|
else if( strcmp( q, "dtls12" ) == 0 )
|
||||||
{
|
{
|
||||||
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
opt.max_version = MBEDTLS_SSL_MINOR_VERSION_3;
|
||||||
|
|
10
scripts/ci.requirements.txt
Normal file
10
scripts/ci.requirements.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Python package requirements for Mbed TLS testing.
|
||||||
|
|
||||||
|
# Use a known version of Pylint, because new versions tend to add warnings
|
||||||
|
# that could start rejecting our code.
|
||||||
|
# 2.4.4 is the version in Ubuntu 20.04. It supports Python >=3.5.
|
||||||
|
pylint == 2.4.4
|
||||||
|
|
||||||
|
# Use the earliest version of mypy that works with our code base.
|
||||||
|
# See https://github.com/ARMmbed/mbedtls/pull/3953 .
|
||||||
|
mypy >= 0.780
|
10
scripts/maintainer.requirements.txt
Normal file
10
scripts/maintainer.requirements.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Python packages that are only useful to Mbed TLS maintainers.
|
||||||
|
|
||||||
|
-r ci.requirements.txt
|
||||||
|
|
||||||
|
# For source code analyses
|
||||||
|
clang
|
||||||
|
|
||||||
|
# For building some test vectors
|
||||||
|
pycryptodomex
|
||||||
|
pycryptodome-test-vectors
|
138
scripts/min_requirements.py
Executable file
138
scripts/min_requirements.py
Executable file
|
@ -0,0 +1,138 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Install all the required Python packages, with the minimum Python version.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copyright The Mbed TLS Contributors
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from mbedtls_dev import typing_util
|
||||||
|
|
||||||
|
def pylint_doesn_t_notice_that_certain_types_are_used_in_annotations(
|
||||||
|
_list: List[typing.Any],
|
||||||
|
) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Requirements:
|
||||||
|
"""Collect and massage Python requirements."""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.requirements = [] #type: List[str]
|
||||||
|
|
||||||
|
def adjust_requirement(self, req: str) -> str:
|
||||||
|
"""Adjust a requirement to the minimum specified version."""
|
||||||
|
# allow inheritance #pylint: disable=no-self-use
|
||||||
|
# If a requirement specifies a minimum version, impose that version.
|
||||||
|
req = re.sub(r'>=|~=', r'==', req)
|
||||||
|
return req
|
||||||
|
|
||||||
|
def add_file(self, filename: str) -> None:
|
||||||
|
"""Add requirements from the specified file.
|
||||||
|
|
||||||
|
This method supports a subset of pip's requirement file syntax:
|
||||||
|
* One requirement specifier per line, which is passed to
|
||||||
|
`adjust_requirement`.
|
||||||
|
* Comments (``#`` at the beginning of the line or after whitespace).
|
||||||
|
* ``-r FILENAME`` to include another file.
|
||||||
|
"""
|
||||||
|
for line in open(filename):
|
||||||
|
line = line.strip()
|
||||||
|
line = re.sub(r'(\A|\s+)#.*', r'', line)
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
m = re.match(r'-r\s+', line)
|
||||||
|
if m:
|
||||||
|
nested_file = os.path.join(os.path.dirname(filename),
|
||||||
|
line[m.end(0):])
|
||||||
|
self.add_file(nested_file)
|
||||||
|
continue
|
||||||
|
self.requirements.append(self.adjust_requirement(line))
|
||||||
|
|
||||||
|
def write(self, out: typing_util.Writable) -> None:
|
||||||
|
"""List the gathered requirements."""
|
||||||
|
for req in self.requirements:
|
||||||
|
out.write(req + '\n')
|
||||||
|
|
||||||
|
def install(
|
||||||
|
self,
|
||||||
|
pip_general_options: Optional[List[str]] = None,
|
||||||
|
pip_install_options: Optional[List[str]] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Call pip to install the requirements."""
|
||||||
|
if pip_general_options is None:
|
||||||
|
pip_general_options = []
|
||||||
|
if pip_install_options is None:
|
||||||
|
pip_install_options = []
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
# This is more complicated than it needs to be for the sake
|
||||||
|
# of Windows. Use a temporary file rather than the command line
|
||||||
|
# to avoid quoting issues. Use a temporary directory rather
|
||||||
|
# than NamedTemporaryFile because with a NamedTemporaryFile on
|
||||||
|
# Windows, the subprocess can't open the file because this process
|
||||||
|
# has an exclusive lock on it.
|
||||||
|
req_file_name = os.path.join(temp_dir, 'requirements.txt')
|
||||||
|
with open(req_file_name, 'w') as req_file:
|
||||||
|
self.write(req_file)
|
||||||
|
subprocess.check_call([sys.executable, '-m', 'pip'] +
|
||||||
|
pip_general_options +
|
||||||
|
['install'] + pip_install_options +
|
||||||
|
['-r', req_file_name])
|
||||||
|
|
||||||
|
DEFAULT_REQUIREMENTS_FILE = 'ci.requirements.txt'
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Command line entry point."""
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument('--no-act', '-n',
|
||||||
|
action='store_true',
|
||||||
|
help="Don't act, just print what will be done")
|
||||||
|
parser.add_argument('--pip-install-option',
|
||||||
|
action='append', dest='pip_install_options',
|
||||||
|
help="Pass this option to pip install")
|
||||||
|
parser.add_argument('--pip-option',
|
||||||
|
action='append', dest='pip_general_options',
|
||||||
|
help="Pass this general option to pip")
|
||||||
|
parser.add_argument('--user',
|
||||||
|
action='append_const', dest='pip_install_options',
|
||||||
|
const='--user',
|
||||||
|
help="Install to the Python user install directory"
|
||||||
|
" (short for --pip-install-option --user)")
|
||||||
|
parser.add_argument('files', nargs='*', metavar='FILE',
|
||||||
|
help="Requirement files"
|
||||||
|
" (default: {} in the script's directory)" \
|
||||||
|
.format(DEFAULT_REQUIREMENTS_FILE))
|
||||||
|
options = parser.parse_args()
|
||||||
|
if not options.files:
|
||||||
|
options.files = [os.path.join(os.path.dirname(__file__),
|
||||||
|
DEFAULT_REQUIREMENTS_FILE)]
|
||||||
|
reqs = Requirements()
|
||||||
|
for filename in options.files:
|
||||||
|
reqs.add_file(filename)
|
||||||
|
reqs.write(sys.stdout)
|
||||||
|
if not options.no_act:
|
||||||
|
reqs.install(pip_general_options=options.pip_general_options,
|
||||||
|
pip_install_options=options.pip_install_options)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
2
tests/.gitignore
vendored
2
tests/.gitignore
vendored
|
@ -13,3 +13,5 @@ include/test/instrument_record_status.h
|
||||||
src/*.o
|
src/*.o
|
||||||
src/drivers/*.o
|
src/drivers/*.o
|
||||||
src/libmbed*
|
src/libmbed*
|
||||||
|
|
||||||
|
libtestdriver1/*
|
||||||
|
|
|
@ -143,6 +143,7 @@ add_test_suite(pk)
|
||||||
add_test_suite(pkcs1_v15)
|
add_test_suite(pkcs1_v15)
|
||||||
add_test_suite(pkcs1_v21)
|
add_test_suite(pkcs1_v21)
|
||||||
add_test_suite(pkcs5)
|
add_test_suite(pkcs5)
|
||||||
|
add_test_suite(pkcs12)
|
||||||
add_test_suite(pkparse)
|
add_test_suite(pkparse)
|
||||||
add_test_suite(pkwrite)
|
add_test_suite(pkwrite)
|
||||||
add_test_suite(poly1305)
|
add_test_suite(poly1305)
|
||||||
|
|
|
@ -144,6 +144,7 @@ ifndef WINDOWS
|
||||||
rm -rf $(BINARIES) *.c *.datax
|
rm -rf $(BINARIES) *.c *.datax
|
||||||
rm -f src/*.o src/drivers/*.o src/libmbed*
|
rm -f src/*.o src/drivers/*.o src/libmbed*
|
||||||
rm -f include/test/instrument_record_status.h
|
rm -f include/test/instrument_record_status.h
|
||||||
|
rm -rf libtestdriver1
|
||||||
else
|
else
|
||||||
if exist *.c del /Q /F *.c
|
if exist *.c del /Q /F *.c
|
||||||
if exist *.exe del /Q /F *.exe
|
if exist *.exe del /Q /F *.exe
|
||||||
|
@ -160,6 +161,50 @@ check: $(BINARIES)
|
||||||
|
|
||||||
test: check
|
test: check
|
||||||
|
|
||||||
|
# Generate test library
|
||||||
|
|
||||||
|
# Perl code that is executed to transform each original line from a library
|
||||||
|
# source file into the corresponding line in the test driver copy of the
|
||||||
|
# library. Add a LIBTESTDRIVER1_/libtestdriver1_ to mbedtls_xxx and psa_xxx
|
||||||
|
# symbols.
|
||||||
|
define libtestdriver1_rewrite :=
|
||||||
|
s!^(\s*#\s*include\s*[\"<])(mbedtls|psa)/!$${1}libtestdriver1/include/$${2}/!; \
|
||||||
|
next if /^\s*#\s*include/; \
|
||||||
|
s/\b(?=MBEDTLS_|PSA_)/LIBTESTDRIVER1_/g; \
|
||||||
|
s/\b(?=mbedtls_|psa_)/libtestdriver1_/g;
|
||||||
|
endef
|
||||||
|
|
||||||
|
libtestdriver1.a:
|
||||||
|
# Copy the library and fake a 3rdparty Makefile include.
|
||||||
|
rm -Rf ./libtestdriver1
|
||||||
|
mkdir ./libtestdriver1
|
||||||
|
cp -Rf ../library ./libtestdriver1
|
||||||
|
cp -Rf ../include ./libtestdriver1
|
||||||
|
mkdir ./libtestdriver1/3rdparty
|
||||||
|
touch ./libtestdriver1/3rdparty/Makefile.inc
|
||||||
|
|
||||||
|
# Set the test driver base (minimal) configuration.
|
||||||
|
cp ./include/test/drivers/config_test_driver.h ./libtestdriver1/include/mbedtls/config.h
|
||||||
|
|
||||||
|
# Set the PSA cryptography configuration for the test library.
|
||||||
|
# It is set from the copied include/psa/crypto_config.h of the Mbed TLS
|
||||||
|
# library the test library is intended to be linked with extended by
|
||||||
|
# ./include/test/drivers/crypto_config_test_driver_extension.h to
|
||||||
|
# mirror the PSA_ACCEL_* macros.
|
||||||
|
mv ./libtestdriver1/include/psa/crypto_config.h ./libtestdriver1/include/psa/crypto_config.h.bak
|
||||||
|
head -n -1 ./libtestdriver1/include/psa/crypto_config.h.bak > ./libtestdriver1/include/psa/crypto_config.h
|
||||||
|
cat ./include/test/drivers/crypto_config_test_driver_extension.h >> ./libtestdriver1/include/psa/crypto_config.h
|
||||||
|
echo "#endif /* PSA_CRYPTO_CONFIG_H */" >> ./libtestdriver1/include/psa/crypto_config.h
|
||||||
|
|
||||||
|
# Prefix MBEDTLS_* PSA_* symbols with LIBTESTDRIVER1_ as well as
|
||||||
|
# mbedtls_* psa_* symbols with libtestdriver1_ to avoid symbol clash
|
||||||
|
# when this test driver library is linked with the Mbed TLS library.
|
||||||
|
perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/library/*.[ch]
|
||||||
|
perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/include/*/*.h
|
||||||
|
|
||||||
|
$(MAKE) -C ./libtestdriver1/library CFLAGS="-I../../ $(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a
|
||||||
|
cp ./libtestdriver1/library/libmbedcrypto.a ../library/libtestdriver1.a
|
||||||
|
|
||||||
ifdef RECORD_PSA_STATUS_COVERAGE_LOG
|
ifdef RECORD_PSA_STATUS_COVERAGE_LOG
|
||||||
include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile
|
include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile
|
||||||
echo " Gen $@"
|
echo " Gen $@"
|
||||||
|
|
|
@ -67,7 +67,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# default values for options
|
# default values for options
|
||||||
MODES="tls1 tls1_1 tls1_2 dtls1 dtls1_2"
|
MODES="tls1 tls1_1 tls12 dtls1 dtls12"
|
||||||
VERIFIES="NO YES"
|
VERIFIES="NO YES"
|
||||||
TYPES="ECDSA RSA PSK"
|
TYPES="ECDSA RSA PSK"
|
||||||
FILTER=""
|
FILTER=""
|
||||||
|
@ -156,7 +156,7 @@ log() {
|
||||||
# is_dtls <mode>
|
# is_dtls <mode>
|
||||||
is_dtls()
|
is_dtls()
|
||||||
{
|
{
|
||||||
test "$1" = "dtls1" -o "$1" = "dtls1_2"
|
test "$1" = "dtls1" -o "$1" = "dtls12"
|
||||||
}
|
}
|
||||||
|
|
||||||
# minor_ver <mode>
|
# minor_ver <mode>
|
||||||
|
@ -172,7 +172,7 @@ minor_ver()
|
||||||
tls1_1|dtls1)
|
tls1_1|dtls1)
|
||||||
echo 2
|
echo 2
|
||||||
;;
|
;;
|
||||||
tls1_2|dtls1_2)
|
tls12|dtls12)
|
||||||
echo 3
|
echo 3
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -881,14 +881,14 @@ setup_arguments()
|
||||||
"tls1_1")
|
"tls1_1")
|
||||||
G_PRIO_MODE="+VERS-TLS1.1"
|
G_PRIO_MODE="+VERS-TLS1.1"
|
||||||
;;
|
;;
|
||||||
"tls1_2")
|
"tls12")
|
||||||
G_PRIO_MODE="+VERS-TLS1.2"
|
G_PRIO_MODE="+VERS-TLS1.2"
|
||||||
;;
|
;;
|
||||||
"dtls1")
|
"dtls1")
|
||||||
G_PRIO_MODE="+VERS-DTLS1.0"
|
G_PRIO_MODE="+VERS-DTLS1.0"
|
||||||
G_MODE="-u"
|
G_MODE="-u"
|
||||||
;;
|
;;
|
||||||
"dtls1_2")
|
"dtls12")
|
||||||
G_PRIO_MODE="+VERS-DTLS1.2"
|
G_PRIO_MODE="+VERS-DTLS1.2"
|
||||||
G_MODE="-u"
|
G_MODE="-u"
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -160,7 +160,3 @@ RUN cd /tmp \
|
||||||
|
|
||||||
ENV GNUTLS_NEXT_CLI=/usr/local/gnutls-3.6.5/bin/gnutls-cli
|
ENV GNUTLS_NEXT_CLI=/usr/local/gnutls-3.6.5/bin/gnutls-cli
|
||||||
ENV GNUTLS_NEXT_SERV=/usr/local/gnutls-3.6.5/bin/gnutls-serv
|
ENV GNUTLS_NEXT_SERV=/usr/local/gnutls-3.6.5/bin/gnutls-serv
|
||||||
|
|
||||||
RUN pip3 install --no-cache-dir \
|
|
||||||
mbed-host-tests \
|
|
||||||
mock
|
|
||||||
|
|
55
tests/include/test/drivers/config_test_driver.h
Normal file
55
tests/include/test/drivers/config_test_driver.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Mbed TLS configuration for PSA test driver libraries. It includes:
|
||||||
|
* . the minimum set of modules needed by the PSA core.
|
||||||
|
* . the Mbed TLS configuration options that may need to be additionally
|
||||||
|
* enabled for the purpose of a specific test.
|
||||||
|
* . the PSA configuration file for the Mbed TLS library and its test drivers.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright The Mbed TLS Contributors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MBEDTLS_CONFIG_H
|
||||||
|
#define MBEDTLS_CONFIG_H
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
|
||||||
|
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MBEDTLS_PSA_CRYPTO_C
|
||||||
|
#define MBEDTLS_PSA_CRYPTO_CONFIG
|
||||||
|
|
||||||
|
/* PSA core mandatory configuration options */
|
||||||
|
#define MBEDTLS_CIPHER_C
|
||||||
|
#define MBEDTLS_AES_C
|
||||||
|
#define MBEDTLS_SHA256_C
|
||||||
|
#define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1
|
||||||
|
#define MBEDTLS_CTR_DRBG_C
|
||||||
|
#define MBEDTLS_ENTROPY_C
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configuration options that may need to be additionally enabled for the
|
||||||
|
* purpose of a specific set of tests.
|
||||||
|
*/
|
||||||
|
//#define MBEDTLS_SHA1_C
|
||||||
|
//#define MBEDTLS_SHA512_C
|
||||||
|
//#define MBEDTLS_PEM_PARSE_C
|
||||||
|
//#define MBEDTLS_BASE64_C
|
||||||
|
|
||||||
|
#include "mbedtls/config_psa.h"
|
||||||
|
#include "mbedtls/check_config.h"
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_CONFIG_H */
|
231
tests/include/test/drivers/crypto_config_test_driver_extension.h
Normal file
231
tests/include/test/drivers/crypto_config_test_driver_extension.h
Normal file
|
@ -0,0 +1,231 @@
|
||||||
|
/**
|
||||||
|
* This file is intended to be used to build PSA test driver libraries. It is
|
||||||
|
* intended to be appended by the test build system to the crypto_config.h file
|
||||||
|
* of the Mbed TLS library the test library will be linked to. It mirrors the
|
||||||
|
* PSA_ACCEL_* macros defining the cryptographic operations the test library
|
||||||
|
* supports.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CBC_PKCS7)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CFB)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_CFB)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_CFB
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CFB 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_CTR)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_CTR)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_CTR
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CTR 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_ECDSA)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_ECDSA
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_ECDSA 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_MD2)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD2)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_MD2
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_MD2 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_MD4)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD4)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_MD4
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_MD4 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_MD5)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_MD5
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_MD5 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_OFB)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_OFB)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_OFB
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_OFB 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_RIPEMD160)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_RIPEMD160
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_RSA_PSS)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_SHA_1)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_1 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_SHA_224)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_224 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_SHA_256)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_256 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_SHA_384)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_384 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_SHA_512)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_512 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_ALG_XTS)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_XTS)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_XTS
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_XTS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR)
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR)
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CBC_MAC 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CCM 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_CMAC 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_ECB_NO_PADDING 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_ECDH 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_GCM 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_HKDF 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_HMAC 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_STREAM_CIPHER 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS 1
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DERIVE 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_HMAC 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DES 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RAW_DATA 1
|
||||||
|
#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY 1
|
|
@ -74,7 +74,7 @@ psa_status_t mbedtls_test_transparent_hash_finish(
|
||||||
size_t *hash_length );
|
size_t *hash_length );
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_hash_abort(
|
psa_status_t mbedtls_test_transparent_hash_abort(
|
||||||
mbedtls_psa_hash_operation_t *operation );
|
mbedtls_transparent_test_driver_hash_operation_t *operation );
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */
|
#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */
|
||||||
|
|
|
@ -56,6 +56,11 @@ static inline mbedtls_test_driver_key_management_hooks_t
|
||||||
extern mbedtls_test_driver_key_management_hooks_t
|
extern mbedtls_test_driver_key_management_hooks_t
|
||||||
mbedtls_test_driver_key_management_hooks;
|
mbedtls_test_driver_key_management_hooks;
|
||||||
|
|
||||||
|
psa_status_t mbedtls_test_transparent_init( void );
|
||||||
|
void mbedtls_test_transparent_free( void );
|
||||||
|
psa_status_t mbedtls_test_opaque_init( void );
|
||||||
|
void mbedtls_test_opaque_free( void );
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_generate_key(
|
psa_status_t mbedtls_test_transparent_generate_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
uint8_t *key, size_t key_size, size_t *key_length );
|
uint8_t *key, size_t key_size, size_t *key_length );
|
||||||
|
|
|
@ -56,6 +56,34 @@
|
||||||
#undef KNOWN_SUPPORTED_HASH_ALG
|
#undef KNOWN_SUPPORTED_HASH_ALG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** \def KNOWN_MBEDTLS_SUPPORTED_HASH_ALG
|
||||||
|
*
|
||||||
|
* A hash algorithm that is known to be supported by Mbed TLS APIs.
|
||||||
|
*
|
||||||
|
* This is used in some smoke tests where the hash algorithm is used as
|
||||||
|
* part of another algorithm like a signature algorithm and the hashing is
|
||||||
|
* completed through an Mbed TLS hash API, not the PSA one.
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_MD2_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD2
|
||||||
|
#elif defined(MBEDTLS_MD4_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD4
|
||||||
|
#elif defined(MBEDTLS_MD5_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_MD5
|
||||||
|
/* MBEDTLS_RIPEMD160_C omitted. This is necessary for the sake of
|
||||||
|
* exercise_signature_key() because Mbed TLS doesn't support RIPEMD160
|
||||||
|
* in RSA PKCS#1v1.5 signatures. A RIPEMD160-only configuration would be
|
||||||
|
* implausible anyway. */
|
||||||
|
#elif defined(MBEDTLS_SHA1_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_1
|
||||||
|
#elif defined(MBEDTLS_SHA256_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_256
|
||||||
|
#elif defined(MBEDTLS_SHA512_C)
|
||||||
|
#define KNOWN_MBEDTLS_SUPPORTED_HASH_ALG PSA_ALG_SHA_512
|
||||||
|
#else
|
||||||
|
#undef KNOWN_MBEDLTS_SUPPORTED_HASH_ALG
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \def KNOWN_SUPPORTED_BLOCK_CIPHER
|
/** \def KNOWN_SUPPORTED_BLOCK_CIPHER
|
||||||
*
|
*
|
||||||
* A block cipher that is known to be supported.
|
* A block cipher that is known to be supported.
|
||||||
|
|
|
@ -1015,7 +1015,7 @@ component_test_sslv3 () {
|
||||||
make test
|
make test
|
||||||
|
|
||||||
msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
|
msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
|
||||||
tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
|
tests/compat.sh -m 'tls1 tls1_1 tls12 dtls1 dtls12'
|
||||||
env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
|
env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
|
||||||
|
|
||||||
msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
|
msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
|
||||||
|
@ -1092,7 +1092,7 @@ component_test_no_ctr_drbg_classic () {
|
||||||
tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
|
tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
|
||||||
|
|
||||||
msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
|
msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
|
||||||
tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
|
tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
|
||||||
}
|
}
|
||||||
|
|
||||||
component_test_no_ctr_drbg_use_psa () {
|
component_test_no_ctr_drbg_use_psa () {
|
||||||
|
@ -1114,7 +1114,7 @@ component_test_no_ctr_drbg_use_psa () {
|
||||||
tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
|
tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
|
||||||
|
|
||||||
msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
|
msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
|
||||||
tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
|
tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
|
||||||
}
|
}
|
||||||
|
|
||||||
component_test_no_hmac_drbg_classic () {
|
component_test_no_hmac_drbg_classic () {
|
||||||
|
@ -1141,7 +1141,7 @@ component_test_no_hmac_drbg_classic () {
|
||||||
# To save time, only test one protocol version, since this part of
|
# To save time, only test one protocol version, since this part of
|
||||||
# the protocol is identical in (D)TLS up to 1.2.
|
# the protocol is identical in (D)TLS up to 1.2.
|
||||||
msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
|
msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
|
||||||
tests/compat.sh -m tls1_2 -t 'ECDSA'
|
tests/compat.sh -m tls12 -t 'ECDSA'
|
||||||
}
|
}
|
||||||
|
|
||||||
component_test_no_hmac_drbg_use_psa () {
|
component_test_no_hmac_drbg_use_psa () {
|
||||||
|
@ -1168,7 +1168,7 @@ component_test_no_hmac_drbg_use_psa () {
|
||||||
# To save time, only test one protocol version, since this part of
|
# To save time, only test one protocol version, since this part of
|
||||||
# the protocol is identical in (D)TLS up to 1.2.
|
# the protocol is identical in (D)TLS up to 1.2.
|
||||||
msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
|
msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
|
||||||
tests/compat.sh -m tls1_2 -t 'ECDSA'
|
tests/compat.sh -m tls12 -t 'ECDSA'
|
||||||
}
|
}
|
||||||
|
|
||||||
component_test_psa_external_rng_no_drbg_classic () {
|
component_test_psa_external_rng_no_drbg_classic () {
|
||||||
|
@ -1591,15 +1591,179 @@ component_test_no_use_psa_crypto_full_cmake_asan() {
|
||||||
env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
|
env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
|
||||||
}
|
}
|
||||||
|
|
||||||
component_test_psa_crypto_config_basic() {
|
component_test_psa_crypto_config_accel_ecdsa () {
|
||||||
# Test the library excluding all Mbed TLS cryptographic support for which
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
|
||||||
# we have an accelerator support. Acceleration is faked with the
|
|
||||||
# transparent test driver.
|
# Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
|
||||||
msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
|
# partial support for cipher operations in the driver test library.
|
||||||
scripts/config.py full
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
|
||||||
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||||
|
|
||||||
|
# SHA384 needed for some ECDSA signature tests.
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
|
||||||
|
|
||||||
|
loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
|
||||||
|
loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
||||||
|
make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
|
||||||
|
|
||||||
|
# Restore test driver base configuration
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
|
||||||
|
|
||||||
scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
||||||
scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
|
scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
|
||||||
|
scripts/config.py unset MBEDTLS_ECDSA_C
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
|
||||||
|
|
||||||
|
loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
|
||||||
|
make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
|
||||||
|
|
||||||
|
unset loc_accel_flags
|
||||||
|
unset loc_accel_list
|
||||||
|
|
||||||
|
if_build_succeeded not grep mbedtls_ecdsa_ library/ecdsa.o
|
||||||
|
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
|
||||||
|
make test
|
||||||
|
}
|
||||||
|
|
||||||
|
component_test_psa_crypto_config_accel_rsa_signature () {
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
|
||||||
|
|
||||||
|
# Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
|
||||||
|
# partial support for cipher operations in the driver test library.
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||||
|
|
||||||
|
# It seems it is not possible to remove only the support for RSA signature
|
||||||
|
# in the library. Thus we have to remove all RSA support (signature and
|
||||||
|
# encryption/decryption). AS there is no driver support for asymmetric
|
||||||
|
# encryption/decryption so far remove RSA encryption/decryption from the
|
||||||
|
# application algorithm list.
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
|
||||||
|
|
||||||
|
# Make sure both the library and the test library support the SHA hash
|
||||||
|
# algorithms and only those ones (SHA256 is included by default). That way:
|
||||||
|
# - the test library can compute the RSA signatures even in the case of a
|
||||||
|
# composite RSA signature algorithm based on a SHA hash (no other hash
|
||||||
|
# used in the unit tests).
|
||||||
|
# - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
|
||||||
|
# fulfilled as the hash SHA algorithm is supported by the library, and
|
||||||
|
# thus the tests are run, not skipped.
|
||||||
|
# - when testing a signature key with an algorithm wildcard built from
|
||||||
|
# PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
|
||||||
|
# algorithm based on the hashes supported by the library is also
|
||||||
|
# supported by the test library.
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
|
||||||
|
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
|
||||||
|
# We need PEM parsing in the test library as well to support the import
|
||||||
|
# of PEM encoded RSA keys.
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
|
||||||
|
|
||||||
|
loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
|
||||||
|
loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
||||||
|
make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
|
||||||
|
|
||||||
|
# Restore test driver base configuration
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
|
||||||
|
scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
|
||||||
|
|
||||||
|
|
||||||
|
# Mbed TLS library build
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
||||||
|
|
||||||
|
# Remove RSA support and its dependencies
|
||||||
|
scripts/config.py unset MBEDTLS_PKCS1_V15
|
||||||
|
scripts/config.py unset MBEDTLS_PKCS1_V21
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||||
|
scripts/config.py unset MBEDTLS_RSA_C
|
||||||
|
scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
||||||
|
|
||||||
|
scripts/config.py unset MBEDTLS_MD2_C
|
||||||
|
scripts/config.py unset MBEDTLS_MD4_C
|
||||||
|
scripts/config.py unset MBEDTLS_MD5_C
|
||||||
|
scripts/config.py unset MBEDTLS_RIPEMD160_C
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
|
||||||
|
|
||||||
|
loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
|
||||||
|
make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
|
||||||
|
|
||||||
|
unset loc_accel_flags
|
||||||
|
unset loc_accel_list
|
||||||
|
|
||||||
|
if_build_succeeded not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
|
||||||
|
if_build_succeeded not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
|
||||||
|
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
|
||||||
|
make test
|
||||||
|
}
|
||||||
|
|
||||||
|
component_test_psa_crypto_config_accel_hash () {
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
|
||||||
|
|
||||||
|
# Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
|
||||||
|
# partial support for cipher operations in the driver test library.
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||||
|
|
||||||
|
loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
|
||||||
|
loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
||||||
|
make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
|
||||||
|
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
||||||
|
scripts/config.py unset MBEDTLS_MD2_C
|
||||||
|
scripts/config.py unset MBEDTLS_MD4_C
|
||||||
|
scripts/config.py unset MBEDTLS_MD5_C
|
||||||
|
scripts/config.py unset MBEDTLS_RIPEMD160_C
|
||||||
|
scripts/config.py unset MBEDTLS_SHA1_C
|
||||||
|
# Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
|
||||||
|
scripts/config.py unset MBEDTLS_SHA512_C
|
||||||
|
# Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
|
||||||
|
# Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
|
||||||
|
scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
|
||||||
|
loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
|
||||||
|
make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
|
||||||
|
|
||||||
|
unset loc_accel_flags
|
||||||
|
unset loc_accel_list
|
||||||
|
|
||||||
|
if_build_succeeded not grep mbedtls_sha512_init library/sha512.o
|
||||||
|
if_build_succeeded not grep mbedtls_sha1_init library/sha1.o
|
||||||
|
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
|
||||||
|
make test
|
||||||
|
}
|
||||||
|
|
||||||
|
component_test_psa_crypto_config_accel_cipher () {
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
|
||||||
|
|
||||||
|
loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
|
||||||
|
loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
|
||||||
|
make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
|
||||||
|
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||||
|
scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
|
||||||
|
|
||||||
# There is no intended accelerator support for ALG STREAM_CIPHER and
|
# There is no intended accelerator support for ALG STREAM_CIPHER and
|
||||||
# ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
|
# ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
|
||||||
|
@ -1608,26 +1772,25 @@ component_test_psa_crypto_config_basic() {
|
||||||
# PSA configuration options.
|
# PSA configuration options.
|
||||||
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
|
||||||
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
|
||||||
|
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
|
||||||
|
|
||||||
# Don't test DES encryption as:
|
scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
|
||||||
# 1) It is not an issue if we don't test all cipher types here.
|
scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
|
||||||
# 2) That way we don't have to modify in psa_crypto.c the compilation
|
scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
|
||||||
# guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
|
scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
|
||||||
# available to the test driver. Modifications that we would need to
|
scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
|
||||||
# revert when we move to compile the test driver separately.
|
scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
|
||||||
# We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
|
|
||||||
# suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
|
|
||||||
scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
|
|
||||||
scripts/config.py unset MBEDTLS_DES_C
|
scripts/config.py unset MBEDTLS_DES_C
|
||||||
|
|
||||||
loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
|
loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
|
||||||
loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
|
make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
|
||||||
loc_cflags="${loc_cflags} -I../tests/include -O2"
|
|
||||||
|
|
||||||
make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
|
unset loc_accel_flags
|
||||||
unset loc_cflags
|
unset loc_accel_list
|
||||||
|
|
||||||
msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
|
if_build_succeeded not grep mbedtls_des* library/des.o
|
||||||
|
|
||||||
|
msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
|
||||||
make test
|
make test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2777,6 +2940,36 @@ component_test_valgrind () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
support_test_cmake_out_of_source () {
|
||||||
|
distrib_id=""
|
||||||
|
distrib_ver=""
|
||||||
|
distrib_ver_minor=""
|
||||||
|
distrib_ver_major=""
|
||||||
|
|
||||||
|
# Attempt to parse lsb-release to find out distribution and version. If not
|
||||||
|
# found this should fail safe (test is supported).
|
||||||
|
if [[ -f /etc/lsb-release ]]; then
|
||||||
|
|
||||||
|
while read -r lsb_line; do
|
||||||
|
case "$lsb_line" in
|
||||||
|
"DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
|
||||||
|
"DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
|
||||||
|
esac
|
||||||
|
done < /etc/lsb-release
|
||||||
|
|
||||||
|
distrib_ver_major="${distrib_ver%%.*}"
|
||||||
|
distrib_ver="${distrib_ver#*.}"
|
||||||
|
distrib_ver_minor="${distrib_ver%%.*}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Running the out of source CMake test on Ubuntu 16.04 using more than one
|
||||||
|
# processor (as the CI does) can create a race condition whereby the build
|
||||||
|
# fails to see a generated file, despite that file actually having been
|
||||||
|
# generated. This problem appears to go away with 18.04 or newer, so make
|
||||||
|
# the out of source tests unsupported on Ubuntu 16.04.
|
||||||
|
[ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
|
||||||
|
}
|
||||||
|
|
||||||
component_test_cmake_out_of_source () {
|
component_test_cmake_out_of_source () {
|
||||||
msg "build: cmake 'out-of-source' build"
|
msg "build: cmake 'out-of-source' build"
|
||||||
MBEDTLS_ROOT_DIR="$PWD"
|
MBEDTLS_ROOT_DIR="$PWD"
|
||||||
|
|
|
@ -457,50 +457,87 @@ class CodeParser():
|
||||||
|
|
||||||
return enum_consts
|
return enum_consts
|
||||||
|
|
||||||
def parse_identifiers(self, include, exclude=None):
|
IGNORED_CHUNK_REGEX = re.compile('|'.join([
|
||||||
"""
|
r'/\*.*?\*/', # block comment entirely on one line
|
||||||
Parse all lines of a header where a function/enum/struct/union/typedef
|
r'//.*', # line comment
|
||||||
identifier is declared, based on some regex and heuristics. Highly
|
r'(?P<string>")(?:[^\\\"]|\\.)*"', # string literal
|
||||||
dependent on formatting style.
|
]))
|
||||||
|
|
||||||
Args:
|
def strip_comments_and_literals(self, line, in_block_comment):
|
||||||
* include: A List of glob expressions to look for files through.
|
"""Strip comments and string literals from line.
|
||||||
* exclude: A List of glob expressions for excluding files.
|
|
||||||
|
|
||||||
Returns a List of Match objects with identifiers.
|
Continuation lines are not supported.
|
||||||
|
|
||||||
|
If in_block_comment is true, assume that the line starts inside a
|
||||||
|
block comment.
|
||||||
|
|
||||||
|
Return updated values of (line, in_block_comment) where:
|
||||||
|
* Comments in line have been replaced by a space (or nothing at the
|
||||||
|
start or end of the line).
|
||||||
|
* String contents have been removed.
|
||||||
|
* in_block_comment indicates whether the line ends inside a block
|
||||||
|
comment that continues on the next line.
|
||||||
"""
|
"""
|
||||||
identifier_regex = re.compile(
|
|
||||||
|
# Terminate current multiline comment?
|
||||||
|
if in_block_comment:
|
||||||
|
m = re.search(r"\*/", line)
|
||||||
|
if m:
|
||||||
|
in_block_comment = False
|
||||||
|
line = line[m.end(0):]
|
||||||
|
else:
|
||||||
|
return '', True
|
||||||
|
|
||||||
|
# Remove full comments and string literals.
|
||||||
|
# Do it all together to handle cases like "/*" correctly.
|
||||||
|
# Note that continuation lines are not supported.
|
||||||
|
line = re.sub(self.IGNORED_CHUNK_REGEX,
|
||||||
|
lambda s: '""' if s.group('string') else ' ',
|
||||||
|
line)
|
||||||
|
|
||||||
|
# Start an unfinished comment?
|
||||||
|
# (If `/*` was part of a complete comment, it's already been removed.)
|
||||||
|
m = re.search(r"/\*", line)
|
||||||
|
if m:
|
||||||
|
in_block_comment = True
|
||||||
|
line = line[:m.start(0)]
|
||||||
|
|
||||||
|
return line, in_block_comment
|
||||||
|
|
||||||
|
IDENTIFIER_REGEX = re.compile('|'.join([
|
||||||
# Match " something(a" or " *something(a". Functions.
|
# Match " something(a" or " *something(a". Functions.
|
||||||
# Assumptions:
|
# Assumptions:
|
||||||
# - function definition from return type to one of its arguments is
|
# - function definition from return type to one of its arguments is
|
||||||
# all on one line
|
# all on one line
|
||||||
# - function definition line only contains alphanumeric, asterisk,
|
# - function definition line only contains alphanumeric, asterisk,
|
||||||
# underscore, and open bracket
|
# underscore, and open bracket
|
||||||
r".* \**(\w+) *\( *\w|"
|
r".* \**(\w+) *\( *\w",
|
||||||
# Match "(*something)(".
|
# Match "(*something)(".
|
||||||
r".*\( *\* *(\w+) *\) *\(|"
|
r".*\( *\* *(\w+) *\) *\(",
|
||||||
# Match names of named data structures.
|
# Match names of named data structures.
|
||||||
r"(?:typedef +)?(?:struct|union|enum) +(\w+)(?: *{)?$|"
|
r"(?:typedef +)?(?:struct|union|enum) +(\w+)(?: *{)?$",
|
||||||
# Match names of typedef instances, after closing bracket.
|
# Match names of typedef instances, after closing bracket.
|
||||||
r"}? *(\w+)[;[].*"
|
r"}? *(\w+)[;[].*",
|
||||||
)
|
]))
|
||||||
# The regex below is indented for clarity.
|
# The regex below is indented for clarity.
|
||||||
exclusion_lines = re.compile(
|
EXCLUSION_LINES = re.compile("|".join([
|
||||||
r"^("
|
r"extern +\"C\"",
|
||||||
r"extern +\"C\"|" # pylint: disable=bad-continuation
|
r"(typedef +)?(struct|union|enum)( *{)?$",
|
||||||
r"(typedef +)?(struct|union|enum)( *{)?$|"
|
r"} *;?$",
|
||||||
r"} *;?$|"
|
r"$",
|
||||||
r"$|"
|
r"//",
|
||||||
r"//|"
|
r"#",
|
||||||
r"#"
|
]))
|
||||||
r")"
|
|
||||||
)
|
|
||||||
|
|
||||||
files = self.get_files(include, exclude)
|
def parse_identifiers_in_file(self, header_file, identifiers):
|
||||||
self.log.debug("Looking for identifiers in {} files".format(len(files)))
|
"""
|
||||||
|
Parse all lines of a header where a function/enum/struct/union/typedef
|
||||||
|
identifier is declared, based on some regex and heuristics. Highly
|
||||||
|
dependent on formatting style.
|
||||||
|
|
||||||
|
Append found matches to the list ``identifiers``.
|
||||||
|
"""
|
||||||
|
|
||||||
identifiers = []
|
|
||||||
for header_file in files:
|
|
||||||
with open(header_file, "r", encoding="utf-8") as header:
|
with open(header_file, "r", encoding="utf-8") as header:
|
||||||
in_block_comment = False
|
in_block_comment = False
|
||||||
# The previous line variable is used for concatenating lines
|
# The previous line variable is used for concatenating lines
|
||||||
|
@ -509,25 +546,15 @@ class CodeParser():
|
||||||
previous_line = ""
|
previous_line = ""
|
||||||
|
|
||||||
for line_no, line in enumerate(header):
|
for line_no, line in enumerate(header):
|
||||||
# Skip parsing this line if a block comment ends on it,
|
line, in_block_comment = \
|
||||||
# but don't skip if it has just started -- there is a chance
|
self.strip_comments_and_literals(line, in_block_comment)
|
||||||
# it ends on the same line.
|
|
||||||
if re.search(r"/\*", line):
|
|
||||||
in_block_comment = not in_block_comment
|
|
||||||
if re.search(r"\*/", line):
|
|
||||||
in_block_comment = not in_block_comment
|
|
||||||
continue
|
|
||||||
|
|
||||||
if in_block_comment:
|
if self.EXCLUSION_LINES.match(line):
|
||||||
previous_line = ""
|
|
||||||
continue
|
|
||||||
|
|
||||||
if exclusion_lines.search(line):
|
|
||||||
previous_line = ""
|
previous_line = ""
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If the line contains only space-separated alphanumeric
|
# If the line contains only space-separated alphanumeric
|
||||||
# characters (or underscore, asterisk, or, open bracket),
|
# characters (or underscore, asterisk, or open parenthesis),
|
||||||
# and nothing else, high chance it's a declaration that
|
# and nothing else, high chance it's a declaration that
|
||||||
# continues on the next line
|
# continues on the next line
|
||||||
if re.search(r"^([\w\*\(]+\s+)+$", line):
|
if re.search(r"^([\w\*\(]+\s+)+$", line):
|
||||||
|
@ -546,7 +573,7 @@ class CodeParser():
|
||||||
if line[0] == " ":
|
if line[0] == " ":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
identifier = identifier_regex.search(line)
|
identifier = self.IDENTIFIER_REGEX.search(line)
|
||||||
|
|
||||||
if not identifier:
|
if not identifier:
|
||||||
continue
|
continue
|
||||||
|
@ -563,6 +590,26 @@ class CodeParser():
|
||||||
identifier.span(),
|
identifier.span(),
|
||||||
group))
|
group))
|
||||||
|
|
||||||
|
def parse_identifiers(self, include, exclude=None):
|
||||||
|
"""
|
||||||
|
Parse all lines of a header where a function/enum/struct/union/typedef
|
||||||
|
identifier is declared, based on some regex and heuristics. Highly
|
||||||
|
dependent on formatting style.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
* include: A List of glob expressions to look for files through.
|
||||||
|
* exclude: A List of glob expressions for excluding files.
|
||||||
|
|
||||||
|
Returns a List of Match objects with identifiers.
|
||||||
|
"""
|
||||||
|
|
||||||
|
files = self.get_files(include, exclude)
|
||||||
|
self.log.debug("Looking for identifiers in {} files".format(len(files)))
|
||||||
|
|
||||||
|
identifiers = []
|
||||||
|
for header_file in files:
|
||||||
|
self.parse_identifiers_in_file(header_file, identifiers)
|
||||||
|
|
||||||
return identifiers
|
return identifiers
|
||||||
|
|
||||||
def parse_symbols(self):
|
def parse_symbols(self):
|
||||||
|
@ -779,7 +826,8 @@ class NameChecker():
|
||||||
match.name
|
match.name
|
||||||
for match
|
for match
|
||||||
in self.parse_result["macros"] + self.parse_result["enum_consts"]}
|
in self.parse_result["macros"] + self.parse_result["enum_consts"]}
|
||||||
typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$")
|
typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$|"
|
||||||
|
r"MBEDTLS_TEST_LIBTESTDRIVER*")
|
||||||
|
|
||||||
for name_match in self.parse_result["mbed_words"]:
|
for name_match in self.parse_result["mbed_words"]:
|
||||||
found = name_match.name in all_caps_names
|
found = name_match.name in all_caps_names
|
||||||
|
|
|
@ -29,7 +29,7 @@ use strict;
|
||||||
|
|
||||||
my %configs = (
|
my %configs = (
|
||||||
'config-ccm-psk-tls1_2.h' => {
|
'config-ccm-psk-tls1_2.h' => {
|
||||||
'compat' => '-m tls1_2 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
|
'compat' => '-m tls12 -f \'^TLS-PSK-WITH-AES-...-CCM-8\'',
|
||||||
},
|
},
|
||||||
'config-mini-tls1_1.h' => {
|
'config-mini-tls1_1.h' => {
|
||||||
'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #'
|
'compat' => '-m tls1_1 -f \'^DES-CBC3-SHA$\|^TLS-RSA-WITH-3DES-EDE-CBC-SHA$\'', #'
|
||||||
|
@ -37,7 +37,7 @@ my %configs = (
|
||||||
'config-no-entropy.h' => {
|
'config-no-entropy.h' => {
|
||||||
},
|
},
|
||||||
'config-suite-b.h' => {
|
'config-suite-b.h' => {
|
||||||
'compat' => "-m tls1_2 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
|
'compat' => "-m tls12 -f 'ECDHE-ECDSA.*AES.*GCM' -p mbedTLS",
|
||||||
},
|
},
|
||||||
'config-symmetric-only.h' => {
|
'config-symmetric-only.h' => {
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
|
|
||||||
#include "test/drivers/hash.h"
|
#include "test/drivers/hash.h"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
|
#include "libtestdriver1/library/psa_crypto_hash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
mbedtls_test_driver_hash_hooks_t
|
mbedtls_test_driver_hash_hooks_t
|
||||||
mbedtls_test_driver_hash_hooks = MBEDTLS_TEST_DRIVER_HASH_INIT;
|
mbedtls_test_driver_hash_hooks = MBEDTLS_TEST_DRIVER_HASH_INIT;
|
||||||
|
|
||||||
|
@ -45,10 +49,26 @@ psa_status_t mbedtls_test_transparent_hash_compute(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_compute(
|
libtestdriver1_mbedtls_psa_hash_compute(
|
||||||
alg, input, input_length,
|
alg, input, input_length,
|
||||||
hash, hash_size, hash_length );
|
hash, hash_size, hash_length );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_compute(
|
||||||
|
alg, input, input_length,
|
||||||
|
hash, hash_size, hash_length );
|
||||||
|
#else
|
||||||
|
(void) alg;
|
||||||
|
(void) input;
|
||||||
|
(void) input_length;
|
||||||
|
(void) hash;
|
||||||
|
(void) hash_size;
|
||||||
|
(void) hash_length;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
@ -67,8 +87,18 @@ psa_status_t mbedtls_test_transparent_hash_setup(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_setup( operation, alg );
|
libtestdriver1_mbedtls_psa_hash_setup( operation, alg );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_setup( operation, alg );
|
||||||
|
#else
|
||||||
|
(void) operation;
|
||||||
|
(void) alg;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
@ -87,9 +117,19 @@ psa_status_t mbedtls_test_transparent_hash_clone(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_clone( source_operation,
|
libtestdriver1_mbedtls_psa_hash_clone( source_operation,
|
||||||
target_operation );
|
target_operation );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_clone( source_operation, target_operation );
|
||||||
|
#else
|
||||||
|
(void) source_operation;
|
||||||
|
(void) target_operation;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
@ -109,9 +149,20 @@ psa_status_t mbedtls_test_transparent_hash_update(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_update(
|
libtestdriver1_mbedtls_psa_hash_update(
|
||||||
operation, input, input_length );
|
operation, input, input_length );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_update( operation, input, input_length );
|
||||||
|
#else
|
||||||
|
(void) operation;
|
||||||
|
(void) input;
|
||||||
|
(void) input_length;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
@ -132,9 +183,21 @@ psa_status_t mbedtls_test_transparent_hash_finish(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_finish(
|
libtestdriver1_mbedtls_psa_hash_finish(
|
||||||
operation, hash, hash_size, hash_length );
|
operation, hash, hash_size, hash_length );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_finish( operation, hash, hash_size, hash_length );
|
||||||
|
#else
|
||||||
|
(void) operation;
|
||||||
|
(void) hash;
|
||||||
|
(void) hash_size;
|
||||||
|
(void) hash_length;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
@ -152,8 +215,17 @@ psa_status_t mbedtls_test_transparent_hash_abort(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
mbedtls_test_driver_hash_hooks.driver_status =
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
mbedtls_transparent_test_driver_hash_abort( operation );
|
libtestdriver1_mbedtls_psa_hash_abort( operation );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status =
|
||||||
|
mbedtls_psa_hash_abort( operation );
|
||||||
|
#else
|
||||||
|
(void) operation;
|
||||||
|
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
|
|
||||||
#include "test/random.h"
|
#include "test/random.h"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
|
#include "libtestdriver1/library/psa_crypto_cipher.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
|
mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks =
|
||||||
|
@ -70,10 +74,21 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_encrypt(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_encrypt(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
alg, iv, iv_length, input, input_length,
|
||||||
|
output, output_size, output_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_encrypt(
|
||||||
attributes, key_buffer, key_buffer_size,
|
attributes, key_buffer, key_buffer_size,
|
||||||
alg, iv, iv_length, input, input_length,
|
alg, iv, iv_length, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
||||||
|
@ -105,10 +120,21 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_decrypt(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_decrypt(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
alg, input, input_length,
|
||||||
|
output, output_size, output_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_decrypt(
|
||||||
attributes, key_buffer, key_buffer_size,
|
attributes, key_buffer, key_buffer_size,
|
||||||
alg, input, input_length,
|
alg, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
||||||
|
@ -128,8 +154,18 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return ( mbedtls_transparent_test_driver_cipher_encrypt_setup(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
|
||||||
|
operation,
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key, key_length, alg ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_encrypt_setup(
|
||||||
operation, attributes, key, key_length, alg ) );
|
operation, attributes, key, key_length, alg ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||||
|
@ -143,8 +179,18 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return ( mbedtls_transparent_test_driver_cipher_decrypt_setup(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
|
||||||
|
operation,
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key, key_length, alg ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_decrypt_setup(
|
||||||
operation, attributes, key, key_length, alg ) );
|
operation, attributes, key, key_length, alg ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_abort(
|
psa_status_t mbedtls_test_transparent_cipher_abort(
|
||||||
|
@ -155,7 +201,12 @@ psa_status_t mbedtls_test_transparent_cipher_abort(
|
||||||
if( operation->alg == 0 )
|
if( operation->alg == 0 )
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
|
|
||||||
mbedtls_transparent_test_driver_cipher_abort( operation );
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
libtestdriver1_mbedtls_psa_cipher_abort( operation );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
mbedtls_psa_cipher_abort( operation );
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Wiping the entire struct here, instead of member-by-member. This is
|
/* Wiping the entire struct here, instead of member-by-member. This is
|
||||||
* useful for the test suite, since it gives a chance of catching memory
|
* useful for the test suite, since it gives a chance of catching memory
|
||||||
|
@ -176,8 +227,15 @@ psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_set_iv(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_set_iv(
|
||||||
operation, iv, iv_length ) );
|
operation, iv, iv_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_set_iv( operation, iv, iv_length ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_update(
|
psa_status_t mbedtls_test_transparent_cipher_update(
|
||||||
|
@ -206,9 +264,18 @@ psa_status_t mbedtls_test_transparent_cipher_update(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_update(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_update(
|
||||||
operation, input, input_length,
|
operation, input, input_length,
|
||||||
output, output_size, output_length ) );
|
output, output_size, output_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_update(
|
||||||
|
operation, input, input_length,
|
||||||
|
output, output_size, output_length ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_cipher_finish(
|
psa_status_t mbedtls_test_transparent_cipher_finish(
|
||||||
|
@ -235,8 +302,16 @@ psa_status_t mbedtls_test_transparent_cipher_finish(
|
||||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||||
|
|
||||||
return( mbedtls_transparent_test_driver_cipher_finish(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( libtestdriver1_mbedtls_psa_cipher_finish(
|
||||||
operation, output, output_size, output_length ) );
|
operation, output, output_size, output_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||||
|
return( mbedtls_psa_cipher_finish(
|
||||||
|
operation, output, output_size, output_length ) );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -33,9 +33,13 @@
|
||||||
#include "mbedtls/error.h"
|
#include "mbedtls/error.h"
|
||||||
|
|
||||||
#include "test/drivers/key_management.h"
|
#include "test/drivers/key_management.h"
|
||||||
|
|
||||||
#include "test/random.h"
|
#include "test/random.h"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
|
#include "libtestdriver1/library/psa_crypto_ecp.h"
|
||||||
|
#include "libtestdriver1/library/psa_crypto_rsa.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
mbedtls_test_driver_key_management_hooks_t
|
mbedtls_test_driver_key_management_hooks_t
|
||||||
|
@ -60,6 +64,39 @@ const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] =
|
||||||
0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
|
0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
|
||||||
0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
|
0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
|
||||||
|
|
||||||
|
psa_status_t mbedtls_test_transparent_init( void )
|
||||||
|
{
|
||||||
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
|
status = libtestdriver1_psa_crypto_init( );
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
|
return( status );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
(void)status;
|
||||||
|
return( PSA_SUCCESS );
|
||||||
|
}
|
||||||
|
|
||||||
|
void mbedtls_test_transparent_free( void )
|
||||||
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
|
libtestdriver1_mbedtls_psa_crypto_free( );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
psa_status_t mbedtls_test_opaque_init( void )
|
||||||
|
{
|
||||||
|
return( PSA_SUCCESS );
|
||||||
|
}
|
||||||
|
|
||||||
|
void mbedtls_test_opaque_free( void )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_generate_key(
|
psa_status_t mbedtls_test_transparent_generate_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
uint8_t *key, size_t key_size, size_t *key_length )
|
uint8_t *key, size_t key_size, size_t *key_length )
|
||||||
|
@ -80,28 +117,35 @@ psa_status_t mbedtls_test_transparent_generate_key(
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copied from psa_crypto.c */
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR)
|
|
||||||
if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type( attributes ) )
|
if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type( attributes ) )
|
||||||
&& PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
|
&& PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
|
||||||
{
|
{
|
||||||
return( mbedtls_transparent_test_driver_ecp_generate_key(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||||
|
return( libtestdriver1_mbedtls_psa_ecp_generate_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key, key_size, key_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||||
|
return( mbedtls_psa_ecp_generate_key(
|
||||||
attributes, key, key_size, key_length ) );
|
attributes, key, key_size, key_length ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else if( psa_get_key_type( attributes ) == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR)
|
|
||||||
if ( psa_get_key_type( attributes ) == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
|
||||||
return( mbedtls_transparent_test_driver_rsa_generate_key(
|
|
||||||
attributes, key, key_size, key_length ) );
|
|
||||||
else
|
|
||||||
#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) */
|
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||||
|
return( libtestdriver1_mbedtls_psa_rsa_generate_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key, key_size, key_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||||
|
return( mbedtls_psa_rsa_generate_key(
|
||||||
|
attributes, key, key_size, key_length ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
(void)attributes;
|
(void)attributes;
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
psa_status_t mbedtls_test_opaque_generate_key(
|
psa_status_t mbedtls_test_opaque_generate_key(
|
||||||
const psa_key_attributes_t *attributes,
|
const psa_key_attributes_t *attributes,
|
||||||
|
@ -128,35 +172,47 @@ psa_status_t mbedtls_test_transparent_import_key(
|
||||||
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
||||||
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
||||||
|
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
|
||||||
psa_key_type_t type = psa_get_key_type( attributes );
|
psa_key_type_t type = psa_get_key_type( attributes );
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
|
||||||
if( PSA_KEY_TYPE_IS_ECC( type ) )
|
if( PSA_KEY_TYPE_IS_ECC( type ) )
|
||||||
{
|
{
|
||||||
status = mbedtls_transparent_test_driver_ecp_import_key(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||||
|
return( libtestdriver1_mbedtls_psa_ecp_import_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
data, data_length,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
key_buffer_length, bits ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
|
return( mbedtls_psa_ecp_import_key(
|
||||||
attributes,
|
attributes,
|
||||||
data, data_length,
|
data, data_length,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
key_buffer_length, bits );
|
key_buffer_length, bits ) );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
}
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY)
|
else if( PSA_KEY_TYPE_IS_RSA( type ) )
|
||||||
if( PSA_KEY_TYPE_IS_RSA( type ) )
|
|
||||||
{
|
{
|
||||||
status = mbedtls_transparent_test_driver_rsa_import_key(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||||
|
return( libtestdriver1_mbedtls_psa_rsa_import_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
data, data_length,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
key_buffer_length, bits ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
return( mbedtls_psa_rsa_import_key(
|
||||||
attributes,
|
attributes,
|
||||||
data, data_length,
|
data, data_length,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
key_buffer_length, bits );
|
key_buffer_length, bits ) );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
}
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
|
||||||
(void)data;
|
(void)data;
|
||||||
(void)data_length;
|
(void)data_length;
|
||||||
(void)key_buffer;
|
(void)key_buffer;
|
||||||
|
@ -164,9 +220,8 @@ psa_status_t mbedtls_test_transparent_import_key(
|
||||||
(void)key_buffer_length;
|
(void)key_buffer_length;
|
||||||
(void)bits;
|
(void)bits;
|
||||||
(void)type;
|
(void)type;
|
||||||
}
|
|
||||||
|
|
||||||
return( status );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_opaque_export_key(
|
psa_status_t mbedtls_test_opaque_export_key(
|
||||||
|
@ -255,39 +310,48 @@ psa_status_t mbedtls_test_transparent_export_public_key(
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
|
||||||
psa_key_type_t key_type = psa_get_key_type( attributes );
|
psa_key_type_t key_type = psa_get_key_type( attributes );
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
|
||||||
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
||||||
{
|
{
|
||||||
status = mbedtls_transparent_test_driver_ecp_export_public_key(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||||
|
return( libtestdriver1_mbedtls_psa_ecp_export_public_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
data, data_size, data_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
|
return( mbedtls_psa_ecp_export_public_key(
|
||||||
attributes,
|
attributes,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
data, data_size, data_length );
|
data, data_size, data_length ) );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
}
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY)
|
else if( PSA_KEY_TYPE_IS_RSA( key_type ) )
|
||||||
if( PSA_KEY_TYPE_IS_RSA( key_type ) )
|
|
||||||
{
|
{
|
||||||
status = mbedtls_transparent_test_driver_rsa_export_public_key(
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
|
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||||
|
return( libtestdriver1_mbedtls_psa_rsa_export_public_key(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||||
|
key_buffer, key_buffer_size,
|
||||||
|
data, data_size, data_length ) );
|
||||||
|
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||||
|
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||||
|
return( mbedtls_psa_rsa_export_public_key(
|
||||||
attributes,
|
attributes,
|
||||||
key_buffer, key_buffer_size,
|
key_buffer, key_buffer_size,
|
||||||
data, data_size, data_length );
|
data, data_size, data_length ) );
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
}
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
|
||||||
(void)key_buffer;
|
(void)key_buffer;
|
||||||
(void)key_buffer_size;
|
(void)key_buffer_size;
|
||||||
(void)key_type;
|
(void)key_type;
|
||||||
}
|
|
||||||
|
|
||||||
return( status );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_opaque_export_public_key(
|
psa_status_t mbedtls_test_opaque_export_public_key(
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue