Merge branch 'development' into development-restricted
* development: (236 commits) Changing the key length to 32 bytes in one of the PSA cipher setup tests Removal of RC4 certs and fixes to docs and tests Fix fd range for select on Windows Refactor file descriptor checks into a common function Removing global variable and moving variant function comment block Fix typo in doc'n of session resumption API Code review fixes Fix warning in some configurations Fix cmake build of fuzz_privkey Fix async support in ssl_server2 Improve ChangeLog and migration guide entries Use a proper DRBG in programs Use the dedicated dummy_random in fuzzing programs Fix cmake build of programs Add ChangeLog and migration guide entries Simplify internal code Remove "internal RNG" code from ECP Remove config option MBEDTLS_ECP_NO_INTERNAL_RNG Add RNG params to private key parsing Add RNG parameter to check_pair functions ...
This commit is contained in:
commit
21efe44af3
364 changed files with 6397 additions and 13821 deletions
35
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
35
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: To report a bug, please fill this form.
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Summary
|
||||
|
||||
|
||||
|
||||
### System information
|
||||
|
||||
Mbed TLS version (number or commit id):
|
||||
Operating system and version:
|
||||
Configuration (if not default, please attach `config.h`):
|
||||
Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
|
||||
Additional environment information:
|
||||
|
||||
### Expected behavior
|
||||
|
||||
|
||||
|
||||
### Actual behavior
|
||||
|
||||
|
||||
|
||||
### Steps to reproduce
|
||||
|
||||
|
||||
|
||||
### Additional information
|
||||
|
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Mbed TLS security team
|
||||
url: mailto:mbed-tls-security@lists.trustedfirmware.org
|
||||
about: Report a security vulnerability.
|
||||
- name: Mbed TLS mailing list
|
||||
url: https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
|
||||
about: Mbed TLS community support and general discussion.
|
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
name: Enhancement request
|
||||
about: To request an enhancement, please fill this form.
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Suggested enhancement
|
||||
|
||||
|
||||
|
||||
### Justification
|
||||
|
||||
Mbed TLS needs this because
|
||||
|
46
.github/issue_template.md
vendored
46
.github/issue_template.md
vendored
|
@ -1,46 +0,0 @@
|
|||
_Note:_ this is a template, please remove the parts that are not
|
||||
applicable (these initial notes, and the "Bug" section for a Feature request
|
||||
and vice-versa).
|
||||
|
||||
**Note:** to report a security vulnerability, see
|
||||
[SECURITY.md](../SECURITY.md). Please do not use github issues for
|
||||
vulnerabilities.
|
||||
|
||||
_Note:_ to get support, see [SUPPORT.md](../SUPPORT.md). Please do not use
|
||||
github issues for questions.
|
||||
|
||||
---------------------------------------------------------------
|
||||
### Description
|
||||
- Type: Bug | Enhancement / Feature Request
|
||||
- Priority: Blocker | Major | Minor
|
||||
|
||||
---------------------------------------------------------------
|
||||
## Bug
|
||||
|
||||
**OS**
|
||||
Mbed OS|linux|windows|
|
||||
|
||||
**mbed TLS build:**
|
||||
Version: x.x.x or git commit id
|
||||
OS version: x.x.x
|
||||
Configuration: please attach config.h file where possible
|
||||
Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
|
||||
Additional environment information:
|
||||
|
||||
**Peer device TLS stack and version**
|
||||
OpenSSL|GnuTls|Chrome|NSS(Firefox)|SecureChannel (IIS/Internet Explorer/Edge)|Other
|
||||
Version:
|
||||
|
||||
**Expected behavior**
|
||||
|
||||
**Actual behavior**
|
||||
|
||||
**Steps to reproduce**
|
||||
|
||||
----------------------------------------------------------------
|
||||
## Enhancement / Feature Request
|
||||
|
||||
**Suggested enhancement**
|
||||
|
||||
**Justification - why does the library need this feature?**
|
||||
|
|
@ -28,12 +28,6 @@ jobs:
|
|||
script:
|
||||
- tests/scripts/all.sh -k test_full_cmake_gcc_asan
|
||||
|
||||
- name: macOS
|
||||
os: osx
|
||||
compiler: clang
|
||||
script:
|
||||
- tests/scripts/all.sh -k test_default_out_of_box
|
||||
|
||||
- name: Windows
|
||||
os: windows
|
||||
before_install:
|
||||
|
|
34
BRANCHES.md
34
BRANCHES.md
|
@ -16,9 +16,10 @@ At any point in time, we have a number of maintained branches consisting of:
|
|||
these only get bug fixes and security fixes.
|
||||
|
||||
We use [Semantic Versioning](https://semver.org/). In particular, we maintain
|
||||
API compatibility in the `master` branch between major version changes. We
|
||||
also maintain ABI compatibility within LTS branches; see the next section for
|
||||
details.
|
||||
API compatibility in the `master` branch across minor version changes (e.g.
|
||||
the API of 3.(x+1) is backward compatible with 3.x). We only break API
|
||||
compatibility on major version changes (e.g. from 3.x to 4.0). We also maintain
|
||||
ABI compatibility within LTS branches; see the next section for details.
|
||||
|
||||
## Backwards Compatibility
|
||||
|
||||
|
@ -28,11 +29,28 @@ undocumented features, then you should be able to re-compile it without
|
|||
modification with any later release x.y'.z' with the same major version
|
||||
number, and your code will still build, be secure, and work.
|
||||
|
||||
There are rare exceptions: code that was relying on something that became
|
||||
insecure in the meantime (for example, crypto that was found to be weak) may
|
||||
need to be changed. In case security comes in conflict with backwards
|
||||
compatibility, we will put security first, but always attempt to provide a
|
||||
compatibility option.
|
||||
Note that new releases of Mbed TLS may extend the API. Here are some
|
||||
examples of changes that are common in minor releases of Mbed TLS, and are
|
||||
not considered API compatibility breaks:
|
||||
|
||||
* Adding or reordering fields in a structure or union.
|
||||
* Removing a field from a structure, unless the field is documented as public.
|
||||
* Adding items to an enum.
|
||||
* Returning an error code that was not previously documented for a function
|
||||
when a new error condition arises.
|
||||
* Changing which error code is returned in a case where multiple error
|
||||
conditions apply.
|
||||
* Changing the behavior of a function from failing to succeeding, when the
|
||||
change is a reasonable extension of the current behavior, i.e. the
|
||||
addition of a new feature.
|
||||
|
||||
There are rare exceptions where we break API compatibility: code that was
|
||||
relying on something that became insecure in the meantime (for example,
|
||||
crypto that was found to be weak) may need to be changed. In case security
|
||||
comes in conflict with backwards compatibility, we will put security first,
|
||||
but always attempt to provide a compatibility option.
|
||||
|
||||
## Long-time support branches
|
||||
|
||||
For the LTS branches, additionally we try very hard to also maintain ABI
|
||||
compatibility (same definition as API except with re-linking instead of
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
# mbedtls, mbedx509, mbedcrypto and apidoc targets.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
# We specify a minimum requirement of 3.10.2, but for now use 3.5.1 here
|
||||
# until our infrastructure catches up.
|
||||
cmake_minimum_required(VERSION 3.5.1)
|
||||
|
||||
# https://cmake.org/cmake/help/latest/policy/CMP0011.html
|
||||
# Setting this policy is required in CMake >= 3.18.0, otherwise a warning is generated. The OLD
|
||||
|
|
|
@ -22,7 +22,7 @@ API changes
|
|||
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
|
||||
which have also been renamed to ecp_internal_alt.h and rsa_alt_helpers.h
|
||||
respectively.
|
||||
* Move internal headers.
|
||||
Header files that were only meant for the library's internal use and
|
||||
|
|
6
ChangeLog.d/alt-context-relaxation.txt
Normal file
6
ChangeLog.d/alt-context-relaxation.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
Features
|
||||
* Alternative implementations of the AES, DHM, ECJPAKE, ECP, RSA and timing
|
||||
modules had undocumented constraints on their context types. These
|
||||
constraints have been relaxed.
|
||||
See docs/architecture/alternative-implementations.md for the remaining
|
||||
constraints.
|
9
ChangeLog.d/dhm-fields.txt
Normal file
9
ChangeLog.d/dhm-fields.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
Features
|
||||
* The new functions mbedtls_dhm_get_len() and mbedtls_dhm_get_bitlen()
|
||||
query the size of the modulus in a Diffie-Hellman context.
|
||||
* The new function mbedtls_dhm_get_value() copy a field out of a
|
||||
Diffie-Hellman context.
|
||||
|
||||
API changes
|
||||
* Instead of accessing the len field of a DHM context, which is no longer
|
||||
supported, use the new function mbedtls_dhm_get_len() .
|
4
ChangeLog.d/ecjpake-point_format.txt
Normal file
4
ChangeLog.d/ecjpake-point_format.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Features
|
||||
* Use the new function mbedtls_ecjpake_set_point_format() to select the
|
||||
point format for ECJPAKE instead of accessing the point_format field
|
||||
directly, which is no longer supported.
|
3
ChangeLog.d/ecp_max_bits.txt
Normal file
3
ChangeLog.d/ecp_max_bits.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Removals
|
||||
* MBEDTLS_ECP_MAX_BITS is no longer a configuration option because it is
|
||||
now determined automatically based on supported curves.
|
5
ChangeLog.d/fix-ssl-cf-hmac-alt.txt
Normal file
5
ChangeLog.d/fix-ssl-cf-hmac-alt.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
Bugfix
|
||||
* Fix a regression introduced in 2.24.0 which broke (D)TLS CBC ciphersuites
|
||||
(when the encrypt-then-MAC extension is not in use) with some ALT
|
||||
implementations of the underlying hash (SHA-1, SHA-256, SHA-384), causing
|
||||
the affected side to wrongly reject valid messages. Fixes #4118.
|
4
ChangeLog.d/issue4083.txt
Normal file
4
ChangeLog.d/issue4083.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Removals
|
||||
* Remove the following functions: mbedtls_timing_self_test(),
|
||||
mbedtls_hardclock_poll(), mbedtls_timing_hardclock() and
|
||||
mbedtls_set_alarm(). Fixes #4083.
|
4
ChangeLog.d/issue4084.txt
Normal file
4
ChangeLog.d/issue4084.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Removals
|
||||
* Remove all support for MD2, MD4, RC4, Blowfish and XTEA. This removes the
|
||||
corresponding modules and all their APIs and related configuration
|
||||
options. Fixes #4084.
|
6
ChangeLog.d/issue4212.txt
Normal file
6
ChangeLog.d/issue4212.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
API changes
|
||||
* In modules that implement cryptographic hash functions, many functions
|
||||
mbedtls_xxx() now return int instead of void, and the corresponding
|
||||
function mbedtls_xxx_ret() which was identical except for returning int
|
||||
has been removed. This also concerns mbedtls_xxx_drbg_update(). See the
|
||||
migration guide for more information. Fixes #4212.
|
|
@ -1,11 +1,10 @@
|
|||
Removals
|
||||
* Remove the TLS 1.0, TLS 1.1 and DTLS 1.0 support by removing the following
|
||||
library constants: MBEDTLS_SSL_PROTO_TLS1,
|
||||
MBEDTLS_SSL_PROTO_TLS1_1, MBEDTLS_SSL_CBC_RECORD_SPLITTING,
|
||||
MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED,
|
||||
MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED,
|
||||
MBEDTLS_SSL_FALLBACK_SCSV, MBEDTLS_SSL_FALLBACK_SCSV_VALUE,
|
||||
MBEDTLS_SSL_IS_FALLBACK, MBEDTLS_SSL_IS_NOT_FALLBACK, and functions:
|
||||
* Remove support for TLS 1.0, TLS 1.1 and DTLS 1.0, as well as support for
|
||||
CBC record splitting, fallback SCSV, and the ability to configure
|
||||
ciphersuites per version, which are no longer relevant. This removes the
|
||||
configuration options MBEDTLS_SSL_PROTO_TLS1,
|
||||
MBEDTLS_SSL_PROTO_TLS1_1, MBEDTLS_SSL_CBC_RECORD_SPLITTING and
|
||||
MBEDTLS_SSL_FALLBACK_SCSV as well as the functions
|
||||
mbedtls_ssl_conf_cbc_record_splitting(),
|
||||
mbedtls_ssl_get_key_exchange_md_ssl_tls(), mbedtls_ssl_conf_fallback().
|
||||
Fixes #4286.
|
||||
mbedtls_ssl_get_key_exchange_md_ssl_tls(), mbedtls_ssl_conf_fallback(),
|
||||
and mbedtls_ssl_conf_ciphersuites_for_version(). Fixes #4286.
|
||||
|
|
4
ChangeLog.d/issue4313.txt
Normal file
4
ChangeLog.d/issue4313.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Removals
|
||||
* Remove the following macros: MBEDTLS_CHECK_PARAMS,
|
||||
MBEDTLS_CHECK_PARAMS_ASSERT, MBEDTLS_PARAM_FAILED,
|
||||
MBEDTLS_PARAM_FAILED_ALT. Fixes #4313.
|
4
ChangeLog.d/issue4378.txt
Normal file
4
ChangeLog.d/issue4378.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Removals
|
||||
* Remove the MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION config.h
|
||||
option. The mbedtls_x509_crt_parse_der_with_ext_cb() is the way to go for
|
||||
migration path. Fixes #4378.
|
3
ChangeLog.d/issue4398.txt
Normal file
3
ChangeLog.d/issue4398.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
API changes
|
||||
* Replace MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE by a runtime
|
||||
configuration function mbedtls_ssl_conf_preference_order(). Fixes #4398.
|
4
ChangeLog.d/issue4405.txt
Normal file
4
ChangeLog.d/issue4405.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Removals
|
||||
* Remove the MBEDTLS_X509_CHECK_KEY_USAGE and
|
||||
MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE config.h options and let the code
|
||||
behave as if they were always enabled. Fixes #4405.
|
14
ChangeLog.d/mandatory-rng-param.txt
Normal file
14
ChangeLog.d/mandatory-rng-param.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
API changes
|
||||
* For all functions that take a random number generator (RNG) as a
|
||||
parameter, this parameter is now mandatory (that is, NULL is not an
|
||||
acceptable value). Functions which previously accepted NULL and now
|
||||
reject it are: the X.509 CRT and CSR writing functions; the PK and RSA
|
||||
sign and decrypt function; mbedtls_rsa_private(); the functions
|
||||
in DHM and ECDH that compute the shared secret; the scalar multiplication
|
||||
functions in ECP.
|
||||
* The following functions now require an RNG parameter:
|
||||
mbedtls_ecp_check_pub_priv(), mbedtls_pk_check_pair(),
|
||||
mbedtls_pk_parse_key(), mbedtls_pk_parse_keyfile().
|
||||
Removals
|
||||
* The configuration option MBEDTLS_ECP_NO_INTERNAL_RNG has been removed as
|
||||
it no longer had any effect.
|
9
ChangeLog.d/max-record-payload-api.txt
Normal file
9
ChangeLog.d/max-record-payload-api.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
API changes
|
||||
* Remove the SSL APIs mbedtls_ssl_get_input_max_frag_len() and
|
||||
mbedtls_ssl_get_output_max_frag_len(), and add a new API
|
||||
mbedtls_ssl_get_max_in_record_payload(), complementing the existing
|
||||
mbedtls_ssl_get_max_out_record_payload().
|
||||
Uses of mbedtls_ssl_get_input_max_frag_len() and
|
||||
mbedtls_ssl_get_input_max_frag_len() should be replaced by
|
||||
mbedtls_ssl_get_max_in_record_payload() and
|
||||
mbedtls_ssl_get_max_out_record_payload(), respectively.
|
3
ChangeLog.d/mbed-can-do-timing.txt
Normal file
3
ChangeLog.d/mbed-can-do-timing.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Bugfix
|
||||
* Remove outdated check-config.h check that prevented implementing the
|
||||
timing module on Mbed OS. Fixes #4633.
|
3
ChangeLog.d/psa_key_derivation-bad_workflow.txt
Normal file
3
ChangeLog.d/psa_key_derivation-bad_workflow.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
Bugfix
|
||||
* Fix PSA_ALG_TLS12_PRF and PSA_ALG_TLS12_PSK_TO_MS being too permissive
|
||||
about missing inputs.
|
|
@ -6,4 +6,3 @@ API changes
|
|||
decryption functions now always use the private key and verification and
|
||||
encryption use the public key. Verification functions also no longer have
|
||||
RNG parameters.
|
||||
* The RNG is now mandatory for all private-key RSA operations.
|
||||
|
|
5
ChangeLog.d/rsa-padding.txt
Normal file
5
ChangeLog.d/rsa-padding.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
API changes
|
||||
* mbedtls_rsa_init() now always selects the PKCS#1v1.5 encoding for an RSA
|
||||
key. To use an RSA key with PSS or OAEP, call mbedtls_rsa_set_padding()
|
||||
after initializing the context. mbedtls_rsa_set_padding() now returns an
|
||||
error if its parameters are invalid.
|
4
ChangeLog.d/tool-versions.txt
Normal file
4
ChangeLog.d/tool-versions.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Requirement changes
|
||||
* Refresh the minimum supported versions of tools to build the
|
||||
library. CMake versions older than 3.10.2 and Python older
|
||||
than 3.6 are no longer supported.
|
4
ChangeLog.d/winsock.txt
Normal file
4
ChangeLog.d/winsock.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Bugfix
|
||||
* Fix mbedtls_net_poll() and mbedtls_net_recv_timeout() often failing with
|
||||
MBEDTLS_ERR_NET_POLL_FAILED on Windows. Fixes #4465.
|
||||
|
13
README.md
13
README.md
|
@ -26,7 +26,7 @@ Documentation for the Mbed TLS interfaces in the default library configuration i
|
|||
|
||||
To generate a local copy of the library documentation in HTML format, tailored to your compile-time configuration:
|
||||
|
||||
1. Make sure that [Doxygen](http://www.doxygen.nl/) is installed. We use version 1.8.11 but slightly older or more recent versions should work.
|
||||
1. Make sure that [Doxygen](http://www.doxygen.nl/) is installed.
|
||||
1. Run `make apidoc`.
|
||||
1. Browse `apidoc/index.html` or `apidoc/modules.html`.
|
||||
|
||||
|
@ -39,7 +39,7 @@ There are currently three active build systems used within Mbed TLS releases:
|
|||
|
||||
- GNU Make
|
||||
- CMake
|
||||
- Microsoft Visual Studio (Microsoft Visual Studio 2013 or later)
|
||||
- Microsoft Visual Studio
|
||||
|
||||
The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically.
|
||||
|
||||
|
@ -49,10 +49,13 @@ The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx
|
|||
|
||||
You need the following tools to build the library with the provided makefiles:
|
||||
|
||||
* GNU Make or a build tool that CMake supports.
|
||||
* A C99 toolchain (compiler, linker, archiver). We actively test with GCC 5.4, Clang 3.8, IAR8 and Visual Studio 2013. More recent versions should work. Slightly older versions may work.
|
||||
* Python 3 to generate the test code, and to generate sample programs in the development branch.
|
||||
* GNU Make 3.82 or a build tool that CMake supports.
|
||||
* A C99 toolchain (compiler, linker, archiver). We actively test with GCC 5.4, Clang 3.8, IAR 8 and Visual Studio 2013. More recent versions should work. Slightly older versions may work.
|
||||
* Python 3.6 to generate the test code, and to generate sample programs in the development branch.
|
||||
* Perl to run the tests, and to generate some source files in the development branch.
|
||||
* CMake 3.10.2 or later (if using CMake).
|
||||
* Microsoft Visual Studio 2013 or later (if using Visual Studio).
|
||||
* Doxygen 1.8.11 or later (if building the documentation; slightly older versions should work).
|
||||
|
||||
### Generated source files in the development branch
|
||||
|
||||
|
|
|
@ -49,8 +49,6 @@
|
|||
#define MBEDTLS_PKCS1_V21
|
||||
#define MBEDTLS_SELF_TEST
|
||||
#define MBEDTLS_VERSION_FEATURES
|
||||
#define MBEDTLS_X509_CHECK_KEY_USAGE
|
||||
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
|
||||
|
||||
/* mbed TLS modules */
|
||||
#define MBEDTLS_AES_C
|
||||
|
|
|
@ -84,8 +84,7 @@
|
|||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
/* Save RAM by adjusting to our exact needs */
|
||||
#define MBEDTLS_ECP_MAX_BITS 384
|
||||
#define MBEDTLS_MPI_MAX_SIZE 48 // 384 bits is 48 bytes
|
||||
#define MBEDTLS_MPI_MAX_SIZE 48 // 384-bit EC curve = 48 bytes
|
||||
|
||||
/* Save RAM at the expense of speed, see ecp.h */
|
||||
#define MBEDTLS_ECP_WINDOW_SIZE 2
|
||||
|
|
|
@ -47,11 +47,9 @@
|
|||
|
||||
/* Mbed Crypto modules */
|
||||
#define MBEDTLS_AES_C
|
||||
#define MBEDTLS_ARC4_C
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_ASN1_WRITE_C
|
||||
#define MBEDTLS_BASE64_C
|
||||
#define MBEDTLS_BLOWFISH_C
|
||||
#define MBEDTLS_CAMELLIA_C
|
||||
#define MBEDTLS_ARIA_C
|
||||
#define MBEDTLS_CCM_C
|
||||
|
@ -68,8 +66,6 @@
|
|||
#define MBEDTLS_HMAC_DRBG_C
|
||||
#define MBEDTLS_NIST_KW_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_MD2_C
|
||||
#define MBEDTLS_MD4_C
|
||||
#define MBEDTLS_MD5_C
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PEM_PARSE_C
|
||||
|
@ -94,7 +90,6 @@
|
|||
//#define MBEDTLS_THREADING_C
|
||||
#define MBEDTLS_TIMING_C
|
||||
#define MBEDTLS_VERSION_C
|
||||
#define MBEDTLS_XTEA_C
|
||||
|
||||
#include "mbedtls/config_psa.h"
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@
|
|||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
/* Save RAM by adjusting to our exact needs */
|
||||
#define MBEDTLS_ECP_MAX_BITS 256
|
||||
#define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes
|
||||
#define MBEDTLS_MPI_MAX_SIZE 32 // 256-bit EC curve = 32 bytes
|
||||
|
||||
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */
|
||||
#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
|
||||
|
|
40
docs/3.0-migration-guide.d/mandatory-rng-param.md
Normal file
40
docs/3.0-migration-guide.d/mandatory-rng-param.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
The RNG parameter is now mandatory for all functions that accept one
|
||||
--------------------------------------------------------------------
|
||||
|
||||
This change affects all users who called a function accepting a `f_rng`
|
||||
parameter with `NULL` as the value of this argument; this is no longer
|
||||
supported.
|
||||
|
||||
The changed functions are: the X.509 CRT and CSR writing functions; the PK and
|
||||
RSA sign and decrypt functions; `mbedtls_rsa_private()`; the functions in DHM
|
||||
and ECDH that compute the shared secret; the scalar multiplication functions in
|
||||
ECP.
|
||||
|
||||
You now need to pass a properly seeded, cryptographically secure RNG to all
|
||||
functions that accept a `f_rng` parameter. It is of course still possible to
|
||||
pass `NULL` as the context pointer `p_rng` if your RNG function doesn't need a
|
||||
context.
|
||||
|
||||
Alternative implementations of a module (enabled with the `MBEDTLS_module_ALT`
|
||||
configuration options) may have their own internal and are free to ignore the
|
||||
`f_rng` argument but must allow users to pass one anyway.
|
||||
|
||||
Some functions gained an RNG parameter
|
||||
--------------------------------------
|
||||
|
||||
This affects users of the following functions: `mbedtls_ecp_check_pub_priv()`,
|
||||
`mbedtls_pk_check_pair()`, `mbedtls_pk_parse_key()`, and
|
||||
`mbedtls_pk_parse_keyfile()`.
|
||||
|
||||
You now need to pass a properly seeded, cryptographically secure RNG when
|
||||
calling these functions. It is used for blinding, a counter-measure against
|
||||
side-channel attacks.
|
||||
|
||||
The configuration option `MBEDTLS_ECP_NO_INTERNAL_RNG` was removed
|
||||
------------------------------------------------------------------
|
||||
|
||||
This doesn't affect users of the default configuration; it only affects people
|
||||
who were explicitly setting this option.
|
||||
|
||||
This was a trade-off between code size and counter-measures; it is no longer
|
||||
relevant as the counter-measure is now always on at no cost in code size.
|
11
docs/3.0-migration-guide.d/max-record-payload-api.md
Normal file
11
docs/3.0-migration-guide.d/max-record-payload-api.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Remove MaximumFragmentLength (MFL) query API
|
||||
-----------------------------------------------------------------
|
||||
|
||||
This affects users which use the MFL query APIs
|
||||
`mbedtls_ssl_get_{input,output}_max_frag_len()` to
|
||||
infer upper bounds on the plaintext size of incoming and
|
||||
outgoing record.
|
||||
|
||||
Users should switch to `mbedtls_ssl_get_max_{in,out}_record_payload()`
|
||||
instead, which also provides such upper bounds but takes more factors
|
||||
than just the MFL configuration into account.
|
|
@ -0,0 +1,9 @@
|
|||
Move part of timing module out of the library
|
||||
--
|
||||
|
||||
The change affects users who use any of the following functions:
|
||||
`mbedtls_timing_self_test()`, `mbedtls_hardclock_poll()`,
|
||||
`mbedtls_timing_hardclock()` and `mbedtls_set_alarm()`.
|
||||
|
||||
If you were relying on these functions, you'll now need to change to using your
|
||||
platform's corresponding functions directly.
|
|
@ -19,11 +19,3 @@ RSA verification functions also no longer take random generator arguments (this
|
|||
was only needed when using a private key). This affects all applications using
|
||||
the RSA verify functions.
|
||||
|
||||
RNG is now mandatory in all RSA private key operations
|
||||
------------------------------------------------------
|
||||
|
||||
The random generator is now mandatory for blinding in all RSA private-key
|
||||
operations (`mbedtls_rsa_private`, `mbedtls_rsa_xxx_sign`,
|
||||
`mbedtls_rsa_xxx_decrypt`) as well as for encryption
|
||||
(`mbedtls_rsa_xxx_encrypt`). This means that passing a null `f_rng` is no longer
|
||||
supported.
|
||||
|
|
23
docs/3.0-migration-guide.d/remove-ssl-get-session_pointer.md
Normal file
23
docs/3.0-migration-guide.d/remove-ssl-get-session_pointer.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
Remove the SSL API mbedtls_ssl_get_session_pointer()
|
||||
-----------------------------------------------------------------
|
||||
|
||||
This affects two classes of users:
|
||||
|
||||
1. Users who manually inspect parts of the current session through
|
||||
direct structure field access.
|
||||
|
||||
2. Users of session resumption who query the current session
|
||||
via `mbedtls_ssl_get_session_pointer()` prior to saving or exporting
|
||||
it via `mbedtls_ssl_session_copy()` or `mbedtls_ssl_session_save()`,
|
||||
respectively.
|
||||
|
||||
Migration paths:
|
||||
|
||||
1. Mbed TLS 3.0 does not offer a migration path for the usecase 1: Like many
|
||||
other Mbed TLS structures, the structure of `mbedtls_ssl_session` is no
|
||||
longer part of the public API in Mbed TLS 3.0, and direct structure field
|
||||
access is no longer supported. Please see the corresponding migration guide.
|
||||
|
||||
2. Users should replace calls to `mbedtls_ssl_get_session_pointer()` by
|
||||
calls to `mbedtls_ssl_get_session()` as demonstrated in the example
|
||||
program `programs/ssl/ssl_client2.c`.
|
|
@ -0,0 +1,17 @@
|
|||
Remove the config option MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
This change does not affect users of the default configuration; it only affect
|
||||
users who enable this option.
|
||||
|
||||
The X.509 standard says that implementations must reject critical extensions that
|
||||
they don't recognize, and this is what Mbed TLS does by default. This option
|
||||
allowed to continue parsing those certificates but didn't provide a convenient
|
||||
way to handle those extensions.
|
||||
|
||||
The migration path from that option is to use the
|
||||
`mbedtls_x509_crt_parse_der_with_ext_cb()` function which is functionally
|
||||
equivalent to `mbedtls_x509_crt_parse_der()`, and/or
|
||||
`mbedtls_x509_crt_parse_der_nocopy()` but it calls the callback with every
|
||||
unsupported certificate extension and additionally the "certificate policies"
|
||||
extension if it contains any unsupported certificate policies.
|
|
@ -0,0 +1,18 @@
|
|||
Remove `MBEDTLS_X509_CHECK_*_KEY_USAGE` options from `config.h`
|
||||
-------------------------------------------------------------------
|
||||
|
||||
This change affects users who have chosen the configuration options to disable the
|
||||
library's verification of the `keyUsage` and `extendedKeyUsage` fields of x509
|
||||
certificates.
|
||||
|
||||
The `MBEDTLS_X509_CHECK_KEY_USAGE` and `MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE`
|
||||
configuration options are removed and the X509 code now behaves as if they were
|
||||
always enabled. It is consequently not possible anymore to disable at compile
|
||||
time the verification of the `keyUsage` and `extendedKeyUsage` fields of X509
|
||||
certificates.
|
||||
|
||||
The verification of the `keyUsage` and `extendedKeyUsage` fields is important,
|
||||
disabling it can cause security issues and it is thus not recommended. If the
|
||||
verification is for some reason undesirable, it can still be disabled by means
|
||||
of the verification callback function passed to `mbedtls_x509_crt_verify()` (see
|
||||
the documentation of this function for more information).
|
|
@ -0,0 +1,8 @@
|
|||
Remove MD2, MD4, RC4, Blowfish and XTEA algorithms
|
||||
--
|
||||
|
||||
This change affects users of the MD2, MD4, RC4, Blowfish and XTEA algorithms.
|
||||
|
||||
They are already niche or obsolete and most of them are weak or broken. For
|
||||
those reasons possible users should consider switching to modern and safe
|
||||
alternatives to be found in literature.
|
|
@ -50,7 +50,9 @@ 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.
|
||||
`mbedtls_ssl_get_max_out_record_payload()` and
|
||||
`mbedtls_ssl_get_max_in_record_payload()`
|
||||
instead.
|
||||
|
||||
Deprecated hex-encoded primes were removed from DHM
|
||||
---------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
Remove MBEDTLS_CHECK_PARAMS option
|
||||
----------------------------------
|
||||
|
||||
This change does not affect users who use the default configuration; it only
|
||||
affects users who enabled that option.
|
||||
|
||||
The option `MBEDTLS_CHECK_PARAMS` (disabled by default) enabled certain kinds
|
||||
of “parameter validation”. It covered two kinds of validations:
|
||||
|
||||
- In some functions that require a valid pointer, “parameter validation” checks
|
||||
that the pointer is non-null. With the feature disabled, a null pointer is not
|
||||
treated differently from any other invalid pointer, and typically leads to a
|
||||
runtime crash. 90% of the uses of the feature are of this kind.
|
||||
- In some functions that take an enum-like argument, “parameter validation”
|
||||
checks that the value is a valid one. With the feature disabled, an invalid
|
||||
value causes a silent default to one of the valid values.
|
||||
|
||||
The default reaction to a failed check was to call a function
|
||||
`mbedtls_param_failed()` which the application had to provide. If this function
|
||||
returned, its caller returned an error `MBEDTLS_ERR_xxx_BAD_INPUT_DATA`.
|
||||
|
||||
This feature was only used in some classic (non-PSA) cryptography modules. It was
|
||||
not used in X.509, TLS or in PSA crypto, and it was not implemented in all
|
||||
classic crypto modules.
|
||||
|
||||
This feature has been removed. The library no longer checks for NULL pointers;
|
||||
checks for enum-like arguments will be kept or re-introduced on a case-by-case
|
||||
basis, but their presence will no longer be dependent on a compile-time option.
|
||||
|
||||
Validation of enum-like values is somewhat useful, but not extremely important,
|
||||
because the parameters concerned are usually constants in applications.
|
||||
|
||||
For more information see issue #4313.
|
|
@ -3,9 +3,25 @@ Remove suport for TLS 1.0, 1.1 and DTLS 1.0
|
|||
|
||||
This change affects users of the TLS 1.0, 1.1 and DTLS 1.0 protocols.
|
||||
|
||||
The versions of (D)TLS that are being removed are not as secure as the latest
|
||||
versions. Keeping them in the library creates opportunities for misconfiguration
|
||||
These versions have been deprecated by RFC 8996.
|
||||
Keeping them in the library creates opportunities for misconfiguration
|
||||
and possibly downgrade attacks. More generally, more code means a larger attack
|
||||
surface, even if the code is supposedly not used.
|
||||
|
||||
The migration path is to adopt the latest versions of the protocol.
|
||||
|
||||
As a consequence of removing TLS 1.0, support for CBC record splitting was
|
||||
also removed, as it was a work-around for a weakness in this particular
|
||||
version. There is no migration path since the feature is no longer relevant.
|
||||
|
||||
As a consequence of currently supporting only one version of (D)TLS (and in the
|
||||
future 1.3 which will have a different version negociation mechanism), support
|
||||
for fallback SCSV (RFC 7507) was also removed. There is no migration path as
|
||||
it's no longer useful with TLS 1.2 and later.
|
||||
|
||||
As a consequence of currently supporting only one version of (D)TLS (and in the
|
||||
future 1.3 which will have a different concept of ciphersuites), support for
|
||||
configuring ciphersuites separately for each version via
|
||||
`mbedtls_ssl_conf_ciphersuites_for_version()` was removed. Use
|
||||
`mbedtls_ssl_conf_ciphersuites()` to configure ciphersuites to use with (D)TLS
|
||||
1.2; in the future a different API will be added for (D)TLS 1.3.
|
||||
|
|
43
docs/3.0-migration-guide.d/rename_the__ret_functions.md
Normal file
43
docs/3.0-migration-guide.d/rename_the__ret_functions.md
Normal file
|
@ -0,0 +1,43 @@
|
|||
Rename mbedtls_*_ret() cryptography functions whose deprecated variants
|
||||
have been removed
|
||||
-----------------
|
||||
|
||||
This change affects users who were using the `mbedtls_*_ret()` cryptography
|
||||
functions.
|
||||
|
||||
Those functions were created based on now-deprecated functions according to a
|
||||
requirement that a function needs to return a value. This change brings back the
|
||||
original names of those functions. The renamed functions are:
|
||||
|
||||
| name before this change | after the change |
|
||||
|------------------------------|--------------------------|
|
||||
| mbedtls_ctr_drbg_update_ret | mbedtls_ctr_drbg_update |
|
||||
| mbedtls_hmac_drbg_update_ret | mbedtls_hmac_drbg_update |
|
||||
| mbedtls_md5_starts_ret | mbedtls_md5_starts |
|
||||
| mbedtls_md5_update_ret | mbedtls_md5_update |
|
||||
| mbedtls_md5_finish_ret | mbedtls_md5_finish |
|
||||
| mbedtls_md5_ret | mbedtls_md5 |
|
||||
| mbedtls_ripemd160_starts_ret | mbedtls_ripemd160_starts |
|
||||
| mbedtls_ripemd160_update_ret | mbedtls_ripemd160_update |
|
||||
| mbedtls_ripemd160_finish_ret | mbedtls_ripemd160_finish |
|
||||
| mbedtls_ripemd160_ret | mbedtls_ripemd160 |
|
||||
| mbedtls_sha1_starts_ret | mbedtls_sha1_starts |
|
||||
| mbedtls_sha1_update_ret | mbedtls_sha1_update |
|
||||
| mbedtls_sha1_finish_ret | mbedtls_sha1_finish |
|
||||
| mbedtls_sha1_ret | mbedtls_sha1 |
|
||||
| mbedtls_sha256_starts_ret | mbedtls_sha256_starts |
|
||||
| mbedtls_sha256_update_ret | mbedtls_sha256_update |
|
||||
| mbedtls_sha256_finish_ret | mbedtls_sha256_finish |
|
||||
| mbedtls_sha256_ret | mbedtls_sha256 |
|
||||
| mbedtls_sha512_starts_ret | mbedtls_sha512_starts |
|
||||
| mbedtls_sha512_update_ret | mbedtls_sha512_update |
|
||||
| mbedtls_sha512_finish_ret | mbedtls_sha512_finish |
|
||||
| mbedtls_sha512_ret | mbedtls_sha512 |
|
||||
|
||||
To migrate to the this change the user can keep the `*_ret` names in their code
|
||||
and include the `compat_2.x.h` header file which holds macros with proper
|
||||
renaming or to rename those function in their code according to the list from
|
||||
mentioned header file.
|
||||
|
||||
|
||||
|
29
docs/3.0-migration-guide.d/rsa-padding.md
Normal file
29
docs/3.0-migration-guide.d/rsa-padding.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
Remove the padding parameters from mbedtls_rsa_init()
|
||||
-----------------------------------------------------
|
||||
|
||||
This affects all users who use the RSA encryption, decryption, sign and
|
||||
verify APIs.
|
||||
|
||||
The function mbedtls_rsa_init() no longer supports selecting the PKCS#1 v2.1
|
||||
encoding and its hash. It just selects the PKCS#1 v1.5 encoding by default. If
|
||||
you were using the PKCS#1 v2.1 encoding you now need, subsequently to the call
|
||||
to mbedtls_rsa_init(), to call mbedtls_rsa_set_padding() to set it.
|
||||
|
||||
To choose the padding type when initializing a context, instead of
|
||||
```C
|
||||
mbedtls_rsa_init(ctx, padding, hash_id);
|
||||
```
|
||||
, use
|
||||
```C
|
||||
mbedtls_rsa_init(ctx);
|
||||
mbedtls_rsa_set_padding(ctx, padding, hash_id);
|
||||
```
|
||||
|
||||
To use PKCS#1 v1.5 padding, instead of
|
||||
```C
|
||||
mbedtls_rsa_init(ctx, MBEDTLS_RSA_PKCS_V15, <ignored>);
|
||||
```
|
||||
, just use
|
||||
```C
|
||||
mbedtls_rsa_init(ctx);
|
||||
```
|
30
docs/3.0-migration-guide.d/ssl-ticket-api.md
Normal file
30
docs/3.0-migration-guide.d/ssl-ticket-api.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
Modified semantics of mbedtls_ssl_{get,set}_session()
|
||||
-----------------------------------------------------------------
|
||||
|
||||
This affects users who call `mbedtls_ssl_get_session()` or
|
||||
`mbedtls_ssl_set_session()` multiple times on the same SSL context
|
||||
representing an established TLS 1.2 connection.
|
||||
Those users will now observe the second call to fail with
|
||||
`MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`.
|
||||
|
||||
Migration path:
|
||||
- Exporting the same TLS 1.2 connection multiple times via
|
||||
`mbedtls_ssl_get_session()` leads to multiple copies of
|
||||
the same session. This use of `mbedtls_ssl_get_session()`
|
||||
is discouraged, and the following should be considered:
|
||||
* If the various session copies are later loaded into
|
||||
fresh SSL contexts via `mbedtls_ssl_set_session()`,
|
||||
export via `mbedtls_ssl_get_session()` only once and
|
||||
load the same session into different contexts via
|
||||
`mbedtls_ssl_set_session()`. Since `mbedtls_ssl_set_session()`
|
||||
makes a copy of the session that's being loaded, this
|
||||
is functionally equivalent.
|
||||
* If the various session copies are later serialized
|
||||
via `mbedtls_ssl_session_save()`, export and serialize
|
||||
the session only once via `mbedtls_ssl_get_session()` and
|
||||
`mbedtls_ssl_session_save()` and make copies of the raw
|
||||
data instead.
|
||||
- Calling `mbedtls_ssl_set_session()` multiple times in Mbed TLS 2.x
|
||||
is not useful since subsequent calls overwrite the effect of previous
|
||||
calls. Applications achieve equivalent functional behaviour by
|
||||
issuing only the very last call to `mbedtls_ssl_set_session()`.
|
|
@ -0,0 +1,14 @@
|
|||
Turn MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE configuration option into a runtime option
|
||||
--
|
||||
|
||||
This change affects users who were enabling MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
|
||||
option in the `config.h`
|
||||
|
||||
This option has been removed and a new function with similar functionality has
|
||||
been introduced into the SSL API.
|
||||
|
||||
This new function `mbedtls_ssl_conf_preference_order()` can be used to
|
||||
change the preferred order of ciphersuites on the server to those used on the client,
|
||||
e.g.: `mbedtls_ssl_conf_preference_order(ssl_config, MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT)`
|
||||
has the same effect as enabling the removed option. The default state is to use
|
||||
the server order of suites.
|
|
@ -22,7 +22,7 @@ in order to match the new signature.
|
|||
Deprecated functions were removed from hashing modules
|
||||
------------------------------------------------------
|
||||
|
||||
Modules: MD2, MD4, MD5, SHA1, SHA256, SHA512, MD.
|
||||
Modules: MD5, SHA1, SHA256, SHA512, MD.
|
||||
|
||||
- The functions `mbedtls_xxx_starts()`, `mbedtls_xxx_update()`,
|
||||
`mbedtls_xxx_finish()` and `mbedtls_xxx()` were removed. Please use the
|
||||
|
@ -59,7 +59,7 @@ 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.
|
||||
renamed to `ecp_internal_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
|
||||
|
|
91
docs/architecture/alternative-implementations.md
Normal file
91
docs/architecture/alternative-implementations.md
Normal file
|
@ -0,0 +1,91 @@
|
|||
Alternative implementations of Mbed TLS functionality
|
||||
=====================================================
|
||||
|
||||
This document describes how parts of the Mbed TLS functionality can be replaced at compile time to integrate the library on a platform.
|
||||
|
||||
This document is an overview. It is not exhaustive. Please consult the documentation of individual modules and read the library header files for more details.
|
||||
|
||||
## Platform integration
|
||||
|
||||
Mbed TLS works out of the box on Unix/Linux/POSIX-like systems and on Windows. On embedded platforms, you may need to customize some aspects of how Mbed TLS interacts with the underlying platform. This section discusses the main areas that can be configured.
|
||||
|
||||
The platform module (`include/mbedtls/platform.h`) controls how Mbed TLS accesses standard library features such as memory management (`calloc`, `free`), `printf`, `exit`. You can define custom functions instead of the ones from the C standard library through `MBEDTLS_PLATFORM_XXX` options in the configuration file. Many options have two mechanisms: either define `MBEDTLS_PLATFORM_XXX_MACRO` to the name of a function to call instead of the standard function `xxx`, or define `MBEDTLS_PLATFORM_XXX_ALT` and [register an alternative implementation during the platform setup](#alternative-implementations-of-platform-functions).
|
||||
|
||||
The storage of the non-volatile seed for random generation, enabled with `MBEDTLS_ENTROPY_NV_SEED`, is also controlled via the platform module.
|
||||
|
||||
For timing functions, you can [declare an alternative implementation of the timing module](#module-alternative-implementations).
|
||||
|
||||
On multithreaded platforms, [declare an alternative implementation of the threading module](#module-alternative-implementations).
|
||||
|
||||
To configure entropy sources (hardware random generators), see the `MBEDTLS_ENTROPY_XXX` options in the configuration file.
|
||||
|
||||
For networking, the `net_sockets` module does not currently support alternative implementations. If this module does not work on your platform, disable `MBEDTLS_NET_C` and use custom functions for TLS.
|
||||
|
||||
If your platform has a cryptographic accelerator, you can use it via a [PSA driver](#psa-cryptography-drivers) or declare an [alternative implementation of the corresponding module(s)](#module-alternative-implementations) or [of specific functions](#function-alternative-implementations). PSA drivers will ultimately replace the alternative implementation mechanism, but alternative implementation will remain supported in at least all Mbed TLS versions of the form 3.x. The interface of PSA drivers is currently still experimental and subject to change.
|
||||
|
||||
## PSA cryptography drivers
|
||||
|
||||
On platforms where a hardware cryptographic engine is present, you can implement a driver for this engine in the PSA interface. Drivers are supported for cryptographic operations with transparent keys (keys available in cleartext), for cryptographic operations with opaque keys (keys that are only available inside the cryptographic engine), and for random generation. Calls to `psa_xxx` functions that perform cryptographic operations are directed to drivers instead of the built-in code as applicable. See the [PSA cryptography driver interface specification](docs/proposed/psa-driver-interface.md), the [Mbed TLS PSA driver developer guide](docs/proposed/psa-driver-developer-guide.md) and the [Mbed TLS PSA driver integration guide](docs/proposed/psa-driver-integration-guide.md) for more information.
|
||||
|
||||
As of Mbed TLS 3.0, this interface is still experimental and subject to change, and not all operations support drivers yet. The configuration option `MBEDTLS_USE_PSA_CRYPTO` causes parts of the `mbedtls_xxx` API to use PSA crypto and therefore to support drivers, however it is not yet compatible with all drivers.
|
||||
|
||||
## Module alternative implementations
|
||||
|
||||
You can replace the code of some modules of Mbed TLS at compile time by a custom implementation. This is possible for low-level cryptography modules (symmetric algorithms, DHM, RSA, ECP, ECJPAKE) and for some platform-related modules (threading, timing). Such custom implementations are called “alternative implementations”, or “ALT implementations” for short.
|
||||
|
||||
The general principle of an alternative implementation is:
|
||||
* Enable `MBEDTLS_XXX_ALT` in the compile-time configuration where XXX is the module name. For example, `MBEDTLS_AES_ALT` for an implementation of the AES module. This is in addition to enabling `MBEDTLS_XXX_C`.
|
||||
* Create a header file `xxx_alt.h` that defines the context type(s) used by the module. For example, `mbedtls_aes_context` for AES.
|
||||
* Implement all the functions from the module, i.e. the functions declared in `include/mbedtls/xxx.h`.
|
||||
|
||||
See https://tls.mbed.org/kb/development/hw_acc_guidelines for a more detailed guide.
|
||||
|
||||
### Constraints on context types
|
||||
|
||||
Generally, alternative implementations can define their context types to any C type except incomplete and array types (although they would normally be `struct` types). This section lists some known limitations where the context type needs to be a structure with certain fields.
|
||||
|
||||
Where a context type needs to have a certain field, the field must have the same type and semantics as in the built-in implementation, but does not need to be at the same position in the structure. Furthermore, unless otherwise indicated, only read access is necessary: the field can be `const`, and modifications to it do not need to be supported. For example, if an alternative implementation of asymmetric cryptography uses a different representation of large integers, it is sufficient to provide a read-only copy of the fields listed here of type `mbedtls_mpi`.
|
||||
|
||||
* AES: if `MBEDTLS_AESNI_C` or `MBEDTLS_PADLOCK_C` is enabled, `mbedtls_aes_context` must have the fields `nr` and `rk`.
|
||||
* DHM: if `MBEDTLS_DEBUG_C` is enabled, `mbedtls_dhm_context` must have the fields `P`, `Q`, `G`, `GX`, `GY` and `K`.
|
||||
* ECP: `mbedtls_ecp_group` must have the fields `id`, `P`, `A`, `B`, `G`, `N`, `pbits` and `nbits`.
|
||||
* If `MBEDTLS_PK_PARSE_EC_EXTENDED` is enabled, those fields must be writable, and `mbedtls_ecp_point_read_binary()` must support a group structure where only `P`, `pbits`, `A` and `B` are set.
|
||||
|
||||
It must be possible to move a context object in memory (except during the execution of a library function that takes this context as an argument). (This is necessary, for example, to support applications that populate a context on the stack of an inner function and then copy the context upwards through the call chain, or applications written in a language with automatic memory management that can move objects on the heap.) That is, call sequences like the following must work:
|
||||
```
|
||||
mbedtls_xxx_context ctx1, ctx2;
|
||||
mbedtls_xxx_init(&ctx1);
|
||||
mbedtls_xxx_setup(&ctx1, …);
|
||||
ctx2 = ctx1;
|
||||
memset(&ctx1, 0, sizeof(ctx1));
|
||||
mbedtls_xxx_do_stuff(&ctx2, …);
|
||||
mbedtls_xxx_free(&ctx2);
|
||||
```
|
||||
In practice, this means that a pointer to a context or to a part of a context does not remain valid across function calls. Alternative implementations do not need to support copying of contexts: contexts can only be cloned through explicit `clone()` functions.
|
||||
|
||||
## Function alternative implementations
|
||||
|
||||
In some cases, it is possible to replace a single function or a small set of functions instead of [providing an alternative implementation of the whole module](#module-alternative-implementations).
|
||||
|
||||
### Alternative implementations of cryptographic functions
|
||||
|
||||
Options to replace individual functions of cryptographic modules generally have a name obtained by upper-casing the function name and appending `_ALT`. If the function name contains `_internal`, `_ext` or `_ret`, this is removed in the `_ALT` symbol. When the corresponding option is enabled, the built-in implementation of the function will not be compiled, and you must provide an alternative implementation at link time.
|
||||
|
||||
For example, enable `MBEDTLS_AES_ENCRYPT_ALT` at compile time and provide your own implementation of `mbedtls_aes_encrypt()` to provide an accelerated implementation of AES encryption that is compatible with the built-in key schedule. If you wish to implement key schedule differently, you can also enable `MBEDTLS_AES_SETKEY_ENC_ALT` and implement `mbedtls_aes_setkey_enc()`.
|
||||
|
||||
Another example: enable `MBEDTLS_SHA256_PROCESS_ALT` and implement `mbedtls_internal_sha256_process()` to provide an accelerated implementation of SHA-256 and SHA-224.
|
||||
|
||||
Note that since alternative implementations of individual functions cooperate with the built-in implementation of other functions, you must use the same layout for context objects as the built-in implementation. If you want to use different context types, you need to [provide an alternative implementation of the whole module](#module-alternative-implementations).
|
||||
|
||||
### Alternative implementations of platform functions
|
||||
|
||||
Several platform functions can be reconfigured dynamically by following the process described here. To reconfigure how Mbed TLS calls the standard library function `xxx()`:
|
||||
|
||||
* Define the symbol `MBEDTLS_PLATFORM_XXX_ALT` at compile time.
|
||||
* During the initialization of your application, set the global variable `mbedtls_xxx` to an alternative implementation of `xxx()`.
|
||||
|
||||
For example, to provide a custom `printf` function at run time, enable `MBEDTLS_PLATFORM_PRINTF_ALT` at compile time and assign to `mbedtls_printf` during the initialization of your application.
|
||||
|
||||
Merely enabling `MBEDTLS_PLATFORM_XXX_ALT` does not change the behavior: by default, `mbedtls_xxx` points to the standard function `xxx`.
|
||||
|
||||
Note that there are variations on the naming pattern. For example, some configurable functions are activated in pairs, such as `mbedtls_calloc` and `mbedtls_free` via `MBEDTLS_PLATFORM_MEMORY`. Consult the documentation of individual configuration options and of the platform module for details.
|
|
@ -45,15 +45,11 @@
|
|||
* - Symmetric:
|
||||
* - AES (see \c mbedtls_aes_crypt_ecb(), \c mbedtls_aes_crypt_cbc(), \c mbedtls_aes_crypt_cfb128() and
|
||||
* \c mbedtls_aes_crypt_ctr()).
|
||||
* - ARCFOUR (see \c mbedtls_arc4_crypt()).
|
||||
* - Blowfish / BF (see \c mbedtls_blowfish_crypt_ecb(), \c mbedtls_blowfish_crypt_cbc(),
|
||||
* \c mbedtls_blowfish_crypt_cfb64() and \c mbedtls_blowfish_crypt_ctr())
|
||||
* - Camellia (see \c mbedtls_camellia_crypt_ecb(), \c mbedtls_camellia_crypt_cbc(),
|
||||
* \c mbedtls_camellia_crypt_cfb128() and \c mbedtls_camellia_crypt_ctr()).
|
||||
* - DES/3DES (see \c mbedtls_des_crypt_ecb(), \c mbedtls_des_crypt_cbc(), \c mbedtls_des3_crypt_ecb()
|
||||
* and \c mbedtls_des3_crypt_cbc()).
|
||||
* - GCM (AES-GCM and CAMELLIA-GCM) (see \c mbedtls_gcm_init())
|
||||
* - XTEA (see \c mbedtls_xtea_crypt_ecb()).
|
||||
* - Asymmetric:
|
||||
* - Diffie-Hellman-Merkle (see \c mbedtls_dhm_read_public(), \c mbedtls_dhm_make_public()
|
||||
* and \c mbedtls_dhm_calc_secret()).
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
* \c mbedtls_md_setup())
|
||||
*
|
||||
* The following hashing-algorithms are provided:
|
||||
* - MD2, MD4, MD5 128-bit one-way hash functions by Ron Rivest.
|
||||
* - MD5 128-bit one-way hash function by Ron Rivest.
|
||||
* - SHA-1, SHA-256, SHA-384/512 160-bit or more one-way hash functions by
|
||||
* NIST and NSA.
|
||||
*
|
||||
|
|
|
@ -1577,13 +1577,13 @@ ENABLE_PREPROCESSING = YES
|
|||
# compilation will be performed. Macro expansion can be done in a controlled
|
||||
# way by setting EXPAND_ONLY_PREDEF to YES.
|
||||
|
||||
MACRO_EXPANSION = NO
|
||||
MACRO_EXPANSION = YES
|
||||
|
||||
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
|
||||
# then the macro expansion is limited to the macros specified with the
|
||||
# PREDEFINED and EXPAND_AS_DEFINED tags.
|
||||
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
EXPAND_ONLY_PREDEF = YES
|
||||
|
||||
# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
|
||||
# pointed to by INCLUDE_PATH will be searched when a #include is found.
|
||||
|
@ -1630,7 +1630,7 @@ PREDEFINED = WIN32 \
|
|||
# Use the PREDEFINED tag if you want to use a different macro definition that
|
||||
# overrules the definition found in the source code.
|
||||
|
||||
EXPAND_AS_DEFINED =
|
||||
EXPAND_AS_DEFINED = MBEDTLS_PRIVATE
|
||||
|
||||
# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
|
||||
# doxygen's preprocessor will remove all references to function-like macros
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#ifndef MBEDTLS_AES_H
|
||||
#define MBEDTLS_AES_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -78,9 +79,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_aes_context
|
||||
{
|
||||
int nr; /*!< The number of rounds. */
|
||||
uint32_t *rk; /*!< AES round keys. */
|
||||
uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
|
||||
int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */
|
||||
uint32_t *MBEDTLS_PRIVATE(rk); /*!< AES round keys. */
|
||||
uint32_t MBEDTLS_PRIVATE(buf)[68]; /*!< Unaligned data buffer. This buffer can
|
||||
hold 32 extra Bytes, which can be used for
|
||||
one of the following purposes:
|
||||
<ul><li>Alignment if VIA padlock is
|
||||
|
@ -97,9 +98,9 @@ mbedtls_aes_context;
|
|||
*/
|
||||
typedef struct mbedtls_aes_xts_context
|
||||
{
|
||||
mbedtls_aes_context crypt; /*!< The AES context to use for AES block
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(crypt); /*!< The AES context to use for AES block
|
||||
encryption or decryption. */
|
||||
mbedtls_aes_context tweak; /*!< The AES context used for tweak
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(tweak); /*!< The AES context used for tweak
|
||||
computation. */
|
||||
} mbedtls_aes_xts_context;
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
/**
|
||||
* \file arc4.h
|
||||
*
|
||||
* \brief The ARCFOUR stream cipher
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers instead.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef MBEDTLS_ARC4_H
|
||||
#define MBEDTLS_ARC4_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_ARC4_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief ARC4 context structure
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers instead.
|
||||
*
|
||||
*/
|
||||
typedef struct mbedtls_arc4_context
|
||||
{
|
||||
int x; /*!< permutation index */
|
||||
int y; /*!< permutation index */
|
||||
unsigned char m[256]; /*!< permutation table */
|
||||
}
|
||||
mbedtls_arc4_context;
|
||||
|
||||
#else /* MBEDTLS_ARC4_ALT */
|
||||
#include "arc4_alt.h"
|
||||
#endif /* MBEDTLS_ARC4_ALT */
|
||||
|
||||
/**
|
||||
* \brief Initialize ARC4 context
|
||||
*
|
||||
* \param ctx ARC4 context to be initialized
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear ARC4 context
|
||||
*
|
||||
* \param ctx ARC4 context to be cleared
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief ARC4 key schedule
|
||||
*
|
||||
* \param ctx ARC4 context to be setup
|
||||
* \param key the secret key
|
||||
* \param keylen length of the key, in bytes
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
|
||||
unsigned int keylen );
|
||||
|
||||
/**
|
||||
* \brief ARC4 cipher function
|
||||
*
|
||||
* \param ctx ARC4 context
|
||||
* \param length length of the input data
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer for the output data
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
|
||||
unsigned char *output );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_arc4_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* arc4.h */
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#ifndef MBEDTLS_ARIA_H
|
||||
#define MBEDTLS_ARIA_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -64,9 +65,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_aria_context
|
||||
{
|
||||
unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
|
||||
unsigned char MBEDTLS_PRIVATE(nr); /*!< The number of rounds (12, 14 or 16) */
|
||||
/*! The ARIA round keys. */
|
||||
uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
|
||||
uint32_t MBEDTLS_PRIVATE(rk)[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
|
||||
}
|
||||
mbedtls_aria_context;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_ASN1_H
|
||||
#define MBEDTLS_ASN1_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -148,9 +149,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_asn1_buf
|
||||
{
|
||||
int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
|
||||
size_t len; /**< ASN1 length, in octets. */
|
||||
unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
|
||||
int MBEDTLS_PRIVATE(tag); /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
|
||||
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */
|
||||
unsigned char *MBEDTLS_PRIVATE(p); /**< ASN1 data, e.g. in ASCII. */
|
||||
}
|
||||
mbedtls_asn1_buf;
|
||||
|
||||
|
@ -159,9 +160,9 @@ mbedtls_asn1_buf;
|
|||
*/
|
||||
typedef struct mbedtls_asn1_bitstring
|
||||
{
|
||||
size_t len; /**< ASN1 length, in octets. */
|
||||
unsigned char unused_bits; /**< Number of unused bits at the end of the string */
|
||||
unsigned char *p; /**< Raw ASN1 data for the bit string */
|
||||
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */
|
||||
unsigned char MBEDTLS_PRIVATE(unused_bits); /**< Number of unused bits at the end of the string */
|
||||
unsigned char *MBEDTLS_PRIVATE(p); /**< Raw ASN1 data for the bit string */
|
||||
}
|
||||
mbedtls_asn1_bitstring;
|
||||
|
||||
|
@ -170,8 +171,8 @@ mbedtls_asn1_bitstring;
|
|||
*/
|
||||
typedef struct mbedtls_asn1_sequence
|
||||
{
|
||||
mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
|
||||
struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
|
||||
mbedtls_asn1_buf MBEDTLS_PRIVATE(buf); /**< Buffer containing the given ASN.1 item. */
|
||||
struct mbedtls_asn1_sequence *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
|
||||
}
|
||||
mbedtls_asn1_sequence;
|
||||
|
||||
|
@ -180,10 +181,10 @@ mbedtls_asn1_sequence;
|
|||
*/
|
||||
typedef struct mbedtls_asn1_named_data
|
||||
{
|
||||
mbedtls_asn1_buf oid; /**< The object identifier. */
|
||||
mbedtls_asn1_buf val; /**< The named value. */
|
||||
struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
|
||||
unsigned char next_merged; /**< Merge next item into the current one? */
|
||||
mbedtls_asn1_buf MBEDTLS_PRIVATE(oid); /**< The object identifier. */
|
||||
mbedtls_asn1_buf MBEDTLS_PRIVATE(val); /**< The named value. */
|
||||
struct mbedtls_asn1_named_data *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
|
||||
unsigned char MBEDTLS_PRIVATE(next_merged); /**< Merge next item into the current one? */
|
||||
}
|
||||
mbedtls_asn1_named_data;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_BIGNUM_H
|
||||
#define MBEDTLS_BIGNUM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -183,9 +184,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_mpi
|
||||
{
|
||||
int s; /*!< Sign: -1 if the mpi is negative, 1 otherwise */
|
||||
size_t n; /*!< total # of limbs */
|
||||
mbedtls_mpi_uint *p; /*!< pointer to limbs */
|
||||
int MBEDTLS_PRIVATE(s); /*!< Sign: -1 if the mpi is negative, 1 otherwise */
|
||||
size_t MBEDTLS_PRIVATE(n); /*!< total # of limbs */
|
||||
mbedtls_mpi_uint *MBEDTLS_PRIVATE(p); /*!< pointer to limbs */
|
||||
}
|
||||
mbedtls_mpi;
|
||||
|
||||
|
|
|
@ -1,278 +0,0 @@
|
|||
/**
|
||||
* \file blowfish.h
|
||||
*
|
||||
* \brief Blowfish block cipher
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBEDTLS_BLOWFISH_H
|
||||
#define MBEDTLS_BLOWFISH_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#define MBEDTLS_BLOWFISH_ENCRYPT 1
|
||||
#define MBEDTLS_BLOWFISH_DECRYPT 0
|
||||
#define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
|
||||
#define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
|
||||
#define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */
|
||||
#define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
|
||||
|
||||
#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 /**< Bad input data. */
|
||||
|
||||
#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_BLOWFISH_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief Blowfish context structure
|
||||
*/
|
||||
typedef struct mbedtls_blowfish_context
|
||||
{
|
||||
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
|
||||
uint32_t S[4][256]; /*!< key dependent S-boxes */
|
||||
}
|
||||
mbedtls_blowfish_context;
|
||||
|
||||
#else /* MBEDTLS_BLOWFISH_ALT */
|
||||
#include "blowfish_alt.h"
|
||||
#endif /* MBEDTLS_BLOWFISH_ALT */
|
||||
|
||||
/**
|
||||
* \brief Initialize a Blowfish context.
|
||||
*
|
||||
* \param ctx The Blowfish context to be initialized.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear a Blowfish context.
|
||||
*
|
||||
* \param ctx The Blowfish context to be cleared.
|
||||
* This may be \c NULL, in which case this function
|
||||
* returns immediately. If it is not \c NULL, it must
|
||||
* point to an initialized Blowfish context.
|
||||
*/
|
||||
void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Perform a Blowfish key schedule operation.
|
||||
*
|
||||
* \param ctx The Blowfish context to perform the key schedule on.
|
||||
* \param key The encryption key. This must be a readable buffer of
|
||||
* length \p keybits Bits.
|
||||
* \param keybits The length of \p key in Bits. This must be between
|
||||
* \c 32 and \c 448 and a multiple of \c 8.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
|
||||
/**
|
||||
* \brief Perform a Blowfish-ECB block encryption/decryption operation.
|
||||
*
|
||||
* \param ctx The Blowfish context to use. This must be initialized
|
||||
* and bound to a key.
|
||||
* \param mode The mode of operation. Possible values are
|
||||
* #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
|
||||
* #MBEDTLS_BLOWFISH_DECRYPT for decryption.
|
||||
* \param input The input block. This must be a readable buffer
|
||||
* of size \c 8 Bytes.
|
||||
* \param output The output block. This must be a writable buffer
|
||||
* of size \c 8 Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
|
||||
unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
* \brief Perform a Blowfish-CBC buffer encryption/decryption operation.
|
||||
*
|
||||
* \note Upon exit, the content of the IV is updated so that you can
|
||||
* call the function same function again on the following
|
||||
* block(s) of data and get the same result as if it was
|
||||
* encrypted in one call. This allows a "streaming" usage.
|
||||
* If on the other hand you need to retain the contents of the
|
||||
* IV, you should either save it manually or use the cipher
|
||||
* module instead.
|
||||
*
|
||||
* \param ctx The Blowfish context to use. This must be initialized
|
||||
* and bound to a key.
|
||||
* \param mode The mode of operation. Possible values are
|
||||
* #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
|
||||
* #MBEDTLS_BLOWFISH_DECRYPT for decryption.
|
||||
* \param length The length of the input data in Bytes. This must be
|
||||
* multiple of \c 8.
|
||||
* \param iv The initialization vector. This must be a read/write buffer
|
||||
* of length \c 8 Bytes. It is updated by this function.
|
||||
* \param input The input data. This must be a readable buffer of length
|
||||
* \p length Bytes.
|
||||
* \param output The output data. This must be a writable buffer of length
|
||||
* \p length Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
/**
|
||||
* \brief Perform a Blowfish CFB buffer encryption/decryption operation.
|
||||
*
|
||||
* \note Upon exit, the content of the IV is updated so that you can
|
||||
* call the function same function again on the following
|
||||
* block(s) of data and get the same result as if it was
|
||||
* encrypted in one call. This allows a "streaming" usage.
|
||||
* If on the other hand you need to retain the contents of the
|
||||
* IV, you should either save it manually or use the cipher
|
||||
* module instead.
|
||||
*
|
||||
* \param ctx The Blowfish context to use. This must be initialized
|
||||
* and bound to a key.
|
||||
* \param mode The mode of operation. Possible values are
|
||||
* #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or
|
||||
* #MBEDTLS_BLOWFISH_DECRYPT for decryption.
|
||||
* \param length The length of the input data in Bytes.
|
||||
* \param iv_off The offset in the initialiation vector.
|
||||
* The value pointed to must be smaller than \c 8 Bytes.
|
||||
* It is updated by this function to support the aforementioned
|
||||
* streaming usage.
|
||||
* \param iv The initialization vector. This must be a read/write buffer
|
||||
* of size \c 8 Bytes. It is updated after use.
|
||||
* \param input The input data. This must be a readable buffer of length
|
||||
* \p length Bytes.
|
||||
* \param output The output data. This must be a writable buffer of length
|
||||
* \p length Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif /*MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
/**
|
||||
* \brief Perform a Blowfish-CTR buffer encryption/decryption operation.
|
||||
*
|
||||
* \warning You must never reuse a nonce value with the same key. Doing so
|
||||
* would void the encryption for the two messages encrypted with
|
||||
* the same nonce and key.
|
||||
*
|
||||
* There are two common strategies for managing nonces with CTR:
|
||||
*
|
||||
* 1. You can handle everything as a single message processed over
|
||||
* successive calls to this function. In that case, you want to
|
||||
* set \p nonce_counter and \p nc_off to 0 for the first call, and
|
||||
* then preserve the values of \p nonce_counter, \p nc_off and \p
|
||||
* stream_block across calls to this function as they will be
|
||||
* updated by this function.
|
||||
*
|
||||
* With this strategy, you must not encrypt more than 2**64
|
||||
* blocks of data with the same key.
|
||||
*
|
||||
* 2. You can encrypt separate messages by dividing the \p
|
||||
* nonce_counter buffer in two areas: the first one used for a
|
||||
* per-message nonce, handled by yourself, and the second one
|
||||
* updated by this function internally.
|
||||
*
|
||||
* For example, you might reserve the first 4 bytes for the
|
||||
* per-message nonce, and the last 4 bytes for internal use. In that
|
||||
* case, before calling this function on a new message you need to
|
||||
* set the first 4 bytes of \p nonce_counter to your chosen nonce
|
||||
* value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
|
||||
* stream_block to be ignored). That way, you can encrypt at most
|
||||
* 2**32 messages of up to 2**32 blocks each with the same key.
|
||||
*
|
||||
* The per-message nonce (or information sufficient to reconstruct
|
||||
* it) needs to be communicated with the ciphertext and must be unique.
|
||||
* The recommended way to ensure uniqueness is to use a message
|
||||
* counter.
|
||||
*
|
||||
* Note that for both stategies, sizes are measured in blocks and
|
||||
* that a Blowfish block is 8 bytes.
|
||||
*
|
||||
* \warning Upon return, \p stream_block contains sensitive data. Its
|
||||
* content must not be written to insecure storage and should be
|
||||
* securely discarded as soon as it's no longer needed.
|
||||
*
|
||||
* \param ctx The Blowfish context to use. This must be initialized
|
||||
* and bound to a key.
|
||||
* \param length The length of the input data in Bytes.
|
||||
* \param nc_off The offset in the current stream_block (for resuming
|
||||
* within current cipher stream). The offset pointer
|
||||
* should be \c 0 at the start of a stream and must be
|
||||
* smaller than \c 8. It is updated by this function.
|
||||
* \param nonce_counter The 64-bit nonce and counter. This must point to a
|
||||
* read/write buffer of length \c 8 Bytes.
|
||||
* \param stream_block The saved stream-block for resuming. This must point to
|
||||
* a read/write buffer of length \c 8 Bytes.
|
||||
* \param input The input data. This must be a readable buffer of
|
||||
* length \p length Bytes.
|
||||
* \param output The output data. This must be a writable buffer of
|
||||
* length \p length Bytes.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
|
||||
unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* blowfish.h */
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_CAMELLIA_H
|
||||
#define MBEDTLS_CAMELLIA_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -53,8 +54,8 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_camellia_context
|
||||
{
|
||||
int nr; /*!< number of rounds */
|
||||
uint32_t rk[68]; /*!< CAMELLIA round keys */
|
||||
int MBEDTLS_PRIVATE(nr); /*!< number of rounds */
|
||||
uint32_t MBEDTLS_PRIVATE(rk)[68]; /*!< CAMELLIA round keys */
|
||||
}
|
||||
mbedtls_camellia_context;
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CCM_H
|
||||
#define MBEDTLS_CCM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -77,7 +78,7 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_ccm_context
|
||||
{
|
||||
mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
}
|
||||
mbedtls_ccm_context;
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CHACHA20_H
|
||||
#define MBEDTLS_CHACHA20_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -51,9 +52,9 @@ extern "C" {
|
|||
|
||||
typedef struct mbedtls_chacha20_context
|
||||
{
|
||||
uint32_t state[16]; /*! The state (before round operations). */
|
||||
uint8_t keystream8[64]; /*! Leftover keystream bytes. */
|
||||
size_t keystream_bytes_used; /*! Number of keystream bytes already used. */
|
||||
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
|
||||
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
|
||||
size_t MBEDTLS_PRIVATE(keystream_bytes_used); /*! Number of keystream bytes already used. */
|
||||
}
|
||||
mbedtls_chacha20_context;
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CHACHAPOLY_H
|
||||
#define MBEDTLS_CHACHAPOLY_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -61,12 +62,12 @@ mbedtls_chachapoly_mode_t;
|
|||
|
||||
typedef struct mbedtls_chachapoly_context
|
||||
{
|
||||
mbedtls_chacha20_context chacha20_ctx; /**< The ChaCha20 context. */
|
||||
mbedtls_poly1305_context poly1305_ctx; /**< The Poly1305 context. */
|
||||
uint64_t aad_len; /**< The length (bytes) of the Additional Authenticated Data. */
|
||||
uint64_t ciphertext_len; /**< The length (bytes) of the ciphertext. */
|
||||
int state; /**< The current state of the context. */
|
||||
mbedtls_chachapoly_mode_t mode; /**< Cipher mode (encrypt or decrypt). */
|
||||
mbedtls_chacha20_context MBEDTLS_PRIVATE(chacha20_ctx); /**< The ChaCha20 context. */
|
||||
mbedtls_poly1305_context MBEDTLS_PRIVATE(poly1305_ctx); /**< The Poly1305 context. */
|
||||
uint64_t MBEDTLS_PRIVATE(aad_len); /**< The length (bytes) of the Additional Authenticated Data. */
|
||||
uint64_t MBEDTLS_PRIVATE(ciphertext_len); /**< The length (bytes) of the ciphertext. */
|
||||
int MBEDTLS_PRIVATE(state); /**< The current state of the context. */
|
||||
mbedtls_chachapoly_mode_t MBEDTLS_PRIVATE(mode); /**< Cipher mode (encrypt or decrypt). */
|
||||
}
|
||||
mbedtls_chachapoly_context;
|
||||
|
||||
|
|
|
@ -55,9 +55,8 @@
|
|||
#endif
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#if defined(TARGET_LIKE_MBED) && \
|
||||
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
|
||||
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
|
||||
#if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C)
|
||||
#error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
||||
|
@ -151,14 +150,6 @@
|
|||
#error "MBEDTLS_ECP_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C) && !( \
|
||||
defined(MBEDTLS_ECP_ALT) || \
|
||||
defined(MBEDTLS_CTR_DRBG_C) || \
|
||||
defined(MBEDTLS_HMAC_DRBG_C) || \
|
||||
defined(MBEDTLS_ECP_NO_INTERNAL_RNG))
|
||||
#error "MBEDTLS_ECP_C requires a DRBG module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C)
|
||||
#error "MBEDTLS_PK_PARSE_C defined, but not all prerequesites"
|
||||
#endif
|
||||
|
@ -826,6 +817,10 @@
|
|||
#error "MBEDTLS_SSL_PROTO_TLS1_1 (TLS v1.1 support) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4286"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS) //no-check-names
|
||||
#error "MBEDTLS_CHECK_PARAMS was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4313"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) //no-check-names
|
||||
#error "MBEDTLS_SSL_CID_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335"
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CIPHER_H
|
||||
#define MBEDTLS_CIPHER_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -44,7 +45,7 @@
|
|||
#define MBEDTLS_CIPHER_MODE_WITH_PADDING
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
|
||||
#if defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
|
||||
defined(MBEDTLS_CHACHA20_C)
|
||||
#define MBEDTLS_CIPHER_MODE_STREAM
|
||||
#endif
|
||||
|
@ -72,7 +73,7 @@ extern "C" {
|
|||
/**
|
||||
* \brief Supported cipher types.
|
||||
*
|
||||
* \warning RC4 and DES are considered weak ciphers and their use
|
||||
* \warning DES is considered weak cipher and its use
|
||||
* constitutes a security risk. Arm recommends considering stronger
|
||||
* ciphers instead.
|
||||
*/
|
||||
|
@ -83,8 +84,6 @@ typedef enum {
|
|||
MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */
|
||||
MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */
|
||||
MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */
|
||||
MBEDTLS_CIPHER_ID_BLOWFISH, /**< The Blowfish cipher. */
|
||||
MBEDTLS_CIPHER_ID_ARC4, /**< The RC4 cipher. */
|
||||
MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */
|
||||
MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */
|
||||
} mbedtls_cipher_id_t;
|
||||
|
@ -92,7 +91,7 @@ typedef enum {
|
|||
/**
|
||||
* \brief Supported {cipher type, cipher mode} pairs.
|
||||
*
|
||||
* \warning RC4 and DES are considered weak ciphers and their use
|
||||
* \warning DES is considered weak cipher and its use
|
||||
* constitutes a security risk. Arm recommends considering stronger
|
||||
* ciphers instead.
|
||||
*/
|
||||
|
@ -135,11 +134,6 @@ typedef enum {
|
|||
MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. */
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. */
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. */
|
||||
MBEDTLS_CIPHER_BLOWFISH_ECB, /**< Blowfish cipher with ECB mode. */
|
||||
MBEDTLS_CIPHER_BLOWFISH_CBC, /**< Blowfish cipher with CBC mode. */
|
||||
MBEDTLS_CIPHER_BLOWFISH_CFB64, /**< Blowfish cipher with CFB64 mode. */
|
||||
MBEDTLS_CIPHER_BLOWFISH_CTR, /**< Blowfish cipher with CTR mode. */
|
||||
MBEDTLS_CIPHER_ARC4_128, /**< RC4 cipher with 128-bit mode. */
|
||||
MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */
|
||||
MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */
|
||||
MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */
|
||||
|
@ -267,37 +261,37 @@ typedef struct mbedtls_cipher_info_t
|
|||
/** Full cipher identifier. For example,
|
||||
* MBEDTLS_CIPHER_AES_256_CBC.
|
||||
*/
|
||||
mbedtls_cipher_type_t type;
|
||||
mbedtls_cipher_type_t MBEDTLS_PRIVATE(type);
|
||||
|
||||
/** The cipher mode. For example, MBEDTLS_MODE_CBC. */
|
||||
mbedtls_cipher_mode_t mode;
|
||||
mbedtls_cipher_mode_t MBEDTLS_PRIVATE(mode);
|
||||
|
||||
/** The cipher key length, in bits. This is the
|
||||
* default length for variable sized ciphers.
|
||||
* Includes parity bits for ciphers like DES.
|
||||
*/
|
||||
unsigned int key_bitlen;
|
||||
unsigned int MBEDTLS_PRIVATE(key_bitlen);
|
||||
|
||||
/** Name of the cipher. */
|
||||
const char * name;
|
||||
const char * MBEDTLS_PRIVATE(name);
|
||||
|
||||
/** IV or nonce size, in Bytes.
|
||||
* For ciphers that accept variable IV sizes,
|
||||
* this is the recommended size.
|
||||
*/
|
||||
unsigned int iv_size;
|
||||
unsigned int MBEDTLS_PRIVATE(iv_size);
|
||||
|
||||
/** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and
|
||||
* MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the
|
||||
* cipher supports variable IV or variable key sizes, respectively.
|
||||
*/
|
||||
int flags;
|
||||
int MBEDTLS_PRIVATE(flags);
|
||||
|
||||
/** The block size, in Bytes. */
|
||||
unsigned int block_size;
|
||||
unsigned int MBEDTLS_PRIVATE(block_size);
|
||||
|
||||
/** Struct for base cipher information and functions. */
|
||||
const mbedtls_cipher_base_t *base;
|
||||
const mbedtls_cipher_base_t *MBEDTLS_PRIVATE(base);
|
||||
|
||||
} mbedtls_cipher_info_t;
|
||||
|
||||
|
@ -307,43 +301,43 @@ typedef struct mbedtls_cipher_info_t
|
|||
typedef struct mbedtls_cipher_context_t
|
||||
{
|
||||
/** Information about the associated cipher. */
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
const mbedtls_cipher_info_t *MBEDTLS_PRIVATE(cipher_info);
|
||||
|
||||
/** Key length to use. */
|
||||
int key_bitlen;
|
||||
int MBEDTLS_PRIVATE(key_bitlen);
|
||||
|
||||
/** Operation that the key of the context has been
|
||||
* initialized for.
|
||||
*/
|
||||
mbedtls_operation_t operation;
|
||||
mbedtls_operation_t MBEDTLS_PRIVATE(operation);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
||||
/** Padding functions to use, if relevant for
|
||||
* the specific cipher mode.
|
||||
*/
|
||||
void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
|
||||
int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
|
||||
void (*MBEDTLS_PRIVATE(add_padding))( unsigned char *output, size_t olen, size_t data_len );
|
||||
int (*MBEDTLS_PRIVATE(get_padding))( unsigned char *input, size_t ilen, size_t *data_len );
|
||||
#endif
|
||||
|
||||
/** Buffer for input that has not been processed yet. */
|
||||
unsigned char unprocessed_data[MBEDTLS_MAX_BLOCK_LENGTH];
|
||||
unsigned char MBEDTLS_PRIVATE(unprocessed_data)[MBEDTLS_MAX_BLOCK_LENGTH];
|
||||
|
||||
/** Number of Bytes that have not been processed yet. */
|
||||
size_t unprocessed_len;
|
||||
size_t MBEDTLS_PRIVATE(unprocessed_len);
|
||||
|
||||
/** Current IV or NONCE_COUNTER for CTR-mode, data unit (or sector) number
|
||||
* for XTS-mode. */
|
||||
unsigned char iv[MBEDTLS_MAX_IV_LENGTH];
|
||||
unsigned char MBEDTLS_PRIVATE(iv)[MBEDTLS_MAX_IV_LENGTH];
|
||||
|
||||
/** IV size in Bytes, for ciphers with variable-length IVs. */
|
||||
size_t iv_size;
|
||||
size_t MBEDTLS_PRIVATE(iv_size);
|
||||
|
||||
/** The cipher-specific context. */
|
||||
void *cipher_ctx;
|
||||
void *MBEDTLS_PRIVATE(cipher_ctx);
|
||||
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
/** CMAC-specific context. */
|
||||
mbedtls_cmac_context_t *cmac_ctx;
|
||||
mbedtls_cmac_context_t *MBEDTLS_PRIVATE(cmac_ctx);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
|
@ -354,7 +348,7 @@ typedef struct mbedtls_cipher_context_t
|
|||
* mbedtls_cipher_setup(), and set if it was established through
|
||||
* mbedtls_cipher_setup_psa().
|
||||
*/
|
||||
unsigned char psa_enabled;
|
||||
unsigned char MBEDTLS_PRIVATE(psa_enabled);
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
} mbedtls_cipher_context_t;
|
||||
|
@ -504,10 +498,10 @@ static inline unsigned int mbedtls_cipher_get_block_size(
|
|||
const mbedtls_cipher_context_t *ctx )
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->block_size;
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(block_size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -523,10 +517,10 @@ static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
|
|||
const mbedtls_cipher_context_t *ctx )
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, MBEDTLS_MODE_NONE );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return MBEDTLS_MODE_NONE;
|
||||
|
||||
return ctx->cipher_info->mode;
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(mode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -543,13 +537,13 @@ static inline int mbedtls_cipher_get_iv_size(
|
|||
const mbedtls_cipher_context_t *ctx )
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return 0;
|
||||
|
||||
if( ctx->iv_size != 0 )
|
||||
return (int) ctx->iv_size;
|
||||
if( ctx->MBEDTLS_PRIVATE(iv_size) != 0 )
|
||||
return (int) ctx->MBEDTLS_PRIVATE(iv_size);
|
||||
|
||||
return (int) ctx->cipher_info->iv_size;
|
||||
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(iv_size);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -565,10 +559,10 @@ static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
|
|||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_CIPHER_NONE );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return MBEDTLS_CIPHER_NONE;
|
||||
|
||||
return ctx->cipher_info->type;
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -584,10 +578,10 @@ static inline const char *mbedtls_cipher_get_name(
|
|||
const mbedtls_cipher_context_t *ctx )
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->name;
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -604,10 +598,10 @@ static inline int mbedtls_cipher_get_key_bitlen(
|
|||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_KEY_LENGTH_NONE );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return MBEDTLS_KEY_LENGTH_NONE;
|
||||
|
||||
return (int) ctx->cipher_info->key_bitlen;
|
||||
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -623,10 +617,10 @@ static inline mbedtls_operation_t mbedtls_cipher_get_operation(
|
|||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_OPERATION_NONE );
|
||||
if( ctx->cipher_info == NULL )
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
return MBEDTLS_OPERATION_NONE;
|
||||
|
||||
return ctx->operation;
|
||||
return ctx->MBEDTLS_PRIVATE(operation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CMAC_H
|
||||
#define MBEDTLS_CMAC_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -55,14 +56,14 @@ extern "C" {
|
|||
struct mbedtls_cmac_context_t
|
||||
{
|
||||
/** The internal state of the CMAC algorithm. */
|
||||
unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
unsigned char MBEDTLS_PRIVATE(state)[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
/** Unprocessed data - either data that was not block aligned and is still
|
||||
* pending processing, or the final block. */
|
||||
unsigned char unprocessed_block[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
unsigned char MBEDTLS_PRIVATE(unprocessed_block)[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
/** The length of data pending processing. */
|
||||
size_t unprocessed_len;
|
||||
size_t MBEDTLS_PRIVATE(unprocessed_len);
|
||||
};
|
||||
|
||||
#else /* !MBEDTLS_CMAC_ALT */
|
||||
|
|
58
include/mbedtls/compat-2.x.h
Normal file
58
include/mbedtls/compat-2.x.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* \file compat-2.x.h
|
||||
*
|
||||
* \brief Compatibility definitions
|
||||
*
|
||||
* \deprecated Use the new names directly instead
|
||||
*/
|
||||
/*
|
||||
* 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_DEPRECATED_WARNING)
|
||||
#warning "Including compat-2.x.h is deprecated"
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_COMPAT2X_H
|
||||
#define MBEDTLS_COMPAT2X_H
|
||||
|
||||
/*
|
||||
* Macros for renamed functions
|
||||
*/
|
||||
#define mbedtls_ctr_drbg_update_ret mbedtls_ctr_drbg_update
|
||||
#define mbedtls_hmac_drbg_update_ret mbedtls_hmac_drbg_update
|
||||
#define mbedtls_md5_starts_ret mbedtls_md5_starts
|
||||
#define mbedtls_md5_update_ret mbedtls_md5_update
|
||||
#define mbedtls_md5_finish_ret mbedtls_md5_finish
|
||||
#define mbedtls_md5_ret mbedtls_md5
|
||||
#define mbedtls_ripemd160_starts_ret mbedtls_ripemd160_starts
|
||||
#define mbedtls_ripemd160_update_ret mbedtls_ripemd160_update
|
||||
#define mbedtls_ripemd160_finish_ret mbedtls_ripemd160_finish
|
||||
#define mbedtls_ripemd160_ret mbedtls_ripemd160
|
||||
#define mbedtls_sha1_starts_ret mbedtls_sha1_starts
|
||||
#define mbedtls_sha1_update_ret mbedtls_sha1_update
|
||||
#define mbedtls_sha1_finish_ret mbedtls_sha1_finish
|
||||
#define mbedtls_sha1_ret mbedtls_sha1
|
||||
#define mbedtls_sha256_starts_ret mbedtls_sha256_starts
|
||||
#define mbedtls_sha256_update_ret mbedtls_sha256_update
|
||||
#define mbedtls_sha256_finish_ret mbedtls_sha256_finish
|
||||
#define mbedtls_sha256_ret mbedtls_sha256
|
||||
#define mbedtls_sha512_starts_ret mbedtls_sha512_starts
|
||||
#define mbedtls_sha512_update_ret mbedtls_sha512_update
|
||||
#define mbedtls_sha512_finish_ret mbedtls_sha512_finish
|
||||
#define mbedtls_sha512_ret mbedtls_sha512
|
||||
|
||||
#endif /* MBEDTLS_COMPAT2X_H */
|
|
@ -47,7 +47,6 @@
|
|||
*
|
||||
* Used in:
|
||||
* library/aria.c
|
||||
* library/timing.c
|
||||
* library/bn_mul.h
|
||||
*
|
||||
* Required by:
|
||||
|
@ -255,72 +254,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_DEPRECATED_REMOVED
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHECK_PARAMS
|
||||
*
|
||||
* This configuration option controls whether the library validates more of
|
||||
* the parameters passed to it.
|
||||
*
|
||||
* When this flag is not defined, the library only attempts to validate an
|
||||
* input parameter if: (1) they may come from the outside world (such as the
|
||||
* network, the filesystem, etc.) or (2) not validating them could result in
|
||||
* internal memory errors such as overflowing a buffer controlled by the
|
||||
* library. On the other hand, it doesn't attempt to validate parameters whose
|
||||
* values are fully controlled by the application (such as pointers).
|
||||
*
|
||||
* When this flag is defined, the library additionally attempts to validate
|
||||
* parameters that are fully controlled by the application, and should always
|
||||
* be valid if the application code is fully correct and trusted.
|
||||
*
|
||||
* For example, when a function accepts as input a pointer to a buffer that may
|
||||
* contain untrusted data, and its documentation mentions that this pointer
|
||||
* must not be NULL:
|
||||
* - The pointer is checked to be non-NULL only if this option is enabled.
|
||||
* - The content of the buffer is always validated.
|
||||
*
|
||||
* When this flag is defined, if a library function receives a parameter that
|
||||
* is invalid:
|
||||
* 1. The function will invoke the macro MBEDTLS_PARAM_FAILED().
|
||||
* 2. If MBEDTLS_PARAM_FAILED() did not terminate the program, the function
|
||||
* will immediately return. If the function returns an Mbed TLS error code,
|
||||
* the error code in this case is MBEDTLS_ERR_xxx_BAD_INPUT_DATA.
|
||||
*
|
||||
* When defining this flag, you also need to arrange a definition for
|
||||
* MBEDTLS_PARAM_FAILED(). You can do this by any of the following methods:
|
||||
* - By default, the library defines MBEDTLS_PARAM_FAILED() to call a
|
||||
* function mbedtls_param_failed(), but the library does not define this
|
||||
* function. If you do not make any other arrangements, you must provide
|
||||
* the function mbedtls_param_failed() in your application.
|
||||
* See `platform_util.h` for its prototype.
|
||||
* - If you enable the macro #MBEDTLS_CHECK_PARAMS_ASSERT, then the
|
||||
* library defines MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`.
|
||||
* You can still supply an alternative definition of
|
||||
* MBEDTLS_PARAM_FAILED(), which may call `assert`.
|
||||
* - If you define a macro MBEDTLS_PARAM_FAILED() before including `config.h`
|
||||
* or you uncomment the definition of MBEDTLS_PARAM_FAILED() in `config.h`,
|
||||
* the library will call the macro that you defined and will not supply
|
||||
* its own version. Note that if MBEDTLS_PARAM_FAILED() calls `assert`,
|
||||
* you need to enable #MBEDTLS_CHECK_PARAMS_ASSERT so that library source
|
||||
* files include `<assert.h>`.
|
||||
*
|
||||
* Uncomment to enable validation of application-controlled parameters.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_PARAMS
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
*
|
||||
* Allow MBEDTLS_PARAM_FAILED() to call `assert`, and make it default to
|
||||
* `assert`. This macro is only used if #MBEDTLS_CHECK_PARAMS is defined.
|
||||
*
|
||||
* If this macro is not defined, then MBEDTLS_PARAM_FAILED() defaults to
|
||||
* calling a function mbedtls_param_failed(). See the documentation of
|
||||
* #MBEDTLS_CHECK_PARAMS for details.
|
||||
*
|
||||
* Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`.
|
||||
*/
|
||||
//#define MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
|
||||
/* \} name SECTION: System support */
|
||||
|
||||
/**
|
||||
|
@ -334,7 +267,7 @@
|
|||
/**
|
||||
* \def MBEDTLS_TIMING_ALT
|
||||
*
|
||||
* Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(),
|
||||
* Uncomment to provide your own alternate implementation for
|
||||
* mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay()
|
||||
*
|
||||
* Only works if you have MBEDTLS_TIMING_C enabled.
|
||||
|
@ -363,16 +296,14 @@
|
|||
* Uncomment a macro to enable alternate implementation of the corresponding
|
||||
* module.
|
||||
*
|
||||
* \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
|
||||
* \warning MD5, DES and SHA-1 are considered weak and their
|
||||
* use constitutes a security risk. If possible, we recommend
|
||||
* avoiding dependencies on them, and considering stronger message
|
||||
* digests and ciphers instead.
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_AES_ALT
|
||||
//#define MBEDTLS_ARC4_ALT
|
||||
//#define MBEDTLS_ARIA_ALT
|
||||
//#define MBEDTLS_BLOWFISH_ALT
|
||||
//#define MBEDTLS_CAMELLIA_ALT
|
||||
//#define MBEDTLS_CCM_ALT
|
||||
//#define MBEDTLS_CHACHA20_ALT
|
||||
|
@ -383,8 +314,6 @@
|
|||
//#define MBEDTLS_ECJPAKE_ALT
|
||||
//#define MBEDTLS_GCM_ALT
|
||||
//#define MBEDTLS_NIST_KW_ALT
|
||||
//#define MBEDTLS_MD2_ALT
|
||||
//#define MBEDTLS_MD4_ALT
|
||||
//#define MBEDTLS_MD5_ALT
|
||||
//#define MBEDTLS_POLY1305_ALT
|
||||
//#define MBEDTLS_RIPEMD160_ALT
|
||||
|
@ -392,7 +321,6 @@
|
|||
//#define MBEDTLS_SHA1_ALT
|
||||
//#define MBEDTLS_SHA256_ALT
|
||||
//#define MBEDTLS_SHA512_ALT
|
||||
//#define MBEDTLS_XTEA_ALT
|
||||
|
||||
/*
|
||||
* When replacing the elliptic curve module, pleace consider, that it is
|
||||
|
@ -406,7 +334,7 @@
|
|||
//#define MBEDTLS_ECP_ALT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MD2_PROCESS_ALT
|
||||
* \def MBEDTLS_SHA256_PROCESS_ALT
|
||||
*
|
||||
* MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you
|
||||
* alternate core implementation of symmetric crypto or hash function. Keep in
|
||||
|
@ -428,7 +356,7 @@
|
|||
* Uncomment a macro to enable alternate implementation of the corresponding
|
||||
* function.
|
||||
*
|
||||
* \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
|
||||
* \warning MD5, DES and SHA-1 are considered weak and their use
|
||||
* constitutes a security risk. If possible, we recommend avoiding
|
||||
* dependencies on them, and considering stronger message digests
|
||||
* and ciphers instead.
|
||||
|
@ -442,8 +370,6 @@
|
|||
* implementation should be provided for mbedtls_ecdsa_sign_det_ext().
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_MD2_PROCESS_ALT
|
||||
//#define MBEDTLS_MD4_PROCESS_ALT
|
||||
//#define MBEDTLS_MD5_PROCESS_ALT
|
||||
//#define MBEDTLS_RIPEMD160_PROCESS_ALT
|
||||
//#define MBEDTLS_SHA1_PROCESS_ALT
|
||||
|
@ -717,28 +643,6 @@
|
|||
*/
|
||||
#define MBEDTLS_ECP_NIST_OPTIM
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ECP_NO_INTERNAL_RNG
|
||||
*
|
||||
* When this option is disabled, mbedtls_ecp_mul() will make use of an
|
||||
* internal RNG when called with a NULL \c f_rng argument, in order to protect
|
||||
* against some side-channel attacks.
|
||||
*
|
||||
* This protection introduces a dependency of the ECP module on one of the
|
||||
* DRBG modules. For very constrained implementations that don't require this
|
||||
* protection (for example, because you're only doing signature verification,
|
||||
* so not manipulating any secret, or because local/physical side-channel
|
||||
* attacks are outside your threat model), it might be desirable to get rid of
|
||||
* that dependency.
|
||||
*
|
||||
* \warning Enabling this option makes some uses of ECP vulnerable to some
|
||||
* side-channel attacks. Only enable it if you know that's not a problem for
|
||||
* your use case.
|
||||
*
|
||||
* Uncomment this macro to disable some counter-measures in ECP.
|
||||
*/
|
||||
//#define MBEDTLS_ECP_NO_INTERNAL_RNG
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ECP_RESTARTABLE
|
||||
*
|
||||
|
@ -1080,8 +984,7 @@
|
|||
/**
|
||||
* \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
||||
*
|
||||
* Do not add default entropy sources. These are the platform specific
|
||||
* or mbedtls_timing_hardclock poll function.
|
||||
* Do not add default entropy sources in mbedtls_entropy_init().
|
||||
*
|
||||
* This is useful to have more control over the added entropy sources in an
|
||||
* application.
|
||||
|
@ -1537,16 +1440,6 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_RENEGOTIATION
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
|
||||
*
|
||||
* Pick the ciphersuite according to the client's preferences rather than ours
|
||||
* in the SSL Server module (MBEDTLS_SSL_SRV_C).
|
||||
*
|
||||
* Uncomment this macro to respect client's ciphersuite order
|
||||
*/
|
||||
//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
*
|
||||
|
@ -1879,18 +1772,6 @@
|
|||
*/
|
||||
#define MBEDTLS_VERSION_FEATURES
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
|
||||
*
|
||||
* If set, the X509 parser will not break-off when parsing an X509 certificate
|
||||
* and encountering an unknown critical extension.
|
||||
*
|
||||
* \warning Depending on your PKI use, enabling this can be a security risk!
|
||||
*
|
||||
* Uncomment to prevent an error.
|
||||
*/
|
||||
//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
|
||||
*
|
||||
|
@ -1910,33 +1791,6 @@
|
|||
*/
|
||||
//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_CHECK_KEY_USAGE
|
||||
*
|
||||
* Enable verification of the keyUsage extension (CA and leaf certificates).
|
||||
*
|
||||
* Disabling this avoids problems with mis-issued and/or misused
|
||||
* (intermediate) CA and leaf certificates.
|
||||
*
|
||||
* \warning Depending on your PKI use, disabling this can be a security risk!
|
||||
*
|
||||
* Comment to skip keyUsage checking for both CA and leaf certificates.
|
||||
*/
|
||||
#define MBEDTLS_X509_CHECK_KEY_USAGE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
|
||||
*
|
||||
* Enable verification of the extendedKeyUsage extension (leaf certificates).
|
||||
*
|
||||
* Disabling this avoids problems with mis-issued and/or misused certificates.
|
||||
*
|
||||
* \warning Depending on your PKI use, disabling this can be a security risk!
|
||||
*
|
||||
* Comment to skip extendedKeyUsage checking for certificates.
|
||||
*/
|
||||
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_X509_REMOVE_INFO
|
||||
*
|
||||
|
@ -2055,24 +1909,6 @@
|
|||
*/
|
||||
#define MBEDTLS_AES_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ARC4_C
|
||||
*
|
||||
* Enable the ARCFOUR stream cipher.
|
||||
*
|
||||
* Module: library/arc4.c
|
||||
* Caller: library/cipher.c
|
||||
*
|
||||
* This module enables the following ciphersuites (if other requisites are
|
||||
* enabled as well):
|
||||
*
|
||||
* \warning ARC4 is considered a weak cipher and its use constitutes a
|
||||
* security risk. If possible, we recommend avoidng dependencies on
|
||||
* it, and considering stronger ciphers instead.
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_ARC4_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_ASN1_PARSE_C
|
||||
*
|
||||
|
@ -2130,15 +1966,6 @@
|
|||
*/
|
||||
#define MBEDTLS_BIGNUM_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_BLOWFISH_C
|
||||
*
|
||||
* Enable the Blowfish block cipher.
|
||||
*
|
||||
* Module: library/blowfish.c
|
||||
*/
|
||||
#define MBEDTLS_BLOWFISH_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_CAMELLIA_C
|
||||
*
|
||||
|
@ -2541,40 +2368,6 @@
|
|||
*/
|
||||
#define MBEDTLS_MD_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MD2_C
|
||||
*
|
||||
* Enable the MD2 hash algorithm.
|
||||
*
|
||||
* Module: library/md2.c
|
||||
* Caller:
|
||||
*
|
||||
* Uncomment to enable support for (rare) MD2-signed X.509 certs.
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use constitutes a
|
||||
* security risk. If possible, we recommend avoiding dependencies on
|
||||
* it, and considering stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_MD2_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MD4_C
|
||||
*
|
||||
* Enable the MD4 hash algorithm.
|
||||
*
|
||||
* Module: library/md4.c
|
||||
* Caller:
|
||||
*
|
||||
* Uncomment to enable support for (rare) MD4-signed X.509 certs.
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use constitutes a
|
||||
* security risk. If possible, we recommend avoiding dependencies on
|
||||
* it, and considering stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
//#define MBEDTLS_MD4_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MD5_C
|
||||
*
|
||||
|
@ -2770,7 +2563,6 @@
|
|||
* Caller: library/pkparse.c
|
||||
*
|
||||
* Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C
|
||||
* Can use: MBEDTLS_ARC4_C
|
||||
*
|
||||
* This module enables PKCS#12 functions.
|
||||
*/
|
||||
|
@ -3215,16 +3007,6 @@
|
|||
*/
|
||||
#define MBEDTLS_X509_CSR_WRITE_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_XTEA_C
|
||||
*
|
||||
* Enable the XTEA block cipher.
|
||||
*
|
||||
* Module: library/xtea.c
|
||||
* Caller:
|
||||
*/
|
||||
#define MBEDTLS_XTEA_C
|
||||
|
||||
/* \} name SECTION: mbed TLS modules */
|
||||
|
||||
/**
|
||||
|
@ -3260,7 +3042,6 @@
|
|||
//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
|
||||
|
||||
/* ECP options */
|
||||
//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
|
||||
//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
|
||||
//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
|
||||
|
||||
|
@ -3303,42 +3084,6 @@
|
|||
//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
|
||||
//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
|
||||
|
||||
/**
|
||||
* \brief This macro is invoked by the library when an invalid parameter
|
||||
* is detected that is only checked with #MBEDTLS_CHECK_PARAMS
|
||||
* (see the documentation of that option for context).
|
||||
*
|
||||
* When you leave this undefined here, the library provides
|
||||
* a default definition. If the macro #MBEDTLS_CHECK_PARAMS_ASSERT
|
||||
* is defined, the default definition is `assert(cond)`,
|
||||
* otherwise the default definition calls a function
|
||||
* mbedtls_param_failed(). This function is declared in
|
||||
* `platform_util.h` for the benefit of the library, but
|
||||
* you need to define in your application.
|
||||
*
|
||||
* When you define this here, this replaces the default
|
||||
* definition in platform_util.h (which no longer declares the
|
||||
* function mbedtls_param_failed()) and it is your responsibility
|
||||
* to make sure this macro expands to something suitable (in
|
||||
* particular, that all the necessary declarations are visible
|
||||
* from within the library - you can ensure that by providing
|
||||
* them in this file next to the macro definition).
|
||||
* If you define this macro to call `assert`, also define
|
||||
* #MBEDTLS_CHECK_PARAMS_ASSERT so that library source files
|
||||
* include `<assert.h>`.
|
||||
*
|
||||
* Note that you may define this macro to expand to nothing, in
|
||||
* which case you don't have to worry about declarations or
|
||||
* definitions. However, you will then be notified about invalid
|
||||
* parameters only in non-void functions, and void function will
|
||||
* just silently return early on invalid parameters, which
|
||||
* partially negates the benefits of enabling
|
||||
* #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
|
||||
*
|
||||
* \param cond The expression that should evaluate to true, but doesn't.
|
||||
*/
|
||||
//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
|
||||
|
||||
/* PSA options */
|
||||
/**
|
||||
* Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the
|
||||
|
|
|
@ -103,16 +103,6 @@ extern "C" {
|
|||
#endif /* !MBEDTLS_PSA_ACCEL_ALG_HMAC */
|
||||
#endif /* PSA_WANT_ALG_HMAC */
|
||||
|
||||
#if defined(PSA_WANT_ALG_MD2) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD2)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD2 1
|
||||
#define MBEDTLS_MD2_C
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_MD4) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD4)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD4 1
|
||||
#define MBEDTLS_MD4_C
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_MD5) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD5 1
|
||||
#define MBEDTLS_MD5_C
|
||||
|
@ -277,13 +267,6 @@ extern "C" {
|
|||
#endif /* PSA_HAVE_SOFT_KEY_TYPE_AES || PSA_HAVE_SOFT_BLOCK_MODE */
|
||||
#endif /* PSA_WANT_KEY_TYPE_AES */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_ARC4)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4)
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1
|
||||
#define MBEDTLS_ARC4_C
|
||||
#endif /*!MBEDTLS_PSA_ACCEL_KEY_TYPE_ARC4 */
|
||||
#endif /* PSA_WANT_KEY_TYPE_ARC4 */
|
||||
|
||||
#if defined(PSA_WANT_KEY_TYPE_CAMELLIA)
|
||||
#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA)
|
||||
#define PSA_HAVE_SOFT_KEY_TYPE_CAMELLIA 1
|
||||
|
@ -591,16 +574,6 @@ extern "C" {
|
|||
#define PSA_WANT_ALG_TLS12_PSK_TO_MS 1
|
||||
#endif /* MBEDTLS_MD_C */
|
||||
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD2 1
|
||||
#define PSA_WANT_ALG_MD2 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD4 1
|
||||
#define PSA_WANT_ALG_MD4 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_MD5 1
|
||||
#define PSA_WANT_ALG_MD5 1
|
||||
|
@ -661,13 +634,6 @@ extern "C" {
|
|||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ARC4_C)
|
||||
#define PSA_WANT_KEY_TYPE_ARC4 1
|
||||
#define PSA_WANT_ALG_STREAM_CIPHER 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ARC4 1
|
||||
#define MBEDTLS_PSA_BUILTIN_ALG_STREAM_CIPHER 1
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
#define PSA_WANT_KEY_TYPE_CAMELLIA 1
|
||||
#define MBEDTLS_PSA_BUILTIN_KEY_TYPE_CAMELLIA 1
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
#ifndef MBEDTLS_CTR_DRBG_H
|
||||
#define MBEDTLS_CTR_DRBG_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -168,8 +169,8 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_ctr_drbg_context
|
||||
{
|
||||
unsigned char counter[16]; /*!< The counter (V). */
|
||||
int reseed_counter; /*!< The reseed counter.
|
||||
unsigned char MBEDTLS_PRIVATE(counter)[16]; /*!< The counter (V). */
|
||||
int MBEDTLS_PRIVATE(reseed_counter); /*!< The reseed counter.
|
||||
* This is the number of requests that have
|
||||
* been made since the last (re)seeding,
|
||||
* minus one.
|
||||
|
@ -179,25 +180,25 @@ typedef struct mbedtls_ctr_drbg_context
|
|||
* or -1 if no nonce length has been explicitly
|
||||
* set (see mbedtls_ctr_drbg_set_nonce_len()).
|
||||
*/
|
||||
int prediction_resistance; /*!< This determines whether prediction
|
||||
int MBEDTLS_PRIVATE(prediction_resistance); /*!< This determines whether prediction
|
||||
resistance is enabled, that is
|
||||
whether to systematically reseed before
|
||||
each random generation. */
|
||||
size_t entropy_len; /*!< The amount of entropy grabbed on each
|
||||
size_t MBEDTLS_PRIVATE(entropy_len); /*!< The amount of entropy grabbed on each
|
||||
seed or reseed operation, in bytes. */
|
||||
int reseed_interval; /*!< The reseed interval.
|
||||
int MBEDTLS_PRIVATE(reseed_interval); /*!< The reseed interval.
|
||||
* This is the maximum number of requests
|
||||
* that can be made between reseedings. */
|
||||
|
||||
mbedtls_aes_context aes_ctx; /*!< The AES context. */
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(aes_ctx); /*!< The AES context. */
|
||||
|
||||
/*
|
||||
* Callbacks (Entropy)
|
||||
*/
|
||||
int (*f_entropy)(void *, unsigned char *, size_t);
|
||||
int (*MBEDTLS_PRIVATE(f_entropy))(void *, unsigned char *, size_t);
|
||||
/*!< The entropy callback function. */
|
||||
|
||||
void *p_entropy; /*!< The context for the entropy function. */
|
||||
void *MBEDTLS_PRIVATE(p_entropy); /*!< The context for the entropy function. */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized if and only if f_entropy != NULL.
|
||||
|
@ -207,7 +208,7 @@ typedef struct mbedtls_ctr_drbg_context
|
|||
* Note that this invariant may change without notice. Do not rely on it
|
||||
* and do not access the mutex directly in application code.
|
||||
*/
|
||||
mbedtls_threading_mutex_t mutex;
|
||||
mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex);
|
||||
#endif
|
||||
}
|
||||
mbedtls_ctr_drbg_context;
|
||||
|
@ -462,9 +463,9 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
|
|||
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
|
||||
* \return An error from the underlying AES cipher on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
size_t add_len );
|
||||
int mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional,
|
||||
size_t add_len );
|
||||
|
||||
/**
|
||||
* \brief This function updates a CTR_DRBG instance with additional
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_DES_H
|
||||
#define MBEDTLS_DES_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -60,7 +61,7 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_des_context
|
||||
{
|
||||
uint32_t sk[32]; /*!< DES subkeys */
|
||||
uint32_t MBEDTLS_PRIVATE(sk)[32]; /*!< DES subkeys */
|
||||
}
|
||||
mbedtls_des_context;
|
||||
|
||||
|
@ -69,7 +70,7 @@ mbedtls_des_context;
|
|||
*/
|
||||
typedef struct mbedtls_des3_context
|
||||
{
|
||||
uint32_t sk[96]; /*!< 3DES subkeys */
|
||||
uint32_t MBEDTLS_PRIVATE(sk)[96]; /*!< 3DES subkeys */
|
||||
}
|
||||
mbedtls_des3_context;
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
#ifndef MBEDTLS_DHM_H
|
||||
#define MBEDTLS_DHM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -84,6 +85,17 @@
|
|||
#define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */
|
||||
#define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */
|
||||
|
||||
/** Which parameter to access in mbedtls_dhm_get_value(). */
|
||||
typedef enum
|
||||
{
|
||||
MBEDTLS_DHM_PARAM_P, /*!< The prime modulus. */
|
||||
MBEDTLS_DHM_PARAM_G, /*!< The generator. */
|
||||
MBEDTLS_DHM_PARAM_X, /*!< Our secret value. */
|
||||
MBEDTLS_DHM_PARAM_GX, /*!< Our public key = \c G^X mod \c P. */
|
||||
MBEDTLS_DHM_PARAM_GY, /*!< The public key of the peer = \c G^Y mod \c P. */
|
||||
MBEDTLS_DHM_PARAM_K, /*!< The shared secret = \c G^(XY) mod \c P. */
|
||||
} mbedtls_dhm_parameter;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -95,17 +107,16 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_dhm_context
|
||||
{
|
||||
size_t len; /*!< The size of \p P in Bytes. */
|
||||
mbedtls_mpi P; /*!< The prime modulus. */
|
||||
mbedtls_mpi G; /*!< The generator. */
|
||||
mbedtls_mpi X; /*!< Our secret value. */
|
||||
mbedtls_mpi GX; /*!< Our public key = \c G^X mod \c P. */
|
||||
mbedtls_mpi GY; /*!< The public key of the peer = \c G^Y mod \c P. */
|
||||
mbedtls_mpi K; /*!< The shared secret = \c G^(XY) mod \c P. */
|
||||
mbedtls_mpi RP; /*!< The cached value = \c R^2 mod \c P. */
|
||||
mbedtls_mpi Vi; /*!< The blinding value. */
|
||||
mbedtls_mpi Vf; /*!< The unblinding value. */
|
||||
mbedtls_mpi pX; /*!< The previous \c X. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(P); /*!< The prime modulus. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(G); /*!< The generator. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(X); /*!< Our secret value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(GX); /*!< Our public key = \c G^X mod \c P. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(GY); /*!< The public key of the peer = \c G^Y mod \c P. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(K); /*!< The shared secret = \c G^(XY) mod \c P. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(RP); /*!< The cached value = \c R^2 mod \c P. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Vi); /*!< The blinding value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Vf); /*!< The unblinding value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(pX); /*!< The previous \c X. */
|
||||
}
|
||||
mbedtls_dhm_context;
|
||||
|
||||
|
@ -268,10 +279,10 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
|
|||
* \param output_size The size of the destination buffer. This must be at
|
||||
* least the size of \c ctx->len (the size of \c P).
|
||||
* \param olen On exit, holds the actual number of Bytes written.
|
||||
* \param f_rng The RNG function, for blinding purposes. This may
|
||||
* b \c NULL if blinding isn't needed.
|
||||
* \param p_rng The RNG context. This may be \c NULL if \p f_rng
|
||||
* doesn't need a context argument.
|
||||
* \param f_rng The RNG function. Must not be \c NULL. Used for
|
||||
* blinding.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be
|
||||
* \c NULL if \p f_rng doesn't need a context parameter.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_DHM_XXX error code on failure.
|
||||
|
@ -281,6 +292,42 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx,
|
|||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief This function returns the size of the prime modulus in bits.
|
||||
*
|
||||
* \param ctx The DHM context to query.
|
||||
*
|
||||
* \return The size of the prime modulus in bits,
|
||||
* i.e. the number n such that 2^(n-1) <= P < 2^n.
|
||||
*/
|
||||
size_t mbedtls_dhm_get_bitlen( const mbedtls_dhm_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief This function returns the size of the prime modulus in bytes.
|
||||
*
|
||||
* \param ctx The DHM context to query.
|
||||
*
|
||||
* \return The size of the prime modulus in bytes,
|
||||
* i.e. the number n such that 2^(8*(n-1)) <= P < 2^(8*n).
|
||||
*/
|
||||
size_t mbedtls_dhm_get_len( const mbedtls_dhm_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief This function copies a parameter of a DHM key.
|
||||
*
|
||||
* \param ctx The DHM context to query.
|
||||
* \param param The parameter to copy.
|
||||
* \param dest The MPI object to copy the value into. It must be
|
||||
* initialized.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_DHM_BAD_INPUT_DATA if \p field is invalid.
|
||||
* \return An \c MBEDTLS_ERR_MPI_XXX error code if the copy fails.
|
||||
*/
|
||||
int mbedtls_dhm_get_value( const mbedtls_dhm_context *ctx,
|
||||
mbedtls_dhm_parameter param,
|
||||
mbedtls_mpi *dest );
|
||||
|
||||
/**
|
||||
* \brief This function frees and clears the components
|
||||
* of a DHM context.
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifndef MBEDTLS_ECDH_H
|
||||
#define MBEDTLS_ECDH_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -102,13 +103,13 @@ typedef enum
|
|||
*/
|
||||
typedef struct mbedtls_ecdh_context_mbed
|
||||
{
|
||||
mbedtls_ecp_group grp; /*!< The elliptic curve used. */
|
||||
mbedtls_mpi d; /*!< The private key. */
|
||||
mbedtls_ecp_point Q; /*!< The public key. */
|
||||
mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
|
||||
mbedtls_mpi z; /*!< The shared secret. */
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< The elliptic curve used. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< The private key. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Q); /*!< The public key. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Qp); /*!< The value of the public key of the peer. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(z); /*!< The shared secret. */
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */
|
||||
mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(rs); /*!< The restart context for EC computations. */
|
||||
#endif
|
||||
} mbedtls_ecdh_context_mbed;
|
||||
#endif
|
||||
|
@ -123,35 +124,35 @@ typedef struct mbedtls_ecdh_context_mbed
|
|||
typedef struct mbedtls_ecdh_context
|
||||
{
|
||||
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
|
||||
mbedtls_ecp_group grp; /*!< The elliptic curve used. */
|
||||
mbedtls_mpi d; /*!< The private key. */
|
||||
mbedtls_ecp_point Q; /*!< The public key. */
|
||||
mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
|
||||
mbedtls_mpi z; /*!< The shared secret. */
|
||||
int point_format; /*!< The format of point export in TLS messages. */
|
||||
mbedtls_ecp_point Vi; /*!< The blinding value. */
|
||||
mbedtls_ecp_point Vf; /*!< The unblinding value. */
|
||||
mbedtls_mpi _d; /*!< The previous \p d. */
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< The elliptic curve used. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< The private key. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Q); /*!< The public key. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Qp); /*!< The value of the public key of the peer. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(z); /*!< The shared secret. */
|
||||
int MBEDTLS_PRIVATE(point_format); /*!< The format of point export in TLS messages. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Vi); /*!< The blinding value. */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Vf); /*!< The unblinding value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(_d); /*!< The previous \p d. */
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
int restart_enabled; /*!< The flag for restartable mode. */
|
||||
mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */
|
||||
int MBEDTLS_PRIVATE(restart_enabled); /*!< The flag for restartable mode. */
|
||||
mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(rs); /*!< The restart context for EC computations. */
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
#else
|
||||
uint8_t point_format; /*!< The format of point export in TLS messages
|
||||
uint8_t MBEDTLS_PRIVATE(point_format); /*!< The format of point export in TLS messages
|
||||
as defined in RFC 4492. */
|
||||
mbedtls_ecp_group_id grp_id;/*!< The elliptic curve used. */
|
||||
mbedtls_ecdh_variant var; /*!< The ECDH implementation/structure used. */
|
||||
mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id);/*!< The elliptic curve used. */
|
||||
mbedtls_ecdh_variant MBEDTLS_PRIVATE(var); /*!< The ECDH implementation/structure used. */
|
||||
union
|
||||
{
|
||||
mbedtls_ecdh_context_mbed mbed_ecdh;
|
||||
mbedtls_ecdh_context_mbed MBEDTLS_PRIVATE(mbed_ecdh);
|
||||
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
|
||||
mbedtls_ecdh_context_everest everest_ecdh;
|
||||
mbedtls_ecdh_context_everest MBEDTLS_PRIVATE(everest_ecdh);
|
||||
#endif
|
||||
} ctx; /*!< Implementation-specific context. The
|
||||
} MBEDTLS_PRIVATE(ctx); /*!< Implementation-specific context. The
|
||||
context in use is specified by the \c var
|
||||
field. */
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
uint8_t restart_enabled; /*!< The flag for restartable mode. Functions of
|
||||
uint8_t MBEDTLS_PRIVATE(restart_enabled); /*!< The flag for restartable mode. Functions of
|
||||
an alternative implementation not supporting
|
||||
restartable mode must return
|
||||
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error
|
||||
|
@ -221,10 +222,7 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp
|
|||
* This must be initialized.
|
||||
* \param d Our secret exponent (private key).
|
||||
* This must be initialized.
|
||||
* \param f_rng The RNG function. This may be \c NULL if randomization
|
||||
* of intermediate results during the ECP computations is
|
||||
* not needed (discouraged). See the documentation of
|
||||
* mbedtls_ecp_mul() for more.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be
|
||||
* \c NULL if \p f_rng is \c NULL or doesn't need a
|
||||
* context argument.
|
||||
|
@ -427,8 +425,7 @@ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
|
|||
* \param buf The buffer to write the generated shared key to. This
|
||||
* must be a writable buffer of size \p blen Bytes.
|
||||
* \param blen The length of the destination buffer \p buf in Bytes.
|
||||
* \param f_rng The RNG function, for blinding purposes. This may
|
||||
* b \c NULL if blinding isn't needed.
|
||||
* \param f_rng The RNG function to use. This must not be \c NULL.
|
||||
* \param p_rng The RNG context. This may be \c NULL if \p f_rng
|
||||
* doesn't need a context argument.
|
||||
*
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#ifndef MBEDTLS_ECDSA_H
|
||||
#define MBEDTLS_ECDSA_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -107,12 +108,12 @@ typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and
|
||||
mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(ecp); /*!< base context for ECP restart and
|
||||
shared administrative info */
|
||||
mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */
|
||||
mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */
|
||||
mbedtls_ecdsa_restart_ver_ctx *MBEDTLS_PRIVATE(ver); /*!< ecdsa_verify() sub-context */
|
||||
mbedtls_ecdsa_restart_sig_ctx *MBEDTLS_PRIVATE(sig); /*!< ecdsa_sign() sub-context */
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */
|
||||
mbedtls_ecdsa_restart_det_ctx *MBEDTLS_PRIVATE(det); /*!< ecdsa_sign_det() sub-context */
|
||||
#endif
|
||||
} mbedtls_ecdsa_restart_ctx;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_ECJPAKE_H
|
||||
#define MBEDTLS_ECJPAKE_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
/*
|
||||
* J-PAKE is a password-authenticated key exchange that allows deriving a
|
||||
|
@ -73,21 +74,21 @@ typedef enum {
|
|||
*/
|
||||
typedef struct mbedtls_ecjpake_context
|
||||
{
|
||||
const mbedtls_md_info_t *md_info; /**< Hash to use */
|
||||
mbedtls_ecp_group grp; /**< Elliptic curve */
|
||||
mbedtls_ecjpake_role role; /**< Are we client or server? */
|
||||
int point_format; /**< Format for point export */
|
||||
const mbedtls_md_info_t *MBEDTLS_PRIVATE(md_info); /**< Hash to use */
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /**< Elliptic curve */
|
||||
mbedtls_ecjpake_role MBEDTLS_PRIVATE(role); /**< Are we client or server? */
|
||||
int MBEDTLS_PRIVATE(point_format); /**< Format for point export */
|
||||
|
||||
mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */
|
||||
mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */
|
||||
mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */
|
||||
mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */
|
||||
mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Xm1); /**< My public key 1 C: X1, S: X3 */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Xm2); /**< My public key 2 C: X2, S: X4 */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp1); /**< Peer public key 1 C: X3, S: X1 */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp2); /**< Peer public key 2 C: X4, S: X2 */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp); /**< Peer public key C: Xs, S: Xc */
|
||||
|
||||
mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */
|
||||
mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(xm1); /**< My private key 1 C: x1, S: x3 */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(xm2); /**< My private key 2 C: x2, S: x4 */
|
||||
|
||||
mbedtls_mpi s; /**< Pre-shared secret (passphrase) */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(s); /**< Pre-shared secret (passphrase) */
|
||||
} mbedtls_ecjpake_context;
|
||||
|
||||
#else /* MBEDTLS_ECJPAKE_ALT */
|
||||
|
@ -130,6 +131,21 @@ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
|
|||
const unsigned char *secret,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* \brief Set the point format for future reads and writes.
|
||||
*
|
||||
* \param ctx The ECJPAKE context to configure.
|
||||
* \param point_format The point format to use:
|
||||
* #MBEDTLS_ECP_PF_UNCOMPRESSED (default)
|
||||
* or #MBEDTLS_ECP_PF_COMPRESSED.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p point_format
|
||||
* is invalid.
|
||||
*/
|
||||
int mbedtls_ecjpake_set_point_format( mbedtls_ecjpake_context *ctx,
|
||||
int point_format );
|
||||
|
||||
/**
|
||||
* \brief Check if an ECJPAKE context is ready for use.
|
||||
*
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#ifndef MBEDTLS_ECP_H
|
||||
#define MBEDTLS_ECP_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -92,6 +93,7 @@ extern "C" {
|
|||
* - Add it at the end of this enum, otherwise you'll break the ABI by
|
||||
* changing the numerical value for existing curves.
|
||||
* - Increment MBEDTLS_ECP_DP_MAX below if needed.
|
||||
* - Update the calculation of MBEDTLS_ECP_MAX_BITS below.
|
||||
* - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to
|
||||
* config.h.
|
||||
* - List the curve as a dependency of MBEDTLS_ECP_C and
|
||||
|
@ -100,7 +102,8 @@ extern "C" {
|
|||
* MBEDTLS_ECP_yyy_ENABLED above.
|
||||
* - Add the necessary definitions to ecp_curves.c.
|
||||
* - Add the curve to the ecp_supported_curves array in ecp.c.
|
||||
* - Add the curve to applicable profiles in x509_crt.c if applicable.
|
||||
* - Add the curve to applicable profiles in x509_crt.c.
|
||||
* - Add the curve to applicable presets in ssl_tls.c.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
|
@ -142,10 +145,10 @@ typedef enum
|
|||
*/
|
||||
typedef struct mbedtls_ecp_curve_info
|
||||
{
|
||||
mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */
|
||||
uint16_t tls_id; /*!< The TLS NamedCurve identifier. */
|
||||
uint16_t bit_size; /*!< The curve size in bits. */
|
||||
const char *name; /*!< A human-friendly name. */
|
||||
mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id); /*!< An internal identifier. */
|
||||
uint16_t MBEDTLS_PRIVATE(tls_id); /*!< The TLS NamedCurve identifier. */
|
||||
uint16_t MBEDTLS_PRIVATE(bit_size); /*!< The curve size in bits. */
|
||||
const char *MBEDTLS_PRIVATE(name); /*!< A human-friendly name. */
|
||||
} mbedtls_ecp_curve_info;
|
||||
|
||||
/**
|
||||
|
@ -161,9 +164,9 @@ typedef struct mbedtls_ecp_curve_info
|
|||
*/
|
||||
typedef struct mbedtls_ecp_point
|
||||
{
|
||||
mbedtls_mpi X; /*!< The X coordinate of the ECP point. */
|
||||
mbedtls_mpi Y; /*!< The Y coordinate of the ECP point. */
|
||||
mbedtls_mpi Z; /*!< The Z coordinate of the ECP point. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(X); /*!< The X coordinate of the ECP point. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Y); /*!< The Y coordinate of the ECP point. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Z); /*!< The Z coordinate of the ECP point. */
|
||||
}
|
||||
mbedtls_ecp_point;
|
||||
|
||||
|
@ -203,10 +206,16 @@ mbedtls_ecp_point;
|
|||
* additions or subtractions. Therefore, it is only an approximative modular
|
||||
* reduction. It must return 0 on success and non-zero on failure.
|
||||
*
|
||||
* \note Alternative implementations must keep the group IDs distinct. If
|
||||
* two group structures have the same ID, then they must be
|
||||
* identical.
|
||||
*
|
||||
* \note Alternative implementations of the ECP module must obey the
|
||||
* following constraints.
|
||||
* * Group IDs must be distinct: if two group structures have
|
||||
* the same ID, then they must be identical.
|
||||
* * The fields \c id, \c P, \c A, \c B, \c G, \c N,
|
||||
* \c pbits and \c nbits must have the same type and semantics
|
||||
* as in the built-in implementation.
|
||||
* They must be available for reading, but direct modification
|
||||
* of these fields does not need to be supported.
|
||||
* They do not need to be at the same offset in the structure.
|
||||
*/
|
||||
typedef struct mbedtls_ecp_group
|
||||
{
|
||||
|
@ -222,14 +231,16 @@ typedef struct mbedtls_ecp_group
|
|||
size_t nbits; /*!< For Short Weierstrass: The number of bits in \p P.
|
||||
For Montgomery curves: the number of bits in the
|
||||
private keys. */
|
||||
unsigned int h; /*!< \internal 1 if the constants are static. */
|
||||
int (*modp)(mbedtls_mpi *); /*!< The function for fast pseudo-reduction
|
||||
/* End of public fields */
|
||||
|
||||
unsigned int MBEDTLS_PRIVATE(h); /*!< \internal 1 if the constants are static. */
|
||||
int (*MBEDTLS_PRIVATE(modp))(mbedtls_mpi *); /*!< The function for fast pseudo-reduction
|
||||
mod \p P (see above).*/
|
||||
int (*t_pre)(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
int (*t_post)(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
void *t_data; /*!< Unused. */
|
||||
mbedtls_ecp_point *T; /*!< Pre-computed points for ecp_mul_comb(). */
|
||||
size_t T_size; /*!< The number of dynamic allocated pre-computed points. */
|
||||
int (*MBEDTLS_PRIVATE(t_pre))(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
int (*MBEDTLS_PRIVATE(t_post))(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
void *MBEDTLS_PRIVATE(t_data); /*!< Unused. */
|
||||
mbedtls_ecp_point *MBEDTLS_PRIVATE(T); /*!< Pre-computed points for ecp_mul_comb(). */
|
||||
size_t MBEDTLS_PRIVATE(T_size); /*!< The number of dynamic allocated pre-computed points. */
|
||||
}
|
||||
mbedtls_ecp_group;
|
||||
|
||||
|
@ -241,16 +252,6 @@ mbedtls_ecp_group;
|
|||
* \{
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_ECP_MAX_BITS)
|
||||
/**
|
||||
* The maximum size of the groups, that is, of \c N and \c P.
|
||||
*/
|
||||
#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
|
||||
#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
|
||||
|
||||
#if !defined(MBEDTLS_ECP_WINDOW_SIZE)
|
||||
/*
|
||||
* Maximum "window" size used for point multiplication.
|
||||
|
@ -296,6 +297,47 @@ mbedtls_ecp_group;
|
|||
#include "ecp_alt.h"
|
||||
#endif /* MBEDTLS_ECP_ALT */
|
||||
|
||||
/**
|
||||
* The maximum size of the groups, that is, of \c N and \c P.
|
||||
*/
|
||||
#if !defined(MBEDTLS_ECP_C)
|
||||
/* Dummy definition to help code that has optional ECP support and
|
||||
* defines an MBEDTLS_ECP_MAX_BYTES-sized array unconditionally. */
|
||||
#define MBEDTLS_ECP_MAX_BITS 1
|
||||
/* Note: the curves must be listed in DECREASING size! */
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 521
|
||||
#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 512
|
||||
#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 448
|
||||
#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 384
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 384
|
||||
#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 256
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 256
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 256
|
||||
#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 255
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 225 // n is slightly above 2^224
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 224
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 192
|
||||
#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
|
||||
#define MBEDTLS_ECP_MAX_BITS 192
|
||||
#else
|
||||
#error "Missing definition of MBEDTLS_ECP_MAX_BITS"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
|
||||
#define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
|
||||
/**
|
||||
|
@ -317,10 +359,10 @@ typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned ops_done; /*!< current ops count */
|
||||
unsigned depth; /*!< call depth (0 = top-level) */
|
||||
mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */
|
||||
mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */
|
||||
unsigned MBEDTLS_PRIVATE(ops_done); /*!< current ops count */
|
||||
unsigned MBEDTLS_PRIVATE(depth); /*!< call depth (0 = top-level) */
|
||||
mbedtls_ecp_restart_mul_ctx *MBEDTLS_PRIVATE(rsm); /*!< ecp_mul_comb() sub-context */
|
||||
mbedtls_ecp_restart_muladd_ctx *MBEDTLS_PRIVATE(ma); /*!< ecp_muladd() sub-context */
|
||||
} mbedtls_ecp_restart_ctx;
|
||||
|
||||
/*
|
||||
|
@ -370,9 +412,9 @@ typedef void mbedtls_ecp_restart_ctx;
|
|||
*/
|
||||
typedef struct mbedtls_ecp_keypair
|
||||
{
|
||||
mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
|
||||
mbedtls_mpi d; /*!< our secret value */
|
||||
mbedtls_ecp_point Q; /*!< our public value */
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< Elliptic curve and base point */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< our secret value */
|
||||
mbedtls_ecp_point MBEDTLS_PRIVATE(Q); /*!< our public value */
|
||||
}
|
||||
mbedtls_ecp_keypair;
|
||||
|
||||
|
@ -869,15 +911,8 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
|
|||
* \note To prevent timing attacks, this function
|
||||
* executes the exact same sequence of base-field
|
||||
* operations for any valid \p m. It avoids any if-branch or
|
||||
* array index depending on the value of \p m.
|
||||
*
|
||||
* \note If \p f_rng is not NULL, it is used to randomize
|
||||
* intermediate results to prevent potential timing attacks
|
||||
* targeting these results. We recommend always providing
|
||||
* a non-NULL \p f_rng. The overhead is negligible.
|
||||
* Note: unless #MBEDTLS_ECP_NO_INTERNAL_RNG is defined, when
|
||||
* \p f_rng is NULL, an internal RNG (seeded from the value
|
||||
* of \p m) will be used instead.
|
||||
* array index depending on the value of \p m. If also uses
|
||||
* \p f_rng to randomize some intermediate results.
|
||||
*
|
||||
* \param grp The ECP group to use.
|
||||
* This must be initialized and have group parameters
|
||||
|
@ -886,9 +921,9 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
|
|||
* This must be initialized.
|
||||
* \param m The integer by which to multiply. This must be initialized.
|
||||
* \param P The point to multiply. This must be initialized.
|
||||
* \param f_rng The RNG function. This may be \c NULL if randomization
|
||||
* of intermediate results isn't desired (discouraged).
|
||||
* \param p_rng The RNG context to be passed to \p p_rng.
|
||||
* \param f_rng The RNG function. This must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be \c
|
||||
* NULL if \p f_rng doesn't need a context.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private
|
||||
|
@ -917,9 +952,9 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
|||
* This must be initialized.
|
||||
* \param m The integer by which to multiply. This must be initialized.
|
||||
* \param P The point to multiply. This must be initialized.
|
||||
* \param f_rng The RNG function. This may be \c NULL if randomization
|
||||
* of intermediate results isn't desired (discouraged).
|
||||
* \param p_rng The RNG context to be passed to \p p_rng.
|
||||
* \param f_rng The RNG function. This must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be \c
|
||||
* NULL if \p f_rng doesn't need a context.
|
||||
* \param rs_ctx The restart context (NULL disables restart).
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
|
@ -1223,14 +1258,18 @@ int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
|
|||
* part is ignored.
|
||||
* \param prv The keypair structure holding the full keypair.
|
||||
* This must be initialized.
|
||||
* \param f_rng The RNG function. This must not be \c NULL.
|
||||
* \param p_rng The RNG context to be passed to \p f_rng. This may be \c
|
||||
* NULL if \p f_rng doesn't need a context.
|
||||
*
|
||||
* \return \c 0 on success, meaning that the keys are valid and match.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX
|
||||
* error code on calculation failure.
|
||||
*/
|
||||
int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub,
|
||||
const mbedtls_ecp_keypair *prv );
|
||||
int mbedtls_ecp_check_pub_priv(
|
||||
const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_ENTROPY_H
|
||||
#define MBEDTLS_ENTROPY_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -104,11 +105,11 @@ typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, s
|
|||
*/
|
||||
typedef struct mbedtls_entropy_source_state
|
||||
{
|
||||
mbedtls_entropy_f_source_ptr f_source; /**< The entropy source callback */
|
||||
void * p_source; /**< The callback data pointer */
|
||||
size_t size; /**< Amount received in bytes */
|
||||
size_t threshold; /**< Minimum bytes required before release */
|
||||
int strong; /**< Is the source strong? */
|
||||
mbedtls_entropy_f_source_ptr MBEDTLS_PRIVATE(f_source); /**< The entropy source callback */
|
||||
void * MBEDTLS_PRIVATE(p_source); /**< The callback data pointer */
|
||||
size_t MBEDTLS_PRIVATE(size); /**< Amount received in bytes */
|
||||
size_t MBEDTLS_PRIVATE(threshold); /**< Minimum bytes required before release */
|
||||
int MBEDTLS_PRIVATE(strong); /**< Is the source strong? */
|
||||
}
|
||||
mbedtls_entropy_source_state;
|
||||
|
||||
|
@ -117,21 +118,21 @@ mbedtls_entropy_source_state;
|
|||
*/
|
||||
typedef struct mbedtls_entropy_context
|
||||
{
|
||||
int accumulator_started; /* 0 after init.
|
||||
int MBEDTLS_PRIVATE(accumulator_started); /* 0 after init.
|
||||
* 1 after the first update.
|
||||
* -1 after free. */
|
||||
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
||||
mbedtls_sha512_context accumulator;
|
||||
mbedtls_sha512_context MBEDTLS_PRIVATE(accumulator);
|
||||
#else
|
||||
mbedtls_sha256_context accumulator;
|
||||
mbedtls_sha256_context MBEDTLS_PRIVATE(accumulator);
|
||||
#endif
|
||||
int source_count; /* Number of entries used in source. */
|
||||
mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
|
||||
int MBEDTLS_PRIVATE(source_count); /* Number of entries used in source. */
|
||||
mbedtls_entropy_source_state MBEDTLS_PRIVATE(source)[MBEDTLS_ENTROPY_MAX_SOURCES];
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
mbedtls_threading_mutex_t mutex; /*!< mutex */
|
||||
mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); /*!< mutex */
|
||||
#endif
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
int initial_entropy_run;
|
||||
int MBEDTLS_PRIVATE(initial_entropy_run);
|
||||
#endif
|
||||
}
|
||||
mbedtls_entropy_context;
|
||||
|
|
|
@ -61,11 +61,9 @@
|
|||
* ERROR 2 0x006E 0x0001
|
||||
* MPI 7 0x0002-0x0010
|
||||
* GCM 3 0x0012-0x0014 0x0013-0x0013
|
||||
* BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
|
||||
* THREADING 3 0x001A-0x001E
|
||||
* AES 5 0x0020-0x0022 0x0021-0x0025
|
||||
* CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
|
||||
* XTEA 2 0x0028-0x0028 0x0029-0x0029
|
||||
* BASE64 2 0x002A-0x002C
|
||||
* OID 1 0x002E-0x002E 0x000B-0x000B
|
||||
* PADLOCK 1 0x0030-0x0030
|
||||
|
@ -79,9 +77,6 @@
|
|||
* PBKDF2 1 0x007C-0x007C
|
||||
* HMAC_DRBG 4 0x0003-0x0009
|
||||
* CCM 3 0x000D-0x0011
|
||||
* ARC4 1 0x0019-0x0019
|
||||
* MD2 1 0x002B-0x002B
|
||||
* MD4 1 0x002D-0x002D
|
||||
* MD5 1 0x002F-0x002F
|
||||
* RIPEMD160 1 0x0031-0x0031
|
||||
* SHA1 1 0x0035-0x0035 0x0073-0x0073
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#ifndef MBEDTLS_GCM_H
|
||||
#define MBEDTLS_GCM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -58,15 +59,15 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_gcm_context
|
||||
{
|
||||
mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
|
||||
uint64_t HL[16]; /*!< Precalculated HTable low. */
|
||||
uint64_t HH[16]; /*!< Precalculated HTable high. */
|
||||
uint64_t len; /*!< The total length of the encrypted data. */
|
||||
uint64_t add_len; /*!< The total length of the additional data. */
|
||||
unsigned char base_ectr[16]; /*!< The first ECTR for tag. */
|
||||
unsigned char y[16]; /*!< The Y working value. */
|
||||
unsigned char buf[16]; /*!< The buf working value. */
|
||||
int mode; /*!< The operation to perform:
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
uint64_t MBEDTLS_PRIVATE(HL)[16]; /*!< Precalculated HTable low. */
|
||||
uint64_t MBEDTLS_PRIVATE(HH)[16]; /*!< Precalculated HTable high. */
|
||||
uint64_t MBEDTLS_PRIVATE(len); /*!< The total length of the encrypted data. */
|
||||
uint64_t MBEDTLS_PRIVATE(add_len); /*!< The total length of the additional data. */
|
||||
unsigned char MBEDTLS_PRIVATE(base_ectr)[16]; /*!< The first ECTR for tag. */
|
||||
unsigned char MBEDTLS_PRIVATE(y)[16]; /*!< The Y working value. */
|
||||
unsigned char MBEDTLS_PRIVATE(buf)[16]; /*!< The buf working value. */
|
||||
int MBEDTLS_PRIVATE(mode); /*!< The operation to perform:
|
||||
#MBEDTLS_GCM_ENCRYPT or
|
||||
#MBEDTLS_GCM_DECRYPT. */
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_HMAC_DRBG_H
|
||||
#define MBEDTLS_HMAC_DRBG_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -86,19 +87,19 @@ typedef struct mbedtls_hmac_drbg_context
|
|||
{
|
||||
/* Working state: the key K is not stored explicitly,
|
||||
* but is implied by the HMAC context */
|
||||
mbedtls_md_context_t md_ctx; /*!< HMAC context (inc. K) */
|
||||
unsigned char V[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
|
||||
int reseed_counter; /*!< reseed counter */
|
||||
mbedtls_md_context_t MBEDTLS_PRIVATE(md_ctx); /*!< HMAC context (inc. K) */
|
||||
unsigned char MBEDTLS_PRIVATE(V)[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
|
||||
int MBEDTLS_PRIVATE(reseed_counter); /*!< reseed counter */
|
||||
|
||||
/* Administrative state */
|
||||
size_t entropy_len; /*!< entropy bytes grabbed on each (re)seed */
|
||||
int prediction_resistance; /*!< enable prediction resistance (Automatic
|
||||
size_t MBEDTLS_PRIVATE(entropy_len); /*!< entropy bytes grabbed on each (re)seed */
|
||||
int MBEDTLS_PRIVATE(prediction_resistance); /*!< enable prediction resistance (Automatic
|
||||
reseed before every random generation) */
|
||||
int reseed_interval; /*!< reseed interval */
|
||||
int MBEDTLS_PRIVATE(reseed_interval); /*!< reseed interval */
|
||||
|
||||
/* Callbacks */
|
||||
int (*f_entropy)(void *, unsigned char *, size_t); /*!< entropy function */
|
||||
void *p_entropy; /*!< context for the entropy function */
|
||||
int (*MBEDTLS_PRIVATE(f_entropy))(void *, unsigned char *, size_t); /*!< entropy function */
|
||||
void *MBEDTLS_PRIVATE(p_entropy); /*!< context for the entropy function */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized if and only if
|
||||
|
@ -109,7 +110,7 @@ typedef struct mbedtls_hmac_drbg_context
|
|||
* Note that this invariant may change without notice. Do not rely on it
|
||||
* and do not access the mutex directly in application code.
|
||||
*/
|
||||
mbedtls_threading_mutex_t mutex;
|
||||
mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex);
|
||||
#endif
|
||||
} mbedtls_hmac_drbg_context;
|
||||
|
||||
|
@ -294,8 +295,8 @@ void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
|
|||
* \return \c 0 on success, or an error from the underlying
|
||||
* hash calculation.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t add_len );
|
||||
int mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t add_len );
|
||||
|
||||
/**
|
||||
* \brief This function reseeds the HMAC_DRBG context, that is
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#ifndef MBEDTLS_MD_H
|
||||
#define MBEDTLS_MD_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -45,15 +46,13 @@ extern "C" {
|
|||
/**
|
||||
* \brief Supported message digests.
|
||||
*
|
||||
* \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
|
||||
* \warning MD5 and SHA-1 are considered weak message digests and
|
||||
* their use constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
MBEDTLS_MD_NONE=0, /**< None. */
|
||||
MBEDTLS_MD_MD2, /**< The MD2 message digest. */
|
||||
MBEDTLS_MD_MD4, /**< The MD4 message digest. */
|
||||
MBEDTLS_MD_MD5, /**< The MD5 message digest. */
|
||||
MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */
|
||||
MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */
|
||||
|
@ -93,13 +92,13 @@ typedef struct mbedtls_md_info_t mbedtls_md_info_t;
|
|||
typedef struct mbedtls_md_context_t
|
||||
{
|
||||
/** Information about the associated message digest. */
|
||||
const mbedtls_md_info_t *md_info;
|
||||
const mbedtls_md_info_t *MBEDTLS_PRIVATE(md_info);
|
||||
|
||||
/** The digest-specific context. */
|
||||
void *md_ctx;
|
||||
void *MBEDTLS_PRIVATE(md_ctx);
|
||||
|
||||
/** The HMAC part of the context. */
|
||||
void *hmac_ctx;
|
||||
void *MBEDTLS_PRIVATE(hmac_ctx);
|
||||
} mbedtls_md_context_t;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
/**
|
||||
* \file md2.h
|
||||
*
|
||||
* \brief MD2 message digest algorithm (hash function)
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use constitutes a
|
||||
* security risk. We recommend considering stronger message digests
|
||||
* instead.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef MBEDTLS_MD2_H
|
||||
#define MBEDTLS_MD2_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD2_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief MD2 context structure
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
typedef struct mbedtls_md2_context
|
||||
{
|
||||
unsigned char cksum[16]; /*!< checksum of the data block */
|
||||
unsigned char state[48]; /*!< intermediate digest state */
|
||||
unsigned char buffer[16]; /*!< data block being processed */
|
||||
size_t left; /*!< amount of data in buffer */
|
||||
}
|
||||
mbedtls_md2_context;
|
||||
|
||||
#else /* MBEDTLS_MD2_ALT */
|
||||
#include "md2_alt.h"
|
||||
#endif /* MBEDTLS_MD2_ALT */
|
||||
|
||||
/**
|
||||
* \brief Initialize MD2 context
|
||||
*
|
||||
* \param ctx MD2 context to be initialized
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md2_init( mbedtls_md2_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear MD2 context
|
||||
*
|
||||
* \param ctx MD2 context to be cleared
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md2_free( mbedtls_md2_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clone (the state of) an MD2 context
|
||||
*
|
||||
* \param dst The destination context
|
||||
* \param src The context to be cloned
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md2_clone( mbedtls_md2_context *dst,
|
||||
const mbedtls_md2_context *src );
|
||||
|
||||
/**
|
||||
* \brief MD2 context setup
|
||||
*
|
||||
* \param ctx context to be initialized
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief MD2 process buffer
|
||||
*
|
||||
* \param ctx MD2 context
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief MD2 final digest
|
||||
*
|
||||
* \param ctx MD2 context
|
||||
* \param output MD2 checksum result
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief MD2 process data block (internal use only)
|
||||
*
|
||||
* \param ctx MD2 context
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Output = MD2( input buffer )
|
||||
*
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* \param output MD2 checksum result
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md2_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*
|
||||
* \warning MD2 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md2_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* mbedtls_md2.h */
|
|
@ -1,206 +0,0 @@
|
|||
/**
|
||||
* \file md4.h
|
||||
*
|
||||
* \brief MD4 message digest algorithm (hash function)
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use constitutes a
|
||||
* security risk. We recommend considering stronger message digests
|
||||
* instead.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
#ifndef MBEDTLS_MD4_H
|
||||
#define MBEDTLS_MD4_H
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_MD4_ALT)
|
||||
// Regular implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief MD4 context structure
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
typedef struct mbedtls_md4_context
|
||||
{
|
||||
uint32_t total[2]; /*!< number of bytes processed */
|
||||
uint32_t state[4]; /*!< intermediate digest state */
|
||||
unsigned char buffer[64]; /*!< data block being processed */
|
||||
}
|
||||
mbedtls_md4_context;
|
||||
|
||||
#else /* MBEDTLS_MD4_ALT */
|
||||
#include "md4_alt.h"
|
||||
#endif /* MBEDTLS_MD4_ALT */
|
||||
|
||||
/**
|
||||
* \brief Initialize MD4 context
|
||||
*
|
||||
* \param ctx MD4 context to be initialized
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md4_init( mbedtls_md4_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear MD4 context
|
||||
*
|
||||
* \param ctx MD4 context to be cleared
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md4_free( mbedtls_md4_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clone (the state of) an MD4 context
|
||||
*
|
||||
* \param dst The destination context
|
||||
* \param src The context to be cloned
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
void mbedtls_md4_clone( mbedtls_md4_context *dst,
|
||||
const mbedtls_md4_context *src );
|
||||
|
||||
/**
|
||||
* \brief MD4 context setup
|
||||
*
|
||||
* \param ctx context to be initialized
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*/
|
||||
int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief MD4 process buffer
|
||||
*
|
||||
* \param ctx MD4 context
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief MD4 final digest
|
||||
*
|
||||
* \param ctx MD4 context
|
||||
* \param output MD4 checksum result
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief MD4 process data block (internal use only)
|
||||
*
|
||||
* \param ctx MD4 context
|
||||
* \param data buffer holding one block of data
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
|
||||
const unsigned char data[64] );
|
||||
|
||||
/**
|
||||
* \brief Output = MD4( input buffer )
|
||||
*
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* \param output MD4 checksum result
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md4_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*
|
||||
* \warning MD4 is considered a weak message digest and its use
|
||||
* constitutes a security risk. We recommend considering
|
||||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md4_self_test( int verbose );
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* mbedtls_md4.h */
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_MD5_H
|
||||
#define MBEDTLS_MD5_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -53,9 +54,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_md5_context
|
||||
{
|
||||
uint32_t total[2]; /*!< number of bytes processed */
|
||||
uint32_t state[4]; /*!< intermediate digest state */
|
||||
unsigned char buffer[64]; /*!< data block being processed */
|
||||
uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
|
||||
uint32_t MBEDTLS_PRIVATE(state)[4]; /*!< intermediate digest state */
|
||||
unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
|
||||
}
|
||||
mbedtls_md5_context;
|
||||
|
||||
|
@ -113,7 +114,7 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
|
|||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
|
||||
int mbedtls_md5_starts( mbedtls_md5_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief MD5 process buffer
|
||||
|
@ -129,9 +130,9 @@ int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
|
|||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
int mbedtls_md5_update( mbedtls_md5_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief MD5 final digest
|
||||
|
@ -146,8 +147,8 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
|
|||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
|
||||
unsigned char output[16] );
|
||||
int mbedtls_md5_finish( mbedtls_md5_context *ctx,
|
||||
unsigned char output[16] );
|
||||
|
||||
/**
|
||||
* \brief MD5 process data block (internal use only)
|
||||
|
@ -179,9 +180,9 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
|
|||
* stronger message digests instead.
|
||||
*
|
||||
*/
|
||||
int mbedtls_md5_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] );
|
||||
int mbedtls_md5( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_NET_SOCKETS_H
|
||||
#define MBEDTLS_NET_SOCKETS_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -84,7 +85,7 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_net_context
|
||||
{
|
||||
int fd; /**< The underlying file descriptor */
|
||||
int MBEDTLS_PRIVATE(fd); /**< The underlying file descriptor */
|
||||
}
|
||||
mbedtls_net_context;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#ifndef MBEDTLS_NIST_KW_H
|
||||
#define MBEDTLS_NIST_KW_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -65,7 +66,7 @@ typedef enum
|
|||
* Don't make any assumptions on this context!
|
||||
*/
|
||||
typedef struct {
|
||||
mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
} mbedtls_nist_kw_context;
|
||||
|
||||
#else /* MBEDTLS_NIST_key wrapping_ALT */
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_OID_H
|
||||
#define MBEDTLS_OID_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -230,8 +231,6 @@
|
|||
* PKCS#1 OIDs
|
||||
*/
|
||||
#define MBEDTLS_OID_PKCS1_RSA MBEDTLS_OID_PKCS1 "\x01" /**< rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 } */
|
||||
#define MBEDTLS_OID_PKCS1_MD2 MBEDTLS_OID_PKCS1 "\x02" /**< md2WithRSAEncryption ::= { pkcs-1 2 } */
|
||||
#define MBEDTLS_OID_PKCS1_MD4 MBEDTLS_OID_PKCS1 "\x03" /**< md4WithRSAEncryption ::= { pkcs-1 3 } */
|
||||
#define MBEDTLS_OID_PKCS1_MD5 MBEDTLS_OID_PKCS1 "\x04" /**< md5WithRSAEncryption ::= { pkcs-1 4 } */
|
||||
#define MBEDTLS_OID_PKCS1_SHA1 MBEDTLS_OID_PKCS1 "\x05" /**< sha1WithRSAEncryption ::= { pkcs-1 5 } */
|
||||
#define MBEDTLS_OID_PKCS1_SHA224 MBEDTLS_OID_PKCS1 "\x0e" /**< sha224WithRSAEncryption ::= { pkcs-1 14 } */
|
||||
|
@ -250,8 +249,6 @@
|
|||
/*
|
||||
* Digest algorithms
|
||||
*/
|
||||
#define MBEDTLS_OID_DIGEST_ALG_MD2 MBEDTLS_OID_RSA_COMPANY "\x02\x02" /**< id-mbedtls_md2 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2 } */
|
||||
#define MBEDTLS_OID_DIGEST_ALG_MD4 MBEDTLS_OID_RSA_COMPANY "\x02\x04" /**< id-mbedtls_md4 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 4 } */
|
||||
#define MBEDTLS_OID_DIGEST_ALG_MD5 MBEDTLS_OID_RSA_COMPANY "\x02\x05" /**< id-mbedtls_md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5 } */
|
||||
#define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */
|
||||
#define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_NIST_ALG "\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */
|
||||
|
@ -302,8 +299,6 @@
|
|||
/*
|
||||
* PKCS#5 PBES1 algorithms
|
||||
*/
|
||||
#define MBEDTLS_OID_PKCS5_PBE_MD2_DES_CBC MBEDTLS_OID_PKCS5 "\x01" /**< pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1} */
|
||||
#define MBEDTLS_OID_PKCS5_PBE_MD2_RC2_CBC MBEDTLS_OID_PKCS5 "\x04" /**< pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4} */
|
||||
#define MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC MBEDTLS_OID_PKCS5 "\x03" /**< pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3} */
|
||||
#define MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC MBEDTLS_OID_PKCS5 "\x06" /**< pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6} */
|
||||
#define MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC MBEDTLS_OID_PKCS5 "\x0a" /**< pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10} */
|
||||
|
@ -319,8 +314,6 @@
|
|||
*/
|
||||
#define MBEDTLS_OID_PKCS12_PBE MBEDTLS_OID_PKCS12 "\x01" /**< pkcs-12PbeIds OBJECT IDENTIFIER ::= {pkcs-12 1} */
|
||||
|
||||
#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_128 MBEDTLS_OID_PKCS12_PBE "\x01" /**< pbeWithSHAAnd128BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 1} */
|
||||
#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_40 MBEDTLS_OID_PKCS12_PBE "\x02" /**< pbeWithSHAAnd40BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 2} */
|
||||
#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x03" /**< pbeWithSHAAnd3-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 3} */
|
||||
#define MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x04" /**< pbeWithSHAAnd2-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 4} */
|
||||
#define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC MBEDTLS_OID_PKCS12_PBE "\x05" /**< pbeWithSHAAnd128BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 5} */
|
||||
|
@ -440,11 +433,11 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_oid_descriptor_t
|
||||
{
|
||||
const char *asn1; /*!< OID ASN.1 representation */
|
||||
size_t asn1_len; /*!< length of asn1 */
|
||||
const char *MBEDTLS_PRIVATE(asn1); /*!< OID ASN.1 representation */
|
||||
size_t MBEDTLS_PRIVATE(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 */
|
||||
const char *MBEDTLS_PRIVATE(name); /*!< official name (e.g. from RFC) */
|
||||
const char *MBEDTLS_PRIVATE(description); /*!< human friendly description */
|
||||
#endif
|
||||
} mbedtls_oid_descriptor_t;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_PEM_H
|
||||
#define MBEDTLS_PEM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -57,9 +58,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_pem_context
|
||||
{
|
||||
unsigned char *buf; /*!< buffer for decoded data */
|
||||
size_t buflen; /*!< length of the buffer */
|
||||
unsigned char *info; /*!< buffer for extra header information */
|
||||
unsigned char *MBEDTLS_PRIVATE(buf); /*!< buffer for decoded data */
|
||||
size_t MBEDTLS_PRIVATE(buflen); /*!< length of the buffer */
|
||||
unsigned char *MBEDTLS_PRIVATE(info); /*!< buffer for extra header information */
|
||||
}
|
||||
mbedtls_pem_context;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#ifndef MBEDTLS_PK_H
|
||||
#define MBEDTLS_PK_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -91,8 +92,8 @@ typedef enum {
|
|||
*/
|
||||
typedef struct mbedtls_pk_rsassa_pss_options
|
||||
{
|
||||
mbedtls_md_type_t mgf1_hash_id;
|
||||
int expected_salt_len;
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(mgf1_hash_id);
|
||||
int MBEDTLS_PRIVATE(expected_salt_len);
|
||||
|
||||
} mbedtls_pk_rsassa_pss_options;
|
||||
|
||||
|
@ -163,9 +164,9 @@ typedef enum
|
|||
*/
|
||||
typedef struct mbedtls_pk_debug_item
|
||||
{
|
||||
mbedtls_pk_debug_type type;
|
||||
const char *name;
|
||||
void *value;
|
||||
mbedtls_pk_debug_type MBEDTLS_PRIVATE(type);
|
||||
const char *MBEDTLS_PRIVATE(name);
|
||||
void *MBEDTLS_PRIVATE(value);
|
||||
} mbedtls_pk_debug_item;
|
||||
|
||||
/** Maximum number of item send for debugging, plus 1 */
|
||||
|
@ -181,8 +182,8 @@ typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
|
|||
*/
|
||||
typedef struct mbedtls_pk_context
|
||||
{
|
||||
const mbedtls_pk_info_t * pk_info; /**< Public key information */
|
||||
void * pk_ctx; /**< Underlying public key context */
|
||||
const mbedtls_pk_info_t * MBEDTLS_PRIVATE(pk_info); /**< Public key information */
|
||||
void * MBEDTLS_PRIVATE(pk_ctx); /**< Underlying public key context */
|
||||
} mbedtls_pk_context;
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
|
@ -191,8 +192,8 @@ typedef struct mbedtls_pk_context
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
const mbedtls_pk_info_t * pk_info; /**< Public key information */
|
||||
void * rs_ctx; /**< Underlying restart context */
|
||||
const mbedtls_pk_info_t * MBEDTLS_PRIVATE(pk_info); /**< Public key information */
|
||||
void * MBEDTLS_PRIVATE(rs_ctx); /**< Underlying restart context */
|
||||
} mbedtls_pk_restart_ctx;
|
||||
#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
|
||||
/* Now we can declare functions that take a pointer to that */
|
||||
|
@ -208,7 +209,7 @@ typedef void mbedtls_pk_restart_ctx;
|
|||
*/
|
||||
static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
|
||||
{
|
||||
return( (mbedtls_rsa_context *) (pk).pk_ctx );
|
||||
return( (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx) );
|
||||
}
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
|
@ -221,7 +222,7 @@ static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
|
|||
*/
|
||||
static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
|
||||
{
|
||||
return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
|
||||
return( (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx) );
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
|
@ -497,7 +498,7 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
|
|||
* given the key type.
|
||||
* \param sig_len On successful return,
|
||||
* the number of bytes written to \p sig.
|
||||
* \param f_rng RNG function
|
||||
* \param f_rng RNG function, must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \return 0 on success, or a specific error code.
|
||||
|
@ -537,7 +538,7 @@ int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
|
|||
* given the key type.
|
||||
* \param sig_len On successful return,
|
||||
* the number of bytes written to \p sig.
|
||||
* \param f_rng RNG function
|
||||
* \param f_rng RNG function, must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
* \param rs_ctx Restart context (NULL to disable restart)
|
||||
*
|
||||
|
@ -562,7 +563,7 @@ int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx,
|
|||
* \param output Decrypted output
|
||||
* \param olen Decrypted message length
|
||||
* \param osize Size of the output buffer
|
||||
* \param f_rng RNG function
|
||||
* \param f_rng RNG function, must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \note For RSA keys, the default padding type is PKCS#1 v1.5.
|
||||
|
@ -583,9 +584,11 @@ int mbedtls_pk_decrypt( mbedtls_pk_context *ctx,
|
|||
* \param output Encrypted output
|
||||
* \param olen Encrypted output length
|
||||
* \param osize Size of the output buffer
|
||||
* \param f_rng RNG function
|
||||
* \param f_rng RNG function, must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \note \p f_rng is used for padding generation.
|
||||
*
|
||||
* \note For RSA keys, the default padding type is PKCS#1 v1.5.
|
||||
*
|
||||
* \return 0 on success, or a specific error code.
|
||||
|
@ -600,6 +603,8 @@ int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
|
|||
*
|
||||
* \param pub Context holding a public key.
|
||||
* \param prv Context holding a private (and public) key.
|
||||
* \param f_rng RNG function, must not be \c NULL.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \return \c 0 on success (keys were checked and match each other).
|
||||
* \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the keys could not
|
||||
|
@ -607,7 +612,10 @@ int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
|
|||
* \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid.
|
||||
* \return Another non-zero value if the keys do not match.
|
||||
*/
|
||||
int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
|
||||
int mbedtls_pk_check_pair( const mbedtls_pk_context *pub,
|
||||
const mbedtls_pk_context *prv,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief Export debug information
|
||||
|
@ -659,6 +667,8 @@ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
|
|||
* The empty password is not supported.
|
||||
* \param pwdlen Size of the password in bytes.
|
||||
* Ignored if \p pwd is \c NULL.
|
||||
* \param f_rng RNG function, must not be \c NULL. Used for blinding.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \note On entry, ctx must be empty, either freshly initialised
|
||||
* with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
|
||||
|
@ -669,8 +679,9 @@ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
|
|||
* \return 0 if successful, or a specific PK or PEM error code
|
||||
*/
|
||||
int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
|
||||
const unsigned char *key, size_t keylen,
|
||||
const unsigned char *pwd, size_t pwdlen );
|
||||
const unsigned char *key, size_t keylen,
|
||||
const unsigned char *pwd, size_t pwdlen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
|
||||
/** \ingroup pk_module */
|
||||
/**
|
||||
|
@ -710,6 +721,8 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
|
|||
* Pass a null-terminated string if expecting an encrypted
|
||||
* key; a non-encrypted key will also be accepted.
|
||||
* The empty password is not supported.
|
||||
* \param f_rng RNG function, must not be \c NULL. Used for blinding.
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \note On entry, ctx must be empty, either freshly initialised
|
||||
* with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
|
||||
|
@ -720,7 +733,8 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
|
|||
* \return 0 if successful, or a specific PK or PEM error code
|
||||
*/
|
||||
int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
|
||||
const char *path, const char *password );
|
||||
const char *path, const char *password,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
|
||||
/** \ingroup pk_module */
|
||||
/**
|
||||
|
|
|
@ -52,25 +52,6 @@ extern "C" {
|
|||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
|
||||
/**
|
||||
* \brief PKCS12 Password Based function (encryption / decryption)
|
||||
* for pbeWithSHAAnd128BitRC4
|
||||
*
|
||||
* \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
|
||||
* \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
|
||||
* \param pwd the password used (may be NULL if no password is used)
|
||||
* \param pwdlen length of the password (may be 0)
|
||||
* \param input the input data
|
||||
* \param len data length
|
||||
* \param output the output buffer
|
||||
*
|
||||
* \return 0 if successful, or a MBEDTLS_ERR_XXX code
|
||||
*/
|
||||
int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
|
||||
const unsigned char *pwd, size_t pwdlen,
|
||||
const unsigned char *input, size_t len,
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief PKCS12 Password Based function (encryption / decryption)
|
||||
* for cipher-based and mbedtls_md-based PBE's
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_PLATFORM_H
|
||||
#define MBEDTLS_PLATFORM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -367,7 +368,7 @@ int mbedtls_platform_set_nv_seed(
|
|||
*/
|
||||
typedef struct mbedtls_platform_context
|
||||
{
|
||||
char dummy; /**< A placeholder member, as empty structs are not portable. */
|
||||
char MBEDTLS_PRIVATE(dummy); /**< A placeholder member, as empty structs are not portable. */
|
||||
}
|
||||
mbedtls_platform_context;
|
||||
|
||||
|
|
|
@ -39,78 +39,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS)
|
||||
|
||||
#if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
/* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
|
||||
* (which is what our config.h suggests). */
|
||||
#include <assert.h>
|
||||
#endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
|
||||
|
||||
#if defined(MBEDTLS_PARAM_FAILED)
|
||||
/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
|
||||
*
|
||||
* This flag can be used to check whether it is safe to assume that
|
||||
* MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed().
|
||||
*/
|
||||
#define MBEDTLS_PARAM_FAILED_ALT
|
||||
|
||||
#elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
|
||||
#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
|
||||
#define MBEDTLS_PARAM_FAILED_ALT
|
||||
|
||||
#else /* MBEDTLS_PARAM_FAILED */
|
||||
#define MBEDTLS_PARAM_FAILED( cond ) \
|
||||
mbedtls_param_failed( #cond, __FILE__, __LINE__ )
|
||||
|
||||
/**
|
||||
* \brief User supplied callback function for parameter validation failure.
|
||||
* See #MBEDTLS_CHECK_PARAMS for context.
|
||||
*
|
||||
* This function will be called unless an alternative treatement
|
||||
* is defined through the #MBEDTLS_PARAM_FAILED macro.
|
||||
*
|
||||
* This function can return, and the operation will be aborted, or
|
||||
* alternatively, through use of setjmp()/longjmp() can resume
|
||||
* execution in the application code.
|
||||
*
|
||||
* \param failure_condition The assertion that didn't hold.
|
||||
* \param file The file where the assertion failed.
|
||||
* \param line The line in the file where the assertion failed.
|
||||
*/
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line );
|
||||
#endif /* MBEDTLS_PARAM_FAILED */
|
||||
|
||||
/* Internal macro meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
|
||||
do { \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_PARAM_FAILED( cond ); \
|
||||
return( ret ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
/* Internal macro meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE( cond ) \
|
||||
do { \
|
||||
if( !(cond) ) \
|
||||
{ \
|
||||
MBEDTLS_PARAM_FAILED( cond ); \
|
||||
return; \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#else /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
/* Internal macros meant to be called only from within the library. */
|
||||
#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
|
||||
#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
|
||||
|
||||
#endif /* MBEDTLS_CHECK_PARAMS */
|
||||
|
||||
/* Internal helper macros for deprecating API constants. */
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#ifndef MBEDTLS_POLY1305_H
|
||||
#define MBEDTLS_POLY1305_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -51,11 +52,11 @@ extern "C" {
|
|||
|
||||
typedef struct mbedtls_poly1305_context
|
||||
{
|
||||
uint32_t r[4]; /** The value for 'r' (low 128 bits of the key). */
|
||||
uint32_t s[4]; /** The value for 's' (high 128 bits of the key). */
|
||||
uint32_t acc[5]; /** The accumulator number. */
|
||||
uint8_t queue[16]; /** The current partial block of data. */
|
||||
size_t queue_len; /** The number of bytes stored in 'queue'. */
|
||||
uint32_t MBEDTLS_PRIVATE(r)[4]; /** The value for 'r' (low 128 bits of the key). */
|
||||
uint32_t MBEDTLS_PRIVATE(s)[4]; /** The value for 's' (high 128 bits of the key). */
|
||||
uint32_t MBEDTLS_PRIVATE(acc)[5]; /** The accumulator number. */
|
||||
uint8_t MBEDTLS_PRIVATE(queue)[16]; /** The current partial block of data. */
|
||||
size_t MBEDTLS_PRIVATE(queue_len); /** The number of bytes stored in 'queue'. */
|
||||
}
|
||||
mbedtls_poly1305_context;
|
||||
|
||||
|
|
32
include/mbedtls/private_access.h
Normal file
32
include/mbedtls/private_access.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* \file private_access.h
|
||||
*
|
||||
* \brief Macro wrapper for struct's memebrs.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MBEDTLS_PRIVATE_ACCESS_H
|
||||
#define MBEDTLS_PRIVATE_ACCESS_H
|
||||
|
||||
#ifndef MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
#define MBEDTLS_PRIVATE(member) private_##member
|
||||
#else
|
||||
#define MBEDTLS_PRIVATE(member) member
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_PRIVATE_ACCESS_H */
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#ifndef MBEDTLS_PSA_UTIL_H
|
||||
#define MBEDTLS_PSA_UTIL_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -120,14 +121,6 @@ static inline psa_algorithm_t mbedtls_psa_translate_md( mbedtls_md_type_t md_alg
|
|||
{
|
||||
switch( md_alg )
|
||||
{
|
||||
#if defined(MBEDTLS_MD2_C)
|
||||
case MBEDTLS_MD_MD2:
|
||||
return( PSA_ALG_MD2 );
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD4_C)
|
||||
case MBEDTLS_MD_MD4:
|
||||
return( PSA_ALG_MD4 );
|
||||
#endif
|
||||
#if defined(MBEDTLS_MD5_C)
|
||||
case MBEDTLS_MD_MD5:
|
||||
return( PSA_ALG_MD5 );
|
||||
|
@ -380,7 +373,7 @@ static inline psa_key_type_t mbedtls_psa_parse_tls_ecc_group(
|
|||
if( curve_info == NULL )
|
||||
return( 0 );
|
||||
return( PSA_KEY_TYPE_ECC_KEY_PAIR(
|
||||
mbedtls_ecc_group_to_psa( curve_info->grp_id, bits ) ) );
|
||||
mbedtls_ecc_group_to_psa( curve_info->MBEDTLS_PRIVATE(grp_id), bits ) ) );
|
||||
}
|
||||
#endif /* MBEDTLS_ECP_C */
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_RIPEMD160_H
|
||||
#define MBEDTLS_RIPEMD160_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -44,9 +45,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_ripemd160_context
|
||||
{
|
||||
uint32_t total[2]; /*!< number of bytes processed */
|
||||
uint32_t state[5]; /*!< intermediate digest state */
|
||||
unsigned char buffer[64]; /*!< data block being processed */
|
||||
uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
|
||||
uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< intermediate digest state */
|
||||
unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
|
||||
}
|
||||
mbedtls_ripemd160_context;
|
||||
|
||||
|
@ -84,7 +85,7 @@ void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
|
|||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
|
||||
int mbedtls_ripemd160_starts( mbedtls_ripemd160_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief RIPEMD-160 process buffer
|
||||
|
@ -95,9 +96,9 @@ int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
|
|||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
int mbedtls_ripemd160_update( mbedtls_ripemd160_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief RIPEMD-160 final digest
|
||||
|
@ -107,8 +108,8 @@ int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
|
|||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
|
||||
unsigned char output[20] );
|
||||
int mbedtls_ripemd160_finish( mbedtls_ripemd160_context *ctx,
|
||||
unsigned char output[20] );
|
||||
|
||||
/**
|
||||
* \brief RIPEMD-160 process data block (internal use only)
|
||||
|
@ -130,9 +131,9 @@ int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
|
|||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_ripemd160_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] );
|
||||
int mbedtls_ripemd160( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_RSA_H
|
||||
#define MBEDTLS_RSA_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -81,48 +82,44 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* \brief The RSA context structure.
|
||||
*
|
||||
* \note Direct manipulation of the members of this structure
|
||||
* is deprecated. All manipulation should instead be done through
|
||||
* the public interface functions.
|
||||
*/
|
||||
typedef struct mbedtls_rsa_context
|
||||
{
|
||||
int ver; /*!< Reserved for internal purposes.
|
||||
int MBEDTLS_PRIVATE(ver); /*!< Reserved for internal purposes.
|
||||
* Do not set this field in application
|
||||
* code. Its meaning might change without
|
||||
* notice. */
|
||||
size_t len; /*!< The size of \p N in Bytes. */
|
||||
size_t MBEDTLS_PRIVATE(len); /*!< The size of \p N in Bytes. */
|
||||
|
||||
mbedtls_mpi N; /*!< The public modulus. */
|
||||
mbedtls_mpi E; /*!< The public exponent. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(N); /*!< The public modulus. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(E); /*!< The public exponent. */
|
||||
|
||||
mbedtls_mpi D; /*!< The private exponent. */
|
||||
mbedtls_mpi P; /*!< The first prime factor. */
|
||||
mbedtls_mpi Q; /*!< The second prime factor. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(D); /*!< The private exponent. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(P); /*!< The first prime factor. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Q); /*!< The second prime factor. */
|
||||
|
||||
mbedtls_mpi DP; /*!< <code>D % (P - 1)</code>. */
|
||||
mbedtls_mpi DQ; /*!< <code>D % (Q - 1)</code>. */
|
||||
mbedtls_mpi QP; /*!< <code>1 / (Q % P)</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(DP); /*!< <code>D % (P - 1)</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(DQ); /*!< <code>D % (Q - 1)</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(QP); /*!< <code>1 / (Q % P)</code>. */
|
||||
|
||||
mbedtls_mpi RN; /*!< cached <code>R^2 mod N</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(RN); /*!< cached <code>R^2 mod N</code>. */
|
||||
|
||||
mbedtls_mpi RP; /*!< cached <code>R^2 mod P</code>. */
|
||||
mbedtls_mpi RQ; /*!< cached <code>R^2 mod Q</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(RP); /*!< cached <code>R^2 mod P</code>. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(RQ); /*!< cached <code>R^2 mod Q</code>. */
|
||||
|
||||
mbedtls_mpi Vi; /*!< The cached blinding value. */
|
||||
mbedtls_mpi Vf; /*!< The cached un-blinding value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Vi); /*!< The cached blinding value. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(Vf); /*!< The cached un-blinding value. */
|
||||
|
||||
int padding; /*!< Selects padding mode:
|
||||
int MBEDTLS_PRIVATE(padding); /*!< Selects padding mode:
|
||||
#MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
|
||||
#MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
|
||||
int hash_id; /*!< Hash identifier of mbedtls_md_type_t type,
|
||||
int MBEDTLS_PRIVATE(hash_id); /*!< Hash identifier of mbedtls_md_type_t type,
|
||||
as specified in md.h for use in the MGF
|
||||
mask generating function used in the
|
||||
EME-OAEP and EMSA-PSS encodings. */
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
/* Invariant: the mutex is initialized iff ver != 0. */
|
||||
mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
|
||||
mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); /*!< Thread-safety mutex. */
|
||||
#endif
|
||||
}
|
||||
mbedtls_rsa_context;
|
||||
|
@ -134,33 +131,51 @@ mbedtls_rsa_context;
|
|||
/**
|
||||
* \brief This function initializes an RSA context.
|
||||
*
|
||||
* \note This function initializes the padding and the hash
|
||||
* identifier to respectively #MBEDTLS_RSA_PKCS_V15 and
|
||||
* #MBEDTLS_MD_NONE. See mbedtls_rsa_set_padding() for more
|
||||
* information about those parameters.
|
||||
*
|
||||
* \param ctx The RSA context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_rsa_init( mbedtls_rsa_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief This function sets padding for an already initialized RSA
|
||||
* context.
|
||||
*
|
||||
* \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
|
||||
* encryption scheme and the RSASSA-PSS signature scheme.
|
||||
*
|
||||
* \note The \p hash_id parameter is ignored when using
|
||||
* #MBEDTLS_RSA_PKCS_V15 padding.
|
||||
*
|
||||
* \note The choice of padding mode is strictly enforced for private key
|
||||
* operations, since there might be security concerns in
|
||||
* \note The choice of padding mode is strictly enforced for private
|
||||
* key operations, since there might be security concerns in
|
||||
* mixing padding modes. For public key operations it is
|
||||
* a default value, which can be overridden by calling specific
|
||||
* \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
|
||||
* \c mbedtls_rsa_rsaes_xxx or \c mbedtls_rsa_rsassa_xxx
|
||||
* functions.
|
||||
*
|
||||
* \note The hash selected in \p hash_id is always used for OEAP
|
||||
* encryption. For PSS signatures, it is always used for
|
||||
* making signatures, but can be overridden for verifying them.
|
||||
* If set to #MBEDTLS_MD_NONE, it is always overridden.
|
||||
*
|
||||
* \param ctx The RSA context to initialize. This must not be \c NULL.
|
||||
* \param ctx The initialized RSA context to be configured.
|
||||
* \param padding The padding mode to use. This must be either
|
||||
* #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
|
||||
* \param hash_id The hash identifier of ::mbedtls_md_type_t type, if
|
||||
* \p padding is #MBEDTLS_RSA_PKCS_V21. It is unused
|
||||
* otherwise.
|
||||
* \param hash_id The hash identifier for PSS or OAEP, if \p padding is
|
||||
* #MBEDTLS_RSA_PKCS_V21. #MBEDTLS_MD_NONE is accepted by this
|
||||
* function but may be not suitable for some operations.
|
||||
* Ignored if \p padding is #MBEDTLS_RSA_PKCS_V15.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_RSA_INVALID_PADDING failure:
|
||||
* \p padding or \p hash_id is invalid.
|
||||
*/
|
||||
void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
|
||||
int padding,
|
||||
int hash_id );
|
||||
int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
|
||||
mbedtls_md_type_t hash_id );
|
||||
|
||||
/**
|
||||
* \brief This function imports a set of core parameters into an
|
||||
|
@ -391,18 +406,6 @@ int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
|
|||
int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
|
||||
mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
|
||||
|
||||
/**
|
||||
* \brief This function sets padding for an already initialized RSA
|
||||
* context. See mbedtls_rsa_init() for details.
|
||||
*
|
||||
* \param ctx The initialized RSA context to be configured.
|
||||
* \param padding The padding mode to use. This must be either
|
||||
* #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
|
||||
* \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
|
||||
*/
|
||||
void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
|
||||
int hash_id );
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the length of RSA modulus in Bytes.
|
||||
*
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_SHA1_H
|
||||
#define MBEDTLS_SHA1_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -58,9 +59,9 @@ extern "C" {
|
|||
*/
|
||||
typedef struct mbedtls_sha1_context
|
||||
{
|
||||
uint32_t total[2]; /*!< The number of Bytes processed. */
|
||||
uint32_t state[5]; /*!< The intermediate digest state. */
|
||||
unsigned char buffer[64]; /*!< The data block being processed. */
|
||||
uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< The number of Bytes processed. */
|
||||
uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< The intermediate digest state. */
|
||||
unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< The data block being processed. */
|
||||
}
|
||||
mbedtls_sha1_context;
|
||||
|
||||
|
@ -123,7 +124,7 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
|
|||
* \return A negative error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
|
||||
int mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer into an ongoing SHA-1
|
||||
|
@ -142,9 +143,9 @@ int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
|
|||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
int mbedtls_sha1_update( mbedtls_sha1_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief This function finishes the SHA-1 operation, and writes
|
||||
|
@ -162,8 +163,8 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
|
|||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
|
||||
unsigned char output[20] );
|
||||
int mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
|
||||
unsigned char output[20] );
|
||||
|
||||
/**
|
||||
* \brief SHA-1 process data block (internal use only).
|
||||
|
@ -206,9 +207,9 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
|
|||
* \return A negative error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_sha1_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] );
|
||||
int mbedtls_sha1( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[20] );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
#ifndef MBEDTLS_SHA256_H
|
||||
#define MBEDTLS_SHA256_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
|
@ -49,14 +50,14 @@ extern "C" {
|
|||
*
|
||||
* The structure is used both for SHA-256 and for SHA-224
|
||||
* checksum calculations. The choice between these two is
|
||||
* made in the call to mbedtls_sha256_starts_ret().
|
||||
* made in the call to mbedtls_sha256_starts().
|
||||
*/
|
||||
typedef struct mbedtls_sha256_context
|
||||
{
|
||||
uint32_t total[2]; /*!< The number of Bytes processed. */
|
||||
uint32_t state[8]; /*!< The intermediate digest state. */
|
||||
unsigned char buffer[64]; /*!< The data block being processed. */
|
||||
int is224; /*!< Determines which function to use:
|
||||
uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< The number of Bytes processed. */
|
||||
uint32_t MBEDTLS_PRIVATE(state)[8]; /*!< The intermediate digest state. */
|
||||
unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< The data block being processed. */
|
||||
int MBEDTLS_PRIVATE(is224); /*!< Determines which function to use:
|
||||
0: Use SHA-256, or 1: Use SHA-224. */
|
||||
}
|
||||
mbedtls_sha256_context;
|
||||
|
@ -101,7 +102,7 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
|
|||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
|
||||
int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer into an ongoing
|
||||
|
@ -116,9 +117,9 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
|
|||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
int mbedtls_sha256_update( mbedtls_sha256_context *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief This function finishes the SHA-256 operation, and writes
|
||||
|
@ -133,8 +134,8 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
|||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||
unsigned char *output );
|
||||
int mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief This function processes a single data block within
|
||||
|
@ -170,10 +171,10 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
|||
* \param is224 Determines which function to use. This must be
|
||||
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||
*/
|
||||
int mbedtls_sha256_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char *output,
|
||||
int is224 );
|
||||
int mbedtls_sha256( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char *output,
|
||||
int is224 );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue