mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[mbedtls] move mbedtls to 2.28.0 LTS version (#7539)
- Squashed 'third_party/mbedtls/repo/' content from commit 23e9e0bd2 git-subtree-dir: third_party/mbedtls/repo git-subtree-split: 23e9e0bd2c7d1b5496773356d5a2c0c56d722d93 - update Makefiles - update `check-android-build`
This commit is contained in:
Vendored
+24
-1
@@ -67,6 +67,9 @@ libmbedcrypto_a_SOURCES = \
|
||||
repo/library/cipher_wrap.c \
|
||||
repo/library/cmac.c \
|
||||
repo/library/common.h \
|
||||
repo/library/constant_time.c \
|
||||
repo/library/constant_time_internal.h \
|
||||
repo/library/constant_time_invasive.h \
|
||||
repo/library/ctr_drbg.c \
|
||||
repo/library/debug.c \
|
||||
repo/library/des.c \
|
||||
@@ -76,6 +79,7 @@ libmbedcrypto_a_SOURCES = \
|
||||
repo/library/ecjpake.c \
|
||||
repo/library/ecp.c \
|
||||
repo/library/ecp_curves.c \
|
||||
repo/library/ecp_invasive.h \
|
||||
repo/library/entropy.c \
|
||||
repo/library/entropy_poll.c \
|
||||
repo/library/error.c \
|
||||
@@ -87,6 +91,12 @@ libmbedcrypto_a_SOURCES = \
|
||||
repo/library/md2.c \
|
||||
repo/library/md4.c \
|
||||
repo/library/md5.c \
|
||||
repo/library/mps_common.h \
|
||||
repo/library/mps_error.h \
|
||||
repo/library/mps_reader.c \
|
||||
repo/library/mps_reader.h \
|
||||
repo/library/mps_trace.c \
|
||||
repo/library/mps_trace.h \
|
||||
repo/library/memory_buffer_alloc.c \
|
||||
repo/library/net_sockets.c \
|
||||
repo/library/nist_kw.c \
|
||||
@@ -104,11 +114,25 @@ libmbedcrypto_a_SOURCES = \
|
||||
repo/library/platform_util.c \
|
||||
repo/library/poly1305.c \
|
||||
repo/library/psa_crypto.c \
|
||||
repo/library/psa_crypto_aead.c \
|
||||
repo/library/psa_crypto_aead.h \
|
||||
repo/library/psa_crypto_core.h \
|
||||
repo/library/psa_crypto_cipher.c \
|
||||
repo/library/psa_crypto_cipher.h \
|
||||
repo/library/psa_crypto_client.c \
|
||||
repo/library/psa_crypto_driver_wrappers.c \
|
||||
repo/library/psa_crypto_driver_wrappers.h \
|
||||
repo/library/psa_crypto_ecp.c \
|
||||
repo/library/psa_crypto_ecp.h \
|
||||
repo/library/psa_crypto_hash.c \
|
||||
repo/library/psa_crypto_hash.h \
|
||||
repo/library/psa_crypto_invasive.h \
|
||||
repo/library/psa_crypto_its.h \
|
||||
repo/library/psa_crypto_mac.c \
|
||||
repo/library/psa_crypto_mac.h \
|
||||
repo/library/psa_crypto_random_impl.h \
|
||||
repo/library/psa_crypto_rsa.c \
|
||||
repo/library/psa_crypto_rsa.h \
|
||||
repo/library/psa_crypto_se.c \
|
||||
repo/library/psa_crypto_se.h \
|
||||
repo/library/psa_crypto_slot_management.c \
|
||||
@@ -126,7 +150,6 @@ libmbedcrypto_a_SOURCES = \
|
||||
repo/library/ssl_ciphersuites.c \
|
||||
repo/library/ssl_cli.c \
|
||||
repo/library/ssl_cookie.c \
|
||||
repo/library/ssl_invasive.h \
|
||||
repo/library/ssl_msg.c \
|
||||
repo/library/ssl_srv.c \
|
||||
repo/library/ssl_ticket.c \
|
||||
|
||||
Vendored
+2
-2
@@ -2,11 +2,11 @@
|
||||
|
||||
## URL
|
||||
|
||||
https://github.com/ARMmbed/mbedtls/releases/tag/mbedtls-2.25.0
|
||||
https://github.com/ARMmbed/mbedtls/releases/tag/mbedtls-2.28.0
|
||||
|
||||
## Version
|
||||
|
||||
2.25.0
|
||||
2.28.0
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+14
-9
@@ -1,7 +1,17 @@
|
||||
Note: This is just a template, so feel free to use/remove the unnecessary things
|
||||
_Note:_ this is a template, please remove the parts that are not
|
||||
applicable (these initial notes, and the "Bug" section for a Feature request
|
||||
and vice-versa).
|
||||
|
||||
**Note:** to report a security vulnerability, see
|
||||
[SECURITY.md](../SECURITY.md). Please do not use github issues for
|
||||
vulnerabilities.
|
||||
|
||||
_Note:_ to get support, see [SUPPORT.md](../SUPPORT.md). Please do not use
|
||||
github issues for questions.
|
||||
|
||||
---------------------------------------------------------------
|
||||
### Description
|
||||
- Type: Bug | Enhancement\Feature Request
|
||||
- Type: Bug | Enhancement / Feature Request
|
||||
- Priority: Blocker | Major | Minor
|
||||
|
||||
---------------------------------------------------------------
|
||||
@@ -28,14 +38,9 @@ Version:
|
||||
**Steps to reproduce**
|
||||
|
||||
----------------------------------------------------------------
|
||||
## Enhancement\Feature Request
|
||||
|
||||
**Justification - why does the library need this feature?**
|
||||
## Enhancement / Feature Request
|
||||
|
||||
**Suggested enhancement**
|
||||
|
||||
-----------------------------------------------------------------
|
||||
**Justification - why does the library need this feature?**
|
||||
|
||||
## Question
|
||||
|
||||
**Please first check for answers in the [Mbed TLS knowledge Base](https://tls.mbed.org/kb). If you can't find the answer you're looking for then please use the [Mbed TLS mailing list](https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls)**
|
||||
|
||||
@@ -18,6 +18,7 @@ Testing
|
||||
Coverage
|
||||
*.gcno
|
||||
*.gcda
|
||||
coverage-summary.txt
|
||||
|
||||
# generated by scripts/memory.sh
|
||||
massif-*
|
||||
@@ -48,6 +49,9 @@ massif-*
|
||||
# Generated documentation:
|
||||
/apidoc
|
||||
|
||||
# PSA Crypto compliance test repo, cloned by test_psa_compliance.py
|
||||
/psa-arch-tests
|
||||
|
||||
# Editor navigation files:
|
||||
/GPATH
|
||||
/GRTAGS
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
[mypy]
|
||||
mypy_path = scripts
|
||||
namespace_packages = True
|
||||
warn_unused_configs = True
|
||||
Vendored
+5
-2
@@ -1,3 +1,6 @@
|
||||
[MASTER]
|
||||
init-hook='import sys; sys.path.append("scripts")'
|
||||
|
||||
[BASIC]
|
||||
# We're ok with short funtion argument names.
|
||||
# [invalid-name]
|
||||
@@ -12,9 +15,9 @@ bad-functions=input
|
||||
# [missing-docstring]
|
||||
docstring-min-length=10
|
||||
|
||||
# Allow longer methods than the default.
|
||||
# No upper limit on method names. Pylint <2.1.0 has an upper limit of 30.
|
||||
# [invalid-name]
|
||||
method-rgx=[a-z_][a-z0-9_]{2,35}$
|
||||
method-rgx=[a-z_][a-z0-9_]{2,}$
|
||||
|
||||
# Allow module names containing a dash (but no underscore or uppercase letter).
|
||||
# They are whole programs, not meant to be included by another module.
|
||||
|
||||
Vendored
+5
-18
@@ -14,38 +14,25 @@ jobs:
|
||||
- graphviz
|
||||
- gcc-arm-none-eabi
|
||||
- libnewlib-arm-none-eabi
|
||||
- gcc-arm-linux-gnueabi
|
||||
- libc6-dev-armel-cross
|
||||
language: python # Needed to get pip for Python 3
|
||||
python: 3.5 # version from Ubuntu 16.04
|
||||
install:
|
||||
- pip install pylint==2.4.4
|
||||
- scripts/min_requirements.py
|
||||
script:
|
||||
- tests/scripts/all.sh -k 'check_*'
|
||||
- tests/scripts/all.sh -k test_default_out_of_box
|
||||
- tests/scripts/test-ref-configs.pl
|
||||
- tests/scripts/all.sh -k build_arm_none_eabi_gcc_arm5vte build_arm_none_eabi_gcc_m0plus
|
||||
- tests/scripts/all.sh -k test_ref_configs
|
||||
- tests/scripts/all.sh -k build_arm_linux_gnueabi_gcc_arm5vte build_arm_none_eabi_gcc_m0plus
|
||||
|
||||
- name: full configuration
|
||||
script:
|
||||
- tests/scripts/all.sh -k test_full_cmake_gcc_asan
|
||||
|
||||
- name: macOS
|
||||
os: osx
|
||||
compiler: clang
|
||||
script:
|
||||
- tests/scripts/all.sh -k test_default_out_of_box
|
||||
|
||||
- name: Windows
|
||||
os: windows
|
||||
before_install:
|
||||
- choco install python --version=3.5.4
|
||||
env:
|
||||
# Add the directory where the Choco package goes
|
||||
- PATH=/c/Python35:/c/Python35/Scripts:$PATH
|
||||
script:
|
||||
- type python; python --version
|
||||
- python scripts/generate_psa_constants.py
|
||||
# Logs appear out of sequence on Windows. Give time to catch up.
|
||||
- sleep 5
|
||||
- scripts/windows_msbuild.bat v141 # Visual Studio 2017
|
||||
|
||||
after_failure:
|
||||
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
# Maintained branches
|
||||
|
||||
At any point in time, we have a number of maintained branches consisting of:
|
||||
|
||||
- The [`master`](https://github.com/ARMmbed/mbedtls/tree/master) branch:
|
||||
this always contains the latest release, including all publicly available
|
||||
security fixes.
|
||||
- The [`development`](https://github.com/ARMmbed/mbedtls/tree/development) branch:
|
||||
this is where new features land,
|
||||
as well as bug fixes and security fixes.
|
||||
- One or more long-time support (LTS) branches:
|
||||
these only get bug fixes and security fixes.
|
||||
|
||||
We use [Semantic Versioning](https://semver.org/). In particular, we maintain
|
||||
API compatibility in the `master` branch between major version changes. We
|
||||
also maintain ABI compatibility within LTS branches; see the next section for
|
||||
details.
|
||||
|
||||
## Backwards Compatibility
|
||||
|
||||
We maintain API compatibility in released versions of Mbed TLS. If you have
|
||||
code that's working and secure with Mbed TLS x.y.z and does not rely on
|
||||
undocumented features, then you should be able to re-compile it without
|
||||
modification with any later release x.y'.z' with the same major version
|
||||
number, and your code will still build, be secure, and work.
|
||||
|
||||
There are rare exceptions: code that was relying on something that became
|
||||
insecure in the meantime (for example, crypto that was found to be weak) may
|
||||
need to be changed. In case security comes in conflict with backwards
|
||||
compatibility, we will put security first, but always attempt to provide a
|
||||
compatibility option.
|
||||
|
||||
For the LTS branches, additionally we try very hard to also maintain ABI
|
||||
compatibility (same definition as API except with re-linking instead of
|
||||
re-compiling) and to avoid any increase in code size or RAM usage, or in the
|
||||
minimum version of tools needed to build the code. The only exception, as
|
||||
before, is in case those goals would conflict with fixing a security issue, we
|
||||
will put security first but provide a compatibility option. (So far we never
|
||||
had to break ABI compatibility in an LTS branch, but we occasionally had to
|
||||
increase code size for a security fix.)
|
||||
|
||||
For contributors, see the [Backwards Compatibility section of
|
||||
CONTRIBUTING](CONTRIBUTING.md#cackwords-compatibility).
|
||||
|
||||
## Current Branches
|
||||
|
||||
The following branches are currently maintained:
|
||||
|
||||
- [master](https://github.com/ARMmbed/mbedtls/tree/master)
|
||||
- [`development`](https://github.com/ARMmbed/mbedtls/)
|
||||
- [`mbedtls-2.28`](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.28)
|
||||
maintained until at least the end of 2024.
|
||||
|
||||
Users are urged to always use the latest version of a maintained branch.
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
## Known issues
|
||||
|
||||
Known issues in Mbed TLS are [tracked on GitHub](https://github.com/ARMmbed/mbedtls/issues).
|
||||
|
||||
## Reporting a bug
|
||||
|
||||
If you think you've found a bug in Mbed TLS, please follow these steps:
|
||||
|
||||
1. Make sure you're using the latest version of a
|
||||
[maintained branch](BRANCHES.md): `master`, `development`,
|
||||
or a long-time support branch.
|
||||
2. Check [GitHub](https://github.com/ARMmbed/mbedtls/issues) to see if
|
||||
your issue has already been reported. If not, …
|
||||
3. If the issue is a security risk (for example: buffer overflow,
|
||||
data leak), please report it confidentially as described in
|
||||
[`SECURITY.md`](SECURITY.md). If not, …
|
||||
4. Please [create an issue on on GitHub](https://github.com/ARMmbed/mbedtls/issues).
|
||||
|
||||
Please do not use GitHub for support questions. If you want to know
|
||||
how to do something with Mbed TLS, please see [`SUPPORT.md`](SUPPORT.md) for available documentation and support channels.
|
||||
+19
-1
@@ -21,6 +21,18 @@
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
# https://cmake.org/cmake/help/latest/policy/CMP0011.html
|
||||
# Setting this policy is required in CMake >= 3.18.0, otherwise a warning is generated. The OLD
|
||||
# policy setting is deprecated, and will be removed in future versions.
|
||||
cmake_policy(SET CMP0011 NEW)
|
||||
# https://cmake.org/cmake/help/latest/policy/CMP0012.html
|
||||
# Setting the CMP0012 policy to NEW is required for FindPython3 to work with CMake 3.18.2
|
||||
# (there is a bug in this particular version), otherwise, setting the CMP0012 policy is required
|
||||
# for CMake versions >= 3.18.3 otherwise a deprecated warning is generated. The OLD policy setting
|
||||
# is deprecated and will be removed in future versions.
|
||||
cmake_policy(SET CMP0012 NEW)
|
||||
|
||||
if(TEST_CPP)
|
||||
project("mbed TLS" C CXX)
|
||||
else()
|
||||
@@ -167,6 +179,9 @@ if(CMAKE_COMPILER_IS_GNU)
|
||||
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
|
||||
OUTPUT_VARIABLE GCC_VERSION)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings")
|
||||
if (GCC_VERSION VERSION_GREATER 3.0 OR GCC_VERSION VERSION_EQUAL 3.0)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2 -Wno-format-nonliteral")
|
||||
endif()
|
||||
if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wvla")
|
||||
endif()
|
||||
@@ -182,6 +197,9 @@ if(CMAKE_COMPILER_IS_GNU)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-signedness")
|
||||
endif()
|
||||
endif()
|
||||
if (GCC_VERSION VERSION_GREATER 7.0 OR GCC_VERSION VERSION_EQUAL 7.0)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2 -Wformat-truncation")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
||||
@@ -192,7 +210,7 @@ if(CMAKE_COMPILER_IS_GNU)
|
||||
endif(CMAKE_COMPILER_IS_GNU)
|
||||
|
||||
if(CMAKE_COMPILER_IS_CLANG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O2")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
|
||||
|
||||
+7
-3
@@ -22,9 +22,10 @@ Making a Contribution
|
||||
1. All new files should include the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) standard license header where possible.
|
||||
1. Ensure that each commit has at least one `Signed-off-by:` line from the committer. If anyone else contributes to the commit, they should also add their own `Signed-off-by:` line. By adding this line, contributor(s) certify that the contribution is made under the terms of the [Developer Certificate of Origin](dco.txt). The contribution licensing is described in the [License section of the README](README.md#License).
|
||||
|
||||
API/ABI Compatibility
|
||||
---------------------
|
||||
The project aims to minimise the impact on users upgrading to newer versions of the library and it should not be necessary for a user to make any changes to their own code to work with a newer version of the library. Unless the user has made an active decision to use newer features, a newer generation of the library or a change has been necessary due to a security issue or other significant software defect, no modifications to their own code should be necessary. To achieve this, API compatibility is maintained between different versions of Mbed TLS on the main development branch and in LTS (Long Term Support) branches.
|
||||
Backwards Compatibility
|
||||
-----------------------
|
||||
|
||||
The project aims to minimise the impact on users upgrading to newer versions of the library and it should not be necessary for a user to make any changes to their own code to work with a newer version of the library. Unless the user has made an active decision to use newer features, a newer generation of the library or a change has been necessary due to a security issue or other significant software defect, no modifications to their own code should be necessary. To achieve this, API compatibility is maintained between different versions of Mbed TLS on the main development branch and in LTS (Long Term Support) branches, as described in [BRANCHES.md](BRANCHES.md).
|
||||
|
||||
To minimise such disruption to users, where a change to the interface is required, all changes to the ABI or API, even on the main development branch where new features are added, need to be justifiable by either being a significant enhancement, new feature or bug fix which is best resolved by an interface change.
|
||||
|
||||
@@ -48,6 +49,9 @@ When backporting to these branches please observe the following rules:
|
||||
|
||||
It would be highly appreciated if contributions are backported to LTS branches in addition to the [development branch](https://github.com/ARMmbed/mbedtls/tree/development) by contributors.
|
||||
|
||||
The list of maintained branches can be found in the [Current Branches section
|
||||
of BRANCHES.md](BRANCHES.md#current-branches).
|
||||
|
||||
Currently maintained LTS branches are:
|
||||
1. [mbedtls-2.7](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.7)
|
||||
1. [mbedtls-2.16](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.16)
|
||||
|
||||
Vendored
+434
-2
@@ -1,5 +1,437 @@
|
||||
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
|
||||
|
||||
API changes
|
||||
* Update AEAD output size macros to bring them in line with the PSA Crypto
|
||||
API version 1.0 spec. This version of the spec parameterizes them on the
|
||||
key type used, as well as the key bit-size in the case of
|
||||
PSA_AEAD_TAG_LENGTH.
|
||||
The old versions of these macros were renamed and deprecated as follows:
|
||||
- PSA_AEAD_TAG_LENGTH -> PSA_AEAD_TAG_LENGTH_1_ARG
|
||||
- PSA_AEAD_ENCRYPT_OUTPUT_SIZE -> PSA_AEAD_ENCRYPT_OUTPUT_SIZE_2_ARG
|
||||
- PSA_AEAD_DECRYPT_OUTPUT_SIZE -> PSA_AEAD_DECRYPT_OUTPUT_SIZE_2_ARG
|
||||
- PSA_AEAD_UPDATE_OUTPUT_SIZE -> PSA_AEAD_UPDATE_OUTPUT_SIZE_2_ARG
|
||||
- PSA_AEAD_FINISH_OUTPUT_SIZE -> PSA_AEAD_FINISH_OUTPUT_SIZE_1_ARG
|
||||
- PSA_AEAD_VERIFY_OUTPUT_SIZE -> PSA_AEAD_VERIFY_OUTPUT_SIZE_1_ARG
|
||||
* Implement one-shot cipher functions, psa_cipher_encrypt and
|
||||
psa_cipher_decrypt, according to the PSA Crypto API 1.0.0
|
||||
specification.
|
||||
|
||||
Requirement changes
|
||||
* The library now uses the %zu format specifier with the printf() family of
|
||||
functions, so requires a toolchain that supports it. This change does not
|
||||
affect the maintained LTS branches, so when contributing changes please
|
||||
bear this in mind and do not add them to backported code.
|
||||
|
||||
Features
|
||||
* Add mbedtls_rsa_rsassa_pss_sign_ext() function allowing to generate a
|
||||
signature with a specific salt length. This function allows to validate
|
||||
test cases provided in the NIST's CAVP test suite. Contributed by Cédric
|
||||
Meuter in PR #3183.
|
||||
* Added support for built-in driver keys through the PSA opaque crypto
|
||||
driver interface. Refer to the documentation of
|
||||
MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS for more information.
|
||||
* Implement psa_sign_message() and psa_verify_message().
|
||||
* The new function mbedtls_mpi_random() generates a random value in a
|
||||
given range uniformly.
|
||||
* Implement psa_mac_compute() and psa_mac_verify() as defined in the
|
||||
PSA Cryptograpy API 1.0.0 specification.
|
||||
* MBEDTLS_ECP_MAX_BITS is now determined automatically from the configured
|
||||
curves and no longer needs to be configured explicitly to save RAM.
|
||||
|
||||
Security
|
||||
* Fix a bias in the generation of finite-field Diffie-Hellman-Merkle (DHM)
|
||||
private keys and of blinding values for DHM and elliptic curves (ECP)
|
||||
computations. Reported by FlorianF89 in #4245.
|
||||
* Fix a potential side channel vulnerability in ECDSA ephemeral key generation.
|
||||
An adversary who is capable of very precise timing measurements could
|
||||
learn partial information about the leading bits of the nonce used for the
|
||||
signature, allowing the recovery of the private key after observing a
|
||||
large number of signature operations. This completes a partial fix in
|
||||
Mbed TLS 2.20.0.
|
||||
* It was possible to configure MBEDTLS_ECP_MAX_BITS to a value that is
|
||||
too small, leading to buffer overflows in ECC operations. Fail the build
|
||||
in such a case.
|
||||
* An adversary with access to precise enough information about memory
|
||||
accesses (typically, an untrusted operating system attacking a secure
|
||||
enclave) could recover an RSA private key after observing the victim
|
||||
performing a single private-key operation. Found and reported by
|
||||
Zili KOU, Wenjian HE, Sharad Sinha, and Wei ZHANG.
|
||||
* An adversary with access to precise enough timing information (typically, a
|
||||
co-located process) could recover a Curve25519 or Curve448 static ECDH key
|
||||
after inputting a chosen public key and observing the victim performing the
|
||||
corresponding private-key operation. Found and reported by Leila Batina,
|
||||
Lukas Chmielewski, Björn Haase, Niels Samwel and Peter Schwabe.
|
||||
|
||||
Bugfix
|
||||
* Add printf function attributes to mbedtls_debug_print_msg to ensure we
|
||||
get printf format specifier warnings.
|
||||
* Fix premature fopen() call in mbedtls_entropy_write_seed_file which may
|
||||
lead to seed file corruption in the case where the path to the seed file is
|
||||
equal to MBEDTLS_PLATFORM_STD_NV_SEED_FILE. Contributed by Victor
|
||||
Krasnoshchok in #3616.
|
||||
* PSA functions other than psa_open_key now return PSA_ERROR_INVALID_HANDLE
|
||||
rather than PSA_ERROR_DOES_NOT_EXIST for an invalid handle, bringing them
|
||||
in line with version 1.0.0 of the specification. Fix #4162.
|
||||
* PSA functions creating a key now return PSA_ERROR_INVALID_ARGUMENT rather
|
||||
than PSA_ERROR_INVALID_HANDLE when the identifier specified for the key
|
||||
to create is not valid, bringing them in line with version 1.0.0 of the
|
||||
specification. Fix #4271.
|
||||
* Fix some cases in the bignum module where the library constructed an
|
||||
unintended representation of the value 0 which was not processed
|
||||
correctly by some bignum operations. This could happen when
|
||||
mbedtls_mpi_read_string() was called on "-0", or when
|
||||
mbedtls_mpi_mul_mpi() and mbedtls_mpi_mul_int() was called with one of
|
||||
the arguments being negative and the other being 0. Fixes #4643.
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero. Fixes #1792
|
||||
* Fix a compilation error when MBEDTLS_ECP_RANDOMIZE_MXZ_ALT is
|
||||
defined. Fixes #4217.
|
||||
* Fix an incorrect error code when parsing a PKCS#8 private key.
|
||||
* In a TLS client, enforce the Diffie-Hellman minimum parameter size
|
||||
set with mbedtls_ssl_conf_dhm_min_bitlen() precisely. Before, the
|
||||
minimum size was rounded down to the nearest multiple of 8.
|
||||
* In library/net_sockets.c, _POSIX_C_SOURCE and _XOPEN_SOURCE are
|
||||
defined to specific values. If the code is used in a context
|
||||
where these are already defined, this can result in a compilation
|
||||
error. Instead, assume that if they are defined, the values will
|
||||
be adequate to build Mbed TLS.
|
||||
* The cipher suite TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384 was not available
|
||||
when SHA-1 was disabled and was offered when SHA-1 was enabled but SHA-384
|
||||
was disabled. Fix the dependency. Fixes #4472.
|
||||
* Do not offer SHA384 cipher suites when SHA-384 is disabled. Fixes #4499.
|
||||
* With MBEDTLS_PSA_CRYPTO_C disabled, some functions were getting built
|
||||
nonetheless, resulting in undefined reference errors when building a
|
||||
shared library. Reported by Guillermo Garcia M. in #4411.
|
||||
* Fix test suite code on platforms where int32_t is not int, such as
|
||||
Arm Cortex-M. Fixes #4530.
|
||||
* Fix some issues affecting MBEDTLS_ARIA_ALT implementations: a misplaced
|
||||
directive in a header and a missing initialization in the self-test.
|
||||
* Fix a missing initialization in the Camellia self-test, affecting
|
||||
MBEDTLS_CAMELLIA_ALT implementations.
|
||||
* Restore the ability to configure PSA via Mbed TLS options to support RSA
|
||||
key pair operations but exclude RSA key generation. When MBEDTLS_GENPRIME
|
||||
is not defined PSA will no longer attempt to use mbedtls_rsa_gen_key().
|
||||
Fixes #4512.
|
||||
* Fix a regression introduced in 2.24.0 which broke (D)TLS CBC ciphersuites
|
||||
(when the encrypt-then-MAC extension is not in use) with some ALT
|
||||
implementations of the underlying hash (SHA-1, SHA-256, SHA-384), causing
|
||||
the affected side to wrongly reject valid messages. Fixes #4118.
|
||||
* Remove outdated check-config.h check that prevented implementing the
|
||||
timing module on Mbed OS. Fixes #4633.
|
||||
* Fix PSA_ALG_TLS12_PRF and PSA_ALG_TLS12_PSK_TO_MS being too permissive
|
||||
about missing inputs.
|
||||
* Fix mbedtls_net_poll() and mbedtls_net_recv_timeout() often failing with
|
||||
MBEDTLS_ERR_NET_POLL_FAILED on Windows. Fixes #4465.
|
||||
* Fix a resource leak in a test suite with an alternative AES
|
||||
implementation. Fixes #4176.
|
||||
* Fix a crash in mbedtls_mpi_debug_mpi on a bignum having 0 limbs. This
|
||||
could notably be triggered by setting the TLS debug level to 3 or above
|
||||
and using a Montgomery curve for the key exchange. Reported by lhuang04
|
||||
in #4578. Fixes #4608.
|
||||
* psa_verify_hash() was relying on implementation-specific behavior of
|
||||
mbedtls_rsa_rsassa_pss_verify() and was causing failures in some _ALT
|
||||
implementations. This reliance is now removed. Fixes #3990.
|
||||
* Disallow inputs of length different from the corresponding hash when
|
||||
signing or verifying with PSA_ALG_RSA_PSS (The PSA Crypto API mandates
|
||||
that PSA_ALG_RSA_PSS uses the same hash throughout the algorithm.)
|
||||
* Fix a null pointer dereference when mbedtls_mpi_exp_mod() was called with
|
||||
A=0 represented with 0 limbs. Up to and including Mbed TLS 2.26, this bug
|
||||
could not be triggered by code that constructed A with one of the
|
||||
mbedtls_mpi_read_xxx functions (including in particular TLS code) since
|
||||
those always built an mpi object with at least one limb.
|
||||
Credit to OSS-Fuzz. Fixes #4641.
|
||||
* Fix mbedtls_mpi_gcd(G,A,B) when the value of B is zero. This had no
|
||||
effect on Mbed TLS's internal use of mbedtls_mpi_gcd(), but may affect
|
||||
applications that call mbedtls_mpi_gcd() directly. Fixes #4642.
|
||||
* The PSA API no longer allows the creation or destruction of keys with a
|
||||
read-only lifetime. The persistence level PSA_KEY_PERSISTENCE_READ_ONLY
|
||||
can now only be used as intended, for keys that cannot be modified through
|
||||
normal use of the API.
|
||||
* When MBEDTLS_PSA_CRYPTO_SPM is enabled, crypto_spe.h was not included
|
||||
in all the right places. Include it from crypto_platform.h, which is
|
||||
the natural place. Fixes #4649.
|
||||
* mbedtls_pk_sign() and mbedtls_pk_verify() and their extended and
|
||||
restartable variants now always honor the specified hash length if
|
||||
nonzero. Before, for RSA, hash_len was ignored in favor of the length of
|
||||
the specified hash algorithm.
|
||||
* Fix which alert is sent in some cases to conform to the
|
||||
applicable RFC: on an invalid Finished message value, an
|
||||
invalid max_fragment_length extension, or an
|
||||
unsupported extension used by the server.
|
||||
* Correct (change from 12 to 13 bytes) the value of the macro describing the
|
||||
maximum nonce length returned by psa_aead_generate_nonce().
|
||||
|
||||
Changes
|
||||
* Add extra printf compiler warning flags to builds.
|
||||
* Fix memsan build false positive in x509_crt.c with Clang 11
|
||||
* Fix the setting of the read timeout in the DTLS sample programs.
|
||||
* Remove the AES sample application programs/aes/aescrypt2 which shows
|
||||
bad cryptographic practice. Fix #1906.
|
||||
* Alternative implementations of CMAC may now opt to not support 3DES as a
|
||||
CMAC block cipher, and still pass the CMAC self test.
|
||||
* Remove configs/config-psa-crypto.h, which was identical to the default
|
||||
configuration except for having some extra cryptographic mechanisms
|
||||
enabled and for unintended differences. This configuration was primarily
|
||||
intended to demonstrate the PSA API, and lost most of its usefulness when
|
||||
MBEDTLS_PSA_CRYPTO_C became enabled by default.
|
||||
* When building the test suites with GNU make, invoke python3 or python, not
|
||||
python2, which is no longer supported upstream.
|
||||
* When using session cache based session resumption on the server,
|
||||
double-check that custom session cache implementations return
|
||||
sessions which are consistent with the negotiated ciphersuite
|
||||
and compression method.
|
||||
* Fix build failure on MinGW toolchain when __USE_MING_ANSI_STDIO is on.
|
||||
When that flag is on, standard GNU C printf format specifiers
|
||||
should be used.
|
||||
* Reduce the default value of MBEDTLS_ECP_WINDOW_SIZE. This reduces RAM usage
|
||||
during ECC operations at a negligible performance cost.
|
||||
* mbedtls_mpi_read_binary(), mbedtls_mpi_read_binary_le() and
|
||||
mbedtls_mpi_read_string() now construct an mbedtls_mpi object with 0 limbs
|
||||
when their input has length 0. Note that this is an implementation detail
|
||||
and can change at any time, so this change should be transparent, but it
|
||||
may result in mbedtls_mpi_write_binary() or mbedtls_mpi_write_string()
|
||||
now writing an empty string where it previously wrote one or more
|
||||
zero digits when operating from values constructed with an mpi_read
|
||||
function and some mpi operations.
|
||||
* Implicitly add PSA_KEY_USAGE_SIGN_MESSAGE key usage policy flag when
|
||||
PSA_KEY_USAGE_SIGN_HASH flag is set and PSA_KEY_USAGE_VERIFY_MESSAGE flag
|
||||
when PSA_KEY_USAGE_VERIFY_HASH flag is set. This usage flag extension
|
||||
is also applied when loading a key from storage.
|
||||
|
||||
= mbed TLS 2.26.0 branch released 2021-03-08
|
||||
|
||||
API changes
|
||||
* Renamed the PSA Crypto API output buffer size macros to bring them in line
|
||||
with version 1.0.0 of the specification.
|
||||
* The API glue function mbedtls_ecc_group_of_psa() now takes the curve size
|
||||
in bits rather than bytes, with an additional flag to indicate if the
|
||||
size may have been rounded up to a whole number of bytes.
|
||||
* Renamed the PSA Crypto API AEAD tag length macros to bring them in line
|
||||
with version 1.0.0 of the specification.
|
||||
|
||||
Default behavior changes
|
||||
* In mbedtls_rsa_context objects, the ver field was formerly documented
|
||||
as always 0. It is now reserved for internal purposes and may take
|
||||
different values.
|
||||
|
||||
New deprecations
|
||||
* PSA_KEY_EXPORT_MAX_SIZE, PSA_HASH_SIZE, PSA_MAC_FINAL_SIZE,
|
||||
PSA_BLOCK_CIPHER_BLOCK_SIZE, PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE and
|
||||
PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN have been renamed, and the old names
|
||||
deprecated.
|
||||
* PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH and PSA_ALG_AEAD_WITH_TAG_LENGTH
|
||||
have been renamed, and the old names deprecated.
|
||||
|
||||
Features
|
||||
* The PSA crypto subsystem can now use HMAC_DRBG instead of CTR_DRBG.
|
||||
CTR_DRBG is used by default if it is available, but you can override
|
||||
this choice by setting MBEDTLS_PSA_HMAC_DRBG_MD_TYPE at compile time.
|
||||
Fix #3354.
|
||||
* Automatic fallback to a software implementation of ECP when
|
||||
MBEDTLS_ECP_xxx_ALT accelerator hooks are in use can now be turned off
|
||||
through setting the new configuration flag MBEDTLS_ECP_NO_FALLBACK.
|
||||
* The PSA crypto subsystem can now be configured to use less static RAM by
|
||||
tweaking the setting for the maximum amount of keys simultaneously in RAM.
|
||||
MBEDTLS_PSA_KEY_SLOT_COUNT sets the maximum number of volatile keys that
|
||||
can exist simultaneously. It has a sensible default if not overridden.
|
||||
* Partial implementation of the PSA crypto driver interface: Mbed TLS can
|
||||
now use an external random generator instead of the library's own
|
||||
entropy collection and DRBG code. Enable MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
|
||||
and see the documentation of mbedtls_psa_external_get_random() for details.
|
||||
* Applications using both mbedtls_xxx and psa_xxx functions (for example,
|
||||
applications using TLS and MBEDTLS_USE_PSA_CRYPTO) can now use the PSA
|
||||
random generator with mbedtls_xxx functions. See the documentation of
|
||||
mbedtls_psa_get_random() for details.
|
||||
* In the PSA API, the policy for a MAC or AEAD algorithm can specify a
|
||||
minimum MAC or tag length thanks to the new wildcards
|
||||
PSA_ALG_AT_LEAST_THIS_LENGTH_MAC and
|
||||
PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG.
|
||||
|
||||
Security
|
||||
* Fix a security reduction in CTR_DRBG when the initial seeding obtained a
|
||||
nonce from entropy. Applications were affected if they called
|
||||
mbedtls_ctr_drbg_set_nonce_len(), if they called
|
||||
mbedtls_ctr_drbg_set_entropy_len() with a size that was 3/2 times the key
|
||||
length, or when the entropy module uses SHA-256 and CTR_DRBG uses AES-256.
|
||||
In such cases, a random nonce was necessary to achieve the advertised
|
||||
security strength, but the code incorrectly used a constant instead of
|
||||
entropy from the nonce.
|
||||
Found by John Stroebel in #3819 and fixed in #3973.
|
||||
* Fix a buffer overflow in mbedtls_mpi_sub_abs() when calculating
|
||||
|A| - |B| where |B| is larger than |A| and has more limbs (so the
|
||||
function should return MBEDTLS_ERR_MPI_NEGATIVE_VALUE). Only
|
||||
applications calling mbedtls_mpi_sub_abs() directly are affected:
|
||||
all calls inside the library were safe since this function is
|
||||
only called with |A| >= |B|. Reported by Guido Vranken in #4042.
|
||||
* Fix an errorneous estimation for an internal buffer in
|
||||
mbedtls_pk_write_key_pem(). If MBEDTLS_MPI_MAX_SIZE is set to an odd
|
||||
value the function might fail to write a private RSA keys of the largest
|
||||
supported size.
|
||||
Found by Daniel Otte, reported in #4093 and fixed in #4094.
|
||||
* Fix a stack buffer overflow with mbedtls_net_poll() and
|
||||
mbedtls_net_recv_timeout() when given a file descriptor that is
|
||||
beyond FD_SETSIZE. Reported by FigBug in #4169.
|
||||
* Guard against strong local side channel attack against base64 tables by
|
||||
making access aceess to them use constant flow code.
|
||||
|
||||
Bugfix
|
||||
* Fix use-after-scope error in programs/ssl/ssl_client2.c and ssl_server2.c
|
||||
* Fix memory leak that occured when calling psa_close_key() on a
|
||||
wrapped key with MBEDTLS_PSA_CRYPTO_SE_C defined.
|
||||
* Fix an incorrect error code if an RSA private operation glitched.
|
||||
* Fix a memory leak in an error case in psa_generate_derived_key_internal().
|
||||
* Fix a resource leak in CTR_DRBG and HMAC_DRBG when MBEDTLS_THREADING_C
|
||||
is enabled, on platforms where initializing a mutex allocates resources.
|
||||
This was a regression introduced in the previous release. Reported in
|
||||
#4017, #4045 and #4071.
|
||||
* Ensure that calling mbedtls_rsa_free() or mbedtls_entropy_free()
|
||||
twice is safe. This happens for RSA when some Mbed TLS library functions
|
||||
fail. Such a double-free was not safe when MBEDTLS_THREADING_C was
|
||||
enabled on platforms where freeing a mutex twice is not safe.
|
||||
* Fix a resource leak in a bad-arguments case of mbedtls_rsa_gen_key()
|
||||
when MBEDTLS_THREADING_C is enabled on platforms where initializing
|
||||
a mutex allocates resources.
|
||||
* Fixes a bug where, if the library was configured to include support for
|
||||
both the old SE interface and the new PSA driver interface, external keys were
|
||||
not loaded from storage. This was fixed by #3996.
|
||||
* This change makes 'mbedtls_x509write_crt_set_basic_constraints'
|
||||
consistent with RFC 5280 4.2.1.9 which says: "Conforming CAs MUST
|
||||
include this extension in all CA certificates that contain public keys
|
||||
used to validate digital signatures on certificates and MUST mark the
|
||||
extension as critical in such certificates." Previous to this change,
|
||||
the extension was always marked as non-critical. This was fixed by
|
||||
#3698.
|
||||
|
||||
Changes
|
||||
* A new library C file psa_crypto_client.c has been created to contain
|
||||
the PSA code needed by a PSA crypto client when the PSA crypto
|
||||
implementation is not included into the library.
|
||||
* On recent enough versions of FreeBSD and DragonFlyBSD, the entropy module
|
||||
now uses the getrandom syscall instead of reading from /dev/urandom.
|
||||
|
||||
= mbed TLS 2.25.0 branch released 2020-12-11
|
||||
|
||||
API changes
|
||||
@@ -20,7 +452,7 @@ Requirement changes
|
||||
warning on CMake 3.19.0. #3801
|
||||
|
||||
New deprecations
|
||||
* PSA_KEY_TYPE_CHACHA20 and PSA_KEY_TYPE_ARC4 have been deprecated.
|
||||
* PSA_ALG_CHACHA20 and PSA_ALG_ARC4 have been deprecated.
|
||||
Use PSA_ALG_STREAM_CIPHER instead.
|
||||
* The functions mbedtls_cipher_auth_encrypt() and
|
||||
mbedtls_cipher_auth_decrypt() are deprecated in favour of the new
|
||||
@@ -91,7 +523,7 @@ Security
|
||||
Johan Malmgren and Johan Uppman Bruce from Sectra.
|
||||
|
||||
Bugfix
|
||||
* Fix an invalid (but nonzero) return code from mbedtls_pk_parse_subpubkey()
|
||||
* Fix an invalid (but non-zero) return code from mbedtls_pk_parse_subpubkey()
|
||||
when the input has trailing garbage. Fixes #2512.
|
||||
* Fix build failure in configurations where MBEDTLS_USE_PSA_CRYPTO is
|
||||
enabled but ECDSA is disabled. Contributed by jdurkop. Fixes #3294.
|
||||
|
||||
Vendored
+2
-2
@@ -138,11 +138,11 @@ C_SOURCE_FILES = $(wildcard \
|
||||
tests/suites/*.function \
|
||||
)
|
||||
# Exuberant-ctags invocation. Other ctags implementations may require different options.
|
||||
CTAGS = ctags --langmap=c:+.h.function -o
|
||||
CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
|
||||
tags: $(C_SOURCE_FILES)
|
||||
$(CTAGS) $@ $(C_SOURCE_FILES)
|
||||
TAGS: $(C_SOURCE_FILES)
|
||||
etags -o $@ $(C_SOURCE_FILES)
|
||||
etags --no-line-directive -o $@ $(C_SOURCE_FILES)
|
||||
global: GPATH GRTAGS GSYMS GTAGS
|
||||
GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
|
||||
ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
|
||||
|
||||
Vendored
+18
-1
@@ -25,6 +25,8 @@ To generate a local copy of the library documentation in HTML format, tailored t
|
||||
1. Run `make apidoc`.
|
||||
1. Browse `apidoc/index.html` or `apidoc/modules.html`.
|
||||
|
||||
For other sources of documentation, see the [SUPPORT](SUPPORT.md) document.
|
||||
|
||||
Compiling
|
||||
---------
|
||||
|
||||
@@ -36,7 +38,7 @@ There are currently three active build systems used within Mbed TLS releases:
|
||||
|
||||
The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically.
|
||||
|
||||
The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`. Also, when loading shared libraries using dlopen(), you'll need to load libmbedcrypto first, then libmbedx509, before you can load libmbedtls.
|
||||
The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`.
|
||||
|
||||
### Tool versions
|
||||
|
||||
@@ -195,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)
|
||||
- [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
|
||||
--------------------
|
||||
|
||||
@@ -245,3 +255,10 @@ Contributing
|
||||
------------
|
||||
|
||||
We gratefully accept bug reports and contributions from the community. Please see the [contributing guidelines](CONTRIBUTING.md) for details on how to do this.
|
||||
|
||||
Contact
|
||||
-------
|
||||
|
||||
* To report a security vulnerability in Mbed TLS, please email <mbed-tls-security@lists.trustedfirmware.org>. For more information, see [`SECURITY.md`](SECURITY.md).
|
||||
* To report a bug or request a feature in Mbed TLS, please [file an issue on GitHub](https://github.com/ARMmbed/mbedtls/issues/new/choose).
|
||||
* Please see [`SUPPORT.md`](SUPPORT.md) for other channels for discussion and support about Mbed TLS.
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
## Reporting Vulneratibilities
|
||||
|
||||
If you think you have found an Mbed TLS security vulnerability, then please
|
||||
send an email to the security team at
|
||||
<mbed-tls-security@lists.trustedfirmware.org>.
|
||||
|
||||
## Security Incident Handling Process
|
||||
|
||||
Our security process is detailled in our
|
||||
[security
|
||||
center](https://developer.trustedfirmware.org/w/mbed-tls/security-center/).
|
||||
|
||||
Its primary goal is to ensure fixes are ready to be deployed when the issue
|
||||
goes public.
|
||||
|
||||
## Maintained branches
|
||||
|
||||
Only the maintained branches, as listed in [`BRANCHES.md`](BRANCHES.md),
|
||||
get security fixes.
|
||||
Users are urged to always use the latest version of a maintained branch.
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
## Documentation
|
||||
|
||||
Here are some useful sources of information about using Mbed TLS:
|
||||
|
||||
- API documentation, see the [Documentation section of the
|
||||
README](README.md#License);
|
||||
- the `docs` directory in the source tree;
|
||||
- the [Mbed TLS knowledge Base](https://tls.mbed.org/kb);
|
||||
- the [Mbed TLS mailing-list
|
||||
archives](https://lists.trustedfirmware.org/pipermail/mbed-tls/).
|
||||
|
||||
## Asking Questions
|
||||
|
||||
If you can't find your answer in the above sources, please use the [Mbed TLS
|
||||
mailing list](https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls).
|
||||
-3371
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -80,8 +80,7 @@
|
||||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
/* Save RAM by adjusting to our exact needs */
|
||||
#define MBEDTLS_ECP_MAX_BITS 384
|
||||
#define MBEDTLS_MPI_MAX_SIZE 48 // 384 bits is 48 bytes
|
||||
#define MBEDTLS_MPI_MAX_SIZE 48 // 48 bytes for a 384-bit elliptic curve
|
||||
|
||||
/* Save RAM at the expense of speed, see ecp.h */
|
||||
#define MBEDTLS_ECP_WINDOW_SIZE 2
|
||||
|
||||
+1
-2
@@ -81,8 +81,7 @@
|
||||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
/* Save RAM by adjusting to our exact needs */
|
||||
#define MBEDTLS_ECP_MAX_BITS 256
|
||||
#define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes
|
||||
#define MBEDTLS_MPI_MAX_SIZE 32 // 32 bytes for a 256-bit elliptic curve
|
||||
|
||||
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
|
||||
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
*.html
|
||||
*.pdf
|
||||
!PSACryptoDriverModelSpec.pdf
|
||||
|
||||
Binary file not shown.
+73
@@ -0,0 +1,73 @@
|
||||
PSA Cryptograpy API implementation and PSA driver interface
|
||||
===========================================================
|
||||
|
||||
## Introduction
|
||||
|
||||
The [PSA Cryptography API specification](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) defines an interface to cryptographic operations for which the Mbed TLS library provides a reference implementation. The PSA Cryptography API specification is complemented by the PSA driver interface specification which defines an interface for cryptoprocessor drivers.
|
||||
|
||||
This document describes the high level organization of the Mbed TLS PSA Cryptography API implementation which is tightly related to the PSA driver interface.
|
||||
|
||||
## High level organization of the Mbed TLS PSA Cryptography API implementation
|
||||
In one sentence, the Mbed TLS PSA Cryptography API implementation is made of a core and PSA drivers as defined in the PSA driver interface. The key point is that software cryptographic operations are organized as PSA drivers: they interact with the core through the PSA driver interface.
|
||||
|
||||
### Rationale
|
||||
|
||||
* Addressing software and hardware cryptographic implementations through the same C interface reduces the core code size and its call graph complexity. The core and its dispatching to software and hardware implementations are consequently easier to test and validate.
|
||||
* The organization of the software cryptographic implementations in drivers promotes modularization of those implementations.
|
||||
* As hardware capabilities, software cryptographic functionalities can be described by a JSON driver description file as defined in the PSA driver interface.
|
||||
* Along with JSON driver description files, the PSA driver specification defines the deliverables for a driver to be included into the Mbed TLS PSA Cryptography implementation. This provides a natural framework to integrate third party or alternative software implementations of cryptographic operations.
|
||||
|
||||
## The Mbed TLS PSA Cryptography API implementation core
|
||||
|
||||
The core implements all the APIs as defined in the PSA Cryptography API specification but does not perform on its own any cryptographic operation. The core relies on PSA drivers to actually
|
||||
perform the cryptographic operations. The core is responsible for:
|
||||
|
||||
* the key store.
|
||||
* checking PSA API arguments and translating them into valid arguments for the necessary calls to the PSA driver interface.
|
||||
* dispatching the cryptographic operations to the appropriate PSA drivers.
|
||||
|
||||
The sketch of an Mbed TLS PSA cryptographic API implementation is thus:
|
||||
```C
|
||||
psa_status_t psa_api( ... )
|
||||
{
|
||||
psa_status_t status;
|
||||
|
||||
/* Pre driver interface call processing: validation of arguments, building
|
||||
* of arguments for the call to the driver interface, ... */
|
||||
|
||||
...
|
||||
|
||||
/* Call to the driver interface */
|
||||
status = psa_driver_wrapper_<entry_point>( ... );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
/* Post driver interface call processing: validation of the values returned
|
||||
* by the driver, finalization of the values to return to the caller,
|
||||
* clean-up in case of error ... */
|
||||
}
|
||||
```
|
||||
The code of most PSA APIs is expected to match precisely the above layout. However, it is likely that the code structure of some APIs will be more complicated with several calls to the driver interface, mainly to encompass a larger variety of hardware designs. For example, to encompass hardware accelerators that are capable of verifying a MAC and those that are only capable of computing a MAC, the psa_mac_verify() API could call first psa_driver_wrapper_mac_verify() and then fallback to psa_driver_wrapper_mac_compute().
|
||||
|
||||
The implementations of `psa_driver_wrapper_<entry_point>` functions are generated by the build system based on the JSON driver description files of the various PSA drivers making up the Mbed TLS PSA Cryptography API implementation. The implementations are generated in a psa_crypto_driver_wrappers.c C file and the function prototypes declared in a psa_crypto_driver_wrappers.h header file.
|
||||
|
||||
The psa_driver_wrapper_<entry_point>() functions dispatch cryptographic operations to accelerator drivers, secure element drivers as well as to the software implementations of cryptographic operations.
|
||||
|
||||
Note that the implementation allows to build the library with only a C compiler by shipping a generated file corresponding to a pure software implementation. The driver entry points and their code in this generated file are guarded by pre-processor directives based on PSA_WANT_xyz macros (see [Conditional inclusion of cryptographic mechanism through the PSA API in Mbed TLS](psa-conditional-inclusion-c.html). That way, it is possible to compile and include in the library only the desired cryptographic operations.
|
||||
|
||||
### Key creation
|
||||
|
||||
Key creation implementation in Mbed TLS PSA core is articulated around three internal functions: psa_start_key_creation(), psa_finish_key_creation() and psa_fail_key_creation(). Implementations of key creation PSA APIs, namely psa_import_key(), psa_generate_key(), psa_key_derivation_output_key() and psa_copy_key() go by the following sequence:
|
||||
1. Check the input parameters.
|
||||
2. Call psa_start_key_creation() that allocates a key slot, prepares it with the specified key attributes, and in case of a volatile key assign it a volatile key identifier.
|
||||
3. Generate or copy the key material into the key slot. This entails the allocation of the buffer to store the key material.
|
||||
4. Call psa_finish_key_creation() that mostly saves persistent keys into persistent storage.
|
||||
|
||||
In case of any error occurring at step 3 or 4, psa_fail_key_creation() is called. It wipes and cleans the slot especially the key material: reset to zero of the RAM memory that contained the key material, free the allocated buffer.
|
||||
|
||||
|
||||
## Mbed TLS PSA Cryptography API implementation drivers
|
||||
|
||||
A driver of the Mbed TLS PSA Cryptography API implementation (Mbed TLS PSA driver in the following) is a driver in the sense that it is compliant with the PSA driver interface specification. But it is not an actual driver that drives some hardware. It implements cryptographic operations purely in software.
|
||||
|
||||
An Mbed TLS PSA driver C file is named psa_crypto_<driver_name>.c and its associated header file psa_crypto_<driver_name>.h. The functions implementing a driver entry point as defined in the PSA driver interface specification are named as mbedtls_psa_<driver name>_<entry point>(). As an example, the psa_crypto_rsa.c and psa_crypto_rsa.h are the files containing the Mbed TLS PSA driver implementing RSA cryptographic operations. This RSA driver implements among other entry points the "import_key" entry point. The function implementing this entry point is named mbedtls_psa_rsa_import_key().
|
||||
+28
-10
@@ -4,9 +4,19 @@ This document describes the test strategy for the driver interfaces in Mbed Cryp
|
||||
|
||||
The driver interfaces are standardized through PSA Cryptography functional specifications.
|
||||
|
||||
## Secure element driver interface
|
||||
## Secure element driver interface testing
|
||||
|
||||
The secure element driver interface (SE interface for short) is defined by [`psa/crypto_se_driver.h`](../../../include/psa/crypto_se_driver.h). This is an interface between Mbed Crypto and one or more third-party drivers.
|
||||
### Secure element driver interfaces
|
||||
|
||||
#### Opaque driver interface
|
||||
|
||||
The [unified driver interface](../../proposed/psa-driver-interface.md) supports both transparent drivers (for accelerators) and opaque drivers (for secure elements).
|
||||
|
||||
Drivers exposing this interface need to be registered at compile time by declaring their JSON description file.
|
||||
|
||||
#### Dynamic secure element driver interface
|
||||
|
||||
The dynamic secure element driver interface (SE interface for short) is defined by [`psa/crypto_se_driver.h`](../../../include/psa/crypto_se_driver.h). This is an interface between Mbed Crypto and one or more third-party drivers.
|
||||
|
||||
The SE interface consists of one function provided by Mbed Crypto (`psa_register_se_driver`) and many functions that drivers must implement. To make a driver usable by Mbed Crypto, the initialization code must call `psa_register_se_driver` with a structure that describes the driver. The structure mostly contains function pointers, pointing to the driver's methods. All calls to a driver function are triggered by a call to a PSA crypto API function.
|
||||
|
||||
@@ -18,6 +28,8 @@ Many SE driver interface unit tests could be covered by running the existing API
|
||||
|
||||
#### SE driver registration
|
||||
|
||||
This applies to dynamic drivers only.
|
||||
|
||||
* Test `psa_register_se_driver` with valid and with invalid arguments.
|
||||
* Make at least one failing call to `psa_register_se_driver` followed by a successful call.
|
||||
* Make at least one test that successfully registers the maximum number of drivers and fails to register one more.
|
||||
@@ -102,14 +114,20 @@ We should have at least one driver that covers the whole interface:
|
||||
|
||||
A PKCS#11 driver would be a good candidate. It would be useful as part of our product offering.
|
||||
|
||||
## Accelerator driver interface
|
||||
## Transparent driver interface testing
|
||||
|
||||
The accelerator driver interface is defined by [`psa/crypto_accel_driver.h`](../../../include/psa/crypto_accel_driver.h).
|
||||
|
||||
TODO
|
||||
|
||||
## Entropy driver interface
|
||||
|
||||
The entropy driver interface is defined by [`psa/crypto_entropy_driver.h`](../../../include/psa/crypto_entropy_driver.h).
|
||||
The [unified driver interface](../../proposed/psa-driver-interface.md) defines interfaces for accelerators.
|
||||
|
||||
### Test requirements
|
||||
|
||||
#### Requirements for transparent driver testing
|
||||
|
||||
Every cryptographic mechanism for which a transparent driver interface exists (key creation, cryptographic operations, …) must be exercised in at least one build. The test must verify that the driver code is called.
|
||||
|
||||
#### Requirements for fallback
|
||||
|
||||
The driver interface includes a fallback mechanism so that a driver can reject a request at runtime and let another driver handle the request. For each entry point, there must be at least three test runs with two or more drivers available with driver A configured to fall back to driver B, with one run where A returns `PSA_SUCCESS`, one where A returns `PSA_ERROR_NOT_SUPPORTED` and B is invoked, and one where A returns a different error and B is not invoked.
|
||||
|
||||
## Entropy and randomness interface testing
|
||||
|
||||
TODO
|
||||
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
# Mbed TLS PSA keystore format stability testing strategy
|
||||
|
||||
## Introduction
|
||||
|
||||
The PSA crypto subsystem includes a persistent key store. It is possible to create a persistent key and read it back later. This must work even if Mbed TLS has been upgraded in the meantime (except for deliberate breaks in the backward compatibility of the storage).
|
||||
|
||||
The goal of this document is to define a test strategy for the key store that not only validates that it's possible to load a key that was saved with the version of Mbed TLS under test, but also that it's possible to load a key that was saved with previous versions of Mbed TLS.
|
||||
|
||||
Interoperability is not a goal: PSA crypto implementations are not intended to have compatible storage formats. Downgrading is not required to work.
|
||||
|
||||
## General approach
|
||||
|
||||
### Limitations of a direct approach
|
||||
|
||||
The goal of storage format stability testing is: as a user of Mbed TLS, I want to store a key under version V and read it back under version W, with W ≥ V.
|
||||
|
||||
Doing the testing this way would be difficult because we'd need to have version V of Mbed TLS available when testing version W.
|
||||
|
||||
An alternative, semi-direct approach consists of generating test data under version V, and reading it back under version W. Done naively, this would require keeping a large amount of test data (full test coverage multiplied by the number of versions that we want to preserve backward compatibility with).
|
||||
|
||||
### Save-and-compare approach
|
||||
|
||||
Importing and saving a key is deterministic. Therefore we can ensure the stability of the storage format by creating test cases under a version V of Mbed TLS, where the test case parameters include both the parameters to pass to key creation and the expected state of the storage after the key is created. The test case creates a key as indicated by the parameters, then compares the actual state of the storage with the expected state.
|
||||
|
||||
In addition, the test case also loads the key and checks that it has the expected data and metadata. Import-and-save testing and load-and-check testing can be split into separate test functions with the same payloads.
|
||||
|
||||
If the test passes with version V, this means that the test data is consistent with what the implementation does. When the test later runs under version W ≥ V, it creates and reads back a storage state which is known to be identical to the state that V would have produced. Thus, this approach validates that W can read storage states created by V.
|
||||
|
||||
Note that it is the combination of import-and-save passing on version V and load-and-check passing on version W with the same data that proves that version W can read back what version V wrote. From the perspective of a particular version of the library, the import-and-save tests guarantee forward compatibility while the load-and-check tests guarantee backward compatibility.
|
||||
|
||||
Use a similar approach for files other than keys where possible and relevant.
|
||||
|
||||
### Keeping up with storage format evolution
|
||||
|
||||
Test cases should normally not be removed from the code base: if something has worked before, it should keep working in future versions, so we should keep testing it.
|
||||
|
||||
This cannot be enforced solely by looking at a single version of Mbed TLS, since there would be no indication that more test cases used to exist. It can only be enforced through review of library changes. The review may be assisted by a tool that compares the old and the new version, in the same way that `abi-check.py` compares the library's API and ABI.
|
||||
|
||||
If the way certain keys are stored changes, and we don't deliberately decide to stop supporting old keys (which should only be done by retiring a version of the storage format), then we should keep the corresponding test cases in load-only mode: create a file with the expected content, load it and check the data that it contains.
|
||||
|
||||
## Storage architecture overview
|
||||
|
||||
The PSA subsystem provides storage on top of the PSA trusted storage interface. The state of the storage is a mapping from file identifer (a 64-bit number) to file content (a byte array). These files include:
|
||||
|
||||
* [Key files](#key-storage) (files containing one key's metadata and, except for some secure element keys, key material).
|
||||
* The [random generator injected seed or state file](#random-generator-state) (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`).
|
||||
* [Storage transaction file](#storage-transaction-resumption).
|
||||
* [Driver state files](#driver-state-files).
|
||||
|
||||
For a more detailed description, refer to the [Mbed Crypto storage specification](../mbed-crypto-storage-specification.md).
|
||||
|
||||
In addition, Mbed TLS includes an implementation of the PSA trusted storage interface on top of C stdio. This document addresses the test strategy for [PSA ITS over file](#psa-its-over-file) in a separate section below.
|
||||
|
||||
## Key storage testing
|
||||
|
||||
This section describes the desired test cases for keys created with the current storage format version. When the storage format changes, if backward compatibility is desired, old test data should be kept as described under [“Keeping up with storage format evolution”](#keeping-up-with-storage-format-evolution).
|
||||
|
||||
### Keystore layout
|
||||
|
||||
Objective: test that the key file name corresponds to the key identifier.
|
||||
|
||||
Method: Create a key with a given identifier (using `psa_import_key`) and verify that a file with the expected name is created, and no other. Repeat for different identifiers.
|
||||
|
||||
### General key format
|
||||
|
||||
Objective: test the format of the key file: which field goes where and how big it is.
|
||||
|
||||
Method: Create a key with certain metadata with `psa_import_key`. Read the file content and validate that it has the expected layout, deduced from the storage specification. Repeat with different metadata. Ensure that there are test cases covering all fields.
|
||||
|
||||
### Enumeration of test cases for keys
|
||||
|
||||
Objective: ensure that the coverage is sufficient to have assurance that all keys are stored correctly. This requires a sufficient selection of key types, sizes, policies, etc.
|
||||
|
||||
In particular, the tests must validate that each `PSA_xxx` constant that is stored in a key is covered by at least one test case:
|
||||
|
||||
* Lifetimes: `PSA_KEY_LIFETIME_xxx`, `PSA_KEY_PERSISTENCE_xxx`, `PSA_KEY_LOCATION_xxx`.
|
||||
* Usage flags: `PSA_KEY_USAGE_xxx`.
|
||||
* Algorithms in policies: `PSA_ALG_xxx`.
|
||||
* Key types: `PSA_KEY_TYPE_xxx`, `PSA_ECC_FAMILY_xxx`, `PSA_DH_FAMILY_xxx`.
|
||||
|
||||
In addition, the coverage of key material must ensure that any variation in key representation is detected. See [“Considerations on key material representations”](#Considerations-on-key-material-representations) for considerations regarding key types.
|
||||
|
||||
Method: Each test case creates a key with `psa_import_key`, purges it from memory, then reads it back and exercises it.
|
||||
|
||||
Generate test cases automatically based on an enumeration of available constants and some knowledge of what attributes (sizes, algorithms, …) and content to use for keys of a certain type.
|
||||
|
||||
### Testing with alternative lifetime values
|
||||
|
||||
Objective: have test coverage for lifetimes other than the default persistent lifetime (`PSA_KEY_LIFETIME_PERSISTENT`).
|
||||
|
||||
Method:
|
||||
|
||||
* For alternative locations: have tests conditional on the presence of a driver for that location.
|
||||
* For alternative persistence levels: have load-and-check tests for supported persistence levels. We may also want to have negative tests ensuring that keys with a not-supported persistence level are not accidentally created.
|
||||
|
||||
### Considerations on key material representations
|
||||
|
||||
The risks of incompatibilities in key representations depends on the key type and on the presence of drivers. Compatibility of and with drivers is currently out of scope of this document.
|
||||
|
||||
Some types only have one plausible representation. Others admit alternative plausible representations (different encodings, or non-canonical representations).
|
||||
Here are some areas to watch for, with an identified risk of incompatibilities.
|
||||
|
||||
* HMAC keys longer than the block size: pre-hashed or not?
|
||||
* DES keys: was parity enforced?
|
||||
* RSA keys: can invalid DER encodings (e.g. leading zeros, ignored sign bit) have been stored?
|
||||
* RSA private keys: can invalid CRT parameters have been stored?
|
||||
* Montgomery private keys: were they stored in masked form?
|
||||
|
||||
## Random generator state
|
||||
|
||||
TODO
|
||||
|
||||
## Driver state files
|
||||
|
||||
Not yet implemented.
|
||||
|
||||
TODO
|
||||
|
||||
## Storage transaction resumption
|
||||
|
||||
Only relevant for secure element support. Not yet fully implemented.
|
||||
|
||||
TODO
|
||||
|
||||
## PSA ITS over file
|
||||
|
||||
TODO
|
||||
@@ -47,3 +47,22 @@ together with their level of testing:
|
||||
Those functions are implemented in `library/ssl_tls13_keys.c` and
|
||||
tested in `test_suite_ssl` using test vectors from RFC 8448 and
|
||||
https://tls13.ulfheim.net/.
|
||||
|
||||
- New TLS Message Processing Stack (MPS)
|
||||
|
||||
The TLS 1.3 prototype is developed alongside a rewrite of the TLS messaging layer,
|
||||
encompassing low-level details such as record parsing, handshake reassembly, and
|
||||
DTLS retransmission state machine.
|
||||
|
||||
MPS has the following components:
|
||||
- Layer 1 (Datagram handling)
|
||||
- Layer 2 (Record handling)
|
||||
- Layer 3 (Message handling)
|
||||
- Layer 4 (Retransmission State Machine)
|
||||
- Reader (Abstracted pointer arithmetic and reassembly logic for incoming data)
|
||||
- Writer (Abstracted pointer arithmetic and fragmentation logic for outgoing data)
|
||||
|
||||
Of those components, the following have been upstreamed
|
||||
as part of `MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL`:
|
||||
|
||||
- Reader ([`library/mps_reader.h`](../../library/mps_reader.h))
|
||||
|
||||
+31
-31
@@ -76,7 +76,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
||||
{
|
||||
psa_status_t status;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Import an AES key...\t");
|
||||
fflush(stdout);
|
||||
@@ -95,7 +95,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
||||
psa_set_key_bits(&attributes, 128);
|
||||
|
||||
/* Import the key */
|
||||
status = psa_import_key(&attributes, key, key_len, &key);
|
||||
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to import key\n");
|
||||
return;
|
||||
@@ -106,7 +106,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
}
|
||||
@@ -135,7 +135,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
||||
0xa9, 0xe8, 0xcc, 0xac, 0xd0, 0xf6, 0x54, 0x5c};
|
||||
uint8_t signature[PSA_SIGNATURE_MAX_SIZE] = {0};
|
||||
size_t signature_length;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Sign a message...\t");
|
||||
fflush(stdout);
|
||||
@@ -154,14 +154,14 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
||||
psa_set_key_bits(&attributes, 1024);
|
||||
|
||||
/* Import the key */
|
||||
status = psa_import_key(&attributes, key, key_len, &key);
|
||||
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to import key\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Sign message using the key */
|
||||
status = psa_sign_hash(key, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
|
||||
status = psa_sign_hash(key_id, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
|
||||
hash, sizeof(hash),
|
||||
signature, sizeof(signature),
|
||||
&signature_length);
|
||||
@@ -176,7 +176,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
}
|
||||
@@ -203,7 +203,7 @@ This example shows how to encrypt data using an AES (Advanced Encryption Standar
|
||||
void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
{
|
||||
enum {
|
||||
block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE(PSA_KEY_TYPE_AES),
|
||||
block_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES),
|
||||
};
|
||||
psa_status_t status;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
@@ -213,7 +213,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
size_t iv_len;
|
||||
uint8_t output[block_size];
|
||||
size_t output_len;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||
|
||||
printf("Encrypt with cipher...\t");
|
||||
@@ -232,7 +232,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_set_key_algorithm(&attributes, alg);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_bits(&attributes, 128);
|
||||
status = psa_import_key(&attributes, key, key_len, &key);
|
||||
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to import a key\n");
|
||||
return;
|
||||
@@ -240,7 +240,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Encrypt the plaintext */
|
||||
status = psa_cipher_encrypt_setup(&operation, key, alg);
|
||||
status = psa_cipher_encrypt_setup(&operation, key_id, alg);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to begin cipher operation\n");
|
||||
return;
|
||||
@@ -268,7 +268,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_cipher_abort(&operation);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
}
|
||||
@@ -288,7 +288,7 @@ This example shows how to decrypt encrypted data using an AES key in CBC mode wi
|
||||
void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
{
|
||||
enum {
|
||||
block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE(PSA_KEY_TYPE_AES),
|
||||
block_size = PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES),
|
||||
};
|
||||
psa_status_t status;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
@@ -298,7 +298,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
uint8_t iv[block_size] = ENCRYPTED_WITH_IV;
|
||||
uint8_t output[block_size];
|
||||
size_t output_len;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Decrypt with cipher...\t");
|
||||
fflush(stdout);
|
||||
@@ -316,7 +316,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_set_key_algorithm(&attributes, alg);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_bits(&attributes, 128);
|
||||
status = psa_import_key(&attributes, key, key_len, &key);
|
||||
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to import a key\n");
|
||||
return;
|
||||
@@ -324,7 +324,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Decrypt the ciphertext */
|
||||
status = psa_cipher_decrypt_setup(&operation, key, alg);
|
||||
status = psa_cipher_decrypt_setup(&operation, key_id, alg);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to begin cipher operation\n");
|
||||
return;
|
||||
@@ -352,7 +352,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
psa_cipher_abort(&operation);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
}
|
||||
@@ -445,7 +445,7 @@ This example shows how to verify the SHA-256 hash of a message:
|
||||
0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
|
||||
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
|
||||
};
|
||||
size_t expected_hash_len = PSA_HASH_SIZE(alg);
|
||||
size_t expected_hash_len = PSA_HASH_LENGTH(alg);
|
||||
|
||||
printf("Verify a hash...\t");
|
||||
fflush(stdout);
|
||||
@@ -482,7 +482,7 @@ This example shows how to verify the SHA-256 hash of a message:
|
||||
mbedtls_psa_crypto_free();
|
||||
```
|
||||
|
||||
The API provides the macro `PSA_HASH_SIZE`, which returns the expected hash length (in bytes) for the specified algorithm.
|
||||
The API provides the macro `PSA_HASH_LENGTH`, which returns the expected hash length (in bytes) for the specified algorithm.
|
||||
|
||||
#### Handling hash operation contexts
|
||||
|
||||
@@ -702,7 +702,7 @@ This example shows how to authenticate and encrypt a message:
|
||||
size_t output_length = 0;
|
||||
size_t tag_length = 16;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Authenticate encrypt...\t");
|
||||
fflush(stdout);
|
||||
@@ -726,11 +726,11 @@ This example shows how to authenticate and encrypt a message:
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_bits(&attributes, 128);
|
||||
status = psa_import_key(&attributes, key, sizeof(key), &key);
|
||||
status = psa_import_key(&attributes, key, sizeof(key), &key_id);
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Authenticate and encrypt */
|
||||
status = psa_aead_encrypt(key, PSA_ALG_CCM,
|
||||
status = psa_aead_encrypt(key_id, PSA_ALG_CCM,
|
||||
nonce, sizeof(nonce),
|
||||
additional_data, sizeof(additional_data),
|
||||
input_data, sizeof(input_data),
|
||||
@@ -747,7 +747,7 @@ This example shows how to authenticate and encrypt a message:
|
||||
free(output_data);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
```
|
||||
@@ -773,7 +773,7 @@ This example shows how to authenticate and decrypt a message:
|
||||
size_t output_size = 0;
|
||||
size_t output_length = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Authenticate decrypt...\t");
|
||||
fflush(stdout);
|
||||
@@ -797,7 +797,7 @@ This example shows how to authenticate and decrypt a message:
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_bits(&attributes, 128);
|
||||
status = psa_import_key(&attributes, key_data, sizeof(key_data), &key);
|
||||
status = psa_import_key(&attributes, key_data, sizeof(key_data), &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to import a key\n");
|
||||
return;
|
||||
@@ -805,7 +805,7 @@ This example shows how to authenticate and decrypt a message:
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
/* Authenticate and decrypt */
|
||||
status = psa_aead_decrypt(key, PSA_ALG_CCM,
|
||||
status = psa_aead_decrypt(key_id, PSA_ALG_CCM,
|
||||
nonce, sizeof(nonce),
|
||||
additional_data, sizeof(additional_data),
|
||||
input_data, sizeof(input_data),
|
||||
@@ -822,7 +822,7 @@ This example shows how to authenticate and decrypt a message:
|
||||
free(output_data);
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
```
|
||||
@@ -848,7 +848,7 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
size_t exported_length = 0;
|
||||
static uint8_t exported[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits)];
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t key;
|
||||
psa_key_id_t key_id;
|
||||
|
||||
printf("Generate a key pair...\t");
|
||||
fflush(stdout);
|
||||
@@ -867,14 +867,14 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
psa_set_key_type(&attributes,
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
|
||||
psa_set_key_bits(&attributes, key_bits);
|
||||
status = psa_generate_key(&attributes, &key);
|
||||
status = psa_generate_key(&attributes, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to generate key\n");
|
||||
return;
|
||||
}
|
||||
psa_reset_key_attributes(&attributes);
|
||||
|
||||
status = psa_export_public_key(key, exported, sizeof(exported),
|
||||
status = psa_export_public_key(key_id, exported, sizeof(exported),
|
||||
&exported_length);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("Failed to export public key %ld\n", status);
|
||||
@@ -884,7 +884,7 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
printf("Exported a public key\n");
|
||||
|
||||
/* Destroy the key */
|
||||
psa_destroy_key(key);
|
||||
psa_destroy_key(key_id);
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
```
|
||||
|
||||
@@ -5,8 +5,6 @@ This document is a proposed interface for deciding at build time which cryptogra
|
||||
|
||||
This is currently a proposal for Mbed TLS. It is not currently on track for standardization in PSA.
|
||||
|
||||
Time-stamp: "2020/11/26 09:30:50 GMT"
|
||||
|
||||
## Introduction
|
||||
|
||||
### Purpose of this specification
|
||||
@@ -86,9 +84,17 @@ For each constant or constructor macro of the form `PSA_KEY_TYPE_xxx`, the symbo
|
||||
|
||||
For asymmetric cryptography, `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR` determines whether private-key operations are desired, and `PSA_WANT_KEY_TYPE_xxx_PUBLIC_KEY` determines whether public-key operations are desired. `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR` implicitly enables `PSA_WANT_KEY_TYPE_xxx_PUBLIC_KEY`: there is no way to only include private-key operations (which typically saves little code).
|
||||
|
||||
#### Configuration symbols for curves
|
||||
#### Configuration symbols for elliptic curves
|
||||
|
||||
For elliptic curve key types, only the specified curves are included. To include a curve, include a symbol of the form **`PSA_WANT_ECC_family_size`**. For example: `PSA_WANT_ECC_SECP_R1_256` for secp256r1, `PSA_WANT_ECC_MONTGOMERY_CURVE25519`. It is an error to require an ECC key type but no curve, and Mbed TLS will reject this at compile time.
|
||||
For elliptic curve key types, only the specified curves are included. To include a curve, include a symbol of the form **`PSA_WANT_ECC_family_size`**. For example: `PSA_WANT_ECC_SECP_R1_256` for secp256r1, `PSA_WANT_ECC_MONTGOMERY_255` for Curve25519. It is an error to require an ECC key type but no curve, and Mbed TLS will reject this at compile time.
|
||||
|
||||
Rationale: this is a deviation of the general principle that `PSA_ECC_FAMILY_xxx` would have a corresponding symbol `PSA_WANT_ECC_FAMILY_xxx`. This deviation is justified by the fact that it is very common to wish to include only certain curves in a family, and that can lead to a significant gain in code size.
|
||||
|
||||
#### Configuration symbols for Diffie-Hellman groups
|
||||
|
||||
There are no configuration symbols for Diffie-Hellman groups (`PSA_DH_GROUP_xxx`).
|
||||
|
||||
Rationale: Finite-field Diffie-Hellman code is usually not specialized for any particular group, so reducing the number of available groups at compile time only saves a little code space. Constrained implementations tend to omit FFDH anyway, so the small code size gain is not important.
|
||||
|
||||
#### Configuration symbols for algorithms
|
||||
|
||||
@@ -195,7 +201,7 @@ The boolean symbol mechanism proposed here can be translated to a list of JSON c
|
||||
|
||||
#### Naming of symbols
|
||||
|
||||
The names of [elliptic curve symbols](#configuration-symbols-for-curves) are a bit weird: `SECP_R1_256` instead of `SECP256R1`. Should we make them more classical, but less systematic?
|
||||
The names of [elliptic curve symbols](#configuration-symbols-for-elliptic-curves) are a bit weird: `SECP_R1_256` instead of `SECP256R1`, `MONTGOMERY_255` instead of `CURVE25519`. Should we make them more classical, but less systematic?
|
||||
|
||||
#### Impossible combinations
|
||||
|
||||
|
||||
+218
-6
@@ -5,8 +5,6 @@ This document describes an interface for cryptoprocessor drivers in the PSA cryp
|
||||
|
||||
This specification is work in progress and should be considered to be in a beta stage. There is ongoing work to implement this interface in Mbed TLS, which is the reference implementation of the PSA Cryptography API. At this stage, Arm does not expect major changes, but minor changes are expected based on experience from the first implementation and on external feedback.
|
||||
|
||||
Time-stamp: "2020/11/24 11:03:32 GMT"
|
||||
|
||||
## Introduction
|
||||
|
||||
### Purpose of the driver interface
|
||||
@@ -136,7 +134,7 @@ Example 2: the following capability declares that the driver can perform determ
|
||||
"entry_points": ["sign_hash"],
|
||||
"algorithms": ["PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256)",
|
||||
"PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_384)"],
|
||||
"key_types": ["PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP_R1)"],
|
||||
"key_types": ["PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)"],
|
||||
"key_sizes": [256, 384]
|
||||
}
|
||||
```
|
||||
@@ -166,7 +164,7 @@ The name `_` may be used instead of a curve or group to indicate that the capabi
|
||||
Valid examples:
|
||||
```
|
||||
PSA_KEY_TYPE_AES
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP_R1)
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(_)
|
||||
```
|
||||
|
||||
@@ -196,6 +194,8 @@ The signature of a driver entry point generally looks like the signature of the
|
||||
|
||||
Some entry points are grouped in families that must be implemented as a whole. If a driver supports an entry point family, it must provide all the entry points in the family.
|
||||
|
||||
Drivers can also have entry points related to random generation. A transparent driver can provide a [random generation interface](#random-generation-entry-points). Separately, transparent and opaque drivers can have [entropy collection entry points](#entropy-collection-entry-point).
|
||||
|
||||
#### General considerations on driver entry point parameters
|
||||
|
||||
Buffer parameters for driver entry points obey the following conventions:
|
||||
@@ -375,6 +375,49 @@ This section describes some minimal validity requirements for standard key types
|
||||
* For elliptic curve private keys (`PSA_KEY_TYPE_ECC_KEY_PAIR`), check the size and range. TODO: what else?
|
||||
* For elliptic curve public keys (`PSA_KEY_TYPE_ECC_PUBLIC_KEY`), check the size and range, and that the point is on the curve. TODO: what else?
|
||||
|
||||
### Entropy collection entry point
|
||||
|
||||
A driver can declare an entropy source by providing a `"get_entropy"` entry point. This entry point has the following prototype for a driver with the prefix `"acme"`:
|
||||
|
||||
```
|
||||
psa_status_t acme_get_entropy(uint32_t flags,
|
||||
size_t *estimate_bits,
|
||||
uint8_t *output,
|
||||
size_t output_size);
|
||||
```
|
||||
|
||||
The semantics of the parameters is as follows:
|
||||
|
||||
* `flags`: a bit-mask of [entropy collection flags](#entropy-collection-flags).
|
||||
* `estimate_bits`: on success, an estimate of the amount of entropy that is present in the `output` buffer, in bits. This must be at least `1` on success. The value is ignored on failure. Drivers should return a conservative estimate, even in circumstances where the quality of the entropy source is degraded due to environmental conditions (e.g. undervolting, low temperature, etc.).
|
||||
* `output`: on success, this buffer contains non-deterministic data with an estimated entropy of at least `*estimate_bits` bits. When the entropy is coming from a hardware peripheral, this should preferably be raw or lightly conditioned measurements from a physical process, such that statistical tests run over a sufficiently large amount of output can confirm the entropy estimates. But this specification also permits entropy sources that are fully conditioned, for example when the PSA Cryptography system is running as an application in an operating system and `"get_entropy"` returns data from the random generator in the operating system's kernel.
|
||||
* `output_size`: the size of the `output` buffer in bytes. This size should be large enough to allow a driver to pass unconditioned data with a low density of entropy; for example a peripheral that returns eight bytes of data with an estimated one bit of entropy cannot provide meaningful output in less than 8 bytes.
|
||||
|
||||
Note that there is no output parameter indicating how many bytes the driver wrote to the buffer. Such an output length indication is not necessary because the entropy may be located anywhere in the buffer, so the driver may write less than `output_size` bytes but the core does not need to know this. The output parameter `estimate_bits` contains the amount of entropy, expressed in bits, which may be significantly less than `output_size * 8`.
|
||||
|
||||
The entry point may return the following statuses:
|
||||
|
||||
* `PSA_SUCCESS`: success. The output buffer contains some entropy.
|
||||
* `PSA_ERROR_INSUFFICIENT_ENTROPY`: no entropy is available without blocking. This is only permitted if the `PSA_DRIVER_GET_ENTROPY_BLOCK` flag is clear. The core may call `get_entropy` again later, giving time for entropy to be gathered or for adverse environmental conditions to be rectified.
|
||||
* Other error codes indicate a transient or permanent failure of the entropy source.
|
||||
|
||||
Unlike most other entry points, if multiple transparent drivers include a `"get_entropy"` point, the core will call all of them (as well as the entry points from opaque drivers). Fallback is not applicable to `"get_entropy"`.
|
||||
|
||||
#### Entropy collection flags
|
||||
|
||||
* `PSA_DRIVER_GET_ENTROPY_BLOCK`: If this flag is set, the driver should block until it has at least one bit of entropy. If this flag is clear, the driver should avoid blocking if no entropy is readily available.
|
||||
* `PSA_DRIVER_GET_ENTROPY_KEEPALIVE`: This flag is intended to help with energy management for entropy-generating peripherals. If this flag is set, the driver should expect another call to `acme_get_entropy` after a short time. If this flag is clear, the core is not expecting to call the `"get_entropy"` entry point again within a short amount of time (but it may do so nonetheless).
|
||||
|
||||
#### Entropy collection and blocking
|
||||
|
||||
The intent of the `BLOCK` and `KEEPALIVE` [flags](#entropy-collection-flags) is to support drivers for TRNG (True Random Number Generator, i.e. an entropy source peripheral) that have a long ramp-up time, especially on platforms with multiple entropy sources.
|
||||
|
||||
Here is a suggested call sequence for entropy collection that leverages these flags:
|
||||
|
||||
1. The core makes a first round of calls to `"get_entropy"` on every source with the `BLOCK` flag clear and the `KEEPALIVE` flag set, so that drivers can prepare the TRNG peripheral.
|
||||
2. The core makes a second round of calls with the `BLOCK` flag set and the `KEEPALIVE` flag clear to gather needed entropy.
|
||||
3. If the second round does not collect enough entropy, the core makes more similar rounds, until the total amount of collected entropy is sufficient.
|
||||
|
||||
### Miscellaneous driver entry points
|
||||
|
||||
#### Driver initialization
|
||||
@@ -428,6 +471,109 @@ This entry point has several roles:
|
||||
3. [Determine the key size](#key-size-determination-on-import) and output it through `*bits`.
|
||||
4. Copy the validated key data from `data` to `key_buffer`. The output must be in the canonical format documented for [`psa_export_key()`](https://armmbed.github.io/mbed-crypto/html/api/keys/management.html#c.psa_export_key) or [`psa_export_public_key()`](https://armmbed.github.io/mbed-crypto/html/api/keys/management.html#c.psa_export_public_key), so if the input is not in this format, the entry point must convert it.
|
||||
|
||||
### Random generation entry points
|
||||
|
||||
A transparent driver may provide an operation family that can be used as a cryptographic random number generator. The random generation mechanism must obey the following requirements:
|
||||
|
||||
* The random output must be of cryptographic quality, with a uniform distribution. Therefore, if the random generator includes an entropy source, this entropy source must be fed through a CSPRNG (cryptographically secure pseudo-random number generator).
|
||||
* Random generation is expected to be fast. (If a device can provide entropy but is slow at generating random data, declare it as an [entropy driver](#entropy-collection-entry-point) instead.)
|
||||
* The random generator should be able to incorporate entropy provided by an outside source. If it isn't, the random generator can only be used if it's the only entropy source on the platform. (A random generator peripheral can be declared as an [entropy source](#entropy-collection-entry-point) instead of a random generator; this way the core will combine it with other entropy sources.)
|
||||
* The random generator may either be deterministic (in the sense that it always returns the same data when given the same entropy inputs) or non-deterministic (including its own entropy source). In other words, this interface is suitable both for PRNG (pseudo-random number generator, also known as DRBG (deterministic random bit generator)) and for NRBG (non-deterministic random bit generator).
|
||||
|
||||
If no driver implements the random generation entry point family, the core provides an unspecified random generation mechanism.
|
||||
|
||||
This operation family requires the following type, entry points and parameters (TODO: where exactly are the parameters in the JSON structure?):
|
||||
|
||||
* Type `"random_context_t"`: the type of a random generation context.
|
||||
* `"init_random"` (entry point, optional): if this function is present, [the core calls it once](#random-generator-initialization) after allocating a `"random_context_t"` object.
|
||||
* `"add_entropy"` (entry point, optional): the core calls this function to [inject entropy](#entropy-injection). This entry point is optional if the driver is for a peripheral that includes an entropy source of its own, however [random generator drivers without entropy injection](#random-generator-drivers-without-entropy-injection) have limited portability since they can only be used on platforms with no other entropy source. This entry point is mandatory if `"initial_entropy_size"` is nonzero.
|
||||
* `"get_random"` (entry point, mandatory): the core calls this function whenever it needs to [obtain random data](#the-get_random-entry-point).
|
||||
* `"initial_entropy_size"` (integer, mandatory): the minimum number of bytes of entropy that the core must supply before the driver can output random data. This can be `0` if the driver is for a peripheral that includes an entropy source of its own.
|
||||
* `"reseed_entropy_size"` (integer, optional): the minimum number of bytes of entropy that the core should supply via [`"add_entropy"`](#entropy-injection) when the driver runs out of entropy. This value is also a hint for the size to supply if the core makes additional calls to `"add_entropy"`, for example to enforce prediction resistance. If omitted, the core should pass an amount of entropy corresponding to the expected security strength of the device (for example, pass 32 bytes of entropy when reseeding to achieve a security strength of 256 bits). If specified, the core should pass the larger of `"reseed_entropy_size"` and the amount corresponding to the security strength.
|
||||
|
||||
Random generation is not parametrized by an algorithm. The choice of algorithm is up to the driver.
|
||||
|
||||
#### Random generator initialization
|
||||
|
||||
The `"init_random"` entry point has the following prototype for a driver with the prefix `"acme"`:
|
||||
|
||||
```
|
||||
psa_status_t acme_init_random(acme_random_context_t *context);
|
||||
```
|
||||
|
||||
The core calls this entry point once after allocating a random generation context. Initially, the context object is all-bits-zero.
|
||||
|
||||
If a driver does not have an `"init_random"` entry point, the context object passed to the first call to `"add_entropy"` or `"get_random"` will be all-bits-zero.
|
||||
|
||||
#### Entropy injection
|
||||
|
||||
The `"add_entropy"` entry point has the following prototype for a driver with the prefix `"acme"`:
|
||||
|
||||
```
|
||||
psa_status_t acme_add_entropy(acme_random_context_t *context,
|
||||
const uint8_t *entropy,
|
||||
size_t entropy_size);
|
||||
```
|
||||
|
||||
The semantics of the parameters is as follows:
|
||||
|
||||
* `context`: a random generation context. On the first call to `"add_entropy"`, this object has been initialized by a call to the driver's `"init_random"` entry point if one is present, and to all-bits-zero otherwise.
|
||||
* `entropy`: a buffer containing full-entropy data to seed the random generator. “Full-entropy” means that the data is uniformly distributed and independent of any other observable quantity.
|
||||
* `entropy_size`: the size of the `entropy` buffer in bytes. It is guaranteed to be at least `1`, but it may be smaller than the amount of entropy that the driver needs to deliver random data, in which case the core will call the `"add_entropy"` entry point again to supply more entropy.
|
||||
|
||||
The core calls this function to supply entropy to the driver. The driver must mix this entropy into its internal state. The driver must mix the whole supplied entropy, even if there is more than what the driver requires, to ensure that all entropy sources are mixed into the random generator state. The driver may mix additional entropy of its own.
|
||||
|
||||
The core may call this function at any time. For example, to enforce prediction resistance, the core can call `"add_entropy"` immediately after each call to `"get_random"`. The core must call this function in two circumstances:
|
||||
|
||||
* Before the first call to the `"get_random"` entry point, to supply `"initial_entropy_size"` bytes of entropy.
|
||||
* After a call to the `"get_random"` entry point returns less than the required amount of random data, to supply at least `"reseed_entropy_size"` bytes of entropy.
|
||||
|
||||
When the driver requires entropy, the core can supply it with one or more successive calls to the `"add_entropy"` entry point. If the required entropy size is zero, the core does not need to call `"add_entropy"`.
|
||||
|
||||
#### Combining entropy sources with a random generation driver
|
||||
|
||||
This section provides guidance on combining one or more [entropy sources](#entropy-collection-entry-point) (each having a `"get_entropy"` entry point) with a random generation driver (with an `"add_entropy"` entry point).
|
||||
|
||||
Note that `"get_entropy"` returns data with an estimated amount of entropy that is in general less than the buffer size. The core must apply a mixing algorithm to the output of `"get_entropy"` to obtain full-entropy data.
|
||||
|
||||
For example, the core may use a simple mixing scheme based on a pseudorandom function family $(F_k)$ with an $E$-bit output where $E = 8 \cdot \mathtt{entropy_size}$ and $\mathtt{entropy_size}$ is the desired amount of entropy in bytes (typically the random driver's `"initial_entropy_size"` property for the initial seeding and the `"reseed_entropy_size"` property for subsequent reseeding). The core calls the `"get_entropy"` points of the available entropy drivers, outputting a string $s_i$ and an entropy estimate $e_i$ on the $i$th call. It does so until the total entropy estimate $e_1 + e_2 + \ldots + e_n$ is at least $E$. The core then calculates $F_k(0)$ where $k = s_1 || s_2 || \ldots || s_n$. This value is a string of $\mathtt{entropy_size}$, and since $(F_k)$ is a pseudorandom function family, $F_k(0)$ is uniformly distributed over strings of $\mathtt{entropy_size}$ bytes. Therefore $F_k(0)$ is a suitable value to pass to `"add_entropy"`.
|
||||
|
||||
Note that the mechanism above is only given as an example. Implementations may choose a different mechanism, for example involving multiple pools or intermediate compression functions.
|
||||
|
||||
#### Random generator drivers without entropy injection
|
||||
|
||||
Random generator drivers should have the capability to inject additional entropy through the `"add_entropy"` entry point. This ensures that the random generator depends on all the entropy sources that are available on the platform. A driver where a call to `"add_entropy"` does not affect the state of the random generator is not compliant with this specification.
|
||||
|
||||
However, a driver may omit the `"add_entropy"` entry point. This limits the driver's portability: implementations of the PSA Cryptography specification may reject drivers without an `"add_entropy"` entry point, or only accept such drivers in certain configurations. In particular, the `"add_entropy"` entry point is required if:
|
||||
|
||||
* the integration of PSA Cryptography includes an entropy source that is outside the driver; or
|
||||
* the core saves random data in persistent storage to be preserved across platform resets.
|
||||
|
||||
#### The `"get_random"` entry point
|
||||
|
||||
The `"get_random"` entry point has the following prototype for a driver with the prefix `"acme"`:
|
||||
|
||||
```
|
||||
psa_status_t acme_get_random(acme_random_context_t *context,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length);
|
||||
```
|
||||
|
||||
The semantics of the parameters is as follows:
|
||||
|
||||
* `context`: a random generation context. If the driver's `"initial_entropy_size"` property is nonzero, the core must have called `"add_entropy"` at least once with a total of at least `"initial_entropy_size"` bytes of entropy before it calls `"get_random"`. Alternatively, if the driver's `"initial_entropy_size"` property is zero and the core did not call `"add_entropy"`, or if the driver has no `"add_entropy"` entry point, the core must have called `"init_random"` if present, and otherwise the context is all-bits zero.
|
||||
* `output`: on success (including partial success), the first `*output_length` bytes of this buffer contain cryptographic-quality random data. The output is not used on error.
|
||||
* `output_size`: the size of the `output` buffer in bytes.
|
||||
* `*output_length`: on success (including partial success), the number of bytes of random data that the driver has written to the `output` buffer. This is preferably `output_size`, but the driver is allowed to return less data if it runs out of entropy as described below. The core sets this value to 0 on entry. The value is not used on error.
|
||||
|
||||
The driver may return the following status codes:
|
||||
|
||||
* `PSA_SUCCESS`: the `output` buffer contains `*output_length` bytes of cryptographic-quality random data. Note that this may be less than `output_size`; in this case the core should call the driver's `"add_entropy"` method to supply at least `"reseed_entropy_size"` bytes of entropy before calling `"get_random"` again.
|
||||
* `PSA_ERROR_INSUFFICIENT_ENTROPY`: the core must supply additional entropy by calling the `"add_entropy"` entry point with at least `"reseed_entropy_size"` bytes.
|
||||
* `PSA_ERROR_NOT_SUPPORTED`: the random generator is not available. This is only permitted if the driver specification for random generation has the [fallback property](#fallback) enabled.
|
||||
* Other error codes such as `PSA_ERROR_COMMUNICATION_FAILURE` or `PSA_ERROR_HARDWARE_FAILURE` indicate a transient or permanent error.
|
||||
|
||||
### Fallback
|
||||
|
||||
Sometimes cryptographic accelerators only support certain cryptographic mechanisms partially. The capability description language allows specifying some restrictions, including restrictions on key sizes, but it cannot cover all the possibilities that may arise in practice. Furthermore, it may be desirable to deploy the same binary image on different devices, only some of which have a cryptographic accelerators.
|
||||
@@ -460,7 +606,8 @@ The `"key_context"` property in the [driver description](#driver-description-top
|
||||
* `"public_key_size"` (integer or string, optional): this many bytes are included in every key context for a public key. If omitted, this value defaults to 0.
|
||||
* `"symmetric_factor"` (integer or string, optional): every key context for a symmetric key includes this many times the key size. If omitted, this value defaults to 0.
|
||||
* `"store_public_key"` (boolean, optional): If specified and true, for a key pair, the key context includes space for the public key. If omitted or false, no additional space is added for the public key.
|
||||
* `"size_function"` (string, optional): the name of a function that returns the number of bytes that the driver needs in a key context for a key. This may be a pointer to function. This must be a C identifier; more complex expressions are not permitted. If the core uses this function, it supersedes all the other properties.
|
||||
* `"size_function"` (string, optional): the name of a function that returns the number of bytes that the driver needs in a key context for a key. This may be a pointer to function. This must be a C identifier; more complex expressions are not permitted. If the core uses this function, it supersedes all the other properties except for `"builtin_key_size"` (where applicable, if present).
|
||||
* `"builtin_key_size"` (integer or string, optional): If specified, this overrides all other methods (including the `"size_function"` entry point) to determine the size of the key context for [built-in keys](#built-in-keys). This allows drivers to efficiently represent application keys as wrapped key material, but built-in keys by an internal identifier that takes up less space.
|
||||
|
||||
The integer properties must be C language constants. A typical value for `"base_size"` is `sizeof(acme_key_context_t)` where `acme_key_context_t` is a type defined in a driver header file.
|
||||
|
||||
@@ -516,6 +663,7 @@ Opaque drivers may provide the following key management entry points:
|
||||
* `"generate_key"`: called by `psa_generate_key()`.
|
||||
* `"key_derivation_output_key"`: called by `psa_key_derivation_output_key()`.
|
||||
* `"copy_key"`: called by `psa_copy_key()` when copying a key within the same [location](#lifetimes-and-locations).
|
||||
* `"get_builtin_key"`: called by functions that access a key to retrieve information about a [built-in key](#built-in-keys).
|
||||
|
||||
In addition, secure elements that store the key material internally must provide the following two entry points:
|
||||
|
||||
@@ -646,6 +794,37 @@ The core will not update the persistent state in storage while an entry point is
|
||||
|
||||
In a multithreaded environment, the driver may only call these two functions from the thread that is executing the entry point.
|
||||
|
||||
#### Built-in keys
|
||||
|
||||
Opaque drivers may declare built-in keys. Built-in keys can be accessed, but not created, through the PSA Cryptography API.
|
||||
|
||||
A built-in key is identified by its location and its **slot number**. Drivers that support built-in keys must provide a `"get_builtin_key"` entry point to retrieve the key data and metadata. The core calls this entry point when it needs to access the key, typically because the application requested an operation on the key. The core may keep information about the key in cache, and successive calls to access the same slot number should return the same data. This entry point has the following prototype:
|
||||
|
||||
```
|
||||
psa_status_t acme_get_builtin_key(psa_drv_slot_number_t slot_number,
|
||||
psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
size_t *key_buffer_length);
|
||||
```
|
||||
|
||||
If this function returns `PSA_SUCCESS` or `PSA_ERROR_BUFFER_TOO_SMALL`, it must fill `attributes` with the attributes of the key (except for the key identifier). On success, this function must also fill `key_buffer` with the key context.
|
||||
|
||||
On entry, `psa_get_key_lifetime(attributes)` is the location at which the driver was declared and a persistence level with which the platform is attempting to register the key. The driver entry point may choose to change the lifetime (`psa_set_key_lifetime(attributes, lifetime)`) of the reported key attributes to one with the same location but a different persistence level, in case the driver has more specific knowledge about the actual persistence level of the key which is being retrieved. For example, if a driver knows it cannot delete a key, it may override the persistence level in the lifetime to `PSA_KEY_PERSISTENCE_READ_ONLY`. The standard attributes other than the key identifier and lifetime have the value conveyed by `PSA_KEY_ATTRIBUTES_INIT`.
|
||||
|
||||
The output parameter `key_buffer` points to a writable buffer of `key_buffer_size` bytes. If the driver has a [`"builtin_key_size"` property](#key-format-for-opaque-drivers) property, `key_buffer_size` has this value, otherwise `key_buffer_size` has the value determined from the key type and size.
|
||||
|
||||
Typically, for a built-in key, the key context is a reference to key material that is kept inside the secure element, similar to the format returned by [`"allocate_key"`](#key-management-in-a-secure-element-with-storage). A driver may have built-in keys even if it doesn't have an `"allocate_key"` entry point.
|
||||
|
||||
This entry point may return the following status values:
|
||||
|
||||
* `PSA_SUCCESS`: the requested key exists, and the output parameters `attributes` and `key_buffer` contain the key metadata and key context respectively, and `*key_buffer_length` contains the length of the data written to `key_buffer`.
|
||||
* `PSA_ERROR_BUFFER_TOO_SMALL`: `key_buffer_size` is insufficient. In this case, the driver must pass the key's attributes in `*attributes`. In particular, `get_builtin_key(slot_number, &attributes, NULL, 0)` is a way for the core to obtain the key's attributes.
|
||||
* `PSA_ERROR_DOES_NOT_EXIST`: the requested key does not exist.
|
||||
* Other error codes such as `PSA_ERROR_COMMUNICATION_FAILURE` or `PSA_ERROR_HARDWARE_FAILURE` indicate a transient or permanent error.
|
||||
|
||||
The core will pass authorized requests to destroy a built-in key to the [`"destroy_key"`](#key-management-in-a-secure-element-with-storage) entry point if there is one. If built-in keys must not be destroyed, it is up to the driver to reject such requests.
|
||||
|
||||
## How to use drivers from an application
|
||||
|
||||
### Using transparent drivers
|
||||
@@ -661,7 +840,7 @@ For example, the following snippet creates an AES-GCM key which is only accessib
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_DEFAULT, PSA_KEY_LOCATION_acme));
|
||||
psa_set_key_identifer(&attributes, 42);
|
||||
psa_set_key_identifier(&attributes, 42);
|
||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_size(&attributes, 128);
|
||||
psa_set_key_algorithm(&attributes, PSA_ALG_GCM);
|
||||
@@ -704,6 +883,19 @@ psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION
|
||||
|
||||
## Open questions
|
||||
|
||||
### Value representation
|
||||
|
||||
#### Integers
|
||||
|
||||
It would be better if there was a uniform requirement on integer values. Do they have to be JSON integers? C preprocessor integers (which could be e.g. a macro defined in some header file)? C compile-time constants (allowing `sizeof`)?
|
||||
|
||||
This choice is partly driven by the use of the values, so they might not be uniform. Note that if the value can be zero and it's plausible that the core would want to statically allocate an array of the given size, the core needs to know whether the value is 0 so that it could use code like
|
||||
```
|
||||
#if ACME_FOO_SIZE != 0
|
||||
uint8_t foo[ACME_FOO_SIZE];
|
||||
#endif
|
||||
```
|
||||
|
||||
### Driver declarations
|
||||
|
||||
#### Declaring driver entry points
|
||||
@@ -779,6 +971,26 @@ An example use case for updating the persistent state at arbitrary times is to r
|
||||
|
||||
`psa_crypto_driver_get_persistent_state` does not identify the calling driver, so the driver needs to remember which driver it's calling. This may require a thread-local variable in a multithreaded core. Is this ok?
|
||||
|
||||
### Randomness
|
||||
|
||||
#### Input to `"add_entropy"`
|
||||
|
||||
Should the input to the [`"add_entropy"` entry point](#entropy-injection) be a full-entropy buffer (with data from all entropy sources already mixed), raw entropy direct from the entropy sources, or give the core a choice?
|
||||
|
||||
* Raw data: drivers must implement entropy mixing. `"add_entropy"` needs an extra parameter to indicate the amount of entropy in the data. The core must not do any conditioning.
|
||||
* Choice: drivers must implement entropy mixing. `"add_entropy"` needs an extra parameter to indicate the amount of entropy in the data. The core may do conditioning if it wants, but doesn't have to.
|
||||
* Full entropy: drivers don't need to do entropy mixing.
|
||||
|
||||
#### Flags for `"get_entropy"`
|
||||
|
||||
Are the [entropy collection flags](#entropy-collection-flags) well-chosen?
|
||||
|
||||
#### Random generator instantiations
|
||||
|
||||
May the core instantiate a random generation context more than once? In other words, can there be multiple objects of type `acme_random_context_t`?
|
||||
|
||||
Functionally, one RNG is as good as any. If the core wants some parts of the system to use a deterministic generator for reproducibility, it can't use this interface anyway, since the RNG is not necessarily deterministic. However, for performance on multiprocessor systems, a multithreaded core could prefer to use one RNG instance per thread.
|
||||
|
||||
<!--
|
||||
Local Variables:
|
||||
time-stamp-line-limit: 40
|
||||
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
This document describes the compile-time configuration option
|
||||
`MBEDTLS_USE_PSA_CRYPTO` from a user's perspective, more specifically its
|
||||
current effects as well as the parts that aren't covered yet.
|
||||
|
||||
Current effects
|
||||
===============
|
||||
|
||||
General limitations
|
||||
-------------------
|
||||
|
||||
Compile-time: enabling `MBEDTLS_USE_PSA_CRYPTO` requires
|
||||
`MBEDTLS_ECP_RESTARTABLE` and
|
||||
`MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER` to be disabled.
|
||||
|
||||
Effect: `MBEDTLS_USE_PSA_CRYPTO` currently has no effect on TLS 1.3 (which is
|
||||
itself experimental and only partially supported so far): TLS 1.3 always uses
|
||||
the legacy APIs even when this option is set.
|
||||
|
||||
Stability: any API that's only available when `MBEDTLS_USE_PSA_CRYPTO` is
|
||||
defined is considered experimental and may change in incompatible ways at any
|
||||
time. Said otherwise, these APIs are explicitly excluded from the usual API
|
||||
stability promises.
|
||||
|
||||
New APIs / API extensions
|
||||
-------------------------
|
||||
|
||||
Some of these APIs are meant for the application to use in place of
|
||||
pre-existing APIs, in order to get access to the benefits; in the sub-sections
|
||||
below these are indicated by "Use in (X.509 and) TLS: opt-in", meaning that
|
||||
this requires changes to the application code for the (X.509 and) TLS layers
|
||||
to pick up the improvements.
|
||||
|
||||
Some of these APIs are mostly meant for internal use by the TLS (and X.509)
|
||||
layers; they are indicated below by "Use in (X.509 and) TLS: automatic",
|
||||
meaning that no changes to the application code are required for the TLS (and
|
||||
X.509) layers to pick up the improvements.
|
||||
|
||||
### PSA-held (opaque) keys in the PK layer
|
||||
|
||||
There is a new API function `mbedtls_pk_setup_opaque()` that can be used to
|
||||
wrap a PSA keypair into a PK context. The key can be used for private-key
|
||||
operations and its public part can be exported.
|
||||
|
||||
Benefits: isolation of long-term secrets, use of PSA Crypto drivers.
|
||||
|
||||
Limitations: only for private keys, only ECC. (That is, only ECDSA signature
|
||||
generation. Note: currently this will use randomized ECDSA while Mbed TLS uses
|
||||
deterministic ECDSA by default.) The following operations are not supported
|
||||
with a context set this way, while they would be available with a normal
|
||||
`ECKEY` context: `mbedtls_pk_verify()`, `mbedtls_pk_check_pair()`,
|
||||
`mbedtls_pk_debug()`.
|
||||
|
||||
Use in X.509 and TLS: opt-in. The application needs to construct the PK context
|
||||
using the new API in order to get the benefits; it can then pass the
|
||||
resulting context to the following existing APIs:
|
||||
|
||||
- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
|
||||
key together with a certificate for ECDSA-based key exchanges (note: while
|
||||
this is supported on both sides, it's currently only tested client-side);
|
||||
- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
|
||||
request).
|
||||
|
||||
In the TLS and X.509 API, there are two other functions which accept a key or
|
||||
keypair as a PK context: `mbedtls_x509write_crt_set_subject_key()` and
|
||||
`mbedtls_x509write_crt_set_issuer_key()`. Use of opaque contexts here probably
|
||||
works but is so far untested.
|
||||
|
||||
### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
|
||||
|
||||
There are two new API functions `mbedtls_ssl_conf_psk_opaque()` and
|
||||
`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
|
||||
register a PSA key for use with a PSK key exchange.
|
||||
|
||||
Benefits: isolation of long-term secrets.
|
||||
|
||||
Limitations: the key can only be used with "pure"
|
||||
PSK key exchanges (ciphersuites starting with `TLS_PSK_WITH_`), to the
|
||||
exclusion of RSA-PSK, DHE-PSK and ECDHE-PSK key exchanges. It is the responsibility of
|
||||
the user to make sure that when provisioning an opaque pre-shared key, the
|
||||
only PSK ciphersuites that can be negotiated are "pure" PSK; other XXX-PSK key
|
||||
exchanges will result in a handshake failure with the handshake function
|
||||
returning `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`.
|
||||
|
||||
Use in TLS: opt-in. The application needs to register the key using the new
|
||||
APIs to get the benefits.
|
||||
|
||||
### PSA-based operations in the Cipher layer
|
||||
|
||||
There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
|
||||
that will call PSA to store the key and perform the operations.
|
||||
|
||||
Benefits: use of PSA Crypto drivers; partial isolation of short-term secrets
|
||||
(still generated outside of PSA, but then held by PSA).
|
||||
|
||||
Limitations: the key is still passed in the clear by the application. The
|
||||
multi-part APIs are not supported, only the one-shot APIs. The only modes
|
||||
supported are ECB, CBC without padding, GCM and CCM (this excludes stream
|
||||
ciphers and ChachaPoly); the only cipher supported is AES (this excludes Aria,
|
||||
Camellia, and ChachaPoly). (Note: ECB is currently not tested.) (Note: it is
|
||||
possible to perform multiple one-shot operations with the same context;
|
||||
however this is not unit-tested, only tested via usage in TLS.)
|
||||
|
||||
Use in TLS: automatic. Used when the cipher and mode is supported (with
|
||||
gracious fallback to the legacy API otherwise) in all places where a cipher is
|
||||
used. There are two such places: in `ssl_tls.c` for record protection, and in
|
||||
`ssl_ticket.c` for protecting tickets we issue.
|
||||
|
||||
Internal changes
|
||||
----------------
|
||||
|
||||
All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
|
||||
is enabled, no change required on the application side.
|
||||
|
||||
### TLS: cipher operations based on PSA
|
||||
|
||||
See "PSA-based operations in the Cipher layer" above.
|
||||
|
||||
### PK layer: ECDSA verification based on PSA
|
||||
|
||||
Scope: `mbedtls_pk_verify()` will call to PSA for ECDSA signature
|
||||
verification.
|
||||
|
||||
Benefits: use of PSA Crypto drivers.
|
||||
|
||||
Use in TLS and X.509: in all places where an ECDSA signature is verified.
|
||||
|
||||
### TLS: ECDHE computation based on PSA
|
||||
|
||||
Scope: Client-side, for ECDHE-RSA and ECDHE-ECDSA key exchanges, the
|
||||
computation of the ECDHE key exchange is done by PSA.
|
||||
|
||||
Limitations: client-side only, ECDHE-PSK not covered
|
||||
|
||||
Benefits: use of PSA Crypto drivers.
|
||||
|
||||
### TLS: handshake hashes and PRF computed with PSA
|
||||
|
||||
Scope: with TLS 1.2, the following are computed with PSA:
|
||||
- the running handshake hashes;
|
||||
- the hash of the ServerKeyExchange part that is signed;
|
||||
- the `verify_data` part of the Finished message;
|
||||
- the TLS PRF.
|
||||
|
||||
Benefits: use of PSA Crypto drivers.
|
||||
|
||||
### X.509: some hashes computed with PSA
|
||||
|
||||
Scope: the following hashes are computed with PSA:
|
||||
- when verifying a certificate chain, hash of the child for verifying the
|
||||
parent's signature;
|
||||
- when writing a CSR, hash of the request for self-signing the request.
|
||||
|
||||
Benefits: use of PSA Crypto drivers.
|
||||
|
||||
Parts that are not covered yet
|
||||
==============================
|
||||
|
||||
This is only a high-level overview, grouped by theme
|
||||
|
||||
TLS: 1.3 experimental support
|
||||
-----------------------------
|
||||
|
||||
No part of the experimental support for TLS 1.3 is covered at the moment.
|
||||
|
||||
TLS: key exchanges / asymmetric crypto
|
||||
--------------------------------------
|
||||
|
||||
The following key exchanges are not covered at all:
|
||||
|
||||
- RSA
|
||||
- DHE-RSA
|
||||
- DHE-PSK
|
||||
- RSA-PSK
|
||||
- ECDHE-PSK
|
||||
- ECDH-RSA
|
||||
- ECDH-ECDSA
|
||||
- ECJPAKE
|
||||
|
||||
The following key exchanges are only partially covered:
|
||||
|
||||
- ECDHE-RSA: RSA operations are not covered and, server-side, the ECDHE
|
||||
operation isn't either
|
||||
- ECDHE-ECDSA: server-side, the ECDHE operation isn't covered. (ECDSA
|
||||
signature generation is only covered if using `mbedtls_pk_setup_opaque()`.)
|
||||
|
||||
PSK if covered when the application uses `mbedtls_ssl_conf_psk_opaque()` or
|
||||
`mbedtls_ssl_set_hs_psk_opaque()`.
|
||||
|
||||
TLS: symmetric crypto
|
||||
---------------------
|
||||
|
||||
- some ciphers not supported via PSA yet: ARIA, Camellia, ChachaPoly (silent
|
||||
fallback to the legacy APIs)
|
||||
- the HMAC part of the CBC and NULL ciphersuites
|
||||
- the HMAC computation in `ssl_cookie.c`
|
||||
|
||||
X.509
|
||||
-----
|
||||
|
||||
- most hash operations are still done via the legacy API, except the few that
|
||||
are documented above as using PSA
|
||||
- RSA PKCS#1 v1.5 signature generation (from PSA-held keys)
|
||||
- RSA PKCS#1 v1.5 signature verification
|
||||
- RSA-PSS signature verification
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage mbed TLS v2.25.0 source code documentation
|
||||
* @mainpage mbed TLS v2.28.0 source code documentation
|
||||
*
|
||||
* This documentation describes the internal structure of mbed TLS. It was
|
||||
* automatically generated from specially formatted comment blocks in
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ DOXYFILE_ENCODING = UTF-8
|
||||
# identify the project. Note that if you do not use Doxywizard you need
|
||||
# to put quotes around the project name if it contains spaces.
|
||||
|
||||
PROJECT_NAME = "mbed TLS v2.25.0"
|
||||
PROJECT_NAME = "mbed TLS v2.28.0"
|
||||
|
||||
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
|
||||
# This could be handy for archiving the generated documentation or
|
||||
|
||||
+25
-9
@@ -45,6 +45,7 @@
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -54,17 +55,22 @@
|
||||
#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
|
||||
|
||||
/* Error codes in range 0x0020-0x0022 */
|
||||
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
|
||||
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
|
||||
/** Invalid key length. */
|
||||
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
|
||||
/** Invalid data input length. */
|
||||
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
|
||||
|
||||
/* Error codes in range 0x0021-0x0025 */
|
||||
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
|
||||
/** Invalid input data. */
|
||||
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
|
||||
|
||||
/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
|
||||
/** Feature not available. For example, an unsupported AES key size. */
|
||||
#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
|
||||
|
||||
/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
|
||||
/** AES hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
@@ -169,6 +175,7 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
|
||||
@@ -187,6 +194,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
|
||||
@@ -207,6 +215,7 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
@@ -227,6 +236,7 @@ int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
@@ -255,6 +265,7 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
||||
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
@@ -302,6 +313,7 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
|
||||
* on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -346,6 +358,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
* smaller than an AES block in size (16 Bytes) or if \p
|
||||
* length is larger than 2^20 blocks (16 MiB).
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -394,6 +407,7 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -438,6 +452,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -492,6 +507,7 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
@@ -506,10 +522,6 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
||||
* \brief This function performs an AES-CTR encryption or decryption
|
||||
* operation.
|
||||
*
|
||||
* This function performs the operation defined in the \p mode
|
||||
* parameter (encrypt/decrypt), on the input data buffer
|
||||
* defined in the \p input parameter.
|
||||
*
|
||||
* Due to the nature of CTR, you must use the same key schedule
|
||||
* for both encryption and decryption operations. Therefore, you
|
||||
* must use the context initialized with mbedtls_aes_setkey_enc()
|
||||
@@ -578,6 +590,7 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
@@ -598,6 +611,7 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
@@ -613,6 +627,7 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
@@ -662,6 +677,7 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
int mbedtls_aes_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@
|
||||
#include <stddef.h>
|
||||
|
||||
/* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
|
||||
/** ARC4 hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+12
-8
@@ -50,25 +50,29 @@
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x005C )
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C /**< Bad input data. */
|
||||
/** Bad input data. */
|
||||
#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C
|
||||
|
||||
#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /**< Invalid data input length. */
|
||||
/** Invalid data input length. */
|
||||
#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E
|
||||
|
||||
/* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */
|
||||
/** Feature not available. For example, an unsupported ARIA key size. */
|
||||
#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A
|
||||
|
||||
/* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058 /**< ARIA hardware accelerator failed. */
|
||||
|
||||
#if !defined(MBEDTLS_ARIA_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
/** ARIA hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_ARIA_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief The ARIA context-type definition.
|
||||
*/
|
||||
|
||||
+14
-7
@@ -46,13 +46,20 @@
|
||||
* ASN1 is a standard to specify data structures.
|
||||
* \{
|
||||
*/
|
||||
#define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */
|
||||
#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */
|
||||
#define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */
|
||||
#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */
|
||||
#define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. */
|
||||
#define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */
|
||||
#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */
|
||||
/** Out of data when parsing an ASN1 data structure. */
|
||||
#define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060
|
||||
/** ASN1 tag was of an unexpected value. */
|
||||
#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062
|
||||
/** Error when trying to determine the length or invalid length. */
|
||||
#define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064
|
||||
/** Actual length differs from expected length. */
|
||||
#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066
|
||||
/** Data is invalid. */
|
||||
#define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068
|
||||
/** Memory allocation failed */
|
||||
#define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A
|
||||
/** Buffer too small when writing ASN.1 data structure. */
|
||||
#define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C
|
||||
|
||||
/* \} name */
|
||||
|
||||
|
||||
+4
-2
@@ -30,8 +30,10 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
|
||||
#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
|
||||
/** Output buffer too small. */
|
||||
#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A
|
||||
/** Invalid character in input. */
|
||||
#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+58
-12
@@ -35,14 +35,22 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */
|
||||
#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */
|
||||
#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */
|
||||
#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */
|
||||
#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */
|
||||
#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */
|
||||
#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */
|
||||
/** An error occurred while reading from or writing to a file. */
|
||||
#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004
|
||||
/** There is an invalid character in the digit string. */
|
||||
#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006
|
||||
/** The buffer is too small to write to. */
|
||||
#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008
|
||||
/** The input arguments are negative or result in illegal output. */
|
||||
#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A
|
||||
/** The input argument for division is zero, which is not allowed. */
|
||||
#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C
|
||||
/** The input arguments are not acceptable. */
|
||||
#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E
|
||||
/** Memory allocation failed. */
|
||||
#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010
|
||||
|
||||
#define MBEDTLS_MPI_CHK(f) \
|
||||
do \
|
||||
@@ -829,14 +837,14 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
|
||||
* \param E The exponent MPI. This must point to an initialized MPI.
|
||||
* \param N The base for the modular reduction. This must point to an
|
||||
* initialized MPI.
|
||||
* \param _RR A helper MPI depending solely on \p N which can be used to
|
||||
* \param prec_RR A helper MPI depending solely on \p N which can be used to
|
||||
* speed-up multiple modular exponentiations for the same value
|
||||
* of \p N. This may be \c NULL. If it is not \c NULL, it must
|
||||
* point to an initialized MPI. If it hasn't been used after
|
||||
* the call to mbedtls_mpi_init(), this function will compute
|
||||
* the helper value and store it in \p _RR for reuse on
|
||||
* the helper value and store it in \p prec_RR for reuse on
|
||||
* subsequent calls to this function. Otherwise, the function
|
||||
* will assume that \p _RR holds the helper value set by a
|
||||
* will assume that \p prec_RR holds the helper value set by a
|
||||
* previous call to mbedtls_mpi_exp_mod(), and reuse it.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
@@ -848,7 +856,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
|
||||
*/
|
||||
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *E, const mbedtls_mpi *N,
|
||||
mbedtls_mpi *_RR );
|
||||
mbedtls_mpi *prec_RR );
|
||||
|
||||
/**
|
||||
* \brief Fill an MPI with a number of random bytes.
|
||||
@@ -871,6 +879,44 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/** Generate a random number uniformly in a range.
|
||||
*
|
||||
* This function generates a random number between \p min inclusive and
|
||||
* \p N exclusive.
|
||||
*
|
||||
* The procedure complies with RFC 6979 §3.3 (deterministic ECDSA)
|
||||
* when the RNG is a suitably parametrized instance of HMAC_DRBG
|
||||
* and \p min is \c 1.
|
||||
*
|
||||
* \note There are `N - min` possible outputs. The lower bound
|
||||
* \p min can be reached, but the upper bound \p N cannot.
|
||||
*
|
||||
* \param X The destination MPI. This must point to an initialized MPI.
|
||||
* \param min The minimum value to return.
|
||||
* It must be nonnegative.
|
||||
* \param N The upper bound of the range, exclusive.
|
||||
* In other words, this is one plus the maximum value to return.
|
||||
* \p N must be strictly larger than \p min.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG parameter to be passed to \p f_rng.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p min or \p N is invalid
|
||||
* or if they are incompatible.
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was
|
||||
* unable to find a suitable value within a limited number
|
||||
* of attempts. This has a negligible probability if \p N
|
||||
* is significantly larger than \p min, which is the case
|
||||
* for all usual cryptographic applications.
|
||||
* \return Another negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_random( mbedtls_mpi *X,
|
||||
mbedtls_mpi_sint min,
|
||||
const mbedtls_mpi *N,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief Compute the greatest common divisor: G = gcd(A, B)
|
||||
*
|
||||
|
||||
+6
-3
@@ -43,13 +43,16 @@
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 /**< Bad input data. */
|
||||
/** Bad input data. */
|
||||
#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
|
||||
|
||||
#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
|
||||
/** Invalid data input length. */
|
||||
#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
|
||||
|
||||
/* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */
|
||||
/** Blowfish hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+49
-9
@@ -44,6 +44,46 @@
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
|
||||
/*
|
||||
* Conversion macros for embedded constants:
|
||||
* build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2
|
||||
*/
|
||||
#if defined(MBEDTLS_HAVE_INT32)
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \
|
||||
( (mbedtls_mpi_uint) (a) << 0 ) | \
|
||||
( (mbedtls_mpi_uint) (b) << 8 ) | \
|
||||
( (mbedtls_mpi_uint) (c) << 16 ) | \
|
||||
( (mbedtls_mpi_uint) (d) << 24 )
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \
|
||||
MBEDTLS_BYTES_TO_T_UINT_4( a, b, 0, 0 )
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
|
||||
MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ), \
|
||||
MBEDTLS_BYTES_TO_T_UINT_4( e, f, g, h )
|
||||
|
||||
#else /* 64-bits */
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \
|
||||
( (mbedtls_mpi_uint) (a) << 0 ) | \
|
||||
( (mbedtls_mpi_uint) (b) << 8 ) | \
|
||||
( (mbedtls_mpi_uint) (c) << 16 ) | \
|
||||
( (mbedtls_mpi_uint) (d) << 24 ) | \
|
||||
( (mbedtls_mpi_uint) (e) << 32 ) | \
|
||||
( (mbedtls_mpi_uint) (f) << 40 ) | \
|
||||
( (mbedtls_mpi_uint) (g) << 48 ) | \
|
||||
( (mbedtls_mpi_uint) (h) << 56 )
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \
|
||||
MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 )
|
||||
|
||||
#define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \
|
||||
MBEDTLS_BYTES_TO_T_UINT_8( a, b, 0, 0, 0, 0, 0, 0 )
|
||||
|
||||
#endif /* bits in mbedtls_mpi_uint */
|
||||
|
||||
#if defined(MBEDTLS_HAVE_ASM)
|
||||
|
||||
#ifndef asm
|
||||
@@ -189,9 +229,9 @@
|
||||
"addq $8, %%rdi\n"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
: "+c" (c), "+D" (d), "+S" (s) \
|
||||
: "b" (b) \
|
||||
: "rax", "rdx", "r8" \
|
||||
: "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
|
||||
: "b" (b), "m" (*(const uint64_t (*)[16]) s) \
|
||||
: "rax", "rdx", "r8" \
|
||||
);
|
||||
|
||||
#endif /* AMD64 */
|
||||
@@ -204,18 +244,18 @@
|
||||
#define MULADDC_CORE \
|
||||
"ldr x4, [%2], #8 \n\t" \
|
||||
"ldr x5, [%1] \n\t" \
|
||||
"mul x6, x4, %3 \n\t" \
|
||||
"umulh x7, x4, %3 \n\t" \
|
||||
"mul x6, x4, %4 \n\t" \
|
||||
"umulh x7, x4, %4 \n\t" \
|
||||
"adds x5, x5, x6 \n\t" \
|
||||
"adc x7, x7, xzr \n\t" \
|
||||
"adds x5, x5, %0 \n\t" \
|
||||
"adc %0, x7, xzr \n\t" \
|
||||
"str x5, [%1], #8 \n\t"
|
||||
|
||||
#define MULADDC_STOP \
|
||||
: "+r" (c), "+r" (d), "+r" (s) \
|
||||
: "r" (b) \
|
||||
: "x4", "x5", "x6", "x7", "cc" \
|
||||
#define MULADDC_STOP \
|
||||
: "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \
|
||||
: "r" (b), "m" (*(const uint64_t (*)[16]) s) \
|
||||
: "x4", "x5", "x6", "x7", "cc" \
|
||||
);
|
||||
|
||||
#endif /* Aarch64 */
|
||||
|
||||
+6
-3
@@ -39,13 +39,16 @@
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 )
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 /**< Bad input data. */
|
||||
/** Bad input data. */
|
||||
#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024
|
||||
|
||||
#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
|
||||
/** Invalid data input length. */
|
||||
#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026
|
||||
|
||||
/* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */
|
||||
/** Camellia hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+6
-3
@@ -55,11 +55,14 @@
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
|
||||
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */
|
||||
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
|
||||
/** Bad input parameters to the function. */
|
||||
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
|
||||
/** Authenticated decryption failed. */
|
||||
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
|
||||
|
||||
/* MBEDTLS_ERR_CCM_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */
|
||||
/** CCM hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+6
-3
@@ -41,15 +41,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 /**< Invalid input parameter(s). */
|
||||
/** Invalid input parameter(s). */
|
||||
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051
|
||||
|
||||
/* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be
|
||||
* used. */
|
||||
#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 /**< Feature not available. For example, s part of the API is not implemented. */
|
||||
/** Feature not available. For example, s part of the API is not implemented. */
|
||||
#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053
|
||||
|
||||
/* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 /**< Chacha20 hardware accelerator failed. */
|
||||
/** Chacha20 hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+4
-2
@@ -41,8 +41,10 @@
|
||||
/* for shared error codes */
|
||||
#include "mbedtls/poly1305.h"
|
||||
|
||||
#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054 /**< The requested operation is not permitted in the current state. */
|
||||
#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056 /**< Authenticated decryption failed: data was not authentic. */
|
||||
/** The requested operation is not permitted in the current state. */
|
||||
#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054
|
||||
/** Authenticated decryption failed: data was not authentic. */
|
||||
#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+20
-11
@@ -55,9 +55,8 @@
|
||||
#endif
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#if defined(TARGET_LIKE_MBED) && \
|
||||
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
|
||||
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
|
||||
#if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C)
|
||||
#error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
||||
@@ -252,6 +251,10 @@
|
||||
#error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
||||
#error "MBEDTLS_ECP_NO_FALLBACK defined, but no alternative implementation enabled"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
|
||||
#error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
|
||||
#endif
|
||||
@@ -506,10 +509,6 @@
|
||||
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
|
||||
#endif
|
||||
@@ -572,10 +571,11 @@
|
||||
#error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && \
|
||||
!( defined(MBEDTLS_CTR_DRBG_C) && \
|
||||
defined(MBEDTLS_ENTROPY_C) )
|
||||
#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites"
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && \
|
||||
!( ( ( defined(MBEDTLS_CTR_DRBG_C) || defined(MBEDTLS_HMAC_DRBG_C) ) && \
|
||||
defined(MBEDTLS_ENTROPY_C) ) || \
|
||||
defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) )
|
||||
#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites (missing RNG)"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SPM) && !defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
@@ -604,6 +604,11 @@
|
||||
#error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with actual entropy sources"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
#error "MBEDTLS_PSA_INJECT_ENTROPY is not compatible with MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_ITS_FILE_C) && \
|
||||
!defined(MBEDTLS_FS_IO)
|
||||
#error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites"
|
||||
@@ -880,6 +885,10 @@
|
||||
#error "MBEDTLS_SSL_DTLS_SRTP defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) && ( !defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) )
|
||||
#error "MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Avoid warning from -pedantic. This is a convenient place for this
|
||||
* workaround since this is included by every single file before the
|
||||
|
||||
+16
-8
@@ -54,16 +54,24 @@
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters. */
|
||||
#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */
|
||||
#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */
|
||||
#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */
|
||||
#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */
|
||||
/** The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080
|
||||
/** Bad input parameters. */
|
||||
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100
|
||||
/** Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180
|
||||
/** Input data contains invalid padding and is rejected. */
|
||||
#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200
|
||||
/** Decryption of block requires a full block. */
|
||||
#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280
|
||||
/** Authentication failed (for AEAD modes). */
|
||||
#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300
|
||||
/** The context is invalid. For example, because it was freed. */
|
||||
#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380
|
||||
|
||||
/* MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */
|
||||
/** Cipher hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400
|
||||
|
||||
#define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */
|
||||
#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */
|
||||
|
||||
+52
-16
@@ -39,7 +39,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A /**< CMAC hardware accelerator failed. */
|
||||
/** CMAC hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A
|
||||
|
||||
#define MBEDTLS_AES_BLOCK_SIZE 16
|
||||
#define MBEDTLS_DES3_BLOCK_SIZE 8
|
||||
@@ -73,9 +74,23 @@ struct mbedtls_cmac_context_t
|
||||
#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.
|
||||
* 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
|
||||
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
||||
* may not be supported by that implementation, and thus
|
||||
* return an error. Alternate implementations must support
|
||||
* AES-128 and AES-256, and may support AES-192 and 3DES.
|
||||
*
|
||||
* \param ctx The cipher context used for the CMAC operation, initialized
|
||||
* as one of the following types: MBEDTLS_CIPHER_AES_128_ECB,
|
||||
@@ -95,9 +110,15 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
* \brief This function feeds an input buffer into an ongoing CMAC
|
||||
* computation.
|
||||
*
|
||||
* It is called between mbedtls_cipher_cmac_starts() or
|
||||
* mbedtls_cipher_cmac_reset(), and mbedtls_cipher_cmac_finish().
|
||||
* Can be called repeatedly.
|
||||
* The CMAC computation must have previously been started
|
||||
* by calling mbedtls_cipher_cmac_starts() or
|
||||
* 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 input The buffer holding the input data.
|
||||
@@ -111,12 +132,13 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input, size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief This function finishes the CMAC operation, and writes
|
||||
* the result to the output buffer.
|
||||
* \brief This function finishes an ongoing CMAC operation, and
|
||||
* writes the result to the output buffer.
|
||||
*
|
||||
* It is called after mbedtls_cipher_cmac_update().
|
||||
* It can be followed by mbedtls_cipher_cmac_reset() and
|
||||
* mbedtls_cipher_cmac_update(), or mbedtls_cipher_free().
|
||||
* It should be followed either by
|
||||
* mbedtls_cipher_cmac_reset(), which starts another CMAC
|
||||
* 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 output The output buffer for the CMAC checksum result.
|
||||
@@ -129,12 +151,14 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief This function prepares the authentication of another
|
||||
* message with the same key as the previous CMAC
|
||||
* operation.
|
||||
* \brief This function starts a new CMAC operation with the same
|
||||
* key as the previous one.
|
||||
*
|
||||
* It is called after mbedtls_cipher_cmac_finish()
|
||||
* and before mbedtls_cipher_cmac_update().
|
||||
* It should be called after finishing the previous CMAC
|
||||
* 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.
|
||||
*
|
||||
@@ -154,6 +178,11 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
||||
* The CMAC result is calculated as
|
||||
* output = generic CMAC(cmac key, input buffer).
|
||||
*
|
||||
* \note When the CMAC implementation is supplied by an alternate
|
||||
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
||||
* may not be supported by that implementation, and thus
|
||||
* return an error. Alternate implementations must support
|
||||
* AES-128 and AES-256, and may support AES-192 and 3DES.
|
||||
*
|
||||
* \param cipher_info The cipher information.
|
||||
* \param key The CMAC key.
|
||||
@@ -198,6 +227,13 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
||||
/**
|
||||
* \brief The CMAC checkup routine.
|
||||
*
|
||||
* \note In case the CMAC routines are provided by an alternative
|
||||
* implementation (i.e. #MBEDTLS_CMAC_ALT is defined), the
|
||||
* checkup routine will succeed even if the implementation does
|
||||
* not support the less widely used AES-192 or 3DES primitives.
|
||||
* The self-test requires at least AES-128 and AES-256 to be
|
||||
* supported by the underlying implementation.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
|
||||
+196
-43
@@ -427,7 +427,7 @@
|
||||
* be overridden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
|
||||
* must stay untouched.
|
||||
*
|
||||
* \note If you use the AES_xxx_ALT macros, then is is recommended to also set
|
||||
* \note If you use the AES_xxx_ALT macros, then it is recommended to also set
|
||||
* MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
|
||||
* tables.
|
||||
*
|
||||
@@ -484,6 +484,11 @@
|
||||
* is still present and it is used for group structures not supported by the
|
||||
* alternative.
|
||||
*
|
||||
* The original implementation can in addition be removed by setting the
|
||||
* MBEDTLS_ECP_NO_FALLBACK option, in which case any function for which the
|
||||
* corresponding MBEDTLS_ECP__FUNCTION_NAME__ALT macro is defined will not be
|
||||
* able to fallback to curves not supported by the alternative implementation.
|
||||
*
|
||||
* Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
|
||||
* and implementing the following functions:
|
||||
* unsigned char mbedtls_internal_ecp_grp_capable(
|
||||
@@ -497,21 +502,28 @@
|
||||
* called before and after each point operation and provide an opportunity to
|
||||
* implement optimized set up and tear down instructions.
|
||||
*
|
||||
* Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and
|
||||
* MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac
|
||||
* function, but will use your mbedtls_internal_ecp_double_jac if the group is
|
||||
* supported (your mbedtls_internal_ecp_grp_capable function returns 1 when
|
||||
* receives it as an argument). If the group is not supported then the original
|
||||
* implementation is used. The other functions and the definition of
|
||||
* mbedtls_ecp_group and mbedtls_ecp_point will not change, so your
|
||||
* implementation of mbedtls_internal_ecp_double_jac and
|
||||
* mbedtls_internal_ecp_grp_capable must be compatible with this definition.
|
||||
* Example: In case you set MBEDTLS_ECP_INTERNAL_ALT and
|
||||
* MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac()
|
||||
* function, but will use your mbedtls_internal_ecp_double_jac() if the group
|
||||
* for the operation is supported by your implementation (i.e. your
|
||||
* mbedtls_internal_ecp_grp_capable() function returns 1 for this group). If the
|
||||
* group is not supported by your implementation, then the original mbed TLS
|
||||
* implementation of ecp_double_jac() is used instead, unless this fallback
|
||||
* behaviour is disabled by setting MBEDTLS_ECP_NO_FALLBACK (in which case
|
||||
* ecp_double_jac() will return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE).
|
||||
*
|
||||
* The function prototypes and the definition of mbedtls_ecp_group and
|
||||
* mbedtls_ecp_point will not change based on MBEDTLS_ECP_INTERNAL_ALT, so your
|
||||
* implementation of mbedtls_internal_ecp__function_name__ must be compatible
|
||||
* with their definitions.
|
||||
*
|
||||
* Uncomment a macro to enable alternate implementation of the corresponding
|
||||
* function.
|
||||
*/
|
||||
/* Required for all the functions in this section */
|
||||
//#define MBEDTLS_ECP_INTERNAL_ALT
|
||||
/* Turn off software fallback for curves not supported in hardware */
|
||||
//#define MBEDTLS_ECP_NO_FALLBACK
|
||||
/* Support for Weierstrass curves with Jacobi representation */
|
||||
//#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
|
||||
//#define MBEDTLS_ECP_ADD_MIXED_ALT
|
||||
@@ -604,6 +616,29 @@
|
||||
*/
|
||||
//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHECK_RETURN_WARNING
|
||||
*
|
||||
* If this macro is defined, emit a compile-time warning if application code
|
||||
* calls a function without checking its return value, but the return value
|
||||
* should generally be checked in portable applications.
|
||||
*
|
||||
* This is only supported on platforms where #MBEDTLS_CHECK_RETURN is
|
||||
* implemented. Otherwise this option has no effect.
|
||||
*
|
||||
* Uncomment to get warnings on using fallible functions without checking
|
||||
* their return value.
|
||||
*
|
||||
* \note This feature is a work in progress.
|
||||
* Warnings will be added to more functions in the future.
|
||||
*
|
||||
* \note A few functions are considered critical, and ignoring the return
|
||||
* value of these functions will trigger a warning even if this
|
||||
* macro is not defined. To completely disable return value check
|
||||
* warnings, define #MBEDTLS_CHECK_RETURN with an empty expansion.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_RETURN_WARNING
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CIPHER_MODE_CBC
|
||||
*
|
||||
@@ -1326,6 +1361,38 @@
|
||||
*/
|
||||
#define MBEDTLS_PKCS1_V21
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
|
||||
*
|
||||
* Enable support for platform built-in keys. If you enable this feature,
|
||||
* you must implement the function mbedtls_psa_platform_get_builtin_key().
|
||||
* See the documentation of that function for more information.
|
||||
*
|
||||
* Built-in keys are typically derived from a hardware unique key or
|
||||
* stored in a secure element.
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C.
|
||||
*
|
||||
* \warning This interface is experimental and may change or be removed
|
||||
* without notice.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_CLIENT
|
||||
*
|
||||
* Enable support for PSA crypto client.
|
||||
*
|
||||
* \note This option allows to include the code necessary for a PSA
|
||||
* crypto client when the PSA crypto implementation is not included in
|
||||
* the library (MBEDTLS_PSA_CRYPTO_C disabled). The code included is the
|
||||
* code to set and get PSA key attributes.
|
||||
* The development of PSA drivers partially relying on the library to
|
||||
* fulfill the hardware gaps is another possible usage of this option.
|
||||
*
|
||||
* \warning This interface is experimental and may change or be removed
|
||||
* without notice.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_CRYPTO_CLIENT
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||
*
|
||||
* Enable support for the experimental PSA crypto driver interface.
|
||||
@@ -1337,6 +1404,44 @@
|
||||
*/
|
||||
//#define MBEDTLS_PSA_CRYPTO_DRIVERS
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
|
||||
*
|
||||
* Make the PSA Crypto module use an external random generator provided
|
||||
* by a driver, instead of Mbed TLS's entropy and DRBG modules.
|
||||
*
|
||||
* \note This random generator must deliver random numbers with cryptographic
|
||||
* quality and high performance. It must supply unpredictable numbers
|
||||
* with a uniform distribution. The implementation of this function
|
||||
* is responsible for ensuring that the random generator is seeded
|
||||
* with sufficient entropy. If you have a hardware TRNG which is slow
|
||||
* or delivers non-uniform output, declare it as an entropy source
|
||||
* with mbedtls_entropy_add_source() instead of enabling this option.
|
||||
*
|
||||
* If you enable this option, you must configure the type
|
||||
* ::mbedtls_psa_external_random_context_t in psa/crypto_platform.h
|
||||
* and define a function called mbedtls_psa_external_get_random()
|
||||
* with the following prototype:
|
||||
* ```
|
||||
* psa_status_t mbedtls_psa_external_get_random(
|
||||
* mbedtls_psa_external_random_context_t *context,
|
||||
* uint8_t *output, size_t output_size, size_t *output_length);
|
||||
* );
|
||||
* ```
|
||||
* The \c context value is initialized to 0 before the first call.
|
||||
* The function must fill the \c output buffer with \p output_size bytes
|
||||
* of random data and set \c *output_length to \p output_size.
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C
|
||||
*
|
||||
* \warning If you enable this option, code that uses the PSA cryptography
|
||||
* interface will not use any of the entropy sources set up for
|
||||
* the entropy module, nor the NV seed that MBEDTLS_ENTROPY_NV_SEED
|
||||
* enables.
|
||||
*
|
||||
* \note This option is experimental and may be removed without notice.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PSA_CRYPTO_SPM
|
||||
*
|
||||
@@ -1815,7 +1920,7 @@
|
||||
/**
|
||||
* \def MBEDTLS_SSL_DTLS_SRTP
|
||||
*
|
||||
* Enable support for negotation of DTLS-SRTP (RFC 5764)
|
||||
* Enable support for negotiation of DTLS-SRTP (RFC 5764)
|
||||
* through the use_srtp extension.
|
||||
*
|
||||
* \note This feature provides the minimum functionality required
|
||||
@@ -1941,7 +2046,10 @@
|
||||
/**
|
||||
* \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
|
||||
*
|
||||
* Enable modifying the maximum I/O buffer size.
|
||||
* When this option is enabled, the SSL buffer will be resized automatically
|
||||
* based on the negotiated maximum fragment length in each direction.
|
||||
*
|
||||
* Requires: MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
*/
|
||||
//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
|
||||
|
||||
@@ -2034,15 +2142,13 @@
|
||||
* will still continue to work as usual, so enabling this option should not
|
||||
* break backwards compatibility.
|
||||
*
|
||||
* \warning The PSA Crypto API is in beta stage. While you're welcome to
|
||||
* experiment using it, incompatible API changes are still possible, and some
|
||||
* parts may not have reached the same quality as the rest of Mbed TLS yet.
|
||||
* \note See docs/use-psa-crypto.md for a complete description of what this
|
||||
* option currently does, and of parts that are not affected by it so far.
|
||||
*
|
||||
* \warning This option enables new Mbed TLS APIs that are dependent on the
|
||||
* PSA Crypto API, so can't come with the same stability guarantees as the
|
||||
* rest of the Mbed TLS APIs. You're welcome to experiment with them, but for
|
||||
* now, access to these APIs is opt-in (via enabling the present option), in
|
||||
* order to clearly differentiate them from the stable Mbed TLS APIs.
|
||||
* \warning This option enables new Mbed TLS APIs which are currently
|
||||
* considered experimental and may change in incompatible ways at any time.
|
||||
* That is, the APIs enabled by this option are not covered by the usual
|
||||
* promises of API stability.
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C.
|
||||
*
|
||||
@@ -2546,6 +2652,11 @@
|
||||
* Enable the CMAC (Cipher-based Message Authentication Code) mode for block
|
||||
* ciphers.
|
||||
*
|
||||
* \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying
|
||||
* implementation of the CMAC algorithm is provided by an alternate
|
||||
* implementation, that alternate implementation may opt to not support
|
||||
* AES-192 or 3DES as underlying block ciphers for the CMAC operation.
|
||||
*
|
||||
* Module: library/cmac.c
|
||||
*
|
||||
* Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
|
||||
@@ -3109,13 +3220,11 @@
|
||||
*
|
||||
* Enable the Platform Security Architecture cryptography API.
|
||||
*
|
||||
* \warning The PSA Crypto API is still beta status. While you're welcome to
|
||||
* experiment using it, incompatible API changes are still possible, and some
|
||||
* parts may not have reached the same quality as the rest of Mbed TLS yet.
|
||||
*
|
||||
* Module: library/psa_crypto.c
|
||||
*
|
||||
* Requires: MBEDTLS_CTR_DRBG_C, MBEDTLS_ENTROPY_C
|
||||
* Requires: either MBEDTLS_CTR_DRBG_C and MBEDTLS_ENTROPY_C,
|
||||
* or MBEDTLS_HMAC_DRBG_C and MBEDTLS_ENTROPY_C,
|
||||
* or MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG.
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_PSA_CRYPTO_C
|
||||
@@ -3524,8 +3633,8 @@
|
||||
//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
|
||||
|
||||
/* ECP options */
|
||||
//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
|
||||
//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
|
||||
//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups. Normally determined automatically from the configured curves. */
|
||||
//#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< Maximum window size used */
|
||||
//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
|
||||
|
||||
/* Entropy options */
|
||||
@@ -3603,6 +3712,53 @@
|
||||
*/
|
||||
//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
|
||||
|
||||
/** \def MBEDTLS_CHECK_RETURN
|
||||
*
|
||||
* This macro is used at the beginning of the declaration of a function
|
||||
* to indicate that its return value should be checked. It should
|
||||
* instruct the compiler to emit a warning or an error if the function
|
||||
* is called without checking its return value.
|
||||
*
|
||||
* There is a default implementation for popular compilers in platform_util.h.
|
||||
* You can override the default implementation by defining your own here.
|
||||
*
|
||||
* If the implementation here is empty, this will effectively disable the
|
||||
* checking of functions' return values.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
|
||||
|
||||
/** \def MBEDTLS_IGNORE_RETURN
|
||||
*
|
||||
* This macro requires one argument, which should be a C function call.
|
||||
* If that function call would cause a #MBEDTLS_CHECK_RETURN warning, this
|
||||
* warning is suppressed.
|
||||
*/
|
||||
//#define MBEDTLS_IGNORE_RETURN( result ) ((void) !(result))
|
||||
|
||||
/* PSA options */
|
||||
/**
|
||||
* Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the
|
||||
* PSA crypto subsystem.
|
||||
*
|
||||
* If this option is unset:
|
||||
* - If CTR_DRBG is available, the PSA subsystem uses it rather than HMAC_DRBG.
|
||||
* - Otherwise, the PSA subsystem uses HMAC_DRBG with either
|
||||
* #MBEDTLS_MD_SHA512 or #MBEDTLS_MD_SHA256 based on availability and
|
||||
* on unspecified heuristics.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256
|
||||
|
||||
/** \def MBEDTLS_PSA_KEY_SLOT_COUNT
|
||||
* Restrict the PSA library to supporting a maximum amount of simultaneously
|
||||
* loaded keys. A loaded key is a key stored by the PSA Crypto core as a
|
||||
* volatile key, or a persistent key which is loaded temporarily by the
|
||||
* library as part of a crypto operation in flight.
|
||||
*
|
||||
* If this option is unset, the library will fall back to a default value of
|
||||
* 32 keys.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
|
||||
|
||||
/* SSL Cache options */
|
||||
//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
|
||||
//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */
|
||||
@@ -3736,7 +3892,7 @@
|
||||
* Maximum number of heap-allocated bytes for the purpose of
|
||||
* DTLS handshake message reassembly and future message buffering.
|
||||
*
|
||||
* This should be at least 9/8 * MBEDTLSSL_IN_CONTENT_LEN
|
||||
* This should be at least 9/8 * MBEDTLS_SSL_IN_CONTENT_LEN
|
||||
* to account for a reassembled handshake message of maximum size,
|
||||
* together with its reassembly bitmap.
|
||||
*
|
||||
@@ -3752,6 +3908,17 @@
|
||||
//#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */
|
||||
//#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
|
||||
|
||||
/** \def MBEDTLS_TLS_EXT_CID
|
||||
*
|
||||
* At the time of writing, the CID extension has not been assigned its
|
||||
* final value. Set this configuration option to make Mbed TLS use a
|
||||
* different value.
|
||||
*
|
||||
* A future minor revision of Mbed TLS may change the default value of
|
||||
* this option to match evolving standards and usage.
|
||||
*/
|
||||
//#define MBEDTLS_TLS_EXT_CID 254
|
||||
|
||||
/**
|
||||
* Complete list of ciphersuites to use, in order of preference.
|
||||
*
|
||||
@@ -3770,20 +3937,6 @@
|
||||
//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
|
||||
//#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */
|
||||
|
||||
/**
|
||||
* Allow SHA-1 in the default TLS configuration for certificate signing.
|
||||
* Without this build-time option, SHA-1 support must be activated explicitly
|
||||
* through mbedtls_ssl_conf_cert_profile. Turning on this option is not
|
||||
* recommended because of it is possible to generate SHA-1 collisions, however
|
||||
* this may be safe for legacy infrastructure where additional controls apply.
|
||||
*
|
||||
* \warning SHA-1 is considered a weak message digest and its use constitutes
|
||||
* a security risk. If possible, we recommend avoiding dependencies
|
||||
* on it, and considering stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
|
||||
|
||||
/**
|
||||
* Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
|
||||
* signature and ciphersuite selection. Without this build-time option, SHA-1
|
||||
@@ -3799,7 +3952,7 @@
|
||||
* on it, and considering stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
|
||||
//#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
|
||||
|
||||
/**
|
||||
* Uncomment the macro to let mbed TLS use your alternate implementation of
|
||||
|
||||
+502
-1
@@ -38,6 +38,36 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* De facto synonyms */
|
||||
/****************************************************************/
|
||||
|
||||
#if defined(PSA_WANT_ALG_ECDSA_ANY) && !defined(PSA_WANT_ALG_ECDSA)
|
||||
#define PSA_WANT_ALG_ECDSA PSA_WANT_ALG_ECDSA_ANY
|
||||
#elif !defined(PSA_WANT_ALG_ECDSA_ANY) && defined(PSA_WANT_ALG_ECDSA)
|
||||
#define PSA_WANT_ALG_ECDSA_ANY PSA_WANT_ALG_ECDSA
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW
|
||||
#elif !defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW) && defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW PSA_WANT_ALG_RSA_PKCS1V15_SIGN
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_RSA_PSS_ANY_SALT) && !defined(PSA_WANT_ALG_RSA_PSS)
|
||||
#define PSA_WANT_ALG_RSA_PSS PSA_WANT_ALG_RSA_PSS_ANY_SALT
|
||||
#elif !defined(PSA_WANT_ALG_RSA_PSS_ANY_SALT) && defined(PSA_WANT_ALG_RSA_PSS)
|
||||
#define PSA_WANT_ALG_RSA_PSS_ANY_SALT PSA_WANT_ALG_RSA_PSS
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Require built-in implementations based on PSA requirements */
|
||||
/****************************************************************/
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
|
||||
|
||||
#if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)
|
||||
@@ -63,6 +93,10 @@ extern "C" {
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
|
||||
#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 /* PSA_WANT_ALG_ECDSA */
|
||||
|
||||
@@ -205,6 +239,8 @@ extern "C" {
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#define MBEDTLS_PK_WRITE_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 /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR */
|
||||
|
||||
@@ -217,9 +253,311 @@ extern "C" {
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#define MBEDTLS_PK_WRITE_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 /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */
|
||||
|
||||
/* If any of the block modes are requested that don't have an
|
||||
* associated HW assist, define PSA_HAVE_SOFT_BLOCK_MODE for checking
|
||||
* in the block cipher key types. */
|
||||
#if (defined(PSA_WANT_ALG_CTR) && !defined(MBEDTLS_PSA_ACCEL_ALG_CTR)) || \
|
||||
(defined(PSA_WANT_ALG_CFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_CFB)) || \
|
||||
(defined(PSA_WANT_ALG_OFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_OFB)) || \
|
||||
(defined(PSA_WANT_ALG_XTS) && !defined(MBEDTLS_PSA_ACCEL_ALG_XTS)) || \
|
||||
defined(PSA_WANT_ALG_ECB_NO_PADDING) || \
|
||||
(defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)) || \
|
||||
(defined(PSA_WANT_ALG_CBC_PKCS7) && \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)) || \
|
||||
(defined(PSA_WANT_ALG_CMAC) && !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC))
|
||||
#define PSA_HAVE_SOFT_BLOCK_MODE 1
|
||||
#endif
|
||||
|
||||
#if (defined(PSA_WANT_ALG_GCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_GCM)) || \
|
||||
(defined(PSA_WANT_ALG_CCM) && !defined(MBEDTLS_PSA_ACCEL_ALG_CCM))
|
||||
#define PSA_HAVE_SOFT_BLOCK_AEAD 1
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_AES)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_AES)
|
||||
#define PSA_HAVE_SOFT_KEY_TYPE_AES 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_AES */
|
||||
#if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_AEAD)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1
|
||||
#define MBEDTLS_AES_C
|
||||
#endif /* PSA_HAVE_SOFT_KEY_TYPE_AES || PSA_HAVE_SOFT_BLOCK_MODE */
|
||||
#endif /* PSA_WANT_KEY_TYPE_AES */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ARC4)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1
|
||||
#define MBEDTLS_ARC4_C
|
||||
#endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4 */
|
||||
#endif /* PSA_WANT_KEY_TYPE_ARC4 */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ARIA)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA)
|
||||
#define PSA_HAVE_SOFT_KEY_TYPE_ARIA 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA */
|
||||
#if defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_AEAD)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARIA 1
|
||||
#define MBEDTLS_ARIA_C
|
||||
#endif /* PSA_HAVE_SOFT_KEY_TYPE_ARIA || PSA_HAVE_SOFT_BLOCK_MODE */
|
||||
#endif /* PSA_WANT_KEY_TYPE_ARIA */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
|
||||
#define PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA */
|
||||
#if defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_MODE) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_AEAD)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1
|
||||
#define MBEDTLS_CAMELLIA_C
|
||||
#endif /* PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA || PSA_HAVE_SOFT_BLOCK_MODE */
|
||||
#endif /* PSA_WANT_KEY_TYPE_CAMELLIA */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_DES)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_DES)
|
||||
#define PSA_HAVE_SOFT_KEY_TYPE_DES 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_DES */
|
||||
#if defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_MODE)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES 1
|
||||
#define MBEDTLS_DES_C
|
||||
#endif /*PSA_HAVE_SOFT_KEY_TYPE_DES || PSA_HAVE_SOFT_BLOCK_MODE */
|
||||
#endif /* PSA_WANT_KEY_TYPE_DES */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_CHACHA20)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20 1
|
||||
#define MBEDTLS_CHACHA20_C
|
||||
#endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20 */
|
||||
#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
|
||||
|
||||
/* If any of the software block ciphers are selected, define
|
||||
* PSA_HAVE_SOFT_BLOCK_CIPHER, which can be used in any of these
|
||||
* situations. */
|
||||
#if defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_DES) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
|
||||
#define PSA_HAVE_SOFT_BLOCK_CIPHER 1
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_STREAM_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1
|
||||
#endif /* PSA_WANT_ALG_STREAM_CIPHER */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CBC_MAC)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_MAC)
|
||||
#error "CBC-MAC is not yet supported via the PSA API in Mbed TLS."
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CBC_MAC 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ALG_CBC_MAC */
|
||||
#endif /* PSA_WANT_ALG_CBC_MAC */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CMAC)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1
|
||||
#define MBEDTLS_CMAC_C
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ALG_CMAC */
|
||||
#endif /* PSA_WANT_ALG_CMAC */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CTR)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CTR) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CTR 1
|
||||
#define MBEDTLS_CIPHER_MODE_CTR
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CTR */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CFB)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CFB) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CFB 1
|
||||
#define MBEDTLS_CIPHER_MODE_CFB
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CFB */
|
||||
|
||||
#if defined(PSA_WANT_ALG_OFB)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_OFB) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_OFB 1
|
||||
#define MBEDTLS_CIPHER_MODE_OFB
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_OFB */
|
||||
|
||||
#if defined(PSA_WANT_ALG_XTS)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_XTS) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_XTS 1
|
||||
#define MBEDTLS_CIPHER_MODE_XTS
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_XTS */
|
||||
|
||||
#if defined(PSA_WANT_ALG_ECB_NO_PADDING)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_CBC_NO_PADDING)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING 1
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CBC_NO_PADDING */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CBC_PKCS7)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7) || \
|
||||
defined(PSA_HAVE_SOFT_BLOCK_CIPHER)
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 1
|
||||
#define MBEDTLS_CIPHER_PADDING_PKCS7
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CBC_PKCS7 */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CCM)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CCM) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1
|
||||
#define MBEDTLS_CCM_C
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_CCM */
|
||||
|
||||
#if defined(PSA_WANT_ALG_GCM)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_GCM) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_AES) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_ARIA) || \
|
||||
defined(PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_GCM 1
|
||||
#define MBEDTLS_GCM_C
|
||||
#endif
|
||||
#endif /* PSA_WANT_ALG_GCM */
|
||||
|
||||
#if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305)
|
||||
#if defined(PSA_WANT_KEY_TYPE_CHACHA20)
|
||||
#define MBEDTLS_CHACHAPOLY_C
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1
|
||||
#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 */
|
||||
#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256)
|
||||
#define MBEDTLS_ECP_DP_BP256R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_256 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256 */
|
||||
#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_256 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384)
|
||||
#define MBEDTLS_ECP_DP_BP384R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_384 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384 */
|
||||
#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_384 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512)
|
||||
#define MBEDTLS_ECP_DP_BP512R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_512 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512 */
|
||||
#endif /* PSA_WANT_ECC_BRAINPOOL_P_R1_512 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_255)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255)
|
||||
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_255 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255 */
|
||||
#endif /* PSA_WANT_ECC_MONTGOMERY_255 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_MONTGOMERY_448)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448)
|
||||
/*
|
||||
* Curve448 is not yet supported via the PSA API in Mbed TLS
|
||||
* (https://github.com/ARMmbed/mbedtls/issues/4249).
|
||||
*/
|
||||
#error "Curve448 is not yet supported via the PSA API in Mbed TLS."
|
||||
#define MBEDTLS_ECP_DP_CURVE448_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_448 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448 */
|
||||
#endif /* PSA_WANT_ECC_MONTGOMERY_448 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_192)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192)
|
||||
#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_192 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192 */
|
||||
#endif /* PSA_WANT_ECC_SECP_R1_192 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_224)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224)
|
||||
#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_224 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224 */
|
||||
#endif /* PSA_WANT_ECC_SECP_R1_224 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_256)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256)
|
||||
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256 */
|
||||
#endif /* PSA_WANT_ECC_SECP_R1_256 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_384)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384)
|
||||
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_384 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384 */
|
||||
#endif /* PSA_WANT_ECC_SECP_R1_384 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_R1_521)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521)
|
||||
#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_521 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521 */
|
||||
#endif /* PSA_WANT_ECC_SECP_R1_521 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_192)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192)
|
||||
#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_192 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192 */
|
||||
#endif /* PSA_WANT_ECC_SECP_K1_192 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_224)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224)
|
||||
/*
|
||||
* SECP224K1 is buggy via the PSA API in Mbed TLS
|
||||
* (https://github.com/ARMmbed/mbedtls/issues/3541).
|
||||
*/
|
||||
#error "SECP224K1 is buggy via the PSA API in Mbed TLS."
|
||||
#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224 */
|
||||
#endif /* PSA_WANT_ECC_SECP_K1_224 */
|
||||
|
||||
#if defined(PSA_WANT_ECC_SECP_K1_256)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256)
|
||||
#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_256 1
|
||||
#endif /* !MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256 */
|
||||
#endif /* PSA_WANT_ECC_SECP_K1_256 */
|
||||
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Infer PSA requirements from Mbed TLS capabilities */
|
||||
/****************************************************************/
|
||||
|
||||
#else /* MBEDTLS_PSA_CRYPTO_CONFIG */
|
||||
|
||||
/*
|
||||
@@ -227,6 +565,16 @@ extern "C" {
|
||||
* is not defined
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CCM 1
|
||||
#define PSA_WANT_ALG_CCM 1
|
||||
#endif /* MBEDTLS_CCM_C */
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CMAC 1
|
||||
#define PSA_WANT_ALG_CMAC 1
|
||||
#endif /* MBEDTLS_CMAC_C */
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1
|
||||
#define PSA_WANT_ALG_ECDH 1
|
||||
@@ -235,6 +583,7 @@ extern "C" {
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
|
||||
#define PSA_WANT_ALG_ECDSA 1
|
||||
#define PSA_WANT_ALG_ECDSA_ANY 1
|
||||
|
||||
// Only add in DETERMINISTIC support if ECDSA is also enabled
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
@@ -251,6 +600,11 @@ extern "C" {
|
||||
#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_GCM 1
|
||||
#define PSA_WANT_ALG_GCM 1
|
||||
#endif /* MBEDTLS_GCM_C */
|
||||
|
||||
#if defined(MBEDTLS_HKDF_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
|
||||
#define PSA_WANT_ALG_HMAC 1
|
||||
@@ -261,6 +615,7 @@ extern "C" {
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
|
||||
#define PSA_WANT_ALG_HMAC 1
|
||||
#define PSA_WANT_KEY_TYPE_HMAC
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1
|
||||
#define PSA_WANT_ALG_TLS12_PRF 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1
|
||||
@@ -293,7 +648,8 @@ extern "C" {
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
|
||||
#endif /* MBEDTLSS_PKCS1_V15 */
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_SIGN_RAW 1
|
||||
#endif /* MBEDTLS_PKCS1_V15 */
|
||||
#if defined(MBEDTLS_PKCS1_V21)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1
|
||||
#define PSA_WANT_ALG_RSA_OAEP 1
|
||||
@@ -314,6 +670,7 @@ extern "C" {
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1
|
||||
#define PSA_WANT_ALG_SHA_224 1
|
||||
#define PSA_WANT_ALG_SHA_256 1
|
||||
#endif
|
||||
|
||||
@@ -326,8 +683,152 @@ extern "C" {
|
||||
#define PSA_WANT_ALG_SHA_512 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
#define PSA_WANT_KEY_TYPE_AES 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#define PSA_WANT_KEY_TYPE_ARC4 1
|
||||
#define PSA_WANT_ALG_STREAM_CIPHER 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
#define PSA_WANT_KEY_TYPE_ARIA 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARIA 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
#define PSA_WANT_KEY_TYPE_CAMELLIA 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
#define PSA_WANT_KEY_TYPE_DES 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHACHA20_C)
|
||||
#define PSA_WANT_KEY_TYPE_CHACHA20 1
|
||||
#define PSA_WANT_ALG_STREAM_CIPHER 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CHACHA20 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C)
|
||||
#define PSA_WANT_ALG_CHACHA20_POLY1305 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING 1
|
||||
#define PSA_WANT_ALG_CBC_NO_PADDING 1
|
||||
#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7 1
|
||||
#define PSA_WANT_ALG_CBC_PKCS7 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) || \
|
||||
defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING 1
|
||||
#define PSA_WANT_ALG_ECB_NO_PADDING 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CFB 1
|
||||
#define PSA_WANT_ALG_CFB 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_CTR 1
|
||||
#define PSA_WANT_ALG_CTR 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_OFB 1
|
||||
#define PSA_WANT_ALG_OFB 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_XTS 1
|
||||
#define PSA_WANT_ALG_XTS 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_256 1
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_256
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_384 1
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_384
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_BRAINPOOL_P_R1_512 1
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_512
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_255 1
|
||||
#define PSA_WANT_ECC_MONTGOMERY_255
|
||||
#endif
|
||||
|
||||
/* Curve448 is not yet supported via the PSA API (https://github.com/ARMmbed/mbedtls/issues/4249) */
|
||||
#if 0 && defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_MONTGOMERY_448 1
|
||||
#define PSA_WANT_ECC_MONTGOMERY_448
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_192 1
|
||||
#define PSA_WANT_ECC_SECP_R1_192
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_224 1
|
||||
#define PSA_WANT_ECC_SECP_R1_224
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_256 1
|
||||
#define PSA_WANT_ECC_SECP_R1_256
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_384 1
|
||||
#define PSA_WANT_ECC_SECP_R1_384
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_R1_521 1
|
||||
#define PSA_WANT_ECC_SECP_R1_521
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_192 1
|
||||
#define PSA_WANT_ECC_SECP_K1_192
|
||||
#endif
|
||||
|
||||
/* SECP224K1 is buggy via the PSA API (https://github.com/ARMmbed/mbedtls/issues/3541) */
|
||||
#if 0 && defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_224 1
|
||||
#define PSA_WANT_ECC_SECP_K1_224
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
#define MBEDTLS_PSA_BUILTIN_ECC_SECP_K1_256 1
|
||||
#define PSA_WANT_ECC_SECP_K1_256
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_CONFIG */
|
||||
|
||||
/* These features are always enabled. */
|
||||
#define PSA_WANT_KEY_TYPE_DERIVE 1
|
||||
#define PSA_WANT_KEY_TYPE_RAW_DATA 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Constant-time functions
|
||||
*
|
||||
* 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_H
|
||||
#define MBEDTLS_CONSTANT_TIME_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/** Constant-time buffer comparison without branches.
|
||||
*
|
||||
* This is equivalent to the standard memcmp function, but is likely to be
|
||||
* compiled to code using bitwise operation rather than a branch.
|
||||
*
|
||||
* This function can be used to write constant-time code by replacing branches
|
||||
* with bit operations using masks.
|
||||
*
|
||||
* \param a Pointer to the first buffer.
|
||||
* \param b Pointer to the second buffer.
|
||||
* \param n The number of bytes to compare in the buffer.
|
||||
*
|
||||
* \return Zero if the content of the two buffer is the same,
|
||||
* otherwise non-zero.
|
||||
*/
|
||||
int mbedtls_ct_memcmp( const void *a,
|
||||
const void *b,
|
||||
size_t n );
|
||||
|
||||
#endif /* MBEDTLS_CONSTANT_TIME_H */
|
||||
+51
-6
@@ -53,10 +53,14 @@
|
||||
#include "mbedtls/threading.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */
|
||||
/** The entropy source failed. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
|
||||
/** The requested random buffer length is too big. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
|
||||
/** The input (entropy + additional data) is too large. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
|
||||
/** Read or write error in file. */
|
||||
#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
|
||||
|
||||
#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */
|
||||
|
||||
@@ -200,6 +204,13 @@ typedef struct mbedtls_ctr_drbg_context
|
||||
void *p_entropy; /*!< The context for the entropy function. */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized if and only if f_entropy != NULL.
|
||||
* This means that the mutex is initialized during the initial seeding
|
||||
* in mbedtls_ctr_drbg_seed() and freed in mbedtls_ctr_drbg_free().
|
||||
*
|
||||
* Note that this invariant may change without notice. Do not rely on it
|
||||
* and do not access the mutex directly in application code.
|
||||
*/
|
||||
mbedtls_threading_mutex_t mutex;
|
||||
#endif
|
||||
}
|
||||
@@ -264,6 +275,15 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
||||
* make a second call to \p f_entropy.
|
||||
*/
|
||||
#endif
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/**
|
||||
* \note When Mbed TLS is built with threading support,
|
||||
* after this function returns successfully,
|
||||
* it is safe to call mbedtls_ctr_drbg_random()
|
||||
* from multiple threads. Other operations, including
|
||||
* reseeding, are not thread-safe.
|
||||
*/
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
/**
|
||||
* - The \p custom string.
|
||||
*
|
||||
@@ -290,6 +310,8 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
||||
* the same context unless you call
|
||||
* mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()
|
||||
* again first.
|
||||
* After a failed call to mbedtls_ctr_drbg_seed(),
|
||||
* you must call mbedtls_ctr_drbg_free().
|
||||
* \param f_entropy The entropy callback, taking as arguments the
|
||||
* \p p_entropy context, the buffer to fill, and the
|
||||
* length of the buffer.
|
||||
@@ -405,6 +427,11 @@ void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
|
||||
* \brief This function reseeds the CTR_DRBG context, that is
|
||||
* extracts data from the entropy source.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional Additional data to add to the state. Can be \c NULL.
|
||||
* \param len The length of the additional data.
|
||||
@@ -422,6 +449,11 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
|
||||
/**
|
||||
* \brief This function updates the state of the CTR_DRBG context.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional The data to update the state with. This must not be
|
||||
* \c NULL unless \p add_len is \c 0.
|
||||
@@ -445,6 +477,11 @@ int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param p_rng The CTR_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_ctr_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
@@ -473,8 +510,16 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
*
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/**
|
||||
* \note When Mbed TLS is built with threading support,
|
||||
* it is safe to call mbedtls_ctr_drbg_random()
|
||||
* from multiple threads. Other operations, including
|
||||
* reseeding, are not thread-safe.
|
||||
*/
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
/**
|
||||
* \param p_rng The CTR_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_ctr_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
|
||||
+50
-1
@@ -80,6 +80,55 @@
|
||||
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PRINTF_ATTRIBUTE
|
||||
*
|
||||
* Mark a function as having printf attributes, and thus enable checking
|
||||
* via -wFormat and other flags. This does nothing on builds with compilers
|
||||
* that do not support the format attribute
|
||||
*
|
||||
* Module: library/debug.c
|
||||
* Caller:
|
||||
*
|
||||
* This module provides debugging functions.
|
||||
*/
|
||||
#if defined(__has_attribute)
|
||||
#if __has_attribute(format)
|
||||
#if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((__format__ (gnu_printf, string_index, first_to_check)))
|
||||
#else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((format(printf, string_index, first_to_check)))
|
||||
#endif
|
||||
#else /* __has_attribute(format) */
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
|
||||
#endif /* __has_attribute(format) */
|
||||
#else /* defined(__has_attribute) */
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PRINTF_SIZET
|
||||
*
|
||||
* MBEDTLS_PRINTF_xxx: Due to issues with older window compilers
|
||||
* and MinGW we need to define the printf specifier for size_t
|
||||
* and long long per platform.
|
||||
*
|
||||
* Module: library/debug.c
|
||||
* Caller:
|
||||
*
|
||||
* This module provides debugging functions.
|
||||
*/
|
||||
#if (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800)
|
||||
#include <inttypes.h>
|
||||
#define MBEDTLS_PRINTF_SIZET PRIuPTR
|
||||
#define MBEDTLS_PRINTF_LONGLONG "I64d"
|
||||
#else /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
#define MBEDTLS_PRINTF_SIZET "zu"
|
||||
#define MBEDTLS_PRINTF_LONGLONG "lld"
|
||||
#endif /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -118,7 +167,7 @@ void mbedtls_debug_set_threshold( int threshold );
|
||||
*/
|
||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *format, ... );
|
||||
const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
|
||||
|
||||
/**
|
||||
* \brief Print the return value of a function to the debug output. This
|
||||
|
||||
+18
-2
@@ -32,6 +32,7 @@
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -39,10 +40,12 @@
|
||||
#define MBEDTLS_DES_ENCRYPT 1
|
||||
#define MBEDTLS_DES_DECRYPT 0
|
||||
|
||||
#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /**< The data input has an invalid length. */
|
||||
/** The data input has an invalid length. */
|
||||
#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
|
||||
|
||||
/* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 /**< DES hardware accelerator failed. */
|
||||
/** DES hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
|
||||
|
||||
#define MBEDTLS_DES_KEY_SIZE 8
|
||||
|
||||
@@ -144,6 +147,7 @@ void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
|
||||
/**
|
||||
@@ -157,6 +161,7 @@ int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SI
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
|
||||
/**
|
||||
@@ -171,6 +176,7 @@ int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
|
||||
/**
|
||||
@@ -185,6 +191,7 @@ int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MB
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
|
||||
/**
|
||||
@@ -195,6 +202,7 @@ int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MB
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
|
||||
|
||||
@@ -206,6 +214,7 @@ int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
|
||||
|
||||
@@ -217,6 +226,7 @@ int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
|
||||
|
||||
@@ -228,6 +238,7 @@ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
|
||||
|
||||
@@ -244,6 +255,7 @@ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
@@ -271,6 +283,7 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -288,6 +301,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
@@ -313,6 +327,7 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
@@ -343,6 +358,7 @@ void mbedtls_des_setkey( uint32_t SK[32],
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
int mbedtls_des_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
+22
-11
@@ -73,20 +73,31 @@
|
||||
/*
|
||||
* DHM Error codes
|
||||
*/
|
||||
#define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters. */
|
||||
#define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */
|
||||
#define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */
|
||||
#define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */
|
||||
#define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */
|
||||
#define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */
|
||||
#define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */
|
||||
#define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */
|
||||
/** Bad input parameters. */
|
||||
#define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080
|
||||
/** Reading of the DHM parameters failed. */
|
||||
#define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100
|
||||
/** Making of the DHM parameters failed. */
|
||||
#define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180
|
||||
/** Reading of the public values failed. */
|
||||
#define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200
|
||||
/** Making of the public value failed. */
|
||||
#define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280
|
||||
/** Calculation of the DHM secret failed. */
|
||||
#define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300
|
||||
/** The ASN.1 data is not formatted correctly. */
|
||||
#define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380
|
||||
/** Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400
|
||||
/** Read or write of file failed. */
|
||||
#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480
|
||||
|
||||
/* MBEDTLS_ERR_DHM_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */
|
||||
/** DHM hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500
|
||||
|
||||
#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */
|
||||
/** Setting the modulus and generator failed. */
|
||||
#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+74
-17
@@ -45,19 +45,29 @@
|
||||
/*
|
||||
* ECP error codes
|
||||
*/
|
||||
#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */
|
||||
#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< The requested feature is not available, for example, the requested curve is not supported. */
|
||||
#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */
|
||||
#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */
|
||||
#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as ephemeral key, failed. */
|
||||
#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */
|
||||
#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< The buffer contains a valid signature followed by more data. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80
|
||||
/** The buffer is too small to write to. */
|
||||
#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00
|
||||
/** The requested feature is not available, for example, the requested curve is not supported. */
|
||||
#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80
|
||||
/** The signature is not valid. */
|
||||
#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00
|
||||
/** Memory allocation failed. */
|
||||
#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80
|
||||
/** Generation of random value, such as ephemeral key, failed. */
|
||||
#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00
|
||||
/** Invalid private or public key. */
|
||||
#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80
|
||||
/** The buffer contains a valid signature followed by more data. */
|
||||
#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00
|
||||
|
||||
/* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< The ECP hardware accelerator failed. */
|
||||
/** The ECP hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80
|
||||
|
||||
#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 /**< Operation in progress, call again with the same parameters to continue. */
|
||||
/** Operation in progress, call again with the same parameters to continue. */
|
||||
#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00
|
||||
|
||||
/* Flags indicating whether to include code that is specific to certain
|
||||
* types of curves. These flags are for internal library use only. */
|
||||
@@ -96,6 +106,7 @@ extern "C" {
|
||||
* - Add it at the end of this enum, otherwise you'll break the ABI by
|
||||
* changing the numerical value for existing curves.
|
||||
* - Increment MBEDTLS_ECP_DP_MAX below if needed.
|
||||
* - Update the calculation of MBEDTLS_ECP_MAX_BITS_MIN below.
|
||||
* - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to
|
||||
* config.h.
|
||||
* - List the curve as a dependency of MBEDTLS_ECP_C and
|
||||
@@ -171,6 +182,40 @@ typedef struct mbedtls_ecp_point
|
||||
}
|
||||
mbedtls_ecp_point;
|
||||
|
||||
/* Determine the minimum safe value of MBEDTLS_ECP_MAX_BITS. */
|
||||
#if !defined(MBEDTLS_ECP_C)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 0
|
||||
/* Note: the curves must be listed in DECREASING size! */
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 521
|
||||
#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 512
|
||||
#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 448
|
||||
#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 384
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 384
|
||||
#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 256
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 256
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 256
|
||||
#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 255
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 225 // n is slightly above 2^224
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 224
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 192
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS_MIN 192
|
||||
#else
|
||||
#error "MBEDTLS_ECP_C enabled, but no curve?"
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
/*
|
||||
* default mbed TLS elliptic curve arithmetic implementation
|
||||
@@ -245,11 +290,23 @@ mbedtls_ecp_group;
|
||||
* \{
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_ECP_MAX_BITS)
|
||||
#if defined(MBEDTLS_ECP_MAX_BITS)
|
||||
|
||||
#if MBEDTLS_ECP_MAX_BITS < MBEDTLS_ECP_MAX_BITS_MIN
|
||||
#error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve"
|
||||
#endif
|
||||
|
||||
#elif defined(MBEDTLS_ECP_C)
|
||||
/**
|
||||
* The maximum size of the groups, that is, of \c N and \c P.
|
||||
*/
|
||||
#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */
|
||||
#define MBEDTLS_ECP_MAX_BITS MBEDTLS_ECP_MAX_BITS_MIN
|
||||
|
||||
#else
|
||||
/* MBEDTLS_ECP_MAX_BITS is not relevant without MBEDTLS_ECP_C, but set it
|
||||
* to a nonzero value so that code that unconditionally allocates an array
|
||||
* of a size based on it keeps working if built without ECC support. */
|
||||
#define MBEDTLS_ECP_MAX_BITS 1
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
|
||||
@@ -258,7 +315,8 @@ mbedtls_ecp_group;
|
||||
#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
|
||||
/*
|
||||
* Maximum "window" size used for point multiplication.
|
||||
* Default: 6.
|
||||
* Default: a point where higher memory usage yields disminishing performance
|
||||
* returns.
|
||||
* Minimum value: 2. Maximum value: 7.
|
||||
*
|
||||
* Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
|
||||
@@ -275,7 +333,7 @@ mbedtls_ecp_group;
|
||||
* 224 475 475 453 398 342
|
||||
* 192 640 640 633 587 476
|
||||
*/
|
||||
#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */
|
||||
#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< The maximum window size used. */
|
||||
#endif /* MBEDTLS_ECP_WINDOW_SIZE */
|
||||
|
||||
#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
|
||||
@@ -466,8 +524,7 @@ mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp );
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the information defined in
|
||||
* mbedtls_ecp_curve_info() for all supported curves in order
|
||||
* of preference.
|
||||
* mbedtls_ecp_curve_info() for all supported curves.
|
||||
*
|
||||
* \note This function returns information about all curves
|
||||
* supported by the library. Some curves may not be
|
||||
@@ -1180,7 +1237,7 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
*
|
||||
* \param grp_id The ECP group identifier.
|
||||
* \param key The destination key.
|
||||
* \param buf The the buffer containing the binary representation of the
|
||||
* \param buf The buffer containing the binary representation of the
|
||||
* key. (Big endian integer for Weierstrass curves, byte
|
||||
* string for Montgomery curves.)
|
||||
* \param buflen The length of the buffer in bytes.
|
||||
|
||||
+15
-8
@@ -48,11 +48,16 @@
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */
|
||||
#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */
|
||||
#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 /**< No sources have been added to poll. */
|
||||
#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D /**< No strong sources have been added to poll. */
|
||||
#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F /**< Read/write error in file. */
|
||||
/** Critical entropy source failure. */
|
||||
#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C
|
||||
/** No more sources can be added. */
|
||||
#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E
|
||||
/** No sources have been added to poll. */
|
||||
#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
|
||||
/** No strong sources have been added to poll. */
|
||||
#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D
|
||||
/** Read/write error in file. */
|
||||
#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F
|
||||
|
||||
/**
|
||||
* \name SECTION: Module settings
|
||||
@@ -120,13 +125,15 @@ mbedtls_entropy_source_state;
|
||||
*/
|
||||
typedef struct mbedtls_entropy_context
|
||||
{
|
||||
int accumulator_started;
|
||||
int accumulator_started; /* 0 after init.
|
||||
* 1 after the first update.
|
||||
* -1 after free. */
|
||||
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
||||
mbedtls_sha512_context accumulator;
|
||||
#else
|
||||
#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
|
||||
mbedtls_sha256_context accumulator;
|
||||
#endif
|
||||
int source_count;
|
||||
int source_count; /* Number of entries used in source. */
|
||||
mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_havege_state havege_data;
|
||||
|
||||
+57
-2
@@ -30,6 +30,11 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Error code layout.
|
||||
*
|
||||
@@ -111,8 +116,58 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001 /**< Generic error */
|
||||
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E /**< This is a bug in the library */
|
||||
/** Generic error */
|
||||
#define MBEDTLS_ERR_ERROR_GENERIC_ERROR -0x0001
|
||||
/** This is a bug in the library */
|
||||
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED -0x006E
|
||||
|
||||
/**
|
||||
* \brief Combines a high-level and low-level error code together.
|
||||
*
|
||||
* Wrapper macro for mbedtls_error_add(). See that function for
|
||||
* more details.
|
||||
*/
|
||||
#define MBEDTLS_ERROR_ADD( high, low ) \
|
||||
mbedtls_error_add( high, low, __FILE__, __LINE__ )
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
/**
|
||||
* \brief Testing hook called before adding/combining two error codes together.
|
||||
* Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS.
|
||||
*/
|
||||
extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Combines a high-level and low-level error code together.
|
||||
*
|
||||
* This function can be called directly however it is usually
|
||||
* called via the #MBEDTLS_ERROR_ADD macro.
|
||||
*
|
||||
* While a value of zero is not a negative error code, it is still an
|
||||
* error code (that denotes success) and can be combined with both a
|
||||
* negative error code or another value of zero.
|
||||
*
|
||||
* \note When invasive testing is enabled via #MBEDTLS_TEST_HOOKS, also try to
|
||||
* call \link mbedtls_test_hook_error_add \endlink.
|
||||
*
|
||||
* \param high high-level error code. See error.h for more details.
|
||||
* \param low low-level error code. See error.h for more details.
|
||||
* \param file file where this error code addition occurred.
|
||||
* \param line line where this error code addition occurred.
|
||||
*/
|
||||
static inline int mbedtls_error_add( int high, int low,
|
||||
const char *file, int line )
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
if( *mbedtls_test_hook_error_add != NULL )
|
||||
( *mbedtls_test_hook_error_add )( high, low, file, line );
|
||||
#endif
|
||||
(void)file;
|
||||
(void)line;
|
||||
|
||||
return( high + low );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Translate a mbed TLS error code into a string representation,
|
||||
|
||||
+6
-3
@@ -44,12 +44,15 @@
|
||||
#define MBEDTLS_GCM_ENCRYPT 1
|
||||
#define MBEDTLS_GCM_DECRYPT 0
|
||||
|
||||
#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */
|
||||
/** Authenticated decryption failed. */
|
||||
#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
|
||||
|
||||
/* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */
|
||||
/** GCM hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
|
||||
|
||||
#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
* \name HKDF Error codes
|
||||
* \{
|
||||
*/
|
||||
#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80 /**< Bad input parameters to function. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80
|
||||
/* \} name */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+63
-7
@@ -41,10 +41,14 @@
|
||||
/*
|
||||
* Error codes
|
||||
*/
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */
|
||||
/** Too many random requested in single call. */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
|
||||
/** Input too large (Entropy + additional). */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
|
||||
/** Read/write error in file. */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
|
||||
/** The entropy source failed. */
|
||||
#define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
|
||||
|
||||
/**
|
||||
* \name SECTION: Module settings
|
||||
@@ -101,6 +105,14 @@ typedef struct mbedtls_hmac_drbg_context
|
||||
void *p_entropy; /*!< context for the entropy function */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized if and only if
|
||||
* md_ctx->md_info != NULL. This means that the mutex is initialized
|
||||
* during the initial seeding in mbedtls_hmac_drbg_seed() or
|
||||
* mbedtls_hmac_drbg_seed_buf() and freed in mbedtls_ctr_drbg_free().
|
||||
*
|
||||
* Note that this invariant may change without notice. Do not rely on it
|
||||
* and do not access the mutex directly in application code.
|
||||
*/
|
||||
mbedtls_threading_mutex_t mutex;
|
||||
#endif
|
||||
} mbedtls_hmac_drbg_context;
|
||||
@@ -150,7 +162,17 @@ void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
|
||||
* \note During the initial seeding, this function calls
|
||||
* the entropy source to obtain a nonce
|
||||
* whose length is half the entropy length.
|
||||
*
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/**
|
||||
* \note When Mbed TLS is built with threading support,
|
||||
* after this function returns successfully,
|
||||
* it is safe to call mbedtls_hmac_drbg_random()
|
||||
* from multiple threads. Other operations, including
|
||||
* reseeding, are not thread-safe.
|
||||
*/
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
/**
|
||||
* \param ctx HMAC_DRBG context to be seeded.
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG.
|
||||
* \param f_entropy The entropy callback, taking as arguments the
|
||||
@@ -189,7 +211,17 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
*
|
||||
* This function is meant for use in algorithms that need a pseudorandom
|
||||
* input such as deterministic ECDSA.
|
||||
*
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/**
|
||||
* \note When Mbed TLS is built with threading support,
|
||||
* after this function returns successfully,
|
||||
* it is safe to call mbedtls_hmac_drbg_random()
|
||||
* from multiple threads. Other operations, including
|
||||
* reseeding, are not thread-safe.
|
||||
*/
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
/**
|
||||
* \param ctx HMAC_DRBG context to be initialised.
|
||||
* \param md_info MD algorithm to use for HMAC_DRBG.
|
||||
* \param data Concatenation of the initial entropy string and
|
||||
@@ -252,6 +284,11 @@ void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
|
||||
/**
|
||||
* \brief This function updates the state of the HMAC_DRBG context.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* If this is \c NULL, there is no additional data.
|
||||
@@ -268,6 +305,11 @@ int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
|
||||
* \brief This function reseeds the HMAC_DRBG context, that is
|
||||
* extracts data from the entropy source.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param additional Additional data to add to the state.
|
||||
* If this is \c NULL, there is no additional data
|
||||
@@ -293,6 +335,11 @@ int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
* \note This function is not thread-safe. It is not safe
|
||||
* to call this function if another thread might be
|
||||
* concurrently obtaining random numbers from the same
|
||||
* context or updating or reseeding the same context.
|
||||
*
|
||||
* \param p_rng The HMAC_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_hmac_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
@@ -322,7 +369,16 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng,
|
||||
*
|
||||
* This function automatically reseeds if the reseed counter is exceeded
|
||||
* or prediction resistance is enabled.
|
||||
*
|
||||
*/
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/**
|
||||
* \note When Mbed TLS is built with threading support,
|
||||
* it is safe to call mbedtls_ctr_drbg_random()
|
||||
* from multiple threads. Other operations, including
|
||||
* reseeding, are not thread-safe.
|
||||
*/
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
/**
|
||||
* \param p_rng The HMAC_DRBG context. This must be a pointer to a
|
||||
* #mbedtls_hmac_drbg_context structure.
|
||||
* \param output The buffer to fill.
|
||||
|
||||
+24
-5
@@ -32,14 +32,20 @@
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
|
||||
/** The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
|
||||
/** Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
|
||||
/** Opening or reading of file failed. */
|
||||
#define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
|
||||
|
||||
/* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */
|
||||
/** MD hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -205,6 +211,7 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_
|
||||
* 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 );
|
||||
|
||||
/**
|
||||
@@ -226,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 #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_clone( mbedtls_md_context_t *dst,
|
||||
const mbedtls_md_context_t *src );
|
||||
|
||||
@@ -275,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
||||
|
||||
/**
|
||||
@@ -293,6 +302,7 @@ int mbedtls_md_starts( mbedtls_md_context_t *ctx );
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
|
||||
|
||||
/**
|
||||
@@ -313,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
|
||||
|
||||
/**
|
||||
@@ -333,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
|
||||
unsigned char *output );
|
||||
|
||||
@@ -354,6 +366,7 @@ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, si
|
||||
* the file pointed by \p path.
|
||||
* \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,
|
||||
unsigned char *output );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
@@ -376,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
|
||||
size_t keylen );
|
||||
|
||||
@@ -398,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
@@ -419,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
|
||||
|
||||
/**
|
||||
@@ -436,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
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
||||
|
||||
/**
|
||||
@@ -460,11 +477,13 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification
|
||||
* failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
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,
|
||||
unsigned char *output );
|
||||
|
||||
/* Internal use */
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@
|
||||
#include <stddef.h>
|
||||
|
||||
/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
|
||||
/** MD2 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
|
||||
/** MD4 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
|
||||
/** MD5 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+41
-16
@@ -49,19 +49,32 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */
|
||||
#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044 /**< The connection to the given server / port failed. */
|
||||
#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046 /**< Binding of the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048 /**< Could not listen on the socket. */
|
||||
#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A /**< Could not accept the incoming connection. */
|
||||
#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C /**< Reading information from the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E /**< Sending information through the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_CONN_RESET -0x0050 /**< Connection was reset by peer. */
|
||||
#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 /**< Failed to get an IP address for the given hostname. */
|
||||
#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 /**< Buffer is too small to hold the data. */
|
||||
#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 /**< The context is invalid, eg because it was free()ed. */
|
||||
#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047 /**< Polling the net context failed. */
|
||||
#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049 /**< Input invalid. */
|
||||
/** Failed to open a socket. */
|
||||
#define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042
|
||||
/** The connection to the given server / port failed. */
|
||||
#define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044
|
||||
/** Binding of the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_BIND_FAILED -0x0046
|
||||
/** Could not listen on the socket. */
|
||||
#define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048
|
||||
/** Could not accept the incoming connection. */
|
||||
#define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A
|
||||
/** Reading information from the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_RECV_FAILED -0x004C
|
||||
/** Sending information through the socket failed. */
|
||||
#define MBEDTLS_ERR_NET_SEND_FAILED -0x004E
|
||||
/** Connection was reset by peer. */
|
||||
#define MBEDTLS_ERR_NET_CONN_RESET -0x0050
|
||||
/** Failed to get an IP address for the given hostname. */
|
||||
#define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052
|
||||
/** Buffer is too small to hold the data. */
|
||||
#define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043
|
||||
/** The context is invalid, eg because it was free()ed. */
|
||||
#define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045
|
||||
/** Polling the net context failed. */
|
||||
#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047
|
||||
/** Input invalid. */
|
||||
#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049
|
||||
|
||||
#define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */
|
||||
|
||||
@@ -124,6 +137,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char
|
||||
*
|
||||
* \return 0 if successful, or one of:
|
||||
* MBEDTLS_ERR_NET_SOCKET_FAILED,
|
||||
* MBEDTLS_ERR_NET_UNKNOWN_HOST,
|
||||
* MBEDTLS_ERR_NET_BIND_FAILED,
|
||||
* MBEDTLS_ERR_NET_LISTEN_FAILED
|
||||
*
|
||||
@@ -143,6 +157,8 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
|
||||
* can be NULL if client_ip is null
|
||||
*
|
||||
* \return 0 if successful, or
|
||||
* MBEDTLS_ERR_NET_SOCKET_FAILED,
|
||||
* MBEDTLS_ERR_NET_BIND_FAILED,
|
||||
* MBEDTLS_ERR_NET_ACCEPT_FAILED, or
|
||||
* MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,
|
||||
* MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
|
||||
@@ -155,6 +171,10 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
|
||||
/**
|
||||
* \brief Check and wait for the context to be ready for read/write
|
||||
*
|
||||
* \note The current implementation of this function uses
|
||||
* select() and returns an error if the file descriptor
|
||||
* is \c FD_SETSIZE or greater.
|
||||
*
|
||||
* \param ctx Socket to check
|
||||
* \param rw Bitflag composed of MBEDTLS_NET_POLL_READ and
|
||||
* MBEDTLS_NET_POLL_WRITE specifying the events
|
||||
@@ -236,16 +256,21 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
|
||||
* 'timeout' seconds. If no error occurs, the actual amount
|
||||
* read is returned.
|
||||
*
|
||||
* \note The current implementation of this function uses
|
||||
* select() and returns an error if the file descriptor
|
||||
* is \c FD_SETSIZE or greater.
|
||||
*
|
||||
* \param ctx Socket
|
||||
* \param buf The buffer to write to
|
||||
* \param len Maximum length of the buffer
|
||||
* \param timeout Maximum number of milliseconds to wait for data
|
||||
* 0 means no timeout (wait forever)
|
||||
*
|
||||
* \return the number of bytes received,
|
||||
* or a non-zero error code:
|
||||
* MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
|
||||
* \return The number of bytes received if successful.
|
||||
* MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out.
|
||||
* MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
|
||||
* Another negative error code (MBEDTLS_ERR_NET_xxx)
|
||||
* for other failures.
|
||||
*
|
||||
* \note This function will block (until data becomes available or
|
||||
* timeout is reached) even if the socket is set to
|
||||
|
||||
+4
-2
@@ -41,8 +41,10 @@
|
||||
#include "mbedtls/md.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_OID_NOT_FOUND -0x002E /**< OID is not found. */
|
||||
#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B /**< output buffer is too small */
|
||||
/** OID is not found. */
|
||||
#define MBEDTLS_ERR_OID_NOT_FOUND -0x002E
|
||||
/** output buffer is too small */
|
||||
#define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B
|
||||
|
||||
/* This is for the benefit of X.509, but defined here in order to avoid
|
||||
* having a "backwards" include of x.509.h here */
|
||||
|
||||
+3
-2
@@ -34,7 +34,8 @@
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
|
||||
/** Input data should be aligned. */
|
||||
#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(address_sanitizer)
|
||||
@@ -71,7 +72,7 @@ extern "C" {
|
||||
*
|
||||
* \param feature The feature to detect
|
||||
*
|
||||
* \return 1 if CPU has support for the feature, 0 otherwise
|
||||
* \return non-zero if CPU has support for the feature, 0 otherwise
|
||||
*/
|
||||
int mbedtls_padlock_has_support( int feature );
|
||||
|
||||
|
||||
+18
-9
@@ -36,15 +36,24 @@
|
||||
* PEM data.
|
||||
* \{
|
||||
*/
|
||||
#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */
|
||||
#define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
|
||||
#define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
|
||||
#define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
|
||||
#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
|
||||
#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
|
||||
#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */
|
||||
/** No PEM header or footer found. */
|
||||
#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080
|
||||
/** PEM string is not as expected. */
|
||||
#define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100
|
||||
/** Failed to allocate memory. */
|
||||
#define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180
|
||||
/** RSA IV is not in hex-format. */
|
||||
#define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200
|
||||
/** Unsupported key encryption algorithm. */
|
||||
#define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280
|
||||
/** Private key password can't be empty. */
|
||||
#define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300
|
||||
/** Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380
|
||||
/** Unavailable feature, e.g. hashing/encryption combination. */
|
||||
#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480
|
||||
/* \} name */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+30
-15
@@ -52,23 +52,38 @@
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /**< Memory allocation failed. */
|
||||
#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
|
||||
#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 /**< Read/write of file failed. */
|
||||
#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 /**< Unsupported key version */
|
||||
#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */
|
||||
#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */
|
||||
#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */
|
||||
#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
|
||||
#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 /**< The algorithm tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */
|
||||
#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */
|
||||
#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The buffer contains a valid signature followed by more data. */
|
||||
/** Memory allocation failed. */
|
||||
#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
|
||||
/** Type mismatch, eg attempt to encrypt with an ECDSA key */
|
||||
#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
|
||||
/** Read/write of file failed. */
|
||||
#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
|
||||
/** Unsupported key version */
|
||||
#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
|
||||
/** Invalid key tag or value. */
|
||||
#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
|
||||
/** Key algorithm is unsupported (only RSA and EC are supported). */
|
||||
#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
|
||||
/** Private key password can't be empty. */
|
||||
#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
|
||||
/** Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
|
||||
/** The pubkey tag or value is invalid (only RSA and EC are supported). */
|
||||
#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
|
||||
/** The algorithm tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
|
||||
/** Elliptic curve is unsupported (only NIST curves are supported). */
|
||||
#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
|
||||
/** Unavailable feature, e.g. RSA disabled for RSA key. */
|
||||
#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
|
||||
/** The buffer contains a valid signature followed by more data. */
|
||||
#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
|
||||
|
||||
/* MBEDTLS_ERR_PK_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 /**< PK hardware accelerator failed. */
|
||||
/** PK hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+29
-17
@@ -34,10 +34,14 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
|
||||
#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
|
||||
#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80
|
||||
/** Feature not available, e.g. unsupported encryption scheme. */
|
||||
#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00
|
||||
/** PBE ASN.1 data not as expected. */
|
||||
#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80
|
||||
/** Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00
|
||||
|
||||
#define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
|
||||
#define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
|
||||
@@ -75,11 +79,13 @@ int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
|
||||
* \brief PKCS12 Password Based function (encryption / decryption)
|
||||
* for cipher-based and mbedtls_md-based PBE's
|
||||
*
|
||||
* \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
|
||||
* \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
|
||||
* \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 cipher_type the cipher used
|
||||
* \param md_type the mbedtls_md used
|
||||
* \param pwd the password used (may be NULL if no password is used)
|
||||
* \param md_type the mbedtls_md 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 input the input data
|
||||
* \param len data length
|
||||
@@ -100,18 +106,24 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
|
||||
* to produce pseudo-random bits for a particular "purpose".
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* \param data buffer to store the derived data in
|
||||
* \param datalen length to fill
|
||||
* \param pwd password to use (may be NULL if no password is used)
|
||||
* \param pwdlen length of the password (may be 0)
|
||||
* \param salt salt buffer to use
|
||||
* \param saltlen length of the salt
|
||||
* \param mbedtls_md mbedtls_md type to use during the derivation
|
||||
* \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
|
||||
* MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
|
||||
* \param datalen length of buffer to fill
|
||||
* \param pwd The password to use. For compliance with PKCS#12 §B.1, this
|
||||
* should be a BMPString, i.e. a Unicode string where each
|
||||
* character is encoded as 2 bytes in big-endian order, with
|
||||
* 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 id id that describes the purpose (can be
|
||||
* #MBEDTLS_PKCS12_DERIVE_KEY, #MBEDTLS_PKCS12_DERIVE_IV or
|
||||
* #MBEDTLS_PKCS12_DERIVE_MAC_KEY)
|
||||
* \param iterations number of iterations
|
||||
*
|
||||
* \return 0 if successful, or a MD, BIGNUM type error.
|
||||
|
||||
+8
-4
@@ -36,10 +36,14 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */
|
||||
#define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */
|
||||
#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80
|
||||
/** Unexpected ASN.1 data. */
|
||||
#define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00
|
||||
/** Requested encryption or digest alg not available. */
|
||||
#define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80
|
||||
/** Given private key password does not allow for correct decryption. */
|
||||
#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00
|
||||
|
||||
#define MBEDTLS_PKCS5_DECRYPT 0
|
||||
#define MBEDTLS_PKCS5_ENCRYPT 1
|
||||
|
||||
+4
-2
@@ -41,8 +41,10 @@
|
||||
#include "mbedtls/platform_time.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */
|
||||
/** Hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070
|
||||
/** The requested feature is not supported by the platform */
|
||||
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -132,6 +132,95 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t;
|
||||
#endif /* MBEDTLS_DEPRECATED_WARNING */
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/* Implementation of the check-return facility.
|
||||
* See the user documentation in config.h.
|
||||
*
|
||||
* Do not use this macro directly to annotate function: instead,
|
||||
* use one of MBEDTLS_CHECK_RETURN_CRITICAL or MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
* depending on how important it is to check the return value.
|
||||
*/
|
||||
#if !defined(MBEDTLS_CHECK_RETURN)
|
||||
#if defined(__GNUC__)
|
||||
#define MBEDTLS_CHECK_RETURN __attribute__((__warn_unused_result__))
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1700
|
||||
#include <sal.h>
|
||||
#define MBEDTLS_CHECK_RETURN _Check_return_
|
||||
#else
|
||||
#define MBEDTLS_CHECK_RETURN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** Critical-failure function
|
||||
*
|
||||
* This macro appearing at the beginning of the declaration of a function
|
||||
* indicates that its return value should be checked in all applications.
|
||||
* Omitting the check is very likely to indicate a bug in the application
|
||||
* and will result in a compile-time warning if #MBEDTLS_CHECK_RETURN
|
||||
* is implemented for the compiler in use.
|
||||
*
|
||||
* \note The use of this macro is a work in progress.
|
||||
* This macro may be added to more functions in the future.
|
||||
* Such an extension is not considered an API break, provided that
|
||||
* there are near-unavoidable circumstances under which the function
|
||||
* can fail. For example, signature/MAC/AEAD verification functions,
|
||||
* and functions that require a random generator, are considered
|
||||
* return-check-critical.
|
||||
*/
|
||||
#define MBEDTLS_CHECK_RETURN_CRITICAL MBEDTLS_CHECK_RETURN
|
||||
|
||||
/** Ordinary-failure function
|
||||
*
|
||||
* This macro appearing at the beginning of the declaration of a function
|
||||
* indicates that its return value should be generally be checked in portable
|
||||
* applications. Omitting the check will result in a compile-time warning if
|
||||
* #MBEDTLS_CHECK_RETURN is implemented for the compiler in use and
|
||||
* #MBEDTLS_CHECK_RETURN_WARNING is enabled in the compile-time configuration.
|
||||
*
|
||||
* You can use #MBEDTLS_IGNORE_RETURN to explicitly ignore the return value
|
||||
* of a function that is annotated with #MBEDTLS_CHECK_RETURN.
|
||||
*
|
||||
* \note The use of this macro is a work in progress.
|
||||
* This macro will be added to more functions in the future.
|
||||
* Eventually this should appear before most functions returning
|
||||
* an error code (as \c int in the \c mbedtls_xxx API or
|
||||
* as ::psa_status_t in the \c psa_xxx API).
|
||||
*/
|
||||
#if defined(MBEDTLS_CHECK_RETURN_WARNING)
|
||||
#define MBEDTLS_CHECK_RETURN_TYPICAL MBEDTLS_CHECK_RETURN
|
||||
#else
|
||||
#define MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
#endif
|
||||
|
||||
/** Benign-failure function
|
||||
*
|
||||
* This macro appearing at the beginning of the declaration of a function
|
||||
* indicates that it is rarely useful to check its return value.
|
||||
*
|
||||
* This macro has an empty expansion. It exists for documentation purposes:
|
||||
* a #MBEDTLS_CHECK_RETURN_OPTIONAL annotation indicates that the function
|
||||
* has been analyzed for return-check usefuless, whereas the lack of
|
||||
* an annotation indicates that the function has not been analyzed and its
|
||||
* return-check usefulness is unknown.
|
||||
*/
|
||||
#define MBEDTLS_CHECK_RETURN_OPTIONAL
|
||||
|
||||
/** \def MBEDTLS_IGNORE_RETURN
|
||||
*
|
||||
* Call this macro with one argument, a function call, to suppress a warning
|
||||
* from #MBEDTLS_CHECK_RETURN due to that function call.
|
||||
*/
|
||||
#if !defined(MBEDTLS_IGNORE_RETURN)
|
||||
/* GCC doesn't silence the warning with just (void)(result).
|
||||
* (void)!(result) is known to work up at least up to GCC 10, as well
|
||||
* as with Clang and MSVC.
|
||||
*
|
||||
* https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Non_002dbugs.html
|
||||
* https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result
|
||||
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
|
||||
*/
|
||||
#define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Securely zeroize a buffer
|
||||
*
|
||||
|
||||
+6
-3
@@ -41,15 +41,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057 /**< Invalid input parameter(s). */
|
||||
/** Invalid input parameter(s). */
|
||||
#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057
|
||||
|
||||
/* MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE is deprecated and should not be
|
||||
* used. */
|
||||
#define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059 /**< Feature not available. For example, s part of the API is not implemented. */
|
||||
/** Feature not available. For example, s part of the API is not implemented. */
|
||||
#define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059
|
||||
|
||||
/* MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B /**< Poly1305 hardware accelerator failed. */
|
||||
/** Poly1305 hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+95
-5
@@ -59,6 +59,9 @@ static inline psa_key_type_t mbedtls_psa_translate_cipher_type(
|
||||
case MBEDTLS_CIPHER_AES_128_CBC:
|
||||
case MBEDTLS_CIPHER_AES_192_CBC:
|
||||
case MBEDTLS_CIPHER_AES_256_CBC:
|
||||
case MBEDTLS_CIPHER_AES_128_ECB:
|
||||
case MBEDTLS_CIPHER_AES_192_ECB:
|
||||
case MBEDTLS_CIPHER_AES_256_ECB:
|
||||
return( PSA_KEY_TYPE_AES );
|
||||
|
||||
/* ARIA not yet supported in PSA. */
|
||||
@@ -86,14 +89,14 @@ static inline psa_algorithm_t mbedtls_psa_translate_cipher_mode(
|
||||
case MBEDTLS_MODE_ECB:
|
||||
return( PSA_ALG_ECB_NO_PADDING );
|
||||
case MBEDTLS_MODE_GCM:
|
||||
return( PSA_ALG_AEAD_WITH_TAG_LENGTH( PSA_ALG_GCM, taglen ) );
|
||||
return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, taglen ) );
|
||||
case MBEDTLS_MODE_CCM:
|
||||
return( PSA_ALG_AEAD_WITH_TAG_LENGTH( PSA_ALG_CCM, taglen ) );
|
||||
return( PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, taglen ) );
|
||||
case MBEDTLS_MODE_CBC:
|
||||
if( taglen == 0 )
|
||||
return( PSA_ALG_CBC_NO_PADDING );
|
||||
/* Intentional fallthrough for taglen != 0 */
|
||||
/* fallthrough */
|
||||
else
|
||||
return( 0 );
|
||||
default:
|
||||
return( 0 );
|
||||
}
|
||||
@@ -151,7 +154,8 @@ static inline psa_algorithm_t mbedtls_psa_translate_md( mbedtls_md_type_t md_alg
|
||||
case MBEDTLS_MD_RIPEMD160:
|
||||
return( PSA_ALG_RIPEMD160 );
|
||||
#endif
|
||||
case MBEDTLS_MD_NONE: /* Intentional fallthrough */
|
||||
case MBEDTLS_MD_NONE:
|
||||
return( 0 );
|
||||
default:
|
||||
return( 0 );
|
||||
}
|
||||
@@ -419,4 +423,90 @@ static inline int mbedtls_psa_tls_ecpoint_to_psa_ec( unsigned char const *src,
|
||||
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
/* Expose whatever RNG the PSA subsystem uses to applications using the
|
||||
* mbedtls_xxx API. The declarations and definitions here need to be
|
||||
* consistent with the implementation in library/psa_crypto_random_impl.h.
|
||||
* See that file for implementation documentation. */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
|
||||
/* The type of a `f_rng` random generator function that many library functions
|
||||
* take.
|
||||
*
|
||||
* This type name is not part of the Mbed TLS stable API. It may be renamed
|
||||
* or moved without warning.
|
||||
*/
|
||||
typedef int mbedtls_f_rng_t( void *p_rng, unsigned char *output, size_t output_size );
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
|
||||
/** The random generator function for the PSA subsystem.
|
||||
*
|
||||
* This function is suitable as the `f_rng` random generator function
|
||||
* parameter of many `mbedtls_xxx` functions. Use #MBEDTLS_PSA_RANDOM_STATE
|
||||
* to obtain the \p p_rng parameter.
|
||||
*
|
||||
* The implementation of this function depends on the configuration of the
|
||||
* library.
|
||||
*
|
||||
* \note Depending on the configuration, this may be a function or
|
||||
* a pointer to a function.
|
||||
*
|
||||
* \note This function may only be used if the PSA crypto subsystem is active.
|
||||
* This means that you must call psa_crypto_init() before any call to
|
||||
* this function, and you must not call this function after calling
|
||||
* mbedtls_psa_crypto_free().
|
||||
*
|
||||
* \param p_rng The random generator context. This must be
|
||||
* #MBEDTLS_PSA_RANDOM_STATE. No other state is
|
||||
* supported.
|
||||
* \param output The buffer to fill. It must have room for
|
||||
* \c output_size bytes.
|
||||
* \param output_size The number of bytes to write to \p output.
|
||||
* This function may fail if \p output_size is too
|
||||
* large. It is guaranteed to accept any output size
|
||||
* requested by Mbed TLS library functions. The
|
||||
* maximum request size depends on the library
|
||||
* configuration.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An `MBEDTLS_ERR_ENTROPY_xxx`,
|
||||
* `MBEDTLS_ERR_PLATFORM_xxx,
|
||||
* `MBEDTLS_ERR_CTR_DRBG_xxx` or
|
||||
* `MBEDTLS_ERR_HMAC_DRBG_xxx` on error.
|
||||
*/
|
||||
int mbedtls_psa_get_random( void *p_rng,
|
||||
unsigned char *output,
|
||||
size_t output_size );
|
||||
|
||||
/** The random generator state for the PSA subsystem.
|
||||
*
|
||||
* This macro expands to an expression which is suitable as the `p_rng`
|
||||
* random generator state parameter of many `mbedtls_xxx` functions.
|
||||
* It must be used in combination with the random generator function
|
||||
* mbedtls_psa_get_random().
|
||||
*
|
||||
* The implementation of this macro depends on the configuration of the
|
||||
* library. Do not make any assumption on its nature.
|
||||
*/
|
||||
#define MBEDTLS_PSA_RANDOM_STATE NULL
|
||||
|
||||
#else /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
|
||||
|
||||
#if defined(MBEDTLS_CTR_DRBG_C)
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
typedef mbedtls_ctr_drbg_context mbedtls_psa_drbg_context_t;
|
||||
static mbedtls_f_rng_t *const mbedtls_psa_get_random = mbedtls_ctr_drbg_random;
|
||||
#elif defined(MBEDTLS_HMAC_DRBG_C)
|
||||
#include "mbedtls/hmac_drbg.h"
|
||||
typedef mbedtls_hmac_drbg_context mbedtls_psa_drbg_context_t;
|
||||
static mbedtls_f_rng_t *const mbedtls_psa_get_random = mbedtls_hmac_drbg_random;
|
||||
#endif
|
||||
extern mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state;
|
||||
|
||||
#define MBEDTLS_PSA_RANDOM_STATE mbedtls_psa_random_state
|
||||
|
||||
#endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
||||
#endif /* MBEDTLS_PSA_UTIL_H */
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@
|
||||
|
||||
/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
|
||||
/** RIPEMD160 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+108
-32
@@ -44,22 +44,33 @@
|
||||
/*
|
||||
* RSA Error codes
|
||||
*/
|
||||
#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
|
||||
#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
|
||||
#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */
|
||||
#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
|
||||
#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
|
||||
#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
|
||||
#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
|
||||
#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080
|
||||
/** Input data contains invalid padding and is rejected. */
|
||||
#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100
|
||||
/** Something failed during generation of a key. */
|
||||
#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180
|
||||
/** Key failed to pass the validity check of the library. */
|
||||
#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200
|
||||
/** The public key operation failed. */
|
||||
#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280
|
||||
/** The private key operation failed. */
|
||||
#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300
|
||||
/** The PKCS#1 verification failed. */
|
||||
#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380
|
||||
/** The output buffer for decryption is not large enough. */
|
||||
#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
|
||||
/** The random generator failed to generate non-zeros. */
|
||||
#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480
|
||||
|
||||
/* MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION is deprecated and should not be used.
|
||||
*/
|
||||
#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
|
||||
/** The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
|
||||
#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500
|
||||
|
||||
/* MBEDTLS_ERR_RSA_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */
|
||||
/** RSA hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580
|
||||
|
||||
/*
|
||||
* RSA constants
|
||||
@@ -97,7 +108,10 @@ extern "C" {
|
||||
*/
|
||||
typedef struct mbedtls_rsa_context
|
||||
{
|
||||
int ver; /*!< Always 0.*/
|
||||
int ver; /*!< Reserved for internal purposes.
|
||||
* Do not set this field in application
|
||||
* code. Its meaning might change without
|
||||
* notice. */
|
||||
size_t len; /*!< The size of \p N in Bytes. */
|
||||
|
||||
mbedtls_mpi N; /*!< The public modulus. */
|
||||
@@ -127,6 +141,7 @@ typedef struct mbedtls_rsa_context
|
||||
mask generating function used in the
|
||||
EME-OAEP and EMSA-PSS encodings. */
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized iff ver != 0. */
|
||||
mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
|
||||
#endif
|
||||
}
|
||||
@@ -972,12 +987,69 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
||||
* \brief This function performs a PKCS#1 v2.1 PSS signature
|
||||
* operation (RSASSA-PSS-SIGN).
|
||||
*
|
||||
* \note The \p hash_id in the RSA context is the one used for the
|
||||
* encoding. \p md_alg in the function call is the type of hash
|
||||
* that is encoded. According to <em>RFC-3447: Public-Key
|
||||
* \note The \c hash_id set in \p ctx (when calling
|
||||
* mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
|
||||
* afterwards) selects the hash used for the
|
||||
* encoding operation and for the mask generation function
|
||||
* (MGF1). For more details on the encoding operation and the
|
||||
* mask generation function, consult <em>RFC-3447: Public-Key
|
||||
* Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
|
||||
* Specifications</em> it is advised to keep both hashes the
|
||||
* same.
|
||||
* Specifications</em>.
|
||||
*
|
||||
* \note This function enforces that the provided salt length complies
|
||||
* with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1 v2.2) §9.1.1
|
||||
* step 3. The constraint is that the hash length plus the salt
|
||||
* length plus 2 bytes must be at most the key length. If this
|
||||
* constraint is not met, this function returns
|
||||
* #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
|
||||
*
|
||||
* \param ctx The initialized RSA context to use.
|
||||
* \param f_rng The RNG function. It must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
|
||||
* if \p f_rng doesn't need a context argument.
|
||||
* \param md_alg The message-digest algorithm used to hash the original data.
|
||||
* Use #MBEDTLS_MD_NONE for signing raw data.
|
||||
* \param hashlen The length of the message digest.
|
||||
* Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
|
||||
* \param hash The buffer holding the message digest or raw data.
|
||||
* If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
|
||||
* buffer of length \p hashlen Bytes. If \p md_alg is not
|
||||
* #MBEDTLS_MD_NONE, it must be a readable buffer of length
|
||||
* the size of the hash corresponding to \p md_alg.
|
||||
* \param saltlen The length of the salt that should be used.
|
||||
* If passed #MBEDTLS_RSA_SALT_LEN_ANY, the function will use
|
||||
* the largest possible salt length up to the hash length,
|
||||
* which is the largest permitted by some standards including
|
||||
* FIPS 186-4 §5.5.
|
||||
* \param sig The buffer to hold the signature. This must be a writable
|
||||
* buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
|
||||
* for an 2048-bit RSA modulus. A buffer length of
|
||||
* #MBEDTLS_MPI_MAX_SIZE is always safe.
|
||||
*
|
||||
* \return \c 0 if the signing operation was successful.
|
||||
* \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_rsa_rsassa_pss_sign_ext( mbedtls_rsa_context *ctx,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng,
|
||||
mbedtls_md_type_t md_alg,
|
||||
unsigned int hashlen,
|
||||
const unsigned char *hash,
|
||||
int saltlen,
|
||||
unsigned char *sig );
|
||||
|
||||
/**
|
||||
* \brief This function performs a PKCS#1 v2.1 PSS signature
|
||||
* operation (RSASSA-PSS-SIGN).
|
||||
*
|
||||
* \note The \c hash_id set in \p ctx (when calling
|
||||
* mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
|
||||
* afterwards) selects the hash used for the
|
||||
* encoding operation and for the mask generation function
|
||||
* (MGF1). For more details on the encoding operation and the
|
||||
* mask generation function, consult <em>RFC-3447: Public-Key
|
||||
* Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
|
||||
* Specifications</em>.
|
||||
*
|
||||
* \note This function always uses the maximum possible salt size,
|
||||
* up to the length of the payload hash. This choice of salt
|
||||
@@ -1007,7 +1079,7 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
||||
* \param md_alg The message-digest algorithm used to hash the original data.
|
||||
* Use #MBEDTLS_MD_NONE for signing raw data.
|
||||
* \param hashlen The length of the message digest.
|
||||
* Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
|
||||
* This is only used if \p md_alg is #MBEDTLS_MD_NONE.
|
||||
* \param hash The buffer holding the message digest or raw data.
|
||||
* If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
|
||||
* buffer of length \p hashlen Bytes. If \p md_alg is not
|
||||
@@ -1133,16 +1205,15 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
|
||||
* \brief This function performs a PKCS#1 v2.1 PSS verification
|
||||
* operation (RSASSA-PSS-VERIFY).
|
||||
*
|
||||
* The hash function for the MGF mask generating function
|
||||
* is that specified in the RSA context.
|
||||
*
|
||||
* \note The \p hash_id in the RSA context is the one used for the
|
||||
* verification. \p md_alg in the function call is the type of
|
||||
* hash that is verified. According to <em>RFC-3447: Public-Key
|
||||
* \note The \c hash_id set in \p ctx (when calling
|
||||
* mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
|
||||
* afterwards) selects the hash used for the
|
||||
* encoding operation and for the mask generation function
|
||||
* (MGF1). For more details on the encoding operation and the
|
||||
* mask generation function, consult <em>RFC-3447: Public-Key
|
||||
* Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
|
||||
* Specifications</em> it is advised to keep both hashes the
|
||||
* same. If \p hash_id in the RSA context is unset,
|
||||
* the \p md_alg from the function call is used.
|
||||
* Specifications</em>. If the \c hash_id set in \p ctx is
|
||||
* #MBEDTLS_MD_NONE, the \p md_alg parameter is used.
|
||||
*
|
||||
* \deprecated It is deprecated and discouraged to call this function
|
||||
* in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
|
||||
@@ -1190,13 +1261,12 @@ int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
|
||||
* \brief This function performs a PKCS#1 v2.1 PSS verification
|
||||
* operation (RSASSA-PSS-VERIFY).
|
||||
*
|
||||
* The hash function for the MGF mask generating function
|
||||
* is that specified in \p mgf1_hash_id.
|
||||
*
|
||||
* \note The \p sig buffer must be as large as the size
|
||||
* of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
|
||||
*
|
||||
* \note The \p hash_id in the RSA context is ignored.
|
||||
* \note The \c hash_id set in \p ctx (when calling
|
||||
* mbedtls_rsa_init() or by calling mbedtls_rsa_set_padding()
|
||||
* afterwards) is ignored.
|
||||
*
|
||||
* \param ctx The initialized RSA public key context to use.
|
||||
* \param f_rng The RNG function to use. If \p mode is #MBEDTLS_RSA_PRIVATE,
|
||||
@@ -1215,7 +1285,13 @@ int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
|
||||
* buffer of length \p hashlen Bytes. If \p md_alg is not
|
||||
* #MBEDTLS_MD_NONE, it must be a readable buffer of length
|
||||
* the size of the hash corresponding to \p md_alg.
|
||||
* \param mgf1_hash_id The message digest used for mask generation.
|
||||
* \param mgf1_hash_id The message digest algorithm used for the
|
||||
* verification operation and the mask generation
|
||||
* function (MGF1). For more details on the encoding
|
||||
* operation and the mask generation function, consult
|
||||
* <em>RFC-3447: Public-Key Cryptography Standards
|
||||
* (PKCS) #1 v2.1: RSA Cryptography
|
||||
* Specifications</em>.
|
||||
* \param expected_salt_len The length of the salt used in padding. Use
|
||||
* #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
|
||||
* \param sig The buffer holding the signature. This must be a readable
|
||||
|
||||
+4
-2
@@ -39,8 +39,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 /**< SHA-1 input data was malformed. */
|
||||
/** SHA-1 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035
|
||||
/** SHA-1 input data was malformed. */
|
||||
#define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+7
-2
@@ -35,8 +35,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */
|
||||
/** SHA-256 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037
|
||||
/** SHA-256 input data was malformed. */
|
||||
#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -235,6 +237,9 @@ MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
|
||||
* be a writable buffer of length \c 32 Bytes.
|
||||
* \param is224 Determines which function to use. This must be
|
||||
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha256_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
|
||||
+4
-2
@@ -34,8 +34,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/* MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075 /**< SHA-512 input data was malformed. */
|
||||
/** SHA-512 hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039
|
||||
/** SHA-512 input data was malformed. */
|
||||
#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+231
-156
@@ -75,64 +75,122 @@
|
||||
/*
|
||||
* SSL Error codes
|
||||
*/
|
||||
#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
|
||||
#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
|
||||
#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
|
||||
#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
|
||||
#define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
|
||||
#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
|
||||
#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
|
||||
#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
|
||||
#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
|
||||
#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
|
||||
#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
|
||||
#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
|
||||
#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */
|
||||
#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
|
||||
#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
|
||||
#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */
|
||||
#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
|
||||
#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */
|
||||
#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
|
||||
#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
|
||||
#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
|
||||
#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */
|
||||
#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */
|
||||
#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
|
||||
#define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< No data of requested type currently available on underlying transport. */
|
||||
#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */
|
||||
#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
|
||||
#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */
|
||||
#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */
|
||||
#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580 /**< Internal-only message signaling that further message-processing should be done */
|
||||
#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 /**< The asynchronous operation is not completed yet. */
|
||||
#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 /**< Internal-only message signaling that a message arrived early. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000 /**< An encrypted DTLS-frame with an unexpected CID was received. */
|
||||
#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00 /**< An operation failed due to an unexpected version or configuration. */
|
||||
#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 /**< A cryptographic operation is in progress. Try again later. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 /**< Invalid value in SSL config */
|
||||
/** The requested feature is not available. */
|
||||
#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
|
||||
/** Verification of the message MAC failed. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
|
||||
/** An invalid SSL record was received. */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
|
||||
/** The connection indicated an EOF. */
|
||||
#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
|
||||
/** An unknown cipher was received. */
|
||||
#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300
|
||||
/** The server has no ciphersuites in common with the client. */
|
||||
#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
|
||||
/** No RNG was provided to the SSL module. */
|
||||
#define MBEDTLS_ERR_SSL_NO_RNG -0x7400
|
||||
/** No client certification received from the client, but required by the authentication mode. */
|
||||
#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
|
||||
/** Our own certificate(s) is/are too large to send in an SSL message. */
|
||||
#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
|
||||
/** The own certificate is not set, but needed by the server. */
|
||||
#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
|
||||
/** The own private key or pre-shared key is not set, but needed. */
|
||||
#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
|
||||
/** No CA Chain is set, but required to operate. */
|
||||
#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
|
||||
/** An unexpected message was received from our peer. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
|
||||
/** A fatal alert message was received from our peer. */
|
||||
#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
|
||||
/** Verification of our peer failed. */
|
||||
#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800
|
||||
/** The peer notified us that the connection is going to be closed. */
|
||||
#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
|
||||
/** Processing of the ClientHello handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
|
||||
/** Processing of the ServerHello handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
|
||||
/** Processing of the Certificate handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
|
||||
/** Processing of the CertificateRequest handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
|
||||
/** Processing of the ServerKeyExchange handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
|
||||
/** Processing of the ServerHelloDone handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
|
||||
/** Processing of the ClientKeyExchange handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
|
||||
/** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
|
||||
/** Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
|
||||
/** Processing of the CertificateVerify handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
|
||||
/** Processing of the ChangeCipherSpec handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
|
||||
/** Processing of the Finished handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80
|
||||
/** Memory allocation failed */
|
||||
#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
|
||||
/** Hardware acceleration function returned with error */
|
||||
#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
|
||||
/** Hardware acceleration function skipped / left alone data */
|
||||
#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
|
||||
/** Processing of the compression / decompression failed */
|
||||
#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00
|
||||
/** Handshake protocol not within min/max boundaries */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
|
||||
/** Processing of the NewSessionTicket handshake message failed. */
|
||||
#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
|
||||
/** Session ticket has expired. */
|
||||
#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
|
||||
/** Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
|
||||
#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
|
||||
/** Unknown identity received (eg, PSK identity) */
|
||||
#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
|
||||
/** Internal error (eg, unexpected failure in lower-level module) */
|
||||
#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
|
||||
/** A counter would wrap (eg, too many messages exchanged). */
|
||||
#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
|
||||
/** Unexpected message at ServerHello in renegotiation. */
|
||||
#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
|
||||
/** DTLS client must retry for hello verification */
|
||||
#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
|
||||
/** A buffer is too small to receive or write a message */
|
||||
#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
|
||||
/** None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
|
||||
#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980
|
||||
/** No data of requested type currently available on underlying transport. */
|
||||
#define MBEDTLS_ERR_SSL_WANT_READ -0x6900
|
||||
/** Connection requires a write call. */
|
||||
#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
|
||||
/** The operation timed out. */
|
||||
#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
|
||||
/** The client initiated a reconnect from the same port. */
|
||||
#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
|
||||
/** Record header looks valid but is not expected. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700
|
||||
/** The alert message received indicates a non-fatal error. */
|
||||
#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680
|
||||
/** Couldn't set the hash for verifying CertificateVerify */
|
||||
#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600
|
||||
/** Internal-only message signaling that further message-processing should be done */
|
||||
#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580
|
||||
/** The asynchronous operation is not completed yet. */
|
||||
#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500
|
||||
/** Internal-only message signaling that a message arrived early. */
|
||||
#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480
|
||||
/** An encrypted DTLS-frame with an unexpected CID was received. */
|
||||
#define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000
|
||||
/** An operation failed due to an unexpected version or configuration. */
|
||||
#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00
|
||||
/** A cryptographic operation is in progress. Try again later. */
|
||||
#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000
|
||||
/** Invalid value in SSL config */
|
||||
#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80
|
||||
|
||||
/*
|
||||
* Various constants
|
||||
@@ -412,8 +470,14 @@
|
||||
|
||||
/* The value of the CID extension is still TBD as of
|
||||
* draft-ietf-tls-dtls-connection-id-05
|
||||
* (https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05) */
|
||||
* (https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05).
|
||||
*
|
||||
* A future minor revision of Mbed TLS may change the default value of
|
||||
* this option to match evolving standards and usage.
|
||||
*/
|
||||
#if !defined(MBEDTLS_TLS_EXT_CID)
|
||||
#define MBEDTLS_TLS_EXT_CID 254 /* TBD */
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
|
||||
|
||||
@@ -536,10 +600,11 @@ typedef int mbedtls_ssl_send_t( void *ctx,
|
||||
* \param buf Buffer to write the received data to
|
||||
* \param len Length of the receive buffer
|
||||
*
|
||||
* \return The callback must return the number of bytes received,
|
||||
* or a non-zero error code.
|
||||
* If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
|
||||
* \returns If data has been received, the positive number of bytes received.
|
||||
* \returns \c 0 if the connection has been closed.
|
||||
* \returns If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
|
||||
* must be returned when the operation would block.
|
||||
* \returns Another negative error code on other kinds of failures.
|
||||
*
|
||||
* \note The callback may receive fewer bytes than the length of the
|
||||
* buffer. It must always return the number of bytes actually
|
||||
@@ -909,6 +974,10 @@ mbedtls_dtls_srtp_info;
|
||||
*/
|
||||
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)
|
||||
mbedtls_time_t start; /*!< starting time */
|
||||
#endif
|
||||
@@ -937,10 +1006,6 @@ struct mbedtls_ssl_session
|
||||
uint32_t ticket_lifetime; /*!< ticket lifetime hint */
|
||||
#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)
|
||||
int trunc_hmac; /*!< flag for truncated hmac activation */
|
||||
#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
|
||||
@@ -955,7 +1020,98 @@ struct mbedtls_ssl_session
|
||||
*/
|
||||
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
|
||||
@@ -1109,91 +1265,6 @@ struct mbedtls_ssl_config
|
||||
/*! number of supported profiles */
|
||||
size_t dtls_srtp_profile_list_len;
|
||||
#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
|
||||
@@ -2987,7 +3058,9 @@ void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
/**
|
||||
* \brief Set the allowed curves in order of preference.
|
||||
* (Default: all defined curves.)
|
||||
* (Default: all defined curves in order of decreasing size,
|
||||
* except that Montgomery curves come last. This order
|
||||
* is likely to change in a future version.)
|
||||
*
|
||||
* On server: this only affects selection of the ECDHE curve;
|
||||
* the curves used for ECDH and ECDSA are determined by the
|
||||
@@ -3019,7 +3092,9 @@ void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
||||
/**
|
||||
* \brief Set the allowed hashes for signatures during the handshake.
|
||||
* (Default: all available hashes except MD5.)
|
||||
* (Default: all SHA-2 hashes, largest first. Also SHA-1 if
|
||||
* the compile-time option
|
||||
* `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is enabled.)
|
||||
*
|
||||
* \note This only affects which hashes are offered and can be used
|
||||
* for signatures during the handshake. Hashes for message
|
||||
@@ -4327,7 +4402,7 @@ void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
|
||||
/**
|
||||
* \brief TLS-PRF function for key derivation.
|
||||
*
|
||||
* \param prf The tls_prf type funtion type to be used.
|
||||
* \param prf The tls_prf type function type to be used.
|
||||
* \param secret Secret for the key derivation function.
|
||||
* \param slen Length of the secret.
|
||||
* \param label String label for the key derivation function,
|
||||
@@ -4337,7 +4412,7 @@ void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
|
||||
* \param dstbuf The buffer holding the derived key.
|
||||
* \param dlen Length of the output buffer.
|
||||
*
|
||||
* \return 0 on sucess. An SSL specific error on failure.
|
||||
* \return 0 on success. An SSL specific error on failure.
|
||||
*/
|
||||
int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf,
|
||||
const unsigned char *secret, size_t slen,
|
||||
|
||||
+98
-99
@@ -275,26 +275,26 @@
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
||||
static inline uint32_t mbedtls_ssl_get_output_buflen( const mbedtls_ssl_context *ctx )
|
||||
static inline size_t mbedtls_ssl_get_output_buflen( const mbedtls_ssl_context *ctx )
|
||||
{
|
||||
#if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
return (uint32_t) mbedtls_ssl_get_output_max_frag_len( ctx )
|
||||
return mbedtls_ssl_get_output_max_frag_len( ctx )
|
||||
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
|
||||
+ MBEDTLS_SSL_CID_OUT_LEN_MAX;
|
||||
#else
|
||||
return (uint32_t) mbedtls_ssl_get_output_max_frag_len( ctx )
|
||||
return mbedtls_ssl_get_output_max_frag_len( ctx )
|
||||
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t mbedtls_ssl_get_input_buflen( const mbedtls_ssl_context *ctx )
|
||||
static inline size_t mbedtls_ssl_get_input_buflen( const mbedtls_ssl_context *ctx )
|
||||
{
|
||||
#if defined (MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
return (uint32_t) mbedtls_ssl_get_input_max_frag_len( ctx )
|
||||
return mbedtls_ssl_get_input_max_frag_len( ctx )
|
||||
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
|
||||
+ MBEDTLS_SSL_CID_IN_LEN_MAX;
|
||||
#else
|
||||
return (uint32_t) mbedtls_ssl_get_input_max_frag_len( ctx )
|
||||
return mbedtls_ssl_get_input_max_frag_len( ctx )
|
||||
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
|
||||
#endif
|
||||
}
|
||||
@@ -430,13 +430,63 @@ struct mbedtls_ssl_handshake_params
|
||||
* Handshake specific crypto variables
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
||||
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) && \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
||||
mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
|
||||
#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)
|
||||
mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
* 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 */
|
||||
#endif
|
||||
#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)
|
||||
const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
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 */
|
||||
size_t psk_len; /*!< Length of PSK from callback */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
|
||||
#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_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
|
||||
mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
|
||||
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
||||
int ecrs_enabled; /*!< Handshake supports EC restart? */
|
||||
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
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
|
||||
#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
|
||||
{
|
||||
size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
|
||||
@@ -557,6 +570,37 @@ struct mbedtls_ssl_handshake_params
|
||||
|
||||
} 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 */
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
@@ -565,8 +609,8 @@ struct mbedtls_ssl_handshake_params
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
mbedtls_md5_context fin_md5;
|
||||
mbedtls_sha1_context fin_sha1;
|
||||
mbedtls_md5_context fin_md5;
|
||||
mbedtls_sha1_context fin_sha1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
@@ -585,35 +629,10 @@ struct mbedtls_ssl_handshake_params
|
||||
#endif
|
||||
#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 premaster[MBEDTLS_PREMASTER_SIZE];
|
||||
/*!< 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)
|
||||
/** Asynchronous operation context. This field is meant for use by the
|
||||
* asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
|
||||
@@ -1212,26 +1231,6 @@ void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
|
||||
int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst,
|
||||
const mbedtls_ssl_session *src );
|
||||
|
||||
/* constant-time buffer comparison */
|
||||
static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
|
||||
{
|
||||
size_t i;
|
||||
volatile const unsigned char *A = (volatile const unsigned char *) a;
|
||||
volatile const unsigned char *B = (volatile const unsigned char *) b;
|
||||
volatile unsigned char diff = 0;
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
/* Read volatile data in order before computing diff.
|
||||
* This avoids IAR compiler warning:
|
||||
* 'the order of volatile accesses is undefined ..' */
|
||||
unsigned char x = A[i], y = B[i];
|
||||
diff |= x ^ y;
|
||||
}
|
||||
|
||||
return( diff );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||
int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl,
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
|
||||
* Recommended value: 86400 (one day).
|
||||
*
|
||||
* \note It is highly recommended to select a cipher that is at
|
||||
* least as strong as the the strongest ciphersuite
|
||||
* least as strong as the strongest ciphersuite
|
||||
* supported. Usually that means a 256-bit key.
|
||||
*
|
||||
* \note The lifetime of the keys is twice the lifetime of tickets.
|
||||
|
||||
+9
-3
@@ -36,16 +36,22 @@ extern "C" {
|
||||
|
||||
/* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be
|
||||
* used. */
|
||||
#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
|
||||
/** The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A
|
||||
|
||||
#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
|
||||
/** Bad input parameters to function. */
|
||||
#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C
|
||||
/** Locking / unlocking / free failed with error code. */
|
||||
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E
|
||||
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
#include <pthread.h>
|
||||
typedef struct mbedtls_threading_mutex_t
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
/* is_valid is 0 after a failed init or a free, and nonzero after a
|
||||
* successful init. This field is not considered part of the public
|
||||
* API of Mbed TLS and may change without notice. */
|
||||
char is_valid;
|
||||
} mbedtls_threading_mutex_t;
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -37,7 +37,7 @@
|
||||
* Major, Minor, Patchlevel
|
||||
*/
|
||||
#define MBEDTLS_VERSION_MAJOR 2
|
||||
#define MBEDTLS_VERSION_MINOR 25
|
||||
#define MBEDTLS_VERSION_MINOR 28
|
||||
#define MBEDTLS_VERSION_PATCH 0
|
||||
|
||||
/**
|
||||
@@ -45,9 +45,9 @@
|
||||
* MMNNPP00
|
||||
* Major version | Minor version | Patch version
|
||||
*/
|
||||
#define MBEDTLS_VERSION_NUMBER 0x02190000
|
||||
#define MBEDTLS_VERSION_STRING "2.25.0"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.25.0"
|
||||
#define MBEDTLS_VERSION_NUMBER 0x021C0000
|
||||
#define MBEDTLS_VERSION_STRING "2.28.0"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.28.0"
|
||||
|
||||
#if defined(MBEDTLS_VERSION_C)
|
||||
|
||||
|
||||
+40
-20
@@ -56,26 +56,46 @@
|
||||
* \name X509 Error codes
|
||||
* \{
|
||||
*/
|
||||
#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 /**< The CRT/CRL/CSR version element is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 /**< CRT/CRL/CSR has an unsupported version number. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */
|
||||
#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
|
||||
#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
|
||||
#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */
|
||||
#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */
|
||||
#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */
|
||||
#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 /**< Destination buffer is too small. */
|
||||
#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000 /**< A fatal error occurred, eg the chain is too long or the vrfy callback failed. */
|
||||
/** Unavailable feature, e.g. RSA hashing/encryption combination. */
|
||||
#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080
|
||||
/** Requested OID is unknown. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100
|
||||
/** The CRT/CRL/CSR format is invalid, e.g. different type expected. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180
|
||||
/** The CRT/CRL/CSR version element is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200
|
||||
/** The serial tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280
|
||||
/** The algorithm tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300
|
||||
/** The name tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380
|
||||
/** The date tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400
|
||||
/** The signature tag or value invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480
|
||||
/** The extension tag or value is invalid. */
|
||||
#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500
|
||||
/** CRT/CRL/CSR has an unsupported version number. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580
|
||||
/** Signature algorithm (oid) is unsupported. */
|
||||
#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600
|
||||
/** Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
|
||||
#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680
|
||||
/** Certificate verification failed, e.g. CRL, CA or signature check failed. */
|
||||
#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700
|
||||
/** Format not recognized as DER or PEM. */
|
||||
#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780
|
||||
/** Input invalid. */
|
||||
#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800
|
||||
/** Allocation of memory failed. */
|
||||
#define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880
|
||||
/** Read/write of file failed. */
|
||||
#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900
|
||||
/** Destination buffer is too small. */
|
||||
#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980
|
||||
/** A fatal error occurred, eg the chain is too long or the vrfy callback failed. */
|
||||
#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000
|
||||
/* \} name */
|
||||
|
||||
/**
|
||||
|
||||
+10
-1
@@ -263,12 +263,21 @@ typedef void mbedtls_x509_crt_restart_ctx;
|
||||
/**
|
||||
* Default security profile. Should provide a good balance between security
|
||||
* and compatibility with current deployments.
|
||||
*
|
||||
* This profile permits:
|
||||
* - SHA2 hashes.
|
||||
* - All supported elliptic curves.
|
||||
* - RSA with 2048 bits and above.
|
||||
*
|
||||
* New minor versions of Mbed TLS may extend this profile, for example if
|
||||
* new curves are added to the library. New minor versions of Mbed TLS will
|
||||
* not reduce this profile unless serious security concerns require it.
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
|
||||
|
||||
/**
|
||||
* Expected next default profile. Recommended for new deployments.
|
||||
* Currently targets a 128-bit security level, except for RSA-2048.
|
||||
* Currently targets a 128-bit security level, except for allowing RSA-2048.
|
||||
*/
|
||||
extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
|
||||
|
||||
|
||||
+4
-2
@@ -34,10 +34,12 @@
|
||||
#define MBEDTLS_XTEA_ENCRYPT 1
|
||||
#define MBEDTLS_XTEA_DECRYPT 0
|
||||
|
||||
#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
|
||||
/** The data input has an invalid length. */
|
||||
#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028
|
||||
|
||||
/* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
|
||||
#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
|
||||
/** XTEA hardware accelerator failed. */
|
||||
#define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+261
-56
@@ -90,10 +90,14 @@ extern "C" {
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
*/
|
||||
psa_status_t psa_crypto_init(void);
|
||||
|
||||
@@ -155,10 +159,10 @@ static void psa_set_key_id( psa_key_attributes_t *attributes,
|
||||
* the owner of a key.
|
||||
*
|
||||
* \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,
|
||||
mbedtls_key_owner_id_t owner_id );
|
||||
mbedtls_key_owner_id_t owner );
|
||||
#endif
|
||||
|
||||
/** Set the location of a persistent key.
|
||||
@@ -260,6 +264,14 @@ static psa_key_usage_t psa_get_key_usage_flags(
|
||||
* - An algorithm value permits this particular algorithm.
|
||||
* - An algorithm wildcard built from #PSA_ALG_ANY_HASH allows the specified
|
||||
* signature scheme with any hash algorithm.
|
||||
* - An algorithm built from #PSA_ALG_AT_LEAST_THIS_LENGTH_MAC allows
|
||||
* any MAC algorithm from the same base class (e.g. CMAC) which
|
||||
* generates/verifies a MAC length greater than or equal to the length
|
||||
* encoded in the wildcard algorithm.
|
||||
* - An algorithm built from #PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG
|
||||
* allows any AEAD algorithm from the same base class (e.g. CCM) which
|
||||
* generates/verifies a tag length greater than or equal to the length
|
||||
* encoded in the wildcard algorithm.
|
||||
*
|
||||
* This function overwrites any algorithm policy
|
||||
* previously set in \p attributes.
|
||||
@@ -368,6 +380,8 @@ static size_t psa_get_key_bits(const psa_key_attributes_t *attributes);
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
* It is implementation-dependent whether a failure to initialize
|
||||
@@ -501,6 +515,8 @@ psa_status_t psa_purge_key(mbedtls_svc_key_id_t key);
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
@@ -540,6 +556,10 @@ psa_status_t psa_copy_key(mbedtls_svc_key_id_t source_key,
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* There was an failure in communication with the cryptoprocessor.
|
||||
* The key material may still be present in the cryptoprocessor.
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* This error is typically a result of either storage corruption on a
|
||||
* cleartext storage backend, or an attempt to read data that was
|
||||
* written by an incompatible version of the library.
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* The storage is corrupted. Implementations shall make a best effort
|
||||
* to erase key material even in this stage, however applications
|
||||
@@ -625,6 +645,8 @@ psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key);
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
@@ -687,6 +709,8 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
|
||||
* For Weierstrass curves, this is the content of the `privateKey` field of
|
||||
* the `ECPrivateKey` format defined by RFC 5915. For Montgomery curves,
|
||||
* the format is defined by RFC 7748, and output is masked according to §5.
|
||||
* For twisted Edwards curves, the private key is as defined by RFC 8032
|
||||
* (a 32-byte string for Edwards25519, a 57-byte string for Edwards448).
|
||||
* - For Diffie-Hellman key exchange key pairs (key types for which
|
||||
* #PSA_KEY_TYPE_IS_DH_KEY_PAIR is true), the
|
||||
* format is the representation of the private key `x` as a big-endian byte
|
||||
@@ -713,7 +737,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p data buffer is too small. You can determine a
|
||||
* sufficient buffer size by calling
|
||||
* #PSA_KEY_EXPORT_MAX_SIZE(\c type, \c bits)
|
||||
* #PSA_EXPORT_KEY_OUTPUT_SIZE(\c type, \c bits)
|
||||
* where \c type is the key type
|
||||
* and \c bits is the key size in bits.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
@@ -752,7 +776,12 @@ psa_status_t psa_export_key(mbedtls_svc_key_id_t key,
|
||||
* modulus INTEGER, -- n
|
||||
* publicExponent INTEGER } -- e
|
||||
* ```
|
||||
* - For elliptic curve public keys (key types for which
|
||||
* - For elliptic curve keys on a twisted Edwards curve (key types for which
|
||||
* #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true and #PSA_KEY_TYPE_ECC_GET_FAMILY
|
||||
* returns #PSA_ECC_FAMILY_TWISTED_EDWARDS), the public key is as defined
|
||||
* by RFC 8032
|
||||
* (a 32-byte string for Edwards25519, a 57-byte string for Edwards448).
|
||||
* - For other elliptic curve public keys (key types for which
|
||||
* #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true), the format is the uncompressed
|
||||
* representation defined by SEC1 §2.3.3 as the content of an ECPoint.
|
||||
* Let `m` be the bit size associated with the curve, i.e. the bit size of
|
||||
@@ -783,7 +812,7 @@ psa_status_t psa_export_key(mbedtls_svc_key_id_t key,
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p data buffer is too small. You can determine a
|
||||
* sufficient buffer size by calling
|
||||
* #PSA_KEY_EXPORT_MAX_SIZE(#PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(\c type), \c bits)
|
||||
* #PSA_EXPORT_KEY_OUTPUT_SIZE(#PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(\c type), \c bits)
|
||||
* where \c type is the key type
|
||||
* and \c bits is the key size in bits.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
@@ -822,7 +851,7 @@ psa_status_t psa_export_public_key(mbedtls_svc_key_id_t key,
|
||||
* \param hash_size Size of the \p hash buffer in bytes.
|
||||
* \param[out] hash_length On success, the number of bytes
|
||||
* that make up the hash value. This is always
|
||||
* #PSA_HASH_SIZE(\p alg).
|
||||
* #PSA_HASH_LENGTH(\p alg).
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
@@ -1032,7 +1061,7 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation,
|
||||
* \param hash_size Size of the \p hash buffer in bytes.
|
||||
* \param[out] hash_length On success, the number of bytes
|
||||
* that make up the hash value. This is always
|
||||
* #PSA_HASH_SIZE(\c alg) where \c alg is the
|
||||
* #PSA_HASH_LENGTH(\c alg) where \c alg is the
|
||||
* hash algorithm that is calculated.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
@@ -1041,7 +1070,7 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation,
|
||||
* The operation state is not valid (it must be active).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p hash buffer is too small. You can determine a
|
||||
* sufficient buffer size by calling #PSA_HASH_SIZE(\c alg)
|
||||
* sufficient buffer size by calling #PSA_HASH_LENGTH(\c alg)
|
||||
* where \c alg is the hash algorithm that is calculated.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
@@ -1479,7 +1508,7 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
|
||||
* \param mac_size Size of the \p mac buffer in bytes.
|
||||
* \param[out] mac_length On success, the number of bytes
|
||||
* that make up the MAC value. This is always
|
||||
* #PSA_MAC_FINAL_SIZE(\c key_type, \c key_bits, \c alg)
|
||||
* #PSA_MAC_LENGTH(\c key_type, \c key_bits, \c alg)
|
||||
* where \c key_type and \c key_bits are the type and
|
||||
* bit-size respectively of the key and \c alg is the
|
||||
* MAC algorithm that is calculated.
|
||||
@@ -1491,7 +1520,7 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
|
||||
* operation).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p mac buffer is too small. You can determine a
|
||||
* sufficient buffer size by calling PSA_MAC_FINAL_SIZE().
|
||||
* sufficient buffer size by calling PSA_MAC_LENGTH().
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
@@ -2084,9 +2113,16 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
|
||||
* authentication tag is appended to the
|
||||
* encrypted data.
|
||||
* \param ciphertext_size Size of the \p ciphertext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg,
|
||||
* \p plaintext_length).
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type,
|
||||
* \p alg, \p plaintext_length) where
|
||||
* \c key_type is the type of \p key.
|
||||
* - #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p
|
||||
* plaintext_length) evaluates to the maximum
|
||||
* ciphertext size of any supported AEAD
|
||||
* encryption.
|
||||
* \param[out] ciphertext_length On success, the size of the output
|
||||
* in the \p ciphertext buffer.
|
||||
*
|
||||
@@ -2100,7 +2136,11 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
|
||||
* \p alg is not supported or is not an AEAD algorithm.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* \p ciphertext_size is too small
|
||||
* \p ciphertext_size is too small.
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, \p alg,
|
||||
* \p plaintext_length) or
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length) can be used to
|
||||
* determine the required buffer size.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
@@ -2144,9 +2184,16 @@ psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
|
||||
* \param ciphertext_length Size of \p ciphertext in bytes.
|
||||
* \param[out] plaintext Output buffer for the decrypted data.
|
||||
* \param plaintext_size Size of the \p plaintext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg,
|
||||
* \p ciphertext_length).
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type,
|
||||
* \p alg, \p ciphertext_length) where
|
||||
* \c key_type is the type of \p key.
|
||||
* - #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p
|
||||
* ciphertext_length) evaluates to the maximum
|
||||
* plaintext size of any supported AEAD
|
||||
* decryption.
|
||||
* \param[out] plaintext_length On success, the size of the output
|
||||
* in the \p plaintext buffer.
|
||||
*
|
||||
@@ -2162,7 +2209,11 @@ psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
|
||||
* \p alg is not supported or is not an AEAD algorithm.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* \p plaintext_size or \p nonce_length is too small
|
||||
* \p plaintext_size is too small.
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type, \p alg,
|
||||
* \p ciphertext_length) or
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length) can be used
|
||||
* to determine the required buffer size.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
@@ -2583,10 +2634,18 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
|
||||
* \param input_length Size of the \p input buffer in bytes.
|
||||
* \param[out] output Buffer where the output is to be written.
|
||||
* \param output_size Size of the \p output buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg,
|
||||
* \p input_length) where \c alg is the
|
||||
* algorithm that is being calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg, \p input_length) where
|
||||
* \c key_type is the type of key and \c alg is
|
||||
* the algorithm that were used to set up the
|
||||
* operation.
|
||||
* - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p
|
||||
* input_length) evaluates to the maximum
|
||||
* output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] output_length On success, the number of bytes
|
||||
* that make up the returned output.
|
||||
*
|
||||
@@ -2597,9 +2656,9 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
|
||||
* set, and have lengths set if required by the algorithm).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p output buffer is too small.
|
||||
* You can determine a sufficient buffer size by calling
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg, \p input_length)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to
|
||||
* determine the required buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
@@ -2636,9 +2695,7 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* This function has two output buffers:
|
||||
* - \p ciphertext contains trailing ciphertext that was buffered from
|
||||
* preceding calls to psa_aead_update().
|
||||
* - \p tag contains the authentication tag. Its length is always
|
||||
* #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is the AEAD algorithm
|
||||
* that the operation performs.
|
||||
* - \p tag contains the authentication tag.
|
||||
*
|
||||
* When this function returns successfuly, the operation becomes inactive.
|
||||
* If this function returns an error status, the operation enters an error
|
||||
@@ -2648,18 +2705,32 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* \param[out] ciphertext Buffer where the last part of the ciphertext
|
||||
* is to be written.
|
||||
* \param ciphertext_size Size of the \p ciphertext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg) where
|
||||
* \c alg is the algorithm that is being
|
||||
* calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg) where \c key_type is the type of key
|
||||
* and \c alg is the algorithm that were used to
|
||||
* set up the operation.
|
||||
* - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to
|
||||
* the maximum output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] ciphertext_length On success, the number of bytes of
|
||||
* returned ciphertext.
|
||||
* \param[out] tag Buffer where the authentication tag is
|
||||
* to be written.
|
||||
* \param tag_size Size of the \p tag buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is
|
||||
* the algorithm that is being calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c
|
||||
* key_type, \c key_bits, \c alg) where
|
||||
* \c key_type and \c key_bits are the type and
|
||||
* bit-size of the key, and \c alg is the
|
||||
* algorithm that were used in the call to
|
||||
* psa_aead_encrypt_setup().
|
||||
* - #PSA_AEAD_TAG_MAX_SIZE evaluates to the
|
||||
* maximum tag size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] tag_length On success, the number of bytes
|
||||
* that make up the returned tag.
|
||||
*
|
||||
@@ -2670,11 +2741,11 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* operation with a nonce set).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p ciphertext or \p tag buffer is too small.
|
||||
* You can determine a sufficient buffer size for \p ciphertext by
|
||||
* calling #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* You can determine a sufficient buffer size for \p tag by
|
||||
* calling #PSA_AEAD_TAG_LENGTH(\c alg).
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, \c alg) or
|
||||
* #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE can be used to determine the
|
||||
* required \p ciphertext buffer size. #PSA_AEAD_TAG_LENGTH(\c key_type,
|
||||
* \c key_bits, \c alg) or #PSA_AEAD_TAG_MAX_SIZE can be used to
|
||||
* determine the required \p tag buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
@@ -2733,10 +2804,15 @@ psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
|
||||
* that could not be processed until the end
|
||||
* of the input.
|
||||
* \param plaintext_size Size of the \p plaintext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg) where
|
||||
* \c alg is the algorithm that is being
|
||||
* calculated.
|
||||
* This must be appropriate for the selected algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg) where \c key_type is the type of key
|
||||
* and \c alg is the algorithm that were used to
|
||||
* set up the operation.
|
||||
* - #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE evaluates to
|
||||
* the maximum output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] plaintext_length On success, the number of bytes of
|
||||
* returned plaintext.
|
||||
* \param[in] tag Buffer containing the authentication tag.
|
||||
@@ -2752,9 +2828,9 @@ psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
|
||||
* operation with a nonce set).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p plaintext buffer is too small.
|
||||
* You can determine a sufficient buffer size for \p plaintext by
|
||||
* calling #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, \c alg) or
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE can be used to determine the
|
||||
* required buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
@@ -2813,19 +2889,139 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Sign a message with a private key. For hash-and-sign algorithms,
|
||||
* this includes the hashing step.
|
||||
*
|
||||
* \note To perform a multi-part hash-and-sign signature algorithm, first use
|
||||
* a multi-part hash operation and then pass the resulting hash to
|
||||
* psa_sign_hash(). PSA_ALG_GET_HASH(\p alg) can be used to determine the
|
||||
* hash algorithm to use.
|
||||
*
|
||||
* \param[in] key Identifier of the key to use for the operation.
|
||||
* It must be an asymmetric key pair. The key must
|
||||
* allow the usage #PSA_KEY_USAGE_SIGN_MESSAGE.
|
||||
* \param[in] alg An asymmetric signature algorithm (PSA_ALG_XXX
|
||||
* value such that #PSA_ALG_IS_SIGN_MESSAGE(\p alg)
|
||||
* is true), that is compatible with the type of
|
||||
* \p key.
|
||||
* \param[in] input The input message to sign.
|
||||
* \param[in] input_length Size of the \p input buffer in bytes.
|
||||
* \param[out] signature Buffer where the signature is to be written.
|
||||
* \param[in] signature_size Size of the \p signature buffer in bytes. This
|
||||
* must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - The required signature size is
|
||||
* #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
|
||||
* where \c key_type and \c key_bits are the type and
|
||||
* bit-size respectively of key.
|
||||
* - #PSA_SIGNATURE_MAX_SIZE evaluates to the
|
||||
* maximum signature size of any supported
|
||||
* signature algorithm.
|
||||
* \param[out] signature_length On success, the number of bytes that make up
|
||||
* the returned signature value.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* \retval #PSA_ERROR_INVALID_HANDLE
|
||||
* \retval #PSA_ERROR_NOT_PERMITTED
|
||||
* The key does not have the #PSA_KEY_USAGE_SIGN_MESSAGE flag,
|
||||
* or it does not permit the requested algorithm.
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p signature buffer is too small. You can
|
||||
* determine a sufficient buffer size by calling
|
||||
* #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
|
||||
* where \c key_type and \c key_bits are the type and bit-size
|
||||
* respectively of \p key.
|
||||
* \retval #PSA_ERROR_NOT_SUPPORTED
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
* It is implementation-dependent whether a failure to initialize
|
||||
* results in this error code.
|
||||
*/
|
||||
psa_status_t psa_sign_message( mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t * input,
|
||||
size_t input_length,
|
||||
uint8_t * signature,
|
||||
size_t signature_size,
|
||||
size_t * signature_length );
|
||||
|
||||
/** \brief Verify the signature of a message with a public key, using
|
||||
* a hash-and-sign verification algorithm.
|
||||
*
|
||||
* \note To perform a multi-part hash-and-sign signature verification
|
||||
* algorithm, first use a multi-part hash operation to hash the message
|
||||
* and then pass the resulting hash to psa_verify_hash().
|
||||
* PSA_ALG_GET_HASH(\p alg) can be used to determine the hash algorithm
|
||||
* to use.
|
||||
*
|
||||
* \param[in] key Identifier of the key to use for the operation.
|
||||
* It must be a public key or an asymmetric key
|
||||
* pair. The key must allow the usage
|
||||
* #PSA_KEY_USAGE_VERIFY_MESSAGE.
|
||||
* \param[in] alg An asymmetric signature algorithm (PSA_ALG_XXX
|
||||
* value such that #PSA_ALG_IS_SIGN_MESSAGE(\p alg)
|
||||
* is true), that is compatible with the type of
|
||||
* \p key.
|
||||
* \param[in] input The message whose signature is to be verified.
|
||||
* \param[in] input_length Size of the \p input buffer in bytes.
|
||||
* \param[out] signature Buffer containing the signature to verify.
|
||||
* \param[in] signature_length Size of the \p signature buffer in bytes.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* \retval #PSA_ERROR_INVALID_HANDLE
|
||||
* \retval #PSA_ERROR_NOT_PERMITTED
|
||||
* The key does not have the #PSA_KEY_USAGE_SIGN_MESSAGE flag,
|
||||
* or it does not permit the requested algorithm.
|
||||
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
||||
* The calculation was performed successfully, but the passed signature
|
||||
* is not a valid signature.
|
||||
* \retval #PSA_ERROR_NOT_SUPPORTED
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
* It is implementation-dependent whether a failure to initialize
|
||||
* results in this error code.
|
||||
*/
|
||||
psa_status_t psa_verify_message( mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t * input,
|
||||
size_t input_length,
|
||||
const uint8_t * signature,
|
||||
size_t signature_length );
|
||||
|
||||
/**
|
||||
* \brief Sign a hash or short message with a private key.
|
||||
*
|
||||
* Note that to perform a hash-and-sign signature algorithm, you must
|
||||
* first calculate the hash by calling psa_hash_setup(), psa_hash_update()
|
||||
* and psa_hash_finish(). Then pass the resulting hash as the \p hash
|
||||
* and psa_hash_finish(), or alternatively by calling psa_hash_compute().
|
||||
* Then pass the resulting hash as the \p hash
|
||||
* parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
|
||||
* to determine the hash algorithm to use.
|
||||
*
|
||||
* \param key Identifier of the key to use for the operation.
|
||||
* It must be an asymmetric key pair. The key must
|
||||
* allow the usage #PSA_KEY_USAGE_SIGN_HASH.
|
||||
* \param alg A signature algorithm that is compatible with
|
||||
* \param alg A signature algorithm (PSA_ALG_XXX
|
||||
* value such that #PSA_ALG_IS_SIGN_HASH(\p alg)
|
||||
* is true), that is compatible with
|
||||
* the type of \p key.
|
||||
* \param[in] hash The hash or message to sign.
|
||||
* \param hash_length Size of the \p hash buffer in bytes.
|
||||
@@ -2865,11 +3061,12 @@ psa_status_t psa_sign_hash(mbedtls_svc_key_id_t key,
|
||||
size_t *signature_length);
|
||||
|
||||
/**
|
||||
* \brief Verify the signature a hash or short message using a public key.
|
||||
* \brief Verify the signature of a hash or short message using a public key.
|
||||
*
|
||||
* Note that to perform a hash-and-sign signature algorithm, you must
|
||||
* first calculate the hash by calling psa_hash_setup(), psa_hash_update()
|
||||
* and psa_hash_finish(). Then pass the resulting hash as the \p hash
|
||||
* and psa_hash_finish(), or alternatively by calling psa_hash_compute().
|
||||
* Then pass the resulting hash as the \p hash
|
||||
* parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
|
||||
* to determine the hash algorithm to use.
|
||||
*
|
||||
@@ -2877,7 +3074,9 @@ psa_status_t psa_sign_hash(mbedtls_svc_key_id_t key,
|
||||
* must be a public key or an asymmetric key pair. The
|
||||
* key must allow the usage
|
||||
* #PSA_KEY_USAGE_VERIFY_HASH.
|
||||
* \param alg A signature algorithm that is compatible with
|
||||
* \param alg A signature algorithm (PSA_ALG_XXX
|
||||
* value such that #PSA_ALG_IS_SIGN_HASH(\p alg)
|
||||
* is true), that is compatible with
|
||||
* the type of \p key.
|
||||
* \param[in] hash The hash or message whose signature is to be
|
||||
* verified.
|
||||
@@ -3443,7 +3642,8 @@ psa_status_t psa_key_derivation_output_bytes(
|
||||
* state and must be aborted by calling psa_key_derivation_abort().
|
||||
*
|
||||
* How much output is produced and consumed from the operation, and how
|
||||
* the key is derived, depends on the key type:
|
||||
* the key is derived, depends on the key type and on the key size
|
||||
* (denoted \c bits below):
|
||||
*
|
||||
* - For key types for which the key is an arbitrary sequence of bytes
|
||||
* of a given size, this function is functionally equivalent to
|
||||
@@ -3453,11 +3653,12 @@ psa_status_t psa_key_derivation_output_bytes(
|
||||
* if the implementation provides an isolation boundary then
|
||||
* the key material is not exposed outside the isolation boundary.
|
||||
* As a consequence, for these key types, this function always consumes
|
||||
* exactly (\p bits / 8) bytes from the operation.
|
||||
* exactly (\c bits / 8) bytes from the operation.
|
||||
* The following key types defined in this specification follow this scheme:
|
||||
*
|
||||
* - #PSA_KEY_TYPE_AES;
|
||||
* - #PSA_KEY_TYPE_ARC4;
|
||||
* - #PSA_KEY_TYPE_ARIA;
|
||||
* - #PSA_KEY_TYPE_CAMELLIA;
|
||||
* - #PSA_KEY_TYPE_DERIVE;
|
||||
* - #PSA_KEY_TYPE_HMAC.
|
||||
@@ -3474,8 +3675,8 @@ psa_status_t psa_key_derivation_output_bytes(
|
||||
* string and process it as specified in RFC 7748 §5.
|
||||
*
|
||||
* - For key types for which the key is represented by a single sequence of
|
||||
* \p bits bits with constraints as to which bit sequences are acceptable,
|
||||
* this function draws a byte string of length (\p bits / 8) bytes rounded
|
||||
* \c bits bits with constraints as to which bit sequences are acceptable,
|
||||
* this function draws a byte string of length (\c bits / 8) bytes rounded
|
||||
* up to the nearest whole number of bytes. If the resulting byte string
|
||||
* is acceptable, it becomes the key, otherwise the drawn bytes are discarded.
|
||||
* This process is repeated until an acceptable byte string is drawn.
|
||||
@@ -3556,6 +3757,8 @@ psa_status_t psa_key_derivation_output_bytes(
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
@@ -3721,6 +3924,8 @@ psa_status_t psa_generate_random(uint8_t *output,
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
|
||||
@@ -1,823 +0,0 @@
|
||||
/**
|
||||
* \file psa/crypto_accel_driver.h
|
||||
* \brief PSA cryptography accelerator driver module
|
||||
*
|
||||
* This header declares types and function signatures for cryptography
|
||||
* drivers that access key material directly. This is meant for
|
||||
* on-chip cryptography accelerators.
|
||||
*
|
||||
* This file is part of the PSA Crypto Driver Model, containing functions for
|
||||
* driver developers to implement to enable hardware to be called in a
|
||||
* standardized way by a PSA Cryptographic API implementation. The functions
|
||||
* comprising the driver model, which driver authors implement, are not
|
||||
* intended to be called by application developers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 PSA_CRYPTO_ACCEL_DRIVER_H
|
||||
#define PSA_CRYPTO_ACCEL_DRIVER_H
|
||||
|
||||
#include "crypto_driver_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup driver_digest Hardware-Accelerated Message Digests
|
||||
*
|
||||
* Generation and authentication of Message Digests (aka hashes) must be done
|
||||
* in parts using the following sequence:
|
||||
* - `psa_drv_hash_setup_t`
|
||||
* - `psa_drv_hash_update_t`
|
||||
* - `psa_drv_hash_update_t`
|
||||
* - ...
|
||||
* - `psa_drv_hash_finish_t`
|
||||
*
|
||||
* If a previously started Message Digest operation needs to be terminated
|
||||
* before the `psa_drv_hash_finish_t` operation is complete, it should be aborted
|
||||
* by the `psa_drv_hash_abort_t`. Failure to do so may result in allocated
|
||||
* resources not being freed or in other undefined behavior.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief The hardware-specific hash context structure
|
||||
*
|
||||
* The contents of this structure are implementation dependent and are
|
||||
* therefore not described here
|
||||
*/
|
||||
typedef struct psa_drv_hash_context_s psa_drv_hash_context_t;
|
||||
|
||||
/** \brief The function prototype for the start operation of a hash (message
|
||||
* digest) operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_hash_<ALGO>_setup
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying hash function
|
||||
*
|
||||
* \param[in,out] p_context A structure that will contain the
|
||||
* hardware-specific hash context
|
||||
*
|
||||
* \retval #PSA_SUCCESS Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context);
|
||||
|
||||
/** \brief The function prototype for the update operation of a hash (message
|
||||
* digest) operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_hash_<ALGO>_update
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously-established hash operation to be
|
||||
* continued
|
||||
* \param[in] p_input A buffer containing the message to be appended
|
||||
* to the hash operation
|
||||
* \param[in] input_length The size in bytes of the input message buffer
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length);
|
||||
|
||||
/** \brief The function prototype for the finish operation of a hash (message
|
||||
* digest) operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_hash_<ALGO>_finish
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started hash operation to be
|
||||
* fiinished
|
||||
* \param[out] p_output A buffer where the generated digest will be
|
||||
* placed
|
||||
* \param[in] output_size The size in bytes of the buffer that has been
|
||||
* allocated for the `p_output` buffer
|
||||
* \param[out] p_output_length The number of bytes placed in `p_output` after
|
||||
* success
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
|
||||
/** \brief The function prototype for the abort operation of a hash (message
|
||||
* digest) operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_hash_<ALGO>_abort
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the previously
|
||||
* started hash operation to be aborted
|
||||
*/
|
||||
typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup accel_mac Hardware-Accelerated Message Authentication Code
|
||||
* Generation and authentication of Message Authentication Codes (MACs) using
|
||||
* cryptographic accelerators can be done either as a single function call (via the
|
||||
* `psa_drv_accel_mac_generate_t` or `psa_drv_accel_mac_verify_t`
|
||||
* functions), or in parts using the following sequence:
|
||||
* - `psa_drv_accel_mac_setup_t`
|
||||
* - `psa_drv_accel_mac_update_t`
|
||||
* - `psa_drv_accel_mac_update_t`
|
||||
* - ...
|
||||
* - `psa_drv_accel_mac_finish_t` or `psa_drv_accel_mac_finish_verify_t`
|
||||
*
|
||||
* If a previously started MAC operation needs to be terminated, it
|
||||
* should be done so by the `psa_drv_accel_mac_abort_t`. Failure to do so may
|
||||
* result in allocated resources not being freed or in other undefined
|
||||
* behavior.
|
||||
*
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief The hardware-accelerator-specific MAC context structure
|
||||
*
|
||||
* The contents of this structure are implementation dependent and are
|
||||
* therefore not described here.
|
||||
*/
|
||||
typedef struct psa_drv_accel_mac_context_s psa_drv_accel_mac_context_t;
|
||||
|
||||
/** \brief The function prototype for the setup operation of a
|
||||
* hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_setup
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT`
|
||||
* is the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in,out] p_context A structure that will contain the
|
||||
* hardware-specific MAC context
|
||||
* \param[in] p_key A buffer containing the cleartext key material
|
||||
* to be used in the operation
|
||||
* \param[in] key_length The size in bytes of the key material
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_setup_t)(psa_drv_accel_mac_context_t *p_context,
|
||||
const uint8_t *p_key,
|
||||
size_t key_length);
|
||||
|
||||
/** \brief The function prototype for the update operation of a
|
||||
* hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_update
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT`
|
||||
* is the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously-established MAC operation to be
|
||||
* continued
|
||||
* \param[in] p_input A buffer containing the message to be appended
|
||||
* to the MAC operation
|
||||
* \param[in] input_length The size in bytes of the input message buffer
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_update_t)(psa_drv_accel_mac_context_t *p_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length);
|
||||
|
||||
/** \brief The function prototype for the finish operation of a
|
||||
* hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_finish
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
|
||||
* the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started MAC operation to be
|
||||
* finished
|
||||
* \param[out] p_mac A buffer where the generated MAC will be placed
|
||||
* \param[in] mac_length The size in bytes of the buffer that has been
|
||||
* allocated for the `p_mac` buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_finish_t)(psa_drv_accel_mac_context_t *p_context,
|
||||
uint8_t *p_mac,
|
||||
size_t mac_length);
|
||||
|
||||
/** \brief The function prototype for the finish and verify operation of a
|
||||
* hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_finish_verify
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
|
||||
* the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started MAC operation to be
|
||||
* verified and finished
|
||||
* \param[in] p_mac A buffer containing the MAC that will be used
|
||||
* for verification
|
||||
* \param[in] mac_length The size in bytes of the data in the `p_mac`
|
||||
* buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The operation completed successfully and the comparison matched
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_finish_verify_t)(psa_drv_accel_mac_context_t *p_context,
|
||||
const uint8_t *p_mac,
|
||||
size_t mac_length);
|
||||
|
||||
/** \brief The function prototype for the abort operation for a previously
|
||||
* started hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_abort
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
|
||||
* the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started MAC operation to be
|
||||
* aborted
|
||||
*
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_abort_t)(psa_drv_accel_mac_context_t *p_context);
|
||||
|
||||
/** \brief The function prototype for the one-shot operation of a
|
||||
* hardware-accelerated MAC operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
|
||||
* the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in] p_input A buffer containing the data to be MACed
|
||||
* \param[in] input_length The length in bytes of the `p_input` data
|
||||
* \param[in] p_key A buffer containing the key material to be used
|
||||
* for the MAC operation
|
||||
* \param[in] key_length The length in bytes of the `p_key` data
|
||||
* \param[in] alg The algorithm to be performed
|
||||
* \param[out] p_mac The buffer where the resulting MAC will be placed
|
||||
* upon success
|
||||
* \param[in] mac_length The length in bytes of the `p_mac` buffer
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_t)(const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
const uint8_t *p_key,
|
||||
size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
uint8_t *p_mac,
|
||||
size_t mac_length);
|
||||
|
||||
/** \brief The function prototype for the one-shot hardware-accelerated MAC
|
||||
* Verify operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_mac_<ALGO>_<MAC_VARIANT>_verify
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
|
||||
* the specific variant of a MAC operation (such as HMAC or CMAC)
|
||||
*
|
||||
* \param[in] p_input A buffer containing the data to be MACed
|
||||
* \param[in] input_length The length in bytes of the `p_input` data
|
||||
* \param[in] p_key A buffer containing the key material to be used
|
||||
* for the MAC operation
|
||||
* \param[in] key_length The length in bytes of the `p_key` data
|
||||
* \param[in] alg The algorithm to be performed
|
||||
* \param[in] p_mac The MAC data to be compared
|
||||
* \param[in] mac_length The length in bytes of the `p_mac` buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The operation completed successfully and the comparison matched
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_mac_verify_t)(const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
const uint8_t *p_key,
|
||||
size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *p_mac,
|
||||
size_t mac_length);
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup accel_cipher Hardware-Accelerated Block Ciphers
|
||||
* Encryption and Decryption using hardware-acceleration in block modes other
|
||||
* than ECB must be done in multiple parts, using the following flow:
|
||||
* - `psa_drv_accel_ciphersetup_t`
|
||||
* - `psa_drv_accel_cipher_set_iv_t` (optional depending upon block mode)
|
||||
* - `psa_drv_accel_cipher_update_t`
|
||||
* - `psa_drv_accel_cipher_update_t`
|
||||
* - ...
|
||||
* - `psa_drv_accel_cipher_finish_t`
|
||||
*
|
||||
* If a previously started hardware-accelerated Cipher operation needs to be
|
||||
* terminated, it should be done so by the `psa_drv_accel_cipher_abort_t`.
|
||||
* Failure to do so may result in allocated resources not being freed or in
|
||||
* other undefined behavior.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief The hardware-accelerator-specific cipher context structure
|
||||
*
|
||||
* The contents of this structure are implementation dependent and are
|
||||
* therefore not described here.
|
||||
*/
|
||||
typedef struct psa_drv_accel_cipher_context_s psa_drv_accel_cipher_context_t;
|
||||
|
||||
/** \brief The function prototype for the setup operation of
|
||||
* hardware-accelerated block cipher operations.
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* conventions:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_setup_<CIPHER_NAME>_<MODE>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where
|
||||
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
|
||||
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
|
||||
*
|
||||
* For stream ciphers:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_setup_<CIPHER_NAME>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4)
|
||||
*
|
||||
* \param[in,out] p_context A structure that will contain the
|
||||
* hardware-specific cipher context
|
||||
* \param[in] direction Indicates if the operation is an encrypt or a
|
||||
* decrypt
|
||||
* \param[in] p_key_data A buffer containing the cleartext key material
|
||||
* to be used in the operation
|
||||
* \param[in] key_data_size The size in bytes of the key material
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_cipher_setup_t)(psa_drv_accel_cipher_context_t *p_context,
|
||||
psa_encrypt_or_decrypt_t direction,
|
||||
const uint8_t *p_key_data,
|
||||
size_t key_data_size);
|
||||
|
||||
/** \brief The function prototype for the set initialization vector operation
|
||||
* of hardware-accelerated block cipher operations
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_set_iv_<CIPHER_NAME>_<MODE>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where
|
||||
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
|
||||
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
|
||||
*
|
||||
* \param[in,out] p_context A structure that contains the previously setup
|
||||
* hardware-specific cipher context
|
||||
* \param[in] p_iv A buffer containing the initialization vecotr
|
||||
* \param[in] iv_length The size in bytes of the contents of `p_iv`
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_cipher_set_iv_t)(psa_drv_accel_cipher_context_t *p_context,
|
||||
const uint8_t *p_iv,
|
||||
size_t iv_length);
|
||||
|
||||
/** \brief The function prototype for the update operation of
|
||||
* hardware-accelerated block cipher operations.
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_update_<CIPHER_NAME>_<MODE>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where
|
||||
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
|
||||
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
* \param[in] p_input A buffer containing the data to be
|
||||
* encrypted or decrypted
|
||||
* \param[in] input_size The size in bytes of the `p_input` buffer
|
||||
* \param[out] p_output A caller-allocated buffer where the
|
||||
* generated output will be placed
|
||||
* \param[in] output_size The size in bytes of the `p_output` buffer
|
||||
* \param[out] p_output_length After completion, will contain the number
|
||||
* of bytes placed in the `p_output` buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_cipher_update_t)(psa_drv_accel_cipher_context_t *p_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_size,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
|
||||
/** \brief The function prototype for the finish operation of
|
||||
* hardware-accelerated block cipher operations.
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_finish_<CIPHER_NAME>_<MODE>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where
|
||||
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
|
||||
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
* \param[out] p_output A caller-allocated buffer where the generated
|
||||
* output will be placed
|
||||
* \param[in] output_size The size in bytes of the `p_output` buffer
|
||||
* \param[out] p_output_length After completion, will contain the number of
|
||||
* bytes placed in the `p_output` buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_cipher_finish_t)(psa_drv_accel_cipher_context_t *p_context,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
|
||||
/** \brief The function prototype for the abort operation of
|
||||
* hardware-accelerated block cipher operations.
|
||||
*
|
||||
* Functions that implement the following prototype should be named in the
|
||||
* following convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_cipher_abort_<CIPHER_NAME>_<MODE>
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where
|
||||
* - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
|
||||
* - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_cipher_abort_t)(psa_drv_accel_cipher_context_t *p_context);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup accel_aead Hardware-Accelerated Authenticated Encryption with Additional Data
|
||||
*
|
||||
* Hardware-accelerated Authenticated Encryption with Additional Data (AEAD)
|
||||
* operations must be done in one function call. While this creates a burden
|
||||
* for implementers as there must be sufficient space in memory for the entire
|
||||
* message, it prevents decrypted data from being made available before the
|
||||
* authentication operation is complete and the data is known to be authentic.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief The function prototype for the hardware-accelerated authenticated
|
||||
* encryption operation.
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_aead_<ALGO>_encrypt
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the AEAD algorithm
|
||||
*
|
||||
* \param[in] p_key A pointer to the key material
|
||||
* \param[in] key_length The size in bytes of the key material
|
||||
* \param[in] alg The AEAD algorithm to compute
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(`alg`) is true)
|
||||
* \param[in] nonce Nonce or IV to use
|
||||
* \param[in] nonce_length Size of the `nonce` buffer in bytes
|
||||
* \param[in] additional_data Additional data that will be MACed
|
||||
* but not encrypted.
|
||||
* \param[in] additional_data_length Size of `additional_data` in bytes
|
||||
* \param[in] plaintext Data that will be MACed and
|
||||
* encrypted.
|
||||
* \param[in] plaintext_length Size of `plaintext` in bytes
|
||||
* \param[out] ciphertext Output buffer for the authenticated and
|
||||
* encrypted data. The additional data is
|
||||
* not part of this output. For algorithms
|
||||
* where the encrypted data and the
|
||||
* authentication tag are defined as
|
||||
* separate outputs, the authentication
|
||||
* tag is appended to the encrypted data.
|
||||
* \param[in] ciphertext_size Size of the `ciphertext` buffer in
|
||||
* bytes
|
||||
* This must be at least
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`,
|
||||
* `plaintext_length`).
|
||||
* \param[out] ciphertext_length On success, the size of the output in
|
||||
* the `ciphertext` buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_aead_encrypt_t)(const uint8_t *p_key,
|
||||
size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *nonce,
|
||||
size_t nonce_length,
|
||||
const uint8_t *additional_data,
|
||||
size_t additional_data_length,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_length,
|
||||
uint8_t *ciphertext,
|
||||
size_t ciphertext_size,
|
||||
size_t *ciphertext_length);
|
||||
|
||||
/** \brief The function prototype for the hardware-accelerated authenticated
|
||||
* decryption operation.
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_aead_<ALGO>_decrypt
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the AEAD algorithm
|
||||
* \param[in] p_key A pointer to the key material
|
||||
* \param[in] key_length The size in bytes of the key material
|
||||
* \param[in] alg The AEAD algorithm to compute
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(`alg`) is true)
|
||||
* \param[in] nonce Nonce or IV to use
|
||||
* \param[in] nonce_length Size of the `nonce` buffer in bytes
|
||||
* \param[in] additional_data Additional data that has been MACed
|
||||
* but not encrypted
|
||||
* \param[in] additional_data_length Size of `additional_data` in bytes
|
||||
* \param[in] ciphertext Data that has been MACed and
|
||||
* encrypted
|
||||
* For algorithms where the encrypted data
|
||||
* and the authentication tag are defined
|
||||
* as separate inputs, the buffer must
|
||||
* contain the encrypted data followed by
|
||||
* the authentication tag.
|
||||
* \param[in] ciphertext_length Size of `ciphertext` in bytes
|
||||
* \param[out] plaintext Output buffer for the decrypted data
|
||||
* \param[in] plaintext_size Size of the `plaintext` buffer in
|
||||
* bytes
|
||||
* This must be at least
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`,
|
||||
* `ciphertext_length`).
|
||||
* \param[out] plaintext_length On success, the size of the output
|
||||
* in the \b plaintext buffer
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_aead_decrypt_t)(const uint8_t *p_key,
|
||||
size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *nonce,
|
||||
size_t nonce_length,
|
||||
const uint8_t *additional_data,
|
||||
size_t additional_data_length,
|
||||
const uint8_t *ciphertext,
|
||||
size_t ciphertext_length,
|
||||
uint8_t *plaintext,
|
||||
size_t plaintext_size,
|
||||
size_t *plaintext_length);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup accel_asymmetric Hardware-Accelerated Asymmetric Cryptography
|
||||
*
|
||||
* Since the amount of data that can (or should) be encrypted or signed using
|
||||
* asymmetric keys is limited by the key size, hardware-accelerated asymmetric
|
||||
* key operations must be done in single function calls.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
|
||||
/**
|
||||
* \brief The function prototype for the hardware-accelerated asymmetric sign
|
||||
* operation.
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_asymmetric_<ALGO>_sign
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the signing algorithm
|
||||
*
|
||||
* This function supports any asymmetric-key output from psa_export_key() as
|
||||
* the buffer in \p p_key. Refer to the documentation of \ref
|
||||
* psa_export_key() for the formats.
|
||||
*
|
||||
* \param[in] p_key A buffer containing the private key
|
||||
* material
|
||||
* \param[in] key_size The size in bytes of the `p_key` data
|
||||
* \param[in] alg A signature algorithm that is compatible
|
||||
* with the type of `p_key`
|
||||
* \param[in] p_hash The hash or message to sign
|
||||
* \param[in] hash_length Size of the `p_hash` buffer in bytes
|
||||
* \param[out] p_signature Buffer where the signature is to be written
|
||||
* \param[in] signature_size Size of the `p_signature` buffer in bytes
|
||||
* \param[out] p_signature_length On success, the number of bytes
|
||||
* that make up the returned signature value
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_asymmetric_sign_t)(const uint8_t *p_key,
|
||||
size_t key_size,
|
||||
psa_algorithm_t alg,
|
||||
psa_key_type_t key_type,
|
||||
const uint8_t *p_hash,
|
||||
size_t hash_length,
|
||||
uint8_t *p_signature,
|
||||
size_t signature_size,
|
||||
size_t *p_signature_length);
|
||||
|
||||
/**
|
||||
* \brief The function prototype for the hardware-accelerated signature verify
|
||||
* operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_asymmetric_<ALGO>_verify
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the signing algorithm
|
||||
*
|
||||
* This function supports any output from \ref psa_export_public_key() as the
|
||||
* buffer in \p p_key. Refer to the documentation of \ref
|
||||
* psa_export_public_key() for the format of public keys and to the
|
||||
* documentation of \ref psa_export_key() for the format for other key types.
|
||||
*
|
||||
* \param[in] p_key A buffer containing the public key material
|
||||
* \param[in] key_size The size in bytes of the `p_key` data
|
||||
* \param[in] alg A signature algorithm that is compatible with
|
||||
* the type of `key`
|
||||
* \param[in] p_hash The hash or message whose signature is to be
|
||||
* verified
|
||||
* \param[in] hash_length Size of the `p_hash` buffer in bytes
|
||||
* \param[in] p_signature Buffer containing the signature to verify
|
||||
* \param[in] signature_length Size of the `p_signature` buffer in bytes
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The signature is valid.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_asymmetric_verify_t)(const uint8_t *p_key,
|
||||
size_t key_size,
|
||||
psa_algorithm_t alg,
|
||||
psa_key_type_t key_type,
|
||||
const uint8_t *p_hash,
|
||||
size_t hash_length,
|
||||
const uint8_t *p_signature,
|
||||
size_t signature_length);
|
||||
|
||||
/**
|
||||
* \brief The function prototype for the hardware-accelerated asymmetric
|
||||
* encrypt operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_asymmetric_<ALGO>_encrypt
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the encryption algorithm
|
||||
*
|
||||
* This function supports any output from \ref psa_export_public_key() as the
|
||||
* buffer in \p p_key. Refer to the documentation of \ref
|
||||
* psa_export_public_key() for the format of public keys and to the
|
||||
* documentation of \ref psa_export_key() for the format for other key types.
|
||||
*
|
||||
* \param[in] p_key A buffer containing the public key material
|
||||
* \param[in] key_size The size in bytes of the `p_key` data
|
||||
* \param[in] alg An asymmetric encryption algorithm that is
|
||||
* compatible with the type of `key`
|
||||
* \param[in] p_input The message to encrypt
|
||||
* \param[in] input_length Size of the `p_input` buffer in bytes
|
||||
* \param[in] p_salt A salt or label, if supported by the
|
||||
* encryption algorithm
|
||||
* If the algorithm does not support a
|
||||
* salt, pass `NULL`
|
||||
* If the algorithm supports an optional
|
||||
* salt and you do not want to pass a salt,
|
||||
* pass `NULL`.
|
||||
* For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
||||
* supported.
|
||||
* \param[in] salt_length Size of the `p_salt` buffer in bytes
|
||||
* If `p_salt` is `NULL`, pass 0.
|
||||
* \param[out] p_output Buffer where the encrypted message is to
|
||||
* be written
|
||||
* \param[in] output_size Size of the `p_output` buffer in bytes
|
||||
* \param[out] p_output_length On success, the number of bytes
|
||||
* that make up the returned output
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_asymmetric_encrypt_t)(const uint8_t *p_key,
|
||||
size_t key_size,
|
||||
psa_algorithm_t alg,
|
||||
psa_key_type_t key_type,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
const uint8_t *p_salt,
|
||||
size_t salt_length,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
|
||||
/**
|
||||
* \brief The function prototype for the hardware=acce;erated asymmetric
|
||||
* decrypt operation
|
||||
*
|
||||
* Functions that implement this prototype should be named in the following
|
||||
* convention:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_accel_asymmetric_<ALGO>_decrypt
|
||||
* ~~~~~~~~~~~~~
|
||||
* Where `ALGO` is the name of the encryption algorithm
|
||||
*
|
||||
* This function supports any asymmetric-key output from psa_export_key() as
|
||||
* the buffer in \p p_key. Refer to the documentation of \ref
|
||||
* psa_export_key() for the formats.
|
||||
*
|
||||
* \param[in] p_key A buffer containing the private key material
|
||||
* \param[in] key_size The size in bytes of the `p_key` data
|
||||
* \param[in] alg An asymmetric encryption algorithm that is
|
||||
* compatible with the type of `key`
|
||||
* \param[in] p_input The message to decrypt
|
||||
* \param[in] input_length Size of the `p_input` buffer in bytes
|
||||
* \param[in] p_salt A salt or label, if supported by the
|
||||
* encryption algorithm
|
||||
* If the algorithm does not support a
|
||||
* salt, pass `NULL`.
|
||||
* If the algorithm supports an optional
|
||||
* salt and you do not want to pass a salt,
|
||||
* pass `NULL`.
|
||||
* For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
|
||||
* supported
|
||||
* \param[in] salt_length Size of the `p_salt` buffer in bytes
|
||||
* If `p_salt` is `NULL`, pass 0
|
||||
* \param[out] p_output Buffer where the decrypted message is to
|
||||
* be written
|
||||
* \param[in] output_size Size of the `p_output` buffer in bytes
|
||||
* \param[out] p_output_length On success, the number of bytes
|
||||
* that make up the returned output
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_accel_asymmetric_decrypt_t)(const uint8_t *p_key,
|
||||
size_t key_size,
|
||||
psa_algorithm_t alg,
|
||||
psa_key_type_t key_type,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
const uint8_t *p_salt,
|
||||
size_t salt_length,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PSA_CRYPTO_ACCEL_DRIVER_H */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Context structure declaration of the Mbed TLS software-based PSA drivers
|
||||
* called through the PSA Crypto driver dispatch layer.
|
||||
* This file contains the context structures of those algorithms which need to
|
||||
* rely on other algorithms, i.e. are 'composite' algorithms.
|
||||
*
|
||||
* \note This file may not be included directly. Applications must
|
||||
* include psa/crypto.h.
|
||||
*
|
||||
* \note This header and its content is not part of the Mbed TLS API and
|
||||
* applications must not depend on it. Its main purpose is to define the
|
||||
* multi-part state objects of the Mbed TLS software-based PSA drivers. The
|
||||
* definition of these objects are then used by crypto_struct.h to define the
|
||||
* implementation-defined types of PSA multi-part state objects.
|
||||
*/
|
||||
/*
|
||||
* 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 PSA_CRYPTO_BUILTIN_COMPOSITES_H
|
||||
#define PSA_CRYPTO_BUILTIN_COMPOSITES_H
|
||||
|
||||
#include <psa/crypto_driver_common.h>
|
||||
|
||||
/*
|
||||
* MAC multi-part operation definitions.
|
||||
*/
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC)
|
||||
#define MBEDTLS_PSA_BUILTIN_MAC
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
typedef struct
|
||||
{
|
||||
/** The HMAC algorithm in use */
|
||||
psa_algorithm_t alg;
|
||||
/** The hash context. */
|
||||
struct psa_hash_operation_s hash_ctx;
|
||||
/** The HMAC part of the context. */
|
||||
uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
|
||||
} mbedtls_psa_hmac_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_HMAC_OPERATION_INIT {0, PSA_HASH_OPERATION_INIT, {0}}
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||
|
||||
#include "mbedtls/cmac.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
psa_algorithm_t alg;
|
||||
union
|
||||
{
|
||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_psa_hmac_operation_t hmac;
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_cipher_context_t cmac;
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CMAC */
|
||||
} ctx;
|
||||
} mbedtls_psa_mac_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, {0}}
|
||||
|
||||
#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Context structure declaration of the Mbed TLS software-based PSA drivers
|
||||
* called through the PSA Crypto driver dispatch layer.
|
||||
* This file contains the context structures of those algorithms which do not
|
||||
* rely on other algorithms, i.e. are 'primitive' algorithms.
|
||||
*
|
||||
* \note This file may not be included directly. Applications must
|
||||
* include psa/crypto.h.
|
||||
*
|
||||
* \note This header and its content is not part of the Mbed TLS API and
|
||||
* applications must not depend on it. Its main purpose is to define the
|
||||
* multi-part state objects of the Mbed TLS software-based PSA drivers. The
|
||||
* definition of these objects are then used by crypto_struct.h to define the
|
||||
* implementation-defined types of PSA multi-part state objects.
|
||||
*/
|
||||
/*
|
||||
* 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 PSA_CRYPTO_BUILTIN_PRIMITIVES_H
|
||||
#define PSA_CRYPTO_BUILTIN_PRIMITIVES_H
|
||||
|
||||
#include <psa/crypto_driver_common.h>
|
||||
|
||||
/*
|
||||
* Hash multi-part operation definitions.
|
||||
*/
|
||||
|
||||
#include "mbedtls/md2.h"
|
||||
#include "mbedtls/md4.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_MD4) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_MD5) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512)
|
||||
#define MBEDTLS_PSA_BUILTIN_HASH
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
psa_algorithm_t alg;
|
||||
union
|
||||
{
|
||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD2)
|
||||
mbedtls_md2_context md2;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD4)
|
||||
mbedtls_md4_context md4;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_MD5)
|
||||
mbedtls_md5_context md5;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160)
|
||||
mbedtls_ripemd160_context ripemd160;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_1)
|
||||
mbedtls_sha1_context sha1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_256) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_224)
|
||||
mbedtls_sha256_context sha256;
|
||||
#endif
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_512) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_SHA_384)
|
||||
mbedtls_sha512_context sha512;
|
||||
#endif
|
||||
} ctx;
|
||||
} mbedtls_psa_hash_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_HASH_OPERATION_INIT {0, {0}}
|
||||
|
||||
/*
|
||||
* Cipher multi-part operation definitions.
|
||||
*/
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CTR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CFB) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_OFB) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_XTS) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_ECB_NO_PADDING) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_NO_PADDING) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CBC_PKCS7)
|
||||
#define MBEDTLS_PSA_BUILTIN_CIPHER 1
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
/* Context structure for the Mbed TLS cipher implementation. */
|
||||
psa_algorithm_t alg;
|
||||
uint8_t iv_length;
|
||||
uint8_t block_length;
|
||||
union {
|
||||
unsigned int dummy;
|
||||
mbedtls_cipher_context_t cipher;
|
||||
} ctx;
|
||||
} mbedtls_psa_cipher_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
|
||||
|
||||
#endif /* PSA_CRYPTO_BUILTIN_PRIMITIVES_H */
|
||||
+172
-3
@@ -44,7 +44,7 @@ typedef mbedtls_svc_key_id_t psa_key_handle_t;
|
||||
|
||||
#define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT
|
||||
|
||||
/** Check wether an handle is null.
|
||||
/** Check whether an handle is null.
|
||||
*
|
||||
* \param handle Handle
|
||||
*
|
||||
@@ -110,6 +110,18 @@ typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
|
||||
#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
|
||||
#define PSA_KEY_EXPORT_MAX_SIZE( key_type, key_bits ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) )
|
||||
#define PSA_BLOCK_CIPHER_BLOCK_SIZE( type ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ) )
|
||||
#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE )
|
||||
#define PSA_HASH_SIZE( alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_HASH_LENGTH( alg ) )
|
||||
#define PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_MAC_LENGTH( key_type, key_bits, alg ) )
|
||||
#define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE )
|
||||
|
||||
/*
|
||||
* Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
|
||||
@@ -249,6 +261,161 @@ MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key
|
||||
#define PSA_ALG_CHACHA20 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER )
|
||||
|
||||
/*
|
||||
* Renamed AEAD tag length macros (PSA Crypto API <= 1.0 beta3)
|
||||
*/
|
||||
#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( aead_alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( aead_alg ) )
|
||||
#define PSA_ALG_AEAD_WITH_TAG_LENGTH( aead_alg, tag_length ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_SHORTENED_TAG( aead_alg, tag_length ) )
|
||||
|
||||
/*
|
||||
* Deprecated PSA AEAD output size macros (PSA Crypto API <= 1.0 beta3)
|
||||
*/
|
||||
|
||||
/** The tag size for an AEAD algorithm, in bytes.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return The tag size for the specified algorithm.
|
||||
* If the AEAD algorithm does not have an identified
|
||||
* tag that can be distinguished from the rest of
|
||||
* the ciphertext, return 0.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_TAG_LENGTH_1_ARG( alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD( alg ) ? \
|
||||
PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \
|
||||
0 )
|
||||
|
||||
/** The maximum size of the output of psa_aead_encrypt(), in bytes.
|
||||
*
|
||||
* If the size of the ciphertext buffer is at least this large, it is
|
||||
* guaranteed that psa_aead_encrypt() will not fail due to an
|
||||
* insufficient buffer size. Depending on the algorithm, the actual size of
|
||||
* the ciphertext may be smaller.
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
* \param plaintext_length Size of the plaintext in bytes.
|
||||
*
|
||||
* \return The AEAD ciphertext size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE_2_ARG( alg, plaintext_length ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD( alg ) ? \
|
||||
(plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \
|
||||
0 )
|
||||
|
||||
/** The maximum size of the output of psa_aead_decrypt(), in bytes.
|
||||
*
|
||||
* If the size of the plaintext buffer is at least this large, it is
|
||||
* guaranteed that psa_aead_decrypt() will not fail due to an
|
||||
* insufficient buffer size. Depending on the algorithm, the actual size of
|
||||
* the plaintext may be smaller.
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
* \param ciphertext_length Size of the plaintext in bytes.
|
||||
*
|
||||
* \return The AEAD ciphertext size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_DECRYPT_OUTPUT_SIZE_2_ARG( alg, ciphertext_length ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD( alg ) && \
|
||||
(ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) ? \
|
||||
(ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) : \
|
||||
0 )
|
||||
|
||||
/** A sufficient output buffer size for psa_aead_update().
|
||||
*
|
||||
* If the size of the output buffer is at least this large, it is
|
||||
* guaranteed that psa_aead_update() will not fail due to an
|
||||
* insufficient buffer size. The actual size of the output may be smaller
|
||||
* in any given call.
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
* \param input_length Size of the input in bytes.
|
||||
*
|
||||
* \return A sufficient output buffer size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
/* For all the AEAD modes defined in this specification, it is possible
|
||||
* to emit output without delay. However, hardware may not always be
|
||||
* capable of this. So for modes based on a block cipher, allow the
|
||||
* implementation to delay the output until it has a full block. */
|
||||
#define PSA_AEAD_UPDATE_OUTPUT_SIZE_2_ARG( alg, input_length ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \
|
||||
PSA_ROUND_UP_TO_MULTIPLE( PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length) ) : \
|
||||
(input_length) )
|
||||
|
||||
/** A sufficient ciphertext buffer size for psa_aead_finish().
|
||||
*
|
||||
* If the size of the ciphertext buffer is at least this large, it is
|
||||
* guaranteed that psa_aead_finish() will not fail due to an
|
||||
* insufficient ciphertext buffer size. The actual size of the output may
|
||||
* be smaller in any given call.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return A sufficient ciphertext buffer size for the
|
||||
* specified algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_FINISH_OUTPUT_SIZE_1_ARG( alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
|
||||
0 )
|
||||
|
||||
/** A sufficient plaintext buffer size for psa_aead_verify().
|
||||
*
|
||||
* If the size of the plaintext buffer is at least this large, it is
|
||||
* guaranteed that psa_aead_verify() will not fail due to an
|
||||
* insufficient plaintext buffer size. The actual size of the output may
|
||||
* be smaller in any given call.
|
||||
*
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return A sufficient plaintext buffer size for the
|
||||
* specified algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_VERIFY_OUTPUT_SIZE_1_ARG( alg ) \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( size_t, \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER( alg ) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
|
||||
0 )
|
||||
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/** Open a handle to an existing persistent key.
|
||||
@@ -293,9 +460,9 @@ MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key
|
||||
* number of open keys, the number of open key handles, or available
|
||||
* memory.
|
||||
* \retval #PSA_ERROR_DOES_NOT_EXIST
|
||||
* There is no persistent key with key identifier \p id.
|
||||
* There is no persistent key with key identifier \p key.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \p id is not a valid persistent key identifier.
|
||||
* \p key is not a valid persistent key identifier.
|
||||
* \retval #PSA_ERROR_NOT_PERMITTED
|
||||
* The specified key exists, but the application does not have the
|
||||
* permission to access it. Note that this specification does not
|
||||
@@ -304,6 +471,8 @@ MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_STORAGE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
* It is implementation-dependent whether a failure to initialize
|
||||
|
||||
@@ -50,14 +50,29 @@
|
||||
#ifndef PSA_CRYPTO_CONFIG_H
|
||||
#define PSA_CRYPTO_CONFIG_H
|
||||
|
||||
/*
|
||||
* CBC-MAC is not yet supported via the PSA API in Mbed TLS.
|
||||
*/
|
||||
//#define PSA_WANT_ALG_CBC_MAC 1
|
||||
#define PSA_WANT_ALG_CBC_NO_PADDING 1
|
||||
#define PSA_WANT_ALG_CBC_PKCS7 1
|
||||
#define PSA_WANT_ALG_CCM 1
|
||||
#define PSA_WANT_ALG_CMAC 1
|
||||
#define PSA_WANT_ALG_CFB 1
|
||||
#define PSA_WANT_ALG_CHACHA20_POLY1305 1
|
||||
#define PSA_WANT_ALG_CMAC 1
|
||||
#define PSA_WANT_ALG_CTR 1
|
||||
#define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1
|
||||
#define PSA_WANT_ALG_ECB_NO_PADDING 1
|
||||
#define PSA_WANT_ALG_ECDH 1
|
||||
#define PSA_WANT_ALG_ECDSA 1
|
||||
#define PSA_WANT_ALG_GCM 1
|
||||
#define PSA_WANT_ALG_HKDF 1
|
||||
#define PSA_WANT_ALG_HMAC 1
|
||||
#define PSA_WANT_ALG_MD2 1
|
||||
#define PSA_WANT_ALG_MD4 1
|
||||
#define PSA_WANT_ALG_MD5 1
|
||||
#define PSA_WANT_ALG_OFB 1
|
||||
#define PSA_WANT_ALG_RIPEMD160 1
|
||||
#define PSA_WANT_ALG_RSA_OAEP 1
|
||||
#define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
|
||||
@@ -68,10 +83,46 @@
|
||||
#define PSA_WANT_ALG_SHA_256 1
|
||||
#define PSA_WANT_ALG_SHA_384 1
|
||||
#define PSA_WANT_ALG_SHA_512 1
|
||||
#define PSA_WANT_ALG_STREAM_CIPHER 1
|
||||
#define PSA_WANT_ALG_TLS12_PRF 1
|
||||
#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1
|
||||
#define PSA_WANT_ALG_XTS 1
|
||||
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_256 1
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_384 1
|
||||
#define PSA_WANT_ECC_BRAINPOOL_P_R1_512 1
|
||||
#define PSA_WANT_ECC_MONTGOMERY_255 1
|
||||
/*
|
||||
* Curve448 is not yet supported via the PSA API in Mbed TLS
|
||||
* (https://github.com/ARMmbed/mbedtls/issues/4249). Thus, do not enable it by
|
||||
* default.
|
||||
*/
|
||||
//#define PSA_WANT_ECC_MONTGOMERY_448 1
|
||||
#define PSA_WANT_ECC_SECP_K1_192 1
|
||||
/*
|
||||
* SECP224K1 is buggy via the PSA API in Mbed TLS
|
||||
* (https://github.com/ARMmbed/mbedtls/issues/3541). Thus, do not enable it by
|
||||
* default.
|
||||
*/
|
||||
//#define PSA_WANT_ECC_SECP_K1_224 1
|
||||
#define PSA_WANT_ECC_SECP_K1_256 1
|
||||
#define PSA_WANT_ECC_SECP_R1_192 1
|
||||
#define PSA_WANT_ECC_SECP_R1_224 1
|
||||
#define PSA_WANT_ECC_SECP_R1_256 1
|
||||
#define PSA_WANT_ECC_SECP_R1_384 1
|
||||
#define PSA_WANT_ECC_SECP_R1_521 1
|
||||
|
||||
#define PSA_WANT_KEY_TYPE_DERIVE 1
|
||||
#define PSA_WANT_KEY_TYPE_HMAC 1
|
||||
#define PSA_WANT_KEY_TYPE_AES 1
|
||||
#define PSA_WANT_KEY_TYPE_ARC4 1
|
||||
#define PSA_WANT_KEY_TYPE_ARIA 1
|
||||
#define PSA_WANT_KEY_TYPE_CAMELLIA 1
|
||||
#define PSA_WANT_KEY_TYPE_CHACHA20 1
|
||||
#define PSA_WANT_KEY_TYPE_DES 1
|
||||
#define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
|
||||
#define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
|
||||
#define PSA_WANT_KEY_TYPE_RAW_DATA 1
|
||||
#define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
|
||||
#define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
* This file contains common definitions shared by all PSA crypto drivers.
|
||||
* Do not include it directly: instead, include the header file(s) for
|
||||
* the type(s) of driver that you are implementing. For example, if
|
||||
* you are writing a driver for a chip that provides both a hardware
|
||||
* random generator and an accelerator for some cryptographic algorithms,
|
||||
* include `psa/crypto_entropy_driver.h` and `psa/crypto_accel_driver.h`.
|
||||
* you are writing a dynamically registered driver for a secure element,
|
||||
* include `psa/crypto_se_driver.h`.
|
||||
*
|
||||
* This file is part of the PSA Crypto Driver Model, containing functions for
|
||||
* driver developers to implement to enable hardware to be called in a
|
||||
@@ -43,6 +42,9 @@
|
||||
* of these types. */
|
||||
#include "crypto_types.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
|
||||
* or a decryption. */
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Declaration of context structures for use with the PSA driver wrapper
|
||||
* interface. This file contains the context structures for 'composite'
|
||||
* operations, i.e. those operations which need to make use of other operations
|
||||
* from the primitives (crypto_driver_contexts_primitives.h)
|
||||
*
|
||||
* Warning: This file will be auto-generated in the future.
|
||||
*
|
||||
* \note This file may not be included directly. Applications must
|
||||
* include psa/crypto.h.
|
||||
*
|
||||
* \note This header and its content is not part of the Mbed TLS API and
|
||||
* applications must not depend on it. Its main purpose is to define the
|
||||
* multi-part state objects of the PSA drivers included in the cryptographic
|
||||
* library. The definition of these objects are then used by crypto_struct.h
|
||||
* to define the implementation-defined types of PSA multi-part state objects.
|
||||
*/
|
||||
/* 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 PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H
|
||||
#define PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_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
|
||||
* declared during the autogeneration process. */
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||
#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
|
||||
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
||||
*
|
||||
* The union members are the driver's context structures, and the member names
|
||||
* are formatted as `'drivername'_ctx`. This allows for procedural generation
|
||||
* of both this file and the content of psa_crypto_driver_wrappers.c */
|
||||
|
||||
typedef union {
|
||||
unsigned dummy; /* Make sure this union is always non-empty */
|
||||
mbedtls_psa_mac_operation_t mbedtls_ctx;
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_transparent_test_driver_mac_operation_t transparent_test_driver_ctx;
|
||||
mbedtls_opaque_test_driver_mac_operation_t opaque_test_driver_ctx;
|
||||
#endif
|
||||
} psa_driver_mac_context_t;
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H */
|
||||
/* End of automatically generated file. */
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Declaration of context structures for use with the PSA driver wrapper
|
||||
* interface. This file contains the context structures for 'primitive'
|
||||
* operations, i.e. those operations which do not rely on other contexts.
|
||||
*
|
||||
* Warning: This file will be auto-generated in the future.
|
||||
*
|
||||
* \note This file may not be included directly. Applications must
|
||||
* include psa/crypto.h.
|
||||
*
|
||||
* \note This header and its content is not part of the Mbed TLS API and
|
||||
* applications must not depend on it. Its main purpose is to define the
|
||||
* multi-part state objects of the PSA drivers included in the cryptographic
|
||||
* library. The definition of these objects are then used by crypto_struct.h
|
||||
* to define the implementation-defined types of PSA multi-part state objects.
|
||||
*/
|
||||
/* 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 PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H
|
||||
#define PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_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
|
||||
* declared during the autogeneration process. */
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||
#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
|
||||
* PSA Driver wrapper layer as the union of all possible driver's contexts.
|
||||
*
|
||||
* The union members are the driver's context structures, and the member names
|
||||
* are formatted as `'drivername'_ctx`. This allows for procedural generation
|
||||
* of both this file and the content of psa_crypto_driver_wrappers.c */
|
||||
|
||||
typedef union {
|
||||
unsigned dummy; /* Make sure this union is always non-empty */
|
||||
mbedtls_psa_hash_operation_t mbedtls_ctx;
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_transparent_test_driver_hash_operation_t test_driver_ctx;
|
||||
#endif
|
||||
} psa_driver_hash_context_t;
|
||||
|
||||
typedef union {
|
||||
unsigned dummy; /* Make sure this union is always non-empty */
|
||||
mbedtls_psa_cipher_operation_t mbedtls_ctx;
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_transparent_test_driver_cipher_operation_t transparent_test_driver_ctx;
|
||||
mbedtls_opaque_test_driver_cipher_operation_t opaque_test_driver_ctx;
|
||||
#endif
|
||||
} psa_driver_cipher_context_t;
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_CONTEXTS_PRIMITIVES_H */
|
||||
/* End of automatically generated file. */
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
* \file psa/crypto_entropy_driver.h
|
||||
* \brief PSA entropy source driver module
|
||||
*
|
||||
* This header declares types and function signatures for entropy sources.
|
||||
*
|
||||
* This file is part of the PSA Crypto Driver Model, containing functions for
|
||||
* driver developers to implement to enable hardware to be called in a
|
||||
* standardized way by a PSA Cryptographic API implementation. The functions
|
||||
* comprising the driver model, which driver authors implement, are not
|
||||
* intended to be called by application developers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 PSA_CRYPTO_ENTROPY_DRIVER_H
|
||||
#define PSA_CRYPTO_ENTROPY_DRIVER_H
|
||||
|
||||
#include "crypto_driver_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup driver_rng Entropy Generation
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief Initialize an entropy driver
|
||||
*
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure
|
||||
* containing any context information for
|
||||
* the implementation
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_entropy_init_t)(void *p_context);
|
||||
|
||||
/** \brief Get a specified number of bits from the entropy source
|
||||
*
|
||||
* It retrives `buffer_size` bytes of data from the entropy source. The entropy
|
||||
* source will always fill the provided buffer to its full size, however, most
|
||||
* entropy sources have biases, and the actual amount of entropy contained in
|
||||
* the buffer will be less than the number of bytes.
|
||||
* The driver will return the actual number of bytes of entropy placed in the
|
||||
* buffer in `p_received_entropy_bytes`.
|
||||
* A PSA Crypto API implementation will likely feed the output of this function
|
||||
* into a Digital Random Bit Generator (DRBG), and typically has a minimum
|
||||
* amount of entropy that it needs.
|
||||
* To accomplish this, the PSA Crypto implementation should be designed to call
|
||||
* this function multiple times until it has received the required amount of
|
||||
* entropy from the entropy source.
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure
|
||||
* containing any context information
|
||||
* for the implementation
|
||||
* \param[out] p_buffer A caller-allocated buffer for the
|
||||
* retrieved entropy to be placed in
|
||||
* \param[in] buffer_size The allocated size of `p_buffer`
|
||||
* \param[out] p_received_entropy_bits The amount of entropy (in bits)
|
||||
* actually provided in `p_buffer`
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_entropy_get_bits_t)(void *p_context,
|
||||
uint8_t *p_buffer,
|
||||
uint32_t buffer_size,
|
||||
uint32_t *p_received_entropy_bits);
|
||||
|
||||
/**
|
||||
* \brief A struct containing all of the function pointers needed to interface
|
||||
* to an entropy source
|
||||
*
|
||||
* PSA Crypto API implementations should populate instances of the table as
|
||||
* appropriate upon startup.
|
||||
*
|
||||
* If one of the functions is not implemented, it should be set to NULL.
|
||||
*/
|
||||
typedef struct {
|
||||
/** The driver-specific size of the entropy context */
|
||||
const size_t context_size;
|
||||
/** Function that performs initialization for the entropy source */
|
||||
psa_drv_entropy_init_t p_init;
|
||||
/** Function that performs the get_bits operation for the entropy source */
|
||||
psa_drv_entropy_get_bits_t p_get_bits;
|
||||
} psa_drv_entropy_t;
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PSA_CRYPTO_ENTROPY_DRIVER_H */
|
||||
+171
-8
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include "crypto_types.h"
|
||||
#include "crypto_compat.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -39,6 +40,10 @@ extern "C" {
|
||||
/* UID for secure storage seed */
|
||||
#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
|
||||
|
||||
/* See config.h for definition */
|
||||
#if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT)
|
||||
#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
|
||||
#endif
|
||||
|
||||
/** \addtogroup attributes
|
||||
* @{
|
||||
@@ -175,6 +180,9 @@ static inline void psa_clear_key_slot_number(
|
||||
* The secure element driver for the specified lifetime does not
|
||||
* support registering a key.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The identifier in \p attributes is invalid, namely the identifier is
|
||||
* not in the user range.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \p attributes specifies a lifetime which is not located
|
||||
* in a secure element.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
@@ -183,8 +191,10 @@ static inline void psa_clear_key_slot_number(
|
||||
* \retval #PSA_ERROR_NOT_PERMITTED
|
||||
* The caller is not authorized to register the specified key slot.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_DATA_INVALID
|
||||
* \retval #PSA_ERROR_DATA_CORRUPT
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
* \retval #PSA_ERROR_BAD_STATE
|
||||
* The library has not been previously initialized by psa_crypto_init().
|
||||
@@ -401,10 +411,9 @@ psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
|
||||
|
||||
/* We need to expand the sample definition of this macro from
|
||||
* the API definition. */
|
||||
#undef PSA_ALG_IS_HASH_AND_SIGN
|
||||
#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
|
||||
(PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
|
||||
PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg))
|
||||
#undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN
|
||||
#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \
|
||||
PSA_ALG_IS_DSA(alg)
|
||||
|
||||
/**@}*/
|
||||
|
||||
@@ -635,20 +644,174 @@ static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id gr
|
||||
*
|
||||
* \param curve A PSA elliptic curve identifier
|
||||
* (`PSA_ECC_FAMILY_xxx`).
|
||||
* \param byte_length The byte-length of a private key on \p curve.
|
||||
* \param bits The bit-length of a private key on \p curve.
|
||||
* \param bits_is_sloppy If true, \p bits may be the bit-length rounded up
|
||||
* to the nearest multiple of 8. This allows the caller
|
||||
* to infer the exact curve from the length of a key
|
||||
* which is supplied as a byte string.
|
||||
*
|
||||
* \return The corresponding Mbed TLS elliptic curve identifier
|
||||
* (`MBEDTLS_ECP_DP_xxx`).
|
||||
* \return #MBEDTLS_ECP_DP_NONE if \c curve is not recognized.
|
||||
* \return #MBEDTLS_ECP_DP_NONE if \p byte_length is not
|
||||
* \return #MBEDTLS_ECP_DP_NONE if \p bits is not
|
||||
* correct for \p curve.
|
||||
*/
|
||||
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
||||
size_t byte_length );
|
||||
size_t bits,
|
||||
int bits_is_sloppy );
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup psa_external_rng External random generator
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
/** External random generator function, implemented by the platform.
|
||||
*
|
||||
* When the compile-time option #MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled,
|
||||
* this function replaces Mbed TLS's entropy and DRBG modules for all
|
||||
* random generation triggered via PSA crypto interfaces.
|
||||
*
|
||||
* \note This random generator must deliver random numbers with cryptographic
|
||||
* quality and high performance. It must supply unpredictable numbers
|
||||
* with a uniform distribution. The implementation of this function
|
||||
* is responsible for ensuring that the random generator is seeded
|
||||
* with sufficient entropy. If you have a hardware TRNG which is slow
|
||||
* or delivers non-uniform output, declare it as an entropy source
|
||||
* with mbedtls_entropy_add_source() instead of enabling this option.
|
||||
*
|
||||
* \param[in,out] context Pointer to the random generator context.
|
||||
* This is all-bits-zero on the first call
|
||||
* and preserved between successive calls.
|
||||
* \param[out] output Output buffer. On success, this buffer
|
||||
* contains random data with a uniform
|
||||
* distribution.
|
||||
* \param output_size The size of the \p output buffer in bytes.
|
||||
* \param[out] output_length On success, set this value to \p output_size.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success. The output buffer contains \p output_size bytes of
|
||||
* cryptographic-quality random data, and \c *output_length is
|
||||
* set to \p output_size.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
|
||||
* The random generator requires extra entropy and there is no
|
||||
* way to obtain entropy under current environment conditions.
|
||||
* This error should not happen under normal circumstances since
|
||||
* this function is responsible for obtaining as much entropy as
|
||||
* it needs. However implementations of this function may return
|
||||
* #PSA_ERROR_INSUFFICIENT_ENTROPY if there is no way to obtain
|
||||
* entropy without blocking indefinitely.
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* A failure of the random generator hardware that isn't covered
|
||||
* by #PSA_ERROR_INSUFFICIENT_ENTROPY.
|
||||
*/
|
||||
psa_status_t mbedtls_psa_external_get_random(
|
||||
mbedtls_psa_external_random_context_t *context,
|
||||
uint8_t *output, size_t output_size, size_t *output_length );
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup psa_builtin_keys Built-in keys
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The minimum value for a key identifier that is built into the
|
||||
* implementation.
|
||||
*
|
||||
* The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN
|
||||
* to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from
|
||||
* #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect
|
||||
* with any other set of implementation-chosen key identifiers.
|
||||
*
|
||||
* This value is part of the library's ABI since changing it would invalidate
|
||||
* the values of built-in key identifiers in applications.
|
||||
*/
|
||||
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t)0x7fff0000)
|
||||
|
||||
/** The maximum value for a key identifier that is built into the
|
||||
* implementation.
|
||||
*
|
||||
* See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information.
|
||||
*/
|
||||
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t)0x7fffefff)
|
||||
|
||||
/** A slot number identifying a key in a driver.
|
||||
*
|
||||
* Values of this type are used to identify built-in keys.
|
||||
*/
|
||||
typedef uint64_t psa_drv_slot_number_t;
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
/** Test whether a key identifier belongs to the builtin key range.
|
||||
*
|
||||
* \param key_id Key identifier to test.
|
||||
*
|
||||
* \retval 1
|
||||
* The key identifier is a builtin key identifier.
|
||||
* \retval 0
|
||||
* The key identifier is not a builtin key identifier.
|
||||
*/
|
||||
static inline int psa_key_id_is_builtin( psa_key_id_t key_id )
|
||||
{
|
||||
return( ( key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ) &&
|
||||
( key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ) );
|
||||
}
|
||||
|
||||
/** Platform function to obtain the location and slot number of a built-in key.
|
||||
*
|
||||
* An application-specific implementation of this function must be provided if
|
||||
* #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided
|
||||
* as part of a platform's system image.
|
||||
*
|
||||
* #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from
|
||||
* #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX.
|
||||
*
|
||||
* In a multi-application configuration
|
||||
* (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined),
|
||||
* this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id)
|
||||
* is allowed to use the given key.
|
||||
*
|
||||
* \param key_id The key ID for which to retrieve the
|
||||
* location and slot attributes.
|
||||
* \param[out] lifetime On success, the lifetime associated with the key
|
||||
* corresponding to \p key_id. Lifetime is a
|
||||
* combination of which driver contains the key,
|
||||
* and with what persistence level the key is
|
||||
* intended to be used. If the platform
|
||||
* implementation does not contain specific
|
||||
* information about the intended key persistence
|
||||
* level, the persistence level may be reported as
|
||||
* #PSA_KEY_PERSISTENCE_DEFAULT.
|
||||
* \param[out] slot_number On success, the slot number known to the driver
|
||||
* registered at the lifetime location reported
|
||||
* through \p lifetime which corresponds to the
|
||||
* requested built-in key.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The requested key identifier designates a built-in key.
|
||||
* In a multi-application configuration, the requested owner
|
||||
* is allowed to access it.
|
||||
* \retval #PSA_ERROR_DOES_NOT_EXIST
|
||||
* The requested key identifier is not a built-in key which is known
|
||||
* to this function. If a key exists in the key storage with this
|
||||
* identifier, the data from the storage will be used.
|
||||
* \return (any other error)
|
||||
* Any other error is propagated to the function that requested the key.
|
||||
* Common errors include:
|
||||
* - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner
|
||||
* is not allowed to access it.
|
||||
*/
|
||||
psa_status_t mbedtls_psa_platform_get_builtin_key(
|
||||
mbedtls_svc_key_id_t key_id,
|
||||
psa_key_lifetime_t *lifetime,
|
||||
psa_drv_slot_number_t *slot_number );
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -81,4 +81,31 @@ static inline int mbedtls_key_owner_id_equal( mbedtls_key_owner_id_t id1,
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
|
||||
|
||||
/*
|
||||
* When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
|
||||
* (Secure Partition Manager) integration which separates the code into two
|
||||
* parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
|
||||
* Environment). When building for the SPE, an additional header file should be
|
||||
* included.
|
||||
*/
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
|
||||
#define PSA_CRYPTO_SECURE 1
|
||||
#include "crypto_spe.h"
|
||||
#endif // MBEDTLS_PSA_CRYPTO_SPM
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
/** The type of the context passed to mbedtls_psa_external_get_random().
|
||||
*
|
||||
* Mbed TLS initializes the context to all-bits-zero before calling
|
||||
* mbedtls_psa_external_get_random() for the first time.
|
||||
*
|
||||
* The definition of this type in the Mbed TLS source code is for
|
||||
* demonstration purposes. Implementers of mbedtls_psa_external_get_random()
|
||||
* are expected to replace it with a custom definition.
|
||||
*/
|
||||
typedef struct {
|
||||
uintptr_t opaque[2];
|
||||
} mbedtls_psa_external_random_context_t;
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
#endif /* PSA_CRYPTO_PLATFORM_H */
|
||||
|
||||
+9
-6
@@ -1061,7 +1061,8 @@ typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_contex
|
||||
* \brief A function that generates a symmetric or asymmetric key on a secure
|
||||
* element
|
||||
*
|
||||
* If \p type is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) = 1),
|
||||
* If the key type \c type recorded in \p attributes
|
||||
* is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\c type) = 1),
|
||||
* the driver may export the public key at the time of generation,
|
||||
* in the format documented for psa_export_public_key() by writing it
|
||||
* to the \p pubkey buffer.
|
||||
@@ -1158,7 +1159,7 @@ typedef struct {
|
||||
* can be problemmatic to manage on embedded platforms, the inputs are passed
|
||||
* to the driver via a function, `psa_drv_se_key_derivation_collateral`, that
|
||||
* is called multiple times with different `collateral_id`s. Thus, for a key
|
||||
* derivation algorithm that required 3 paramter inputs, the flow would look
|
||||
* derivation algorithm that required 3 parameter inputs, the flow would look
|
||||
* something like:
|
||||
* ~~~~~~~~~~~~~{.c}
|
||||
* psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
|
||||
@@ -1206,7 +1207,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *
|
||||
* element key derivation or key agreement operation
|
||||
*
|
||||
* Since many key derivation algorithms require multiple parameters, it is
|
||||
* expeced that this function may be called multiple times for the same
|
||||
* expected that this function may be called multiple times for the same
|
||||
* operation, each with a different algorithm-specific `collateral_id`
|
||||
*
|
||||
* \param[in,out] op_context A hardware-specific structure containing any
|
||||
@@ -1364,20 +1365,22 @@ typedef struct {
|
||||
*
|
||||
* \return #PSA_SUCCESS
|
||||
* The driver was successfully registered. Applications can now
|
||||
* use \p lifetime to access keys through the methods passed to
|
||||
* use \p location to access keys through the methods passed to
|
||||
* this function.
|
||||
* \return #PSA_ERROR_BAD_STATE
|
||||
* This function was called after the initialization of the
|
||||
* cryptography module, and this implementation does not support
|
||||
* driver registration at this stage.
|
||||
* \return #PSA_ERROR_ALREADY_EXISTS
|
||||
* There is already a registered driver for this value of \p lifetime.
|
||||
* There is already a registered driver for this value of \p location.
|
||||
* \return #PSA_ERROR_INVALID_ARGUMENT
|
||||
* \p lifetime is a reserved value.
|
||||
* \p location is a reserved value.
|
||||
* \return #PSA_ERROR_NOT_SUPPORTED
|
||||
* `methods->hal_version` is not supported by this implementation.
|
||||
* \return #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \return #PSA_ERROR_NOT_PERMITTED
|
||||
* \return #PSA_ERROR_STORAGE_FAILURE
|
||||
* \return #PSA_ERROR_DATA_CORRUPT
|
||||
*/
|
||||
psa_status_t psa_register_se_driver(
|
||||
psa_key_location_t location,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user