Merge branch 'development_3.0' into remove_depr_error_codes
This commit is contained in:
commit
d6c246f5bf
236 changed files with 12619 additions and 14161 deletions
23
.github/issue_template.md
vendored
23
.github/issue_template.md
vendored
|
@ -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)**
|
||||
|
|
55
BRANCHES.md
Normal file
55
BRANCHES.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# 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.16`](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.16)
|
||||
maintained until at least the end of 2021, see
|
||||
<https://tls.mbed.org/tech-updates/blog/announcing-lts-branch-mbedtls-2.16>
|
||||
|
||||
Users are urged to always use the latest version of a maintained branch.
|
20
BUGS.md
Normal file
20
BUGS.md
Normal file
|
@ -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.
|
|
@ -10,10 +10,6 @@
|
|||
# directories. That way, a target linking to a library (using the
|
||||
# target_link_librairies command) inherits from the library PUBLIC include
|
||||
# directories and not from the PRIVATE ones.
|
||||
# + Note: there is currently one remaining include_directories command in the
|
||||
# CMake files. It is related to ZLIB support which is planned to be removed.
|
||||
# When the support is removed, the associated include_directories command
|
||||
# will be removed as well as this note.
|
||||
# - MBEDTLS_TARGET_PREFIX: CMake targets are designed to be alterable by calling
|
||||
# CMake in order to avoid target name clashes, via the use of
|
||||
# MBEDTLS_TARGET_PREFIX. The value of this variable is prefixed to the
|
||||
|
@ -43,7 +39,6 @@ endif()
|
|||
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
|
||||
option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
|
||||
|
||||
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
|
||||
|
||||
|
@ -198,7 +193,7 @@ if(CMAKE_COMPILER_IS_GNU)
|
|||
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=2")
|
||||
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")
|
||||
|
@ -256,14 +251,6 @@ else()
|
|||
set(LIB_INSTALL_DIR lib)
|
||||
endif()
|
||||
|
||||
if(ENABLE_ZLIB_SUPPORT)
|
||||
find_package(ZLIB)
|
||||
|
||||
if(ZLIB_FOUND)
|
||||
include_directories(${ZLIB_INCLUDE_DIR})
|
||||
endif(ZLIB_FOUND)
|
||||
endif(ENABLE_ZLIB_SUPPORT)
|
||||
|
||||
add_subdirectory(include)
|
||||
|
||||
add_subdirectory(3rdparty)
|
||||
|
|
|
@ -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)
|
||||
|
|
2
ChangeLog.d/add_const_parameters.txt
Normal file
2
ChangeLog.d/add_const_parameters.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
API changes
|
||||
* Add missing const attributes to API functions.
|
5
ChangeLog.d/bugfix_PR3616.txt
Normal file
5
ChangeLog.d/bugfix_PR3616.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
Bugfix
|
||||
* Fix premature fopen() call in mbedtls_entropy_write_seed_file which may
|
||||
lead to the seed file corruption in case if the path to the seed file is
|
||||
equal to MBEDTLS_PLATFORM_STD_NV_SEED_FILE. Contributed by Victor
|
||||
Krasnoshchok in #3616.
|
2
ChangeLog.d/dtls_sample_use_read_timeout.txt
Normal file
2
ChangeLog.d/dtls_sample_use_read_timeout.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Changes
|
||||
* Fix the setting of the read timeout in the DTLS sample programs.
|
5
ChangeLog.d/fix-invalid-id-error-code.txt
Normal file
5
ChangeLog.d/fix-invalid-id-error-code.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
Bugfix
|
||||
* 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.
|
4
ChangeLog.d/fix_return_type_for_invalid_crypto_key.txt
Normal file
4
ChangeLog.d/fix_return_type_for_invalid_crypto_key.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Bugfix
|
||||
* 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.
|
3
ChangeLog.d/issue1792.txt
Normal file
3
ChangeLog.d/issue1792.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Bugfix
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero. Fixes #1792
|
2
ChangeLog.d/issue4284.txt
Normal file
2
ChangeLog.d/issue4284.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Removals
|
||||
* Removed deprecated things in psa/crypto_compat.h. Fixes #4284
|
7
ChangeLog.d/move_alt_helpers.txt
Normal file
7
ChangeLog.d/move_alt_helpers.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
API changes
|
||||
* Move alt helpers and definitions.
|
||||
Various helpers and definitions available for use in alt implementations
|
||||
have been moved out of the include/ directory and into the library/
|
||||
directory. The files concerned are ecp_internal.h and rsa_internal.h
|
||||
which have also been renamed to ecp_alt.h and rsa_alt_helpers.h
|
||||
respectively.
|
6
ChangeLog.d/move_internal_headers.txt
Normal file
6
ChangeLog.d/move_internal_headers.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
API changes
|
||||
* Move internal headers.
|
||||
Header files that were only meant for the library's internal use and
|
||||
were not meant to be used in application code have been moved out of
|
||||
the include/ directory. The headers concerned are bn_mul.h, aesni.h,
|
||||
padlock.h, entropy_poll.h and *_internal.h.
|
3
ChangeLog.d/mpi_read_negative_zero.txt
Normal file
3
ChangeLog.d/mpi_read_negative_zero.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Bugfix
|
||||
* mbedtls_mpi_read_string on "-0" produced an MPI object that was not treated
|
||||
as equal to 0 in all cases. Fix it to produce the same object as "0".
|
5
ChangeLog.d/pkcs1_v21_sign_ext.txt
Normal file
5
ChangeLog.d/pkcs1_v21_sign_ext.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
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.
|
14
ChangeLog.d/remove_allow_sha1_in_certificates
Normal file
14
ChangeLog.d/remove_allow_sha1_in_certificates
Normal file
|
@ -0,0 +1,14 @@
|
|||
Removals
|
||||
* Remove the MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
|
||||
compile-time option, which was off by default. Users should not trust
|
||||
certificates signed with SHA-1 due to the known attacks against SHA-1.
|
||||
If needed, SHA-1 cerificate can still be used by providing custom
|
||||
verification profile to mbedtls_x509_crt_verify_with_profile function
|
||||
in x509_crt.h, or mbedtls_ssl_conf_cert_profile function in ssl.h.
|
||||
Example of custom verification profile, supporting SHA-1:
|
||||
const mbedtls_x509_crt_profile mbedtls_x509_crt_custom = {
|
||||
MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ),
|
||||
0xFFFFFFF, /* Any PK alg */
|
||||
0xFFFFFFF, /* Any curve */
|
||||
2048
|
||||
};
|
5
ChangeLog.d/remove_certs.txt
Normal file
5
ChangeLog.d/remove_certs.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
API changes
|
||||
* Remove certs module from the API.
|
||||
Transfer keys and certificates embedded in the library to the test
|
||||
component. This contributes to minimizing library API and discourages
|
||||
users from using unsafe keys in production.
|
9
ChangeLog.d/remove_havege.txt
Normal file
9
ChangeLog.d/remove_havege.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
API changes
|
||||
* Remove HAVEGE module.
|
||||
The design of HAVEGE makes it unsuitable for microcontrollers. Platforms
|
||||
with a more complex CPU usually have an operating system interface that
|
||||
provides better randomness. Instead of HAVEGE, declare OS or hardware RNG
|
||||
interfaces with mbedtls_entropy_add_source() and/or use an entropy seed
|
||||
file created securely during device provisioning. See
|
||||
https://tls.mbed.org/kb/how-to/add-entropy-sources-to-entropy-pool for
|
||||
more information.
|
10
ChangeLog.d/remove_obsolete_tls_features.txt
Normal file
10
ChangeLog.d/remove_obsolete_tls_features.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
API changes
|
||||
* Drop support for parsing SSLv2 ClientHello
|
||||
(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO).
|
||||
* Drop support for SSLv3 (MBEDTLS_SSL_PROTO_SSL3).
|
||||
* Drop support for compatibility with our own previous buggy
|
||||
implementation of truncated HMAC (MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT).
|
||||
* Drop support for TLS record-level compression (MBEDTLS_ZLIB_SUPPORT).
|
||||
* Drop support for RC4 TLS ciphersuites.
|
||||
* Drop support for single-DES ciphersuites.
|
||||
* Drop support for MBEDTLS_SSL_HW_RECORD_ACCEL.
|
3
ChangeLog.d/remove_old_transition_helpers.txt
Normal file
3
ChangeLog.d/remove_old_transition_helpers.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
API changes
|
||||
* Remove helpers for the transition from Mbed TLS 1.3 to Mbed TLS 2.0: the
|
||||
header compat-1.3.h and the script rename.pl.
|
4
Makefile
4
Makefile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
---------
|
||||
|
||||
|
|
20
SECURITY.md
Normal file
20
SECURITY.md
Normal file
|
@ -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.
|
15
SUPPORT.md
Normal file
15
SUPPORT.md
Normal file
|
@ -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).
|
|
@ -65,7 +65,6 @@
|
|||
|
||||
/* For test certificates */
|
||||
#define MBEDTLS_BASE64_C
|
||||
#define MBEDTLS_CERTS_C
|
||||
#define MBEDTLS_PEM_PARSE_C
|
||||
|
||||
/* For testing with compat.sh */
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
/* mbed TLS feature support */
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_CIPHER_PADDING_PKCS7
|
||||
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
* Used in:
|
||||
* library/aria.c
|
||||
* library/timing.c
|
||||
* include/mbedtls/bn_mul.h
|
||||
* library/bn_mul.h
|
||||
*
|
||||
* Required by:
|
||||
* MBEDTLS_AESNI_C
|
||||
|
@ -661,10 +661,6 @@
|
|||
* Warning: Only do so when you know what you are doing. This allows for
|
||||
* channels with virtually no security at all!
|
||||
*
|
||||
* This enables the following ciphersuites:
|
||||
* MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA
|
||||
* MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
|
||||
*
|
||||
* Uncomment this macro to enable weak ciphersuites
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
|
@ -672,19 +668,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
*
|
||||
* Remove RC4 ciphersuites by default in SSL / TLS.
|
||||
* This flag removes the ciphersuites based on RC4 from the default list as
|
||||
* returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to
|
||||
* enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them
|
||||
* explicitly.
|
||||
*
|
||||
* Uncomment this macro to remove RC4 ciphersuites by default.
|
||||
*/
|
||||
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
|
||||
*
|
||||
|
@ -774,7 +757,6 @@
|
|||
* MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
|
||||
|
@ -798,7 +780,6 @@
|
|||
* MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
|
||||
*
|
||||
* \warning Using DHE constitutes a security risk as it
|
||||
* is not possible to validate custom DH parameters.
|
||||
|
@ -825,7 +806,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
|
||||
|
||||
|
@ -850,7 +830,6 @@
|
|||
* MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
|
||||
|
||||
|
@ -877,8 +856,6 @@
|
|||
* MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
|
||||
|
@ -936,7 +913,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||
|
||||
|
@ -960,7 +936,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
|
||||
|
@ -973,7 +948,6 @@
|
|||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
|
||||
|
@ -997,7 +971,6 @@
|
|||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
|
||||
|
@ -1079,8 +1052,8 @@
|
|||
/**
|
||||
* \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
||||
*
|
||||
* Do not add default entropy sources. These are the platform specific,
|
||||
* mbedtls_timing_hardclock and HAVEGE based poll functions.
|
||||
* Do not add default entropy sources. These are the platform specific
|
||||
* or mbedtls_timing_hardclock poll function.
|
||||
*
|
||||
* This is useful to have more control over the added entropy sources in an
|
||||
* application.
|
||||
|
@ -1370,20 +1343,10 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_FALLBACK_SCSV
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||
*
|
||||
* Enable hooking functions in SSL module for hardware acceleration of
|
||||
* individual records.
|
||||
*
|
||||
* Uncomment this macro to enable hooking functions.
|
||||
*/
|
||||
//#define MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
|
||||
*
|
||||
* Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
|
||||
* Enable 1/n-1 record splitting for CBC mode in TLS 1.0.
|
||||
*
|
||||
* This is a countermeasure to the BEAST attack, which also minimizes the risk
|
||||
* of interoperability issues compared to sending 0-length records.
|
||||
|
@ -1414,16 +1377,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_RENEGOTIATION
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
|
||||
*
|
||||
* Enable support for receiving and parsing SSLv2 Client Hello messages for the
|
||||
* SSL Server module (MBEDTLS_SSL_SRV_C).
|
||||
*
|
||||
* Uncomment this macro to enable support for SSLv2 Client Hello messages.
|
||||
*/
|
||||
//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
|
||||
*
|
||||
|
@ -1443,18 +1396,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_PROTO_SSL3
|
||||
*
|
||||
* Enable support for SSL 3.0.
|
||||
*
|
||||
* Requires: MBEDTLS_MD5_C
|
||||
* MBEDTLS_SHA1_C
|
||||
*
|
||||
* Comment this macro to disable support for SSL 3.0
|
||||
*/
|
||||
//#define MBEDTLS_SSL_PROTO_SSL3
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_PROTO_TLS1
|
||||
*
|
||||
|
@ -1619,30 +1560,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_TRUNCATED_HMAC
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
|
||||
*
|
||||
* Fallback to old (pre-2.7), non-conforming implementation of the truncated
|
||||
* HMAC extension which also truncates the HMAC key. Note that this option is
|
||||
* only meant for a transitory upgrade period and is likely to be removed in
|
||||
* a future version of the library.
|
||||
*
|
||||
* \warning The old implementation is non-compliant and has a security weakness
|
||||
* (2^80 brute force attack on the HMAC key used for a single,
|
||||
* uninterrupted connection). This should only be enabled temporarily
|
||||
* when (1) the use of truncated HMAC is essential in order to save
|
||||
* bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use
|
||||
* the fixed implementation yet (pre-2.7).
|
||||
*
|
||||
* \deprecated This option is deprecated and will likely be removed in a
|
||||
* future version of Mbed TLS.
|
||||
*
|
||||
* Uncomment to fallback to old, non-compliant truncated HMAC implementation.
|
||||
*
|
||||
* Requires: MBEDTLS_SSL_TRUNCATED_HMAC
|
||||
*/
|
||||
//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_THREADING_ALT
|
||||
*
|
||||
|
@ -1754,31 +1671,6 @@
|
|||
* Comment this macro to disallow using RSASSA-PSS in certificates.
|
||||
*/
|
||||
#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ZLIB_SUPPORT
|
||||
*
|
||||
* If set, the SSL/TLS module uses ZLIB to support compression and
|
||||
* decompression of packet data.
|
||||
*
|
||||
* \warning TLS-level compression MAY REDUCE SECURITY! See for example the
|
||||
* CRIME attack. Before enabling this option, you should examine with care if
|
||||
* CRIME or similar exploits may be applicable to your use case.
|
||||
*
|
||||
* \note Currently compression can't be used with DTLS.
|
||||
*
|
||||
* \deprecated This feature is deprecated and will be removed
|
||||
* in the next major revision of the library.
|
||||
*
|
||||
* Used in: library/ssl_tls.c
|
||||
* library/ssl_cli.c
|
||||
* library/ssl_srv.c
|
||||
*
|
||||
* This feature requires zlib library and headers to be present.
|
||||
*
|
||||
* Uncomment to enable use of ZLIB
|
||||
*/
|
||||
//#define MBEDTLS_ZLIB_SUPPORT
|
||||
/* \} name SECTION: mbed TLS feature support */
|
||||
|
||||
/**
|
||||
|
@ -1887,16 +1779,6 @@
|
|||
*
|
||||
* This module enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. If possible, we recommend avoidng dependencies on
|
||||
|
@ -1955,7 +1837,7 @@
|
|||
* library/ecp.c
|
||||
* library/ecdsa.c
|
||||
* library/rsa.c
|
||||
* library/rsa_internal.c
|
||||
* library/rsa_alt_helpers.h
|
||||
* library/ssl_tls.c
|
||||
*
|
||||
* This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
|
||||
|
@ -2092,18 +1974,6 @@
|
|||
*/
|
||||
#define MBEDTLS_CCM_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CERTS_C
|
||||
*
|
||||
* Enable the test certificates.
|
||||
*
|
||||
* Module: library/certs.c
|
||||
* Caller:
|
||||
*
|
||||
* This module is used for testing (ssl_client/server).
|
||||
*/
|
||||
#define MBEDTLS_CERTS_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHACHA20_C
|
||||
*
|
||||
|
@ -2333,29 +2203,6 @@
|
|||
*/
|
||||
#define MBEDTLS_GCM_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_HAVEGE_C
|
||||
*
|
||||
* Enable the HAVEGE random generator.
|
||||
*
|
||||
* Warning: the HAVEGE random generator is not suitable for virtualized
|
||||
* environments
|
||||
*
|
||||
* Warning: the HAVEGE random generator is dependent on timing and specific
|
||||
* processor traits. It is therefore not advised to use HAVEGE as
|
||||
* your applications primary random generator or primary entropy pool
|
||||
* input. As a secondary input to your entropy pool, it IS able add
|
||||
* the (limited) extra entropy it provides.
|
||||
*
|
||||
* Module: library/havege.c
|
||||
* Caller:
|
||||
*
|
||||
* Requires: MBEDTLS_TIMING_C
|
||||
*
|
||||
* Uncomment to enable the HAVEGE random generator.
|
||||
*/
|
||||
//#define MBEDTLS_HAVEGE_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_HKDF_C
|
||||
*
|
||||
|
@ -2745,7 +2592,7 @@
|
|||
* Enable the RSA public-key cryptosystem.
|
||||
*
|
||||
* Module: library/rsa.c
|
||||
* library/rsa_internal.c
|
||||
* library/rsa_alt_helpers.h
|
||||
* Caller: library/ssl_cli.c
|
||||
* library/ssl_srv.c
|
||||
* library/ssl_tls.c
|
||||
|
@ -2929,9 +2776,6 @@
|
|||
* https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
|
||||
*
|
||||
* Module: library/timing.c
|
||||
* Caller: library/havege.c
|
||||
*
|
||||
* This module is used by the HAVEGE random number generator.
|
||||
*/
|
||||
#define MBEDTLS_TIMING_C
|
||||
|
||||
|
@ -3263,7 +3107,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
|
||||
|
||||
//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
|
||||
//#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 */
|
||||
|
||||
|
@ -3285,20 +3128,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
|
||||
|
|
|
@ -73,7 +73,6 @@
|
|||
|
||||
/* For test certificates */
|
||||
#define MBEDTLS_BASE64_C
|
||||
#define MBEDTLS_CERTS_C
|
||||
#define MBEDTLS_PEM_PARSE_C
|
||||
|
||||
/* Save RAM at the expense of ROM */
|
||||
|
|
|
@ -64,7 +64,6 @@
|
|||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_ERROR_C
|
||||
#define MBEDTLS_GCM_C
|
||||
//#define MBEDTLS_HAVEGE_C
|
||||
#define MBEDTLS_HKDF_C
|
||||
#define MBEDTLS_HMAC_DRBG_C
|
||||
#define MBEDTLS_NIST_KW_C
|
||||
|
|
|
@ -31,7 +31,7 @@ Do not add test-specific interfaces if there's a practical way of doing it anoth
|
|||
|
||||
### Reliance on internal details
|
||||
|
||||
In unit tests and in test programs, it's ok to include header files from `library/`. Do not define non-public interfaces in public headers (`include/mbedtls` has `*_internal.h` headers for legacy reasons, but this approach is deprecated). In contrast, sample programs must not include header files from `library/`.
|
||||
In unit tests and in test programs, it's ok to include internal header files from `library/`. Do not define non-public interfaces in public headers. In contrast, sample programs must not include header files from `library/`.
|
||||
|
||||
Sometimes it makes sense to have unit tests on functions that aren't part of the public API. Declare such functions in `library/*.h` and include the corresponding header in the test code. If the function should be `static` for optimization but can't be `static` for testing, declare it as `MBEDTLS_STATIC_TESTABLE`, and make the tests that use it depend on `MBEDTLS_TEST_HOOKS` (see [“rules for compile-time options”](#rules-for-compile-time-options)).
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -134,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]
|
||||
}
|
||||
```
|
||||
|
@ -164,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(_)
|
||||
```
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
*
|
||||
* @section mainpage_modules Modules
|
||||
*
|
||||
* mbed TLS supports SSLv3 up to TLSv1.2 communication by providing the
|
||||
* mbed TLS supports TLSv1.0 up to TLSv1.2 communication by providing the
|
||||
* following:
|
||||
* - TCP/IP communication functions: listen, connect, accept, read/write.
|
||||
* - SSL/TLS communication functions: init, handshake, read/write.
|
||||
|
|
|
@ -32,11 +32,6 @@
|
|||
* source of entropy. For these purposes \c mbedtls_entropy_func() can be used.
|
||||
* This is an implementation based on a simple entropy accumulator design.
|
||||
*
|
||||
* The other number generator that is included is less strong and uses the
|
||||
* HAVEGE (HArdware Volatile Entropy Gathering and Expansion) software heuristic
|
||||
* which considered unsafe for primary usage, but provides additional random
|
||||
* to the entropy pool if enables.
|
||||
*
|
||||
* Meaning that there seems to be no practical algorithm that can guess
|
||||
* the next bit with a probability larger than 1/2 in an output sequence.
|
||||
*
|
||||
|
|
|
@ -710,7 +710,7 @@ EXCLUDE_SYMLINKS = YES
|
|||
# against the file with absolute path, so to exclude all test directories
|
||||
# for example use the pattern */test/*
|
||||
|
||||
EXCLUDE_PATTERNS = *_internal.h *_wrap.h
|
||||
EXCLUDE_PATTERNS =
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
|
|
|
@ -578,7 +578,7 @@ int mbedtls_asn1_get_alg_null( unsigned char **p,
|
|||
*
|
||||
* \return NULL if not found, or a pointer to the existing entry.
|
||||
*/
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
|
||||
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len );
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,7 +55,7 @@ extern "C" {
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start,
|
||||
size_t len );
|
||||
/**
|
||||
* \brief Write an ASN.1 tag in ASN.1 format.
|
||||
|
@ -69,7 +69,7 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start,
|
||||
unsigned char tag );
|
||||
|
||||
/**
|
||||
|
@ -85,7 +85,7 @@ int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size );
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
@ -103,7 +103,7 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start,
|
||||
const mbedtls_mpi *X );
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
|
@ -119,7 +119,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
|
||||
int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start );
|
||||
|
||||
/**
|
||||
* \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
|
||||
|
@ -135,7 +135,7 @@ int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len );
|
||||
|
||||
/**
|
||||
|
@ -154,7 +154,7 @@ int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
|||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
|
||||
unsigned char *start,
|
||||
const unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len );
|
||||
|
||||
|
@ -171,7 +171,7 @@ int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start,
|
||||
int boolean );
|
||||
|
||||
/**
|
||||
|
@ -188,7 +188,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
|
||||
int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val );
|
||||
|
||||
/**
|
||||
* \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
|
||||
|
@ -203,7 +203,7 @@ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val );
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val );
|
||||
|
||||
/**
|
||||
* \brief Write a string in ASN.1 format using a specific
|
||||
|
@ -222,7 +222,7 @@ int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val );
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start,
|
||||
int tag, const char *text,
|
||||
size_t text_len );
|
||||
|
||||
|
@ -242,7 +242,7 @@ int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start,
|
|||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p,
|
||||
unsigned char *start,
|
||||
const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
|
||||
/**
|
||||
|
@ -260,7 +260,7 @@ int mbedtls_asn1_write_printable_string( unsigned char **p,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
|
||||
/**
|
||||
|
@ -278,7 +278,7 @@ int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
|
||||
/**
|
||||
|
@ -295,7 +295,7 @@ int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t bits );
|
||||
|
||||
/**
|
||||
|
@ -316,7 +316,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
|||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
||||
unsigned char *start,
|
||||
const unsigned char *start,
|
||||
const unsigned char *buf,
|
||||
size_t bits );
|
||||
|
||||
|
@ -334,7 +334,7 @@ int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
|||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size );
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,10 +81,6 @@
|
|||
#error "MBEDTLS_DHM_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) && !defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
||||
#error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C) && \
|
||||
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
|
||||
#error "MBEDTLS_CMAC_C defined, but not all prerequisites"
|
||||
|
@ -210,8 +206,7 @@
|
|||
#error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
|
||||
#endif
|
||||
#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
|
||||
( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
|
||||
defined(MBEDTLS_HAVEGE_C) )
|
||||
( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) )
|
||||
#error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
|
||||
#endif
|
||||
|
||||
|
@ -256,10 +251,6 @@
|
|||
#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
|
||||
|
||||
#if defined(MBEDTLS_HKDF_C) && !defined(MBEDTLS_MD_C)
|
||||
#error "MBEDTLS_HKDF_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
@ -643,11 +634,6 @@
|
|||
#error "MBEDTLS_SHA512_NO_SHA384 defined without MBEDTLS_SHA512_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
|
||||
!defined(MBEDTLS_SHA1_C) )
|
||||
#error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
|
||||
!defined(MBEDTLS_SHA1_C) )
|
||||
#error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
|
||||
|
@ -668,8 +654,8 @@
|
|||
#error "MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if (defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \
|
||||
#if (defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) ||\
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)) && \
|
||||
!(defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
|
||||
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
|
||||
|
@ -704,28 +690,16 @@
|
|||
#error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2))
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1_2))
|
||||
#error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
|
||||
#error "Illegal protocol selection"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
|
||||
#error "Illegal protocol selection"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1)))
|
||||
#error "Illegal protocol selection"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
#error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
|
||||
#endif
|
||||
|
@ -780,8 +754,7 @@
|
|||
#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && !defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||
#error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
|
@ -829,10 +802,6 @@
|
|||
#error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CERTS_C) && !defined(MBEDTLS_X509_USE_C)
|
||||
#error "MBEDTLS_CERTS_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
||||
#error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
@ -862,30 +831,6 @@
|
|||
#error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
|
||||
#endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#elif defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "MBEDTLS_SSL_PROTO_SSL3 is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#elif defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#elif defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "MBEDTLS_SSL_HW_RECORD_ACCEL is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_SRTP) && ( !defined(MBEDTLS_SSL_PROTO_DTLS) )
|
||||
#error "MBEDTLS_SSL_DTLS_SRTP defined, but not all prerequisites"
|
||||
#endif
|
||||
|
|
|
@ -226,13 +226,13 @@ enum {
|
|||
/** Maximum length of any IV, in Bytes. */
|
||||
/* This should ideally be derived automatically from list of ciphers.
|
||||
* This should be kept in sync with MBEDTLS_SSL_MAX_IV_LENGTH defined
|
||||
* in ssl_internal.h. */
|
||||
* in library/ssl_misc.h. */
|
||||
#define MBEDTLS_MAX_IV_LENGTH 16
|
||||
|
||||
/** Maximum block size of any cipher, in Bytes. */
|
||||
/* This should ideally be derived automatically from list of ciphers.
|
||||
* This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
|
||||
* in ssl_internal.h. */
|
||||
* in library/ssl_misc.h. */
|
||||
#define MBEDTLS_MAX_BLOCK_LENGTH 16
|
||||
|
||||
/** Maximum key length, in Bytes. */
|
||||
|
@ -240,7 +240,7 @@ enum {
|
|||
* For now, only check whether XTS is enabled which uses 64 Byte keys,
|
||||
* and use 32 Bytes as an upper bound for the maximum key length otherwise.
|
||||
* This should be kept in sync with MBEDTLS_SSL_MAX_BLOCK_LENGTH defined
|
||||
* in ssl_internal.h, which however deliberately ignores the case of XTS
|
||||
* in library/ssl_misc.h, which however deliberately ignores the case of XTS
|
||||
* since the latter isn't used in SSL/TLS. */
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
#define MBEDTLS_MAX_KEY_LENGTH 64
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -48,7 +48,7 @@
|
|||
* Used in:
|
||||
* library/aria.c
|
||||
* library/timing.c
|
||||
* include/mbedtls/bn_mul.h
|
||||
* library/bn_mul.h
|
||||
*
|
||||
* Required by:
|
||||
* MBEDTLS_AESNI_C
|
||||
|
@ -559,7 +559,8 @@
|
|||
* hardware entropy collector.
|
||||
*
|
||||
* Your function must be called \c mbedtls_hardware_poll(), have the same
|
||||
* prototype as declared in entropy_poll.h, and accept NULL as first argument.
|
||||
* prototype as declared in library/entropy_poll.h, and accept NULL as first
|
||||
* argument.
|
||||
*
|
||||
* Uncomment to use your own hardware entropy collector.
|
||||
*/
|
||||
|
@ -714,10 +715,6 @@
|
|||
* Warning: Only do so when you know what you are doing. This allows for
|
||||
* channels with virtually no security at all!
|
||||
*
|
||||
* This enables the following ciphersuites:
|
||||
* MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA
|
||||
* MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
|
||||
*
|
||||
* Uncomment this macro to enable weak ciphersuites
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
|
@ -725,19 +722,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
*
|
||||
* Remove RC4 ciphersuites by default in SSL / TLS.
|
||||
* This flag removes the ciphersuites based on RC4 from the default list as
|
||||
* returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to
|
||||
* enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them
|
||||
* explicitly.
|
||||
*
|
||||
* Uncomment this macro to remove RC4 ciphersuites by default.
|
||||
*/
|
||||
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_REMOVE_3DES_CIPHERSUITES
|
||||
*
|
||||
|
@ -900,7 +884,6 @@
|
|||
* MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
|
||||
|
@ -924,7 +907,6 @@
|
|||
* MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
|
||||
*
|
||||
* \warning Using DHE constitutes a security risk as it
|
||||
* is not possible to validate custom DH parameters.
|
||||
|
@ -951,7 +933,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
|
||||
|
||||
|
@ -976,7 +957,6 @@
|
|||
* MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
|
||||
|
||||
|
@ -1003,8 +983,6 @@
|
|||
* MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
|
||||
|
@ -1062,7 +1040,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||
|
||||
|
@ -1086,7 +1063,6 @@
|
|||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
|
||||
*/
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
|
||||
|
@ -1099,7 +1075,6 @@
|
|||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
|
||||
|
@ -1123,7 +1098,6 @@
|
|||
*
|
||||
* This enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
|
||||
|
@ -1205,8 +1179,8 @@
|
|||
/**
|
||||
* \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
||||
*
|
||||
* Do not add default entropy sources. These are the platform specific,
|
||||
* mbedtls_timing_hardclock and HAVEGE based poll functions.
|
||||
* Do not add default entropy sources. These are the platform specific
|
||||
* or mbedtls_timing_hardclock poll function.
|
||||
*
|
||||
* This is useful to have more control over the added entropy sources in an
|
||||
* application.
|
||||
|
@ -1672,23 +1646,10 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||
*
|
||||
* Enable hooking functions in SSL module for hardware acceleration of
|
||||
* individual records.
|
||||
*
|
||||
* \deprecated This option is deprecated and will be removed in a future
|
||||
* version of Mbed TLS.
|
||||
*
|
||||
* Uncomment this macro to enable hooking functions.
|
||||
*/
|
||||
//#define MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
|
||||
*
|
||||
* Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
|
||||
* Enable 1/n-1 record splitting for CBC mode in TLS 1.0.
|
||||
*
|
||||
* This is a countermeasure to the BEAST attack, which also minimizes the risk
|
||||
* of interoperability issues compared to sending 0-length records.
|
||||
|
@ -1719,19 +1680,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_RENEGOTIATION
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
|
||||
*
|
||||
* Enable support for receiving and parsing SSLv2 Client Hello messages for the
|
||||
* SSL Server module (MBEDTLS_SSL_SRV_C).
|
||||
*
|
||||
* \deprecated This option is deprecated and will be removed in a future
|
||||
* version of Mbed TLS.
|
||||
*
|
||||
* Uncomment this macro to enable support for SSLv2 Client Hello messages.
|
||||
*/
|
||||
//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
|
||||
*
|
||||
|
@ -1751,21 +1699,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_PROTO_SSL3
|
||||
*
|
||||
* Enable support for SSL 3.0.
|
||||
*
|
||||
* Requires: MBEDTLS_MD5_C
|
||||
* MBEDTLS_SHA1_C
|
||||
*
|
||||
* \deprecated This option is deprecated and will be removed in a future
|
||||
* version of Mbed TLS.
|
||||
*
|
||||
* Comment this macro to disable support for SSL 3.0
|
||||
*/
|
||||
//#define MBEDTLS_SSL_PROTO_SSL3
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_PROTO_TLS1
|
||||
*
|
||||
|
@ -1980,30 +1913,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_TRUNCATED_HMAC
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
|
||||
*
|
||||
* Fallback to old (pre-2.7), non-conforming implementation of the truncated
|
||||
* HMAC extension which also truncates the HMAC key. Note that this option is
|
||||
* only meant for a transitory upgrade period and will be removed in a future
|
||||
* version of the library.
|
||||
*
|
||||
* \warning The old implementation is non-compliant and has a security weakness
|
||||
* (2^80 brute force attack on the HMAC key used for a single,
|
||||
* uninterrupted connection). This should only be enabled temporarily
|
||||
* when (1) the use of truncated HMAC is essential in order to save
|
||||
* bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use
|
||||
* the fixed implementation yet (pre-2.7).
|
||||
*
|
||||
* \deprecated This option is deprecated and will be removed in a
|
||||
* future version of Mbed TLS.
|
||||
*
|
||||
* Uncomment to fallback to old, non-compliant truncated HMAC implementation.
|
||||
*
|
||||
* Requires: MBEDTLS_SSL_TRUNCATED_HMAC
|
||||
*/
|
||||
//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
|
||||
*
|
||||
|
@ -2227,31 +2136,6 @@
|
|||
* Comment this macro to disallow using RSASSA-PSS in certificates.
|
||||
*/
|
||||
#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ZLIB_SUPPORT
|
||||
*
|
||||
* If set, the SSL/TLS module uses ZLIB to support compression and
|
||||
* decompression of packet data.
|
||||
*
|
||||
* \warning TLS-level compression MAY REDUCE SECURITY! See for example the
|
||||
* CRIME attack. Before enabling this option, you should examine with care if
|
||||
* CRIME or similar exploits may be applicable to your use case.
|
||||
*
|
||||
* \note Currently compression can't be used with DTLS.
|
||||
*
|
||||
* \deprecated This feature is deprecated and will be removed
|
||||
* in the next major revision of the library.
|
||||
*
|
||||
* Used in: library/ssl_tls.c
|
||||
* library/ssl_cli.c
|
||||
* library/ssl_srv.c
|
||||
*
|
||||
* This feature requires zlib library and headers to be present.
|
||||
*
|
||||
* Uncomment to enable use of ZLIB
|
||||
*/
|
||||
//#define MBEDTLS_ZLIB_SUPPORT
|
||||
/* \} name SECTION: mbed TLS feature support */
|
||||
|
||||
/**
|
||||
|
@ -2360,16 +2244,6 @@
|
|||
*
|
||||
* This module enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
|
||||
* MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
|
||||
* MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. If possible, we recommend avoidng dependencies on
|
||||
|
@ -2428,7 +2302,7 @@
|
|||
* library/ecp.c
|
||||
* library/ecdsa.c
|
||||
* library/rsa.c
|
||||
* library/rsa_internal.c
|
||||
* library/rsa_alt_helpers.c
|
||||
* library/ssl_tls.c
|
||||
*
|
||||
* This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
|
||||
|
@ -2565,18 +2439,6 @@
|
|||
*/
|
||||
#define MBEDTLS_CCM_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CERTS_C
|
||||
*
|
||||
* Enable the test certificates.
|
||||
*
|
||||
* Module: library/certs.c
|
||||
* Caller:
|
||||
*
|
||||
* This module is used for testing (ssl_client/server).
|
||||
*/
|
||||
#define MBEDTLS_CERTS_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHACHA20_C
|
||||
*
|
||||
|
@ -2812,29 +2674,6 @@
|
|||
*/
|
||||
#define MBEDTLS_GCM_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_HAVEGE_C
|
||||
*
|
||||
* Enable the HAVEGE random generator.
|
||||
*
|
||||
* Warning: the HAVEGE random generator is not suitable for virtualized
|
||||
* environments
|
||||
*
|
||||
* Warning: the HAVEGE random generator is dependent on timing and specific
|
||||
* processor traits. It is therefore not advised to use HAVEGE as
|
||||
* your applications primary random generator or primary entropy pool
|
||||
* input. As a secondary input to your entropy pool, it IS able add
|
||||
* the (limited) extra entropy it provides.
|
||||
*
|
||||
* Module: library/havege.c
|
||||
* Caller:
|
||||
*
|
||||
* Requires: MBEDTLS_TIMING_C
|
||||
*
|
||||
* Uncomment to enable the HAVEGE random generator.
|
||||
*/
|
||||
//#define MBEDTLS_HAVEGE_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_HKDF_C
|
||||
*
|
||||
|
@ -3249,7 +3088,7 @@
|
|||
* Enable the RSA public-key cryptosystem.
|
||||
*
|
||||
* Module: library/rsa.c
|
||||
* library/rsa_internal.c
|
||||
* library/rsa_alt_helpers.c
|
||||
* Caller: library/ssl_cli.c
|
||||
* library/ssl_srv.c
|
||||
* library/ssl_tls.c
|
||||
|
@ -3433,9 +3272,6 @@
|
|||
* https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
|
||||
*
|
||||
* Module: library/timing.c
|
||||
* Caller: library/havege.c
|
||||
*
|
||||
* This module is used by the HAVEGE random number generator.
|
||||
*/
|
||||
#define MBEDTLS_TIMING_C
|
||||
|
||||
|
@ -3843,7 +3679,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
|
||||
|
||||
//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
|
||||
//#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 */
|
||||
|
||||
|
@ -3865,20 +3700,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
|
||||
|
|
|
@ -231,16 +231,23 @@ extern "C" {
|
|||
(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(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_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 */
|
||||
|
@ -258,7 +265,8 @@ extern "C" {
|
|||
#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_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 */
|
||||
|
@ -295,6 +303,21 @@ extern "C" {
|
|||
#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)
|
||||
|
@ -348,6 +371,24 @@ extern "C" {
|
|||
#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_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_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(PSA_WANT_KEY_TYPE_CHACHA20)
|
||||
#define MBEDTLS_CHACHAPOLY_C
|
||||
|
@ -355,6 +396,107 @@ extern "C" {
|
|||
#endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
|
||||
#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 */
|
||||
|
||||
#else /* MBEDTLS_PSA_CRYPTO_CONFIG */
|
||||
|
||||
/*
|
||||
|
@ -362,6 +504,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
|
||||
|
@ -386,6 +538,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
|
||||
|
@ -531,6 +688,73 @@ extern "C" {
|
|||
#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. */
|
||||
|
|
|
@ -44,9 +44,6 @@
|
|||
#include "mbedtls/threading.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#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. */
|
||||
|
@ -130,9 +127,6 @@ typedef struct mbedtls_entropy_context
|
|||
#endif
|
||||
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;
|
||||
#endif
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
mbedtls_threading_mutex_t mutex; /*!< mutex */
|
||||
#endif
|
||||
|
@ -142,6 +136,14 @@ typedef struct mbedtls_entropy_context
|
|||
}
|
||||
mbedtls_entropy_context;
|
||||
|
||||
#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
||||
/**
|
||||
* \brief Platform-specific entropy poll callback
|
||||
*/
|
||||
int mbedtls_platform_entropy_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Initialize the context
|
||||
*
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
* \file havege.h
|
||||
*
|
||||
* \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
|
||||
*/
|
||||
/*
|
||||
* 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_HAVEGE_H
|
||||
#define MBEDTLS_HAVEGE_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief HAVEGE state structure
|
||||
*/
|
||||
typedef struct mbedtls_havege_state
|
||||
{
|
||||
uint32_t PT1, PT2, offset[2];
|
||||
uint32_t pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
|
||||
uint32_t WALK[8192];
|
||||
}
|
||||
mbedtls_havege_state;
|
||||
|
||||
/**
|
||||
* \brief HAVEGE initialization
|
||||
*
|
||||
* \param hs HAVEGE state to be initialized
|
||||
*/
|
||||
void mbedtls_havege_init( mbedtls_havege_state *hs );
|
||||
|
||||
/**
|
||||
* \brief Clear HAVEGE state
|
||||
*
|
||||
* \param hs HAVEGE state to be cleared
|
||||
*/
|
||||
void mbedtls_havege_free( mbedtls_havege_state *hs );
|
||||
|
||||
/**
|
||||
* \brief HAVEGE rand function
|
||||
*
|
||||
* \param p_rng A HAVEGE state
|
||||
* \param output Buffer to fill
|
||||
* \param len Length of buffer
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* havege.h */
|
|
@ -76,8 +76,15 @@ typedef enum {
|
|||
#endif
|
||||
|
||||
/**
|
||||
* Opaque struct defined in md_internal.h.
|
||||
* Opaque struct.
|
||||
*
|
||||
* Constructed using either #mbedtls_md_info_from_string or
|
||||
* #mbedtls_md_info_from_type.
|
||||
*
|
||||
* Fields can be accessed with #mbedtls_md_get_size,
|
||||
* #mbedtls_md_get_type and #mbedtls_md_get_name.
|
||||
*/
|
||||
/* Defined internally in library/md_wrap.h. */
|
||||
typedef struct mbedtls_md_info_t mbedtls_md_info_t;
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,7 @@ typedef struct mbedtls_pk_rsassa_pss_options
|
|||
/* For RSA, the signature can be as large as the bignum module allows.
|
||||
* For RSA_ALT, the signature size is not necessarily tied to what the
|
||||
* bignum module can do, but in the absence of any specific setting,
|
||||
* we use that (rsa_alt_sign_wrap in pk_wrap will check). */
|
||||
* we use that (rsa_alt_sign_wrap in library/pk_wrap.h will check). */
|
||||
#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
|
||||
#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
|
||||
#endif
|
||||
|
@ -757,7 +757,7 @@ int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path )
|
|||
* \return length of data written if successful, or a specific
|
||||
* error code
|
||||
*/
|
||||
int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
int mbedtls_pk_write_key_der( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
|
||||
/**
|
||||
* \brief Write a public key to a SubjectPublicKeyInfo DER structure
|
||||
|
@ -772,7 +772,7 @@ int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_
|
|||
* \return length of data written if successful, or a specific
|
||||
* error code
|
||||
*/
|
||||
int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
|
||||
#if defined(MBEDTLS_PEM_WRITE_C)
|
||||
/**
|
||||
|
@ -785,7 +785,7 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, si
|
|||
*
|
||||
* \return 0 if successful, or a specific error code
|
||||
*/
|
||||
int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
int mbedtls_pk_write_pubkey_pem( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
|
||||
/**
|
||||
* \brief Write a private key to a PKCS#1 or SEC1 PEM string
|
||||
|
@ -797,7 +797,7 @@ int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, si
|
|||
*
|
||||
* \return 0 if successful, or a specific error code
|
||||
*/
|
||||
int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
int mbedtls_pk_write_key_pem( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
|
||||
#endif /* MBEDTLS_PEM_WRITE_C */
|
||||
#endif /* MBEDTLS_PK_WRITE_C */
|
||||
|
||||
|
|
|
@ -96,8 +96,8 @@ static inline psa_algorithm_t mbedtls_psa_translate_cipher_mode(
|
|||
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 );
|
||||
}
|
||||
|
@ -155,7 +155,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 );
|
||||
}
|
||||
|
|
|
@ -965,6 +965,59 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
|
|||
const unsigned char *hash,
|
||||
unsigned char *sig );
|
||||
|
||||
/**
|
||||
* \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
|
||||
* Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
|
||||
* Specifications</em> it is advised to keep both hashes the
|
||||
* same.
|
||||
*
|
||||
* \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).
|
||||
|
|
|
@ -51,19 +51,6 @@
|
|||
#include "mbedtls/ecdh.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set"
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#include "mbedtls/platform_time.h"
|
||||
#endif
|
||||
|
@ -107,7 +94,6 @@
|
|||
#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. */
|
||||
|
@ -137,8 +123,14 @@
|
|||
/*
|
||||
* Various constants
|
||||
*/
|
||||
|
||||
/* These are the high an low bytes of ProtocolVersion as defined by:
|
||||
* - RFC 2246: ProtocolVersion version = { 3, 1 }; // TLS v1.0
|
||||
* - RFC 4346: ProtocolVersion version = { 3, 2 }; // TLS v1.1
|
||||
* - RFC 5246: ProtocolVersion version = { 3, 3 }; // TLS v1.2
|
||||
* - RFC 8446: see section 4.2.1
|
||||
*/
|
||||
#define MBEDTLS_SSL_MAJOR_VERSION_3 3
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
|
||||
#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
|
||||
|
@ -177,7 +169,6 @@
|
|||
#define MBEDTLS_SSL_ETM_ENABLED 1
|
||||
|
||||
#define MBEDTLS_SSL_COMPRESS_NULL 0
|
||||
#define MBEDTLS_SSL_COMPRESS_DEFLATE 1
|
||||
|
||||
#define MBEDTLS_SSL_VERIFY_NONE 0
|
||||
#define MBEDTLS_SSL_VERIFY_OPTIONAL 1
|
||||
|
@ -210,9 +201,6 @@
|
|||
#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
|
||||
#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
|
||||
|
||||
#define MBEDTLS_SSL_ARC4_ENABLED 0
|
||||
#define MBEDTLS_SSL_ARC4_DISABLED 1
|
||||
|
||||
#define MBEDTLS_SSL_PRESET_DEFAULT 0
|
||||
#define MBEDTLS_SSL_PRESET_SUITEB 2
|
||||
|
||||
|
@ -237,10 +225,6 @@
|
|||
* \{
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
|
||||
#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Maximum fragment length in bytes,
|
||||
* determines the size of each of the two internal I/O buffers.
|
||||
|
@ -296,11 +280,7 @@
|
|||
/*
|
||||
* Length of the verify data for secure renegotiation
|
||||
*/
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
|
||||
#else
|
||||
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Signaling ciphersuite values (SCSV)
|
||||
|
@ -499,7 +479,6 @@ mbedtls_ssl_states;
|
|||
typedef enum
|
||||
{
|
||||
MBEDTLS_SSL_TLS_PRF_NONE,
|
||||
MBEDTLS_SSL_TLS_PRF_SSL3,
|
||||
MBEDTLS_SSL_TLS_PRF_TLS1,
|
||||
MBEDTLS_SSL_TLS_PRF_SHA384,
|
||||
MBEDTLS_SSL_TLS_PRF_SHA256
|
||||
|
@ -619,7 +598,7 @@ typedef struct mbedtls_ssl_session mbedtls_ssl_session;
|
|||
typedef struct mbedtls_ssl_context mbedtls_ssl_context;
|
||||
typedef struct mbedtls_ssl_config mbedtls_ssl_config;
|
||||
|
||||
/* Defined in ssl_internal.h */
|
||||
/* Defined in library/ssl_misc.h */
|
||||
typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
|
||||
typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
|
||||
typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
|
||||
|
@ -961,7 +940,10 @@ struct mbedtls_ssl_config
|
|||
* Pointers
|
||||
*/
|
||||
|
||||
const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
|
||||
/** Allowed ciphersuites per version. To access list's elements, please use
|
||||
* \c mbedtls_ssl_get_protocol_version_ciphersuites
|
||||
*/
|
||||
const int *ciphersuite_list[3];
|
||||
|
||||
/** Callback for printing debug output */
|
||||
void (*f_dbg)(void *, int, const char *, int, const char *);
|
||||
|
@ -1151,9 +1133,6 @@ struct mbedtls_ssl_config
|
|||
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
|
||||
|
@ -1212,7 +1191,7 @@ struct mbedtls_ssl_context
|
|||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
|
||||
int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
|
||||
int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
|
||||
int minor_ver; /*!< one of MBEDTLS_SSL_MINOR_VERSION_x macros */
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
|
||||
unsigned badmac_seen; /*!< records with a bad MAC received */
|
||||
|
@ -1330,9 +1309,6 @@ struct mbedtls_ssl_context
|
|||
uint16_t mtu; /*!< path mtu, used to fragment outgoing messages */
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
|
||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||
unsigned char *compress_buf; /*!< zlib data buffer */
|
||||
#endif /* MBEDTLS_ZLIB_SUPPORT */
|
||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
|
||||
signed char split_done; /*!< current record already splitted? */
|
||||
#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
|
||||
|
@ -1397,44 +1373,6 @@ struct mbedtls_ssl_context
|
|||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
};
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
|
||||
#define MBEDTLS_SSL_CHANNEL_OUTBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 0 )
|
||||
#define MBEDTLS_SSL_CHANNEL_INBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 1 )
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif /* MBEDTLS_DEPRECATED_WARNING */
|
||||
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_init)(
|
||||
mbedtls_ssl_context *ssl,
|
||||
const unsigned char *key_enc, const unsigned char *key_dec,
|
||||
size_t keylen,
|
||||
const unsigned char *iv_enc, const unsigned char *iv_dec,
|
||||
size_t ivlen,
|
||||
const unsigned char *mac_enc, const unsigned char *mac_dec,
|
||||
size_t maclen);
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_activate)(
|
||||
mbedtls_ssl_context *ssl,
|
||||
int direction );
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_reset)(
|
||||
mbedtls_ssl_context *ssl );
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_write)(
|
||||
mbedtls_ssl_context *ssl );
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_read)(
|
||||
mbedtls_ssl_context *ssl );
|
||||
MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_finish)(
|
||||
mbedtls_ssl_context *ssl );
|
||||
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
|
||||
/**
|
||||
* \brief Return the name of the ciphersuite associated with the
|
||||
* given ID
|
||||
|
@ -1493,9 +1431,8 @@ int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
|
|||
* pointers and data.
|
||||
*
|
||||
* \param ssl SSL context
|
||||
* \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED,
|
||||
MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
|
||||
* MBEDTLS_ERR_SSL_COMPRESSION_FAILED
|
||||
* \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED or
|
||||
MBEDTLS_ERR_SSL_HW_ACCEL_FAILED
|
||||
*/
|
||||
int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl );
|
||||
|
||||
|
@ -1810,9 +1747,6 @@ int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl,
|
|||
* \note Values lower than the current record layer expansion will
|
||||
* result in an error when trying to send data.
|
||||
*
|
||||
* \note Using record compression together with a non-zero MTU value
|
||||
* will result in an error when trying to send data.
|
||||
*
|
||||
* \param ssl SSL context
|
||||
* \param mtu Value of the path MTU in bytes
|
||||
*/
|
||||
|
@ -2557,6 +2491,17 @@ const mbedtls_ssl_session *mbedtls_ssl_get_session_pointer( const mbedtls_ssl_co
|
|||
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
|
||||
const int *ciphersuites );
|
||||
|
||||
/**
|
||||
* \brief Get ciphersuite for given protocol's minor version.
|
||||
*
|
||||
* \param conf The SSL configuration.
|
||||
* \param prot_version Protocol version. One of MBEDTLS_SSL_MINOR_VERSION_x macros.
|
||||
* \return Ciphersuites pointer if succesful.
|
||||
* \return \c NULL if no ciphersuites where found.
|
||||
*/
|
||||
const int *mbedtls_ssl_get_protocol_version_ciphersuites(
|
||||
const mbedtls_ssl_config *conf, int prot_version );
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
|
||||
#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
|
||||
|
@ -2608,8 +2553,8 @@ int mbedtls_ssl_conf_cid( mbedtls_ssl_config *conf, size_t len,
|
|||
* \param ciphersuites 0-terminated list of allowed ciphersuites
|
||||
* \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
|
||||
* supported)
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_3 supported)
|
||||
*
|
||||
* \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
|
||||
|
@ -3296,8 +3241,7 @@ void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ss
|
|||
*
|
||||
* \param conf SSL configuration
|
||||
* \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_3 supported)
|
||||
*/
|
||||
void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
|
||||
|
@ -3309,15 +3253,13 @@ void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int mino
|
|||
* \note Input outside of the SSL_MAX_XXXXX_VERSION and
|
||||
* SSL_MIN_XXXXX_VERSION range is ignored.
|
||||
*
|
||||
* \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
|
||||
*
|
||||
* \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
|
||||
* MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_1,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_2,
|
||||
* MBEDTLS_SSL_MINOR_VERSION_3 supported)
|
||||
*/
|
||||
void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
|
||||
|
@ -3375,25 +3317,6 @@ void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
|
|||
void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
|
||||
#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
/**
|
||||
* \brief Disable or enable support for RC4
|
||||
* (Default: MBEDTLS_SSL_ARC4_DISABLED)
|
||||
*
|
||||
* \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465
|
||||
* for security reasons. Use at your own risk.
|
||||
*
|
||||
* \note This function is deprecated and will be removed in
|
||||
* a future version of the library.
|
||||
* RC4 is disabled by default at compile time and needs to be
|
||||
* actively enabled for use with legacy systems.
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
|
||||
*/
|
||||
void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
|
||||
#endif /* MBEDTLS_ARC4_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
/**
|
||||
* \brief Whether to send a list of acceptable CAs in
|
||||
|
@ -3463,7 +3386,7 @@ void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
|
|||
* \brief Enable / Disable 1/n-1 record splitting
|
||||
* (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
|
||||
*
|
||||
* \note Only affects SSLv3 and TLS 1.0, not higher versions.
|
||||
* \note Only affects TLS 1.0, not higher versions.
|
||||
* Does not affect non-CBC ciphersuites in any version.
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
|
@ -3687,11 +3610,11 @@ uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
|
|||
const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
|
||||
|
||||
/**
|
||||
* \brief Return the current SSL version (SSLv3/TLSv1/etc)
|
||||
* \brief Return the current TLS version
|
||||
*
|
||||
* \param ssl SSL context
|
||||
*
|
||||
* \return a string containing the SSL version
|
||||
* \return a string containing the TLS version
|
||||
*/
|
||||
const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
|
||||
|
||||
|
@ -3699,14 +3622,9 @@ const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
|
|||
* \brief Return the (maximum) number of bytes added by the record
|
||||
* layer: header + encryption/MAC overhead (inc. padding)
|
||||
*
|
||||
* \note This function is not available (always returns an error)
|
||||
* when record compression is enabled.
|
||||
*
|
||||
* \param ssl SSL context
|
||||
*
|
||||
* \return Current maximum record expansion in bytes, or
|
||||
* MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
|
||||
* enabled, which makes expansion much less predictable
|
||||
* \return Current maximum record expansion in bytes
|
||||
*/
|
||||
int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
|
||||
|
||||
|
@ -3783,9 +3701,6 @@ MBEDTLS_DEPRECATED size_t mbedtls_ssl_get_max_frag_len(
|
|||
* to the caller to call \c mbedtls_ssl_write() again in
|
||||
* order to send the remaining bytes if any.
|
||||
*
|
||||
* \note This function is not available (always returns an error)
|
||||
* when record compression is enabled.
|
||||
*
|
||||
* \sa mbedtls_ssl_set_mtu()
|
||||
* \sa mbedtls_ssl_get_output_max_frag_len()
|
||||
* \sa mbedtls_ssl_get_input_max_frag_len()
|
||||
|
|
|
@ -42,13 +42,8 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_RSA_WITH_NULL_MD5 0x01 /**< Weak! */
|
||||
#define MBEDTLS_TLS_RSA_WITH_NULL_SHA 0x02 /**< Weak! */
|
||||
|
||||
#define MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 0x04
|
||||
#define MBEDTLS_TLS_RSA_WITH_RC4_128_SHA 0x05
|
||||
#define MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA 0x09 /**< Weak! Not in TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
|
||||
|
||||
#define MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15 /**< Weak! Not in TLS 1.2 */
|
||||
#define MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
|
||||
|
||||
#define MBEDTLS_TLS_PSK_WITH_NULL_SHA 0x2C /**< Weak! */
|
||||
|
@ -73,17 +68,14 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
|
||||
#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
|
||||
|
||||
#define MBEDTLS_TLS_PSK_WITH_RC4_128_SHA 0x8A
|
||||
#define MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA 0x8B
|
||||
#define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA 0x8C
|
||||
#define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA 0x8D
|
||||
|
||||
#define MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA 0x8E
|
||||
#define MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x8F
|
||||
#define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA 0x90
|
||||
#define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA 0x91
|
||||
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA 0x92
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x93
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA 0x94
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA 0x95
|
||||
|
@ -122,28 +114,24 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4 /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A
|
||||
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
|
||||
|
@ -163,15 +151,14 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA 0xC033 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039 /**< Weak! No SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A /**< Weak! No SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B /**< Weak! No SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B
|
||||
|
||||
#define MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256 0xC03C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384 0xC03D /**< TLS 1.2 */
|
||||
|
@ -212,14 +199,14 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 0xC070 /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 0xC071 /**< TLS 1.2 */
|
||||
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079 /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072
|
||||
#define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074
|
||||
#define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076
|
||||
#define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078
|
||||
#define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079
|
||||
|
||||
#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07A /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07B /**< TLS 1.2 */
|
||||
|
@ -247,8 +234,8 @@ extern "C" {
|
|||
#define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC097
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC098
|
||||
#define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC099
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B /**< Not in SSL3! */
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A
|
||||
#define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B
|
||||
|
||||
#define MBEDTLS_TLS_RSA_WITH_AES_128_CCM 0xC09C /**< TLS 1.2 */
|
||||
#define MBEDTLS_TLS_RSA_WITH_AES_256_CCM 0xC09D /**< TLS 1.2 */
|
||||
|
|
|
@ -291,17 +291,6 @@ int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
|
|||
*/
|
||||
int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_x509_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
/*
|
||||
* Internal module functions. You probably do not want to use these unless you
|
||||
* know you do.
|
||||
|
|
|
@ -709,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
|
||||
|
@ -774,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
|
||||
|
@ -2840,7 +2847,8 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
|
|||
*
|
||||
* 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.
|
||||
*
|
||||
|
@ -2891,7 +2899,8 @@ psa_status_t psa_sign_hash(mbedtls_svc_key_id_t 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.
|
||||
*
|
||||
|
@ -3465,7 +3474,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
|
||||
|
@ -3475,7 +3485,7 @@ 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;
|
||||
|
@ -3496,8 +3506,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.
|
||||
|
|
144
include/psa/crypto_builtin.h
Normal file
144
include/psa/crypto_builtin.h
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Context structure declaration of the Mbed TLS software-based PSA drivers
|
||||
* called through the PSA Crypto driver dispatch layer.
|
||||
*
|
||||
* \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_H
|
||||
#define PSA_CRYPTO_BUILTIN_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_MD2_C)
|
||||
mbedtls_md2_context md2;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
mbedtls_md4_context md4;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
mbedtls_md5_context md5;
|
||||
#endif
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
mbedtls_ripemd160_context ripemd160;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
mbedtls_sha1_context sha1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
mbedtls_sha256_context sha256;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
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;
|
||||
mbedtls_cipher_context_t cipher;
|
||||
} mbedtls_psa_cipher_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_CIPHER_OPERATION_INIT {0, 0, 0, {0}}
|
||||
|
||||
/*
|
||||
* BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
|
||||
*/
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
|
||||
typedef mbedtls_psa_hash_operation_t mbedtls_transparent_test_driver_hash_operation_t;
|
||||
|
||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_HASH_OPERATION_INIT MBEDTLS_PSA_HASH_OPERATION_INIT
|
||||
|
||||
typedef mbedtls_psa_cipher_operation_t
|
||||
mbedtls_transparent_test_driver_cipher_operation_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int initialised : 1;
|
||||
mbedtls_transparent_test_driver_cipher_operation_t ctx;
|
||||
} mbedtls_opaque_test_driver_cipher_operation_t;
|
||||
|
||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
||||
MBEDTLS_PSA_CIPHER_OPERATION_INIT
|
||||
|
||||
#define MBEDTLS_OPAQUE_TEST_DRIVER_CIPHER_OPERATION_INIT \
|
||||
{ 0, MBEDTLS_TRANSPARENT_TEST_DRIVER_CIPHER_OPERATION_INIT }
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
#endif /* PSA_CRYPTO_BUILTIN_H */
|
|
@ -55,222 +55,6 @@ static inline int psa_key_handle_is_null( psa_key_handle_t handle )
|
|||
return( mbedtls_svc_key_id_is_null( handle ) );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
|
||||
/*
|
||||
* Mechanism for declaring deprecated values
|
||||
*/
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
|
||||
#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_PSA_DEPRECATED
|
||||
#endif
|
||||
|
||||
typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t;
|
||||
typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t;
|
||||
|
||||
#define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY
|
||||
#define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY
|
||||
|
||||
#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
|
||||
( (mbedtls_deprecated_##type) ( value ) )
|
||||
|
||||
/*
|
||||
* Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
|
||||
*/
|
||||
#define PSA_ERROR_UNKNOWN_ERROR \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
|
||||
#define PSA_ERROR_OCCUPIED_SLOT \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
|
||||
#define PSA_ERROR_EMPTY_SLOT \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
|
||||
#define PSA_ERROR_INSUFFICIENT_CAPACITY \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
|
||||
#define PSA_ERROR_TAMPERING_DETECTED \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
|
||||
|
||||
/*
|
||||
* Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
|
||||
*/
|
||||
#define PSA_KEY_USAGE_SIGN \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
|
||||
#define PSA_KEY_USAGE_VERIFY \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
|
||||
|
||||
/*
|
||||
* Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
|
||||
*/
|
||||
#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
|
||||
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)
|
||||
*/
|
||||
MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_sign( psa_key_handle_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash,
|
||||
size_t hash_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length )
|
||||
{
|
||||
return psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length );
|
||||
}
|
||||
|
||||
MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key_handle_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash,
|
||||
size_t hash_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length )
|
||||
{
|
||||
return psa_verify_hash( key, alg, hash, hash_length, signature, signature_length );
|
||||
}
|
||||
|
||||
/*
|
||||
* Size-specific elliptic curve families.
|
||||
*/
|
||||
#define PSA_ECC_CURVE_SECP160K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
|
||||
#define PSA_ECC_CURVE_SECP192K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
|
||||
#define PSA_ECC_CURVE_SECP224K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
|
||||
#define PSA_ECC_CURVE_SECP256K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
|
||||
#define PSA_ECC_CURVE_SECP160R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP192R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP224R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP256R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP384R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP521R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP160R2 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
|
||||
#define PSA_ECC_CURVE_SECT163K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT233K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT239K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT283K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT409K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT571K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT163R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT193R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT233R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT283R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT409R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT571R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT163R2 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
|
||||
#define PSA_ECC_CURVE_SECT193R2 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
|
||||
#define PSA_ECC_CURVE_BRAINPOOL_P256R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
|
||||
#define PSA_ECC_CURVE_BRAINPOOL_P384R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
|
||||
#define PSA_ECC_CURVE_BRAINPOOL_P512R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
|
||||
#define PSA_ECC_CURVE_CURVE25519 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
|
||||
#define PSA_ECC_CURVE_CURVE448 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
|
||||
|
||||
/*
|
||||
* Curves that changed name due to PSA specification.
|
||||
*/
|
||||
#define PSA_ECC_CURVE_SECP_K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
|
||||
#define PSA_ECC_CURVE_SECP_R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
|
||||
#define PSA_ECC_CURVE_SECP_R2 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
|
||||
#define PSA_ECC_CURVE_SECT_K1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
|
||||
#define PSA_ECC_CURVE_SECT_R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
|
||||
#define PSA_ECC_CURVE_SECT_R2 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
|
||||
#define PSA_ECC_CURVE_BRAINPOOL_P_R1 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
|
||||
#define PSA_ECC_CURVE_MONTGOMERY \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
|
||||
|
||||
/*
|
||||
* Finite-field Diffie-Hellman families.
|
||||
*/
|
||||
#define PSA_DH_GROUP_FFDHE2048 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
#define PSA_DH_GROUP_FFDHE3072 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
#define PSA_DH_GROUP_FFDHE4096 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
#define PSA_DH_GROUP_FFDHE6144 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
#define PSA_DH_GROUP_FFDHE8192 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
|
||||
/*
|
||||
* Diffie-Hellman families that changed name due to PSA specification.
|
||||
*/
|
||||
#define PSA_DH_GROUP_RFC7919 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
|
||||
#define PSA_DH_GROUP_CUSTOM \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM )
|
||||
|
||||
/*
|
||||
* Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3)
|
||||
*/
|
||||
#define PSA_ALG_ARC4 \
|
||||
MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER )
|
||||
#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 ) )
|
||||
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/** Open a handle to an existing persistent key.
|
||||
*
|
||||
* Open a handle to a persistent key. A key is persistent if it was created
|
||||
|
@ -313,9 +97,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
|
||||
|
|
|
@ -50,15 +50,22 @@
|
|||
#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_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
|
||||
|
@ -80,6 +87,30 @@
|
|||
#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
|
||||
|
|
69
include/psa/crypto_driver_contexts.h
Normal file
69
include/psa/crypto_driver_contexts.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Declaration of context structures for use with the PSA driver wrapper
|
||||
* interface.
|
||||
*
|
||||
* 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_H
|
||||
#define PSA_CRYPTO_DRIVER_CONTEXTS_H
|
||||
|
||||
#include "psa/crypto.h"
|
||||
#include "psa/crypto_driver_common.h"
|
||||
|
||||
/* Include the context structure definitions for those drivers that were
|
||||
* declared during the autogeneration process. */
|
||||
|
||||
/* Include the context structure definitions for the Mbed TLS software drivers */
|
||||
#include "psa/crypto_builtin.h"
|
||||
|
||||
/* 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_H */
|
||||
/* End of automatically generated file. */
|
|
@ -179,6 +179,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
|
||||
|
@ -303,8 +306,10 @@ void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats );
|
|||
* \param[in] seed Buffer containing the seed value to inject.
|
||||
* \param[in] seed_size Size of the \p seed buffer.
|
||||
* The size of the seed in bytes must be greater
|
||||
* or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM
|
||||
* and #MBEDTLS_ENTROPY_BLOCK_SIZE.
|
||||
* or equal to both #MBEDTLS_ENTROPY_BLOCK_SIZE
|
||||
* and the value of \c MBEDTLS_ENTROPY_MIN_PLATFORM
|
||||
* in `library/entropy_poll.h` in the Mbed TLS source
|
||||
* code.
|
||||
* It must be less or equal to
|
||||
* #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
|
||||
*
|
||||
|
@ -407,10 +412,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)
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -1364,16 +1365,16 @@ 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
|
||||
|
|
|
@ -189,7 +189,7 @@
|
|||
|
||||
/** This macro returns the maximum supported length of the PSK for the
|
||||
* TLS-1.2 PSK-to-MS key derivation
|
||||
* (#PSA_ALG_TLS12_PSK_TO_MS(\p hash_alg)).
|
||||
* (#PSA_ALG_TLS12_PSK_TO_MS(\c hash_alg)).
|
||||
*
|
||||
* The maximum supported length does not depend on the chosen hash algorithm.
|
||||
*
|
||||
|
@ -351,9 +351,10 @@
|
|||
* or the parameters are incompatible, return 0.
|
||||
*/
|
||||
#define PSA_AEAD_NONCE_LENGTH(key_type, alg) \
|
||||
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 && \
|
||||
(PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM || \
|
||||
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_GCM) ? 12 : \
|
||||
(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \
|
||||
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CCM ? 13 : \
|
||||
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_GCM ? 12 : \
|
||||
0 : \
|
||||
(key_type) == PSA_KEY_TYPE_CHACHA20 && \
|
||||
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_CHACHA20_POLY1305 ? 12 : \
|
||||
0)
|
||||
|
@ -369,7 +370,7 @@
|
|||
* just the largest size that may be generated by
|
||||
* #psa_aead_generate_nonce().
|
||||
*/
|
||||
#define PSA_AEAD_NONCE_MAX_SIZE 12
|
||||
#define PSA_AEAD_NONCE_MAX_SIZE 13
|
||||
|
||||
/** A sufficient output buffer size for psa_aead_update().
|
||||
*
|
||||
|
|
|
@ -15,12 +15,20 @@
|
|||
*
|
||||
* <h3>Design notes about multipart operation structures</h3>
|
||||
*
|
||||
* Each multipart operation structure contains a `psa_algorithm_t alg`
|
||||
* field which indicates which specific algorithm the structure is for.
|
||||
* When the structure is not in use, `alg` is 0. Most of the structure
|
||||
* consists of a union which is discriminated by `alg`.
|
||||
* For multipart operations without driver delegation support, each multipart
|
||||
* operation structure contains a `psa_algorithm_t alg` field which indicates
|
||||
* which specific algorithm the structure is for. When the structure is not in
|
||||
* use, `alg` is 0. Most of the structure consists of a union which is
|
||||
* discriminated by `alg`.
|
||||
*
|
||||
* Note that when `alg` is 0, the content of other fields is undefined.
|
||||
* For multipart operations with driver delegation support, each multipart
|
||||
* operation structure contains an `unsigned int id` field indicating which
|
||||
* driver got assigned to do the operation. When the structure is not in use,
|
||||
* 'id' is 0. The structure contains also a driver context which is the union
|
||||
* of the contexts of all drivers able to handle the type of multipart
|
||||
* operation.
|
||||
*
|
||||
* Note that when `alg` or `id` is 0, the content of other fields is undefined.
|
||||
* In particular, it is not guaranteed that a freshly-initialized structure
|
||||
* is all-zero: we initialize structures to something like `{0, 0}`, which
|
||||
* is only guaranteed to initializes the first member of the union;
|
||||
|
@ -65,56 +73,22 @@ extern "C" {
|
|||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/cmac.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/md.h"
|
||||
#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"
|
||||
|
||||
typedef struct {
|
||||
/** Unique ID indicating which driver got assigned to do the
|
||||
* operation. Since driver contexts are driver-specific, swapping
|
||||
* drivers halfway through the operation is not supported.
|
||||
* ID values are auto-generated in psa_driver_wrappers.h */
|
||||
unsigned int id;
|
||||
/** Context structure for the assigned driver, when id is not zero. */
|
||||
void* ctx;
|
||||
} psa_operation_driver_context_t;
|
||||
/* Include the context definition for the compiled-in drivers */
|
||||
#include "psa/crypto_driver_contexts.h"
|
||||
|
||||
struct psa_hash_operation_s
|
||||
{
|
||||
psa_algorithm_t alg;
|
||||
union
|
||||
{
|
||||
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
mbedtls_md2_context md2;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
mbedtls_md4_context md4;
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
mbedtls_md5_context md5;
|
||||
#endif
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
mbedtls_ripemd160_context ripemd160;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
mbedtls_sha1_context sha1;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
mbedtls_sha256_context sha256;
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
mbedtls_sha512_context sha512;
|
||||
#endif
|
||||
} ctx;
|
||||
/** Unique ID indicating which driver got assigned to do the
|
||||
* operation. Since driver contexts are driver-specific, swapping
|
||||
* drivers halfway through the operation is not supported.
|
||||
* ID values are auto-generated in psa_driver_wrappers.h.
|
||||
* ID value zero means the context is not valid or not assigned to
|
||||
* any driver (i.e. the driver context is not active, in use). */
|
||||
unsigned int id;
|
||||
psa_driver_hash_context_t ctx;
|
||||
};
|
||||
|
||||
#define PSA_HASH_OPERATION_INIT {0, {0}}
|
||||
|
@ -127,6 +101,8 @@ static inline struct psa_hash_operation_s psa_hash_operation_init( void )
|
|||
#if defined(MBEDTLS_MD_C)
|
||||
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. */
|
||||
|
@ -164,22 +140,23 @@ static inline struct psa_mac_operation_s psa_mac_operation_init( void )
|
|||
|
||||
struct psa_cipher_operation_s
|
||||
{
|
||||
psa_algorithm_t alg;
|
||||
unsigned int key_set : 1;
|
||||
/** Unique ID indicating which driver got assigned to do the
|
||||
* operation. Since driver contexts are driver-specific, swapping
|
||||
* drivers halfway through the operation is not supported.
|
||||
* ID values are auto-generated in psa_crypto_driver_wrappers.h
|
||||
* ID value zero means the context is not valid or not assigned to
|
||||
* any driver (i.e. none of the driver contexts are active). */
|
||||
unsigned int id;
|
||||
|
||||
unsigned int iv_required : 1;
|
||||
unsigned int iv_set : 1;
|
||||
unsigned int mbedtls_in_use : 1; /* Indicates mbed TLS is handling the operation. */
|
||||
uint8_t iv_size;
|
||||
uint8_t block_size;
|
||||
union
|
||||
{
|
||||
unsigned dummy; /* Enable easier initializing of the union. */
|
||||
mbedtls_cipher_context_t cipher;
|
||||
psa_operation_driver_context_t driver;
|
||||
} ctx;
|
||||
|
||||
uint8_t default_iv_length;
|
||||
|
||||
psa_driver_cipher_context_t ctx;
|
||||
};
|
||||
|
||||
#define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}}
|
||||
#define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, {0}}
|
||||
static inline struct psa_cipher_operation_s psa_cipher_operation_init( void )
|
||||
{
|
||||
const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
|
||||
|
|
|
@ -423,8 +423,8 @@
|
|||
|
||||
/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
|
||||
*
|
||||
* The size of the key can be 8 bytes (single DES), 16 bytes (2-key 3DES) or
|
||||
* 24 bytes (3-key 3DES).
|
||||
* The size of the key can be 64 bits (single DES), 128 bits (2-key 3DES) or
|
||||
* 192 bits (3-key 3DES).
|
||||
*
|
||||
* Note that single DES and 2-key 3DES are weak and strongly
|
||||
* deprecated and should only be used to decrypt legacy data. 3-key 3DES
|
||||
|
@ -451,9 +451,15 @@
|
|||
*/
|
||||
#define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004)
|
||||
|
||||
/** RSA public key. */
|
||||
/** RSA public key.
|
||||
*
|
||||
* The size of an RSA key is the bit size of the modulus.
|
||||
*/
|
||||
#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001)
|
||||
/** RSA key pair (private and public key). */
|
||||
/** RSA key pair (private and public key).
|
||||
*
|
||||
* The size of an RSA key is the bit size of the modulus.
|
||||
*/
|
||||
#define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001)
|
||||
/** Whether a key type is an RSA key (pair or public-only). */
|
||||
#define PSA_KEY_TYPE_IS_RSA(type) \
|
||||
|
@ -463,6 +469,10 @@
|
|||
#define PSA_KEY_TYPE_ECC_KEY_PAIR_BASE ((psa_key_type_t)0x7100)
|
||||
#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x00ff)
|
||||
/** Elliptic curve key pair.
|
||||
*
|
||||
* The size of an elliptic curve key is the bit size associated with the curve,
|
||||
* i.e. the bit size of *q* for a curve over a field *F<sub>q</sub>*.
|
||||
* See the documentation of `PSA_ECC_FAMILY_xxx` curve families for details.
|
||||
*
|
||||
* \param curve A value of type ::psa_ecc_family_t that
|
||||
* identifies the ECC curve to be used.
|
||||
|
@ -470,6 +480,10 @@
|
|||
#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \
|
||||
(PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
|
||||
/** Elliptic curve public key.
|
||||
*
|
||||
* The size of an elliptic curve public key is the same as the corresponding
|
||||
* private key (see #PSA_KEY_TYPE_ECC_KEY_PAIR and the documentation of
|
||||
* `PSA_ECC_FAMILY_xxx` curve families).
|
||||
*
|
||||
* \param curve A value of type ::psa_ecc_family_t that
|
||||
* identifies the ECC curve to be used.
|
||||
|
@ -569,6 +583,22 @@
|
|||
*/
|
||||
#define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41)
|
||||
|
||||
/** The twisted Edwards curves Ed25519 and Ed448.
|
||||
*
|
||||
* These curves are suitable for EdDSA (#PSA_ALG_PURE_EDDSA for both curves,
|
||||
* #PSA_ALG_ED25519PH for the 255-bit curve,
|
||||
* #PSA_ALG_ED448PH for the 448-bit curve).
|
||||
*
|
||||
* This family comprises the following twisted Edwards curves:
|
||||
* - 255-bit: Edwards25519, the twisted Edwards curve birationally equivalent
|
||||
* to Curve25519.
|
||||
* Bernstein et al., _Twisted Edwards curves_, Africacrypt 2008.
|
||||
* - 448-bit: Edwards448, the twisted Edwards curve birationally equivalent
|
||||
* to Curve448.
|
||||
* Hamburg, _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015.
|
||||
*/
|
||||
#define PSA_ECC_FAMILY_TWISTED_EDWARDS ((psa_ecc_family_t) 0x42)
|
||||
|
||||
#define PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE ((psa_key_type_t)0x4200)
|
||||
#define PSA_KEY_TYPE_DH_KEY_PAIR_BASE ((psa_key_type_t)0x7200)
|
||||
#define PSA_KEY_TYPE_DH_GROUP_MASK ((psa_key_type_t)0x00ff)
|
||||
|
@ -787,6 +817,13 @@
|
|||
#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012)
|
||||
/** SHA3-512 */
|
||||
#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013)
|
||||
/** The first 512 bits (64 bytes) of the SHAKE256 output.
|
||||
*
|
||||
* This is the prehashing for Ed448ph (see #PSA_ALG_ED448PH). For other
|
||||
* scenarios where a hash function based on SHA3/SHAKE is desired, SHA3-512
|
||||
* has the same output size and a (theoretically) higher security strength.
|
||||
*/
|
||||
#define PSA_ALG_SHAKE256_512 ((psa_algorithm_t)0x02000015)
|
||||
|
||||
/** In a hash-and-sign algorithm policy, allow any hash algorithm.
|
||||
*
|
||||
|
@ -892,7 +929,7 @@
|
|||
* for policy comparison purposes.
|
||||
*
|
||||
* \param mac_alg A MAC algorithm identifier (value of type
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
|
||||
* is true). This may be a truncated or untruncated
|
||||
* MAC algorithm.
|
||||
* \param mac_length Desired length of the truncated MAC in bytes.
|
||||
|
@ -903,7 +940,7 @@
|
|||
*
|
||||
* \return The corresponding MAC algorithm with the specified
|
||||
* length.
|
||||
* \return Unspecified if \p alg is not a supported
|
||||
* \return Unspecified if \p mac_alg is not a supported
|
||||
* MAC algorithm or if \p mac_length is too small or
|
||||
* too large for the specified MAC algorithm.
|
||||
*/
|
||||
|
@ -916,12 +953,12 @@
|
|||
* MAC algorithm.
|
||||
*
|
||||
* \param mac_alg A MAC algorithm identifier (value of type
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
|
||||
* is true). This may be a truncated or untruncated
|
||||
* MAC algorithm.
|
||||
*
|
||||
* \return The corresponding base MAC algorithm.
|
||||
* \return Unspecified if \p alg is not a supported
|
||||
* \return Unspecified if \p mac_alg is not a supported
|
||||
* MAC algorithm.
|
||||
*/
|
||||
#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
|
||||
|
@ -931,12 +968,12 @@
|
|||
/** Length to which a MAC algorithm is truncated.
|
||||
*
|
||||
* \param mac_alg A MAC algorithm identifier (value of type
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
|
||||
* is true).
|
||||
*
|
||||
* \return Length of the truncated MAC in bytes.
|
||||
* \return 0 if \p alg is a non-truncated MAC algorithm.
|
||||
* \return Unspecified if \p alg is not a supported
|
||||
* \return 0 if \p mac_alg is a non-truncated MAC algorithm.
|
||||
* \return Unspecified if \p mac_alg is not a supported
|
||||
* MAC algorithm.
|
||||
*/
|
||||
#define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
|
||||
|
@ -1146,13 +1183,13 @@
|
|||
* of the ciphertext.
|
||||
*
|
||||
* \param aead_alg An AEAD algorithm identifier (value of type
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg)
|
||||
* is true).
|
||||
* \param tag_length Desired length of the authentication tag in bytes.
|
||||
*
|
||||
* \return The corresponding AEAD algorithm with the specified
|
||||
* length.
|
||||
* \return Unspecified if \p alg is not a supported
|
||||
* \return Unspecified if \p aead_alg is not a supported
|
||||
* AEAD algorithm or if \p tag_length is not valid
|
||||
* for the specified AEAD algorithm.
|
||||
*/
|
||||
|
@ -1165,13 +1202,12 @@
|
|||
/** Retrieve the tag length of a specified AEAD algorithm
|
||||
*
|
||||
* \param aead_alg An AEAD algorithm identifier (value of type
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
|
||||
* #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg)
|
||||
* is true).
|
||||
*
|
||||
* \return The tag length specified by the input algorithm.
|
||||
* \return Unspecified if \p alg is not a supported
|
||||
* AEAD algorithm or if \p tag_length is not valid
|
||||
* for the specified AEAD algorithm.
|
||||
* \return Unspecified if \p aead_alg is not a supported
|
||||
* AEAD algorithm.
|
||||
*/
|
||||
#define PSA_ALG_AEAD_GET_TAG_LENGTH(aead_alg) \
|
||||
(((aead_alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> \
|
||||
|
@ -1180,7 +1216,7 @@
|
|||
/** Calculate the corresponding AEAD algorithm with the default tag length.
|
||||
*
|
||||
* \param aead_alg An AEAD algorithm (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
* #PSA_ALG_IS_AEAD(\p aead_alg) is true).
|
||||
*
|
||||
* \return The corresponding AEAD algorithm with the default
|
||||
* tag length for that algorithm.
|
||||
|
@ -1345,6 +1381,94 @@
|
|||
#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
|
||||
(PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
|
||||
|
||||
/** Edwards-curve digital signature algorithm without prehashing (PureEdDSA),
|
||||
* using standard parameters.
|
||||
*
|
||||
* Contexts are not supported in the current version of this specification
|
||||
* because there is no suitable signature interface that can take the
|
||||
* context as a parameter. A future version of this specification may add
|
||||
* suitable functions and extend this algorithm to support contexts.
|
||||
*
|
||||
* PureEdDSA requires an elliptic curve key on a twisted Edwards curve.
|
||||
* In this specification, the following curves are supported:
|
||||
* - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 255-bit: Ed25519 as specified
|
||||
* in RFC 8032.
|
||||
* The curve is Edwards25519.
|
||||
* The hash function used internally is SHA-512.
|
||||
* - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 448-bit: Ed448 as specified
|
||||
* in RFC 8032.
|
||||
* The curve is Edwards448.
|
||||
* The hash function used internally is the first 114 bytes of the
|
||||
* SHAKE256 output.
|
||||
*
|
||||
* This algorithm can be used with psa_sign_message() and
|
||||
* psa_verify_message(). Since there is no prehashing, it cannot be used
|
||||
* with psa_sign_hash() or psa_verify_hash().
|
||||
*
|
||||
* The signature format is the concatenation of R and S as defined by
|
||||
* RFC 8032 §5.1.6 and §5.2.6 (a 64-byte string for Ed25519, a 114-byte
|
||||
* string for Ed448).
|
||||
*/
|
||||
#define PSA_ALG_PURE_EDDSA ((psa_algorithm_t)0x06000800)
|
||||
|
||||
#define PSA_ALG_HASH_EDDSA_BASE ((psa_algorithm_t)0x06000900)
|
||||
#define PSA_ALG_IS_HASH_EDDSA(alg) \
|
||||
(((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HASH_EDDSA_BASE)
|
||||
|
||||
/** Edwards-curve digital signature algorithm with prehashing (HashEdDSA),
|
||||
* using SHA-512 and the Edwards25519 curve.
|
||||
*
|
||||
* See #PSA_ALG_PURE_EDDSA regarding context support and the signature format.
|
||||
*
|
||||
* This algorithm is Ed25519 as specified in RFC 8032.
|
||||
* The curve is Edwards25519.
|
||||
* The prehash is SHA-512.
|
||||
* The hash function used internally is SHA-512.
|
||||
*
|
||||
* This is a hash-and-sign algorithm: to calculate a signature,
|
||||
* you can either:
|
||||
* - call psa_sign_message() on the message;
|
||||
* - or calculate the SHA-512 hash of the message
|
||||
* with psa_hash_compute()
|
||||
* or with a multi-part hash operation started with psa_hash_setup(),
|
||||
* using the hash algorithm #PSA_ALG_SHA_512,
|
||||
* then sign the calculated hash with psa_sign_hash().
|
||||
* Verifying a signature is similar, using psa_verify_message() or
|
||||
* psa_verify_hash() instead of the signature function.
|
||||
*/
|
||||
#define PSA_ALG_ED25519PH \
|
||||
(PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHA_512 & PSA_ALG_HASH_MASK))
|
||||
|
||||
/** Edwards-curve digital signature algorithm with prehashing (HashEdDSA),
|
||||
* using SHAKE256 and the Edwards448 curve.
|
||||
*
|
||||
* See #PSA_ALG_PURE_EDDSA regarding context support and the signature format.
|
||||
*
|
||||
* This algorithm is Ed448 as specified in RFC 8032.
|
||||
* The curve is Edwards448.
|
||||
* The prehash is the first 64 bytes of the SHAKE256 output.
|
||||
* The hash function used internally is the first 114 bytes of the
|
||||
* SHAKE256 output.
|
||||
*
|
||||
* This is a hash-and-sign algorithm: to calculate a signature,
|
||||
* you can either:
|
||||
* - call psa_sign_message() on the message;
|
||||
* - or calculate the first 64 bytes of the SHAKE256 output of the message
|
||||
* with psa_hash_compute()
|
||||
* or with a multi-part hash operation started with psa_hash_setup(),
|
||||
* using the hash algorithm #PSA_ALG_SHAKE256_512,
|
||||
* then sign the calculated hash with psa_sign_hash().
|
||||
* Verifying a signature is similar, using psa_verify_message() or
|
||||
* psa_verify_hash() instead of the signature function.
|
||||
*/
|
||||
#define PSA_ALG_ED448PH \
|
||||
(PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHAKE256_512 & PSA_ALG_HASH_MASK))
|
||||
|
||||
/* Default definition, to be overridden if the library is extended with
|
||||
* more hash-and-sign algorithms that we want to keep out of this header
|
||||
* file. */
|
||||
#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) 0
|
||||
|
||||
/** Whether the specified algorithm is a hash-and-sign algorithm.
|
||||
*
|
||||
* Hash-and-sign algorithms are asymmetric (public-key) signature algorithms
|
||||
|
@ -1360,7 +1484,8 @@
|
|||
*/
|
||||
#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
|
||||
(PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
|
||||
PSA_ALG_IS_ECDSA(alg))
|
||||
PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_HASH_EDDSA(alg) || \
|
||||
PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg))
|
||||
|
||||
/** Get the hash used by a hash-and-sign signature algorithm.
|
||||
*
|
||||
|
|
|
@ -39,7 +39,6 @@ set(src_crypto
|
|||
entropy_poll.c
|
||||
error.c
|
||||
gcm.c
|
||||
havege.c
|
||||
hkdf.c
|
||||
hmac_drbg.c
|
||||
md.c
|
||||
|
@ -47,6 +46,8 @@ set(src_crypto
|
|||
md4.c
|
||||
md5.c
|
||||
memory_buffer_alloc.c
|
||||
mps_reader.c
|
||||
mps_trace.c
|
||||
nist_kw.c
|
||||
oid.c
|
||||
padlock.c
|
||||
|
@ -61,9 +62,12 @@ set(src_crypto
|
|||
platform_util.c
|
||||
poly1305.c
|
||||
psa_crypto.c
|
||||
psa_crypto_aead.c
|
||||
psa_crypto_cipher.c
|
||||
psa_crypto_client.c
|
||||
psa_crypto_driver_wrappers.c
|
||||
psa_crypto_ecp.c
|
||||
psa_crypto_hash.c
|
||||
psa_crypto_rsa.c
|
||||
psa_crypto_se.c
|
||||
psa_crypto_slot_management.c
|
||||
|
@ -71,7 +75,7 @@ set(src_crypto
|
|||
psa_its_file.c
|
||||
ripemd160.c
|
||||
rsa.c
|
||||
rsa_internal.c
|
||||
rsa_alt_helpers.c
|
||||
sha1.c
|
||||
sha256.c
|
||||
sha512.c
|
||||
|
@ -85,7 +89,6 @@ set(src_crypto
|
|||
list(APPEND src_crypto ${thirdparty_src})
|
||||
|
||||
set(src_x509
|
||||
certs.c
|
||||
pkcs11.c
|
||||
x509.c
|
||||
x509_create.c
|
||||
|
@ -137,10 +140,6 @@ if(USE_PKCS11_HELPER_LIBRARY)
|
|||
set(libs ${libs} pkcs11-helper)
|
||||
endif(USE_PKCS11_HELPER_LIBRARY)
|
||||
|
||||
if(ENABLE_ZLIB_SUPPORT)
|
||||
set(libs ${libs} ${ZLIB_LIBRARIES})
|
||||
endif(ENABLE_ZLIB_SUPPORT)
|
||||
|
||||
if(LINK_WITH_PTHREAD)
|
||||
set(libs ${libs} pthread)
|
||||
endif()
|
||||
|
|
|
@ -96,7 +96,6 @@ OBJS_CRYPTO= \
|
|||
entropy_poll.o \
|
||||
error.o \
|
||||
gcm.o \
|
||||
havege.o \
|
||||
hkdf.o \
|
||||
hmac_drbg.o \
|
||||
md.o \
|
||||
|
@ -104,6 +103,8 @@ OBJS_CRYPTO= \
|
|||
md4.o \
|
||||
md5.o \
|
||||
memory_buffer_alloc.o \
|
||||
mps_reader.o \
|
||||
mps_trace.o \
|
||||
nist_kw.o \
|
||||
oid.o \
|
||||
padlock.o \
|
||||
|
@ -118,9 +119,12 @@ OBJS_CRYPTO= \
|
|||
platform_util.o \
|
||||
poly1305.o \
|
||||
psa_crypto.o \
|
||||
psa_crypto_aead.o \
|
||||
psa_crypto_cipher.o \
|
||||
psa_crypto_client.o \
|
||||
psa_crypto_driver_wrappers.o \
|
||||
psa_crypto_ecp.o \
|
||||
psa_crypto_hash.o \
|
||||
psa_crypto_rsa.o \
|
||||
psa_crypto_se.o \
|
||||
psa_crypto_slot_management.o \
|
||||
|
@ -128,7 +132,7 @@ OBJS_CRYPTO= \
|
|||
psa_its_file.o \
|
||||
ripemd160.o \
|
||||
rsa.o \
|
||||
rsa_internal.o \
|
||||
rsa_alt_helpers.o \
|
||||
sha1.o \
|
||||
sha256.o \
|
||||
sha512.o \
|
||||
|
@ -144,7 +148,6 @@ LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
|
|||
OBJS_CRYPTO+=$(THIRDPARTY_CRYPTO_OBJECTS)
|
||||
|
||||
OBJS_X509= \
|
||||
certs.o \
|
||||
pkcs11.o \
|
||||
x509.o \
|
||||
x509_create.o \
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
#include "mbedtls/padlock.h"
|
||||
#include "padlock.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head )
|
|||
}
|
||||
}
|
||||
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
|
||||
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len )
|
||||
{
|
||||
while( list != NULL )
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
|
||||
int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start, size_t len )
|
||||
{
|
||||
if( len < 0x80 )
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len
|
|||
#endif
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start, unsigned char tag )
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start, unsigned char tag )
|
||||
{
|
||||
if( *p - start < 1 )
|
||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
@ -108,7 +108,7 @@ int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start, unsigned ch
|
|||
return( 1 );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size )
|
||||
{
|
||||
size_t len = 0;
|
||||
|
@ -124,7 +124,7 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
|
|||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X )
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start, const mbedtls_mpi *X )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -161,7 +161,7 @@ cleanup:
|
|||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start )
|
||||
int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -174,7 +174,7 @@ int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start )
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -188,7 +188,7 @@ int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len )
|
||||
{
|
||||
|
@ -209,7 +209,7 @@ int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *s
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean )
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start, int boolean )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -226,7 +226,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolea
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
static int asn1_write_tagged_int( unsigned char **p, unsigned char *start, int val, int tag )
|
||||
static int asn1_write_tagged_int( unsigned char **p, const unsigned char *start, int val, int tag )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t len = 0;
|
||||
|
@ -255,17 +255,17 @@ static int asn1_write_tagged_int( unsigned char **p, unsigned char *start, int v
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val )
|
||||
int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val )
|
||||
{
|
||||
return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_INTEGER ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, unsigned char *start, int val )
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val )
|
||||
{
|
||||
return( asn1_write_tagged_int( p, start, val, MBEDTLS_ASN1_ENUMERATED ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, int tag,
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start, int tag,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -280,26 +280,26 @@ int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, i
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len )
|
||||
{
|
||||
return( mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
||||
unsigned char *start,
|
||||
const unsigned char *start,
|
||||
const unsigned char *buf,
|
||||
size_t bits )
|
||||
{
|
||||
|
@ -341,7 +341,7 @@ int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
|||
return( mbedtls_asn1_write_bitstring( p, start, buf, bits ) );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t bits )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -374,7 +374,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
|
165
library/bignum.c
165
library/bignum.c
|
@ -38,7 +38,7 @@
|
|||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/bn_mul.h"
|
||||
#include "bn_mul.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -470,6 +470,7 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s )
|
|||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t i, j, slen, n;
|
||||
int sign = 1;
|
||||
mbedtls_mpi_uint d;
|
||||
mbedtls_mpi T;
|
||||
MPI_VALIDATE_RET( X != NULL );
|
||||
|
@ -480,6 +481,12 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s )
|
|||
|
||||
mbedtls_mpi_init( &T );
|
||||
|
||||
if( s[0] == '-' )
|
||||
{
|
||||
++s;
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
slen = strlen( s );
|
||||
|
||||
if( radix == 16 )
|
||||
|
@ -494,12 +501,6 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s )
|
|||
|
||||
for( i = slen, j = 0; i > 0; i--, j++ )
|
||||
{
|
||||
if( i == 1 && s[i - 1] == '-' )
|
||||
{
|
||||
X->s = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) );
|
||||
X->p[j / ( 2 * ciL )] |= d << ( ( j % ( 2 * ciL ) ) << 2 );
|
||||
}
|
||||
|
@ -510,26 +511,15 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s )
|
|||
|
||||
for( i = 0; i < slen; i++ )
|
||||
{
|
||||
if( i == 0 && s[i] == '-' )
|
||||
{
|
||||
X->s = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i] ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T, X, radix ) );
|
||||
|
||||
if( X->s == 1 )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, &T, d ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( X, &T, d ) );
|
||||
}
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, &T, d ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( sign < 0 && mbedtls_mpi_bitlen( X ) != 0 )
|
||||
X->s = -1;
|
||||
|
||||
cleanup:
|
||||
|
||||
mbedtls_mpi_free( &T );
|
||||
|
@ -1339,29 +1329,32 @@ cleanup:
|
|||
/**
|
||||
* Helper for mbedtls_mpi subtraction.
|
||||
*
|
||||
* Calculate d - s where d and s have the same size.
|
||||
* Calculate l - r where l and r have the same size.
|
||||
* This function operates modulo (2^ciL)^n and returns the carry
|
||||
* (1 if there was a wraparound, i.e. if `d < s`, and 0 otherwise).
|
||||
* (1 if there was a wraparound, i.e. if `l < r`, and 0 otherwise).
|
||||
*
|
||||
* \param n Number of limbs of \p d and \p s.
|
||||
* \param[in,out] d On input, the left operand.
|
||||
* On output, the result of the subtraction:
|
||||
* \param[in] s The right operand.
|
||||
* d may be aliased to l or r.
|
||||
*
|
||||
* \return 1 if `d < s`.
|
||||
* 0 if `d >= s`.
|
||||
* \param n Number of limbs of \p d, \p l and \p r.
|
||||
* \param[out] d The result of the subtraction.
|
||||
* \param[in] l The left operand.
|
||||
* \param[in] r The right operand.
|
||||
*
|
||||
* \return 1 if `l < r`.
|
||||
* 0 if `l >= r`.
|
||||
*/
|
||||
static mbedtls_mpi_uint mpi_sub_hlp( size_t n,
|
||||
mbedtls_mpi_uint *d,
|
||||
const mbedtls_mpi_uint *s )
|
||||
const mbedtls_mpi_uint *l,
|
||||
const mbedtls_mpi_uint *r )
|
||||
{
|
||||
size_t i;
|
||||
mbedtls_mpi_uint c, z;
|
||||
mbedtls_mpi_uint c = 0, t, z;
|
||||
|
||||
for( i = c = 0; i < n; i++, s++, d++ )
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
z = ( *d < c ); *d -= c;
|
||||
c = ( *d < *s ) + z; *d -= *s;
|
||||
z = ( l[i] < c ); t = l[i] - c;
|
||||
c = ( t < r[i] ) + z; d[i] = t - r[i];
|
||||
}
|
||||
|
||||
return( c );
|
||||
|
@ -1372,7 +1365,6 @@ static mbedtls_mpi_uint mpi_sub_hlp( size_t n,
|
|||
*/
|
||||
int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B )
|
||||
{
|
||||
mbedtls_mpi TB;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t n;
|
||||
mbedtls_mpi_uint carry;
|
||||
|
@ -1380,24 +1372,6 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
MPI_VALIDATE_RET( A != NULL );
|
||||
MPI_VALIDATE_RET( B != NULL );
|
||||
|
||||
mbedtls_mpi_init( &TB );
|
||||
|
||||
if( X == B )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TB, B ) );
|
||||
B = &TB;
|
||||
}
|
||||
|
||||
if( X != A )
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) );
|
||||
|
||||
/*
|
||||
* X should always be positive as a result of unsigned subtractions.
|
||||
*/
|
||||
X->s = 1;
|
||||
|
||||
ret = 0;
|
||||
|
||||
for( n = B->n; n > 0; n-- )
|
||||
if( B->p[n - 1] != 0 )
|
||||
break;
|
||||
|
@ -1408,7 +1382,17 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
carry = mpi_sub_hlp( n, X->p, B->p );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, A->n ) );
|
||||
|
||||
/* Set the high limbs of X to match A. Don't touch the lower limbs
|
||||
* because X might be aliased to B, and we must not overwrite the
|
||||
* significant digits of B. */
|
||||
if( A->n > n )
|
||||
memcpy( X->p + n, A->p + n, ( A->n - n ) * ciL );
|
||||
if( X->n > A->n )
|
||||
memset( X->p + A->n, 0, ( X->n - A->n ) * ciL );
|
||||
|
||||
carry = mpi_sub_hlp( n, X->p, A->p, B->p );
|
||||
if( carry != 0 )
|
||||
{
|
||||
/* Propagate the carry to the first nonzero limb of X. */
|
||||
|
@ -1424,10 +1408,10 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi
|
|||
--X->p[n];
|
||||
}
|
||||
|
||||
/* X should always be positive as a result of unsigned subtractions. */
|
||||
X->s = 1;
|
||||
|
||||
cleanup:
|
||||
|
||||
mbedtls_mpi_free( &TB );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
|
@ -1537,8 +1521,21 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint
|
|||
return( mbedtls_mpi_sub_mpi( X, A, &_B ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for mbedtls_mpi multiplication
|
||||
/** Helper for mbedtls_mpi multiplication.
|
||||
*
|
||||
* Add \p b * \p s to \p d.
|
||||
*
|
||||
* \param i The number of limbs of \p s.
|
||||
* \param[in] s A bignum to multiply, of size \p i.
|
||||
* It may overlap with \p d, but only if
|
||||
* \p d <= \p s.
|
||||
* Its leading limb must not be \c 0.
|
||||
* \param[in,out] d The bignum to add to.
|
||||
* It must be sufficiently large to store the
|
||||
* result of the multiplication. This means
|
||||
* \p i + 1 limbs if \p d[\p i - 1] started as 0 and \p b
|
||||
* is not known a priori.
|
||||
* \param b A scalar to multiply.
|
||||
*/
|
||||
static
|
||||
#if defined(__APPLE__) && defined(__arm__)
|
||||
|
@ -1548,7 +1545,10 @@ static
|
|||
*/
|
||||
__attribute__ ((noinline))
|
||||
#endif
|
||||
void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mpi_uint b )
|
||||
void mpi_mul_hlp( size_t i,
|
||||
const mbedtls_mpi_uint *s,
|
||||
mbedtls_mpi_uint *d,
|
||||
mbedtls_mpi_uint b )
|
||||
{
|
||||
mbedtls_mpi_uint c = 0, t = 0;
|
||||
|
||||
|
@ -1603,10 +1603,10 @@ void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mp
|
|||
|
||||
t++;
|
||||
|
||||
do {
|
||||
while( c != 0 )
|
||||
{
|
||||
*d += c; c = ( *d < c ); d++;
|
||||
}
|
||||
while( c != 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1654,17 +1654,38 @@ cleanup:
|
|||
*/
|
||||
int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b )
|
||||
{
|
||||
mbedtls_mpi _B;
|
||||
mbedtls_mpi_uint p[1];
|
||||
MPI_VALIDATE_RET( X != NULL );
|
||||
MPI_VALIDATE_RET( A != NULL );
|
||||
|
||||
_B.s = 1;
|
||||
_B.n = 1;
|
||||
_B.p = p;
|
||||
p[0] = b;
|
||||
/* mpi_mul_hlp can't deal with a leading 0. */
|
||||
size_t n = A->n;
|
||||
while( n > 0 && A->p[n - 1] == 0 )
|
||||
--n;
|
||||
|
||||
return( mbedtls_mpi_mul_mpi( X, A, &_B ) );
|
||||
/* The general method below doesn't work if n==0 or b==0. By chance
|
||||
* calculating the result is trivial in those cases. */
|
||||
if( b == 0 || n == 0 )
|
||||
{
|
||||
mbedtls_mpi_lset( X, 0 );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Calculate A*b as A + A*(b-1) to take advantage of mpi_mul_hlp */
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
/* In general, A * b requires 1 limb more than b. If
|
||||
* A->p[n - 1] * b / b == A->p[n - 1], then A * b fits in the same
|
||||
* number of limbs as A and the call to grow() is not required since
|
||||
* copy() will take care of the growth if needed. However, experimentally,
|
||||
* making the call to grow() unconditional causes slightly fewer
|
||||
* calls to calloc() in ECP code, presumably because it reuses the
|
||||
* same mpi for a while and this way the mpi is more likely to directly
|
||||
* grow to its final size. */
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, n + 1 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) );
|
||||
mpi_mul_hlp( n, A->p, X->p, b - 1 );
|
||||
|
||||
cleanup:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1805,7 +1826,7 @@ int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
|||
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &Z, A->n + 2 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Z, 0 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &T1, 2 ) );
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &T1, A->n + 2 ) );
|
||||
|
||||
k = mbedtls_mpi_bitlen( &Y ) % biL;
|
||||
if( k < biL - 1 )
|
||||
|
@ -2071,7 +2092,7 @@ static void mpi_montmul( mbedtls_mpi *A, const mbedtls_mpi *B, const mbedtls_mpi
|
|||
* do the calculation without using conditional tests. */
|
||||
/* Set d to d0 + (2^biL)^n - N where d0 is the current value of d. */
|
||||
d[n] += 1;
|
||||
d[n] -= mpi_sub_hlp( n, d, N->p );
|
||||
d[n] -= mpi_sub_hlp( n, d, d, N->p );
|
||||
/* If d0 < N then d < (2^biL)^n
|
||||
* so d[n] == 0 and we want to keep A as it is.
|
||||
* If d0 >= N then d >= (2^biL)^n, and d <= (2^biL)^n + N < 2 * (2^biL)^n
|
||||
|
|
|
@ -28,6 +28,19 @@
|
|||
#ifndef MBEDTLS_CHECK_CRYPTO_CONFIG_H
|
||||
#define MBEDTLS_CHECK_CRYPTO_CONFIG_H
|
||||
|
||||
#if defined(PSA_WANT_ALG_CCM) && \
|
||||
!( defined(PSA_WANT_KEY_TYPE_AES) || \
|
||||
defined(PSA_WANT_KEY_TYPE_CAMELLIA) )
|
||||
#error "PSA_WANT_ALG_CCM defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_CMAC) && \
|
||||
!( defined(PSA_WANT_KEY_TYPE_AES) || \
|
||||
defined(PSA_WANT_KEY_TYPE_CAMELLIA) || \
|
||||
defined(PSA_WANT_KEY_TYPE_DES) )
|
||||
#error "PSA_WANT_ALG_CMAC defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA) && \
|
||||
!( defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||
|
@ -40,6 +53,12 @@
|
|||
#error "PSA_WANT_ALG_ECDSA defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_GCM) && \
|
||||
!( defined(PSA_WANT_KEY_TYPE_AES) || \
|
||||
defined(PSA_WANT_KEY_TYPE_CAMELLIA) )
|
||||
#error "PSA_WANT_ALG_GCM defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT) && \
|
||||
!( defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#if defined(MBEDTLS_CIPHER_C)
|
||||
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/cipher_internal.h"
|
||||
#include "cipher_wrap.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#if defined(MBEDTLS_CIPHER_C)
|
||||
|
||||
#include "mbedtls/cipher_internal.h"
|
||||
#include "cipher_wrap.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \file cipher_internal.h
|
||||
* \file cipher_wrap.h
|
||||
*
|
||||
* \brief Cipher wrappers.
|
||||
*
|
|
@ -273,7 +273,7 @@ static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info,
|
|||
|
||||
r_len = *(*p)++;
|
||||
|
||||
if( end < *p || (size_t)( end - *p ) < r_len )
|
||||
if( end < *p || (size_t)( end - *p ) < r_len || r_len == 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
|
||||
goto cleanup;
|
||||
|
|
|
@ -77,6 +77,8 @@
|
|||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#include "ecp_invasive.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
@ -97,7 +99,7 @@
|
|||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#include "mbedtls/ecp_internal.h"
|
||||
#include "ecp_alt.h"
|
||||
|
||||
#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
|
||||
#if defined(MBEDTLS_HMAC_DRBG_C)
|
||||
|
@ -2808,7 +2810,7 @@ cleanup:
|
|||
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/*
|
||||
* R = m * P with shortcuts for m == 1 and m == -1
|
||||
* R = m * P with shortcuts for m == 0, m == 1 and m == -1
|
||||
* NOT constant-time - ONLY for short Weierstrass!
|
||||
*/
|
||||
static int mbedtls_ecp_mul_shortcuts( mbedtls_ecp_group *grp,
|
||||
|
@ -2819,7 +2821,11 @@ static int mbedtls_ecp_mul_shortcuts( mbedtls_ecp_group *grp,
|
|||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( mbedtls_mpi_cmp_int( m, 1 ) == 0 )
|
||||
if( mbedtls_mpi_cmp_int( m, 0 ) == 0 )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_set_zero( R ) );
|
||||
}
|
||||
else if( mbedtls_mpi_cmp_int( m, 1 ) == 0 )
|
||||
{
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_copy( R, P ) );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \file ecp_internal.h
|
||||
* \file ecp_alt.h
|
||||
*
|
||||
* \brief Function declarations for alternative implementation of elliptic curve
|
||||
* point arithmetic.
|
||||
|
@ -293,5 +293,5 @@ int mbedtls_internal_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
|
|||
|
||||
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
|
||||
|
||||
#endif /* ecp_internal.h */
|
||||
#endif /* ecp_alt.h */
|
||||
|
|
@ -25,6 +25,8 @@
|
|||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#include "ecp_invasive.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(MBEDTLS_ECP_ALT)
|
||||
|
@ -1000,25 +1002,20 @@ static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
|
|||
#define ADD( j ) add32( &cur, A( j ), &c );
|
||||
#define SUB( j ) sub32( &cur, A( j ), &c );
|
||||
|
||||
#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
|
||||
#define biL (ciL << 3) /* bits in limb */
|
||||
|
||||
/*
|
||||
* Helpers for the main 'loop'
|
||||
* (see fix_negative for the motivation of C)
|
||||
*/
|
||||
#define INIT( b ) \
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; \
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; \
|
||||
signed char c = 0, cc; \
|
||||
uint32_t cur; \
|
||||
size_t i = 0, bits = (b); \
|
||||
mbedtls_mpi C; \
|
||||
mbedtls_mpi_uint Cp[ (b) / 8 / sizeof( mbedtls_mpi_uint) + 1 ]; \
|
||||
\
|
||||
C.s = 1; \
|
||||
C.n = (b) / 8 / sizeof( mbedtls_mpi_uint) + 1; \
|
||||
C.p = Cp; \
|
||||
memset( Cp, 0, C.n * sizeof( mbedtls_mpi_uint ) ); \
|
||||
\
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, (b) * 2 / 8 / \
|
||||
sizeof( mbedtls_mpi_uint ) ) ); \
|
||||
/* N is the size of the product of two b-bit numbers, plus one */ \
|
||||
/* limb for fix_negative */ \
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_grow( N, ( b ) * 2 / biL + 1 ) ); \
|
||||
LOAD32;
|
||||
|
||||
#define NEXT \
|
||||
|
@ -1033,33 +1030,41 @@ static inline void sub32( uint32_t *dst, uint32_t src, signed char *carry )
|
|||
STORE32; i++; \
|
||||
cur = c > 0 ? c : 0; STORE32; \
|
||||
cur = 0; while( ++i < MAX32 ) { STORE32; } \
|
||||
if( c < 0 ) MBEDTLS_MPI_CHK( fix_negative( N, c, &C, bits ) );
|
||||
if( c < 0 ) mbedtls_ecp_fix_negative( N, c, bits );
|
||||
|
||||
/*
|
||||
* If the result is negative, we get it in the form
|
||||
* c * 2^(bits + 32) + N, with c negative and N positive shorter than 'bits'
|
||||
* c * 2^bits + N, with c negative and N positive shorter than 'bits'
|
||||
*/
|
||||
static inline int fix_negative( mbedtls_mpi *N, signed char c, mbedtls_mpi *C, size_t bits )
|
||||
MBEDTLS_STATIC_TESTABLE
|
||||
void mbedtls_ecp_fix_negative( mbedtls_mpi *N, signed char c, size_t bits )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
size_t i;
|
||||
|
||||
/* C = - c * 2^(bits + 32) */
|
||||
#if !defined(MBEDTLS_HAVE_INT64)
|
||||
((void) bits);
|
||||
#else
|
||||
if( bits == 224 )
|
||||
C->p[ C->n - 1 ] = ((mbedtls_mpi_uint) -c) << 32;
|
||||
else
|
||||
#endif
|
||||
C->p[ C->n - 1 ] = (mbedtls_mpi_uint) -c;
|
||||
|
||||
/* N = - ( C - N ) */
|
||||
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( N, C, N ) );
|
||||
/* Set N := 2^bits - 1 - N. We know that 0 <= N < 2^bits, so
|
||||
* set the absolute value to 0xfff...fff - N. There is no carry
|
||||
* since we're subtracting from all-bits-one. */
|
||||
for( i = 0; i <= bits / 8 / sizeof( mbedtls_mpi_uint ); i++ )
|
||||
{
|
||||
N->p[i] = ~(mbedtls_mpi_uint)0 - N->p[i];
|
||||
}
|
||||
/* Add 1, taking care of the carry. */
|
||||
i = 0;
|
||||
do
|
||||
++N->p[i];
|
||||
while( N->p[i++] == 0 && i <= bits / 8 / sizeof( mbedtls_mpi_uint ) );
|
||||
/* Invert the sign.
|
||||
* Now N = N0 - 2^bits where N0 is the initial value of N. */
|
||||
N->s = -1;
|
||||
|
||||
cleanup:
|
||||
|
||||
return( ret );
|
||||
/* Add |c| * 2^bits to the absolute value. Since c and N are
|
||||
* negative, this adds c * 2^bits. */
|
||||
mbedtls_mpi_uint msw = (mbedtls_mpi_uint) -c;
|
||||
#if defined(MBEDTLS_HAVE_INT64)
|
||||
if( bits == 224 )
|
||||
msw <<= 32;
|
||||
#endif
|
||||
N->p[bits / 8 / sizeof( mbedtls_mpi_uint)] += msw;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
|
|
51
library/ecp_invasive.h
Normal file
51
library/ecp_invasive.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* \file ecp_invasive.h
|
||||
*
|
||||
* \brief ECP module: interfaces for invasive testing only.
|
||||
*
|
||||
* The interfaces in this file are intended for testing purposes only.
|
||||
* They SHOULD NOT be made available in library integrations except when
|
||||
* building the library for testing.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBEDTLS_ECP_INVASIVE_H
|
||||
#define MBEDTLS_ECP_INVASIVE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ECP_C)
|
||||
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
|
||||
defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
|
||||
defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
/* Preconditions:
|
||||
* - bits is a multiple of 64 or is 224
|
||||
* - c is -1 or -2
|
||||
* - 0 <= N < 2^bits
|
||||
* - N has room for bits plus one limb
|
||||
*
|
||||
* Behavior:
|
||||
* Set N to c * 2^bits + old_value_of_N.
|
||||
*/
|
||||
void mbedtls_ecp_fix_negative( mbedtls_mpi *N, signed char c, size_t bits );
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_ECP_C */
|
||||
|
||||
#endif /* MBEDTLS_ECP_INVASIVE_H */
|
|
@ -28,7 +28,7 @@
|
|||
#endif
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "entropy_poll.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
@ -51,9 +51,6 @@
|
|||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
|
||||
#define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */
|
||||
|
||||
|
@ -72,9 +69,6 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
|
|||
#else
|
||||
mbedtls_sha256_init( &ctx->accumulator );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_havege_init( &ctx->havege_data );
|
||||
#endif
|
||||
|
||||
/* Reminder: Update ENTROPY_HAVE_STRONG in the test files
|
||||
* when adding more strong entropy sources here. */
|
||||
|
@ -95,11 +89,6 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx )
|
|||
MBEDTLS_ENTROPY_MIN_HARDCLOCK,
|
||||
MBEDTLS_ENTROPY_SOURCE_WEAK );
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_entropy_add_source( ctx, mbedtls_havege_poll, &ctx->havege_data,
|
||||
MBEDTLS_ENTROPY_MIN_HAVEGE,
|
||||
MBEDTLS_ENTROPY_SOURCE_STRONG );
|
||||
#endif
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
mbedtls_entropy_add_source( ctx, mbedtls_hardware_poll, NULL,
|
||||
MBEDTLS_ENTROPY_MIN_HARDWARE,
|
||||
|
@ -121,9 +110,6 @@ void mbedtls_entropy_free( mbedtls_entropy_context *ctx )
|
|||
if( ctx->accumulator_started == -1 )
|
||||
return;
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
mbedtls_havege_free( &ctx->havege_data );
|
||||
#endif
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
mbedtls_mutex_free( &ctx->mutex );
|
||||
#endif
|
||||
|
@ -471,15 +457,21 @@ int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx )
|
|||
#if defined(MBEDTLS_FS_IO)
|
||||
int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
|
||||
FILE *f;
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
FILE *f = NULL;
|
||||
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
||||
|
||||
if( ( f = fopen( path, "wb" ) ) == NULL )
|
||||
return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR );
|
||||
|
||||
if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( f = fopen( path, "wb" ) ) == NULL )
|
||||
{
|
||||
ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( fwrite( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) != MBEDTLS_ENTROPY_BLOCK_SIZE )
|
||||
{
|
||||
|
@ -492,7 +484,9 @@ int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *p
|
|||
exit:
|
||||
mbedtls_platform_zeroize( buf, sizeof( buf ) );
|
||||
|
||||
fclose( f );
|
||||
if( f != NULL )
|
||||
fclose( f );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
|
|
|
@ -29,15 +29,12 @@
|
|||
#if defined(MBEDTLS_ENTROPY_C)
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "entropy_poll.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
#include "mbedtls/timing.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
#include "mbedtls/havege.h"
|
||||
#endif
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
@ -249,22 +246,6 @@ int mbedtls_hardclock_poll( void *data,
|
|||
}
|
||||
#endif /* MBEDTLS_TIMING_C */
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
int mbedtls_havege_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
{
|
||||
mbedtls_havege_state *hs = (mbedtls_havege_state *) data;
|
||||
*olen = 0;
|
||||
|
||||
if( mbedtls_havege_random( hs, output, len ) != 0 )
|
||||
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
|
||||
|
||||
*olen = len;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_HAVEGE_C */
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
int mbedtls_nv_seed_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
|
|
|
@ -38,7 +38,6 @@ extern "C" {
|
|||
* Default thresholds for built-in sources, in bytes
|
||||
*/
|
||||
#define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */
|
||||
#define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */
|
||||
#define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */
|
||||
#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
|
||||
#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
|
||||
|
@ -60,16 +59,6 @@ int mbedtls_platform_entropy_poll( void *data,
|
|||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
/**
|
||||
* \brief HAVEGE based entropy poll callback
|
||||
*
|
||||
* Requires an HAVEGE state as its data pointer.
|
||||
*/
|
||||
int mbedtls_havege_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TIMING_C)
|
||||
/**
|
||||
* \brief mbedtls_timing_hardclock-based entropy poll callback
|
|
@ -130,10 +130,6 @@
|
|||
#include "mbedtls/oid.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
#include "mbedtls/padlock.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PEM_PARSE_C) || defined(MBEDTLS_PEM_WRITE_C)
|
||||
#include "mbedtls/pem.h"
|
||||
#endif
|
||||
|
@ -432,8 +428,6 @@ const char * mbedtls_high_level_strerr( int error_code )
|
|||
return( "SSL - Hardware acceleration function returned with error" );
|
||||
case -(MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH):
|
||||
return( "SSL - Hardware acceleration function skipped / left alone data" );
|
||||
case -(MBEDTLS_ERR_SSL_COMPRESSION_FAILED):
|
||||
return( "SSL - Processing of the compression / decompression failed" );
|
||||
case -(MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION):
|
||||
return( "SSL - Handshake protocol not within min/max boundaries" );
|
||||
case -(MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET):
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_AESNI_C)
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
|
|
237
library/havege.c
237
library/havege.c
|
@ -1,237 +0,0 @@
|
|||
/**
|
||||
* \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* The HAVEGE RNG was designed by Andre Seznec in 2002.
|
||||
*
|
||||
* http://www.irisa.fr/caps/projects/hipsor/publi.php
|
||||
*
|
||||
* Contact: seznec(at)irisa_dot_fr - orocheco(at)irisa_dot_fr
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_HAVEGE_C)
|
||||
|
||||
#include "mbedtls/havege.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* On average, one iteration accesses two 8-word blocks in the havege WALK
|
||||
* table, and generates 16 words in the RES array.
|
||||
*
|
||||
* The data read in the WALK table is updated and permuted after each use.
|
||||
* The result of the hardware clock counter read is used for this update.
|
||||
*
|
||||
* 25 conditional tests are present. The conditional tests are grouped in
|
||||
* two nested groups of 12 conditional tests and 1 test that controls the
|
||||
* permutation; on average, there should be 6 tests executed and 3 of them
|
||||
* should be mispredicted.
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SWAP(X,Y) { uint32_t *T = (X); (X) = (Y); (Y) = T; }
|
||||
|
||||
#define TST1_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
|
||||
#define TST2_ENTER if( PTEST & 1 ) { PTEST ^= 3; PTEST >>= 1;
|
||||
|
||||
#define TST1_LEAVE U1++; }
|
||||
#define TST2_LEAVE U2++; }
|
||||
|
||||
#define ONE_ITERATION \
|
||||
\
|
||||
PTEST = PT1 >> 20; \
|
||||
\
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
TST1_ENTER TST1_ENTER TST1_ENTER TST1_ENTER \
|
||||
\
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
TST1_LEAVE TST1_LEAVE TST1_LEAVE TST1_LEAVE \
|
||||
\
|
||||
PTX = (PT1 >> 18) & 7; \
|
||||
PT1 &= 0x1FFF; \
|
||||
PT2 &= 0x1FFF; \
|
||||
CLK = (uint32_t) mbedtls_timing_hardclock(); \
|
||||
\
|
||||
i = 0; \
|
||||
A = &WALK[PT1 ]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 1]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 4]; RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> (1)) ^ (*A << (31)) ^ CLK; \
|
||||
*A = (*B >> (2)) ^ (*B << (30)) ^ CLK; \
|
||||
*B = IN ^ U1; \
|
||||
*C = (*C >> (3)) ^ (*C << (29)) ^ CLK; \
|
||||
*D = (*D >> (4)) ^ (*D << (28)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 2]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ^ 2]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 3]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 6]; RES[i++] ^= *D; \
|
||||
\
|
||||
if( PTEST & 1 ) SWAP( A, C ); \
|
||||
\
|
||||
IN = (*A >> (5)) ^ (*A << (27)) ^ CLK; \
|
||||
*A = (*B >> (6)) ^ (*B << (26)) ^ CLK; \
|
||||
*B = IN; CLK = (uint32_t) mbedtls_timing_hardclock(); \
|
||||
*C = (*C >> (7)) ^ (*C << (25)) ^ CLK; \
|
||||
*D = (*D >> (8)) ^ (*D << (24)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 4]; \
|
||||
B = &WALK[PT2 ^ 1]; \
|
||||
\
|
||||
PTEST = PT2 >> 1; \
|
||||
\
|
||||
PT2 = (RES[(i - 8) ^ PTY] ^ WALK[PT2 ^ PTY ^ 7]); \
|
||||
PT2 = ((PT2 & 0x1FFF) & (~8)) ^ ((PT1 ^ 8) & 0x8); \
|
||||
PTY = (PT2 >> 10) & 7; \
|
||||
\
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
TST2_ENTER TST2_ENTER TST2_ENTER TST2_ENTER \
|
||||
\
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
TST2_LEAVE TST2_LEAVE TST2_LEAVE TST2_LEAVE \
|
||||
\
|
||||
C = &WALK[PT1 ^ 5]; \
|
||||
D = &WALK[PT2 ^ 5]; \
|
||||
\
|
||||
RES[i++] ^= *A; \
|
||||
RES[i++] ^= *B; \
|
||||
RES[i++] ^= *C; \
|
||||
RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> ( 9)) ^ (*A << (23)) ^ CLK; \
|
||||
*A = (*B >> (10)) ^ (*B << (22)) ^ CLK; \
|
||||
*B = IN ^ U2; \
|
||||
*C = (*C >> (11)) ^ (*C << (21)) ^ CLK; \
|
||||
*D = (*D >> (12)) ^ (*D << (20)) ^ CLK; \
|
||||
\
|
||||
A = &WALK[PT1 ^ 6]; RES[i++] ^= *A; \
|
||||
B = &WALK[PT2 ^ 3]; RES[i++] ^= *B; \
|
||||
C = &WALK[PT1 ^ 7]; RES[i++] ^= *C; \
|
||||
D = &WALK[PT2 ^ 7]; RES[i++] ^= *D; \
|
||||
\
|
||||
IN = (*A >> (13)) ^ (*A << (19)) ^ CLK; \
|
||||
*A = (*B >> (14)) ^ (*B << (18)) ^ CLK; \
|
||||
*B = IN; \
|
||||
*C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \
|
||||
*D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \
|
||||
\
|
||||
PT1 = ( RES[( i - 8 ) ^ PTX] ^ \
|
||||
WALK[PT1 ^ PTX ^ 7] ) & (~1); \
|
||||
PT1 ^= (PT2 ^ 0x10) & 0x10; \
|
||||
\
|
||||
for( n++, i = 0; i < 16; i++ ) \
|
||||
hs->pool[n % MBEDTLS_HAVEGE_COLLECT_SIZE] ^= RES[i];
|
||||
|
||||
/*
|
||||
* Entropy gathering function
|
||||
*/
|
||||
static void havege_fill( mbedtls_havege_state *hs )
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t i;
|
||||
uint32_t U1, U2, *A, *B, *C, *D;
|
||||
uint32_t PT1, PT2, *WALK, RES[16];
|
||||
uint32_t PTX, PTY, CLK, PTEST, IN;
|
||||
|
||||
WALK = hs->WALK;
|
||||
PT1 = hs->PT1;
|
||||
PT2 = hs->PT2;
|
||||
|
||||
PTX = U1 = 0;
|
||||
PTY = U2 = 0;
|
||||
|
||||
(void)PTX;
|
||||
|
||||
memset( RES, 0, sizeof( RES ) );
|
||||
|
||||
while( n < MBEDTLS_HAVEGE_COLLECT_SIZE * 4 )
|
||||
{
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
ONE_ITERATION
|
||||
}
|
||||
|
||||
hs->PT1 = PT1;
|
||||
hs->PT2 = PT2;
|
||||
|
||||
hs->offset[0] = 0;
|
||||
hs->offset[1] = MBEDTLS_HAVEGE_COLLECT_SIZE / 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* HAVEGE initialization
|
||||
*/
|
||||
void mbedtls_havege_init( mbedtls_havege_state *hs )
|
||||
{
|
||||
memset( hs, 0, sizeof( mbedtls_havege_state ) );
|
||||
|
||||
havege_fill( hs );
|
||||
}
|
||||
|
||||
void mbedtls_havege_free( mbedtls_havege_state *hs )
|
||||
{
|
||||
if( hs == NULL )
|
||||
return;
|
||||
|
||||
mbedtls_platform_zeroize( hs, sizeof( mbedtls_havege_state ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* HAVEGE rand function
|
||||
*/
|
||||
int mbedtls_havege_random( void *p_rng, unsigned char *buf, size_t len )
|
||||
{
|
||||
uint32_t val;
|
||||
size_t use_len;
|
||||
mbedtls_havege_state *hs = (mbedtls_havege_state *) p_rng;
|
||||
unsigned char *p = buf;
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
use_len = len;
|
||||
if( use_len > sizeof( val ) )
|
||||
use_len = sizeof( val );
|
||||
|
||||
if( hs->offset[1] >= MBEDTLS_HAVEGE_COLLECT_SIZE )
|
||||
havege_fill( hs );
|
||||
|
||||
val = hs->pool[hs->offset[0]++];
|
||||
val ^= hs->pool[hs->offset[1]++];
|
||||
|
||||
memcpy( p, &val, use_len );
|
||||
|
||||
len -= use_len;
|
||||
p += use_len;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_HAVEGE_C */
|
|
@ -26,7 +26,7 @@
|
|||
#if defined(MBEDTLS_MD_C)
|
||||
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "md_wrap.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \file md_internal.h
|
||||
* \file md_wrap.h
|
||||
*
|
||||
* \brief Message digest wrappers.
|
||||
*
|
195
library/mps_common.h
Normal file
195
library/mps_common.h
Normal file
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file mps_common.h
|
||||
*
|
||||
* \brief Common functions and macros used by MPS
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_MPS_COMMON_H
|
||||
#define MBEDTLS_MPS_COMMON_H
|
||||
|
||||
#include "mps_error.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* \name SECTION: MPS Configuration
|
||||
*
|
||||
* \{
|
||||
*/
|
||||
|
||||
/*! This flag controls whether the MPS-internal components
|
||||
* (reader, writer, Layer 1-3) perform validation of the
|
||||
* expected abstract state at the entry of API calls.
|
||||
*
|
||||
* Context: All MPS API functions impose assumptions/preconditions on the
|
||||
* context on which they operate. For example, every structure has a notion of
|
||||
* state integrity which is established by `xxx_init()` and preserved by any
|
||||
* calls to the MPS API which satisfy their preconditions and either succeed,
|
||||
* or fail with an error code which is explicitly documented to not corrupt
|
||||
* structure integrity (such as WANT_READ and WANT_WRITE);
|
||||
* apart from `xxx_init()` any function assumes state integrity as a
|
||||
* precondition (but usually more). If any of the preconditions is violated,
|
||||
* the function's behavior is entirely undefined.
|
||||
* In addition to state integrity, all MPS structures have a more refined
|
||||
* notion of abstract state that the API operates on. For example, all layers
|
||||
* have a notion of 'abtract read state' which indicates if incoming data has
|
||||
* been passed to the user, e.g. through mps_l2_read_start() for Layer 2
|
||||
* or mps_l3_read() in Layer 3. After such a call, it doesn't make sense to
|
||||
* call these reading functions again until the incoming data has been
|
||||
* explicitly 'consumed', e.g. through mps_l2_read_consume() for Layer 2 or
|
||||
* mps_l3_read_consume() on Layer 3. However, even if it doesn't make sense,
|
||||
* it's a design choice whether the API should fail gracefully on such
|
||||
* non-sensical calls or not, and that's what this option is about:
|
||||
*
|
||||
* This option determines whether the expected abstract state
|
||||
* is part of the API preconditions or not: If the option is set,
|
||||
* then the abstract state is not part of the precondition and is
|
||||
* thus required to be validated by the implementation. If an unexpected
|
||||
* abstract state is encountered, the implementation must fail gracefully
|
||||
* with error #MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED.
|
||||
* Conversely, if this option is not set, then the expected abstract state
|
||||
* is included in the preconditions of the respective API calls, and
|
||||
* an implementation's behaviour is undefined if the abstract state is
|
||||
* not as expected.
|
||||
*
|
||||
* For example: Enabling this makes mps_l2_read_done() fail if
|
||||
* no incoming record is currently open; disabling this would
|
||||
* lead to undefined behavior in this case.
|
||||
*
|
||||
* Comment this to remove state validation.
|
||||
*/
|
||||
#define MBEDTLS_MPS_STATE_VALIDATION
|
||||
|
||||
/*! This flag enables/disables assertions on the internal state of MPS.
|
||||
*
|
||||
* Assertions are sanity checks that should never trigger when MPS
|
||||
* is used within the bounds of its API and preconditions.
|
||||
*
|
||||
* Enabling this increases security by limiting the scope of
|
||||
* potential bugs, but comes at the cost of increased code size.
|
||||
*
|
||||
* Note: So far, there is no guiding principle as to what
|
||||
* expected conditions merit an assertion, and which don't.
|
||||
*
|
||||
* Comment this to disable assertions.
|
||||
*/
|
||||
#define MBEDTLS_MPS_ENABLE_ASSERTIONS
|
||||
|
||||
/*! This flag controls whether tracing for MPS should be enabled. */
|
||||
//#define MBEDTLS_MPS_ENABLE_TRACE
|
||||
|
||||
#if defined(MBEDTLS_MPS_STATE_VALIDATION)
|
||||
|
||||
#define MBEDTLS_MPS_STATE_VALIDATE_RAW( cond, string ) \
|
||||
do \
|
||||
{ \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR, string ); \
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#else /* MBEDTLS_MPS_STATE_VALIDATION */
|
||||
|
||||
#define MBEDTLS_MPS_STATE_VALIDATE_RAW( cond, string ) \
|
||||
do \
|
||||
{ \
|
||||
( cond ); \
|
||||
} while( 0 )
|
||||
|
||||
#endif /* MBEDTLS_MPS_STATE_VALIDATION */
|
||||
|
||||
#if defined(MBEDTLS_MPS_ENABLE_ASSERTIONS)
|
||||
|
||||
#define MBEDTLS_MPS_ASSERT_RAW( cond, string ) \
|
||||
do \
|
||||
{ \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR, string ); \
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_INTERNAL_ERROR ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#else /* MBEDTLS_MPS_ENABLE_ASSERTIONS */
|
||||
|
||||
#define MBEDTLS_MPS_ASSERT_RAW( cond, string ) do {} while( 0 )
|
||||
|
||||
#endif /* MBEDTLS_MPS_ENABLE_ASSERTIONS */
|
||||
|
||||
|
||||
/* \} name SECTION: MPS Configuration */
|
||||
|
||||
/**
|
||||
* \name SECTION: Common types
|
||||
*
|
||||
* Various common types used throughout MPS.
|
||||
* \{
|
||||
*/
|
||||
|
||||
/** \brief The type of buffer sizes and offsets used in MPS structures.
|
||||
*
|
||||
* This is an unsigned integer type that should be large enough to
|
||||
* hold the length of any buffer or message processed by MPS.
|
||||
*
|
||||
* The reason to pick a value as small as possible here is
|
||||
* to reduce the size of MPS structures.
|
||||
*
|
||||
* \warning Care has to be taken when using a narrower type
|
||||
* than ::mbedtls_mps_size_t here because of
|
||||
* potential truncation during conversion.
|
||||
*
|
||||
* \warning Handshake messages in TLS may be up to 2^24 ~ 16Mb in size.
|
||||
* If mbedtls_mps_[opt_]stored_size_t is smaller than that, the
|
||||
* maximum handshake message is restricted accordingly.
|
||||
*
|
||||
* For now, we use the default type of size_t throughout, and the use of
|
||||
* smaller types or different types for ::mbedtls_mps_size_t and
|
||||
* ::mbedtls_mps_stored_size_t is not yet supported.
|
||||
*
|
||||
*/
|
||||
typedef size_t mbedtls_mps_stored_size_t;
|
||||
#define MBEDTLS_MPS_STORED_SIZE_MAX ( (mbedtls_mps_stored_size_t) -1 )
|
||||
|
||||
/** \brief The type of buffer sizes and offsets used in the MPS API
|
||||
* and implementation.
|
||||
*
|
||||
* This must be at least as wide as ::mbedtls_stored_size_t but
|
||||
* may be chosen to be strictly larger if more suitable for the
|
||||
* target architecture.
|
||||
*
|
||||
* For example, in a test build for ARM Thumb, using uint_fast16_t
|
||||
* instead of uint16_t reduced the code size from 1060 Byte to 962 Byte,
|
||||
* so almost 10%.
|
||||
*/
|
||||
typedef size_t mbedtls_mps_size_t;
|
||||
#define MBEDTLS_MPS_SIZE_MAX ( (mbedtls_mps_size_t) -1 )
|
||||
|
||||
#if MBEDTLS_MPS_STORED_SIZE_MAX > MBEDTLS_MPS_SIZE_MAX
|
||||
#error "Misconfiguration of mbedtls_mps_size_t and mbedtls_mps_stored_size_t."
|
||||
#endif
|
||||
|
||||
/* \} SECTION: Common types */
|
||||
|
||||
|
||||
#endif /* MBEDTLS_MPS_COMMON_H */
|
103
library/mps_error.h
Normal file
103
library/mps_error.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file mps_error.h
|
||||
*
|
||||
* \brief Error codes used by MPS
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_MPS_ERROR_H
|
||||
#define MBEDTLS_MPS_ERROR_H
|
||||
|
||||
|
||||
/* TODO: The error code allocation needs to be revisited:
|
||||
*
|
||||
* - Should we make (some of) the MPS Reader error codes public?
|
||||
* If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
|
||||
* a gap in the Mbed TLS public error space.
|
||||
* If not, we have to make sure we don't forward those errors
|
||||
* at the level of the public API -- no risk at the moment as
|
||||
* long as MPS is an experimental component not accessible from
|
||||
* public API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \name SECTION: MPS general error codes
|
||||
*
|
||||
* \{
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_MPS_ERR_BASE
|
||||
#define MBEDTLS_MPS_ERR_BASE ( 0 )
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_MPS_MAKE_ERROR(code) \
|
||||
( -( MBEDTLS_MPS_ERR_BASE | (code) ) )
|
||||
|
||||
#define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR( 0x1 )
|
||||
#define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR( 0x2 )
|
||||
|
||||
/* \} name SECTION: MPS general error codes */
|
||||
|
||||
/**
|
||||
* \name SECTION: MPS Reader error codes
|
||||
*
|
||||
* \{
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_MPS_READER_ERR_BASE
|
||||
#define MBEDTLS_MPS_READER_ERR_BASE ( 1 << 8 )
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
|
||||
( -( MBEDTLS_MPS_READER_ERR_BASE | (code) ) )
|
||||
|
||||
/*! An attempt to reclaim the data buffer from a reader failed because
|
||||
* the user hasn't yet read and committed all of it. */
|
||||
#define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR( 0x1 )
|
||||
|
||||
/*! An invalid argument was passed to the reader. */
|
||||
#define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR( 0x2 )
|
||||
|
||||
/*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
|
||||
* after pausing failed because the provided data is not sufficient to serve the
|
||||
* read requests that led to the pausing. */
|
||||
#define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR( 0x3 )
|
||||
|
||||
/*! A get request failed because not enough data is available in the reader. */
|
||||
#define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR( 0x4 )
|
||||
|
||||
/*!< A get request after pausing and reactivating the reader failed because
|
||||
* the request is not in line with the request made prior to pausing. The user
|
||||
* must not change it's 'strategy' after pausing and reactivating a reader. */
|
||||
#define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR( 0x5 )
|
||||
|
||||
/*! An attempt to reclaim the data buffer from a reader failed because the reader
|
||||
* has no accumulator it can use to backup the data that hasn't been processed. */
|
||||
#define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR( 0x6 )
|
||||
|
||||
/*! An attempt to reclaim the data buffer from a reader failed because the
|
||||
* accumulator passed to the reader is not large enough to hold both the
|
||||
* data that hasn't been processed and the excess of the last read-request. */
|
||||
#define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR( 0x7 )
|
||||
|
||||
/* \} name SECTION: MPS Reader error codes */
|
||||
|
||||
#endif /* MBEDTLS_MPS_ERROR_H */
|
564
library/mps_reader.c
Normal file
564
library/mps_reader.c
Normal file
|
@ -0,0 +1,564 @@
|
|||
/*
|
||||
* Message Processing Stack, Reader implementation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
|
||||
|
||||
#include "mps_reader.h"
|
||||
#include "mps_common.h"
|
||||
#include "mps_trace.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_ENABLE_TRACE)
|
||||
static int mbedtls_mps_trace_id = MBEDTLS_MPS_TRACE_BIT_READER;
|
||||
#endif /* MBEDTLS_MPS_ENABLE_TRACE */
|
||||
|
||||
/*
|
||||
* GENERAL NOTE ON CODING STYLE
|
||||
*
|
||||
* The following code intentionally separates memory loads
|
||||
* and stores from other operations (arithmetic or branches).
|
||||
* This leads to the introduction of many local variables
|
||||
* and significantly increases the C-code line count, but
|
||||
* should not increase the size of generated assembly.
|
||||
*
|
||||
* The reason for this is twofold:
|
||||
* (1) It will ease verification efforts using the VST
|
||||
* (Verified Software Toolchain)
|
||||
* whose program logic cannot directly reason
|
||||
* about instructions containing a load or store in
|
||||
* addition to other operations (e.g. *p = *q or
|
||||
* tmp = *p + 42).
|
||||
* (2) Operating on local variables and writing the results
|
||||
* back to the target contexts on success only
|
||||
* allows to maintain structure invariants even
|
||||
* on failure - this in turn has two benefits:
|
||||
* (2.a) If for some reason an error code is not caught
|
||||
* and operation continues, functions are nonetheless
|
||||
* called with sane contexts, reducing the risk
|
||||
* of dangerous behavior.
|
||||
* (2.b) Randomized testing is easier if structures
|
||||
* remain intact even in the face of failing
|
||||
* and/or non-sensical calls.
|
||||
* Moreover, it might even reduce code-size because
|
||||
* the compiler need not write back temporary results
|
||||
* to memory in case of failure.
|
||||
*
|
||||
*/
|
||||
|
||||
static inline int mps_reader_is_accumulating(
|
||||
mbedtls_mps_reader const *rd )
|
||||
{
|
||||
mbedtls_mps_size_t acc_remaining;
|
||||
if( rd->acc == NULL )
|
||||
return( 0 );
|
||||
|
||||
acc_remaining = rd->acc_share.acc_remaining;
|
||||
return( acc_remaining > 0 );
|
||||
}
|
||||
|
||||
static inline int mps_reader_is_producing(
|
||||
mbedtls_mps_reader const *rd )
|
||||
{
|
||||
unsigned char *frag = rd->frag;
|
||||
return( frag == NULL );
|
||||
}
|
||||
|
||||
static inline int mps_reader_is_consuming(
|
||||
mbedtls_mps_reader const *rd )
|
||||
{
|
||||
return( !mps_reader_is_producing( rd ) );
|
||||
}
|
||||
|
||||
static inline mbedtls_mps_size_t mps_reader_get_fragment_offset(
|
||||
mbedtls_mps_reader const *rd )
|
||||
{
|
||||
unsigned char *acc = rd->acc;
|
||||
mbedtls_mps_size_t frag_offset;
|
||||
|
||||
if( acc == NULL )
|
||||
return( 0 );
|
||||
|
||||
frag_offset = rd->acc_share.frag_offset;
|
||||
return( frag_offset );
|
||||
}
|
||||
|
||||
static inline mbedtls_mps_size_t mps_reader_serving_from_accumulator(
|
||||
mbedtls_mps_reader const *rd )
|
||||
{
|
||||
mbedtls_mps_size_t frag_offset, end;
|
||||
|
||||
frag_offset = mps_reader_get_fragment_offset( rd );
|
||||
end = rd->end;
|
||||
|
||||
return( end < frag_offset );
|
||||
}
|
||||
|
||||
static inline void mps_reader_zero( mbedtls_mps_reader *rd )
|
||||
{
|
||||
/* A plain memset() would likely be more efficient,
|
||||
* but the current way of zeroing makes it harder
|
||||
* to overlook fields which should not be zero-initialized.
|
||||
* It's also more suitable for FV efforts since it
|
||||
* doesn't require reasoning about structs being
|
||||
* interpreted as unstructured binary blobs. */
|
||||
static mbedtls_mps_reader const zero =
|
||||
{ .frag = NULL,
|
||||
.frag_len = 0,
|
||||
.commit = 0,
|
||||
.end = 0,
|
||||
.pending = 0,
|
||||
.acc = NULL,
|
||||
.acc_len = 0,
|
||||
.acc_available = 0,
|
||||
.acc_share = { .acc_remaining = 0 }
|
||||
};
|
||||
*rd = zero;
|
||||
}
|
||||
|
||||
int mbedtls_mps_reader_init( mbedtls_mps_reader *rd,
|
||||
unsigned char *acc,
|
||||
mbedtls_mps_size_t acc_len )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_init" );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"* Accumulator size: %u bytes", (unsigned) acc_len );
|
||||
mps_reader_zero( rd );
|
||||
rd->acc = acc;
|
||||
rd->acc_len = acc_len;
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_mps_reader_free( mbedtls_mps_reader *rd )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_free" );
|
||||
mps_reader_zero( rd );
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_mps_reader_feed( mbedtls_mps_reader *rd,
|
||||
unsigned char *new_frag,
|
||||
mbedtls_mps_size_t new_frag_len )
|
||||
{
|
||||
mbedtls_mps_size_t copy_to_acc;
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_feed" );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"* Fragment length: %u bytes", (unsigned) new_frag_len );
|
||||
|
||||
if( new_frag == NULL )
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_INVALID_ARG );
|
||||
|
||||
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_producing( rd ),
|
||||
"mbedtls_mps_reader_feed() requires reader to be in producing mode" );
|
||||
|
||||
if( mps_reader_is_accumulating( rd ) )
|
||||
{
|
||||
unsigned char *acc = rd->acc;
|
||||
mbedtls_mps_size_t acc_remaining = rd->acc_share.acc_remaining;
|
||||
mbedtls_mps_size_t acc_available = rd->acc_available;
|
||||
|
||||
/* Skip over parts of the accumulator that have already been filled. */
|
||||
acc += acc_available;
|
||||
|
||||
copy_to_acc = acc_remaining;
|
||||
if( copy_to_acc > new_frag_len )
|
||||
copy_to_acc = new_frag_len;
|
||||
|
||||
/* Copy new contents to accumulator. */
|
||||
memcpy( acc, new_frag, copy_to_acc );
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Copy new data of size %u of %u into accumulator at offset %u",
|
||||
(unsigned) copy_to_acc, (unsigned) new_frag_len, (unsigned) acc_available );
|
||||
|
||||
/* Check if, with the new fragment, we have enough data. */
|
||||
acc_remaining -= copy_to_acc;
|
||||
if( acc_remaining > 0 )
|
||||
{
|
||||
/* We need to accumulate more data. Stay in producing mode. */
|
||||
acc_available += copy_to_acc;
|
||||
rd->acc_share.acc_remaining = acc_remaining;
|
||||
rd->acc_available = acc_available;
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_NEED_MORE );
|
||||
}
|
||||
|
||||
/* We have filled the accumulator: Move to consuming mode. */
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Enough data available to serve user request" );
|
||||
|
||||
/* Remember overlap of accumulator and fragment. */
|
||||
rd->acc_share.frag_offset = acc_available;
|
||||
acc_available += copy_to_acc;
|
||||
rd->acc_available = acc_available;
|
||||
}
|
||||
else /* Not accumulating */
|
||||
{
|
||||
rd->acc_share.frag_offset = 0;
|
||||
}
|
||||
|
||||
rd->frag = new_frag;
|
||||
rd->frag_len = new_frag_len;
|
||||
rd->commit = 0;
|
||||
rd->end = 0;
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
|
||||
int mbedtls_mps_reader_get( mbedtls_mps_reader *rd,
|
||||
mbedtls_mps_size_t desired,
|
||||
unsigned char **buffer,
|
||||
mbedtls_mps_size_t *buflen )
|
||||
{
|
||||
unsigned char *frag;
|
||||
mbedtls_mps_size_t frag_len, frag_offset, end, frag_fetched, frag_remaining;
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_get" );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"* Bytes requested: %u", (unsigned) desired );
|
||||
|
||||
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
||||
"mbedtls_mps_reader_get() requires reader to be in consuming mode" );
|
||||
|
||||
end = rd->end;
|
||||
frag_offset = mps_reader_get_fragment_offset( rd );
|
||||
|
||||
/* Check if we're still serving from the accumulator. */
|
||||
if( mps_reader_serving_from_accumulator( rd ) )
|
||||
{
|
||||
/* Illustration of supported and unsupported cases:
|
||||
*
|
||||
* - Allowed #1
|
||||
*
|
||||
* +-----------------------------------+
|
||||
* | frag |
|
||||
* +-----------------------------------+
|
||||
*
|
||||
* end end+desired
|
||||
* | |
|
||||
* +-----v-------v-------------+
|
||||
* | acc |
|
||||
* +---------------------------+
|
||||
* | |
|
||||
* frag_offset acc_available
|
||||
*
|
||||
* - Allowed #2
|
||||
*
|
||||
* +-----------------------------------+
|
||||
* | frag |
|
||||
* +-----------------------------------+
|
||||
*
|
||||
* end end+desired
|
||||
* | |
|
||||
* +----------v----------------v
|
||||
* | acc |
|
||||
* +---------------------------+
|
||||
* | |
|
||||
* frag_offset acc_available
|
||||
*
|
||||
* - Not allowed #1 (could be served, but we don't actually use it):
|
||||
*
|
||||
* +-----------------------------------+
|
||||
* | frag |
|
||||
* +-----------------------------------+
|
||||
*
|
||||
* end end+desired
|
||||
* | |
|
||||
* +------v-------------v------+
|
||||
* | acc |
|
||||
* +---------------------------+
|
||||
* | |
|
||||
* frag_offset acc_available
|
||||
*
|
||||
*
|
||||
* - Not allowed #2 (can't be served with a contiguous buffer):
|
||||
*
|
||||
* +-----------------------------------+
|
||||
* | frag |
|
||||
* +-----------------------------------+
|
||||
*
|
||||
* end end + desired
|
||||
* | |
|
||||
* +------v--------------------+ v
|
||||
* | acc |
|
||||
* +---------------------------+
|
||||
* | |
|
||||
* frag_offset acc_available
|
||||
*
|
||||
* In case of Allowed #2 we're switching to serve from
|
||||
* `frag` starting from the next call to mbedtls_mps_reader_get().
|
||||
*/
|
||||
|
||||
unsigned char *acc;
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Serve the request from the accumulator" );
|
||||
if( frag_offset - end < desired )
|
||||
{
|
||||
mbedtls_mps_size_t acc_available;
|
||||
acc_available = rd->acc_available;
|
||||
if( acc_available - end != desired )
|
||||
{
|
||||
/* It might be possible to serve some of these situations by
|
||||
* making additional space in the accumulator, removing those
|
||||
* parts that have already been committed.
|
||||
* On the other hand, this brings additional complexity and
|
||||
* enlarges the code size, while there doesn't seem to be a use
|
||||
* case where we don't attempt exactly the same `get` calls when
|
||||
* resuming on a reader than what we tried before pausing it.
|
||||
* If we believe we adhere to this restricted usage throughout
|
||||
* the library, this check is a good opportunity to
|
||||
* validate this. */
|
||||
MBEDTLS_MPS_TRACE_RETURN(
|
||||
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS );
|
||||
}
|
||||
}
|
||||
|
||||
acc = rd->acc;
|
||||
acc += end;
|
||||
|
||||
*buffer = acc;
|
||||
if( buflen != NULL )
|
||||
*buflen = desired;
|
||||
|
||||
end += desired;
|
||||
rd->end = end;
|
||||
rd->pending = 0;
|
||||
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
/* Attempt to serve the request from the current fragment */
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Serve the request from the current fragment." );
|
||||
|
||||
frag_len = rd->frag_len;
|
||||
frag_fetched = end - frag_offset; /* The amount of data from the current
|
||||
* fragment that has already been passed
|
||||
* to the user. */
|
||||
frag_remaining = frag_len - frag_fetched; /* Remaining data in fragment */
|
||||
|
||||
/* Check if we can serve the read request from the fragment. */
|
||||
if( frag_remaining < desired )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"There's not enough data in the current fragment "
|
||||
"to serve the request." );
|
||||
/* There's not enough data in the current fragment,
|
||||
* so either just RETURN what we have or fail. */
|
||||
if( buflen == NULL )
|
||||
{
|
||||
if( frag_remaining > 0 )
|
||||
{
|
||||
rd->pending = desired - frag_remaining;
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Remember to collect %u bytes before re-opening",
|
||||
(unsigned) rd->pending );
|
||||
}
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_OUT_OF_DATA );
|
||||
}
|
||||
|
||||
desired = frag_remaining;
|
||||
}
|
||||
|
||||
/* There's enough data in the current fragment to serve the
|
||||
* (potentially modified) read request. */
|
||||
|
||||
frag = rd->frag;
|
||||
frag += frag_fetched;
|
||||
|
||||
*buffer = frag;
|
||||
if( buflen != NULL )
|
||||
*buflen = desired;
|
||||
|
||||
end += desired;
|
||||
rd->end = end;
|
||||
rd->pending = 0;
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_mps_reader_commit( mbedtls_mps_reader *rd )
|
||||
{
|
||||
mbedtls_mps_size_t end;
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_commit" );
|
||||
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
||||
"mbedtls_mps_reader_commit() requires reader to be in consuming mode" );
|
||||
|
||||
end = rd->end;
|
||||
rd->commit = end;
|
||||
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_mps_reader_reclaim( mbedtls_mps_reader *rd,
|
||||
int *paused )
|
||||
{
|
||||
unsigned char *frag, *acc;
|
||||
mbedtls_mps_size_t pending, commit;
|
||||
mbedtls_mps_size_t acc_len, frag_offset, frag_len;
|
||||
MBEDTLS_MPS_TRACE_INIT( "mbedtls_mps_reader_reclaim" );
|
||||
|
||||
if( paused != NULL )
|
||||
*paused = 0;
|
||||
|
||||
MBEDTLS_MPS_STATE_VALIDATE_RAW( mps_reader_is_consuming( rd ),
|
||||
"mbedtls_mps_reader_reclaim() requires reader to be in consuming mode" );
|
||||
|
||||
frag = rd->frag;
|
||||
acc = rd->acc;
|
||||
pending = rd->pending;
|
||||
commit = rd->commit;
|
||||
frag_len = rd->frag_len;
|
||||
|
||||
frag_offset = mps_reader_get_fragment_offset( rd );
|
||||
|
||||
if( pending == 0 )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"No unsatisfied read-request has been logged." );
|
||||
|
||||
/* Check if there's data left to be consumed. */
|
||||
if( commit < frag_offset || commit - frag_offset < frag_len )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"There is data left to be consumed." );
|
||||
rd->end = commit;
|
||||
MBEDTLS_MPS_TRACE_RETURN( MBEDTLS_ERR_MPS_READER_DATA_LEFT );
|
||||
}
|
||||
|
||||
rd->acc_available = 0;
|
||||
rd->acc_share.acc_remaining = 0;
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Fragment has been fully processed and committed." );
|
||||
}
|
||||
else
|
||||
{
|
||||
int overflow;
|
||||
|
||||
mbedtls_mps_size_t acc_backup_offset;
|
||||
mbedtls_mps_size_t acc_backup_len;
|
||||
mbedtls_mps_size_t frag_backup_offset;
|
||||
mbedtls_mps_size_t frag_backup_len;
|
||||
|
||||
mbedtls_mps_size_t backup_len;
|
||||
mbedtls_mps_size_t acc_len_needed;
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"There has been an unsatisfied read with %u bytes overhead.",
|
||||
(unsigned) pending );
|
||||
|
||||
if( acc == NULL )
|
||||
{
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"No accumulator present" );
|
||||
MBEDTLS_MPS_TRACE_RETURN(
|
||||
MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR );
|
||||
}
|
||||
acc_len = rd->acc_len;
|
||||
|
||||
/* Check if the upper layer has already fetched
|
||||
* and committed the contents of the accumulator. */
|
||||
if( commit < frag_offset )
|
||||
{
|
||||
/* No, accumulator is still being processed. */
|
||||
frag_backup_offset = 0;
|
||||
frag_backup_len = frag_len;
|
||||
acc_backup_offset = commit;
|
||||
acc_backup_len = frag_offset - commit;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, the accumulator is already processed. */
|
||||
frag_backup_offset = commit - frag_offset;
|
||||
frag_backup_len = frag_len - frag_backup_offset;
|
||||
acc_backup_offset = 0;
|
||||
acc_backup_len = 0;
|
||||
}
|
||||
|
||||
backup_len = acc_backup_len + frag_backup_len;
|
||||
acc_len_needed = backup_len + pending;
|
||||
|
||||
overflow = 0;
|
||||
overflow |= ( backup_len < acc_backup_len );
|
||||
overflow |= ( acc_len_needed < backup_len );
|
||||
|
||||
if( overflow || acc_len < acc_len_needed )
|
||||
{
|
||||
/* Except for the different return code, we behave as if
|
||||
* there hadn't been a call to mbedtls_mps_reader_get()
|
||||
* since the last commit. */
|
||||
rd->end = commit;
|
||||
rd->pending = 0;
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
||||
"The accumulator is too small to handle the backup." );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
||||
"* Size: %u", (unsigned) acc_len );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
||||
"* Needed: %u (%u + %u)",
|
||||
(unsigned) acc_len_needed,
|
||||
(unsigned) backup_len, (unsigned) pending );
|
||||
MBEDTLS_MPS_TRACE_RETURN(
|
||||
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL );
|
||||
}
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Fragment backup: %u", (unsigned) frag_backup_len );
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Accumulator backup: %u", (unsigned) acc_backup_len );
|
||||
|
||||
/* Move uncommitted parts from the accumulator to the front
|
||||
* of the accumulator. */
|
||||
memmove( acc, acc + acc_backup_offset, acc_backup_len );
|
||||
|
||||
/* Copy uncmmitted parts of the current fragment to the
|
||||
* accumulator. */
|
||||
memcpy( acc + acc_backup_len,
|
||||
frag + frag_backup_offset, frag_backup_len );
|
||||
|
||||
rd->acc_available = backup_len;
|
||||
rd->acc_share.acc_remaining = pending;
|
||||
|
||||
if( paused != NULL )
|
||||
*paused = 1;
|
||||
}
|
||||
|
||||
rd->frag = NULL;
|
||||
rd->frag_len = 0;
|
||||
|
||||
rd->commit = 0;
|
||||
rd->end = 0;
|
||||
rd->pending = 0;
|
||||
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
"Final state: aa %u, al %u, ar %u",
|
||||
(unsigned) rd->acc_available, (unsigned) rd->acc_len,
|
||||
(unsigned) rd->acc_share.acc_remaining );
|
||||
MBEDTLS_MPS_TRACE_RETURN( 0 );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
|
382
library/mps_reader.h
Normal file
382
library/mps_reader.h
Normal file
|
@ -0,0 +1,382 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file mps_reader.h
|
||||
*
|
||||
* \brief This file defines reader objects, which together with their
|
||||
* sibling writer objects form the basis for the communication
|
||||
* between the various layers of the Mbed TLS messaging stack,
|
||||
* as well as the communication between the messaging stack and
|
||||
* the (D)TLS handshake protocol implementation.
|
||||
*
|
||||
* Readers provide a means of transferring incoming data from
|
||||
* a 'producer' providing it in chunks of arbitrary size, to
|
||||
* a 'consumer' which fetches and processes it in chunks of
|
||||
* again arbitrary, and potentially different, size.
|
||||
*
|
||||
* Readers can thus be seen as datagram-to-stream converters,
|
||||
* and they abstract away the following two tasks from the user:
|
||||
* 1. The pointer arithmetic of stepping through a producer-
|
||||
* provided chunk in smaller chunks.
|
||||
* 2. The merging of incoming data chunks in case the
|
||||
* consumer requests data in larger chunks than what the
|
||||
* producer provides.
|
||||
*
|
||||
* The basic abstract flow of operation is the following:
|
||||
* - Initially, the reader is in 'producing mode'.
|
||||
* - The producer hands an incoming data buffer to the reader,
|
||||
* moving it from 'producing' to 'consuming' mode.
|
||||
* - The consumer subsequently fetches and processes the buffer
|
||||
* content. Once that's done -- or partially done and a consumer's
|
||||
* request can't be fulfilled -- the producer revokes the reader's
|
||||
* access to the incoming data buffer, putting the reader back to
|
||||
* producing mode.
|
||||
* - The producer subsequently gathers more incoming data and hands
|
||||
* it to the reader until it switches back to consuming mode
|
||||
* if enough data is available for the last consumer request to
|
||||
* be satisfiable.
|
||||
* - Repeat the above.
|
||||
*
|
||||
* The abstract states of the reader from the producer's and
|
||||
* consumer's perspective are as follows:
|
||||
*
|
||||
* - From the perspective of the consumer, the state of the
|
||||
* reader consists of the following:
|
||||
* - A byte stream representing (concatenation of) the data
|
||||
* received through calls to mbedtls_mps_reader_get(),
|
||||
* - A marker within that byte stream indicating which data
|
||||
* can be considered processed, and hence need not be retained,
|
||||
* when the reader is passed back to the producer via
|
||||
* mbedtls_mps_reader_reclaim().
|
||||
* The marker is set via mbedtls_mps_reader_commit()
|
||||
* which places it at the end of the current byte stream.
|
||||
* The consumer need not be aware of the distinction between consumer
|
||||
* and producer mode, because it only interfaces with the reader
|
||||
* when the latter is in consuming mode.
|
||||
*
|
||||
* - From the perspective of the producer, the reader's state is one of:
|
||||
* - Attached: The reader is in consuming mode.
|
||||
* - Unset: No incoming data buffer is currently managed by the reader,
|
||||
* and all previously handed incoming data buffers have been
|
||||
* fully processed. More data needs to be fed into the reader
|
||||
* via mbedtls_mps_reader_feed().
|
||||
*
|
||||
* - Accumulating: No incoming data buffer is currently managed by the
|
||||
* reader, but some data from the previous incoming data
|
||||
* buffer hasn't been processed yet and is internally
|
||||
* held back.
|
||||
* The Attached state belongs to consuming mode, while the Unset and
|
||||
* Accumulating states belong to producing mode.
|
||||
*
|
||||
* Transitioning from the Unset or Accumulating state to Attached is
|
||||
* done via successful calls to mbedtls_mps_reader_feed(), while
|
||||
* transitioning from Attached to either Unset or Accumulating (depending
|
||||
* on what has been processed) is done via mbedtls_mps_reader_reclaim().
|
||||
*
|
||||
* The following diagram depicts the producer-state progression:
|
||||
*
|
||||
* +------------------+ reclaim
|
||||
* | Unset +<-------------------------------------+ get
|
||||
* +--------|---------+ | +------+
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | feed +---------+---+--+ |
|
||||
* +--------------------------------------> <---+
|
||||
* | Attached |
|
||||
* +--------------------------------------> <---+
|
||||
* | feed, enough data available +---------+---+--+ |
|
||||
* | to serve previous consumer request | | |
|
||||
* | | | |
|
||||
* +--------+---------+ | +------+
|
||||
* +----> Accumulating |<-------------------------------------+ commit
|
||||
* | +---+--------------+ reclaim, previous read request
|
||||
* | | couldn't be fulfilled
|
||||
* | |
|
||||
* +--------+
|
||||
* feed, need more data to serve
|
||||
* previous consumer request
|
||||
* |
|
||||
* |
|
||||
* producing mode | consuming mode
|
||||
* |
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_READER_H
|
||||
#define MBEDTLS_READER_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mps_common.h"
|
||||
#include "mps_error.h"
|
||||
|
||||
struct mbedtls_mps_reader;
|
||||
typedef struct mbedtls_mps_reader mbedtls_mps_reader;
|
||||
|
||||
/*
|
||||
* Structure definitions
|
||||
*/
|
||||
|
||||
struct mbedtls_mps_reader
|
||||
{
|
||||
unsigned char *frag; /*!< The fragment of incoming data managed by
|
||||
* the reader; it is provided to the reader
|
||||
* through mbedtls_mps_reader_feed(). The reader
|
||||
* does not own the fragment and does not
|
||||
* perform any allocation operations on it,
|
||||
* but does have read and write access to it.
|
||||
*
|
||||
* The reader is in consuming mode if
|
||||
* and only if \c frag is not \c NULL. */
|
||||
mbedtls_mps_stored_size_t frag_len;
|
||||
/*!< The length of the current fragment.
|
||||
* Must be 0 if \c frag == \c NULL. */
|
||||
mbedtls_mps_stored_size_t commit;
|
||||
/*!< The offset of the last commit, relative
|
||||
* to the first byte in the fragment, if
|
||||
* no accumulator is present. If an accumulator
|
||||
* is present, it is viewed as a prefix to the
|
||||
* current fragment, and this variable contains
|
||||
* an offset from the beginning of the accumulator.
|
||||
*
|
||||
* This is only used when the reader is in
|
||||
* consuming mode, i.e. \c frag != \c NULL;
|
||||
* otherwise, its value is \c 0. */
|
||||
mbedtls_mps_stored_size_t end;
|
||||
/*!< The offset of the end of the last chunk
|
||||
* passed to the user through a call to
|
||||
* mbedtls_mps_reader_get(), relative to the first
|
||||
* byte in the fragment, if no accumulator is
|
||||
* present. If an accumulator is present, it is
|
||||
* viewed as a prefix to the current fragment, and
|
||||
* this variable contains an offset from the
|
||||
* beginning of the accumulator.
|
||||
*
|
||||
* This is only used when the reader is in
|
||||
* consuming mode, i.e. \c frag != \c NULL;
|
||||
* otherwise, its value is \c 0. */
|
||||
mbedtls_mps_stored_size_t pending;
|
||||
/*!< The amount of incoming data missing on the
|
||||
* last call to mbedtls_mps_reader_get().
|
||||
* In particular, it is \c 0 if the last call
|
||||
* was successful.
|
||||
* If a reader is reclaimed after an
|
||||
* unsuccessful call to mbedtls_mps_reader_get(),
|
||||
* this variable is used to have the reader
|
||||
* remember how much data should be accumulated
|
||||
* so that the call to mbedtls_mps_reader_get()
|
||||
* succeeds next time.
|
||||
* This is only used when the reader is in
|
||||
* consuming mode, i.e. \c frag != \c NULL;
|
||||
* otherwise, its value is \c 0. */
|
||||
|
||||
/* The accumulator is only needed if we need to be able to pause
|
||||
* the reader. A few bytes could be saved by moving this to a
|
||||
* separate struct and using a pointer here. */
|
||||
|
||||
unsigned char *acc; /*!< The accumulator is used to gather incoming
|
||||
* data if a read-request via mbedtls_mps_reader_get()
|
||||
* cannot be served from the current fragment. */
|
||||
mbedtls_mps_stored_size_t acc_len;
|
||||
/*!< The total size of the accumulator. */
|
||||
mbedtls_mps_stored_size_t acc_available;
|
||||
/*!< The number of bytes currently gathered in
|
||||
* the accumulator. This is both used in
|
||||
* producing and in consuming mode:
|
||||
* While producing, it is increased until
|
||||
* it reaches the value of \c acc_remaining below.
|
||||
* While consuming, it is used to judge if a
|
||||
* get request can be served from the
|
||||
* accumulator or not.
|
||||
* Must not be larger than \c acc_len. */
|
||||
union
|
||||
{
|
||||
mbedtls_mps_stored_size_t acc_remaining;
|
||||
/*!< This indicates the amount of data still
|
||||
* to be gathered in the accumulator. It is
|
||||
* only used in producing mode.
|
||||
* Must be at most acc_len - acc_available. */
|
||||
mbedtls_mps_stored_size_t frag_offset;
|
||||
/*!< If an accumulator is present and in use, this
|
||||
* field indicates the offset of the current
|
||||
* fragment from the beginning of the
|
||||
* accumulator. If no accumulator is present
|
||||
* or the accumulator is not in use, this is \c 0.
|
||||
* It is only used in consuming mode.
|
||||
* Must not be larger than \c acc_available. */
|
||||
} acc_share;
|
||||
};
|
||||
|
||||
/*
|
||||
* API organization:
|
||||
* A reader object is usually prepared and maintained
|
||||
* by some lower layer and passed for usage to an upper
|
||||
* layer, and the API naturally splits according to which
|
||||
* layer is supposed to use the respective functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Maintenance API (Lower layer)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Initialize a reader object
|
||||
*
|
||||
* \param reader The reader to be initialized.
|
||||
* \param acc The buffer to be used as a temporary accumulator
|
||||
* in case get requests through mbedtls_mps_reader_get()
|
||||
* exceed the buffer provided by mbedtls_mps_reader_feed().
|
||||
* This buffer is owned by the caller and exclusive use
|
||||
* for reading and writing is given to the reader for the
|
||||
* duration of the reader's lifetime. It is thus the caller's
|
||||
* responsibility to maintain (and not touch) the buffer for
|
||||
* the lifetime of the reader, and to properly zeroize and
|
||||
* free the memory after the reader has been destroyed.
|
||||
* \param acc_len The size in Bytes of \p acc.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_mps_reader_init( mbedtls_mps_reader *reader,
|
||||
unsigned char *acc,
|
||||
mbedtls_mps_size_t acc_len );
|
||||
|
||||
/**
|
||||
* \brief Free a reader object
|
||||
*
|
||||
* \param reader The reader to be freed.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_mps_reader_free( mbedtls_mps_reader *reader );
|
||||
|
||||
/**
|
||||
* \brief Pass chunk of data for the reader to manage.
|
||||
*
|
||||
* \param reader The reader context to use. The reader must be
|
||||
* in producing mode.
|
||||
* \param buf The buffer to be managed by the reader.
|
||||
* \param buflen The size in Bytes of \p buffer.
|
||||
*
|
||||
* \return \c 0 on success. In this case, the reader will be
|
||||
* moved to consuming mode and obtains read access
|
||||
* of \p buf until mbedtls_mps_reader_reclaim()
|
||||
* is called. It is the responsibility of the caller
|
||||
* to ensure that the \p buf persists and is not changed
|
||||
* between successful calls to mbedtls_mps_reader_feed()
|
||||
* and mbedtls_mps_reader_reclaim().
|
||||
* \return \c MBEDTLS_ERR_MPS_READER_NEED_MORE if more input data is
|
||||
* required to fulfill a previous request to mbedtls_mps_reader_get().
|
||||
* In this case, the reader remains in producing mode and
|
||||
* takes no ownership of the provided buffer (an internal copy
|
||||
* is made instead).
|
||||
* \return Another negative \c MBEDTLS_ERR_READER_XXX error code on
|
||||
* different kinds of failures.
|
||||
*/
|
||||
int mbedtls_mps_reader_feed( mbedtls_mps_reader *reader,
|
||||
unsigned char *buf,
|
||||
mbedtls_mps_size_t buflen );
|
||||
|
||||
/**
|
||||
* \brief Reclaim reader's access to the current input buffer.
|
||||
*
|
||||
* \param reader The reader context to use. The reader must be
|
||||
* in consuming mode.
|
||||
* \param paused If not \c NULL, the integer at address \p paused will be
|
||||
* modified to indicate whether the reader has been paused
|
||||
* (value \c 1) or not (value \c 0). Pausing happens if there
|
||||
* is uncommitted data and a previous request to
|
||||
* mbedtls_mps_reader_get() has exceeded the bounds of the
|
||||
* input buffer.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_mps_reader_reclaim( mbedtls_mps_reader *reader,
|
||||
int *paused );
|
||||
|
||||
/*
|
||||
* Usage API (Upper layer)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Request data from the reader.
|
||||
*
|
||||
* \param reader The reader context to use. The reader must
|
||||
* be in consuming mode.
|
||||
* \param desired The desired amount of data to be read, in Bytes.
|
||||
* \param buffer The address to store the buffer pointer in.
|
||||
* This must not be \c NULL.
|
||||
* \param buflen The address to store the actual buffer
|
||||
* length in, or \c NULL.
|
||||
*
|
||||
* \return \c 0 on success. In this case, \c *buf holds the
|
||||
* address of a buffer of size \c *buflen
|
||||
* (if \c buflen != \c NULL) or \c desired
|
||||
* (if \c buflen == \c NULL). The user has read access
|
||||
* to the buffer and guarantee of stability of the data
|
||||
* until the next call to mbedtls_mps_reader_reclaim().
|
||||
* \return #MBEDTLS_ERR_MPS_READER_OUT_OF_DATA if there is not enough
|
||||
* data available to serve the get request. In this case, the
|
||||
* reader remains intact and in consuming mode, and the consumer
|
||||
* should retry the call after a successful cycle of
|
||||
* mbedtls_mps_reader_reclaim() and mbedtls_mps_reader_feed().
|
||||
* If, after such a cycle, the consumer requests a different
|
||||
* amount of data, the result is implementation-defined;
|
||||
* progress is guaranteed only if the same amount of data
|
||||
* is requested after a mbedtls_mps_reader_reclaim() and
|
||||
* mbedtls_mps_reader_feed() cycle.
|
||||
* \return Another negative \c MBEDTLS_ERR_READER_XXX error
|
||||
* code for different kinds of failure.
|
||||
*
|
||||
* \note Passing \c NULL as \p buflen is a convenient way to
|
||||
* indicate that fragmentation is not tolerated.
|
||||
* It's functionally equivalent to passing a valid
|
||||
* address as buflen and checking \c *buflen == \c desired
|
||||
* afterwards.
|
||||
*/
|
||||
int mbedtls_mps_reader_get( mbedtls_mps_reader *reader,
|
||||
mbedtls_mps_size_t desired,
|
||||
unsigned char **buffer,
|
||||
mbedtls_mps_size_t *buflen );
|
||||
|
||||
/**
|
||||
* \brief Mark data obtained from mbedtls_mps_reader_get() as processed.
|
||||
*
|
||||
* This call indicates that all data received from prior calls to
|
||||
* mbedtls_mps_reader_get() has been or will have been
|
||||
* processed when mbedtls_mps_reader_reclaim() is called,
|
||||
* and thus need not be backed up.
|
||||
*
|
||||
* This function has no user observable effect until
|
||||
* mbedtls_mps_reader_reclaim() is called. In particular,
|
||||
* buffers received from mbedtls_mps_reader_get() remain
|
||||
* valid until mbedtls_mps_reader_reclaim() is called.
|
||||
*
|
||||
* \param reader The reader context to use.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative \c MBEDTLS_ERR_READER_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mps_reader_commit( mbedtls_mps_reader *reader );
|
||||
|
||||
#endif /* MBEDTLS_READER_H */
|
127
library/mps_trace.c
Normal file
127
library/mps_trace.c
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Message Processing Stack, Trace module
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
|
||||
|
||||
#include "mps_common.h"
|
||||
|
||||
#if defined(MBEDTLS_MPS_ENABLE_TRACE)
|
||||
|
||||
#include "mps_trace.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
static int trace_depth = 0;
|
||||
|
||||
#define color_default "\x1B[0m"
|
||||
#define color_red "\x1B[1;31m"
|
||||
#define color_green "\x1B[1;32m"
|
||||
#define color_yellow "\x1B[1;33m"
|
||||
#define color_blue "\x1B[1;34m"
|
||||
#define color_magenta "\x1B[1;35m"
|
||||
#define color_cyan "\x1B[1;36m"
|
||||
#define color_white "\x1B[1;37m"
|
||||
|
||||
static char const * colors[] =
|
||||
{
|
||||
color_default,
|
||||
color_green,
|
||||
color_yellow,
|
||||
color_magenta,
|
||||
color_cyan,
|
||||
color_blue,
|
||||
color_white
|
||||
};
|
||||
|
||||
#define MPS_TRACE_BUF_SIZE 100
|
||||
|
||||
void mbedtls_mps_trace_print_msg( int id, int line, const char *format, ... )
|
||||
{
|
||||
int ret;
|
||||
char str[MPS_TRACE_BUF_SIZE];
|
||||
va_list argp;
|
||||
va_start( argp, format );
|
||||
ret = mbedtls_vsnprintf( str, MPS_TRACE_BUF_SIZE, format, argp );
|
||||
va_end( argp );
|
||||
|
||||
if( ret >= 0 && ret < MPS_TRACE_BUF_SIZE )
|
||||
{
|
||||
str[ret] = '\0';
|
||||
mbedtls_printf( "[%d|L%d]: %s\n", id, line, str );
|
||||
}
|
||||
}
|
||||
|
||||
int mbedtls_mps_trace_get_depth()
|
||||
{
|
||||
return trace_depth;
|
||||
}
|
||||
void mbedtls_mps_trace_dec_depth()
|
||||
{
|
||||
trace_depth--;
|
||||
}
|
||||
void mbedtls_mps_trace_inc_depth()
|
||||
{
|
||||
trace_depth++;
|
||||
}
|
||||
|
||||
void mbedtls_mps_trace_color( int id )
|
||||
{
|
||||
if( id > (int) ( sizeof( colors ) / sizeof( *colors ) ) )
|
||||
return;
|
||||
printf( "%s", colors[ id ] );
|
||||
}
|
||||
|
||||
void mbedtls_mps_trace_indent( int level, mbedtls_mps_trace_type ty )
|
||||
{
|
||||
if( level > 0 )
|
||||
{
|
||||
while( --level )
|
||||
printf( "| " );
|
||||
|
||||
printf( "| " );
|
||||
}
|
||||
|
||||
switch( ty )
|
||||
{
|
||||
case MBEDTLS_MPS_TRACE_TYPE_COMMENT:
|
||||
mbedtls_printf( "@ " );
|
||||
break;
|
||||
|
||||
case MBEDTLS_MPS_TRACE_TYPE_CALL:
|
||||
mbedtls_printf( "+--> " );
|
||||
break;
|
||||
|
||||
case MBEDTLS_MPS_TRACE_TYPE_ERROR:
|
||||
mbedtls_printf( "E " );
|
||||
break;
|
||||
|
||||
case MBEDTLS_MPS_TRACE_TYPE_RETURN:
|
||||
mbedtls_printf( "< " );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_MPS_ENABLE_TRACE */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
|
175
library/mps_trace.h
Normal file
175
library/mps_trace.h
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file mps_trace.h
|
||||
*
|
||||
* \brief Tracing module for MPS
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H
|
||||
#define MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "mps_common.h"
|
||||
#include "mps_trace.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_vsnprintf vsnprintf
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
#if defined(MBEDTLS_MPS_ENABLE_TRACE)
|
||||
|
||||
/*
|
||||
* Adapt this to enable/disable tracing output
|
||||
* from the various layers of the MPS.
|
||||
*/
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_1
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_2
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_3
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_4
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_READER
|
||||
#define MBEDTLS_MPS_TRACE_ENABLE_WRITER
|
||||
|
||||
/*
|
||||
* To use the existing trace module, only change
|
||||
* MBEDTLS_MPS_TRACE_ENABLE_XXX above, but don't modify the
|
||||
* rest of this file.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
||||
MBEDTLS_MPS_TRACE_TYPE_CALL,
|
||||
MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
||||
MBEDTLS_MPS_TRACE_TYPE_RETURN
|
||||
} mbedtls_mps_trace_type;
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_BIT_LAYER_1 1
|
||||
#define MBEDTLS_MPS_TRACE_BIT_LAYER_2 2
|
||||
#define MBEDTLS_MPS_TRACE_BIT_LAYER_3 3
|
||||
#define MBEDTLS_MPS_TRACE_BIT_LAYER_4 4
|
||||
#define MBEDTLS_MPS_TRACE_BIT_WRITER 5
|
||||
#define MBEDTLS_MPS_TRACE_BIT_READER 6
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_1)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_1 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_1 )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_1 0
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_2)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_2 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_2 )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_2 0
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_3)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_3 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_3 )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_3 0
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_4)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_4 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_4 )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_LAYER_4 0
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_READER)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_READER (1u << MBEDTLS_MPS_TRACE_BIT_READER )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_READER 0
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MPS_TRACE_ENABLE_WRITER)
|
||||
#define MBEDTLS_MPS_TRACE_MASK_WRITER (1u << MBEDTLS_MPS_TRACE_BIT_WRITER )
|
||||
#else
|
||||
#define MBEDTLS_MPS_TRACE_MASK_WRITER 0
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_MASK ( MBEDTLS_MPS_TRACE_MASK_LAYER_1 | \
|
||||
MBEDTLS_MPS_TRACE_MASK_LAYER_2 | \
|
||||
MBEDTLS_MPS_TRACE_MASK_LAYER_3 | \
|
||||
MBEDTLS_MPS_TRACE_MASK_LAYER_4 | \
|
||||
MBEDTLS_MPS_TRACE_MASK_READER | \
|
||||
MBEDTLS_MPS_TRACE_MASK_WRITER )
|
||||
|
||||
/* We have to avoid globals because E-ACSL chokes on them...
|
||||
* Wrap everything in stub functions. */
|
||||
int mbedtls_mps_trace_get_depth( void );
|
||||
void mbedtls_mps_trace_inc_depth( void );
|
||||
void mbedtls_mps_trace_dec_depth( void );
|
||||
|
||||
void mbedtls_mps_trace_color( int id );
|
||||
void mbedtls_mps_trace_indent( int level, mbedtls_mps_trace_type ty );
|
||||
|
||||
void mbedtls_mps_trace_print_msg( int id, int line, const char *format, ... );
|
||||
|
||||
#define MBEDTLS_MPS_TRACE( type, ... ) \
|
||||
do { \
|
||||
if( ! ( MBEDTLS_MPS_TRACE_MASK & ( 1u << mbedtls_mps_trace_id ) ) ) \
|
||||
break; \
|
||||
mbedtls_mps_trace_indent( mbedtls_mps_trace_get_depth(), type ); \
|
||||
mbedtls_mps_trace_color( mbedtls_mps_trace_id ); \
|
||||
mbedtls_mps_trace_print_msg( mbedtls_mps_trace_id, __LINE__, __VA_ARGS__ ); \
|
||||
mbedtls_mps_trace_color( 0 ); \
|
||||
} while( 0 )
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_INIT( ... ) \
|
||||
do { \
|
||||
if( ! ( MBEDTLS_MPS_TRACE_MASK & ( 1u << mbedtls_mps_trace_id ) ) ) \
|
||||
break; \
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_CALL, __VA_ARGS__ ); \
|
||||
mbedtls_mps_trace_inc_depth(); \
|
||||
} while( 0 )
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_END( val ) \
|
||||
do { \
|
||||
if( ! ( MBEDTLS_MPS_TRACE_MASK & ( 1u << mbedtls_mps_trace_id ) ) ) \
|
||||
break; \
|
||||
MBEDTLS_MPS_TRACE( MBEDTLS_MPS_TRACE_TYPE_RETURN, "%d (-%#04x)", \
|
||||
(int) (val), -((unsigned)(val)) ); \
|
||||
mbedtls_mps_trace_dec_depth(); \
|
||||
} while( 0 )
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_RETURN( val ) \
|
||||
do { \
|
||||
/* Breaks tail recursion. */ \
|
||||
int ret__ = val; \
|
||||
MBEDTLS_MPS_TRACE_END( ret__ ); \
|
||||
return( ret__ ); \
|
||||
} while( 0 )
|
||||
|
||||
#else /* MBEDTLS_MPS_TRACE */
|
||||
|
||||
#define MBEDTLS_MPS_TRACE( type, ... ) do { } while( 0 )
|
||||
#define MBEDTLS_MPS_TRACE_INIT( ... ) do { } while( 0 )
|
||||
#define MBEDTLS_MPS_TRACE_END do { } while( 0 )
|
||||
|
||||
#define MBEDTLS_MPS_TRACE_RETURN( val ) return( val );
|
||||
|
||||
#endif /* MBEDTLS_MPS_TRACE */
|
||||
|
||||
#endif /* MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H */
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#if defined(MBEDTLS_PADLOCK_C)
|
||||
|
||||
#include "mbedtls/padlock.h"
|
||||
#include "padlock.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "pk_wrap.h"
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "pk_wrap.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
/* Even if RSA not activated, for the sake of RSA-alt */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \file pk_internal.h
|
||||
* \file pk_wrap.h
|
||||
*
|
||||
* \brief Public Key abstraction layer: wrapper functions
|
||||
*/
|
|
@ -222,7 +222,7 @@ int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *c;
|
||||
|
@ -310,7 +310,7 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *key, unsigned char *buf, si
|
|||
return( (int) len );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_key_der( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_key_der( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char *c;
|
||||
|
@ -553,7 +553,7 @@ int mbedtls_pk_write_key_der( mbedtls_pk_context *key, unsigned char *buf, size_
|
|||
#define PRV_DER_MAX_BYTES ( RSA_PRV_DER_MAX_BYTES > ECP_PRV_DER_MAX_BYTES ? \
|
||||
RSA_PRV_DER_MAX_BYTES : ECP_PRV_DER_MAX_BYTES )
|
||||
|
||||
int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_pubkey_pem( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char output_buf[PUB_DER_MAX_BYTES];
|
||||
|
@ -578,7 +578,7 @@ int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *key, unsigned char *buf, si
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_pk_write_key_pem( mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
int mbedtls_pk_write_key_pem( const mbedtls_pk_context *key, unsigned char *buf, size_t size )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned char output_buf[PRV_DER_MAX_BYTES];
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue