mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-01 04:20:45 +00:00
Merge branch 'development' into convert_NO_SHA384_to_positive
Conflicts: * configs/config-psa-crypto.h: modified here, removed in development * tests/suites/test_suite_x509parse.data: all conflicts are in depends_on lines where development made a change unrelated to MBEDTLS_SHAxxx and our branch either changed `MBEDTLS_SHA256_C` to `MBEDTLS_SHA224_C` or `MBEDTLS_SHA512_C:!MBEDTLS_SHA512_NO_SHA384` to ``MBEDTLS_SHA384_C`, with no change to what the test does. Pick the other branch's dependency changes then apply our SHA dpeendency change.
This commit is contained in:
commit
4228f895c0
@ -6,8 +6,12 @@ At any point in time, we have a number of maintained branches consisting of:
|
||||
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.
|
||||
this is where the next major version of Mbed TLS (version 3.0) is being
|
||||
prepared. It has API changes that make it incompatible with Mbed TLS 2.x,
|
||||
as well as all the new features and bug fixes and security fixes.
|
||||
- The [`development_2.x`](https://github.com/ARMmbed/mbedtls/tree/development_2.x) branch:
|
||||
this branch retains the API of Mbed TLS 2.x, and has a subset of the
|
||||
features added after Mbed TLS 2.26.0 and bug fixes and security fixes.
|
||||
- One or more long-time support (LTS) branches:
|
||||
these only get bug fixes and security fixes.
|
||||
|
||||
@ -48,6 +52,7 @@ The following branches are currently maintained:
|
||||
|
||||
- [master](https://github.com/ARMmbed/mbedtls/tree/master)
|
||||
- [`development`](https://github.com/ARMmbed/mbedtls/)
|
||||
- [`development_2.x`](https://github.com/ARMmbed/mbedtls/tree/development_2.x)
|
||||
- [`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>
|
||||
|
93
ChangeLog
93
ChangeLog
@ -1,5 +1,98 @@
|
||||
mbed TLS ChangeLog (Sorted per branch, date)
|
||||
|
||||
= Mbed TLS 3.0.0 branch released 2021-xx-xx
|
||||
|
||||
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.
|
||||
* Add missing const attributes to API functions.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
Requirement changes
|
||||
* The library now uses the %zu format specifier with the printf() family of
|
||||
functions, so requires a toolchain that supports it. This change does not
|
||||
affect the maintained LTS branches, so when contributing changes please
|
||||
bear this in mind and do not add them to backported code.
|
||||
|
||||
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 certificates can still be verified by using a custom
|
||||
verification profile.
|
||||
|
||||
* Removed deprecated things in psa/crypto_compat.h. Fixes #4284
|
||||
* Removed deprecated functions from hashing modules. Fixes #4280.
|
||||
* Remove PKCS#11 library wrapper. PKCS#11 has limited functionality,
|
||||
lacks automated tests and has scarce documentation. Also, PSA Crypto
|
||||
provides a more flexible private key management.
|
||||
More details on PCKS#11 wrapper removal can be found in the mailing list
|
||||
https://lists.trustedfirmware.org/pipermail/mbed-tls/2020-April/000024.html
|
||||
* Remove deprecated error codes. Fix #4283
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
* 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.
|
||||
* Add printf function attributes to mbedtls_debug_print_msg to ensure we
|
||||
get printf format specifier warnings.
|
||||
* 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.
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero. Fixes #1792
|
||||
* 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".
|
||||
|
||||
Changes
|
||||
* Fix the setting of the read timeout in the DTLS sample programs.
|
||||
* Add extra printf compiler warning flags to builds.
|
||||
* Fix memsan build false positive in x509_crt.c with clang 11
|
||||
* There is ongoing work for the next release (= Mbed TLS 3.0.0 branch to
|
||||
be released 2021-xx-xx), including various API-breaking changes.
|
||||
|
||||
= mbed TLS 2.26.0 branch released 2021-03-08
|
||||
|
||||
API changes
|
||||
|
3
ChangeLog.d/add-missing-parenthesis.txt
Normal file
3
ChangeLog.d/add-missing-parenthesis.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* Fix a compilation error when MBEDTLS_ECP_RANDOMIZE_MXZ_ALT is
|
||||
defined. Fixes #4217.
|
@ -1,2 +0,0 @@
|
||||
API changes
|
||||
* Add missing const attributes to API functions.
|
3
ChangeLog.d/aescrypt2.txt
Normal file
3
ChangeLog.d/aescrypt2.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Changes
|
||||
* Remove the AES sample application programs/aes/aescrypt2 which shows
|
||||
bad cryptographic practice. Fix #1906.
|
3
ChangeLog.d/allow_alt_cmac_without_des.txt
Normal file
3
ChangeLog.d/allow_alt_cmac_without_des.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Changes
|
||||
* Alternative implementations of CMAC may now opt to not support 3DES as a
|
||||
CMAC block cipher, and still pass the CMAC self test.
|
@ -1,5 +0,0 @@
|
||||
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.
|
4
ChangeLog.d/dhm_min_bitlen.txt
Normal file
4
ChangeLog.d/dhm_min_bitlen.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* In a TLS client, enforce the Diffie-Hellman minimum parameter size
|
||||
set with mbedtls_ssl_conf_dhm_min_bitlen() precisely. Before, the
|
||||
minimum size was rounded down to the nearest multiple of 8.
|
@ -1,2 +0,0 @@
|
||||
Changes
|
||||
* Fix the setting of the read timeout in the DTLS sample programs.
|
@ -1,5 +0,0 @@
|
||||
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.
|
2
ChangeLog.d/fix-pk-parse-key-error-code.txt
Normal file
2
ChangeLog.d/fix-pk-parse-key-error-code.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Bugfix
|
||||
* Fix an incorrect error code when parsing a PKCS#8 private key.
|
@ -1,10 +0,0 @@
|
||||
Bugfix
|
||||
* Add printf function attributes to mbedtls_debug_print_msg to ensure we
|
||||
get printf format specifier warnings.
|
||||
Changes
|
||||
* Add extra printf compiler warning flags to builds.
|
||||
Requirement changes
|
||||
* The library now uses the %zu format specifier with the printf() family of
|
||||
functions, so requires a toolchain that supports it. This change does not
|
||||
affect the maintained LTS branches, so when contributing changes please
|
||||
bear this in mind and do not add them to backported code.
|
@ -1,2 +0,0 @@
|
||||
Changes
|
||||
* Fix memsan build false positive in x509_crt.c with clang 11
|
@ -1,4 +0,0 @@
|
||||
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.
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fix a bug in ECDSA that would cause it to fail when the hash is all-bits
|
||||
zero. Fixes #1792
|
5
ChangeLog.d/issue4036.txt
Normal file
5
ChangeLog.d/issue4036.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Default behavior changes
|
||||
* Enable by default the functionalities which have no reason to be disabled.
|
||||
They are: ARIA block cipher, CMAC mode, elliptic curve J-PAKE library and
|
||||
Key Wrapping mode as defined in NIST SP 800-38F. Fixes #4036.
|
||||
|
@ -1,2 +0,0 @@
|
||||
Removals
|
||||
* Removed deprecated functions from hashing modules. Fixes #4280.
|
13
ChangeLog.d/issue4282.txt
Normal file
13
ChangeLog.d/issue4282.txt
Normal file
@ -0,0 +1,13 @@
|
||||
Removals
|
||||
* Remove the following deprecated functions and constants of hex-encoded
|
||||
primes based on RFC 5114 and RFC 3526 from library code and tests:
|
||||
mbedtls_aes_encrypt(), mbedtls_aes_decrypt(), mbedtls_mpi_is_prime(),
|
||||
mbedtls_cipher_auth_encrypt(), mbedtls_cipher_auth_decrypt(),
|
||||
mbedtls_ctr_drbg_update(), mbedtls_hmac_drbg_update(),
|
||||
mbedtls_ecdsa_write_signature_det(), mbedtls_ecdsa_sign_det(),
|
||||
mbedtls_ssl_conf_dh_param(), mbedtls_ssl_get_max_frag_len(),
|
||||
MBEDTLS_DHM_RFC5114_MODP_2048_P, MBEDTLS_DHM_RFC5114_MODP_2048_G,
|
||||
MBEDTLS_DHM_RFC3526_MODP_2048_P, MBEDTLS_DHM_RFC3526_MODP_2048_G,
|
||||
MBEDTLS_DHM_RFC3526_MODP_3072_P, MBEDTLS_DHM_RFC3526_MODP_3072_G,
|
||||
MBEDTLS_DHM_RFC3526_MODP_4096_P, MBEDTLS_DHM_RFC3526_MODP_4096_G.
|
||||
Remove the deprecated file: include/mbedtls/net.h. Fixes #4282.
|
@ -1,2 +0,0 @@
|
||||
Removals
|
||||
* Remove deprecated error codes. Fix #4283
|
@ -1,2 +0,0 @@
|
||||
Removals
|
||||
* Removed deprecated things in psa/crypto_compat.h. Fixes #4284
|
@ -1,7 +0,0 @@
|
||||
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.
|
@ -1,6 +0,0 @@
|
||||
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.
|
@ -1,3 +0,0 @@
|
||||
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".
|
@ -1,5 +0,0 @@
|
||||
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.
|
5
ChangeLog.d/psa-aead-output-size-macros-1.0.txt
Normal file
5
ChangeLog.d/psa-aead-output-size-macros-1.0.txt
Normal file
@ -0,0 +1,5 @@
|
||||
API changes
|
||||
* Update AEAD output size macros to bring them in line with the PSA Crypto
|
||||
API version 1.0 spec. This version of the spec parameterizes them on the
|
||||
key type used, as well as the key bit-size in the case of
|
||||
PSA_AEAD_TAG_LENGTH.
|
4
ChangeLog.d/psa-builtin-keys-implementation.txt
Normal file
4
ChangeLog.d/psa-builtin-keys-implementation.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Features
|
||||
* Added support for built-in driver keys through the PSA opaque crypto
|
||||
driver interface. Refer to the documentation of
|
||||
MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS for more information.
|
3
ChangeLog.d/remove-config-psa-crypto.txt
Normal file
3
ChangeLog.d/remove-config-psa-crypto.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Changes
|
||||
* Remove configs/config-psa-crypto.h, which no longer had any intended
|
||||
differences from the default configuration, but had accidentally diverged.
|
2
ChangeLog.d/remove-enable-weak-ciphersuites.txt
Normal file
2
ChangeLog.d/remove-enable-weak-ciphersuites.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Removals
|
||||
* Remove MBEDTLS_ENABLE_WEAK_CIPHERSUITES configuration option. Fixes #4416.
|
@ -1,14 +0,0 @@
|
||||
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
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
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.
|
@ -1,9 +0,0 @@
|
||||
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.
|
@ -1,10 +0,0 @@
|
||||
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.
|
@ -1,3 +0,0 @@
|
||||
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.
|
@ -1,6 +0,0 @@
|
||||
Removals
|
||||
* Remove PKCS#11 library wrapper. PKCS#11 has limited functionality,
|
||||
lacks automated tests and has scarce documentation. Also, PSA Crypto
|
||||
provides a more flexible private key management.
|
||||
More details on PCKS#11 wrapper removal can be found in the mailing list
|
||||
https://lists.trustedfirmware.org/pipermail/mbed-tls/2020-April/000024.html
|
5
ChangeLog.d/rm-ticket-lifetime-option
Normal file
5
ChangeLog.d/rm-ticket-lifetime-option
Normal file
@ -0,0 +1,5 @@
|
||||
Removals
|
||||
* Remove the MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
|
||||
compile-time option. This option has been inactive for a long time.
|
||||
Please use the `lifetime` parameter of `mbedtls_ssl_ticket_setup()`
|
||||
instead.
|
6
ChangeLog.d/x509_remove_info.txt
Normal file
6
ChangeLog.d/x509_remove_info.txt
Normal file
@ -0,0 +1,6 @@
|
||||
API changes
|
||||
* Add configuration option MBEDTLS_X509_REMOVE_INFO which
|
||||
removes the mbedtls_x509_*_info(), mbedtls_debug_print_crt()
|
||||
as well as other functions and constants only used by
|
||||
those functions. This reduces the code footprint by
|
||||
several kB.
|
@ -5,6 +5,11 @@ Mbed TLS is a C library that implements cryptographic primitives, X.509 certific
|
||||
|
||||
Mbed TLS includes a reference implementation of the [PSA Cryptography API](#psa-cryptography-api). This is currently a preview for evaluation purposes only.
|
||||
|
||||
Stability
|
||||
---------
|
||||
|
||||
**Warning: the [`development`](https://github.com/ARMmbed/mbedtls/tree/development) branch of Mbed TLS currently has an unstable API.** It is where work is happening on the next major release of Mbed TLS. Until Mbed TLS 3.0 is released, if you need a stable API, please use the branch [`development_2.x`](https://github.com/ARMmbed/mbedtls/tree/development_2.x) instead.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
27
docs/3.0-migration-guide.d/00README
Normal file
27
docs/3.0-migration-guide.d/00README
Normal file
@ -0,0 +1,27 @@
|
||||
Please add your migration guide entries here. Until 3.0 is released, each PR
|
||||
that makes backwards-incompatible changes should add a file here, with the
|
||||
extension .md, a descriptive name and the following format:
|
||||
|
||||
---%<------%<------%<------%<------%<------%<------%<------%<---
|
||||
|
||||
The change that was made
|
||||
------------------------
|
||||
|
||||
Who exactly is affected: does this affect users of the default config, of a
|
||||
particular feature? Remember to contextualise.
|
||||
|
||||
If I'm affected, what's my migration path? How should I change my code if this
|
||||
is an API change; if a feature was removed what are my alternatives?
|
||||
|
||||
---%<------%<------%<------%<------%<------%<------%<------%<---
|
||||
|
||||
PRs that make multiple independent changes should include one entry for each
|
||||
changes or logical groups of changes. You can either add multiple files or put
|
||||
multiple entries in the same file.
|
||||
|
||||
For examples, have a look a docs/3.0-migration-guide.md (which includes the
|
||||
top-level header and an intro before the list of entries).
|
||||
|
||||
As part of release preparation, the entries in this directory will be appended
|
||||
to docs/3.0-migration-guide.md and then re-ordered and reviewed one last time.
|
||||
The file is then going to be moved to the version-independent docs repo.
|
@ -0,0 +1,12 @@
|
||||
Remove the configuration to enable weak ciphersuites in SSL / TLS
|
||||
-----------------------------------------------------------------
|
||||
|
||||
This does not affect users who use the default `config.h`, as this option was
|
||||
already off by default.
|
||||
|
||||
If you were using a weak cipher, please switch to any of the modern,
|
||||
recommended ciphersuites (based on AES-GCM, AES-CCM or ChachaPoly for example)
|
||||
and if your peer doesn't support any, encourage them to upgrade their software.
|
||||
|
||||
If you were using a ciphersuite without encryption, you just have to
|
||||
enable MBEDTLS_CIPHER_NULL_CIPHER now.
|
@ -0,0 +1,72 @@
|
||||
Deprecated functions were removed from AES
|
||||
------------------------------------------
|
||||
|
||||
The functions `mbedtls_aes_encrypt()` and `mbedtls_aes_decrypt()` were
|
||||
removed.
|
||||
|
||||
If you're simply using the AES module, you should be calling the higher-level
|
||||
functions `mbedtls_aes_crypt_xxx()`.
|
||||
|
||||
If you're providing an alternative implementation using
|
||||
`MBEDTLS_AES_ENCRYPT_ALT` or `MBEDTLS_AES_DECRYPT_ALT`, you should be
|
||||
replacing the removed functions with `mbedtls_internal_aes_encrypt()` and
|
||||
`mbedtls_internal_aes_decrypt()` respectively.
|
||||
|
||||
Deprecated functions were removed from bignum
|
||||
---------------------------------------------
|
||||
|
||||
The function `mbedtls_mpi_is_prime()` was removed. Please use
|
||||
`mbedtls_mpi_is_prime_ext()` instead which additionally allows specifying the
|
||||
number of Miller-Rabin rounds.
|
||||
|
||||
Deprecated functions were removed from cipher
|
||||
---------------------------------------------
|
||||
|
||||
The functions `mbedtls_cipher_auth_encrypt()` and
|
||||
`mbedtls_cipher_auth_decrypt()` were removed. They were superseded by
|
||||
`mbedtls_cipher_auth_encrypt_ext()` and `mbedtls_cipher_auth_decrypt_ext()`
|
||||
respectively which additionally support key wrapping algorithms such as
|
||||
NIST_KW.
|
||||
|
||||
Deprecated functions were removed from DRBGs
|
||||
--------------------------------------------
|
||||
|
||||
The functions `mbedtls_ctr_drbg_update()` and `mbedtls_hmac_drbg_update()`
|
||||
were removed. They were superseded by `mbedtls_ctr_drbg_update_ret()` and
|
||||
`mbedtls_hmac_drbg_update_ret()` respectively.
|
||||
|
||||
Deprecated functions were removed from ECDSA
|
||||
--------------------------------------------
|
||||
|
||||
The functions `mbedtls_ecdsa_write_signature_det()` and
|
||||
`mbedtls_ecdsa_sign_det()` were removed. They were superseded by
|
||||
`mbedtls_ecdsa_write_signature()` and `mbedtls_ecdsa_sign_det_ext()`
|
||||
respectively.
|
||||
|
||||
Deprecated functions were removed from SSL
|
||||
------------------------------------------
|
||||
|
||||
The function `mbedtls_ssl_conf_dh_param()` was removed. Please use
|
||||
`mbedtls_ssl_conf_dh_param_bin()` or `mbedtls_ssl_conf_dh_param_ctx()` instead.
|
||||
|
||||
The function `mbedtls_ssl_get_max_frag_len()` was removed. Please use
|
||||
`mbedtls_ssl_get_output_max_frag_len()` instead.
|
||||
|
||||
Deprecated hex-encoded primes were removed from DHM
|
||||
---------------------------------------------------
|
||||
|
||||
The macros `MBEDTLS_DHM_RFC5114_MODP_2048_P`, `MBEDTLS_DHM_RFC5114_MODP_2048_G`,
|
||||
`MBEDTLS_DHM_RFC3526_MODP_2048_P`, `MBEDTLS_DHM_RFC3526_MODP_2048_G`,
|
||||
`MBEDTLS_DHM_RFC3526_MODP_3072_P`, `MBEDTLS_DHM_RFC3526_MODP_3072_G`,
|
||||
`MBEDTLS_DHM_RFC3526_MODP_4096_P `and `MBEDTLS_DHM_RFC3526_MODP_4096_G` were
|
||||
removed. The primes from RFC 5114 are deprecated because their derivation is not
|
||||
documented and therefore their usage constitutes a security risk; they are fully
|
||||
removed from the library. Please use parameters from RFC3526 (still in the
|
||||
library, only in binary form) or RFC 7919 (also available in the library) or
|
||||
other trusted sources instead.
|
||||
|
||||
Deprecated net.h file was removed
|
||||
---------------------------------
|
||||
|
||||
The file `include/mbedtls/net.h` was removed because its only function was to
|
||||
include `mbedtls/net_sockets.h` which now should be included directly.
|
222
docs/3.0-migration-guide.md
Normal file
222
docs/3.0-migration-guide.md
Normal file
@ -0,0 +1,222 @@
|
||||
Migrating from Mbed TLS 2.x to Mbed TLS 3.0
|
||||
===========================================
|
||||
|
||||
This guide details the steps required to migrate from Mbed TLS version 2.x to
|
||||
Mbed TLS version 3.0 or greater. Unlike normal releases, Mbed TLS 3.0 breaks
|
||||
compatibility with previous versions, so users (and alt implementors) might
|
||||
need to change their own code in order to make it work with Mbed TLS 3.0.
|
||||
|
||||
Here's the list of breaking changes; each entry should help you answer these
|
||||
two questions: (1) am I affected? (2) if yes, what's my migration path?
|
||||
|
||||
Some function parameters were made const
|
||||
----------------------------------------
|
||||
|
||||
Various functions in the PK and ASN.1 modules had a `const` qualifier added to
|
||||
some of their parameters.
|
||||
|
||||
This normally doesn't affect your code, unless you use pointers to reference
|
||||
those functions. In this case, you'll need to update the type of your pointers
|
||||
in order to match the new signature.
|
||||
|
||||
Deprecated functions were removed from hashing modules
|
||||
------------------------------------------------------
|
||||
|
||||
Modules: MD2, MD4, MD5, SHA1, SHA256, SHA512, MD.
|
||||
|
||||
- The functions `mbedtls_xxx_starts()`, `mbedtls_xxx_update()`,
|
||||
`mbedtls_xxx_finish()` and `mbedtls_xxx()` were removed. Please use the
|
||||
function with the same name with `_ret` appended and check the return value.
|
||||
- The function `mbedtls_md_init_ctx()` was removed; please use
|
||||
`mbedtls_md_setup()` instead.
|
||||
- The functions `mbedtls_xxx_process()` were removed. You normally don't need
|
||||
to call that from application code. However if you do (or if you want to
|
||||
provide your own version of that function), please use
|
||||
`mbedtls_internal_xxx_process()` instead, and check the return value.
|
||||
|
||||
Deprecated error codes for hardware failures were removed
|
||||
---------------------------------------------------------
|
||||
|
||||
- The macros `MBEDTLS_ERR_xxx_FEATURE_UNSUPPORTED` from various crypto modules
|
||||
were removed; `MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED` is now used
|
||||
instead.
|
||||
- The macros `MBEDTLS_ERR_xxx_HW_ACCEL_FAILED` from various crypto modules
|
||||
were removed; `MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED` is now used instead.
|
||||
|
||||
Deprecated names for PSA constants and types were removed
|
||||
---------------------------------------------------------
|
||||
|
||||
Some constants and types that were present in beta versions of the PSA Crypto
|
||||
API were removed from version 1.0 of specification. Please switch to the new
|
||||
names provided by the 1.0 specification instead.
|
||||
|
||||
Internal / alt-focused headers were moved to a private location
|
||||
----------------------------------------------------------------
|
||||
|
||||
This shouldn't affect users who took care not to include headers that
|
||||
were documented as internal, despite being in the public include directory.
|
||||
|
||||
If you're providing alt implementations of ECP or RSA, you'll need to add our
|
||||
`library` directory to your include path when building your alt
|
||||
implementations, and note that `ecp_internal.h` and `rsa_internal.h` have been
|
||||
renamed to `ecp_alt.h` and `rsa_alt_helpers.h` respectively.
|
||||
|
||||
If you're a library user and used to rely on having access to a structure or
|
||||
function that's now in a private header, please reach out on the mailing list
|
||||
and explain your need; we'll consider adding a new API in a future version.
|
||||
|
||||
Remove the option to allow SHA-1 by default in certificates
|
||||
-----------------------------------------------------------
|
||||
|
||||
This does not affect users who use the default `config.h`, as this option was
|
||||
already off by default.
|
||||
|
||||
If you used to enable `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES` in your
|
||||
`config.h`, first please take a moment to consider whether you really still
|
||||
want to accept certificates signed with SHA-1 as those are considered insecure
|
||||
and no CA has issued them for a while. If you really need to allow SHA-1 in
|
||||
certificates, please set up a custom profile as follows:
|
||||
|
||||
```
|
||||
const mbedtls_x509_crt_profile mbedtls_x509_crt_custom = {
|
||||
MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA1 ) |
|
||||
MBEDTLS_X509_ID_FLAG( /* other hash */ ) /* | etc */,
|
||||
0xFFFFFFF, /* Or specific PK algs */
|
||||
0xFFFFFFF, /* Or specific curves */
|
||||
2048 /* Or another RSA min bitlen */
|
||||
};
|
||||
```
|
||||
Then pass it to `mbedtls_x509_crt_verify_with_profile()` if you're verifying
|
||||
a certificate chain directly, or to `mbedtls_ssl_conf_cert_profile()` if the
|
||||
verification happens during a TLS handshake.
|
||||
|
||||
Remove the certs module from the library
|
||||
----------------------------------------
|
||||
|
||||
This should not affect production use of the library, as the certificates and
|
||||
keys included there were never suitable for production use.
|
||||
|
||||
However it might affect you if you relied on them for testing purposes. In
|
||||
that case, please embed your own test certificates in your test code; now that
|
||||
`certs.c` is out of the library there is no longer any stability guaranteed
|
||||
and it may change in incompatible ways at any time.
|
||||
|
||||
Remove the HAVEGE module
|
||||
------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This only affects users who called the HAVEGE modules directly (not
|
||||
recommended), or users who used it through the entropy module but had it as the
|
||||
only source of entropy. If you're in that case, please 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.
|
||||
|
||||
Remove support for parsing SSLv2 ClientHello
|
||||
--------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This only affects TLS servers that have clients who send an SSLv2 ClientHello.
|
||||
These days clients are very unlikely to do that. If you have a client that
|
||||
does, please try contacting them and encouraging them to upgrade their
|
||||
software.
|
||||
|
||||
Remove support for SSL 3.0
|
||||
--------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This only affects TLS users who explicitly enabled `MBEDTLS_SSL_PROTO_SSL3`
|
||||
and relied on that version in order to communicate with peers that are not up
|
||||
to date. If one of your peers is in that case, please try contacting them and
|
||||
encouraging them to upgrade their software.
|
||||
|
||||
Remove support for compatibility with old Mbed TLS's truncated HMAC
|
||||
-------------------------------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This only affects TLS users who enabled `MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT` and
|
||||
used the Truncated HMAC extension to communicate with peers using old version
|
||||
of Mbed TLS. Please consider using a CCM-8 ciphersuite instead of the
|
||||
Truncated HMAC extension, or convincing your peer to upgrade their version of
|
||||
Mbed TLS.
|
||||
|
||||
Remove support for TLS record-level compression
|
||||
-----------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This only affects TLS users who enabled `MBEDTLS_ZLIB_SUPPORT`. This will not
|
||||
cause any failures however if you used to enable TLS record-level compression
|
||||
you may find that your bandwidth usage increases without compression. There's
|
||||
no general solution to this problem; application protocols might have their
|
||||
own compression mechanisms and are in a better position than the TLS stack to
|
||||
avoid variants of the CRIME and BREACH attacks.
|
||||
|
||||
Remove support for TLS RC4-based ciphersuites
|
||||
---------------------------------------------
|
||||
|
||||
This does not affect people who used the default `config.h` and the default
|
||||
list of ciphersuites, as RC4-based ciphersuites were already not negotiated in
|
||||
that case.
|
||||
|
||||
Please switch to any of the modern, recommended ciphersuites (based on
|
||||
AES-GCM, AES-CCM or ChachaPoly for example) and if your peer doesn't support
|
||||
any, encourage them to upgrade their software.
|
||||
|
||||
Remove support for TLS single-DES ciphersuites
|
||||
----------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
Please switch to any of the modern, recommended ciphersuites (based on
|
||||
AES-GCM, AES-CCM or ChachaPoly for example) and if your peer doesn't support
|
||||
any, encourage them to upgrade their software.
|
||||
|
||||
Remove support for TLS record-level hardware acceleration
|
||||
---------------------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
This feature had been broken for a while so we doubt anyone still used it.
|
||||
However if you did, please reach out on the mailing list and let us know about
|
||||
your use case.
|
||||
|
||||
Remove wrapper for libpkcs11-helper
|
||||
-----------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration as it was already
|
||||
disabled by default.
|
||||
|
||||
If you used to rely on this module in order to store your private keys
|
||||
securely, please have a look at the key management facilities provided by the
|
||||
PSA crypto API. If you have a use case that's not covered yet by this API,
|
||||
please reach out on the mailing list.
|
||||
|
||||
Remove config option `MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME`
|
||||
----------------------------------------------------------
|
||||
|
||||
This doesn't affect people using the default configuration.
|
||||
|
||||
This option has not had any effect for a long time. Please use the `lifetime`
|
||||
parameter of `mbedtls_ssl_ticket_setup()` instead.
|
||||
|
||||
Remove helpers for the transition from Mbed TLS 1.3 to Mbed TLS 2.0
|
||||
-------------------------------------------------------------------
|
||||
|
||||
This only affects people who've been using Mbed TLS since before version 2.0
|
||||
and still relied on `compat-1.3.h` in their code.
|
||||
|
||||
Please use the new names directly in your code; `scripts/rename.pl` (from any
|
||||
of the 2.x releases - no longer included in 3.0) might help you do that.
|
@ -63,7 +63,7 @@ Key creation implementation in Mbed TLS PSA core is articulated around three int
|
||||
3. Generate or copy the key material into the key slot. This entails the allocation of the buffer to store the key material.
|
||||
4. Call psa_finish_key_creation() that mostly saves persistent keys into persistent storage.
|
||||
|
||||
In case of any error occuring at step 3 or 4, psa_fail_key_creation() is called. It wipes and cleans the slot especially the key material: reset to zero of the RAM memory that contained the key material, free the allocated buffer.
|
||||
In case of any error occurring at step 3 or 4, psa_fail_key_creation() is called. It wipes and cleans the slot especially the key material: reset to zero of the RAM memory that contained the key material, free the allocated buffer.
|
||||
|
||||
|
||||
## Mbed TLS PSA Cryptography API implementation drivers
|
||||
|
@ -810,7 +810,7 @@ psa_status_t acme_get_builtin_key(psa_drv_slot_number_t slot_number,
|
||||
|
||||
If this function returns `PSA_SUCCESS` or `PSA_ERROR_BUFFER_TOO_SMALL`, it must fill `attributes` with the attributes of the key (except for the key identifier). On success, this function must also fill `key_buffer` with the key context.
|
||||
|
||||
On entry, `psa_get_key_lifetime(attributes)` is the location at which the driver was declared and the persistence level `#PSA_KEY_LIFETIME_PERSISTENT`. The driver entry point may change the lifetime to one with the same location but a different persistence level. The standard attributes other than the key identifier and lifetime have the value conveyed by `PSA_KEY_ATTRIBUTES_INIT`.
|
||||
On entry, `psa_get_key_lifetime(attributes)` is the location at which the driver was declared and a persistence level with which the platform is attempting to register the key. The driver entry point may choose to change the lifetime (`psa_set_key_lifetime(attributes, lifetime)`) of the reported key attributes to one with the same location but a different persistence level, in case the driver has more specific knowledge about the actual persistence level of the key which is being retrieved. For example, if a driver knows it cannot delete a key, it may override the persistence level in the lifetime to `PSA_KEY_PERSISTENCE_READ_ONLY`. The standard attributes other than the key identifier and lifetime have the value conveyed by `PSA_KEY_ATTRIBUTES_INIT`.
|
||||
|
||||
The output parameter `key_buffer` points to a writable buffer of `key_buffer_size` bytes. If the driver has a [`"builtin_key_size"` property](#key-format-for-opaque-drivers) property, `key_buffer_size` has this value, otherwise `key_buffer_size` has the value determined from the key type and size.
|
||||
|
||||
|
@ -611,44 +611,6 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief Deprecated internal AES block encryption function
|
||||
* without return value.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_internal_aes_encrypt()
|
||||
*
|
||||
* \param ctx The AES context to use for encryption.
|
||||
* \param input Plaintext block.
|
||||
* \param output Output (ciphertext) block.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief Deprecated internal AES block decryption function
|
||||
* without return value.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_internal_aes_decrypt()
|
||||
*
|
||||
* \param ctx The AES context to use for decryption.
|
||||
* \param input Ciphertext block.
|
||||
* \param output Output (plaintext) block.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine.
|
||||
|
@ -904,37 +904,6 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A,
|
||||
int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *N );
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief Perform a Miller-Rabin primality test with error
|
||||
* probability of 2<sup>-80</sup>.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_mpi_is_prime_ext() which allows
|
||||
* specifying the number of Miller-Rabin rounds.
|
||||
*
|
||||
* \param X The MPI to check for primality.
|
||||
* This must point to an initialized MPI.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG parameter to be passed to \p f_rng.
|
||||
* This may be \c NULL if \p f_rng doesn't use a
|
||||
* context parameter.
|
||||
*
|
||||
* \return \c 0 if successful, i.e. \p X is probably prime.
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief Miller-Rabin primality test.
|
||||
*
|
||||
|
@ -467,8 +467,8 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
|
||||
* \param cipher_info The cipher to use.
|
||||
* \param taglen For AEAD ciphers, the length in bytes of the
|
||||
* authentication tag to use. Subsequent uses of
|
||||
* mbedtls_cipher_auth_encrypt() or
|
||||
* mbedtls_cipher_auth_decrypt() must provide
|
||||
* mbedtls_cipher_auth_encrypt_ext() or
|
||||
* mbedtls_cipher_auth_decrypt_ext() must provide
|
||||
* the same tag length.
|
||||
* For non-AEAD ciphers, the value must be \c 0.
|
||||
*
|
||||
@ -853,129 +853,6 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif /* MBEDTLS_DEPRECATED_WARNING */
|
||||
/**
|
||||
* \brief The generic authenticated encryption (AEAD) function.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_cipher_auth_encrypt_ext().
|
||||
*
|
||||
* \note This function only supports AEAD algorithms, not key
|
||||
* wrapping algorithms such as NIST_KW; for this, see
|
||||
* mbedtls_cipher_auth_encrypt_ext().
|
||||
*
|
||||
* \param ctx The generic cipher context. This must be initialized and
|
||||
* bound to a key associated with an AEAD algorithm.
|
||||
* \param iv The nonce to use. This must be a readable buffer of
|
||||
* at least \p iv_len Bytes and must not be \c NULL.
|
||||
* \param iv_len The length of the nonce. This must satisfy the
|
||||
* constraints imposed by the AEAD cipher used.
|
||||
* \param ad The additional data to authenticate. This must be a
|
||||
* readable buffer of at least \p ad_len Bytes, and may
|
||||
* be \c NULL is \p ad_len is \c 0.
|
||||
* \param ad_len The length of \p ad.
|
||||
* \param input The buffer holding the input data. This must be a
|
||||
* readable buffer of at least \p ilen Bytes, and may be
|
||||
* \c NULL if \p ilen is \c 0.
|
||||
* \param ilen The length of the input data.
|
||||
* \param output The buffer for the output data. This must be a
|
||||
* writable buffer of at least \p ilen Bytes, and must
|
||||
* not be \c NULL.
|
||||
* \param olen This will be filled with the actual number of Bytes
|
||||
* written to the \p output buffer. This must point to a
|
||||
* writable object of type \c size_t.
|
||||
* \param tag The buffer for the authentication tag. This must be a
|
||||
* writable buffer of at least \p tag_len Bytes. See note
|
||||
* below regarding restrictions with PSA-based contexts.
|
||||
* \param tag_len The desired length of the authentication tag. This
|
||||
* must match the constraints imposed by the AEAD cipher
|
||||
* used, and in particular must not be \c 0.
|
||||
*
|
||||
* \note If the context is based on PSA (that is, it was set up
|
||||
* with mbedtls_cipher_setup_psa()), then it is required
|
||||
* that \c tag == output + ilen. That is, the tag must be
|
||||
* appended to the ciphertext as recommended by RFC 5116.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
||||
* parameter-verification failure.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen,
|
||||
unsigned char *tag, size_t tag_len )
|
||||
MBEDTLS_DEPRECATED;
|
||||
|
||||
/**
|
||||
* \brief The generic authenticated decryption (AEAD) function.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_cipher_auth_decrypt_ext().
|
||||
*
|
||||
* \note This function only supports AEAD algorithms, not key
|
||||
* wrapping algorithms such as NIST_KW; for this, see
|
||||
* mbedtls_cipher_auth_decrypt_ext().
|
||||
*
|
||||
* \note If the data is not authentic, then the output buffer
|
||||
* is zeroed out to prevent the unauthentic plaintext being
|
||||
* used, making this interface safer.
|
||||
*
|
||||
* \param ctx The generic cipher context. This must be initialized and
|
||||
* bound to a key associated with an AEAD algorithm.
|
||||
* \param iv The nonce to use. This must be a readable buffer of
|
||||
* at least \p iv_len Bytes and must not be \c NULL.
|
||||
* \param iv_len The length of the nonce. This must satisfy the
|
||||
* constraints imposed by the AEAD cipher used.
|
||||
* \param ad The additional data to authenticate. This must be a
|
||||
* readable buffer of at least \p ad_len Bytes, and may
|
||||
* be \c NULL is \p ad_len is \c 0.
|
||||
* \param ad_len The length of \p ad.
|
||||
* \param input The buffer holding the input data. This must be a
|
||||
* readable buffer of at least \p ilen Bytes, and may be
|
||||
* \c NULL if \p ilen is \c 0.
|
||||
* \param ilen The length of the input data.
|
||||
* \param output The buffer for the output data. This must be a
|
||||
* writable buffer of at least \p ilen Bytes, and must
|
||||
* not be \c NULL.
|
||||
* \param olen This will be filled with the actual number of Bytes
|
||||
* written to the \p output buffer. This must point to a
|
||||
* writable object of type \c size_t.
|
||||
* \param tag The buffer for the authentication tag. This must be a
|
||||
* readable buffer of at least \p tag_len Bytes. See note
|
||||
* below regarding restrictions with PSA-based contexts.
|
||||
* \param tag_len The length of the authentication tag. This must match
|
||||
* the constraints imposed by the AEAD cipher used, and in
|
||||
* particular must not be \c 0.
|
||||
*
|
||||
* \note If the context is based on PSA (that is, it was set up
|
||||
* with mbedtls_cipher_setup_psa()), then it is required
|
||||
* that \c tag == input + len. That is, the tag must be
|
||||
* appended to the ciphertext as recommended by RFC 5116.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
||||
* parameter-verification failure.
|
||||
* \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen,
|
||||
const unsigned char *tag, size_t tag_len )
|
||||
MBEDTLS_DEPRECATED;
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
|
||||
/**
|
||||
* \brief The authenticated encryption (AEAD/NIST_KW) function.
|
||||
|
@ -74,6 +74,12 @@ struct mbedtls_cmac_context_t
|
||||
* the input data.
|
||||
* Must be called with an initialized cipher context.
|
||||
*
|
||||
* \note When the CMAC implementation is supplied by an alternate
|
||||
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
||||
* may not be supported by that implementation, and thus
|
||||
* return an error. Alternate implementations must support
|
||||
* AES-128 and AES-256, and may support AES-192 and 3DES.
|
||||
*
|
||||
* \param ctx The cipher context used for the CMAC operation, initialized
|
||||
* as one of the following types: MBEDTLS_CIPHER_AES_128_ECB,
|
||||
* MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_CIPHER_AES_256_ECB,
|
||||
@ -151,6 +157,11 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
||||
* The CMAC result is calculated as
|
||||
* output = generic CMAC(cmac key, input buffer).
|
||||
*
|
||||
* \note When the CMAC implementation is supplied by an alternate
|
||||
* implementation (through #MBEDTLS_CMAC_ALT), some ciphers
|
||||
* may not be supported by that implementation, and thus
|
||||
* return an error. Alternate implementations must support
|
||||
* AES-128 and AES-256, and may support AES-192 and 3DES.
|
||||
*
|
||||
* \param cipher_info The cipher information.
|
||||
* \param key The CMAC key.
|
||||
@ -195,6 +206,13 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
||||
/**
|
||||
* \brief The CMAC checkup routine.
|
||||
*
|
||||
* \note In case the CMAC routines are provided by an alternative
|
||||
* implementation (i.e. #MBEDTLS_CMAC_ALT is defined), the
|
||||
* checkup routine will succeed even if the implementation does
|
||||
* not support the less widely used AES-192 or 3DES primitives.
|
||||
* The self-test requires at least AES-128 and AES-256 to be
|
||||
* supported by the underlying implementation.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
|
@ -421,12 +421,6 @@
|
||||
* of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible
|
||||
* with this definition.
|
||||
*
|
||||
* \note Because of a signature change, the core AES encryption and decryption routines are
|
||||
* currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt,
|
||||
* respectively. When setting up alternative implementations, these functions should
|
||||
* be overridden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
|
||||
* must stay untouched.
|
||||
*
|
||||
* \note If you use the AES_xxx_ALT macros, then is is recommended to also set
|
||||
* MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
|
||||
* tables.
|
||||
@ -445,9 +439,7 @@
|
||||
* alternative implementations should use the RNG only for generating
|
||||
* the ephemeral key and nothing else. If this is not possible, then
|
||||
* MBEDTLS_ECDSA_DETERMINISTIC should be disabled and an alternative
|
||||
* implementation should be provided for mbedtls_ecdsa_sign_det_ext()
|
||||
* (and for mbedtls_ecdsa_sign_det() too if backward compatibility is
|
||||
* desirable).
|
||||
* implementation should be provided for mbedtls_ecdsa_sign_det_ext().
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_MD2_PROCESS_ALT
|
||||
@ -659,8 +651,7 @@
|
||||
* Warning: Only do so when you know what you are doing. This allows for
|
||||
* encryption or channels without any security!
|
||||
*
|
||||
* Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable
|
||||
* the following ciphersuites:
|
||||
* To enable the following ciphersuites:
|
||||
* MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA
|
||||
* MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA
|
||||
* MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA
|
||||
@ -708,20 +699,6 @@
|
||||
*/
|
||||
//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES
|
||||
*
|
||||
* Enable weak ciphersuites in SSL / TLS.
|
||||
* Warning: Only do so when you know what you are doing. This allows for
|
||||
* channels with virtually no security at all!
|
||||
*
|
||||
* Uncomment this macro to enable weak ciphersuites
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers instead.
|
||||
*/
|
||||
//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_REMOVE_3DES_CIPHERSUITES
|
||||
*
|
||||
@ -1312,6 +1289,22 @@
|
||||
*/
|
||||
#define MBEDTLS_PKCS1_V21
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
|
||||
*
|
||||
* Enable support for platform built-in keys. If you enable this feature,
|
||||
* you must implement the function mbedtls_psa_platform_get_builtin_key().
|
||||
* See the documentation of that function for more information.
|
||||
*
|
||||
* Built-in keys are typically derived from a hardware unique key or
|
||||
* stored in a secure element.
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C.
|
||||
*
|
||||
* \warning This interface is experimental and may change or be removed
|
||||
* without notice.
|
||||
*/
|
||||
//#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
|
||||
|
||||
/** \def MBEDTLS_PSA_CRYPTO_CLIENT
|
||||
*
|
||||
* Enable support for PSA crypto client.
|
||||
@ -2115,6 +2108,17 @@
|
||||
*/
|
||||
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_REMOVE_INFO
|
||||
*
|
||||
* Disable mbedtls_x509_*_info() and related APIs.
|
||||
*
|
||||
* Uncomment to omit mbedtls_x509_*_info(), as well as mbedtls_debug_print_crt()
|
||||
* and other functions/constants only used by these functions, thus reducing
|
||||
* the code footprint by several KB.
|
||||
*/
|
||||
//#define MBEDTLS_X509_REMOVE_INFO
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
||||
*
|
||||
@ -2411,7 +2415,7 @@
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256
|
||||
* MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384
|
||||
*/
|
||||
//#define MBEDTLS_ARIA_C
|
||||
#define MBEDTLS_ARIA_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CCM_C
|
||||
@ -2465,12 +2469,17 @@
|
||||
* Enable the CMAC (Cipher-based Message Authentication Code) mode for block
|
||||
* ciphers.
|
||||
*
|
||||
* \note When #MBEDTLS_CMAC_ALT is active, meaning that the underlying
|
||||
* implementation of the CMAC algorithm is provided by an alternate
|
||||
* implementation, that alternate implementation may opt to not support
|
||||
* AES-192 or 3DES as underlying block ciphers for the CMAC operation.
|
||||
*
|
||||
* Module: library/cmac.c
|
||||
*
|
||||
* Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_CMAC_C
|
||||
#define MBEDTLS_CMAC_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CTR_DRBG_C
|
||||
@ -2594,9 +2603,9 @@
|
||||
*
|
||||
* Enable the elliptic curve J-PAKE library.
|
||||
*
|
||||
* \warning This is currently experimental. EC J-PAKE support is based on the
|
||||
* Thread v1.0.0 specification; incompatible changes to the specification
|
||||
* might still happen. For this reason, this is disabled by default.
|
||||
* \note EC J-PAKE support is based on the Thread v1.0.0 specification.
|
||||
* It has not been reviewed for compliance with newer standards such as
|
||||
* Thread v1.1 or RFC 8236.
|
||||
*
|
||||
* Module: library/ecjpake.c
|
||||
* Caller:
|
||||
@ -2606,7 +2615,7 @@
|
||||
*
|
||||
* Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
|
||||
*/
|
||||
//#define MBEDTLS_ECJPAKE_C
|
||||
#define MBEDTLS_ECJPAKE_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ECP_C
|
||||
@ -2702,7 +2711,7 @@
|
||||
*
|
||||
* Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C
|
||||
*/
|
||||
//#define MBEDTLS_NIST_KW_C
|
||||
#define MBEDTLS_NIST_KW_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MD_C
|
||||
|
@ -528,35 +528,6 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
int mbedtls_ctr_drbg_random( void *p_rng,
|
||||
unsigned char *output, size_t output_len );
|
||||
|
||||
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief This function updates the state of the CTR_DRBG context.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_ctr_drbg_update_ret()
|
||||
* in 2.16.0.
|
||||
*
|
||||
* \note If \p add_len is greater than
|
||||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first
|
||||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used.
|
||||
* The remaining Bytes are silently discarded.
|
||||
*
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* \param add_len Length of \p additional data.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(
|
||||
mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
size_t add_len );
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
* \brief This function writes a seed file.
|
||||
|
@ -59,9 +59,13 @@
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
|
||||
mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
|
||||
#endif
|
||||
#else
|
||||
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
|
||||
@ -248,7 +252,7 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *text, const mbedtls_ecp_point *X );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Print a X.509 certificate structure to the debug output. This
|
||||
* function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
|
||||
|
@ -382,161 +382,6 @@ int mbedtls_dhm_self_test( int verbose );
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
|
||||
/**
|
||||
* \warning The origin of the primes in RFC 5114 is not documented and
|
||||
* their use therefore constitutes a security risk!
|
||||
*
|
||||
* \deprecated The hex-encoded primes from RFC 5114 are deprecated and are
|
||||
* likely to be removed in a future version of the library without
|
||||
* replacement.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the prime underlying the
|
||||
* 2048-bit MODP Group with 224-bit Prime Order Subgroup, as defined
|
||||
* in <em>RFC-5114: Additional Diffie-Hellman Groups for Use with
|
||||
* IETF Standards</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC5114_MODP_2048_P \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( \
|
||||
"AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \
|
||||
"B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \
|
||||
"EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \
|
||||
"9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \
|
||||
"C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \
|
||||
"B3BF8A317091883681286130BC8985DB1602E714415D9330" \
|
||||
"278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \
|
||||
"CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \
|
||||
"BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \
|
||||
"C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \
|
||||
"CF9DE5384E71B81C0AC4DFFE0C10E64F" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the chosen generator of the 2048-bit MODP
|
||||
* Group with 224-bit Prime Order Subgroup, as defined in <em>RFC-5114:
|
||||
* Additional Diffie-Hellman Groups for Use with IETF Standards</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC5114_MODP_2048_G \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( \
|
||||
"AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF" \
|
||||
"74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA" \
|
||||
"AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7" \
|
||||
"C17669101999024AF4D027275AC1348BB8A762D0521BC98A" \
|
||||
"E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE" \
|
||||
"F180EB34118E98D119529A45D6F834566E3025E316A330EF" \
|
||||
"BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB" \
|
||||
"10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381" \
|
||||
"B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269" \
|
||||
"EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179" \
|
||||
"81BC087F2A7065B384B890D3191F2BFA" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the prime underlying the 2048-bit MODP
|
||||
* Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*
|
||||
* \deprecated The hex-encoded primes from RFC 3625 are deprecated and
|
||||
* superseded by the corresponding macros providing them as
|
||||
* binary constants. Their hex-encoded constants are likely
|
||||
* to be removed in a future version of the library.
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_2048_P \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( \
|
||||
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
|
||||
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
|
||||
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
|
||||
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
|
||||
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
|
||||
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
|
||||
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
|
||||
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
|
||||
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
|
||||
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
|
||||
"15728E5A8AACAA68FFFFFFFFFFFFFFFF" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the chosen generator of the 2048-bit MODP
|
||||
* Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_2048_G \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the prime underlying the 3072-bit MODP
|
||||
* Group, as defined in <em>RFC-3072: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_3072_P \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( \
|
||||
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
|
||||
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
|
||||
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
|
||||
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
|
||||
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
|
||||
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
|
||||
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
|
||||
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
|
||||
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
|
||||
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
|
||||
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
|
||||
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
|
||||
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
|
||||
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
|
||||
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
|
||||
"43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the chosen generator of the 3072-bit MODP
|
||||
* Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_3072_G \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the prime underlying the 4096-bit MODP
|
||||
* Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_4096_P \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( \
|
||||
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
|
||||
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
|
||||
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
|
||||
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
|
||||
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
|
||||
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
|
||||
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
|
||||
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
|
||||
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
|
||||
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
|
||||
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
|
||||
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
|
||||
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
|
||||
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
|
||||
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
|
||||
"43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
|
||||
"88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
|
||||
"2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
|
||||
"287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
|
||||
"1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
|
||||
"93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
|
||||
"FFFFFFFFFFFFFFFF" )
|
||||
|
||||
/**
|
||||
* The hexadecimal presentation of the chosen generator of the 4096-bit MODP
|
||||
* Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
|
||||
* Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
|
||||
*/
|
||||
#define MBEDTLS_DHM_RFC3526_MODP_4096_G \
|
||||
MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
|
||||
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/*
|
||||
* Trustworthy DHM parameters in binary form
|
||||
*/
|
||||
|
@ -138,7 +138,7 @@ int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
|
||||
* previously-hashed message.
|
||||
*
|
||||
* \note The deterministic version implemented in
|
||||
* mbedtls_ecdsa_sign_det() is usually preferred.
|
||||
* mbedtls_ecdsa_sign_det_ext() is usually preferred.
|
||||
*
|
||||
* \note If the bitlength of the message hash is larger than the
|
||||
* bitlength of the group order, then the hash is truncated
|
||||
@ -174,67 +174,6 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief This function computes the ECDSA signature of a
|
||||
* previously-hashed message, deterministic version.
|
||||
*
|
||||
* For more information, see <em>RFC-6979: Deterministic
|
||||
* Usage of the Digital Signature Algorithm (DSA) and Elliptic
|
||||
* Curve Digital Signature Algorithm (ECDSA)</em>.
|
||||
*
|
||||
* \note If the bitlength of the message hash is larger than the
|
||||
* bitlength of the group order, then the hash is truncated as
|
||||
* defined in <em>Standards for Efficient Cryptography Group
|
||||
* (SECG): SEC1 Elliptic Curve Cryptography</em>, section
|
||||
* 4.1.3, step 5.
|
||||
*
|
||||
* \warning Since the output of the internal RNG is always the same for
|
||||
* the same key and message, this limits the efficiency of
|
||||
* blinding and leaks information through side channels. For
|
||||
* secure behavior use mbedtls_ecdsa_sign_det_ext() instead.
|
||||
*
|
||||
* (Optimally the blinding is a random value that is different
|
||||
* on every execution. In this case the blinding is still
|
||||
* random from the attackers perspective, but is the same on
|
||||
* each execution. This means that this blinding does not
|
||||
* prevent attackers from recovering secrets by combining
|
||||
* several measurement traces, but may prevent some attacks
|
||||
* that exploit relationships between secret data.)
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \param grp The context for the elliptic curve to use.
|
||||
* This must be initialized and have group parameters
|
||||
* set, for example through mbedtls_ecp_group_load().
|
||||
* \param r The MPI context in which to store the first part
|
||||
* the signature. This must be initialized.
|
||||
* \param s The MPI context in which to store the second part
|
||||
* the signature. This must be initialized.
|
||||
* \param d The private signing key. This must be initialized
|
||||
* and setup, for example through mbedtls_ecp_gen_privkey().
|
||||
* \param buf The hashed content to be signed. This must be a readable
|
||||
* buffer of length \p blen Bytes. It may be \c NULL if
|
||||
* \p blen is zero.
|
||||
* \param blen The length of \p buf in Bytes.
|
||||
* \param md_alg The hash algorithm used to hash the original data.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
|
||||
* error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
mbedtls_mpi *s, const mbedtls_mpi *d,
|
||||
const unsigned char *buf, size_t blen,
|
||||
mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief This function computes the ECDSA signature of a
|
||||
* previously-hashed message, deterministic version.
|
||||
@ -421,64 +360,6 @@ int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
void *p_rng,
|
||||
mbedtls_ecdsa_restart_ctx *rs_ctx );
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief This function computes an ECDSA signature and writes
|
||||
* it to a buffer, serialized as defined in <em>RFC-4492:
|
||||
* Elliptic Curve Cryptography (ECC) Cipher Suites for
|
||||
* Transport Layer Security (TLS)</em>.
|
||||
*
|
||||
* The deterministic version is defined in <em>RFC-6979:
|
||||
* Deterministic Usage of the Digital Signature Algorithm (DSA)
|
||||
* and Elliptic Curve Digital Signature Algorithm (ECDSA)</em>.
|
||||
*
|
||||
* \warning It is not thread-safe to use the same context in
|
||||
* multiple threads.
|
||||
*
|
||||
* \note If the bitlength of the message hash is larger than the
|
||||
* bitlength of the group order, then the hash is truncated as
|
||||
* defined in <em>Standards for Efficient Cryptography Group
|
||||
* (SECG): SEC1 Elliptic Curve Cryptography</em>, section
|
||||
* 4.1.3, step 5.
|
||||
*
|
||||
* \see ecp.h
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_ecdsa_write_signature() in
|
||||
* Mbed TLS version 2.0 and later.
|
||||
*
|
||||
* \param ctx The ECDSA context to use. This must be initialized
|
||||
* and have a group and private key bound to it, for example
|
||||
* via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair().
|
||||
* \param hash The message hash to be signed. This must be a readable
|
||||
* buffer of length \p blen Bytes.
|
||||
* \param hlen The length of the hash \p hash in Bytes.
|
||||
* \param sig The buffer to which to write the signature. This must be a
|
||||
* writable buffer of length at least twice as large as the
|
||||
* size of the curve used, plus 9. For example, 73 Bytes if
|
||||
* a 256-bit curve is used. A buffer length of
|
||||
* #MBEDTLS_ECDSA_MAX_LEN is always safe.
|
||||
* \param slen The address at which to store the actual length of
|
||||
* the signature written. Must not be \c NULL.
|
||||
* \param md_alg The message digest that was used to hash the message.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
|
||||
* \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t *slen,
|
||||
mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
|
||||
/**
|
||||
* \brief This function reads and verifies an ECDSA signature.
|
||||
*
|
||||
|
@ -30,6 +30,11 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Error code layout.
|
||||
*
|
||||
@ -117,6 +122,54 @@ extern "C" {
|
||||
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */
|
||||
|
||||
/**
|
||||
* \brief Combines a high-level and low-level error code together.
|
||||
*
|
||||
* Wrapper macro for mbedtls_error_add(). See that function for
|
||||
* more details.
|
||||
*/
|
||||
#define MBEDTLS_ERROR_ADD( high, low ) \
|
||||
mbedtls_error_add( high, low, __FILE__, __LINE__ )
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
/**
|
||||
* \brief Testing hook called before adding/combining two error codes together.
|
||||
* Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS.
|
||||
*/
|
||||
extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Combines a high-level and low-level error code together.
|
||||
*
|
||||
* This function can be called directly however it is usually
|
||||
* called via the #MBEDTLS_ERROR_ADD macro.
|
||||
*
|
||||
* While a value of zero is not a negative error code, it is still an
|
||||
* error code (that denotes success) and can be combined with both a
|
||||
* negative error code or another value of zero.
|
||||
*
|
||||
* \note When invasive testing is enabled via #MBEDTLS_TEST_HOOKS, also try to
|
||||
* call \link mbedtls_test_hook_error_add \endlink.
|
||||
*
|
||||
* \param high high-level error code. See error.h for more details.
|
||||
* \param low low-level error code. See error.h for more details.
|
||||
* \param file file where this error code addition occured.
|
||||
* \param line line where this error code addition occured.
|
||||
*/
|
||||
static inline int mbedtls_error_add( int high, int low,
|
||||
const char *file, int line )
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
if( *mbedtls_test_hook_error_add != NULL )
|
||||
( *mbedtls_test_hook_error_add )( high, low, file, line );
|
||||
#endif
|
||||
(void)file;
|
||||
(void)line;
|
||||
|
||||
return( high + low );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Translate a mbed TLS error code into a string representation,
|
||||
* Result is truncated if necessary and always includes a terminating
|
||||
|
@ -397,30 +397,6 @@ int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len
|
||||
*/
|
||||
void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
|
||||
|
||||
#if ! defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
/**
|
||||
* \brief This function updates the state of the HMAC_DRBG context.
|
||||
*
|
||||
* \deprecated Superseded by mbedtls_hmac_drbg_update_ret()
|
||||
* in 2.16.0.
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param additional The data to update the state with.
|
||||
* If this is \c NULL, there is no additional data.
|
||||
* \param add_len Length of \p additional in bytes.
|
||||
* Unused if \p additional is \c NULL.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(
|
||||
mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t add_len );
|
||||
#undef MBEDTLS_DEPRECATED
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
* \brief This function writes a seed file.
|
||||
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* \file net.h
|
||||
*
|
||||
* \brief Deprecated header file that includes net_sockets.h
|
||||
*
|
||||
* \deprecated Superseded by mbedtls/net_sockets.h
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "Deprecated header file: Superseded by mbedtls/net_sockets.h"
|
||||
#endif /* MBEDTLS_DEPRECATED_WARNING */
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
@ -441,8 +441,10 @@ typedef struct mbedtls_oid_descriptor_t
|
||||
{
|
||||
const char *asn1; /*!< OID ASN.1 representation */
|
||||
size_t asn1_len; /*!< length of asn1 */
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
const char *name; /*!< official name (e.g. from RFC) */
|
||||
const char *description; /*!< human friendly description */
|
||||
#endif
|
||||
} mbedtls_oid_descriptor_t;
|
||||
|
||||
/**
|
||||
@ -582,6 +584,7 @@ int mbedtls_oid_get_md_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_a
|
||||
int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac );
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Translate Extended Key Usage OID into description
|
||||
*
|
||||
@ -591,6 +594,7 @@ int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_
|
||||
* \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
|
||||
*/
|
||||
int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Translate certificate policies OID into description
|
||||
|
@ -2859,34 +2859,6 @@ void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Set the Diffie-Hellman public P and G values,
|
||||
* read as hexadecimal strings (server-side only)
|
||||
* (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG])
|
||||
*
|
||||
* \param conf SSL configuration
|
||||
* \param dhm_P Diffie-Hellman-Merkle modulus
|
||||
* \param dhm_G Diffie-Hellman-Merkle generator
|
||||
*
|
||||
* \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin.
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf,
|
||||
const char *dhm_P,
|
||||
const char *dhm_G );
|
||||
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief Set the Diffie-Hellman public P and G values
|
||||
* from big-endian binary presentations.
|
||||
@ -3659,32 +3631,6 @@ size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl );
|
||||
* \return Current maximum fragment length for the output buffer.
|
||||
*/
|
||||
size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl );
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define MBEDTLS_DEPRECATED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief This function is a deprecated approach to getting the max
|
||||
* fragment length. Its an alias for
|
||||
* \c mbedtls_ssl_get_output_max_frag_len(), as the behaviour
|
||||
* is the same. See \c mbedtls_ssl_get_output_max_frag_len() for
|
||||
* more detail.
|
||||
*
|
||||
* \sa mbedtls_ssl_get_input_max_frag_len()
|
||||
* \sa mbedtls_ssl_get_output_max_frag_len()
|
||||
*
|
||||
* \param ssl SSL context
|
||||
*
|
||||
* \return Current maximum fragment length for the output buffer.
|
||||
*/
|
||||
MBEDTLS_DEPRECATED size_t mbedtls_ssl_get_max_frag_len(
|
||||
const mbedtls_ssl_context *ssl );
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||
|
||||
/**
|
||||
|
@ -316,9 +316,11 @@ int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
|
||||
mbedtls_x509_buf *serial );
|
||||
int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
|
||||
mbedtls_x509_buf *ext, int tag );
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
|
||||
mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
|
||||
const void *sig_opts );
|
||||
#endif
|
||||
int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
|
||||
int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
|
||||
int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
|
||||
|
@ -134,6 +134,7 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s
|
||||
int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Returns an informational string about the CRL.
|
||||
*
|
||||
@ -147,6 +148,7 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
|
||||
*/
|
||||
int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
|
||||
const mbedtls_x509_crl *crl );
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/**
|
||||
* \brief Initialize a CRL (chain)
|
||||
|
@ -176,6 +176,74 @@ mbedtls_x509_crt_profile;
|
||||
#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
|
||||
#endif
|
||||
|
||||
/* This macro unfolds to the concatenation of macro invocations
|
||||
* X509_CRT_ERROR_INFO( error code,
|
||||
* error code as string,
|
||||
* human readable description )
|
||||
* where X509_CRT_ERROR_INFO is defined by the user.
|
||||
* See x509_crt.c for an example of how to use this. */
|
||||
#define MBEDTLS_X509_CRT_ERROR_INFO_LIST \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_EXPIRED, \
|
||||
"MBEDTLS_X509_BADCERT_EXPIRED", \
|
||||
"The certificate validity has expired" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_REVOKED, \
|
||||
"MBEDTLS_X509_BADCERT_REVOKED", \
|
||||
"The certificate has been revoked (is on a CRL)" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_CN_MISMATCH, \
|
||||
"MBEDTLS_X509_BADCERT_CN_MISMATCH", \
|
||||
"The certificate Common Name (CN) does not match with the expected CN" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_NOT_TRUSTED, \
|
||||
"MBEDTLS_X509_BADCERT_NOT_TRUSTED", \
|
||||
"The certificate is not correctly signed by the trusted CA" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_NOT_TRUSTED, \
|
||||
"MBEDTLS_X509_BADCRL_NOT_TRUSTED", \
|
||||
"The CRL is not correctly signed by the trusted CA" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_EXPIRED, \
|
||||
"MBEDTLS_X509_BADCRL_EXPIRED", \
|
||||
"The CRL is expired" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_MISSING, \
|
||||
"MBEDTLS_X509_BADCERT_MISSING", \
|
||||
"Certificate was missing" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_SKIP_VERIFY, \
|
||||
"MBEDTLS_X509_BADCERT_SKIP_VERIFY", \
|
||||
"Certificate verification was skipped" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_OTHER, \
|
||||
"MBEDTLS_X509_BADCERT_OTHER", \
|
||||
"Other reason (can be used by verify callback)" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_FUTURE, \
|
||||
"MBEDTLS_X509_BADCERT_FUTURE", \
|
||||
"The certificate validity starts in the future" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_FUTURE, \
|
||||
"MBEDTLS_X509_BADCRL_FUTURE", \
|
||||
"The CRL is from the future" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_KEY_USAGE, \
|
||||
"MBEDTLS_X509_BADCERT_KEY_USAGE", \
|
||||
"Usage does not match the keyUsage extension" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, \
|
||||
"MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", \
|
||||
"Usage does not match the extendedKeyUsage extension" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_NS_CERT_TYPE, \
|
||||
"MBEDTLS_X509_BADCERT_NS_CERT_TYPE", \
|
||||
"Usage does not match the nsCertType extension" ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_BAD_MD, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_MD", \
|
||||
"The certificate is signed with an unacceptable hash." ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_BAD_PK, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_PK", \
|
||||
"The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA)." ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCERT_BAD_KEY, \
|
||||
"MBEDTLS_X509_BADCERT_BAD_KEY", \
|
||||
"The certificate is signed with an unacceptable key (eg bad curve, RSA too short)." ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_BAD_MD, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_MD", \
|
||||
"The CRL is signed with an unacceptable hash." ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_BAD_PK, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_PK", \
|
||||
"The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA)." ) \
|
||||
X509_CRT_ERROR_INFO( MBEDTLS_X509_BADCRL_BAD_KEY, \
|
||||
"MBEDTLS_X509_BADCRL_BAD_KEY", \
|
||||
"The CRL is signed with an unacceptable key (eg bad curve, RSA too short)." )
|
||||
|
||||
/**
|
||||
* Container for writing a certificate (CRT)
|
||||
*/
|
||||
@ -509,6 +577,8 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
|
||||
*/
|
||||
int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf,
|
||||
mbedtls_x509_subject_alternative_name *san );
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Returns an informational string about the
|
||||
* certificate.
|
||||
@ -538,6 +608,7 @@ int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
|
||||
*/
|
||||
int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
|
||||
uint32_t flags );
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/**
|
||||
* \brief Verify a chain of certificates.
|
||||
|
@ -121,6 +121,7 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz
|
||||
int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/**
|
||||
* \brief Returns an informational string about the
|
||||
* CSR.
|
||||
@ -135,6 +136,7 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
|
||||
*/
|
||||
int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
|
||||
const mbedtls_x509_csr *csr );
|
||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/**
|
||||
* \brief Initialize a CSR
|
||||
|
@ -2113,9 +2113,16 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
|
||||
* authentication tag is appended to the
|
||||
* encrypted data.
|
||||
* \param ciphertext_size Size of the \p ciphertext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg,
|
||||
* \p plaintext_length).
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type,
|
||||
* \p alg, \p plaintext_length) where
|
||||
* \c key_type is the type of \p key.
|
||||
* - #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p
|
||||
* plaintext_length) evaluates to the maximum
|
||||
* ciphertext size of any supported AEAD
|
||||
* encryption.
|
||||
* \param[out] ciphertext_length On success, the size of the output
|
||||
* in the \p ciphertext buffer.
|
||||
*
|
||||
@ -2129,7 +2136,11 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
|
||||
* \p alg is not supported or is not an AEAD algorithm.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* \p ciphertext_size is too small
|
||||
* \p ciphertext_size is too small.
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\c key_type, \p alg,
|
||||
* \p plaintext_length) or
|
||||
* #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length) can be used to
|
||||
* determine the required buffer size.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
@ -2173,9 +2184,16 @@ psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
|
||||
* \param ciphertext_length Size of \p ciphertext in bytes.
|
||||
* \param[out] plaintext Output buffer for the decrypted data.
|
||||
* \param plaintext_size Size of the \p plaintext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg,
|
||||
* \p ciphertext_length).
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type,
|
||||
* \p alg, \p ciphertext_length) where
|
||||
* \c key_type is the type of \p key.
|
||||
* - #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p
|
||||
* ciphertext_length) evaluates to the maximum
|
||||
* plaintext size of any supported AEAD
|
||||
* decryption.
|
||||
* \param[out] plaintext_length On success, the size of the output
|
||||
* in the \p plaintext buffer.
|
||||
*
|
||||
@ -2191,7 +2209,11 @@ psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
|
||||
* \p alg is not supported or is not an AEAD algorithm.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* \p plaintext_size or \p nonce_length is too small
|
||||
* \p plaintext_size is too small.
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\c key_type, \p alg,
|
||||
* \p ciphertext_length) or
|
||||
* #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length) can be used
|
||||
* to determine the required buffer size.
|
||||
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
@ -2612,10 +2634,18 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
|
||||
* \param input_length Size of the \p input buffer in bytes.
|
||||
* \param[out] output Buffer where the output is to be written.
|
||||
* \param output_size Size of the \p output buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg,
|
||||
* \p input_length) where \c alg is the
|
||||
* algorithm that is being calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg, \p input_length) where
|
||||
* \c key_type is the type of key and \c alg is
|
||||
* the algorithm that were used to set up the
|
||||
* operation.
|
||||
* - #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p
|
||||
* input_length) evaluates to the maximum
|
||||
* output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] output_length On success, the number of bytes
|
||||
* that make up the returned output.
|
||||
*
|
||||
@ -2626,9 +2656,9 @@ psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
|
||||
* set, and have lengths set if required by the algorithm).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p output buffer is too small.
|
||||
* You can determine a sufficient buffer size by calling
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg, \p input_length)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c key_type, \c alg, \p input_length) or
|
||||
* #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length) can be used to
|
||||
* determine the required buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
@ -2665,9 +2695,7 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* This function has two output buffers:
|
||||
* - \p ciphertext contains trailing ciphertext that was buffered from
|
||||
* preceding calls to psa_aead_update().
|
||||
* - \p tag contains the authentication tag. Its length is always
|
||||
* #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is the AEAD algorithm
|
||||
* that the operation performs.
|
||||
* - \p tag contains the authentication tag.
|
||||
*
|
||||
* When this function returns successfuly, the operation becomes inactive.
|
||||
* If this function returns an error status, the operation enters an error
|
||||
@ -2677,18 +2705,32 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* \param[out] ciphertext Buffer where the last part of the ciphertext
|
||||
* is to be written.
|
||||
* \param ciphertext_size Size of the \p ciphertext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg) where
|
||||
* \c alg is the algorithm that is being
|
||||
* calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg) where \c key_type is the type of key
|
||||
* and \c alg is the algorithm that were used to
|
||||
* set up the operation.
|
||||
* - #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE evaluates to
|
||||
* the maximum output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] ciphertext_length On success, the number of bytes of
|
||||
* returned ciphertext.
|
||||
* \param[out] tag Buffer where the authentication tag is
|
||||
* to be written.
|
||||
* \param tag_size Size of the \p tag buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is
|
||||
* the algorithm that is being calculated.
|
||||
* This must be appropriate for the selected
|
||||
* algorithm and key:
|
||||
* - The exact tag size is #PSA_AEAD_TAG_LENGTH(\c
|
||||
* key_type, \c key_bits, \c alg) where
|
||||
* \c key_type and \c key_bits are the type and
|
||||
* bit-size of the key, and \c alg is the
|
||||
* algorithm that were used in the call to
|
||||
* psa_aead_encrypt_setup().
|
||||
* - #PSA_AEAD_TAG_MAX_SIZE evaluates to the
|
||||
* maximum tag size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] tag_length On success, the number of bytes
|
||||
* that make up the returned tag.
|
||||
*
|
||||
@ -2699,11 +2741,11 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
|
||||
* operation with a nonce set).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p ciphertext or \p tag buffer is too small.
|
||||
* You can determine a sufficient buffer size for \p ciphertext by
|
||||
* calling #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* You can determine a sufficient buffer size for \p tag by
|
||||
* calling #PSA_AEAD_TAG_LENGTH(\c alg).
|
||||
* #PSA_AEAD_FINISH_OUTPUT_SIZE(\c key_type, \c alg) or
|
||||
* #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE can be used to determine the
|
||||
* required \p ciphertext buffer size. #PSA_AEAD_TAG_LENGTH(\c key_type,
|
||||
* \c key_bits, \c alg) or #PSA_AEAD_TAG_MAX_SIZE can be used to
|
||||
* determine the required \p tag buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
@ -2762,10 +2804,15 @@ psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
|
||||
* that could not be processed until the end
|
||||
* of the input.
|
||||
* \param plaintext_size Size of the \p plaintext buffer in bytes.
|
||||
* This must be at least
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg) where
|
||||
* \c alg is the algorithm that is being
|
||||
* calculated.
|
||||
* This must be appropriate for the selected algorithm and key:
|
||||
* - A sufficient output size is
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type,
|
||||
* \c alg) where \c key_type is the type of key
|
||||
* and \c alg is the algorithm that were used to
|
||||
* set up the operation.
|
||||
* - #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE evaluates to
|
||||
* the maximum output size of any supported AEAD
|
||||
* algorithm.
|
||||
* \param[out] plaintext_length On success, the number of bytes of
|
||||
* returned plaintext.
|
||||
* \param[in] tag Buffer containing the authentication tag.
|
||||
@ -2781,9 +2828,9 @@ psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
|
||||
* operation with a nonce set).
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* The size of the \p plaintext buffer is too small.
|
||||
* You can determine a sufficient buffer size for \p plaintext by
|
||||
* calling #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg)
|
||||
* where \c alg is the algorithm that is being calculated.
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c key_type, \c alg) or
|
||||
* #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE can be used to determine the
|
||||
* required buffer size.
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The total length of input to psa_aead_update_ad() so far is
|
||||
* less than the additional data length that was previously
|
||||
|
@ -715,6 +715,104 @@ psa_status_t mbedtls_psa_external_get_random(
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup psa_builtin_keys Built-in keys
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The minimum value for a key identifier that is built into the
|
||||
* implementation.
|
||||
*
|
||||
* The range of key identifiers from #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN
|
||||
* to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX within the range from
|
||||
* #PSA_KEY_ID_VENDOR_MIN and #PSA_KEY_ID_VENDOR_MAX and must not intersect
|
||||
* with any other set of implementation-chosen key identifiers.
|
||||
*
|
||||
* This value is part of the library's ABI since changing it would invalidate
|
||||
* the values of built-in key identifiers in applications.
|
||||
*/
|
||||
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t)0x7fff0000)
|
||||
|
||||
/** The maximum value for a key identifier that is built into the
|
||||
* implementation.
|
||||
*
|
||||
* See #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN for more information.
|
||||
*/
|
||||
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t)0x7fffefff)
|
||||
|
||||
/** A slot number identifying a key in a driver.
|
||||
*
|
||||
* Values of this type are used to identify built-in keys.
|
||||
*/
|
||||
typedef uint64_t psa_drv_slot_number_t;
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
/** Test whether a key identifier belongs to the builtin key range.
|
||||
*
|
||||
* \param key_id Key identifier to test.
|
||||
*
|
||||
* \retval 1
|
||||
* The key identifier is a builtin key identifier.
|
||||
* \retval 0
|
||||
* The key identifier is not a builtin key identifier.
|
||||
*/
|
||||
static inline int psa_key_id_is_builtin( psa_key_id_t key_id )
|
||||
{
|
||||
return( ( key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ) &&
|
||||
( key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ) );
|
||||
}
|
||||
|
||||
/** Platform function to obtain the location and slot number of a built-in key.
|
||||
*
|
||||
* An application-specific implementation of this function must be provided if
|
||||
* #MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS is enabled. This would typically be provided
|
||||
* as part of a platform's system image.
|
||||
*
|
||||
* #MBEDTLS_SVC_KEY_ID_GET_KEY_ID(\p key_id) needs to be in the range from
|
||||
* #MBEDTLS_PSA_KEY_ID_BUILTIN_MIN to #MBEDTLS_PSA_KEY_ID_BUILTIN_MAX.
|
||||
*
|
||||
* In a multi-application configuration
|
||||
* (\c MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER is defined),
|
||||
* this function should check that #MBEDTLS_SVC_KEY_ID_GET_OWNER_ID(\p key_id)
|
||||
* is allowed to use the given key.
|
||||
*
|
||||
* \param key_id The key ID for which to retrieve the
|
||||
* location and slot attributes.
|
||||
* \param[out] lifetime On success, the lifetime associated with the key
|
||||
* corresponding to \p key_id. Lifetime is a
|
||||
* combination of which driver contains the key,
|
||||
* and with what persistence level the key is
|
||||
* intended to be used. If the platform
|
||||
* implementation does not contain specific
|
||||
* information about the intended key persistence
|
||||
* level, the persistence level may be reported as
|
||||
* #PSA_KEY_PERSISTENCE_DEFAULT.
|
||||
* \param[out] slot_number On success, the slot number known to the driver
|
||||
* registered at the lifetime location reported
|
||||
* through \p lifetime which corresponds to the
|
||||
* requested built-in key.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The requested key identifier designates a built-in key.
|
||||
* In a multi-application configuration, the requested owner
|
||||
* is allowed to access it.
|
||||
* \retval #PSA_ERROR_DOES_NOT_EXIST
|
||||
* The requested key identifier is not a built-in key which is known
|
||||
* to this function. If a key exists in the key storage with this
|
||||
* identifier, the data from the storage will be used.
|
||||
* \return (any other error)
|
||||
* Any other error is propagated to the function that requested the key.
|
||||
* Common errors include:
|
||||
* - #PSA_ERROR_NOT_PERMITTED: the key exists but the requested owner
|
||||
* is not allowed to access it.
|
||||
*/
|
||||
psa_status_t mbedtls_psa_platform_get_builtin_key(
|
||||
mbedtls_svc_key_id_t key_id,
|
||||
psa_key_lifetime_t *lifetime,
|
||||
psa_drv_slot_number_t *slot_number );
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -117,26 +117,35 @@
|
||||
*/
|
||||
#define PSA_MAC_MAX_SIZE PSA_HASH_MAX_SIZE
|
||||
|
||||
/** The tag size for an AEAD algorithm, in bytes.
|
||||
/** The length of a tag for an AEAD algorithm, in bytes.
|
||||
*
|
||||
* This macro can be used to allocate a buffer of sufficient size to store the
|
||||
* tag output from psa_aead_finish().
|
||||
*
|
||||
* See also #PSA_AEAD_TAG_MAX_SIZE.
|
||||
*
|
||||
* \param key_type The type of the AEAD key.
|
||||
* \param key_bits The size of the AEAD key in bits.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return The tag size for the specified algorithm.
|
||||
* \return The tag length for the specified algorithm and key.
|
||||
* If the AEAD algorithm does not have an identified
|
||||
* tag that can be distinguished from the rest of
|
||||
* the ciphertext, return 0.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
#define PSA_AEAD_TAG_LENGTH(alg) \
|
||||
(PSA_ALG_IS_AEAD(alg) ? \
|
||||
(((alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> PSA_AEAD_TAG_LENGTH_OFFSET) : \
|
||||
0)
|
||||
#define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
|
||||
PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
|
||||
((void) (key_bits), 0))
|
||||
|
||||
/** The maximum tag size for all supported AEAD algorithms, in bytes.
|
||||
*
|
||||
* See also #PSA_AEAD_TAG_LENGTH(\p alg).
|
||||
* See also #PSA_AEAD_TAG_LENGTH(\p key_type, \p key_bits, \p alg).
|
||||
*/
|
||||
#define PSA_AEAD_TAG_MAX_SIZE 16
|
||||
|
||||
@ -241,10 +250,14 @@
|
||||
* insufficient buffer size. Depending on the algorithm, the actual size of
|
||||
* the ciphertext may be smaller.
|
||||
*
|
||||
* See also #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length).
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param key_type A symmetric key type that is
|
||||
* compatible with algorithm \p alg.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
@ -252,11 +265,13 @@
|
||||
*
|
||||
* \return The AEAD ciphertext size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(alg, plaintext_length) \
|
||||
(PSA_AEAD_TAG_LENGTH(alg) != 0 ? \
|
||||
(plaintext_length) + PSA_AEAD_TAG_LENGTH(alg) : \
|
||||
#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
|
||||
(plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
|
||||
0)
|
||||
|
||||
/** A sufficient output buffer size for psa_aead_encrypt(), for any of the
|
||||
@ -268,7 +283,8 @@
|
||||
* \note This macro returns a compile-time constant if its arguments are
|
||||
* compile-time constants.
|
||||
*
|
||||
* See also #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg, \p plaintext_length).
|
||||
* See also #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p key_type, \p alg,
|
||||
* \p plaintext_length).
|
||||
*
|
||||
* \param plaintext_length Size of the plaintext in bytes.
|
||||
*
|
||||
@ -287,10 +303,14 @@
|
||||
* insufficient buffer size. Depending on the algorithm, the actual size of
|
||||
* the plaintext may be smaller.
|
||||
*
|
||||
* See also #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length).
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param key_type A symmetric key type that is
|
||||
* compatible with algorithm \p alg.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
@ -298,11 +318,14 @@
|
||||
*
|
||||
* \return The AEAD ciphertext size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(alg, ciphertext_length) \
|
||||
(PSA_AEAD_TAG_LENGTH(alg) != 0 ? \
|
||||
(ciphertext_length) - PSA_AEAD_TAG_LENGTH(alg) : \
|
||||
#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
|
||||
(ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH(alg) ? \
|
||||
(ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
|
||||
0)
|
||||
|
||||
/** A sufficient output buffer size for psa_aead_decrypt(), for any of the
|
||||
@ -314,7 +337,8 @@
|
||||
* \note This macro returns a compile-time constant if its arguments are
|
||||
* compile-time constants.
|
||||
*
|
||||
* See also #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg, \p ciphertext_length).
|
||||
* See also #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p key_type, \p alg,
|
||||
* \p ciphertext_length).
|
||||
*
|
||||
* \param ciphertext_length Size of the ciphertext in bytes.
|
||||
*
|
||||
@ -352,11 +376,11 @@
|
||||
*/
|
||||
#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 ? 13 : \
|
||||
PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg) == PSA_ALG_GCM ? 12 : \
|
||||
MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM) ? 13 : \
|
||||
MBEDTLS_PSA_ALG_AEAD_EQUAL(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 : \
|
||||
MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CHACHA20_POLY1305) ? 12 : \
|
||||
0)
|
||||
|
||||
/** The maximum default nonce size among all supported pairs of key types and
|
||||
@ -379,10 +403,14 @@
|
||||
* insufficient buffer size. The actual size of the output may be smaller
|
||||
* in any given call.
|
||||
*
|
||||
* See also #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length).
|
||||
*
|
||||
* \warning This macro may evaluate its arguments multiple times or
|
||||
* zero times, so you should not pass arguments that contain
|
||||
* side effects.
|
||||
*
|
||||
* \param key_type A symmetric key type that is
|
||||
* compatible with algorithm \p alg.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
@ -390,16 +418,20 @@
|
||||
*
|
||||
* \return A sufficient output buffer size for the specified
|
||||
* algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
/* For all the AEAD modes defined in this specification, it is possible
|
||||
* to emit output without delay. However, hardware may not always be
|
||||
* capable of this. So for modes based on a block cipher, allow the
|
||||
* implementation to delay the output until it has a full block. */
|
||||
#define PSA_AEAD_UPDATE_OUTPUT_SIZE(alg, input_length) \
|
||||
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length)) : \
|
||||
(input_length))
|
||||
#define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), (input_length)) : \
|
||||
(input_length) : \
|
||||
0)
|
||||
|
||||
/** A sufficient output buffer size for psa_aead_update(), for any of the
|
||||
* supported key types and AEAD algorithms.
|
||||
@ -407,7 +439,7 @@
|
||||
* If the size of the output buffer is at least this large, it is guaranteed
|
||||
* that psa_aead_update() will not fail due to an insufficient buffer size.
|
||||
*
|
||||
* See also #PSA_AEAD_UPDATE_OUTPUT_SIZE(\p alg, \p input_length).
|
||||
* See also #PSA_AEAD_UPDATE_OUTPUT_SIZE(\p key_type, \p alg, \p input_length).
|
||||
*
|
||||
* \param input_length Size of the input in bytes.
|
||||
*/
|
||||
@ -421,23 +453,30 @@
|
||||
* insufficient ciphertext buffer size. The actual size of the output may
|
||||
* be smaller in any given call.
|
||||
*
|
||||
* See also #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE.
|
||||
*
|
||||
* \param key_type A symmetric key type that is
|
||||
compatible with algorithm \p alg.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return A sufficient ciphertext buffer size for the
|
||||
* specified algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
#define PSA_AEAD_FINISH_OUTPUT_SIZE(alg) \
|
||||
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
|
||||
#define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
|
||||
0)
|
||||
|
||||
/** A sufficient ciphertext buffer size for psa_aead_finish(), for any of the
|
||||
* supported key types and AEAD algorithms.
|
||||
*
|
||||
* See also #PSA_AEAD_FINISH_OUTPUT_SIZE(\p alg).
|
||||
* See also #PSA_AEAD_FINISH_OUTPUT_SIZE(\p key_type, \p alg).
|
||||
*/
|
||||
#define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)
|
||||
|
||||
@ -448,23 +487,30 @@
|
||||
* insufficient plaintext buffer size. The actual size of the output may
|
||||
* be smaller in any given call.
|
||||
*
|
||||
* See also #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE.
|
||||
*
|
||||
* \param key_type A symmetric key type that is
|
||||
* compatible with algorithm \p alg.
|
||||
* \param alg An AEAD algorithm
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
* #PSA_ALG_IS_AEAD(\p alg) is true).
|
||||
*
|
||||
* \return A sufficient plaintext buffer size for the
|
||||
* specified algorithm.
|
||||
* If the AEAD algorithm is not recognized, return 0.
|
||||
* If the key type or AEAD algorithm is not
|
||||
* recognized, or the parameters are incompatible,
|
||||
* return 0.
|
||||
*/
|
||||
#define PSA_AEAD_VERIFY_OUTPUT_SIZE(alg) \
|
||||
(PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
|
||||
#define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \
|
||||
(PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
|
||||
PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
|
||||
PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
|
||||
0)
|
||||
|
||||
/** A sufficient plaintext buffer size for psa_aead_verify(), for any of the
|
||||
* supported key types and AEAD algorithms.
|
||||
*
|
||||
* See also #PSA_AEAD_VERIFY_OUTPUT_SIZE(\p alg).
|
||||
* See also #PSA_AEAD_VERIFY_OUTPUT_SIZE(\p key_type, \p alg).
|
||||
*/
|
||||
#define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)
|
||||
|
||||
|
@ -2137,4 +2137,27 @@ static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup helper_macros Helper macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Helper macros */
|
||||
|
||||
/** Check if two AEAD algorithm identifiers refer to the same AEAD algorithm
|
||||
* regardless of the tag length they encode.
|
||||
*
|
||||
* \param aead_alg_1 An AEAD algorithm identifier.
|
||||
* \param aead_alg_2 An AEAD algorithm identifier.
|
||||
*
|
||||
* \return 1 if both identifiers refer to the same AEAD algorithm,
|
||||
* 0 otherwise.
|
||||
* Unspecified if neither \p aead_alg_1 nor \p aead_alg_2 are
|
||||
* a supported AEAD algorithm.
|
||||
*/
|
||||
#define MBEDTLS_PSA_ALG_AEAD_EQUAL(aead_alg_1, aead_alg_2) \
|
||||
(!(((aead_alg_1) ^ (aead_alg_2)) & \
|
||||
~(PSA_ALG_AEAD_TAG_LENGTH_MASK | PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)))
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif /* PSA_CRYPTO_VALUES_H */
|
||||
|
@ -921,15 +921,6 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_ENCRYPT_ALT */
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_internal_aes_encrypt( ctx, input, output );
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/*
|
||||
* AES-ECB block decryption
|
||||
*/
|
||||
@ -994,15 +985,6 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
}
|
||||
#endif /* !MBEDTLS_AES_DECRYPT_ALT */
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_internal_aes_decrypt( ctx, input, output );
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/*
|
||||
* AES-ECB block encryption/decryption
|
||||
*/
|
||||
|
@ -1666,8 +1666,7 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint
|
||||
* calculating the result is trivial in those cases. */
|
||||
if( b == 0 || n == 0 )
|
||||
{
|
||||
mbedtls_mpi_lset( X, 0 );
|
||||
return( 0 );
|
||||
return( mbedtls_mpi_lset( X, 0 ) );
|
||||
}
|
||||
|
||||
/* Calculate A*b as A + A*(b-1) to take advantage of mpi_mul_hlp */
|
||||
@ -2718,26 +2717,6 @@ int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds,
|
||||
return( mpi_miller_rabin( &XX, rounds, f_rng, p_rng ) );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/*
|
||||
* Pseudo-primality test, error probability 2^-80
|
||||
*/
|
||||
int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng )
|
||||
{
|
||||
MPI_VALIDATE_RET( X != NULL );
|
||||
MPI_VALIDATE_RET( f_rng != NULL );
|
||||
|
||||
/*
|
||||
* In the past our key generation aimed for an error rate of at most
|
||||
* 2^-80. Since this function is deprecated, aim for the same certainty
|
||||
* here as well.
|
||||
*/
|
||||
return( mbedtls_mpi_is_prime_ext( X, 40, f_rng, p_rng ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Prime number generation
|
||||
*
|
||||
|
@ -1288,8 +1288,8 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
||||
/*
|
||||
* Packet-oriented encryption for AEAD modes: internal function shared by
|
||||
* mbedtls_cipher_auth_encrypt() and mbedtls_cipher_auth_encrypt_ext().
|
||||
* Packet-oriented encryption for AEAD modes: internal function used by
|
||||
* mbedtls_cipher_auth_encrypt_ext().
|
||||
*/
|
||||
static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
@ -1368,8 +1368,8 @@ static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx,
|
||||
}
|
||||
|
||||
/*
|
||||
* Packet-oriented encryption for AEAD modes: internal function shared by
|
||||
* mbedtls_cipher_auth_encrypt() and mbedtls_cipher_auth_encrypt_ext().
|
||||
* Packet-oriented encryption for AEAD modes: internal function used by
|
||||
* mbedtls_cipher_auth_encrypt_ext().
|
||||
*/
|
||||
static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
@ -1468,54 +1468,6 @@ static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx,
|
||||
|
||||
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/*
|
||||
* Packet-oriented encryption for AEAD modes: public legacy function.
|
||||
*/
|
||||
int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen,
|
||||
unsigned char *tag, size_t tag_len )
|
||||
{
|
||||
CIPHER_VALIDATE_RET( ctx != NULL );
|
||||
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
||||
CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL );
|
||||
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
||||
CIPHER_VALIDATE_RET( ilen == 0 || output != NULL );
|
||||
CIPHER_VALIDATE_RET( olen != NULL );
|
||||
CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL );
|
||||
|
||||
return( mbedtls_cipher_aead_encrypt( ctx, iv, iv_len, ad, ad_len,
|
||||
input, ilen, output, olen,
|
||||
tag, tag_len ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Packet-oriented decryption for AEAD modes: public legacy function.
|
||||
*/
|
||||
int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen,
|
||||
const unsigned char *tag, size_t tag_len )
|
||||
{
|
||||
CIPHER_VALIDATE_RET( ctx != NULL );
|
||||
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
||||
CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL );
|
||||
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
||||
CIPHER_VALIDATE_RET( ilen == 0 || output != NULL );
|
||||
CIPHER_VALIDATE_RET( olen != NULL );
|
||||
CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL );
|
||||
|
||||
return( mbedtls_cipher_aead_decrypt( ctx, iv, iv_len, ad, ad_len,
|
||||
input, ilen, output, olen,
|
||||
tag, tag_len ) );
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
|
||||
|
@ -867,11 +867,12 @@ static int cmac_test_wth_cipher( int verbose,
|
||||
{
|
||||
/* When CMAC is implemented by an alternative implementation, or
|
||||
* the underlying primitive itself is implemented alternatively,
|
||||
* AES-192 may be unavailable. This should not cause the selftest
|
||||
* function to fail. */
|
||||
* AES-192 and/or 3DES may be unavailable. This should not cause
|
||||
* the selftest function to fail. */
|
||||
if( ( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ||
|
||||
ret == MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ) &&
|
||||
cipher_type == MBEDTLS_CIPHER_AES_192_ECB ) {
|
||||
( cipher_type == MBEDTLS_CIPHER_AES_192_ECB ||
|
||||
cipher_type == MBEDTLS_CIPHER_DES_EDE3_ECB ) ) {
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "skipped\n" );
|
||||
continue;
|
||||
|
@ -304,7 +304,7 @@ exit:
|
||||
}
|
||||
|
||||
/* CTR_DRBG_Instantiate with derivation function (SP 800-90A §10.2.1.3.2)
|
||||
* mbedtls_ctr_drbg_update(ctx, additional, add_len)
|
||||
* mbedtls_ctr_drbg_update_ret(ctx, additional, add_len)
|
||||
* implements
|
||||
* CTR_DRBG_Instantiate(entropy_input, nonce, personalization_string,
|
||||
* security_strength) -> initial_working_state
|
||||
@ -335,19 +335,6 @@ exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
size_t add_len )
|
||||
{
|
||||
/* MAX_INPUT would be more logical here, but we have to match
|
||||
* block_cipher_df()'s limits since we can't propagate errors */
|
||||
if( add_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT )
|
||||
add_len = MBEDTLS_CTR_DRBG_MAX_SEED_INPUT;
|
||||
(void) mbedtls_ctr_drbg_update_ret( ctx, additional, add_len );
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/* CTR_DRBG_Reseed with derivation function (SP 800-90A §10.2.1.4.2)
|
||||
* mbedtls_ctr_drbg_reseed(ctx, additional, len, nonce_len)
|
||||
* implements
|
||||
|
@ -284,7 +284,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
}
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_pk_context *pk )
|
||||
@ -379,7 +379,7 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
|
||||
crt = crt->next;
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
static void mbedtls_debug_printf_ecdh_internal( const mbedtls_ssl_context *ssl,
|
||||
|
@ -79,7 +79,7 @@ static int dhm_read_bignum( mbedtls_mpi *X,
|
||||
return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = mbedtls_mpi_read_binary( X, *p, n ) ) != 0 )
|
||||
return( MBEDTLS_ERR_DHM_READ_PARAMS_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PARAMS_FAILED, ret ) );
|
||||
|
||||
(*p) += n;
|
||||
|
||||
@ -222,7 +222,7 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
|
||||
cleanup:
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -242,7 +242,7 @@ int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
|
||||
if( ( ret = mbedtls_mpi_copy( &ctx->P, P ) ) != 0 ||
|
||||
( ret = mbedtls_mpi_copy( &ctx->G, G ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_DHM_SET_GROUP_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_SET_GROUP_FAILED, ret ) );
|
||||
}
|
||||
|
||||
ctx->len = mbedtls_mpi_size( &ctx->P );
|
||||
@ -263,7 +263,7 @@ int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx,
|
||||
return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = mbedtls_mpi_read_binary( &ctx->GY, input, ilen ) ) != 0 )
|
||||
return( MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -313,7 +313,7 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
|
||||
cleanup:
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -462,7 +462,7 @@ cleanup:
|
||||
mbedtls_mpi_free( &GYb );
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_DHM_CALC_SECRET_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_CALC_SECRET_FAILED, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -544,7 +544,7 @@ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_DHM_INVALID_FORMAT + ret;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_INVALID_FORMAT, ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -553,7 +553,7 @@ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
|
||||
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &dhm->P ) ) != 0 ||
|
||||
( ret = mbedtls_asn1_get_mpi( &p, end, &dhm->G ) ) != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_DHM_INVALID_FORMAT + ret;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_INVALID_FORMAT, ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -567,13 +567,13 @@ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
|
||||
mbedtls_mpi_free( &rec );
|
||||
if ( ret != 0 )
|
||||
{
|
||||
ret = MBEDTLS_ERR_DHM_INVALID_FORMAT + ret;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_INVALID_FORMAT, ret );
|
||||
goto exit;
|
||||
}
|
||||
if ( p != end )
|
||||
{
|
||||
ret = MBEDTLS_ERR_DHM_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
120
library/ecdsa.c
120
library/ecdsa.c
@ -420,6 +420,9 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
/*
|
||||
* Deterministic signature wrapper
|
||||
*
|
||||
* note: The f_rng_blind parameter must not be NULL.
|
||||
*
|
||||
*/
|
||||
static int ecdsa_sign_det_restartable( mbedtls_ecp_group *grp,
|
||||
mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
@ -475,69 +478,9 @@ sign:
|
||||
ret = mbedtls_ecdsa_sign( grp, r, s, d, buf, blen,
|
||||
mbedtls_hmac_drbg_random, p_rng );
|
||||
#else
|
||||
if( f_rng_blind != NULL )
|
||||
ret = ecdsa_sign_restartable( grp, r, s, d, buf, blen,
|
||||
mbedtls_hmac_drbg_random, p_rng,
|
||||
f_rng_blind, p_rng_blind, rs_ctx );
|
||||
else
|
||||
{
|
||||
mbedtls_hmac_drbg_context *p_rng_blind_det;
|
||||
|
||||
#if !defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/*
|
||||
* To avoid reusing rng_ctx and risking incorrect behavior we seed a
|
||||
* second HMAC-DRBG with the same seed. We also apply a label to avoid
|
||||
* reusing the bits of the ephemeral key for blinding and eliminate the
|
||||
* risk that they leak this way.
|
||||
*/
|
||||
const char* blind_label = "BLINDING CONTEXT";
|
||||
mbedtls_hmac_drbg_context rng_ctx_blind;
|
||||
|
||||
mbedtls_hmac_drbg_init( &rng_ctx_blind );
|
||||
p_rng_blind_det = &rng_ctx_blind;
|
||||
mbedtls_hmac_drbg_seed_buf( p_rng_blind_det, md_info,
|
||||
data, 2 * grp_len );
|
||||
ret = mbedtls_hmac_drbg_update_ret( p_rng_blind_det,
|
||||
(const unsigned char*) blind_label,
|
||||
strlen( blind_label ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_hmac_drbg_free( &rng_ctx_blind );
|
||||
goto cleanup;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* In the case of restartable computations we would either need to store
|
||||
* the second RNG in the restart context too or set it up at every
|
||||
* restart. The first option would penalize the correct application of
|
||||
* the function and the second would defeat the purpose of the
|
||||
* restartable feature.
|
||||
*
|
||||
* Therefore in this case we reuse the original RNG. This comes with the
|
||||
* price that the resulting signature might not be a valid deterministic
|
||||
* ECDSA signature with a very low probability (same magnitude as
|
||||
* successfully guessing the private key). However even then it is still
|
||||
* a valid ECDSA signature.
|
||||
*/
|
||||
p_rng_blind_det = p_rng;
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
/*
|
||||
* Since the output of the RNGs is always the same for the same key and
|
||||
* message, this limits the efficiency of blinding and leaks information
|
||||
* through side channels. After mbedtls_ecdsa_sign_det() is removed NULL
|
||||
* won't be a valid value for f_rng_blind anymore. Therefore it should
|
||||
* be checked by the caller and this branch and check can be removed.
|
||||
*/
|
||||
ret = ecdsa_sign_restartable( grp, r, s, d, buf, blen,
|
||||
mbedtls_hmac_drbg_random, p_rng,
|
||||
mbedtls_hmac_drbg_random, p_rng_blind_det,
|
||||
rs_ctx );
|
||||
|
||||
#if !defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
mbedtls_hmac_drbg_free( &rng_ctx_blind );
|
||||
#endif
|
||||
}
|
||||
ret = ecdsa_sign_restartable( grp, r, s, d, buf, blen,
|
||||
mbedtls_hmac_drbg_random, p_rng,
|
||||
f_rng_blind, p_rng_blind, rs_ctx );
|
||||
#endif /* MBEDTLS_ECDSA_SIGN_ALT */
|
||||
|
||||
cleanup:
|
||||
@ -550,26 +493,8 @@ cleanup:
|
||||
}
|
||||
|
||||
/*
|
||||
* Deterministic signature wrappers
|
||||
* Deterministic signature wrapper
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
mbedtls_mpi *s, const mbedtls_mpi *d,
|
||||
const unsigned char *buf, size_t blen,
|
||||
mbedtls_md_type_t md_alg )
|
||||
{
|
||||
ECDSA_VALIDATE_RET( grp != NULL );
|
||||
ECDSA_VALIDATE_RET( r != NULL );
|
||||
ECDSA_VALIDATE_RET( s != NULL );
|
||||
ECDSA_VALIDATE_RET( d != NULL );
|
||||
ECDSA_VALIDATE_RET( buf != NULL || blen == 0 );
|
||||
|
||||
return( ecdsa_sign_det_restartable( grp, r, s, d, buf, blen, md_alg,
|
||||
NULL, NULL, NULL ) );
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
mbedtls_mpi *s, const mbedtls_mpi *d,
|
||||
const unsigned char *buf, size_t blen,
|
||||
@ -756,10 +681,13 @@ int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
mbedtls_mpi r, s;
|
||||
ECDSA_VALIDATE_RET( ctx != NULL );
|
||||
ECDSA_VALIDATE_RET( hash != NULL );
|
||||
ECDSA_VALIDATE_RET( sig != NULL );
|
||||
ECDSA_VALIDATE_RET( slen != NULL );
|
||||
ECDSA_VALIDATE_RET( ctx != NULL );
|
||||
ECDSA_VALIDATE_RET( hash != NULL );
|
||||
ECDSA_VALIDATE_RET( sig != NULL );
|
||||
ECDSA_VALIDATE_RET( slen != NULL );
|
||||
|
||||
if( f_rng == NULL )
|
||||
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
|
||||
|
||||
mbedtls_mpi_init( &r );
|
||||
mbedtls_mpi_init( &s );
|
||||
@ -811,22 +739,6 @@ int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
|
||||
ctx, md_alg, hash, hlen, sig, slen, f_rng, p_rng, NULL ) );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED) && \
|
||||
defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t *slen,
|
||||
mbedtls_md_type_t md_alg )
|
||||
{
|
||||
ECDSA_VALIDATE_RET( ctx != NULL );
|
||||
ECDSA_VALIDATE_RET( hash != NULL );
|
||||
ECDSA_VALIDATE_RET( sig != NULL );
|
||||
ECDSA_VALIDATE_RET( slen != NULL );
|
||||
return( mbedtls_ecdsa_write_signature( ctx, md_alg, hash, hlen, sig, slen,
|
||||
NULL, NULL ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read and check signature
|
||||
*/
|
||||
@ -870,8 +782,8 @@ int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
|
||||
if( p + len != end )
|
||||
{
|
||||
ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -2477,7 +2477,7 @@ static int ecp_randomize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
if( mbedtls_internal_ecp_grp_capable( grp ) )
|
||||
return( mbedtls_internal_ecp_randomize_mxz( grp, P, f_rng, p_rng );
|
||||
return( mbedtls_internal_ecp_randomize_mxz( grp, P, f_rng, p_rng ) );
|
||||
#endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
|
||||
|
||||
#if defined(MBEDTLS_ECP_NO_FALLBACK) && defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
|
||||
|
@ -858,4 +858,8 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
||||
|
||||
#endif /* MBEDTLS_ERROR_C */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_ERROR_C || MBEDTLS_ERROR_STRERROR_DUMMY */
|
||||
|
@ -104,15 +104,6 @@ exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
size_t add_len )
|
||||
{
|
||||
(void) mbedtls_hmac_drbg_update_ret( ctx, additional, add_len );
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/*
|
||||
* Simplified HMAC_DRBG initialisation (for use with deterministic ECDSA)
|
||||
*/
|
||||
|
201
library/oid.c
201
library/oid.c
@ -41,6 +41,17 @@
|
||||
*/
|
||||
#define ADD_LEN(s) s, MBEDTLS_OID_SIZE(s)
|
||||
|
||||
/*
|
||||
* Macro to generate mbedtls_oid_descriptor_t
|
||||
*/
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
#define OID_DESCRIPTOR(s, name, description) { ADD_LEN(s), name, description }
|
||||
#define NULL_OID_DESCRIPTOR { NULL, 0, NULL, NULL }
|
||||
#else
|
||||
#define OID_DESCRIPTOR(s, name, description) { ADD_LEN(s) }
|
||||
#define NULL_OID_DESCRIPTOR { NULL, 0 }
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macro to generate an internal function for oid_XXX_from_asn1() (used by
|
||||
* the other functions)
|
||||
@ -64,6 +75,7 @@
|
||||
return( NULL ); \
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/*
|
||||
* Macro to generate a function for retrieving a single attribute from the
|
||||
* descriptor of an mbedtls_oid_descriptor_t wrapper.
|
||||
@ -76,6 +88,7 @@ int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 )
|
||||
*ATTR1 = data->descriptor.ATTR1; \
|
||||
return( 0 ); \
|
||||
}
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/*
|
||||
* Macro to generate a function for retrieving a single attribute from an
|
||||
@ -157,83 +170,83 @@ typedef struct {
|
||||
static const oid_x520_attr_t oid_x520_attr_type[] =
|
||||
{
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_CN ), "id-at-commonName", "Common Name" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_CN, "id-at-commonName", "Common Name" ),
|
||||
"CN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_COUNTRY ), "id-at-countryName", "Country" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_COUNTRY, "id-at-countryName", "Country" ),
|
||||
"C",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_LOCALITY ), "id-at-locality", "Locality" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_LOCALITY, "id-at-locality", "Locality" ),
|
||||
"L",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_STATE ), "id-at-state", "State" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_STATE, "id-at-state", "State" ),
|
||||
"ST",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_ORGANIZATION ),"id-at-organizationName", "Organization" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_ORGANIZATION,"id-at-organizationName", "Organization" ),
|
||||
"O",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_ORG_UNIT ), "id-at-organizationalUnitName", "Org Unit" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_ORG_UNIT, "id-at-organizationalUnitName", "Org Unit" ),
|
||||
"OU",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS9_EMAIL ), "emailAddress", "E-mail address" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS9_EMAIL, "emailAddress", "E-mail address" ),
|
||||
"emailAddress",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_SERIAL_NUMBER ),"id-at-serialNumber", "Serial number" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_SERIAL_NUMBER,"id-at-serialNumber", "Serial number" ),
|
||||
"serialNumber",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_POSTAL_ADDRESS ),"id-at-postalAddress", "Postal address" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_POSTAL_ADDRESS,"id-at-postalAddress", "Postal address" ),
|
||||
"postalAddress",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_POSTAL_CODE ), "id-at-postalCode", "Postal code" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_POSTAL_CODE, "id-at-postalCode", "Postal code" ),
|
||||
"postalCode",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_SUR_NAME ), "id-at-surName", "Surname" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_SUR_NAME, "id-at-surName", "Surname" ),
|
||||
"SN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_GIVEN_NAME ), "id-at-givenName", "Given name" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_GIVEN_NAME, "id-at-givenName", "Given name" ),
|
||||
"GN",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_INITIALS ), "id-at-initials", "Initials" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_INITIALS, "id-at-initials", "Initials" ),
|
||||
"initials",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_GENERATION_QUALIFIER ), "id-at-generationQualifier", "Generation qualifier" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_GENERATION_QUALIFIER, "id-at-generationQualifier", "Generation qualifier" ),
|
||||
"generationQualifier",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_TITLE ), "id-at-title", "Title" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_TITLE, "id-at-title", "Title" ),
|
||||
"title",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_DN_QUALIFIER ),"id-at-dnQualifier", "Distinguished Name qualifier" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_DN_QUALIFIER,"id-at-dnQualifier", "Distinguished Name qualifier" ),
|
||||
"dnQualifier",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_PSEUDONYM ), "id-at-pseudonym", "Pseudonym" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_PSEUDONYM, "id-at-pseudonym", "Pseudonym" ),
|
||||
"pseudonym",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DOMAIN_COMPONENT ), "id-domainComponent", "Domain component" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DOMAIN_COMPONENT, "id-domainComponent", "Domain component" ),
|
||||
"DC",
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER ), "id-at-uniqueIdentifier", "Unique Identifier" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER, "id-at-uniqueIdentifier", "Unique Identifier" ),
|
||||
"uniqueIdentifier",
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
NULL,
|
||||
}
|
||||
};
|
||||
@ -252,31 +265,31 @@ typedef struct {
|
||||
static const oid_x509_ext_t oid_x509_ext[] =
|
||||
{
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_BASIC_CONSTRAINTS ), "id-ce-basicConstraints", "Basic Constraints" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_BASIC_CONSTRAINTS, "id-ce-basicConstraints", "Basic Constraints" ),
|
||||
MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_KEY_USAGE ), "id-ce-keyUsage", "Key Usage" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_KEY_USAGE, "id-ce-keyUsage", "Key Usage" ),
|
||||
MBEDTLS_OID_X509_EXT_KEY_USAGE,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EXTENDED_KEY_USAGE ), "id-ce-extKeyUsage", "Extended Key Usage" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EXTENDED_KEY_USAGE, "id-ce-extKeyUsage", "Extended Key Usage" ),
|
||||
MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_SUBJECT_ALT_NAME ), "id-ce-subjectAltName", "Subject Alt Name" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_SUBJECT_ALT_NAME, "id-ce-subjectAltName", "Subject Alt Name" ),
|
||||
MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_NS_CERT_TYPE ), "id-netscape-certtype", "Netscape Certificate Type" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_NS_CERT_TYPE, "id-netscape-certtype", "Netscape Certificate Type" ),
|
||||
MBEDTLS_OID_X509_EXT_NS_CERT_TYPE,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_CERTIFICATE_POLICIES ), "id-ce-certificatePolicies", "Certificate Policies" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_CERTIFICATE_POLICIES, "id-ce-certificatePolicies", "Certificate Policies" ),
|
||||
MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
0,
|
||||
},
|
||||
};
|
||||
@ -284,16 +297,17 @@ static const oid_x509_ext_t oid_x509_ext[] =
|
||||
FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type)
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
static const mbedtls_oid_descriptor_t oid_ext_key_usage[] =
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_SERVER_AUTH ), "id-kp-serverAuth", "TLS Web Server Authentication" },
|
||||
{ ADD_LEN( MBEDTLS_OID_CLIENT_AUTH ), "id-kp-clientAuth", "TLS Web Client Authentication" },
|
||||
{ ADD_LEN( MBEDTLS_OID_CODE_SIGNING ), "id-kp-codeSigning", "Code Signing" },
|
||||
{ ADD_LEN( MBEDTLS_OID_EMAIL_PROTECTION ), "id-kp-emailProtection", "E-mail Protection" },
|
||||
{ ADD_LEN( MBEDTLS_OID_TIME_STAMPING ), "id-kp-timeStamping", "Time Stamping" },
|
||||
{ ADD_LEN( MBEDTLS_OID_OCSP_SIGNING ), "id-kp-OCSPSigning", "OCSP Signing" },
|
||||
{ ADD_LEN( MBEDTLS_OID_WISUN_FAN ), "id-kp-wisun-fan-device", "Wi-SUN Alliance Field Area Network (FAN)" },
|
||||
{ NULL, 0, NULL, NULL },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_SERVER_AUTH, "id-kp-serverAuth", "TLS Web Server Authentication" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_CLIENT_AUTH, "id-kp-clientAuth", "TLS Web Client Authentication" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_CODE_SIGNING, "id-kp-codeSigning", "Code Signing" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EMAIL_PROTECTION, "id-kp-emailProtection", "E-mail Protection" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_TIME_STAMPING, "id-kp-timeStamping", "Time Stamping" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_OCSP_SIGNING, "id-kp-OCSPSigning", "OCSP Signing" ),
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_WISUN_FAN, "id-kp-wisun-fan-device", "Wi-SUN Alliance Field Area Network (FAN)" ),
|
||||
NULL_OID_DESCRIPTOR,
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage)
|
||||
@ -301,12 +315,13 @@ FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t, e
|
||||
|
||||
static const mbedtls_oid_descriptor_t oid_certificate_policies[] =
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ANY_POLICY ), "anyPolicy", "Any Policy" },
|
||||
{ NULL, 0, NULL, NULL },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ANY_POLICY, "anyPolicy", "Any Policy" ),
|
||||
NULL_OID_DESCRIPTOR,
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, certificate_policies, oid_certificate_policies)
|
||||
FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies, mbedtls_oid_descriptor_t, certificate_policies, const char *, description)
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_MD_C)
|
||||
/*
|
||||
@ -323,55 +338,55 @@ static const oid_sig_alg_t oid_sig_alg[] =
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_MD2 ), "md2WithRSAEncryption", "RSA with MD2" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_MD2, "md2WithRSAEncryption", "RSA with MD2" ),
|
||||
MBEDTLS_MD_MD2, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_MD4 ), "md4WithRSAEncryption", "RSA with MD4" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_MD4, "md4WithRSAEncryption", "RSA with MD4" ),
|
||||
MBEDTLS_MD_MD4, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_MD5 ), "md5WithRSAEncryption", "RSA with MD5" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_MD5, "md5WithRSAEncryption", "RSA with MD5" ),
|
||||
MBEDTLS_MD_MD5, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_SHA1 ), "sha-1WithRSAEncryption", "RSA with SHA1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA1, "sha-1WithRSAEncryption", "RSA with SHA1" ),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA224_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_SHA224 ), "sha224WithRSAEncryption", "RSA with SHA-224" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA224, "sha224WithRSAEncryption", "RSA with SHA-224" ),
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_SHA256 ), "sha256WithRSAEncryption", "RSA with SHA-256" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA256, "sha256WithRSAEncryption", "RSA with SHA-256" ),
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA384_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_SHA384 ), "sha384WithRSAEncryption", "RSA with SHA-384" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA384, "sha384WithRSAEncryption", "RSA with SHA-384" ),
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA384_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_SHA512 ), "sha512WithRSAEncryption", "RSA with SHA-512" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA512, "sha512WithRSAEncryption", "RSA with SHA-512" ),
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_RSA_SHA_OBS ), "sha-1WithRSAEncryption", "RSA with SHA1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_RSA_SHA_OBS, "sha-1WithRSAEncryption", "RSA with SHA1" ),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
@ -379,47 +394,51 @@ static const oid_sig_alg_t oid_sig_alg[] =
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ECDSA_SHA1 ), "ecdsa-with-SHA1", "ECDSA with SHA1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA1, "ecdsa-with-SHA1", "ECDSA with SHA1" ),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA224_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ECDSA_SHA224 ), "ecdsa-with-SHA224", "ECDSA with SHA224" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA224, "ecdsa-with-SHA224", "ECDSA with SHA224" ),
|
||||
MBEDTLS_MD_SHA224, MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ECDSA_SHA256 ), "ecdsa-with-SHA256", "ECDSA with SHA256" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA256, "ecdsa-with-SHA256", "ECDSA with SHA256" ),
|
||||
MBEDTLS_MD_SHA256, MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ECDSA_SHA384 ), "ecdsa-with-SHA384", "ECDSA with SHA384" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA384, "ecdsa-with-SHA384", "ECDSA with SHA384" ),
|
||||
MBEDTLS_MD_SHA384, MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_ECDSA_SHA512 ), "ecdsa-with-SHA512", "ECDSA with SHA512" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA512, "ecdsa-with-SHA512", "ECDSA with SHA512" ),
|
||||
MBEDTLS_MD_SHA512, MBEDTLS_PK_ECDSA,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#endif /* MBEDTLS_ECDSA_C */
|
||||
#if defined(MBEDTLS_RSA_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_RSASSA_PSS ), "RSASSA-PSS", "RSASSA-PSS" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_RSASSA_PSS, "RSASSA-PSS", "RSASSA-PSS" ),
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_RSASSA_PSS,
|
||||
},
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_MD_NONE, MBEDTLS_PK_NONE,
|
||||
},
|
||||
};
|
||||
|
||||
FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg)
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t, sig_alg, const char *, description)
|
||||
#endif
|
||||
|
||||
FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg, oid_sig_alg_t, sig_alg, mbedtls_md_type_t, md_alg, mbedtls_pk_type_t, pk_alg)
|
||||
FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg, oid_sig_alg_t, oid_sig_alg, mbedtls_pk_type_t, pk_alg, mbedtls_md_type_t, md_alg)
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
@ -435,19 +454,19 @@ typedef struct {
|
||||
static const oid_pk_alg_t oid_pk_alg[] =
|
||||
{
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS1_RSA ), "rsaEncryption", "RSA" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_RSA, "rsaEncryption", "RSA" ),
|
||||
MBEDTLS_PK_RSA,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_ALG_UNRESTRICTED ), "id-ecPublicKey", "Generic EC key" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_ALG_UNRESTRICTED, "id-ecPublicKey", "Generic EC key" ),
|
||||
MBEDTLS_PK_ECKEY,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_ALG_ECDH ), "id-ecDH", "EC key for ECDH" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_ALG_ECDH, "id-ecDH", "EC key for ECDH" ),
|
||||
MBEDTLS_PK_ECKEY_DH,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_PK_NONE,
|
||||
},
|
||||
};
|
||||
@ -469,72 +488,72 @@ static const oid_ecp_grp_t oid_ecp_grp[] =
|
||||
{
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192R1 ), "secp192r1", "secp192r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP192R1, "secp192r1", "secp192r1" ),
|
||||
MBEDTLS_ECP_DP_SECP192R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224R1 ), "secp224r1", "secp224r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP224R1, "secp224r1", "secp224r1" ),
|
||||
MBEDTLS_ECP_DP_SECP224R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256R1 ), "secp256r1", "secp256r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP256R1, "secp256r1", "secp256r1" ),
|
||||
MBEDTLS_ECP_DP_SECP256R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP384R1 ), "secp384r1", "secp384r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP384R1, "secp384r1", "secp384r1" ),
|
||||
MBEDTLS_ECP_DP_SECP384R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP521R1 ), "secp521r1", "secp521r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP521R1, "secp521r1", "secp521r1" ),
|
||||
MBEDTLS_ECP_DP_SECP521R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP192K1 ), "secp192k1", "secp192k1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP192K1, "secp192k1", "secp192k1" ),
|
||||
MBEDTLS_ECP_DP_SECP192K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP224K1 ), "secp224k1", "secp224k1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP224K1, "secp224k1", "secp224k1" ),
|
||||
MBEDTLS_ECP_DP_SECP224K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_SECP256K1 ), "secp256k1", "secp256k1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP256K1, "secp256k1", "secp256k1" ),
|
||||
MBEDTLS_ECP_DP_SECP256K1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_BP256R1 ), "brainpoolP256r1","brainpool256r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP256R1, "brainpoolP256r1","brainpool256r1" ),
|
||||
MBEDTLS_ECP_DP_BP256R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_BP384R1 ), "brainpoolP384r1","brainpool384r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP384R1, "brainpoolP384r1","brainpool384r1" ),
|
||||
MBEDTLS_ECP_DP_BP384R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */
|
||||
#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_EC_GRP_BP512R1 ), "brainpoolP512r1","brainpool512r1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP512R1, "brainpoolP512r1","brainpool512r1" ),
|
||||
MBEDTLS_ECP_DP_BP512R1,
|
||||
},
|
||||
#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_ECP_DP_NONE,
|
||||
},
|
||||
};
|
||||
@ -556,15 +575,15 @@ typedef struct {
|
||||
static const oid_cipher_alg_t oid_cipher_alg[] =
|
||||
{
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DES_CBC ), "desCBC", "DES-CBC" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DES_CBC, "desCBC", "DES-CBC" ),
|
||||
MBEDTLS_CIPHER_DES_CBC,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DES_EDE3_CBC ), "des-ede3-cbc", "DES-EDE3-CBC" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DES_EDE3_CBC, "des-ede3-cbc", "DES-EDE3-CBC" ),
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_CIPHER_NONE,
|
||||
},
|
||||
};
|
||||
@ -586,58 +605,58 @@ static const oid_md_alg_t oid_md_alg[] =
|
||||
{
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD2 ), "id-md2", "MD2" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_MD2, "id-md2", "MD2" ),
|
||||
MBEDTLS_MD_MD2,
|
||||
},
|
||||
#endif /* MBEDTLS_MD2_C */
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD4 ), "id-md4", "MD4" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_MD4, "id-md4", "MD4" ),
|
||||
MBEDTLS_MD_MD4,
|
||||
},
|
||||
#endif /* MBEDTLS_MD4_C */
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_MD5 ), "id-md5", "MD5" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_MD5, "id-md5", "MD5" ),
|
||||
MBEDTLS_MD_MD5,
|
||||
},
|
||||
#endif /* MBEDTLS_MD5_C */
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA1 ), "id-sha1", "SHA-1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA1, "id-sha1", "SHA-1" ),
|
||||
MBEDTLS_MD_SHA1,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA224_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA224 ), "id-sha224", "SHA-224" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA224, "id-sha224", "SHA-224" ),
|
||||
MBEDTLS_MD_SHA224,
|
||||
},
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA256 ), "id-sha256", "SHA-256" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA256, "id-sha256", "SHA-256" ),
|
||||
MBEDTLS_MD_SHA256,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA384 ), "id-sha384", "SHA-384" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA384, "id-sha384", "SHA-384" ),
|
||||
MBEDTLS_MD_SHA384,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_SHA512 ), "id-sha512", "SHA-512" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA512, "id-sha512", "SHA-512" ),
|
||||
MBEDTLS_MD_SHA512,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
#if defined(MBEDTLS_RIPEMD160_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_DIGEST_ALG_RIPEMD160 ), "id-ripemd160", "RIPEMD-160" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_RIPEMD160, "id-ripemd160", "RIPEMD-160" ),
|
||||
MBEDTLS_MD_RIPEMD160,
|
||||
},
|
||||
#endif /* MBEDTLS_RIPEMD160_C */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_MD_NONE,
|
||||
},
|
||||
};
|
||||
@ -658,36 +677,36 @@ static const oid_md_hmac_t oid_md_hmac[] =
|
||||
{
|
||||
#if defined(MBEDTLS_SHA1_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_HMAC_SHA1 ), "hmacSHA1", "HMAC-SHA-1" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA1, "hmacSHA1", "HMAC-SHA-1" ),
|
||||
MBEDTLS_MD_SHA1,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA1_C */
|
||||
#if defined(MBEDTLS_SHA224_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_HMAC_SHA224 ), "hmacSHA224", "HMAC-SHA-224" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA224, "hmacSHA224", "HMAC-SHA-224" ),
|
||||
MBEDTLS_MD_SHA224,
|
||||
},
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_HMAC_SHA256 ), "hmacSHA256", "HMAC-SHA-256" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA256, "hmacSHA256", "HMAC-SHA-256" ),
|
||||
MBEDTLS_MD_SHA256,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA256_C */
|
||||
#if defined(MBEDTLS_SHA384_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_HMAC_SHA384 ), "hmacSHA384", "HMAC-SHA-384" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA384, "hmacSHA384", "HMAC-SHA-384" ),
|
||||
MBEDTLS_MD_SHA384,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA384_C */
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_HMAC_SHA512 ), "hmacSHA512", "HMAC-SHA-512" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA512, "hmacSHA512", "HMAC-SHA-512" ),
|
||||
MBEDTLS_MD_SHA512,
|
||||
},
|
||||
#endif /* MBEDTLS_SHA512_C */
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_MD_NONE,
|
||||
},
|
||||
};
|
||||
@ -709,15 +728,15 @@ typedef struct {
|
||||
static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] =
|
||||
{
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC ), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC, "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" ),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE3_CBC,
|
||||
},
|
||||
{
|
||||
{ ADD_LEN( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC ), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" },
|
||||
OID_DESCRIPTOR( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC, "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" ),
|
||||
MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE_CBC,
|
||||
},
|
||||
{
|
||||
{ NULL, 0, NULL, NULL },
|
||||
NULL_OID_DESCRIPTOR,
|
||||
MBEDTLS_MD_NONE, MBEDTLS_CIPHER_NONE,
|
||||
},
|
||||
};
|
||||
|
@ -343,7 +343,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
ret = mbedtls_base64_decode( NULL, 0, &len, s1, s2 - s1 );
|
||||
|
||||
if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER )
|
||||
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) );
|
||||
|
||||
if( ( buf = mbedtls_calloc( 1, len ) ) == NULL )
|
||||
return( MBEDTLS_ERR_PEM_ALLOC_FAILED );
|
||||
@ -352,7 +352,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||
{
|
||||
mbedtls_platform_zeroize( buf, len );
|
||||
mbedtls_free( buf );
|
||||
return( MBEDTLS_ERR_PEM_INVALID_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) );
|
||||
}
|
||||
|
||||
if( enc != 0 )
|
||||
|
@ -60,21 +60,21 @@ static int pkcs12_parse_pbe_params( mbedtls_asn1_buf *params,
|
||||
*
|
||||
*/
|
||||
if( params->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &salt->len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) );
|
||||
|
||||
salt->p = *p;
|
||||
*p += salt->len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( p, end, iterations ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
||||
const unsigned char *end = params->p + params->len;
|
||||
|
||||
if( params->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
/*
|
||||
* PBKDF2-params ::= SEQUENCE {
|
||||
* salt OCTET STRING,
|
||||
@ -73,13 +73,13 @@ static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &salt->len,
|
||||
MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
|
||||
salt->p = p;
|
||||
p += salt->len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, iterations ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
@ -87,21 +87,21 @@ static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, keylen ) ) != 0 )
|
||||
{
|
||||
if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg_null( &p, end, &prf_alg_oid ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( mbedtls_oid_get_md_hmac( &prf_alg_oid, md_type ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE );
|
||||
|
||||
if( p != end )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -134,12 +134,12 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
|
||||
* }
|
||||
*/
|
||||
if( pbe_params->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg( &p, end, &kdf_alg_oid,
|
||||
&kdf_alg_params ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
|
||||
// Only PBKDF2 supported at the moment
|
||||
//
|
||||
@ -160,7 +160,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
|
||||
if( ( ret = mbedtls_asn1_get_alg( &p, end, &enc_scheme_oid,
|
||||
&enc_scheme_params ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PKCS5_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PKCS5_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( mbedtls_oid_get_cipher_alg( &enc_scheme_oid, &cipher_alg ) != 0 )
|
||||
|
@ -186,8 +186,8 @@ static int pk_get_ecparams( unsigned char **p, const unsigned char *end,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if ( end - *p < 1 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
/* Tag may be either OID or SEQUENCE */
|
||||
params->tag = **p;
|
||||
@ -197,21 +197,21 @@ static int pk_get_ecparams( unsigned char **p, const unsigned char *end,
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, ¶ms->len, params->tag ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
params->p = *p;
|
||||
*p += params->len;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -247,7 +247,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
|
||||
/* SpecifiedECDomainVersion ::= INTEGER { 1, 2, 3 } */
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, &ver ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( ver < 1 || ver > 3 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT );
|
||||
@ -285,13 +285,13 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
|
||||
/* Prime-p ::= INTEGER -- Field of size p. */
|
||||
if( ( ret = mbedtls_asn1_get_mpi( &p, end_field, &grp->P ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
grp->pbits = mbedtls_mpi_bitlen( &grp->P );
|
||||
|
||||
if( p != end_field )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/*
|
||||
* Curve ::= SEQUENCE {
|
||||
@ -315,7 +315,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ||
|
||||
( ret = mbedtls_mpi_read_binary( &grp->A, p, len ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
p += len;
|
||||
@ -323,7 +323,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ||
|
||||
( ret = mbedtls_mpi_read_binary( &grp->B, p, len ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
p += len;
|
||||
@ -333,14 +333,14 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
p += len;
|
||||
|
||||
if( p != end_curve )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/*
|
||||
* ECPoint ::= OCTET STRING
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_ecp_point_read_binary( grp, &grp->G,
|
||||
( const unsigned char *) p, len ) ) != 0 )
|
||||
@ -366,7 +366,7 @@ static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_
|
||||
* order INTEGER
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &grp->N ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
grp->nbits = mbedtls_mpi_bitlen( &grp->N );
|
||||
|
||||
@ -528,15 +528,15 @@ static int pk_get_rsapubkey( unsigned char **p,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/* Import N */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_rsa_import_raw( rsa, *p, len, NULL, 0, NULL, 0,
|
||||
NULL, 0, NULL, 0 ) ) != 0 )
|
||||
@ -546,7 +546,7 @@ static int pk_get_rsapubkey( unsigned char **p,
|
||||
|
||||
/* Import E */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_rsa_import_raw( rsa, NULL, 0, NULL, 0, NULL, 0,
|
||||
NULL, 0, *p, len ) ) != 0 )
|
||||
@ -561,8 +561,8 @@ static int pk_get_rsapubkey( unsigned char **p,
|
||||
}
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -584,7 +584,7 @@ static int pk_get_pk_alg( unsigned char **p,
|
||||
memset( params, 0, sizeof(mbedtls_asn1_buf) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg( p, end, &alg_oid, params ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_ALG, ret ) );
|
||||
|
||||
if( mbedtls_oid_get_pk_alg( &alg_oid, pk_alg ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
|
||||
@ -624,7 +624,7 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = *p + len;
|
||||
@ -633,11 +633,11 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
|
||||
return( ret );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_PK_INVALID_PUBKEY +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL )
|
||||
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
|
||||
@ -662,8 +662,8 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
|
||||
ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG;
|
||||
|
||||
if( ret == 0 && *p != end )
|
||||
ret = MBEDTLS_ERR_PK_INVALID_PUBKEY +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
|
||||
if( ret != 0 )
|
||||
mbedtls_pk_free( pk );
|
||||
@ -734,14 +734,14 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( version != 0 )
|
||||
@ -831,8 +831,8 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
|
||||
|
||||
if( p != end )
|
||||
{
|
||||
ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
}
|
||||
|
||||
cleanup:
|
||||
@ -843,7 +843,7 @@ cleanup:
|
||||
{
|
||||
/* Wrap error code if it's coming from a lower level */
|
||||
if( ( ret & 0xff80 ) == 0 )
|
||||
ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret );
|
||||
else
|
||||
ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT;
|
||||
|
||||
@ -883,24 +883,24 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck,
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( version != 1 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_mpi_read_binary( &eck->d, p, len ) ) != 0 )
|
||||
{
|
||||
mbedtls_ecp_keypair_free( eck );
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
p += len;
|
||||
@ -924,7 +924,7 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck,
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
{
|
||||
mbedtls_ecp_keypair_free( eck );
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -940,11 +940,11 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck,
|
||||
end2 = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_bitstring_null( &p, end2, &len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( p + len != end2 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
if( ( ret = pk_get_ecpubkey( &p, end2, eck ) ) == 0 )
|
||||
pubkey_done = 1;
|
||||
@ -961,7 +961,7 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck,
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
{
|
||||
mbedtls_ecp_keypair_free( eck );
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -970,7 +970,7 @@ static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck,
|
||||
NULL, NULL ) ) != 0 )
|
||||
{
|
||||
mbedtls_ecp_keypair_free( eck );
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 )
|
||||
@ -1028,26 +1028,28 @@ static int pk_parse_key_pkcs8_unencrypted_der(
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( version != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret ) );
|
||||
|
||||
if( ( ret = pk_get_pk_alg( &p, end, &pk_alg, ¶ms ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( len < 1 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL )
|
||||
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
|
||||
@ -1130,16 +1132,16 @@ static int pk_parse_key_pkcs8_encrypted_der(
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg( &p, end, &pbe_alg_oid, &pbe_params ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) );
|
||||
|
||||
buf = p;
|
||||
|
||||
@ -1518,7 +1520,8 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
|
||||
return( ret );
|
||||
}
|
||||
mbedtls_pk_free( ctx );
|
||||
if( ret != ( MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) )
|
||||
if( ret != ( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
@ -553,20 +553,8 @@ MBEDTLS_STATIC_TESTABLE psa_status_t psa_mac_key_can_do(
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
|
||||
/** Try to allocate a buffer to an empty key slot.
|
||||
*
|
||||
* \param[in,out] slot Key slot to attach buffer to.
|
||||
* \param[in] buffer_length Requested size of the buffer.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The buffer has been successfully allocated.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* Not enough memory was available for allocation.
|
||||
* \retval #PSA_ERROR_ALREADY_EXISTS
|
||||
* Trying to allocate a buffer to a non-empty key slot.
|
||||
*/
|
||||
static psa_status_t psa_allocate_buffer_to_slot( psa_key_slot_t *slot,
|
||||
size_t buffer_length )
|
||||
psa_status_t psa_allocate_buffer_to_slot( psa_key_slot_t *slot,
|
||||
size_t buffer_length )
|
||||
{
|
||||
if( slot->key.data != NULL )
|
||||
return( PSA_ERROR_ALREADY_EXISTS );
|
||||
@ -1024,8 +1012,7 @@ static psa_status_t psa_get_and_lock_transparent_key_slot_with_policy(
|
||||
psa_get_and_lock_key_slot_with_policy( key, p_slot, usage, alg )
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
||||
|
||||
/** Wipe key data from a slot. Preserve metadata such as the policy. */
|
||||
static psa_status_t psa_remove_key_data_from_memory( psa_key_slot_t *slot )
|
||||
psa_status_t psa_remove_key_data_from_memory( psa_key_slot_t *slot )
|
||||
{
|
||||
/* Data pointer will always be either a valid pointer or NULL in an
|
||||
* initialized slot, so we can just free it. */
|
||||
|
@ -154,10 +154,14 @@ static psa_status_t psa_aead_setup(
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
|
||||
if( PSA_AEAD_TAG_LENGTH( alg ) > full_tag_length )
|
||||
if( PSA_AEAD_TAG_LENGTH( attributes->core.type,
|
||||
key_bits, alg )
|
||||
> full_tag_length )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
operation->tag_length = PSA_AEAD_TAG_LENGTH( alg );
|
||||
operation->tag_length = PSA_AEAD_TAG_LENGTH( attributes->core.type,
|
||||
key_bits,
|
||||
alg );
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
@ -180,6 +180,24 @@ static inline psa_key_slot_number_t psa_key_slot_get_slot_number(
|
||||
*/
|
||||
psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot );
|
||||
|
||||
/** Try to allocate a buffer to an empty key slot.
|
||||
*
|
||||
* \param[in,out] slot Key slot to attach buffer to.
|
||||
* \param[in] buffer_length Requested size of the buffer.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The buffer has been successfully allocated.
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
||||
* Not enough memory was available for allocation.
|
||||
* \retval #PSA_ERROR_ALREADY_EXISTS
|
||||
* Trying to allocate a buffer to a non-empty key slot.
|
||||
*/
|
||||
psa_status_t psa_allocate_buffer_to_slot( psa_key_slot_t *slot,
|
||||
size_t buffer_length );
|
||||
|
||||
/** Wipe key data from a slot. Preserves metadata such as the policy. */
|
||||
psa_status_t psa_remove_key_data_from_memory( psa_key_slot_t *slot );
|
||||
|
||||
/** Copy key data (in export format) into an empty key slot.
|
||||
*
|
||||
* This function assumes that the slot does not contain
|
||||
|
@ -101,7 +101,7 @@ psa_status_t psa_driver_wrapper_sign_hash(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_signature_sign_hash( attributes,
|
||||
status = mbedtls_test_transparent_signature_sign_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
@ -129,16 +129,16 @@ psa_status_t psa_driver_wrapper_sign_hash(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_signature_sign_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_size,
|
||||
signature_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_signature_sign_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_size,
|
||||
signature_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||
default:
|
||||
@ -185,14 +185,15 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_signature_verify_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_length );
|
||||
status = mbedtls_test_transparent_signature_verify_hash(
|
||||
attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_length );
|
||||
/* Declared with fallback == true */
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -211,15 +212,15 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_signature_verify_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_signature_verify_hash( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
alg,
|
||||
hash,
|
||||
hash_length,
|
||||
signature,
|
||||
signature_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||
default:
|
||||
@ -229,8 +230,8 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the key buffer size for the key material of a generated key in the
|
||||
* case of an opaque driver without storage.
|
||||
/** Get the key buffer size required to store the key material of a key
|
||||
* associated with an opaque driver without storage.
|
||||
*
|
||||
* \param[in] attributes The key attributes.
|
||||
* \param[out] key_buffer_size Minimum buffer size to contain the key material
|
||||
@ -256,38 +257,20 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size(
|
||||
switch( location )
|
||||
{
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
#ifdef TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION
|
||||
*key_buffer_size = test_size_function( key_type, key_bits );
|
||||
return( PSA_SUCCESS );
|
||||
#else /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */
|
||||
if( PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) )
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
/* Emulate property 'builtin_key_size' */
|
||||
if( psa_key_id_is_builtin(
|
||||
MBEDTLS_SVC_KEY_ID_GET_KEY_ID(
|
||||
psa_get_key_id( attributes ) ) ) )
|
||||
{
|
||||
int public_key_overhead =
|
||||
( ( TEST_DRIVER_KEY_CONTEXT_STORE_PUBLIC_KEY == 1 ) ?
|
||||
PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) : 0 );
|
||||
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE
|
||||
+ TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE
|
||||
+ public_key_overhead;
|
||||
*key_buffer_size = sizeof( psa_drv_slot_number_t );
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_PUBLIC_KEY( key_type ) )
|
||||
{
|
||||
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE
|
||||
+ TEST_DRIVER_KEY_CONTEXT_PUBLIC_KEY_SIZE;
|
||||
}
|
||||
else if ( !PSA_KEY_TYPE_IS_KEY_PAIR( key_type ) &&
|
||||
!PSA_KEY_TYPE_IS_PUBLIC_KEY ( key_type ) )
|
||||
{
|
||||
*key_buffer_size = TEST_DRIVER_KEY_CONTEXT_BASE_SIZE
|
||||
+ TEST_DRIVER_KEY_CONTEXT_SYMMETRIC_FACTOR
|
||||
* ( ( key_bits + 7 ) / 8 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
return( PSA_SUCCESS );
|
||||
#endif /* TEST_DRIVER_KEY_CONTEXT_SIZE_FUNCTION */
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
*key_buffer_size = mbedtls_test_size_function( key_type, key_bits );
|
||||
return( ( *key_buffer_size != 0 ) ?
|
||||
PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
default:
|
||||
@ -335,7 +318,7 @@ psa_status_t psa_driver_wrapper_generate_key(
|
||||
{
|
||||
/* Cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_generate_key(
|
||||
status = mbedtls_test_transparent_generate_key(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
key_buffer_length );
|
||||
/* Declared with fallback == true */
|
||||
@ -353,8 +336,8 @@ psa_status_t psa_driver_wrapper_generate_key(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
status = test_opaque_generate_key(
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
status = mbedtls_test_opaque_generate_key(
|
||||
attributes, key_buffer, key_buffer_size, key_buffer_length );
|
||||
break;
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
@ -418,10 +401,11 @@ psa_status_t psa_driver_wrapper_import_key(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_import_key( attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
status = mbedtls_test_transparent_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
/* Declared with fallback == true */
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -485,13 +469,13 @@ psa_status_t psa_driver_wrapper_export_key(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_export_key( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_export_key( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||
default:
|
||||
@ -537,12 +521,13 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_export_public_key( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length );
|
||||
status = mbedtls_test_transparent_export_public_key(
|
||||
attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length );
|
||||
/* Declared with fallback == true */
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -559,13 +544,13 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_export_public_key( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_export_public_key( attributes,
|
||||
key_buffer,
|
||||
key_buffer_size,
|
||||
data,
|
||||
data_size,
|
||||
data_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||
default:
|
||||
@ -574,6 +559,30 @@ psa_status_t psa_driver_wrapper_export_public_key(
|
||||
}
|
||||
}
|
||||
|
||||
psa_status_t psa_driver_wrapper_get_builtin_key(
|
||||
psa_drv_slot_number_t slot_number,
|
||||
psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
||||
{
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||
switch( location )
|
||||
{
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_get_builtin_key(
|
||||
slot_number,
|
||||
attributes,
|
||||
key_buffer, key_buffer_size, key_buffer_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
default:
|
||||
(void) slot_number;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
(void) key_buffer_length;
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Cipher functions
|
||||
*/
|
||||
@ -599,15 +608,15 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
/* Key is stored in the slot in export representation, so
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_cipher_encrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length );
|
||||
status = mbedtls_test_transparent_cipher_encrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length );
|
||||
/* Declared with fallback == true */
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -616,16 +625,16 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_cipher_encrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_cipher_encrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
default:
|
||||
/* Key is declared with a lifetime not known to us */
|
||||
@ -666,15 +675,15 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
|
||||
/* Key is stored in the slot in export representation, so
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_cipher_decrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length );
|
||||
status = mbedtls_test_transparent_cipher_decrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length );
|
||||
/* Declared with fallback == true */
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -683,16 +692,16 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
return( test_opaque_cipher_decrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length ) );
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
return( mbedtls_test_opaque_cipher_decrypt( &attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg,
|
||||
input,
|
||||
input_length,
|
||||
output,
|
||||
output_size,
|
||||
output_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
default:
|
||||
/* Key is declared with a lifetime not known to us */
|
||||
@ -728,7 +737,7 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_cipher_encrypt_setup(
|
||||
status = mbedtls_test_transparent_cipher_encrypt_setup(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
attributes,
|
||||
key_buffer,
|
||||
@ -760,8 +769,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
status = test_opaque_cipher_encrypt_setup(
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
status = mbedtls_test_opaque_cipher_encrypt_setup(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
@ -800,7 +809,7 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
|
||||
* cycle through all known transparent accelerators */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_cipher_decrypt_setup(
|
||||
status = mbedtls_test_transparent_cipher_decrypt_setup(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
attributes,
|
||||
key_buffer,
|
||||
@ -831,8 +840,8 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
|
||||
/* Add cases for opaque driver here */
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TEST_DRIVER_LIFETIME:
|
||||
status = test_opaque_cipher_decrypt_setup(
|
||||
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
|
||||
status = mbedtls_test_opaque_cipher_decrypt_setup(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
@ -871,12 +880,12 @@ psa_status_t psa_driver_wrapper_cipher_set_iv(
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( test_transparent_cipher_set_iv(
|
||||
return( mbedtls_test_transparent_cipher_set_iv(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
iv, iv_length ) );
|
||||
|
||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
||||
return( test_opaque_cipher_set_iv(
|
||||
return( mbedtls_test_opaque_cipher_set_iv(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
iv, iv_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
@ -912,13 +921,13 @@ psa_status_t psa_driver_wrapper_cipher_update(
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( test_transparent_cipher_update(
|
||||
return( mbedtls_test_transparent_cipher_update(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
|
||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
||||
return( test_opaque_cipher_update(
|
||||
return( mbedtls_test_opaque_cipher_update(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
@ -954,12 +963,12 @@ psa_status_t psa_driver_wrapper_cipher_finish(
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( test_transparent_cipher_finish(
|
||||
return( mbedtls_test_transparent_cipher_finish(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
output, output_size, output_length ) );
|
||||
|
||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
||||
return( test_opaque_cipher_finish(
|
||||
return( mbedtls_test_opaque_cipher_finish(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
output, output_size, output_length ) );
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
@ -988,7 +997,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
status = test_transparent_cipher_abort(
|
||||
status = mbedtls_test_transparent_cipher_abort(
|
||||
&operation->ctx.transparent_test_driver_ctx );
|
||||
mbedtls_platform_zeroize(
|
||||
&operation->ctx.transparent_test_driver_ctx,
|
||||
@ -996,7 +1005,7 @@ psa_status_t psa_driver_wrapper_cipher_abort(
|
||||
return( status );
|
||||
|
||||
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
|
||||
status = test_opaque_cipher_abort(
|
||||
status = mbedtls_test_opaque_cipher_abort(
|
||||
&operation->ctx.opaque_test_driver_ctx );
|
||||
mbedtls_platform_zeroize(
|
||||
&operation->ctx.opaque_test_driver_ctx,
|
||||
@ -1025,7 +1034,7 @@ psa_status_t psa_driver_wrapper_hash_compute(
|
||||
|
||||
/* Try accelerators first */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = mbedtls_transparent_test_driver_hash_compute(
|
||||
status = mbedtls_test_transparent_hash_compute(
|
||||
alg, input, input_length, hash, hash_size, hash_length );
|
||||
if( status != PSA_ERROR_NOT_SUPPORTED )
|
||||
return( status );
|
||||
@ -1057,7 +1066,7 @@ psa_status_t psa_driver_wrapper_hash_setup(
|
||||
|
||||
/* Try setup on accelerators first */
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = mbedtls_transparent_test_driver_hash_setup(
|
||||
status = mbedtls_test_transparent_hash_setup(
|
||||
&operation->ctx.test_driver_ctx, alg );
|
||||
if( status == PSA_SUCCESS )
|
||||
operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
|
||||
@ -1097,7 +1106,7 @@ psa_status_t psa_driver_wrapper_hash_clone(
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
|
||||
return( mbedtls_transparent_test_driver_hash_clone(
|
||||
return( mbedtls_test_transparent_hash_clone(
|
||||
&source_operation->ctx.test_driver_ctx,
|
||||
&target_operation->ctx.test_driver_ctx ) );
|
||||
#endif
|
||||
@ -1121,7 +1130,7 @@ psa_status_t psa_driver_wrapper_hash_update(
|
||||
#endif
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( mbedtls_transparent_test_driver_hash_update(
|
||||
return( mbedtls_test_transparent_hash_update(
|
||||
&operation->ctx.test_driver_ctx,
|
||||
input, input_length ) );
|
||||
#endif
|
||||
@ -1147,7 +1156,7 @@ psa_status_t psa_driver_wrapper_hash_finish(
|
||||
#endif
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( mbedtls_transparent_test_driver_hash_finish(
|
||||
return( mbedtls_test_transparent_hash_finish(
|
||||
&operation->ctx.test_driver_ctx,
|
||||
hash, hash_size, hash_length ) );
|
||||
#endif
|
||||
@ -1170,7 +1179,7 @@ psa_status_t psa_driver_wrapper_hash_abort(
|
||||
#endif
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
|
||||
return( mbedtls_transparent_test_driver_hash_abort(
|
||||
return( mbedtls_test_transparent_hash_abort(
|
||||
&operation->ctx.test_driver_ctx ) );
|
||||
#endif
|
||||
default:
|
||||
@ -1199,7 +1208,7 @@ psa_status_t psa_driver_wrapper_aead_encrypt(
|
||||
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_aead_encrypt(
|
||||
status = mbedtls_test_transparent_aead_encrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg,
|
||||
nonce, nonce_length,
|
||||
@ -1251,7 +1260,7 @@ psa_status_t psa_driver_wrapper_aead_decrypt(
|
||||
|
||||
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
status = test_transparent_aead_decrypt(
|
||||
status = mbedtls_test_transparent_aead_decrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg,
|
||||
nonce, nonce_length,
|
||||
|
@ -68,6 +68,11 @@ psa_status_t psa_driver_wrapper_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
|
||||
|
||||
psa_status_t psa_driver_wrapper_get_builtin_key(
|
||||
psa_drv_slot_number_t slot_number,
|
||||
psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
|
||||
|
||||
/*
|
||||
* Cipher functions
|
||||
*/
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "psa/crypto.h"
|
||||
|
||||
#include "psa_crypto_core.h"
|
||||
#include "psa_crypto_driver_wrappers.h"
|
||||
#include "psa_crypto_slot_management.h"
|
||||
#include "psa_crypto_storage.h"
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||
@ -274,6 +275,77 @@ exit:
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
|
||||
static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot )
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_lifetime_t lifetime = PSA_KEY_LIFETIME_VOLATILE;
|
||||
psa_drv_slot_number_t slot_number = 0;
|
||||
size_t key_buffer_size = 0;
|
||||
size_t key_buffer_length = 0;
|
||||
|
||||
if( ! psa_key_id_is_builtin(
|
||||
MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ) ) )
|
||||
{
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
}
|
||||
|
||||
/* Check the platform function to see whether this key actually exists */
|
||||
status = mbedtls_psa_platform_get_builtin_key(
|
||||
slot->attr.id, &lifetime, &slot_number );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
/* Set required key attributes to ensure get_builtin_key can retrieve the
|
||||
* full attributes. */
|
||||
psa_set_key_id( &attributes, slot->attr.id );
|
||||
psa_set_key_lifetime( &attributes, lifetime );
|
||||
|
||||
/* Get the full key attributes from the driver in order to be able to
|
||||
* calculate the required buffer size. */
|
||||
status = psa_driver_wrapper_get_builtin_key(
|
||||
slot_number, &attributes,
|
||||
NULL, 0, NULL );
|
||||
if( status != PSA_ERROR_BUFFER_TOO_SMALL )
|
||||
{
|
||||
/* Builtin keys cannot be defined by the attributes alone */
|
||||
if( status == PSA_SUCCESS )
|
||||
status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
return( status );
|
||||
}
|
||||
|
||||
/* If the key should exist according to the platform, then ask the driver
|
||||
* what its expected size is. */
|
||||
status = psa_driver_wrapper_get_key_buffer_size( &attributes,
|
||||
&key_buffer_size );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
/* Allocate a buffer of the required size and load the builtin key directly
|
||||
* into the (now properly sized) slot buffer. */
|
||||
status = psa_allocate_buffer_to_slot( slot, key_buffer_size );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
status = psa_driver_wrapper_get_builtin_key(
|
||||
slot_number, &attributes,
|
||||
slot->key.data, slot->key.bytes, &key_buffer_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
/* Copy actual key length and core attributes into the slot on success */
|
||||
slot->key.bytes = key_buffer_length;
|
||||
slot->attr = attributes.core;
|
||||
|
||||
exit:
|
||||
if( status != PSA_SUCCESS )
|
||||
psa_remove_key_data_from_memory( slot );
|
||||
return( status );
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
|
||||
psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key,
|
||||
psa_key_slot_t **p_slot )
|
||||
{
|
||||
@ -291,17 +363,29 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key,
|
||||
if( status != PSA_ERROR_DOES_NOT_EXIST )
|
||||
return( status );
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
/* Loading keys from storage requires support for such a mechanism */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) || \
|
||||
defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
psa_key_id_t volatile_key_id;
|
||||
|
||||
status = psa_get_empty_key_slot( &volatile_key_id, p_slot );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
(*p_slot)->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
|
||||
(*p_slot)->attr.id = key;
|
||||
(*p_slot)->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
|
||||
|
||||
status = PSA_ERROR_DOES_NOT_EXIST;
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
/* Load keys in the 'builtin' range through their own interface */
|
||||
status = psa_load_builtin_key_into_slot( *p_slot );
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
if( status == PSA_ERROR_DOES_NOT_EXIST )
|
||||
status = psa_load_persistent_key_into_slot( *p_slot );
|
||||
#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
|
||||
|
||||
status = psa_load_persistent_key_into_slot( *p_slot );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
psa_wipe_key_slot( *p_slot );
|
||||
@ -309,9 +393,9 @@ psa_status_t psa_get_and_lock_key_slot( mbedtls_svc_key_id_t key,
|
||||
status = PSA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return( status );
|
||||
#else
|
||||
#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
return( PSA_ERROR_INVALID_HANDLE );
|
||||
#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C || MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
}
|
||||
|
||||
psa_status_t psa_unlock_key_slot( psa_key_slot_t *slot )
|
||||
|
@ -102,7 +102,7 @@ int mbedtls_rsa_import( mbedtls_rsa_context *ctx,
|
||||
( D != NULL && ( ret = mbedtls_mpi_copy( &ctx->D, D ) ) != 0 ) ||
|
||||
( E != NULL && ( ret = mbedtls_mpi_copy( &ctx->E, E ) ) != 0 ) )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
|
||||
if( N != NULL )
|
||||
@ -142,7 +142,7 @@ int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx,
|
||||
cleanup:
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -293,7 +293,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
|
||||
if( ( ret = mbedtls_mpi_mul_mpi( &ctx->N, &ctx->P,
|
||||
&ctx->Q ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
|
||||
ctx->len = mbedtls_mpi_size( &ctx->N );
|
||||
@ -308,7 +308,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
|
||||
ret = mbedtls_rsa_deduce_primes( &ctx->N, &ctx->E, &ctx->D,
|
||||
&ctx->P, &ctx->Q );
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
|
||||
}
|
||||
else if( d_missing )
|
||||
@ -318,7 +318,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
|
||||
&ctx->E,
|
||||
&ctx->D ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,7 +333,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx )
|
||||
ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D,
|
||||
&ctx->DP, &ctx->DQ, &ctx->QP );
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
#endif /* MBEDTLS_RSA_NO_CRT */
|
||||
|
||||
@ -461,13 +461,13 @@ int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
|
||||
( DQ != NULL && ( ret = mbedtls_mpi_copy( DQ, &ctx->DQ ) ) != 0 ) ||
|
||||
( QP != NULL && ( ret = mbedtls_mpi_copy( QP, &ctx->QP ) ) != 0 ) )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
#else
|
||||
if( ( ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D,
|
||||
DP, DQ, QP ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -635,8 +635,9 @@ cleanup:
|
||||
if( ret != 0 )
|
||||
{
|
||||
mbedtls_rsa_free( ctx );
|
||||
|
||||
if( ( -ret & ~0x7f ) == 0 )
|
||||
ret = MBEDTLS_ERR_RSA_KEY_GEN_FAILED + ret;
|
||||
ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_KEY_GEN_FAILED, ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
@ -769,7 +770,7 @@ cleanup:
|
||||
mbedtls_mpi_free( &T );
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_RSA_PUBLIC_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -1085,7 +1086,7 @@ cleanup:
|
||||
mbedtls_mpi_free( &I );
|
||||
|
||||
if( ret != 0 && ret >= -0x007f )
|
||||
return( MBEDTLS_ERR_RSA_PRIVATE_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret ) );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -1198,7 +1199,7 @@ int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
|
||||
|
||||
/* Generate a random octet string seed */
|
||||
if( ( ret = f_rng( p_rng, p, hlen ) ) != 0 )
|
||||
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) );
|
||||
|
||||
p += hlen;
|
||||
|
||||
@ -1287,7 +1288,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
|
||||
|
||||
/* Check if RNG failed to generate data */
|
||||
if( rng_dl == 0 || ret != 0 )
|
||||
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) );
|
||||
|
||||
p++;
|
||||
}
|
||||
@ -1881,7 +1882,7 @@ static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
|
||||
/* Generate salt of length slen in place in the encoded message */
|
||||
salt = p;
|
||||
if( ( ret = f_rng( p_rng, salt, slen ) ) != 0 )
|
||||
return( MBEDTLS_ERR_RSA_RNG_FAILED + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) );
|
||||
|
||||
p += slen;
|
||||
|
||||
|
@ -1536,7 +1536,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_ENABLE_WEAK_CIPHERSUITES)
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
@ -1669,8 +1668,6 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] =
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
|
||||
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
||||
|
||||
#endif /* MBEDTLS_ENABLE_WEAK_CIPHERSUITES */
|
||||
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
|
||||
|
@ -2549,6 +2549,7 @@ static int ssl_parse_server_dh_params( mbedtls_ssl_context *ssl,
|
||||
unsigned char *end )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
||||
size_t dhm_actual_bitlen;
|
||||
|
||||
/*
|
||||
* Ephemeral DH parameters:
|
||||
@ -2566,10 +2567,11 @@ static int ssl_parse_server_dh_params( mbedtls_ssl_context *ssl,
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( ssl->handshake->dhm_ctx.len * 8 < ssl->conf->dhm_min_bitlen )
|
||||
dhm_actual_bitlen = mbedtls_mpi_bitlen( &ssl->handshake->dhm_ctx.P );
|
||||
if( dhm_actual_bitlen < ssl->conf->dhm_min_bitlen )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "DHM prime too short: %" MBEDTLS_PRINTF_SIZET " < %u",
|
||||
ssl->handshake->dhm_ctx.len * 8,
|
||||
dhm_actual_bitlen,
|
||||
ssl->conf->dhm_min_bitlen ) );
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE );
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ int mbedtls_ssl_cookie_write( void *p_ctx,
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) );
|
||||
#endif
|
||||
|
||||
ret = ssl_cookie_hmac( &ctx->hmac_ctx, *p - 4,
|
||||
@ -182,8 +182,8 @@ int mbedtls_ssl_cookie_write( void *p_ctx,
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR +
|
||||
MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR,
|
||||
MBEDTLS_ERR_THREADING_MUTEX_ERROR ) );
|
||||
#endif
|
||||
|
||||
return( ret );
|
||||
@ -210,7 +210,7 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 )
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR, ret ) );
|
||||
#endif
|
||||
|
||||
if( ssl_cookie_hmac( &ctx->hmac_ctx, cookie,
|
||||
@ -220,8 +220,8 @@ int mbedtls_ssl_cookie_check( void *p_ctx,
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 )
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR +
|
||||
MBEDTLS_ERR_THREADING_MUTEX_ERROR );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_SSL_INTERNAL_ERROR,
|
||||
MBEDTLS_ERR_THREADING_MUTEX_ERROR ) );
|
||||
#endif
|
||||
|
||||
if( ret != 0 )
|
||||
|
@ -782,7 +782,7 @@ int mbedtls_ssl_encrypt_buf( mbedtls_ssl_context *ssl,
|
||||
&rec->data_len,
|
||||
transform->taglen ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_encrypt", ret );
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_encrypt_ext", ret );
|
||||
return( ret );
|
||||
}
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "after encrypt: tag",
|
||||
@ -1341,7 +1341,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||
* explicit_iv_len Bytes preceeding data, and taglen
|
||||
* bytes following data + data_len. This justifies
|
||||
* the debug message and the invocation of
|
||||
* mbedtls_cipher_auth_decrypt() below. */
|
||||
* mbedtls_cipher_auth_decrypt_ext() below. */
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "IV used", iv, transform->ivlen );
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "TAG used", data + rec->data_len,
|
||||
@ -1357,7 +1357,7 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
|
||||
data, rec->buf_len - (data - rec->buf), &olen, /* dst */
|
||||
transform->taglen ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_decrypt", ret );
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_auth_decrypt_ext", ret );
|
||||
|
||||
if( ret == MBEDTLS_ERR_CIPHER_AUTH_FAILED )
|
||||
return( MBEDTLS_ERR_SSL_INVALID_MAC );
|
||||
@ -4871,7 +4871,6 @@ void mbedtls_ssl_update_out_pointers( mbedtls_ssl_context *ssl,
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ssl->out_ctr = ssl->out_hdr - 8;
|
||||
ssl->out_len = ssl->out_hdr + 3;
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
ssl->out_cid = ssl->out_len;
|
||||
@ -4952,6 +4951,7 @@ void mbedtls_ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl )
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
||||
{
|
||||
ssl->out_ctr = ssl->out_buf;
|
||||
ssl->out_hdr = ssl->out_buf + 8;
|
||||
ssl->in_hdr = ssl->in_buf + 8;
|
||||
}
|
||||
@ -5112,6 +5112,120 @@ static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl )
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
|
||||
/* This function is called from mbedtls_ssl_read() when a handshake message is
|
||||
* received after the initial handshake. In this context, handshake messages
|
||||
* may only be sent for the purpose of initiating renegotiations.
|
||||
*
|
||||
* This function is introduced as a separate helper since the handling
|
||||
* of post-handshake handshake messages changes significantly in TLS 1.3,
|
||||
* and having a helper function allows to distinguish between TLS <= 1.2 and
|
||||
* TLS 1.3 in the future without bloating the logic of mbedtls_ssl_read().
|
||||
*/
|
||||
static int ssl_handle_hs_message_post_handshake( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
/*
|
||||
* - For client-side, expect SERVER_HELLO_REQUEST.
|
||||
* - For server-side, expect CLIENT_HELLO.
|
||||
* - Fail (TLS) or silently drop record (DTLS) in other cases.
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT &&
|
||||
( ssl->in_msg[0] != MBEDTLS_SSL_HS_HELLO_REQUEST ||
|
||||
ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake received (not HelloRequest)" ) );
|
||||
|
||||
/* With DTLS, drop the packet (probably from last handshake) */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
#endif
|
||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CLI_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER &&
|
||||
ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_HELLO )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake received (not ClientHello)" ) );
|
||||
|
||||
/* With DTLS, drop the packet (probably from last handshake) */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
#endif
|
||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_SRV_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
/* Determine whether renegotiation attempt should be accepted */
|
||||
if( ! ( ssl->conf->disable_renegotiation == MBEDTLS_SSL_RENEGOTIATION_DISABLED ||
|
||||
( ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION &&
|
||||
ssl->conf->allow_legacy_renegotiation ==
|
||||
MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION ) ) )
|
||||
{
|
||||
/*
|
||||
* Accept renegotiation request
|
||||
*/
|
||||
|
||||
/* DTLS clients need to know renego is server-initiated */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
|
||||
ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT )
|
||||
{
|
||||
ssl->renego_status = MBEDTLS_SSL_RENEGOTIATION_PENDING;
|
||||
}
|
||||
#endif
|
||||
ret = mbedtls_ssl_start_renegotiation( ssl );
|
||||
if( ret != MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO &&
|
||||
ret != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_start_renegotiation",
|
||||
ret );
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
{
|
||||
/*
|
||||
* Refuse renegotiation
|
||||
*/
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "refusing renegotiation, sending alert" ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
{
|
||||
if( ( ret = mbedtls_ssl_send_alert_message( ssl,
|
||||
MBEDTLS_SSL_ALERT_LEVEL_WARNING,
|
||||
MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 ||
|
||||
MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Receive application data decrypted from the SSL layer
|
||||
*/
|
||||
@ -5210,108 +5324,17 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
|
||||
|
||||
if( ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "received handshake message" ) );
|
||||
|
||||
/*
|
||||
* - For client-side, expect SERVER_HELLO_REQUEST.
|
||||
* - For server-side, expect CLIENT_HELLO.
|
||||
* - Fail (TLS) or silently drop record (DTLS) in other cases.
|
||||
*/
|
||||
|
||||
#if defined(MBEDTLS_SSL_CLI_C)
|
||||
if( ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT &&
|
||||
( ssl->in_msg[0] != MBEDTLS_SSL_HS_HELLO_REQUEST ||
|
||||
ssl->in_hslen != mbedtls_ssl_hs_hdr_len( ssl ) ) )
|
||||
ret = ssl_handle_hs_message_post_handshake( ssl );
|
||||
if( ret != 0)
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake received (not HelloRequest)" ) );
|
||||
|
||||
/* With DTLS, drop the packet (probably from last handshake) */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_CLI_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
if( ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER &&
|
||||
ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_HELLO )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "handshake received (not ClientHello)" ) );
|
||||
|
||||
/* With DTLS, drop the packet (probably from last handshake) */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_SRV_C */
|
||||
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
/* Determine whether renegotiation attempt should be accepted */
|
||||
if( ! ( ssl->conf->disable_renegotiation == MBEDTLS_SSL_RENEGOTIATION_DISABLED ||
|
||||
( ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION &&
|
||||
ssl->conf->allow_legacy_renegotiation ==
|
||||
MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION ) ) )
|
||||
{
|
||||
/*
|
||||
* Accept renegotiation request
|
||||
*/
|
||||
|
||||
/* DTLS clients need to know renego is server-initiated */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
|
||||
ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT )
|
||||
{
|
||||
ssl->renego_status = MBEDTLS_SSL_RENEGOTIATION_PENDING;
|
||||
}
|
||||
#endif
|
||||
ret = mbedtls_ssl_start_renegotiation( ssl );
|
||||
if( ret != MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO &&
|
||||
ret != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_start_renegotiation",
|
||||
ret );
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
||||
{
|
||||
/*
|
||||
* Refuse renegotiation
|
||||
*/
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "refusing renegotiation, sending alert" ) );
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
|
||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
|
||||
{
|
||||
if( ( ret = mbedtls_ssl_send_alert_message( ssl,
|
||||
MBEDTLS_SSL_ALERT_LEVEL_WARNING,
|
||||
MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION ) ) != 0 )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 ||
|
||||
MBEDTLS_SSL_PROTO_TLS1_2 */
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_handle_hs_message_post_handshake",
|
||||
ret );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/* At this point, we don't know whether the renegotiation has been
|
||||
* completed or not. The cases to consider are the following:
|
||||
/* At this point, we don't know whether the renegotiation triggered
|
||||
* by the post-handshake message has been completed or not. The cases
|
||||
* to consider are the following:
|
||||
* 1) The renegotiation is complete. In this case, no new record
|
||||
* has been read yet.
|
||||
* 2) The renegotiation is incomplete because the client received
|
||||
@ -5319,7 +5342,8 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
|
||||
* 3) The renegotiation is incomplete because the client received
|
||||
* a non-handshake, non-application data message while awaiting
|
||||
* the ServerHello.
|
||||
* In each of these case, looping will be the proper action:
|
||||
*
|
||||
* In each of these cases, looping will be the proper action:
|
||||
* - For 1), the next iteration will read a new record and check
|
||||
* if it's application data.
|
||||
* - For 2), the loop condition isn't satisfied as application data
|
||||
@ -5328,6 +5352,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
|
||||
* will re-deliver the message that was held back by the client
|
||||
* when expecting the ServerHello.
|
||||
*/
|
||||
|
||||
continue;
|
||||
}
|
||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||
|
@ -4180,24 +4180,6 @@ void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
||||
|
||||
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( ( ret = mbedtls_mpi_read_string( &conf->dhm_P, 16, dhm_P ) ) != 0 ||
|
||||
( ret = mbedtls_mpi_read_string( &conf->dhm_G, 16, dhm_G ) ) != 0 )
|
||||
{
|
||||
mbedtls_mpi_free( &conf->dhm_P );
|
||||
mbedtls_mpi_free( &conf->dhm_G );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf,
|
||||
const unsigned char *dhm_P, size_t P_len,
|
||||
const unsigned char *dhm_G, size_t G_len )
|
||||
@ -4722,13 +4704,6 @@ size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl )
|
||||
|
||||
return( max_len );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl )
|
||||
{
|
||||
return mbedtls_ssl_get_output_max_frag_len( ssl );
|
||||
}
|
||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
|
@ -300,9 +300,6 @@ static const char * const features[] = {
|
||||
#if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
|
||||
"MBEDTLS_CTR_DRBG_USE_128_BIT_KEY",
|
||||
#endif /* MBEDTLS_CTR_DRBG_USE_128_BIT_KEY */
|
||||
#if defined(MBEDTLS_ENABLE_WEAK_CIPHERSUITES)
|
||||
"MBEDTLS_ENABLE_WEAK_CIPHERSUITES",
|
||||
#endif /* MBEDTLS_ENABLE_WEAK_CIPHERSUITES */
|
||||
#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES)
|
||||
"MBEDTLS_REMOVE_3DES_CIPHERSUITES",
|
||||
#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */
|
||||
@ -435,6 +432,9 @@ static const char * const features[] = {
|
||||
#if defined(MBEDTLS_PKCS1_V21)
|
||||
"MBEDTLS_PKCS1_V21",
|
||||
#endif /* MBEDTLS_PKCS1_V21 */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
|
||||
"MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS",
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
|
||||
"MBEDTLS_PSA_CRYPTO_CLIENT",
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
|
||||
@ -594,6 +594,9 @@ static const char * const features[] = {
|
||||
#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
|
||||
"MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE",
|
||||
#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
|
||||
#if defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
"MBEDTLS_X509_REMOVE_INFO",
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
"MBEDTLS_X509_RSASSA_PSS_SUPPORT",
|
||||
#endif /* MBEDTLS_X509_RSASSA_PSS_SUPPORT */
|
||||
|
126
library/x509.c
126
library/x509.c
@ -81,18 +81,18 @@ int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_SERIAL +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SERIAL,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
if( **p != ( MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_PRIMITIVE | 2 ) &&
|
||||
**p != MBEDTLS_ASN1_INTEGER )
|
||||
return( MBEDTLS_ERR_X509_INVALID_SERIAL +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SERIAL,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
serial->tag = *(*p)++;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_len( p, end, &serial->len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_SERIAL + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SERIAL, ret ) );
|
||||
|
||||
serial->p = *p;
|
||||
*p += serial->len;
|
||||
@ -112,7 +112,7 @@ int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg_null( p, end, alg ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -126,7 +126,7 @@ int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_alg( p, end, alg, params ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -151,39 +151,39 @@ static int x509_get_hash_alg( const mbedtls_x509_buf *alg, mbedtls_md_type_t *md
|
||||
|
||||
/* Make sure we got a SEQUENCE and setup bounds */
|
||||
if( alg->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
p = alg->p;
|
||||
end = p + alg->len;
|
||||
|
||||
if( p >= end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
/* Parse md_oid */
|
||||
md_oid.tag = *p;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &md_oid.len, MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
md_oid.p = p;
|
||||
p += md_oid.len;
|
||||
|
||||
/* Get md_alg from md_oid */
|
||||
if( ( ret = mbedtls_oid_get_md_alg( &md_oid, md_alg ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
/* Make sure params is absent of NULL */
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_NULL ) ) != 0 || len != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -217,8 +217,8 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
|
||||
/* Make sure params is a SEQUENCE and setup bounds */
|
||||
if( params->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
p = (unsigned char *) params->p;
|
||||
end = p + params->len;
|
||||
@ -239,14 +239,14 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
return( ret );
|
||||
|
||||
if( ( ret = mbedtls_oid_get_md_alg( &alg_id, md_alg ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p != end2 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
@ -265,19 +265,19 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
|
||||
/* Only MFG1 is recognised for now */
|
||||
if( MBEDTLS_OID_CMP( MBEDTLS_OID_MGF1, &alg_id ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE +
|
||||
MBEDTLS_ERR_OID_NOT_FOUND );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE,
|
||||
MBEDTLS_ERR_OID_NOT_FOUND ) );
|
||||
|
||||
/* Parse HashAlgorithm */
|
||||
if( ( ret = x509_get_hash_alg( &alg_params, mgf_md ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
if( p != end2 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
@ -291,14 +291,14 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
end2 = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end2, salt_len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p != end2 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p == end )
|
||||
return( 0 );
|
||||
@ -314,21 +314,21 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
|
||||
end2 = p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( &p, end2, &trailer_field ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p != end2 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
if( trailer_field != 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG );
|
||||
}
|
||||
else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG, ret ) );
|
||||
|
||||
if( p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_ALG +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_ALG,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -354,47 +354,47 @@ static int x509_get_attr_type_value( unsigned char **p,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) );
|
||||
|
||||
end = *p + len;
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
oid = &cur->oid;
|
||||
oid->tag = **p;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &oid->len, MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) );
|
||||
|
||||
oid->p = *p;
|
||||
*p += oid->len;
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
if( **p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING &&
|
||||
**p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING &&
|
||||
**p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING &&
|
||||
**p != MBEDTLS_ASN1_BIT_STRING )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
val = &cur->val;
|
||||
val->tag = *(*p)++;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_len( p, end, &val->len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) );
|
||||
|
||||
val->p = *p;
|
||||
*p += val->len;
|
||||
|
||||
if( *p != end )
|
||||
{
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
cur->next = NULL;
|
||||
@ -440,7 +440,7 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &set_len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_NAME + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_NAME, ret ) );
|
||||
|
||||
end_set = *p + set_len;
|
||||
|
||||
@ -604,8 +604,8 @@ int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
unsigned char tag;
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
tag = **p;
|
||||
|
||||
@ -614,14 +614,14 @@ int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
|
||||
else if( tag == MBEDTLS_ASN1_GENERALIZED_TIME )
|
||||
year_len = 4;
|
||||
else
|
||||
return( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
|
||||
(*p)++;
|
||||
ret = mbedtls_asn1_get_len( p, end, &len );
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_DATE + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) );
|
||||
|
||||
return x509_parse_time( p, len, year_len, tm );
|
||||
}
|
||||
@ -633,13 +633,13 @@ int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x
|
||||
int tag_type;
|
||||
|
||||
if( ( end - *p ) < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_SIGNATURE +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SIGNATURE,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) );
|
||||
|
||||
tag_type = **p;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_SIGNATURE + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_SIGNATURE, ret ) );
|
||||
|
||||
sig->tag = tag_type;
|
||||
sig->len = len;
|
||||
@ -663,7 +663,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
|
||||
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = mbedtls_oid_get_sig_alg( sig_oid, md_alg, pk_alg ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG, ret ) );
|
||||
|
||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
|
||||
if( *pk_alg == MBEDTLS_PK_RSASSA_PSS )
|
||||
@ -714,7 +714,7 @@ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
|
||||
ret = mbedtls_asn1_get_tag( p, end, &ext->len,
|
||||
MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag );
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag;
|
||||
ext->p = *p;
|
||||
@ -725,11 +725,11 @@ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( end != *p + len )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -831,6 +831,7 @@ int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *se
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/*
|
||||
* Helper for writing signature algorithms
|
||||
*/
|
||||
@ -875,6 +876,7 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s
|
||||
|
||||
return( (int)( size - n ) );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/*
|
||||
* Helper for writing "RSA key size", "EC key size", etc
|
||||
|
@ -79,7 +79,7 @@ static int x509_crl_get_version( unsigned char **p,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
return( MBEDTLS_ERR_X509_INVALID_VERSION + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -125,7 +125,7 @@ static int x509_get_crl_ext( unsigned char **p,
|
||||
/* Get enclosing sequence tag */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
end_ext_data = *p + len;
|
||||
|
||||
@ -133,7 +133,7 @@ static int x509_get_crl_ext( unsigned char **p,
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len,
|
||||
MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
}
|
||||
*p += len;
|
||||
|
||||
@ -142,29 +142,29 @@ static int x509_get_crl_ext( unsigned char **p,
|
||||
&is_critical ) ) != 0 &&
|
||||
( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) )
|
||||
{
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
}
|
||||
|
||||
/* Data should be octet string type */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len,
|
||||
MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
/* Ignore data so far and just check its length */
|
||||
*p += len;
|
||||
if( *p != end_ext_data )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/* Abort on (unsupported) critical extensions */
|
||||
if( is_critical )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
}
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -198,27 +198,27 @@ static int x509_get_crl_entry_ext( unsigned char **p,
|
||||
ext->p = NULL;
|
||||
return( 0 );
|
||||
}
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
}
|
||||
|
||||
end = *p + ext->len;
|
||||
|
||||
if( end != *p + ext->len )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
while( *p < end )
|
||||
{
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
*p += len;
|
||||
}
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -364,8 +364,8 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
if( len != (size_t) ( end - p ) )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -377,7 +377,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
@ -421,7 +421,7 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_x509_get_name( &p, p + len, &crl->issuer ) ) != 0 )
|
||||
@ -444,10 +444,10 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
|
||||
if( ( ret = mbedtls_x509_get_time( &p, end, &crl->next_update ) ) != 0 )
|
||||
{
|
||||
if( ret != ( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) &&
|
||||
ret != ( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) )
|
||||
if( ret != ( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) &&
|
||||
ret != ( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE,
|
||||
MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ) )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( ret );
|
||||
@ -486,8 +486,8 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
if( p != end )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
end = crl->raw.p + crl->raw.len;
|
||||
@ -521,8 +521,8 @@ int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
|
||||
if( p != end )
|
||||
{
|
||||
mbedtls_x509_crl_free( crl );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -614,6 +614,7 @@ int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path )
|
||||
}
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
/*
|
||||
* Return an informational string about the certificate.
|
||||
*/
|
||||
@ -693,6 +694,7 @@ int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/*
|
||||
* Initialize a CRL chain
|
||||
|
@ -393,17 +393,17 @@ static int x509_get_version( unsigned char **p,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = *p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( p, end, ver ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_VERSION + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) );
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_VERSION +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -423,7 +423,7 @@ static int x509_get_dates( unsigned char **p,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_DATE + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE, ret ) );
|
||||
|
||||
end = *p + len;
|
||||
|
||||
@ -434,8 +434,8 @@ static int x509_get_dates( unsigned char **p,
|
||||
return( ret );
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_DATE,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -460,7 +460,7 @@ static int x509_get_uid( unsigned char **p,
|
||||
if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG )
|
||||
return( 0 );
|
||||
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
uid->p = *p;
|
||||
@ -487,7 +487,7 @@ static int x509_get_basic_constraints( unsigned char **p,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( *p == end )
|
||||
return( 0 );
|
||||
@ -498,7 +498,7 @@ static int x509_get_basic_constraints( unsigned char **p,
|
||||
ret = mbedtls_asn1_get_int( p, end, ca_istrue );
|
||||
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( *ca_istrue != 0 )
|
||||
*ca_istrue = 1;
|
||||
@ -508,17 +508,17 @@ static int x509_get_basic_constraints( unsigned char **p,
|
||||
return( 0 );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_int( p, end, max_pathlen ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/* Do not accept max_pathlen equal to INT_MAX to avoid a signed integer
|
||||
* overflow, which is an undefined behavior. */
|
||||
if( *max_pathlen == INT_MAX )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH ) );
|
||||
|
||||
(*max_pathlen)++;
|
||||
|
||||
@ -533,11 +533,11 @@ static int x509_get_ns_cert_type( unsigned char **p,
|
||||
mbedtls_x509_bitstring bs = { 0, 0, NULL };
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_bitstring( p, end, &bs ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( bs.len != 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH ) );
|
||||
|
||||
/* Get actual bitstring */
|
||||
*ns_cert_type = *bs.p;
|
||||
@ -553,11 +553,11 @@ static int x509_get_key_usage( unsigned char **p,
|
||||
mbedtls_x509_bitstring bs = { 0, 0, NULL };
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_bitstring( p, end, &bs ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( bs.len < 1 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH ) );
|
||||
|
||||
/* Get actual bitstring */
|
||||
*key_usage = 0;
|
||||
@ -581,12 +581,12 @@ static int x509_get_ext_key_usage( unsigned char **p,
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_sequence_of( p, end, ext_key_usage, MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
/* Sequence length must be >= 1 */
|
||||
if( ext_key_usage->buf.p == NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -631,11 +631,11 @@ static int x509_get_subject_alt_name( unsigned char **p,
|
||||
/* Get main sequence tag */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
while( *p < end )
|
||||
{
|
||||
@ -645,13 +645,13 @@ static int x509_get_subject_alt_name( unsigned char **p,
|
||||
tag = **p;
|
||||
(*p)++;
|
||||
if( ( ret = mbedtls_asn1_get_len( p, end, &tag_len ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( ( tag & MBEDTLS_ASN1_TAG_CLASS_MASK ) !=
|
||||
MBEDTLS_ASN1_CONTEXT_SPECIFIC )
|
||||
{
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -687,8 +687,8 @@ static int x509_get_subject_alt_name( unsigned char **p,
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_ALLOC_FAILED );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_ALLOC_FAILED ) );
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
@ -704,8 +704,8 @@ static int x509_get_subject_alt_name( unsigned char **p,
|
||||
cur->next = NULL;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -772,18 +772,18 @@ static int x509_get_certificate_policies( unsigned char **p,
|
||||
ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE );
|
||||
if( ret != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( *p + len != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/*
|
||||
* Cannot be an empty sequence.
|
||||
*/
|
||||
if( len == 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
while( *p < end )
|
||||
{
|
||||
@ -795,13 +795,13 @@ static int x509_get_certificate_policies( unsigned char **p,
|
||||
*/
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
policy_end = *p + len;
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
|
||||
MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
policy_oid.tag = MBEDTLS_ASN1_OID;
|
||||
policy_oid.len = len;
|
||||
@ -829,8 +829,8 @@ static int x509_get_certificate_policies( unsigned char **p,
|
||||
cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
|
||||
|
||||
if( cur->next == NULL )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_ALLOC_FAILED );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_ALLOC_FAILED ) );
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
@ -850,7 +850,7 @@ static int x509_get_certificate_policies( unsigned char **p,
|
||||
{
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, policy_end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
/*
|
||||
* Skip the optional policy qualifiers.
|
||||
*/
|
||||
@ -858,16 +858,16 @@ static int x509_get_certificate_policies( unsigned char **p,
|
||||
}
|
||||
|
||||
if( *p != policy_end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
/* Set final sequence entry's next pointer to NULL */
|
||||
cur->next = NULL;
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( parse_ret );
|
||||
}
|
||||
@ -907,14 +907,14 @@ static int x509_get_crt_ext( unsigned char **p,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
end_ext_data = *p + len;
|
||||
|
||||
/* Get extension ID */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &extn_oid.len,
|
||||
MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
extn_oid.tag = MBEDTLS_ASN1_OID;
|
||||
extn_oid.p = *p;
|
||||
@ -923,19 +923,19 @@ static int x509_get_crt_ext( unsigned char **p,
|
||||
/* Get optional critical */
|
||||
if( ( ret = mbedtls_asn1_get_bool( p, end_ext_data, &is_critical ) ) != 0 &&
|
||||
( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
/* Data should be octet string type */
|
||||
if( ( ret = mbedtls_asn1_get_tag( p, end_ext_data, &len,
|
||||
MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
start_ext_octet = *p;
|
||||
end_ext_octet = *p + len;
|
||||
|
||||
if( end_ext_octet != end_ext_data )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
/*
|
||||
* Detect supported extensions
|
||||
@ -961,8 +961,8 @@ static int x509_get_crt_ext( unsigned char **p,
|
||||
if( is_critical )
|
||||
{
|
||||
/* Data is marked as critical: fail */
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
@ -1055,8 +1055,8 @@ static int x509_get_crt_ext( unsigned char **p,
|
||||
}
|
||||
|
||||
if( *p != end )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -1134,7 +1134,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( crt );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
@ -1181,7 +1181,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( crt );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_x509_get_name( &p, p + len, &crt->issuer ) ) != 0 )
|
||||
@ -1214,7 +1214,7 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_crt_free( crt );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( len && ( ret = mbedtls_x509_get_name( &p, p + len, &crt->subject ) ) != 0 )
|
||||
@ -1279,8 +1279,8 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
if( p != end )
|
||||
{
|
||||
mbedtls_x509_crt_free( crt );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
end = crt_end;
|
||||
@ -1318,8 +1318,8 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
if( p != end )
|
||||
{
|
||||
mbedtls_x509_crt_free( crt );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -1702,7 +1702,7 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name,
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
cur_oid.tag = MBEDTLS_ASN1_OID;
|
||||
cur_oid.p = p;
|
||||
@ -1719,20 +1719,20 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name,
|
||||
if( p + len >= end )
|
||||
{
|
||||
mbedtls_platform_zeroize( other_name, sizeof( *other_name ) );
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
p += len;
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OID ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
other_name->value.hardware_module_name.oid.tag = MBEDTLS_ASN1_OID;
|
||||
other_name->value.hardware_module_name.oid.p = p;
|
||||
@ -1741,13 +1741,13 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name,
|
||||
if( p + len >= end )
|
||||
{
|
||||
mbedtls_platform_zeroize( other_name, sizeof( *other_name ) );
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
p += len;
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_OCTET_STRING ) ) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS, ret ) );
|
||||
|
||||
other_name->value.hardware_module_name.val.tag = MBEDTLS_ASN1_OCTET_STRING;
|
||||
other_name->value.hardware_module_name.val.p = p;
|
||||
@ -1757,12 +1757,63 @@ static int x509_get_other_name( const mbedtls_x509_buf *subject_alt_name,
|
||||
{
|
||||
mbedtls_platform_zeroize( other_name,
|
||||
sizeof( *other_name ) );
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf,
|
||||
mbedtls_x509_subject_alternative_name *san )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
switch( san_buf->tag &
|
||||
( MBEDTLS_ASN1_TAG_CLASS_MASK |
|
||||
MBEDTLS_ASN1_TAG_VALUE_MASK ) )
|
||||
{
|
||||
/*
|
||||
* otherName
|
||||
*/
|
||||
case( MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME ):
|
||||
{
|
||||
mbedtls_x509_san_other_name other_name;
|
||||
|
||||
ret = x509_get_other_name( san_buf, &other_name );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
|
||||
memset( san, 0, sizeof( mbedtls_x509_subject_alternative_name ) );
|
||||
san->type = MBEDTLS_X509_SAN_OTHER_NAME;
|
||||
memcpy( &san->san.other_name,
|
||||
&other_name, sizeof( other_name ) );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* dNSName
|
||||
*/
|
||||
case( MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DNS_NAME ):
|
||||
{
|
||||
memset( san, 0, sizeof( mbedtls_x509_subject_alternative_name ) );
|
||||
san->type = MBEDTLS_X509_SAN_DNS_NAME;
|
||||
|
||||
memcpy( &san->san.unstructured_name,
|
||||
san_buf, sizeof( *san_buf ) );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Type not supported
|
||||
*/
|
||||
default:
|
||||
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
static int x509_info_subject_alt_name( char **buf, size_t *size,
|
||||
const mbedtls_x509_sequence
|
||||
*subject_alt_name,
|
||||
@ -1876,56 +1927,6 @@ static int x509_info_subject_alt_name( char **buf, size_t *size,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int mbedtls_x509_parse_subject_alt_name( const mbedtls_x509_buf *san_buf,
|
||||
mbedtls_x509_subject_alternative_name *san )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
switch( san_buf->tag &
|
||||
( MBEDTLS_ASN1_TAG_CLASS_MASK |
|
||||
MBEDTLS_ASN1_TAG_VALUE_MASK ) )
|
||||
{
|
||||
/*
|
||||
* otherName
|
||||
*/
|
||||
case( MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_OTHER_NAME ):
|
||||
{
|
||||
mbedtls_x509_san_other_name other_name;
|
||||
|
||||
ret = x509_get_other_name( san_buf, &other_name );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
|
||||
memset( san, 0, sizeof( mbedtls_x509_subject_alternative_name ) );
|
||||
san->type = MBEDTLS_X509_SAN_OTHER_NAME;
|
||||
memcpy( &san->san.other_name,
|
||||
&other_name, sizeof( other_name ) );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* dNSName
|
||||
*/
|
||||
case( MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_X509_SAN_DNS_NAME ):
|
||||
{
|
||||
memset( san, 0, sizeof( mbedtls_x509_subject_alternative_name ) );
|
||||
san->type = MBEDTLS_X509_SAN_DNS_NAME;
|
||||
|
||||
memcpy( &san->san.unstructured_name,
|
||||
san_buf, sizeof( *san_buf ) );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Type not supported
|
||||
*/
|
||||
default:
|
||||
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define PRINT_ITEM(i) \
|
||||
{ \
|
||||
ret = mbedtls_snprintf( p, n, "%s" i, sep ); \
|
||||
@ -2199,29 +2200,12 @@ struct x509_crt_verify_string {
|
||||
const char *string;
|
||||
};
|
||||
|
||||
#define X509_CRT_ERROR_INFO( err, err_str, info ) { err, info },
|
||||
static const struct x509_crt_verify_string x509_crt_verify_strings[] = {
|
||||
{ MBEDTLS_X509_BADCERT_EXPIRED, "The certificate validity has expired" },
|
||||
{ MBEDTLS_X509_BADCERT_REVOKED, "The certificate has been revoked (is on a CRL)" },
|
||||
{ MBEDTLS_X509_BADCERT_CN_MISMATCH, "The certificate Common Name (CN) does not match with the expected CN" },
|
||||
{ MBEDTLS_X509_BADCERT_NOT_TRUSTED, "The certificate is not correctly signed by the trusted CA" },
|
||||
{ MBEDTLS_X509_BADCRL_NOT_TRUSTED, "The CRL is not correctly signed by the trusted CA" },
|
||||
{ MBEDTLS_X509_BADCRL_EXPIRED, "The CRL is expired" },
|
||||
{ MBEDTLS_X509_BADCERT_MISSING, "Certificate was missing" },
|
||||
{ MBEDTLS_X509_BADCERT_SKIP_VERIFY, "Certificate verification was skipped" },
|
||||
{ MBEDTLS_X509_BADCERT_OTHER, "Other reason (can be used by verify callback)" },
|
||||
{ MBEDTLS_X509_BADCERT_FUTURE, "The certificate validity starts in the future" },
|
||||
{ MBEDTLS_X509_BADCRL_FUTURE, "The CRL is from the future" },
|
||||
{ MBEDTLS_X509_BADCERT_KEY_USAGE, "Usage does not match the keyUsage extension" },
|
||||
{ MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, "Usage does not match the extendedKeyUsage extension" },
|
||||
{ MBEDTLS_X509_BADCERT_NS_CERT_TYPE, "Usage does not match the nsCertType extension" },
|
||||
{ MBEDTLS_X509_BADCERT_BAD_MD, "The certificate is signed with an unacceptable hash." },
|
||||
{ MBEDTLS_X509_BADCERT_BAD_PK, "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA)." },
|
||||
{ MBEDTLS_X509_BADCERT_BAD_KEY, "The certificate is signed with an unacceptable key (eg bad curve, RSA too short)." },
|
||||
{ MBEDTLS_X509_BADCRL_BAD_MD, "The CRL is signed with an unacceptable hash." },
|
||||
{ MBEDTLS_X509_BADCRL_BAD_PK, "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA)." },
|
||||
{ MBEDTLS_X509_BADCRL_BAD_KEY, "The CRL is signed with an unacceptable key (eg bad curve, RSA too short)." },
|
||||
MBEDTLS_X509_CRT_ERROR_INFO_LIST
|
||||
{ 0, NULL }
|
||||
};
|
||||
#undef X509_CRT_ERROR_INFO
|
||||
|
||||
int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
|
||||
uint32_t flags )
|
||||
@ -2250,6 +2234,7 @@ int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
|
||||
int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
|
||||
|
@ -73,7 +73,7 @@ static int x509_csr_get_version( unsigned char **p,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
return( MBEDTLS_ERR_X509_INVALID_VERSION + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_VERSION, ret ) );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -131,8 +131,8 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
if( len != (size_t) ( end - p ) )
|
||||
{
|
||||
mbedtls_x509_csr_free( csr );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -144,7 +144,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_csr_free( csr );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
end = p + len;
|
||||
@ -176,7 +176,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_csr_free( csr );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_x509_get_name( &p, p + len, &csr->subject ) ) != 0 )
|
||||
@ -210,7 +210,7 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC ) ) != 0 )
|
||||
{
|
||||
mbedtls_x509_csr_free( csr );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
}
|
||||
|
||||
p += len;
|
||||
@ -244,8 +244,8 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||
if( p != end )
|
||||
{
|
||||
mbedtls_x509_csr_free( csr );
|
||||
return( MBEDTLS_ERR_X509_INVALID_FORMAT +
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH );
|
||||
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT,
|
||||
MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
@ -323,6 +323,7 @@ int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path )
|
||||
}
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
#define BEFORE_COLON 14
|
||||
#define BC "14"
|
||||
/*
|
||||
@ -367,6 +368,7 @@ int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
|
||||
|
||||
return( (int) ( size - n ) );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
|
||||
/*
|
||||
* Initialize a CSR
|
||||
|
1
programs/.gitignore
vendored
1
programs/.gitignore
vendored
@ -8,7 +8,6 @@
|
||||
*.o
|
||||
*.exe
|
||||
|
||||
aes/aescrypt2
|
||||
aes/crypt_and_hash
|
||||
hash/generic_sum
|
||||
hash/hello
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user