mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-29 12:32:48 +00:00
Merge branch 'development' into sha3
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
commit
4e747337ee
41
.github/pull_request_template.md
vendored
41
.github/pull_request_template.md
vendored
@ -1,36 +1,19 @@
|
||||
Notes:
|
||||
* Pull requests cannot be accepted until the PR follows the [contributing guidelines](../CONTRIBUTING.md). In particular, each commit must have at least one `Signed-off-by:` line from the committer to certify that the contribution is made under the terms of the [Developer Certificate of Origin](../dco.txt).
|
||||
* This is just a template, so feel free to use/remove the unnecessary things
|
||||
## Description
|
||||
A few sentences describing the overall goals of the pull request's commits.
|
||||
|
||||
Please write a few sentences describing the overall goals of the pull request's commits.
|
||||
|
||||
|
||||
## Status
|
||||
**READY/IN DEVELOPMENT/HOLD**
|
||||
|
||||
## Requires Backporting
|
||||
When there is a bug fix, it should be backported to all maintained and supported branches.
|
||||
Changes do not have to be backported if:
|
||||
- This PR is a new feature\enhancement
|
||||
- This PR contains changes in the API. If this is true, and there is a need for the fix to be backported, the fix should be handled differently in the legacy branch
|
||||
## Gatekeeper checklist
|
||||
|
||||
Yes | NO
|
||||
Which branch?
|
||||
|
||||
## Migrations
|
||||
If there is any API change, what's the incentive and logic for it.
|
||||
|
||||
YES | NO
|
||||
|
||||
## Additional comments
|
||||
Any additional information that could be of interest
|
||||
|
||||
## Todos
|
||||
- [ ] Tests
|
||||
- [ ] Documentation
|
||||
- [ ] Changelog updated
|
||||
- [ ] Backported
|
||||
- [ ] **changelog** provided, or not required
|
||||
- [ ] **backport** done, or not required
|
||||
- [ ] **tests** provided, or not required
|
||||
|
||||
|
||||
## Steps to test or reproduce
|
||||
Outline the steps to test or reproduce the PR here.
|
||||
|
||||
## Notes for the submitter
|
||||
|
||||
Please refer to the [contributing guidelines](https://github.com/Mbed-TLS/mbedtls/blob/development/CONTRIBUTING.md), especially the
|
||||
checklist for PR contributors.
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
[MASTER]
|
||||
init-hook='import sys; sys.path.append("scripts")'
|
||||
min-similarity-lines=10
|
||||
|
||||
[BASIC]
|
||||
# We're ok with short funtion argument names.
|
||||
@ -73,3 +74,7 @@ reports=no
|
||||
# Allow unused variables if their name starts with an underscore.
|
||||
# [unused-argument]
|
||||
dummy-variables-rgx=_.*
|
||||
|
||||
[SIMILARITIES]
|
||||
# Ignore imports when computing similarities.
|
||||
ignore-imports=yes
|
||||
|
34
.travis.yml
34
.travis.yml
@ -25,8 +25,40 @@ jobs:
|
||||
- tests/scripts/all.sh -k build_arm_linux_gnueabi_gcc_arm5vte build_arm_none_eabi_gcc_m0plus
|
||||
|
||||
- name: full configuration
|
||||
os: linux
|
||||
dist: focal
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-10
|
||||
- gnutls-bin
|
||||
script:
|
||||
- tests/scripts/all.sh -k test_full_cmake_gcc_asan
|
||||
# Do a manual build+test sequence rather than using all.sh,
|
||||
# because there's no all.sh component that does what we want,
|
||||
# which is a build with Clang >= 10 and ASan, running all the SSL
|
||||
# testing.
|
||||
# - The clang executable in the default PATH is Clang 7 on
|
||||
# Travis's focal instances, but we want Clang >= 10.
|
||||
# - Running all the SSL testing requires a specific set of
|
||||
# OpenSSL and GnuTLS versions and we don't want to bother
|
||||
# with those on Travis.
|
||||
# So we explicitly select clang-10 as the compiler, and we
|
||||
# have ad hoc restrictions on SSL testing based on what is
|
||||
# passing at the time of writing. We will remove these limitations
|
||||
# gradually.
|
||||
- make generated_files
|
||||
- make CC=clang-10 CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all -O2' LDFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
|
||||
- make test
|
||||
- programs/test/selftest
|
||||
- tests/scripts/test_psa_constant_names.py
|
||||
- tests/ssl-opt.sh
|
||||
# Modern OpenSSL does not support fixed ECDH or null ciphers.
|
||||
- tests/compat.sh -p OpenSSL -e 'NULL\|ECDH_'
|
||||
- tests/scripts/travis-log-failure.sh
|
||||
# GnuTLS supports CAMELLIA but compat.sh doesn't properly enable it.
|
||||
- tests/compat.sh -p GnuTLS -e 'CAMELLIA'
|
||||
- tests/scripts/travis-log-failure.sh
|
||||
- tests/context-info.sh
|
||||
|
||||
- name: Windows
|
||||
os: windows
|
||||
|
252
.uncrustify.cfg
Normal file
252
.uncrustify.cfg
Normal file
@ -0,0 +1,252 @@
|
||||
# Configuration options for Uncrustify specifying the Mbed TLS code style.
|
||||
#
|
||||
# Note: The code style represented by this file has not yet been introduced
|
||||
# to Mbed TLS.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
# Wrap lines at 100 characters
|
||||
code_width = 100
|
||||
|
||||
# Allow splitting long for statements between the condition statements
|
||||
ls_for_split_full = true
|
||||
|
||||
# Allow splitting function calls between arguments
|
||||
ls_func_split_full = true
|
||||
|
||||
input_tab_size = 4
|
||||
|
||||
# Spaces-only indentation
|
||||
indent_with_tabs = 0
|
||||
|
||||
indent_columns = 4
|
||||
|
||||
# Indent 'case' 1 level from 'switch'
|
||||
indent_switch_case = indent_columns
|
||||
|
||||
# Line-up strings broken by '\'
|
||||
indent_align_string = true
|
||||
|
||||
# Braces on the same line (Egyptian-style braces)
|
||||
nl_enum_brace = remove
|
||||
nl_union_brace = remove
|
||||
nl_struct_brace = remove
|
||||
nl_do_brace = remove
|
||||
nl_if_brace = remove
|
||||
nl_for_brace = remove
|
||||
nl_else_brace = remove
|
||||
nl_while_brace = remove
|
||||
nl_switch_brace = remove
|
||||
|
||||
# Braces on same line as keywords that follow them - 'else' and the 'while' in 'do {} while ()';
|
||||
nl_brace_else = remove
|
||||
nl_brace_while = remove
|
||||
# Space before else on the same line
|
||||
sp_brace_else = add
|
||||
# If else is on the same line as '{', force exactly 1 space between them
|
||||
sp_else_brace = force
|
||||
|
||||
# Functions are the exception and have braces on the next line
|
||||
nl_fcall_brace = add
|
||||
nl_fdef_brace = add
|
||||
|
||||
# Force exactly one space between ')' and '{' in statements
|
||||
sp_sparen_brace = force
|
||||
|
||||
# At least 1 space around assignment
|
||||
sp_assign = add
|
||||
|
||||
# Remove spaces around the preprocessor '##' token-concatenate
|
||||
sp_pp_concat = ignore
|
||||
|
||||
# At least 1 space around '||' and '&&'
|
||||
sp_bool = add
|
||||
|
||||
# But no space after the '!' operator
|
||||
sp_not = remove
|
||||
|
||||
# No space after the bitwise-not '~' operator
|
||||
sp_inv = remove
|
||||
|
||||
# No space after the addressof '&' operator
|
||||
sp_addr = remove
|
||||
|
||||
# No space around the member '.' and '->' operators
|
||||
sp_member = remove
|
||||
|
||||
# No space after the dereference '*' operator
|
||||
sp_deref = remove
|
||||
|
||||
# No space after a unary negation '-'
|
||||
sp_sign = remove
|
||||
|
||||
# No space between the '++'/'--' operator and its operand
|
||||
sp_incdec = remove
|
||||
|
||||
# At least 1 space around comparison operators
|
||||
sp_compare = add
|
||||
|
||||
# Remove spaces inside all kinds of parentheses:
|
||||
|
||||
# Remove spaces inside parentheses
|
||||
sp_inside_paren = remove
|
||||
|
||||
# No spaces inside statement parentheses
|
||||
sp_inside_sparen = remove
|
||||
|
||||
# No spaces inside cast parentheses '( char )x' -> '(char)x'
|
||||
sp_inside_paren_cast = remove
|
||||
|
||||
# No spaces inside function parentheses
|
||||
sp_inside_fparen = remove
|
||||
# (The case where the function has no parameters/arguments)
|
||||
sp_inside_fparens = remove
|
||||
|
||||
# No spaces inside the first parentheses in a function type
|
||||
sp_inside_tparen = remove
|
||||
|
||||
# (Uncrustify >= 0.74.0) No spaces inside parens in for statements
|
||||
sp_inside_for = remove
|
||||
|
||||
# Remove spaces between nested parentheses '( (' -> '(('
|
||||
sp_paren_paren = remove
|
||||
# (Uncrustify >= 0.74.0)
|
||||
sp_sparen_paren = remove
|
||||
|
||||
# Remove spaces between ')' and adjacent '('
|
||||
sp_cparen_oparen = remove
|
||||
|
||||
# (Uncrustify >= 0.73.0) space between 'do' and '{'
|
||||
sp_do_brace_open = force
|
||||
|
||||
# (Uncrustify >= 0.73.0) space between '}' and 'while'
|
||||
sp_brace_close_while = force
|
||||
|
||||
# At least 1 space before a '*' pointer star
|
||||
sp_before_ptr_star = add
|
||||
|
||||
# Remove spaces between pointer stars
|
||||
sp_between_ptr_star = remove
|
||||
|
||||
# No space after a pointer star
|
||||
sp_after_ptr_star = remove
|
||||
|
||||
# But allow a space in the case of e.g. char * const x;
|
||||
sp_after_ptr_star_qualifier = ignore
|
||||
|
||||
# Remove space after star in a function return type
|
||||
sp_after_ptr_star_func = remove
|
||||
|
||||
# At least 1 space after a type in variable definition etc
|
||||
sp_after_type = add
|
||||
|
||||
# Force exactly 1 space between a statement keyword (e.g. 'if') and an opening parenthesis
|
||||
sp_before_sparen = force
|
||||
|
||||
# Remove a space before a ';'
|
||||
sp_before_semi = remove
|
||||
# (Uncrustify >= 0.73.0) Remove space before a semi in a non-empty for
|
||||
sp_before_semi_for = remove
|
||||
# (Uncrustify >= 0.73.0) Remove space in empty first statement of a for
|
||||
sp_before_semi_for_empty = remove
|
||||
# (Uncrustify >= 0.74.0) Remove space in empty middle statement of a for
|
||||
sp_between_semi_for_empty = remove
|
||||
|
||||
# Add a space after a ';' (unless a comment follows)
|
||||
sp_after_semi = add
|
||||
# (Uncrustify >= 0.73.0) Add a space after a semi in non-empty for statements
|
||||
sp_after_semi_for = add
|
||||
# (Uncrustify >= 0.73.0) No space after final semi in empty for statements
|
||||
sp_after_semi_for_empty = remove
|
||||
|
||||
# Remove spaces on the inside of square brackets '[]'
|
||||
sp_inside_square = remove
|
||||
|
||||
# Must have at least 1 space after a comma
|
||||
sp_after_comma = add
|
||||
|
||||
# Must not have a space before a comma
|
||||
sp_before_comma = remove
|
||||
|
||||
# No space before the ':' in a case statement
|
||||
sp_before_case_colon = remove
|
||||
|
||||
# Must have space after a cast - '(char)x' -> '(char) x'
|
||||
sp_after_cast = add
|
||||
|
||||
# No space between 'sizeof' and '('
|
||||
sp_sizeof_paren = remove
|
||||
|
||||
# At least 1 space inside '{ }'
|
||||
sp_inside_braces = add
|
||||
|
||||
# At least 1 space inside '{ }' in an enum
|
||||
sp_inside_braces_enum = add
|
||||
|
||||
# At least 1 space inside '{ }' in a struct
|
||||
sp_inside_braces_struct = add
|
||||
|
||||
# At least 1 space between a function return type and the function name
|
||||
sp_type_func = add
|
||||
|
||||
# No space between a function name and its arguments/parameters
|
||||
sp_func_proto_paren = remove
|
||||
sp_func_def_paren = remove
|
||||
sp_func_call_paren = remove
|
||||
|
||||
# No space between '__attribute__' and '('
|
||||
sp_attribute_paren = remove
|
||||
|
||||
# No space between 'defined' and '(' in preprocessor conditions
|
||||
sp_defined_paren = remove
|
||||
|
||||
# At least 1 space between a macro's name and its definition
|
||||
sp_macro = add
|
||||
sp_macro_func = add
|
||||
|
||||
# Force exactly 1 space between a '}' and the name of a typedef if on the same line
|
||||
sp_brace_typedef = force
|
||||
|
||||
# At least 1 space before a '\' line continuation
|
||||
sp_before_nl_cont = add
|
||||
|
||||
# At least 1 space around '?' and ':' in ternary statements
|
||||
sp_cond_colon = add
|
||||
sp_cond_question = add
|
||||
|
||||
# Space between #else/#endif and comment afterwards
|
||||
sp_endif_cmt = add
|
||||
|
||||
# Remove newlines at the start of a file
|
||||
nl_start_of_file = remove
|
||||
|
||||
# At least 1 newline at the end of a file
|
||||
nl_end_of_file = add
|
||||
nl_end_of_file_min = 1
|
||||
|
||||
# Add braces in single-line statements
|
||||
mod_full_brace_do = add
|
||||
mod_full_brace_for = add
|
||||
mod_full_brace_if = add
|
||||
mod_full_brace_while = add
|
||||
|
||||
# Remove parentheses from return statements
|
||||
mod_paren_on_return = remove
|
||||
|
||||
# Disable removal of leading spaces in a multi-line comment if the first and
|
||||
# last lines are the same length
|
||||
cmt_multi_check_last = false
|
5
3rdparty/everest/library/everest.c
vendored
5
3rdparty/everest/library/everest.c
vendored
@ -28,12 +28,7 @@
|
||||
#include "everest/x25519.h"
|
||||
#include "everest/everest.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#define mbedtls_calloc calloc
|
||||
#define mbedtls_free free
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
|
||||
|
||||
|
@ -101,6 +101,6 @@ The following branches are currently maintained:
|
||||
- [`development`](https://github.com/Mbed-TLS/mbedtls/)
|
||||
- [`mbedtls-2.28`](https://github.com/Mbed-TLS/mbedtls/tree/mbedtls-2.28)
|
||||
maintained until at least the end of 2024, see
|
||||
<https://github.com/Mbed-TLS/mbedtls/releases/tag/v2.28.0>.
|
||||
<https://github.com/Mbed-TLS/mbedtls/releases/tag/v2.28.2>.
|
||||
|
||||
Users are urged to always use the latest version of a maintained branch.
|
||||
|
@ -304,22 +304,15 @@ if(ENABLE_TESTING)
|
||||
# additional convenience targets for Unix only
|
||||
if(UNIX)
|
||||
|
||||
ADD_CUSTOM_TARGET(covtest
|
||||
COMMAND make test
|
||||
COMMAND programs/test/selftest
|
||||
COMMAND tests/compat.sh
|
||||
COMMAND tests/ssl-opt.sh
|
||||
)
|
||||
|
||||
# For coverage testing:
|
||||
# 1. Build with:
|
||||
# cmake -D CMAKE_BUILD_TYPE=Coverage /path/to/source && make
|
||||
# 2. Run the relevant tests for the part of the code you're interested in.
|
||||
# For the reference coverage measurement, see
|
||||
# tests/scripts/basic-build-test.sh
|
||||
# 3. Run scripts/lcov.sh to generate an HTML report.
|
||||
ADD_CUSTOM_TARGET(lcov
|
||||
COMMAND rm -rf Coverage
|
||||
COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info
|
||||
COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info
|
||||
COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
|
||||
COMMAND lcov --remove all.info -o final.info '*.h'
|
||||
COMMAND gendesc tests/Descriptions.txt -o descriptions
|
||||
COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
|
||||
COMMAND rm -f files.info tests.info all.info final.info descriptions
|
||||
COMMAND scripts/lcov.sh
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(memcheck
|
||||
@ -350,12 +343,12 @@ if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL)
|
||||
write_basic_package_version_file(
|
||||
"cmake/MbedTLSConfigVersion.cmake"
|
||||
COMPATIBILITY SameMajorVersion
|
||||
VERSION 3.2.1)
|
||||
VERSION 3.3.0)
|
||||
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/MbedTLSConfigVersion.cmake"
|
||||
DESTINATION "cmake")
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MbedTLS")
|
||||
|
||||
export(
|
||||
EXPORT MbedTLSTargets
|
||||
@ -365,7 +358,7 @@ if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL)
|
||||
install(
|
||||
EXPORT MbedTLSTargets
|
||||
NAMESPACE MbedTLS::
|
||||
DESTINATION "cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MbedTLS"
|
||||
FILE "MbedTLSTargets.cmake")
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
|
||||
|
@ -1,13 +1,20 @@
|
||||
Contributing
|
||||
============
|
||||
We gratefully accept bug reports and contributions from the community. There are some requirements we need to fulfill in order to be able to integrate contributions:
|
||||
We gratefully accept bug reports and contributions from the community. All PRs are reviewed by the project team / community, and may need some modifications to
|
||||
be accepted.
|
||||
|
||||
- As with any open source project, contributions will be reviewed by the project team and community and may need some modifications to be accepted.
|
||||
- The contribution should not break API or ABI, unless there is a real justification for that. If there is an API change, the contribution, if accepted, will be merged only when there will be a major release.
|
||||
Quick Checklist for PR contributors
|
||||
-----------------------------------
|
||||
More details on all of these points may be found in the sections below.
|
||||
|
||||
- [Sign-off](#license-and-copyright): all commits must be signed off.
|
||||
- [Tests](#tests): please ensure the PR includes adequate tests.
|
||||
- [Changelog](#documentation): if needed, please provide a changelog entry.
|
||||
- [Backports](#long-term-support-branches): provide a backport if needed (it's fine to wait until the main PR is accepted).
|
||||
|
||||
Coding Standards
|
||||
----------------
|
||||
- We would ask that contributions conform to [our coding standards](https://tls.mbed.org/kb/development/mbedtls-coding-standards), and that contributions are fully tested before submission, as mentioned in the [Tests](#tests) and [Continuous Integration](#continuous-integration-tests) sections.
|
||||
- We would ask that contributions conform to [our coding standards](https://mbed-tls.readthedocs.io/en/latest/kb/development/mbedtls-coding-standards/), and that contributions are fully tested before submission, as mentioned in the [Tests](#tests) and [Continuous Integration](#continuous-integration-tests) sections.
|
||||
- The code should be written in a clean and readable style.
|
||||
- The code should be written in a portable generic way, that will benefit the whole community, and not only your own needs.
|
||||
- The code should be secure, and will be reviewed from a security point of view as well.
|
||||
@ -25,13 +32,9 @@ Backwards Compatibility
|
||||
|
||||
The project aims to minimise the impact on users upgrading to newer versions of the library and it should not be necessary for a user to make any changes to their own code to work with a newer version of the library. Unless the user has made an active decision to use newer features, a newer generation of the library or a change has been necessary due to a security issue or other significant software defect, no modifications to their own code should be necessary. To achieve this, API compatibility is maintained between different versions of Mbed TLS on the main development branch and in LTS (Long Term Support) branches, as described in [BRANCHES.md](BRANCHES.md).
|
||||
|
||||
To minimise such disruption to users, where a change to the interface is required, all changes to the ABI or API, even on the main development branch where new features are added, need to be justifiable by either being a significant enhancement, new feature or bug fix which is best resolved by an interface change.
|
||||
To minimise such disruption to users, where a change to the interface is required, all changes to the ABI or API, even on the main development branch where new features are added, need to be justifiable by either being a significant enhancement, new feature or bug fix which is best resolved by an interface change. If there is an API change, the contribution, if accepted, will be merged only when there is a major release.
|
||||
|
||||
Where changes to an existing interface are necessary, functions in the public interface which need to be changed, are marked as 'deprecated'. This is done with the preprocessor symbols `MBEDTLS_DEPRECATED_WARNING` and `MBEDTLS_DEPRECATED_REMOVED`. Then, a new function with a new name but similar if not identical behaviour to the original function containing the necessary changes should be created alongside the existing deprecated function.
|
||||
|
||||
When a build is made with the deprecation preprocessor symbols defined, a compiler warning will be generated to warn a user that the function will be removed at some point in the future, notifying users that they should change from the older deprecated function to the newer function at their own convenience.
|
||||
|
||||
Therefore, no changes are permitted to the definition of functions in the public interface which will change the API. Instead the interface can only be changed by its extension. As described above, if a function needs to be changed, a new function needs to be created alongside it, with a new name, and whatever change is necessary, such as a new parameter or the addition of a return value.
|
||||
No changes are permitted to the definition of functions in the public interface which will change the API. Instead the interface can only be changed by its extension. Where changes to an existing interface are necessary, functions in the public interface which need to be changed are marked as 'deprecated'. If there is a strong reason to replace an existing function with one that has a slightly different interface (different prototype, or different documented behavior), create a new function with a new name with the desired interface. Keep the old function, but mark it as deprecated.
|
||||
|
||||
Periodically, the library will remove deprecated functions from the library which will be a breaking change in the API, but such changes will be made only in a planned, structured way that gives sufficient notice to users of the library.
|
||||
|
||||
@ -54,9 +57,9 @@ Tests
|
||||
-----
|
||||
As mentioned, tests that show the correctness of the feature or bug fix should be added to the pull request, if no such tests exist.
|
||||
|
||||
Mbed TLS includes a comprehensive set of test suites in the `tests/` directory that are dynamically generated to produce the actual test source files (e.g. `test_suite_mpi.c`). These files are generated from a `function file` (e.g. `suites/test_suite_mpi.function`) and a `data file` (e.g. `suites/test_suite_mpi.data`). The function file contains the test functions. The data file contains the test cases, specified as parameters that will be passed to the test function.
|
||||
Mbed TLS includes a comprehensive set of test suites in the `tests/` directory that are dynamically generated to produce the actual test source files (e.g. `test_suite_rsa.c`). These files are generated from a `function file` (e.g. `suites/test_suite_rsa.function`) and a `data file` (e.g. `suites/test_suite_rsa.data`). The function file contains the test functions. The data file contains the test cases, specified as parameters that will be passed to the test function.
|
||||
|
||||
[A Knowledge Base article describing how to add additional tests is available on the Mbed TLS website](https://tls.mbed.org/kb/development/test_suites).
|
||||
[A Knowledge Base article describing how to add additional tests is available on the Mbed TLS website](https://mbed-tls.readthedocs.io/en/latest/kb/development/test_suites/).
|
||||
|
||||
A test script `tests/scripts/basic-build-test.sh` is available to show test coverage of the library. New code contributions should provide a similar level of code coverage to that which already exists for the library.
|
||||
|
||||
@ -75,7 +78,7 @@ Mbed TLS is well documented, but if you think documentation is needed, speak out
|
||||
1. All interfaces should be documented through Doxygen. New APIs should introduce Doxygen documentation.
|
||||
1. Complex parts in the code should include comments.
|
||||
1. If needed, a Readme file is advised.
|
||||
1. If a [Knowledge Base (KB)](https://tls.mbed.org/kb) article should be added, write this as a comment in the PR description.
|
||||
1. If a [Knowledge Base (KB)](https://mbed-tls.readthedocs.io/en/latest/kb/) article should be added, write this as a comment in the PR description.
|
||||
1. A [ChangeLog](https://github.com/Mbed-TLS/mbedtls/blob/development/ChangeLog.d/00README.md) entry should be added for this contribution.
|
||||
|
||||
License and Copyright
|
||||
|
210
ChangeLog
210
ChangeLog
@ -1,9 +1,213 @@
|
||||
Mbed TLS ChangeLog (Sorted per branch, date)
|
||||
|
||||
= Mbed TLS 3.3.0 branch released 2022-12-14
|
||||
|
||||
Default behavior changes
|
||||
* Previously the macro MBEDTLS_SSL_DTLS_CONNECTION_ID implemented version 05
|
||||
of the IETF draft, and was marked experimental and disabled by default.
|
||||
It is now no longer experimental, and implements the final version from
|
||||
RFC 9146, which is not interoperable with the draft-05 version.
|
||||
If you need to communicate with peers that use earlier versions of
|
||||
Mbed TLS, then you need to define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
|
||||
to 1, but then you won't be able to communicate with peers that use the
|
||||
standard (non-draft) version.
|
||||
If you need to interoperate with both classes of peers with the
|
||||
same build of Mbed TLS, please let us know about your situation on the
|
||||
mailing list or GitHub.
|
||||
|
||||
Requirement changes
|
||||
* When building with PSA drivers using generate_driver_wrappers.py, or
|
||||
when building the library from the development branch rather than
|
||||
from a release, the Python module jsonschema is now necessary, in
|
||||
addition to jinja2. The official list of required Python modules is
|
||||
maintained in scripts/basic.requirements.txt and may change again
|
||||
in the future.
|
||||
|
||||
New deprecations
|
||||
* Deprecate mbedtls_asn1_free_named_data().
|
||||
Use mbedtls_asn1_free_named_data_list()
|
||||
or mbedtls_asn1_free_named_data_list_shallow().
|
||||
|
||||
Features
|
||||
* Support rsa_pss_rsae_* signature algorithms in TLS 1.2.
|
||||
* make: enable building unversioned shared library, with e.g.:
|
||||
"SHARED=1 SOEXT_TLS=so SOEXT_X509=so SOEXT_CRYPTO=so make lib"
|
||||
resulting in library names like "libmbedtls.so" rather than
|
||||
"libmbedcrypto.so.11".
|
||||
* Expose the EC J-PAKE functionality through the Draft PSA PAKE Crypto API.
|
||||
Only the ECC primitive with secp256r1 curve and SHA-256 hash algorithm
|
||||
are supported in this implementation.
|
||||
* Some modules can now use PSA drivers for hashes, including with no
|
||||
built-in implementation present, but only in some configurations.
|
||||
- RSA OAEP and PSS (PKCS#1 v2.1), PKCS5, PKCS12 and EC J-PAKE now use
|
||||
hashes from PSA when (and only when) MBEDTLS_MD_C is disabled.
|
||||
- PEM parsing of encrypted files now uses MD-5 from PSA when (and only
|
||||
when) MBEDTLS_MD5_C is disabled.
|
||||
See the documentation of the corresponding macros in mbedtls_config.h for
|
||||
details.
|
||||
Note that some modules are not able to use hashes from PSA yet, including
|
||||
the entropy module. As a consequence, for now the only way to build with
|
||||
all hashes only provided by drivers (no built-in hash) is to use
|
||||
MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG.
|
||||
* When MBEDTLS_USE_PSA_CRYPTO is enabled, X.509, TLS 1.2 and TLS 1.3 now
|
||||
properly negotiate/accept hashes based on their availability in PSA.
|
||||
As a consequence, they now work in configurations where the built-in
|
||||
implementations of (some) hashes are excluded and those hashes are only
|
||||
provided by PSA drivers. (See previous entry for limitation on RSA-PSS
|
||||
though: that module only use hashes from PSA when MBEDTLS_MD_C is off).
|
||||
* Add support for opaque keys as the private keys associated to certificates
|
||||
for authentication in TLS 1.3.
|
||||
* Add the LMS post-quantum-safe stateful-hash asymmetric signature scheme.
|
||||
Signature verification is production-ready, but generation is for testing
|
||||
purposes only. This currently only supports one parameter set
|
||||
(LMS_SHA256_M32_H10), meaning that each private key can be used to sign
|
||||
1024 messages. As such, it is not intended for use in TLS, but instead
|
||||
for verification of assets transmitted over an insecure channel,
|
||||
particularly firmware images.
|
||||
* Add the LM-OTS post-quantum-safe one-time signature scheme, which is
|
||||
required for LMS. This can be used independently, but each key can only
|
||||
be used to sign one message so is impractical for most circumstances.
|
||||
* Mbed TLS now supports TLS 1.3 key establishment via pre-shared keys.
|
||||
The pre-shared keys can be provisioned externally or via the ticket
|
||||
mechanism (session resumption).
|
||||
The ticket mechanism is supported when the configuration option
|
||||
MBEDTLS_SSL_SESSION_TICKETS is enabled.
|
||||
New options MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_xxx_ENABLED
|
||||
control the support for the three possible TLS 1.3 key exchange modes.
|
||||
* cert_write: support for setting extended key usage attributes. A
|
||||
corresponding new public API call has been added in the library,
|
||||
mbedtls_x509write_crt_set_ext_key_usage().
|
||||
* cert_write: support for writing certificate files in either PEM
|
||||
or DER format.
|
||||
* The PSA driver wrapper generator generate_driver_wrappers.py now
|
||||
supports a subset of the driver description language, including
|
||||
the following entry points: import_key, export_key, export_public_key,
|
||||
get_builtin_key, copy_key.
|
||||
* The new functions mbedtls_asn1_free_named_data_list() and
|
||||
mbedtls_asn1_free_named_data_list_shallow() simplify the management
|
||||
of memory in named data lists in X.509 structures.
|
||||
* The TLS 1.2 EC J-PAKE key exchange can now use the PSA Crypto API.
|
||||
Additional PSA key slots will be allocated in the process of such key
|
||||
exchange for builds that enable MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED and
|
||||
MBEDTLS_USE_PSA_CRYPTO.
|
||||
* Add support for DTLS Connection ID as defined by RFC 9146, controlled by
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID (enabled by default) and configured with
|
||||
mbedtls_ssl_set_cid().
|
||||
* Add a driver dispatch layer for raw key agreement, enabling alternative
|
||||
implementations of raw key agreement through the key_agreement driver
|
||||
entry point. This entry point is specified in the proposed PSA driver
|
||||
interface, but had not yet been implemented.
|
||||
* Add an ad-hoc key derivation function handling EC J-PAKE to PMS
|
||||
calculation that can be used to derive the session secret in TLS 1.2,
|
||||
as described in draft-cragie-tls-ecjpake-01. This can be achieved by
|
||||
using PSA_ALG_TLS12_ECJPAKE_TO_PMS as the key derivation algorithm.
|
||||
|
||||
Security
|
||||
* Fix potential heap buffer overread and overwrite in DTLS if
|
||||
MBEDTLS_SSL_DTLS_CONNECTION_ID is enabled and
|
||||
MBEDTLS_SSL_CID_IN_LEN_MAX > 2 * MBEDTLS_SSL_CID_OUT_LEN_MAX.
|
||||
* An adversary with access to precise enough information about memory
|
||||
accesses (typically, an untrusted operating system attacking a secure
|
||||
enclave) could recover an RSA private key after observing the victim
|
||||
performing a single private-key operation if the window size used for the
|
||||
exponentiation was 3 or smaller. Found and reported by Zili KOU,
|
||||
Wenjian HE, Sharad Sinha, and Wei ZHANG. See "Cache Side-channel Attacks
|
||||
and Defenses of the Sliding Window Algorithm in TEEs" - Design, Automation
|
||||
and Test in Europe 2023.
|
||||
|
||||
Bugfix
|
||||
* Refactor mbedtls_aes_context to support shallow-copying. Fixes #2147.
|
||||
* Fix an issue with in-tree CMake builds in releases with GEN_FILES
|
||||
turned off: if a shipped file was missing from the working directory,
|
||||
it could be turned into a symbolic link to itself.
|
||||
* Fix a long-standing build failure when building x86 PIC code with old
|
||||
gcc (4.x). The code will be slower, but will compile. We do however
|
||||
recommend upgrading to a more recent compiler instead. Fixes #1910.
|
||||
* Fix support for little-endian Microblaze when MBEDTLS_HAVE_ASM is defined.
|
||||
Contributed by Kazuyuki Kimura to fix #2020.
|
||||
* Use double quotes to include private header file psa_crypto_cipher.h.
|
||||
Fixes 'file not found with <angled> include' error
|
||||
when building with Xcode.
|
||||
* Fix handling of broken symlinks when loading certificates using
|
||||
mbedtls_x509_crt_parse_path(). Instead of returning an error as soon as a
|
||||
broken link is encountered, skip the broken link and continue parsing
|
||||
other certificate files. Contributed by Eduardo Silva in #2602.
|
||||
* Fix an interoperability failure between an Mbed TLS client with both
|
||||
TLS 1.2 and TLS 1.3 support, and a TLS 1.2 server that supports
|
||||
rsa_pss_rsae_* signature algorithms. This failed because Mbed TLS
|
||||
advertised support for PSS in both TLS 1.2 and 1.3, but only
|
||||
actually supported PSS in TLS 1.3.
|
||||
* Fix a compilation error when using CMake with an IAR toolchain.
|
||||
Fixes #5964.
|
||||
* Fix a build error due to a missing prototype warning when
|
||||
MBEDTLS_DEPRECATED_REMOVED is enabled.
|
||||
* Fix mbedtls_ctr_drbg_free() on an initialized but unseeded context. When
|
||||
MBEDTLS_AES_ALT is enabled, it could call mbedtls_aes_free() on an
|
||||
uninitialized context.
|
||||
* Fix a build issue on Windows using CMake where the source and build
|
||||
directories could not be on different drives. Fixes #5751.
|
||||
* Fix bugs and missing dependencies when building and testing
|
||||
configurations with only one encryption type enabled in TLS 1.2.
|
||||
* Provide the missing definition of mbedtls_setbuf() in some configurations
|
||||
with MBEDTLS_PLATFORM_C disabled. Fixes #6118, #6196.
|
||||
* Fix compilation errors when trying to build with
|
||||
PSA drivers for AEAD (GCM, CCM, Chacha20-Poly1305).
|
||||
* Fix memory leak in ssl_parse_certificate_request() caused by
|
||||
mbedtls_x509_get_name() not freeing allocated objects in case of error.
|
||||
Change mbedtls_x509_get_name() to clean up allocated objects on error.
|
||||
* Fix build failure with MBEDTLS_RSA_C and MBEDTLS_PSA_CRYPTO_C but not
|
||||
MBEDTLS_USE_PSA_CRYPTO or MBEDTLS_PK_WRITE_C. Fixes #6408.
|
||||
* Fix build failure with MBEDTLS_RSA_C and MBEDTLS_PSA_CRYPTO_C but not
|
||||
MBEDTLS_PK_PARSE_C. Fixes #6409.
|
||||
* Fix ECDSA verification, where it was not always validating the
|
||||
public key. This bug meant that it was possible to verify a
|
||||
signature with an invalid public key, in some cases. Reported by
|
||||
Guido Vranken using Cryptofuzz in #4420.
|
||||
* Fix a possible null pointer dereference if a memory allocation fails
|
||||
in TLS PRF code. Reported by Michael Madsen in #6516.
|
||||
* Fix TLS 1.3 session resumption. Fixes #6488.
|
||||
* Add a configuration check to exclude optional client authentication
|
||||
in TLS 1.3 (where it is forbidden).
|
||||
* Fix a bug in which mbedtls_x509_crt_info() would produce non-printable
|
||||
bytes when parsing certificates containing a binary RFC 4108
|
||||
HardwareModuleName as a Subject Alternative Name extension. Hardware
|
||||
serial numbers are now rendered in hex format. Fixes #6262.
|
||||
* Fix bug in error reporting in dh_genprime.c where upon failure,
|
||||
the error code returned by mbedtls_mpi_write_file() is overwritten
|
||||
and therefore not printed.
|
||||
* In the bignum module, operations of the form (-A) - (+A) or (-A) - (-A)
|
||||
with A > 0 created an unintended representation of the value 0 which was
|
||||
not processed correctly by some bignum operations. Fix this. This had no
|
||||
consequence on cryptography code, but might affect applications that call
|
||||
bignum directly and use negative numbers.
|
||||
* Fix a bug whereby the list of signature algorithms sent as part of
|
||||
the TLS 1.2 server certificate request would get corrupted, meaning the
|
||||
first algorithm would not get sent and an entry consisting of two random
|
||||
bytes would be sent instead. Found by Serban Bejan and Dudek Sebastian.
|
||||
* Fix undefined behavior (typically harmless in practice) of
|
||||
mbedtls_mpi_add_mpi(), mbedtls_mpi_add_abs() and mbedtls_mpi_add_int()
|
||||
when both operands are 0 and the left operand is represented with 0 limbs.
|
||||
* Fix undefined behavior (typically harmless in practice) when some bignum
|
||||
functions receive the most negative value of mbedtls_mpi_sint. Credit
|
||||
to OSS-Fuzz. Fixes #6597.
|
||||
* Fix undefined behavior (typically harmless in practice) in PSA ECB
|
||||
encryption and decryption.
|
||||
* Move some SSL-specific code out of libmbedcrypto where it had been placed
|
||||
accidentally.
|
||||
* Fix a build error when compiling the bignum module for some Arm platforms.
|
||||
Fixes #6089, #6124, #6217.
|
||||
|
||||
Changes
|
||||
* Add the ability to query PSA_WANT_xxx macros to query_compile_time_config.
|
||||
* Calling AEAD tag-specific functions for non-AEAD algorithms (which
|
||||
should not be done - they are documented for use only by AES-GCM and
|
||||
ChaCha20+Poly1305) now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
|
||||
instead of success (0).
|
||||
|
||||
= Mbed TLS 3.2.1 branch released 2022-07-12
|
||||
|
||||
Bugfix
|
||||
* Re-add missing generated file library/ssl_debug_helpers_generated.c
|
||||
* Re-add missing generated file library/psa_crypto_driver_wrappers.c
|
||||
|
||||
= Mbed TLS 3.2.0 branch released 2022-07-11
|
||||
|
||||
@ -249,7 +453,7 @@ Bugfix
|
||||
make to break on a clean checkout. Fixes #5340.
|
||||
* Work around an MSVC ARM64 compiler bug causing incorrect behaviour
|
||||
in mbedtls_mpi_exp_mod(). Reported by Tautvydas Žilys in #5467.
|
||||
* Removed the prompt to exit from all windows build programs that was causing
|
||||
* Removed the prompt to exit from all windows build programs, which was causing
|
||||
issues in CI/CD environments.
|
||||
|
||||
Changes
|
||||
@ -463,7 +667,7 @@ API changes
|
||||
provides better randomness. Instead of HAVEGE, declare OS or hardware RNG
|
||||
interfaces with mbedtls_entropy_add_source() and/or use an entropy seed
|
||||
file created securely during device provisioning. See
|
||||
https://tls.mbed.org/kb/how-to/add-entropy-sources-to-entropy-pool for
|
||||
https://mbed-tls.readthedocs.io/en/latest/kb/how-to/add-entropy-sources-to-entropy-pool/ for
|
||||
more information.
|
||||
* Add missing const attributes to API functions.
|
||||
* Remove helpers for the transition from Mbed TLS 1.3 to Mbed TLS 2.0: the
|
||||
|
@ -1,8 +0,0 @@
|
||||
Features
|
||||
* When GnuTLS/Openssl server is configured in TLS 1.2 mode with a certificate
|
||||
declaring an RSA public key and Mbed TLS is configured in hybrid mode, if
|
||||
`rsa_pss_rsae_*` algorithms are before `rsa_pkcs1_*` ones in this list then
|
||||
the GnuTLS/Openssl server chooses an `rsa_pss_rsae_*` signature algorithm
|
||||
for its signature in the key exchange message. As Mbed TLS 1.2 does not
|
||||
support them, the handshake fails. Add `rsa_pss_rsae_*` support for TLS 1.2
|
||||
to resolve the compitablity issue.
|
8
ChangeLog.d/alignment-perf.txt
Normal file
8
ChangeLog.d/alignment-perf.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Features
|
||||
* General performance improvements by accessing multiple bytes at a time.
|
||||
Fixes #1666.
|
||||
* Improvements to use of unaligned and byte-swapped memory, reducing code
|
||||
size and improving performance (depending on compiler and target
|
||||
architecture).
|
||||
Changes
|
||||
* Mixed-endian systems are explicitly not supported any more.
|
@ -1,4 +0,0 @@
|
||||
Bugfix
|
||||
* Fix a long-standing build failure when building x86 PIC code with old
|
||||
gcc (4.x). The code will be slower, but will compile. We do however
|
||||
recommend upgrading to a more recent compiler instead. Fixes #1910.
|
4
ChangeLog.d/c-build-helper-hostcc.txt
Normal file
4
ChangeLog.d/c-build-helper-hostcc.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Features
|
||||
* Use HOSTCC (if it is set) when compiling C code during generation of the
|
||||
configuration-independent files. This allows them to be generated when
|
||||
CC is set for cross compilation.
|
3
ChangeLog.d/cmake-install.txt
Normal file
3
ChangeLog.d/cmake-install.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Changes
|
||||
* Install the .cmake files into CMAKE_INSTALL_LIBDIR/cmake/MbedTLS,
|
||||
typically /usr/lib/cmake/MbedTLS.
|
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* Fix potential undefined behavior in mbedtls_mpi_sub_abs(). Reported by
|
||||
Pascal Cuoq using TrustInSoft Analyzer in #6701; observed independently by
|
||||
Aaron Ucko under Valgrind.
|
3
ChangeLog.d/crypto_config_ccm_star.txt
Normal file
3
ChangeLog.d/crypto_config_ccm_star.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* List PSA_WANT_ALG_CCM_STAR_NO_TAG in psa/crypto_config.h so that it can
|
||||
be toggled with config.py.
|
3
ChangeLog.d/csr_v3_extensions.txt
Normal file
3
ChangeLog.d/csr_v3_extensions.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Features
|
||||
* Add parsing of V3 extensions (key usage, Netscape cert-type,
|
||||
Subject Alternative Names) in x509 Certificate Sign Requests.
|
@ -1,20 +0,0 @@
|
||||
Features
|
||||
* Some crypto modules that previously depended on MD or a low-level hash
|
||||
module, either unconditionally (RSA, PK, PKCS5, PKCS12, EC J-PAKE), or
|
||||
for some features (PEM for encrypted files), are now able to use PSA
|
||||
Crypto instead when the legacy API is not available. This means it is
|
||||
now possible to use all features from those modules in configurations
|
||||
where the built-in implementations of hashes are excluded and the hashes
|
||||
are only provided by PSA drivers. In these configurations, you need to
|
||||
call `psa_crypto_init()` before you call any function from those
|
||||
modules; this is not required in configurations where the built-in
|
||||
implementation is still available. Note that some crypto modules and
|
||||
features still depend on the built-in implementation of hashes:
|
||||
MBEDTLS_HKDF_C (but the PSA HKDF function do not depend on it),
|
||||
MBEDTLS_ENTROPY_C, MBEDTLS_HMAC_DRBG_C and MBEDTLS_ECDSA_DETERMINISTIC.
|
||||
In particular, for now, compiling without built-in hashes requires use
|
||||
of MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG.
|
||||
* When MBEDTLS_USE_PSA_CRYPTO is enabled, X.509, TLS 1.2 and TLS 1.3 no
|
||||
longer depend on MD. This means it is now possible to use them in
|
||||
configurations where the built-in implementations of hashes are excluded
|
||||
and the hashes are only provided by PSA drivers.
|
@ -1,5 +0,0 @@
|
||||
API changes
|
||||
* Add an ad-hoc key derivation function handling ECJPAKE to PMS
|
||||
calculation that can be used to derive the session secret in TLS 1.2,
|
||||
as described in draft-cragie-tls-ecjpake-01. This can be achieved by
|
||||
using PSA_ALG_TLS12_ECJPAKE_TO_PMS as the key derivation algorithm.
|
@ -1,2 +0,0 @@
|
||||
Changes
|
||||
* Add the ability to query PSA_WANT_xxx macros to query_compile_time_config
|
@ -1,2 +0,0 @@
|
||||
Bugfix
|
||||
* Refactor mbedtls_aes_context to support shallow-copying. Fixes #2147.
|
@ -1,4 +0,0 @@
|
||||
Bugfix
|
||||
* Fix mbedtls_ctr_drbg_free() on an initialized but unseeded context. When
|
||||
MBEDTLS_AES_ALT is enabled, it could call mbedtls_aes_free() on an
|
||||
uninitialized context.
|
4
ChangeLog.d/fix-example-programs-no-args.txt
Normal file
4
ChangeLog.d/fix-example-programs-no-args.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* Fix behavior of certain sample programs which could, when run with no
|
||||
arguments, access uninitialized memory in some cases. Fixes #6700 (which
|
||||
was found by TrustInSoft Analyzer during REDOCS'22) and #1120.
|
3
ChangeLog.d/fix-gettimeofday-overflow.txt
Normal file
3
ChangeLog.d/fix-gettimeofday-overflow.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* Fix possible integer overflow in mbedtls_timing_hardclock(), which
|
||||
could cause a crash in programs/test/benchmark.
|
2
ChangeLog.d/fix-iar-warnings.txt
Normal file
2
ChangeLog.d/fix-iar-warnings.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Bugfix
|
||||
* Fix IAR compiler warnings. Contributed by Glenn Strauss in #3835.
|
3
ChangeLog.d/fix-rsaalt-test-guards.txt
Normal file
3
ChangeLog.d/fix-rsaalt-test-guards.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Bugfix
|
||||
* Fix compile error where MBEDTLS_RSA_C and MBEDTLS_X509_CRT_WRITE_C are
|
||||
defined, but MBEDTLS_PK_RSA_ALT_SUPPORT is not defined. Fixes #3174.
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fix build error due to missing prototype
|
||||
warning when MBEDTLS_DEPRECATED_REMOVED is enabled
|
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* Fix a bug in the build where directory names containing spaces were
|
||||
causing generate_errors.pl to error out resulting in a build failure.
|
||||
Fixes issue #6879.
|
@ -1,4 +0,0 @@
|
||||
Bugfix
|
||||
* Fix bugs and missing dependencies when
|
||||
building and testing configurations with
|
||||
only one encryption type enabled in TLS 1.2.
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fix an issue in releases with GEN_FILES turned off whereby missing
|
||||
generated files could be turned into symlinks to themselves.
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fixed an issue that cause compile error using CMake IAR toolchain.
|
||||
Fixes #5964.
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fix a build issue on Windows where the source and build directory could not be on
|
||||
different drives (#5751).
|
@ -1,4 +0,0 @@
|
||||
Bugfix
|
||||
* Use double quotes to include private header file psa_crypto_cipher.h.
|
||||
Fixes 'file not found with <angled> include' error
|
||||
when building with Xcode.
|
@ -0,0 +1,19 @@
|
||||
Bugfix
|
||||
* mbedtls_x509write_crt_set_serial() now explicitly rejects serial numbers
|
||||
whose binary representation is longer than 20 bytes. This was already
|
||||
forbidden by the standard (RFC5280 - section 4.1.2.2) and now it's being
|
||||
enforced also at code level.
|
||||
|
||||
New deprecations
|
||||
* mbedtls_x509write_crt_set_serial() is now being deprecated in favor of
|
||||
mbedtls_x509write_crt_set_serial_raw(). The goal here is to remove any
|
||||
direct dependency of X509 on BIGNUM_C.
|
||||
|
||||
Changes
|
||||
* programs/x509/cert_write:
|
||||
- now it accepts the serial number in 2 different formats: decimal and
|
||||
hex. They cannot be used simultaneously
|
||||
- "serial" is used for the decimal format and it's limted in size to
|
||||
unsigned long long int
|
||||
- "serial_hex" is used for the hex format; max length here is
|
||||
MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN*2
|
@ -0,0 +1,4 @@
|
||||
Features
|
||||
* SHA224_C/SHA384_C are now independent from SHA384_C/SHA512_C respectively.
|
||||
This helps in saving code size when some of the above hashes are not
|
||||
required.
|
@ -0,0 +1,6 @@
|
||||
Features
|
||||
* Add support for reading points in compressed format
|
||||
(MBEDTLS_ECP_PF_COMPRESSED) with mbedtls_ecp_point_read_binary()
|
||||
(and callers) for Short Weierstrass curves with prime p where p = 3 mod 4
|
||||
(all mbedtls MBEDTLS_ECP_DP_SECP* and MBEDTLS_ECP_DP_BP* curves
|
||||
except MBEDTLS_ECP_DP_SECP224R1 and MBEDTLS_ECP_DP_SECP224K1)
|
@ -1,3 +0,0 @@
|
||||
Bugfix
|
||||
* Fix support for little-endian Microblaze when MBEDTLS_HAVE_ASM is defined.
|
||||
Contributed by Kazuyuki Kimura to fix #2020.
|
@ -1,5 +0,0 @@
|
||||
Features
|
||||
* make: enable building unversioned shared library, with e.g.:
|
||||
"SHARED=1 SOEXT_TLS=so SOEXT_X509=so SOEXT_CRYPTO=so make lib"
|
||||
resulting in library names like "libmbedtls.so" rather than
|
||||
"libmbedcrypto.so.11".
|
5
ChangeLog.d/pk-sign-restartable.txt
Normal file
5
ChangeLog.d/pk-sign-restartable.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Changes
|
||||
* When MBEDTLS_USE_PSA_CRYPTO and MBEDTLS_ECDSA_DETERMINISTIC are both
|
||||
defined, mbedtls_pk_sign() now use deterministic ECDSA for ECDSA
|
||||
signatures. This aligns the behaviour with MBEDTLS_USE_PSA_CRYPTO to
|
||||
the behaviour without it, where deterministic ECDSA was already used.
|
4
ChangeLog.d/psa_alg_tls12_ecjpake_to_pms-reject_ka.txt
Normal file
4
ChangeLog.d/psa_alg_tls12_ecjpake_to_pms-reject_ka.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Bugfix
|
||||
* The key derivation algorithm PSA_ALG_TLS12_ECJPAKE_TO_PMS cannot be
|
||||
used on a shared secret from a key agreement since its input must be
|
||||
an ECC public key. Reject this properly.
|
@ -1,4 +0,0 @@
|
||||
Features
|
||||
* Expose the EC J-PAKE functionality through the Draft PSA PAKE Crypto API.
|
||||
Only the ECC primitive with secp256r1 curve and SHA-256 hash algorithm
|
||||
are supported in this implementation.
|
@ -1,5 +0,0 @@
|
||||
Removals
|
||||
* Remove compression property from SSL session struct.
|
||||
MBEDTLS_SSL_COMPRESS_NULL is now the only supported
|
||||
compression option and can be used for compatibility
|
||||
reasons. Changes requested in #4223.
|
@ -1,3 +0,0 @@
|
||||
Features
|
||||
* Add support for opaque keys as the private keys associated to certificates
|
||||
for authentication in TLS 1.3.
|
4
ChangeLog.d/vs2013.txt
Normal file
4
ChangeLog.d/vs2013.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Changes
|
||||
* Visual Studio: Rename the directory containing Visual Studio files from
|
||||
visualc/VS2010 to visualc/VS2013 as we do not support building with versions
|
||||
older than 2013. Update the solution file to specify VS2013 as a minimum.
|
7
ChangeLog.d/workaround_gnutls_anti_replay_fail.txt
Normal file
7
ChangeLog.d/workaround_gnutls_anti_replay_fail.txt
Normal file
@ -0,0 +1,7 @@
|
||||
Bugfix
|
||||
* In TLS 1.3, when using a ticket for session resumption, tweak its age
|
||||
calculation on the client side. It prevents a server with more accurate
|
||||
ticket timestamps (typically timestamps in milliseconds) compared to the
|
||||
Mbed TLS ticket timestamps (in seconds) to compute a ticket age smaller
|
||||
than the age computed and transmitted by the client and thus potentially
|
||||
reject the ticket. Fix #6623.
|
@ -1,5 +0,0 @@
|
||||
Bugfix
|
||||
* Fix handling of broken symlinks when loading certificates using
|
||||
mbedtls_x509_crt_parse_path(). Instead of returning an error as soon as a
|
||||
broken link is encountered, skip the broken link and continue parsing
|
||||
other certificate files. Contributed by Eduardo Silva in #2602.
|
40
Makefile
40
Makefile
@ -4,7 +4,7 @@ PERL ?= perl
|
||||
|
||||
.SILENT:
|
||||
|
||||
.PHONY: all no_test programs lib tests install uninstall clean test check covtest lcov apidoc apidoc_clean
|
||||
.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
|
||||
|
||||
all: programs tests
|
||||
$(MAKE) post_build
|
||||
@ -37,7 +37,7 @@ generated_files: tests/generated_files
|
||||
generated_files: visualc_files
|
||||
|
||||
.PHONY: visualc_files
|
||||
VISUALC_FILES = visualc/VS2010/mbedTLS.sln visualc/VS2010/mbedTLS.vcxproj
|
||||
VISUALC_FILES = visualc/VS2013/mbedTLS.sln visualc/VS2013/mbedTLS.vcxproj
|
||||
# TODO: $(app).vcxproj for each $(app) in programs/
|
||||
visualc_files: $(VISUALC_FILES)
|
||||
|
||||
@ -46,9 +46,9 @@ visualc_files: $(VISUALC_FILES)
|
||||
# they just need to be present.
|
||||
$(VISUALC_FILES): | library/generated_files
|
||||
$(VISUALC_FILES): scripts/generate_visualc_files.pl
|
||||
$(VISUALC_FILES): scripts/data_files/vs2010-app-template.vcxproj
|
||||
$(VISUALC_FILES): scripts/data_files/vs2010-main-template.vcxproj
|
||||
$(VISUALC_FILES): scripts/data_files/vs2010-sln-template.sln
|
||||
$(VISUALC_FILES): scripts/data_files/vs2013-app-template.vcxproj
|
||||
$(VISUALC_FILES): scripts/data_files/vs2013-main-template.vcxproj
|
||||
$(VISUALC_FILES): scripts/data_files/vs2013-sln-template.sln
|
||||
# TODO: also the list of .c and .h source files, but not their content
|
||||
$(VISUALC_FILES):
|
||||
echo " Gen $@ ..."
|
||||
@ -124,10 +124,10 @@ neat: clean_more_on_top
|
||||
$(MAKE) -C programs neat
|
||||
$(MAKE) -C tests neat
|
||||
ifndef WINDOWS
|
||||
rm -f visualc/VS2010/*.vcxproj visualc/VS2010/mbedTLS.sln
|
||||
rm -f visualc/VS2013/*.vcxproj visualc/VS2013/mbedTLS.sln
|
||||
else
|
||||
if exist visualc\VS2010\*.vcxproj del /Q /F visualc\VS2010\*.vcxproj
|
||||
if exist visualc\VS2010\mbedTLS.sln del /Q /F visualc\VS2010\mbedTLS.sln
|
||||
if exist visualc\VS2013\*.vcxproj del /Q /F visualc\VS2013\*.vcxproj
|
||||
if exist visualc\VS2013\mbedTLS.sln del /Q /F visualc\VS2013\mbedTLS.sln
|
||||
endif
|
||||
|
||||
check: lib tests
|
||||
@ -136,23 +136,15 @@ check: lib tests
|
||||
test: check
|
||||
|
||||
ifndef WINDOWS
|
||||
# note: for coverage testing, build with:
|
||||
# make CFLAGS='--coverage -g3 -O0'
|
||||
covtest:
|
||||
$(MAKE) check
|
||||
programs/test/selftest
|
||||
tests/compat.sh
|
||||
tests/ssl-opt.sh
|
||||
|
||||
# For coverage testing:
|
||||
# 1. Build with:
|
||||
# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
|
||||
# 2. Run the relevant tests for the part of the code you're interested in.
|
||||
# For the reference coverage measurement, see
|
||||
# tests/scripts/basic-build-test.sh
|
||||
# 3. Run scripts/lcov.sh to generate an HTML report.
|
||||
lcov:
|
||||
rm -rf Coverage
|
||||
lcov --capture --initial --directory library -o files.info
|
||||
lcov --rc lcov_branch_coverage=1 --capture --directory library -o tests.info
|
||||
lcov --rc lcov_branch_coverage=1 --add-tracefile files.info --add-tracefile tests.info -o all.info
|
||||
lcov --rc lcov_branch_coverage=1 --remove all.info -o final.info '*.h'
|
||||
gendesc tests/Descriptions.txt -o descriptions
|
||||
genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --branch-coverage -o Coverage final.info
|
||||
rm -f files.info tests.info all.info final.info descriptions
|
||||
scripts/lcov.sh
|
||||
|
||||
apidoc:
|
||||
mkdir -p apidoc
|
||||
|
29
README.md
29
README.md
@ -17,7 +17,9 @@ We provide some non-standard configurations focused on specific use cases in the
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation for the Mbed TLS interfaces in the default library configuration is available as part of the [Mbed TLS documentation](https://tls.mbed.org/api/).
|
||||
The main Mbed TLS documentation is available via [ReadTheDocs](https://mbed-tls.readthedocs.io/).
|
||||
|
||||
Documentation for the PSA Cryptography API is available [on GitHub](https://arm-software.github.io/psa-api/crypto/).
|
||||
|
||||
To generate a local copy of the library documentation in HTML format, tailored to your compile-time configuration:
|
||||
|
||||
@ -103,9 +105,9 @@ Setting the variable `SHARED` in your environment will build shared libraries in
|
||||
|
||||
Please note that setting `CFLAGS` overrides its default value of `-O2` and setting `WARNING_CFLAGS` overrides its default value (starting with `-Wall -Wextra`), so if you just want to add some warning options to the default ones, you can do so by setting `CFLAGS=-O2 -Werror` for example. Setting `WARNING_CFLAGS` is useful when you want to get rid of its default content (for example because your compiler doesn't accept `-Wall` as an option). Directory-specific options cannot be overridden from the command line.
|
||||
|
||||
Depending on your platform, you might run into some issues. Please check the Makefiles in `library/`, `programs/` and `tests/` for options to manually add or remove for specific platforms. You can also check [the Mbed TLS Knowledge Base](https://tls.mbed.org/kb) for articles on your platform or issue.
|
||||
Depending on your platform, you might run into some issues. Please check the Makefiles in `library/`, `programs/` and `tests/` for options to manually add or remove for specific platforms. You can also check [the Mbed TLS Knowledge Base](https://mbed-tls.readthedocs.io/en/latest/kb/) for articles on your platform or issue.
|
||||
|
||||
In case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS Knowledge Base](https://tls.mbed.org/kb).
|
||||
In case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS Knowledge Base](https://mbed-tls.readthedocs.io/en/latest/kb/).
|
||||
|
||||
### CMake
|
||||
|
||||
@ -218,7 +220,7 @@ subproject.
|
||||
|
||||
### Microsoft Visual Studio
|
||||
|
||||
The build files for Microsoft Visual Studio are generated for Visual Studio 2010.
|
||||
The build files for Microsoft Visual Studio are generated for Visual Studio 2013.
|
||||
|
||||
The solution file `mbedTLS.sln` contains all the basic projects needed to build the library and all the programs. The files in tests are not generated and compiled, as these need Python and perl environments as well. However, the selftest program in `programs/test/` is still available.
|
||||
|
||||
@ -240,17 +242,19 @@ For machines with a Unix shell and OpenSSL (and optionally GnuTLS) installed, ad
|
||||
- `tests/ssl-opt.sh` runs integration tests for various TLS options (renegotiation, resumption, etc.) and tests interoperability of these options with other implementations.
|
||||
- `tests/compat.sh` tests interoperability of every ciphersuite with other implementations.
|
||||
- `tests/scripts/test-ref-configs.pl` test builds in various reduced configurations.
|
||||
- `tests/scripts/key-exchanges.pl` test builds in configurations with a single key exchange enabled
|
||||
- `tests/scripts/depends.py` test builds in configurations with a single curve, key exchange, hash, cipher, or pkalg on.
|
||||
- `tests/scripts/all.sh` runs a combination of the above tests, plus some more, with various build options (such as ASan, full `mbedtls_config.h`, etc).
|
||||
|
||||
Instead of manually installing the required versions of all tools required for testing, it is possible to use the Docker images from our CI systems, as explained in [our testing infrastructure repository](https://github.com/Mbed-TLS/mbedtls-test/blob/master/README.md#quick-start).
|
||||
|
||||
Porting Mbed TLS
|
||||
----------------
|
||||
|
||||
Mbed TLS can be ported to many different architectures, OS's and platforms. Before starting a port, you may find the following Knowledge Base articles useful:
|
||||
|
||||
- [Porting Mbed TLS to a new environment or OS](https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS)
|
||||
- [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on)
|
||||
- [How do I configure Mbed TLS](https://tls.mbed.org/kb/compiling-and-building/how-do-i-configure-mbedtls)
|
||||
- [Porting Mbed TLS to a new environment or OS](https://mbed-tls.readthedocs.io/en/latest/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS/)
|
||||
- [What external dependencies does Mbed TLS rely on?](https://mbed-tls.readthedocs.io/en/latest/kb/development/what-external-dependencies-does-mbedtls-rely-on/)
|
||||
- [How do I configure Mbed TLS](https://mbed-tls.readthedocs.io/en/latest/kb/compiling-and-building/how-do-i-configure-mbedtls/)
|
||||
|
||||
Mbed TLS is mostly written in portable C99; however, it has a few platform requirements that go beyond the standard, but are met by most modern architectures:
|
||||
|
||||
@ -259,15 +263,16 @@ Mbed TLS is mostly written in portable C99; however, it has a few platform requi
|
||||
- Signed integers must be represented using two's complement.
|
||||
- `int` and `size_t` must be at least 32 bits wide.
|
||||
- The types `uint8_t`, `uint16_t`, `uint32_t` and their signed equivalents must be available.
|
||||
- Mixed-endian platforms are not supported.
|
||||
|
||||
PSA cryptography API
|
||||
--------------------
|
||||
|
||||
### PSA API design
|
||||
### PSA API
|
||||
|
||||
Arm's [Platform Security Architecture (PSA)](https://developer.arm.com/architectures/security-architectures/platform-security-architecture) is a holistic set of threat models, security analyses, hardware and firmware architecture specifications, and an open source firmware reference implementation. PSA provides a recipe, based on industry best practice, that allows security to be consistently designed in, at both a hardware and firmware level.
|
||||
|
||||
The [PSA cryptography API](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) provides access to a set of cryptographic primitives. It has a dual purpose. First, it can be used in a PSA-compliant platform to build services, such as secure boot, secure storage and secure communication. Second, it can also be used independently of other PSA components on any platform.
|
||||
The [PSA cryptography API](https://arm-software.github.io/psa-api/crypto/) provides access to a set of cryptographic primitives. It has a dual purpose. First, it can be used in a PSA-compliant platform to build services, such as secure boot, secure storage and secure communication. Second, it can also be used independently of other PSA components on any platform.
|
||||
|
||||
The design goals of the PSA cryptography API include:
|
||||
|
||||
@ -279,10 +284,6 @@ The design goals of the PSA cryptography API include:
|
||||
|
||||
Arm welcomes feedback on the design of the API. If you think something could be improved, please open an issue on our Github repository. Alternatively, if you prefer to provide your feedback privately, please email us at [`mbed-crypto@arm.com`](mailto:mbed-crypto@arm.com). All feedback received by email is treated confidentially.
|
||||
|
||||
### PSA API documentation
|
||||
|
||||
A browsable copy of the PSA Cryptography API documents is available on the [PSA cryptography interfaces documentation portal](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) in [PDF](https://armmbed.github.io/mbed-crypto/PSA_Cryptography_API_Specification.pdf) and [HTML](https://armmbed.github.io/mbed-crypto/html/index.html) formats.
|
||||
|
||||
### PSA implementation in Mbed TLS
|
||||
|
||||
Mbed TLS includes a reference implementation of the PSA Cryptography API.
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
Here are some useful sources of information about using Mbed TLS:
|
||||
|
||||
- [ReadTheDocs](https://mbed-tls.readthedocs.io/);
|
||||
- API documentation, see the [Documentation section of the
|
||||
README](README.md#License);
|
||||
README](README.md#documentation);
|
||||
- the `docs` directory in the source tree;
|
||||
- the [Mbed TLS knowledge Base](https://tls.mbed.org/kb);
|
||||
- the [Mbed TLS Knowledge Base](https://mbed-tls.readthedocs.io/en/latest/kb/);
|
||||
- the [Mbed TLS mailing-list
|
||||
archives](https://lists.trustedfirmware.org/archives/list/mbed-tls@lists.trustedfirmware.org/).
|
||||
|
||||
|
@ -47,10 +47,6 @@
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_NET_C
|
||||
/* The library does not currently support enabling SHA-224 without SHA-256.
|
||||
* A future version of the library will have this option disabled
|
||||
* by default. */
|
||||
#define MBEDTLS_SHA224_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SSL_CLI_C
|
||||
#define MBEDTLS_SSL_COOKIE_C
|
||||
@ -73,8 +69,8 @@
|
||||
* save ROM and a few bytes of RAM by specifying our own ciphersuite list
|
||||
*/
|
||||
#define MBEDTLS_SSL_CIPHERSUITES \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
|
||||
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
|
||||
|
||||
/*
|
||||
* Save RAM at the expense of interoperability: do this only if you control
|
||||
|
@ -46,10 +46,6 @@
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_NET_C
|
||||
/* The library does not currently support enabling SHA-224 without SHA-256.
|
||||
* A future version of the library will have this option disabled
|
||||
* by default. */
|
||||
#define MBEDTLS_SHA224_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SSL_CLI_C
|
||||
#define MBEDTLS_SSL_SRV_C
|
||||
@ -64,8 +60,8 @@
|
||||
* save ROM and a few bytes of RAM by specifying our own ciphersuite list
|
||||
*/
|
||||
#define MBEDTLS_SSL_CIPHERSUITES \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
|
||||
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, \
|
||||
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8
|
||||
|
||||
/*
|
||||
* Save RAM at the expense of interoperability: do this only if you control
|
||||
|
@ -60,10 +60,6 @@
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
/* The library does not currently support enabling SHA-224 without SHA-256.
|
||||
* A future version of the library will have this option disabled
|
||||
* by default. */
|
||||
#define MBEDTLS_SHA224_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SHA384_C
|
||||
#define MBEDTLS_SHA512_C
|
||||
|
@ -63,10 +63,6 @@
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
/* The library does not currently support enabling SHA-224 without SHA-256.
|
||||
* A future version of the library will have this option disabled
|
||||
* by default. */
|
||||
#define MBEDTLS_SHA224_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SSL_COOKIE_C
|
||||
#define MBEDTLS_SSL_CLI_C
|
||||
|
@ -141,7 +141,7 @@ recommended), or users who used it through the entropy module but had it as the
|
||||
only source of entropy. If you're in that case, please declare OS or hardware
|
||||
RNG interfaces with `mbedtls_entropy_add_source()` and/or use an entropy seed
|
||||
file created securely during device provisioning. See
|
||||
<https://tls.mbed.org/kb/how-to/add-entropy-sources-to-entropy-pool> for more
|
||||
<https://mbed-tls.readthedocs.io/en/latest/kb/how-to/add-entropy-sources-to-entropy-pool> for more
|
||||
information.
|
||||
|
||||
### Remove helpers for the transition from Mbed TLS 1.3 to Mbed TLS 2.0
|
||||
|
@ -38,7 +38,7 @@ The general principle of an alternative implementation is:
|
||||
* 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.
|
||||
See https://mbed-tls.readthedocs.io/en/latest/kb/development/hw_acc_guidelines for a more detailed guide.
|
||||
|
||||
### Constraints on context types
|
||||
|
||||
|
@ -1,47 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script runs tests in various revisions and configurations and analyses
|
||||
# the results in order to highlight any difference in the set of tests skipped
|
||||
# in the test suites of interest.
|
||||
# This script runs tests before and after a PR and analyzes the results in
|
||||
# order to highlight any difference in the set of tests skipped.
|
||||
#
|
||||
# It can be used to ensure the testing criteria mentioned in strategy.md,
|
||||
# It can be used to check the first testing criterion mentioned in strategy.md,
|
||||
# end of section "Supporting builds with drivers without the software
|
||||
# implementation" are met, namely:
|
||||
# implementation", namely: the sets of tests skipped in the default config and
|
||||
# the full config must be the same before and after the PR.
|
||||
#
|
||||
# - the sets of tests skipped in the default config and the full config must be
|
||||
# the same before and after the PR that implements step 3;
|
||||
# - the set of tests skipped in the driver-only build is the same as in an
|
||||
# equivalent software-based configuration, or the difference is small enough,
|
||||
# justified, and a github issue is created to track it.
|
||||
# USAGE:
|
||||
# - First, commit any uncommited changes. (Also, see warning below.)
|
||||
# - Then launch --> [SKIP_SSL_OPT=1] docs/architecture/psa-migration/outcome-analysis.sh
|
||||
# - SKIP_SSL_OPT=1 can optionally be set to skip ssl-opt.sh tests
|
||||
#
|
||||
# WARNING: this script checks out a commit other than the head of the current
|
||||
# branch; it checks out the current branch again when running successfully,
|
||||
# but while the script is running, or if it terminates early in error, you
|
||||
# should be aware that you might be at a different commit than expected.
|
||||
#
|
||||
# NOTE: This is only an example/template script, you should make a copy and
|
||||
# edit it to suit your needs. The part that needs editing is at the top.
|
||||
#
|
||||
# Also, you can comment out parts that don't need to be re-done when
|
||||
# NOTE: you can comment out parts that don't need to be re-done when
|
||||
# re-running this script (for example "get numbers before this PR").
|
||||
|
||||
# ----- BEGIN edit this -----
|
||||
# The component in all.sh that builds and tests with drivers.
|
||||
DRIVER_COMPONENT=test_psa_crypto_config_accel_hash_use_psa
|
||||
# A similar configuration to that of the component, except without drivers,
|
||||
# for comparison.
|
||||
reference_config () {
|
||||
scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
|
||||
scripts/config.py unset MBEDTLS_PKCS1_V21
|
||||
scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
|
||||
scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
|
||||
}
|
||||
# Space-separated list of test suites of interest.
|
||||
SUITES="rsa pkcs1_v15 pk pkparse pkwrite"
|
||||
# ----- END edit this -----
|
||||
|
||||
set -eu
|
||||
|
||||
: ${SKIP_SSL_OPT:=0}
|
||||
|
||||
cleanup() {
|
||||
make clean
|
||||
git checkout -- include/mbedtls/mbedtls_config.h include/psa/crypto_config.h
|
||||
@ -50,7 +33,14 @@ cleanup() {
|
||||
record() {
|
||||
export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-$1.csv"
|
||||
rm -f $MBEDTLS_TEST_OUTCOME_FILE
|
||||
|
||||
make check
|
||||
|
||||
if [ $SKIP_SSL_OPT -eq 0 ]; then
|
||||
make -C programs ssl/ssl_server2 ssl/ssl_client2 \
|
||||
test/udp_proxy test/query_compile_time_config
|
||||
tests/ssl-opt.sh
|
||||
fi
|
||||
}
|
||||
|
||||
# save current HEAD
|
||||
@ -59,38 +49,55 @@ HEAD=$(git branch --show-current)
|
||||
# get the numbers before this PR for default and full
|
||||
cleanup
|
||||
git checkout $(git merge-base HEAD development)
|
||||
|
||||
record "before-default"
|
||||
|
||||
cleanup
|
||||
|
||||
scripts/config.py full
|
||||
record "before-full"
|
||||
|
||||
# get the numbers now for default and full
|
||||
cleanup
|
||||
git checkout $HEAD
|
||||
|
||||
record "after-default"
|
||||
|
||||
cleanup
|
||||
|
||||
scripts/config.py full
|
||||
record "after-full"
|
||||
|
||||
# get the numbers now for driver-only and reference
|
||||
cleanup
|
||||
reference_config
|
||||
record "reference"
|
||||
|
||||
cleanup
|
||||
export MBEDTLS_TEST_OUTCOME_FILE="$PWD/outcome-drivers.csv"
|
||||
tests/scripts/all.sh -k test_psa_crypto_config_accel_hash_use_psa
|
||||
|
||||
# analysis
|
||||
|
||||
populate_suites () {
|
||||
SUITES=''
|
||||
make generated_files >/dev/null
|
||||
data_files=$(cd tests/suites && echo *.data)
|
||||
for data in $data_files; do
|
||||
suite=${data%.data}
|
||||
SUITES="$SUITES $suite"
|
||||
done
|
||||
make neat
|
||||
|
||||
if [ $SKIP_SSL_OPT -eq 0 ]; then
|
||||
SUITES="$SUITES ssl-opt"
|
||||
extra_files=$(cd tests/opt-testcases && echo *.sh)
|
||||
for extra in $extra_files; do
|
||||
suite=${extra%.sh}
|
||||
SUITES="$SUITES $suite"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
compare_suite () {
|
||||
ref="outcome-$1.csv"
|
||||
new="outcome-$2.csv"
|
||||
suite="$3"
|
||||
|
||||
pattern_suite=";test_suite_$suite;"
|
||||
pattern_suite=";$suite;"
|
||||
total=$(grep -c "$pattern_suite" "$ref")
|
||||
sed_cmd="s/^.*$pattern_suite\(.*\);SKIP.*/\1/p"
|
||||
sed -n "$sed_cmd" "$ref" > skipped-ref
|
||||
@ -98,19 +105,33 @@ compare_suite () {
|
||||
nb_ref=$(wc -l <skipped-ref)
|
||||
nb_new=$(wc -l <skipped-new)
|
||||
|
||||
printf "%12s: total %3d; skipped %3d -> %3d\n" \
|
||||
$suite $total $nb_ref $nb_new
|
||||
diff skipped-ref skipped-new | grep '^> ' || true
|
||||
name=${suite#test_suite_}
|
||||
printf "%40s: total %4d; skipped %4d -> %4d\n" \
|
||||
$name $total $nb_ref $nb_new
|
||||
if diff skipped-ref skipped-new | grep '^> '; then
|
||||
ret=1
|
||||
else
|
||||
ret=0
|
||||
fi
|
||||
rm skipped-ref skipped-new
|
||||
return $ret
|
||||
}
|
||||
|
||||
compare_builds () {
|
||||
printf "\n*** Comparing $1 -> $2 ***\n"
|
||||
failed=''
|
||||
for suite in $SUITES; do
|
||||
compare_suite "$1" "$2" "$suite"
|
||||
if compare_suite "$1" "$2" "$suite"; then :; else
|
||||
failed="$failed $suite"
|
||||
fi
|
||||
done
|
||||
if [ -z "$failed" ]; then
|
||||
printf "No coverage gap found.\n"
|
||||
else
|
||||
printf "Suites with less coverage:%s\n" "$failed"
|
||||
fi
|
||||
}
|
||||
|
||||
populate_suites
|
||||
compare_builds before-default after-default
|
||||
compare_builds before-full after-full
|
||||
compare_builds reference drivers
|
||||
|
@ -17,8 +17,11 @@ Restartable ECC operations
|
||||
There is currently no support for that in PSA at all, but it will be added at
|
||||
some point, see <https://github.com/orgs/Mbed-TLS/projects/1#column-18816849>.
|
||||
|
||||
Currently, `MBEDTLS_USE_PSA_CRYPTO` is simply incompatible with
|
||||
`MBEDTLS_ECP_RESTARTABLE`.
|
||||
Currently, when `MBEDTLS_USE_PSA_CRYPTO` and `MBEDTLS_ECP_RESTARTABLE` are
|
||||
both enabled, some operations that should be restartable are not (ECDH in TLS
|
||||
1.2 clients using ECDHE-ECDSA), as they are using PSA instead, and some
|
||||
operations that should use PSA do not (signature generation & verification) as
|
||||
they use the legacy API instead, in order to get restartable behaviour.
|
||||
|
||||
Things that are in the API but not implemented yet
|
||||
--------------------------------------------------
|
||||
|
@ -386,15 +386,16 @@ are expressed (sometimes in bulk), to get things wrong in a way that would
|
||||
result in more tests being skipped, which is easy to miss. Care must be
|
||||
taken to ensure this does not happen. The following criteria can be used:
|
||||
|
||||
- the sets of tests skipped in the default config and the full config must be
|
||||
the same before and after the PR that implements step 3;
|
||||
- the set of tests skipped in the driver-only build is the same as in an
|
||||
equivalent software-based configuration, or the difference is small enough,
|
||||
justified, and a github issue is created to track it.
|
||||
|
||||
Note that the favourable case is when the number of tests skipped is 0 in the
|
||||
driver-only build. In other cases, analysis of the outcome files is needed,
|
||||
see the example script `outcome-analysis.sh` in the same directory.
|
||||
1. The sets of tests skipped in the default config and the full config must be
|
||||
the same before and after the PR that implements step 3. This is tested
|
||||
manually for each PR that changes dependency declarations by using the script
|
||||
`outcome-analysis.sh` in the present directory.
|
||||
2. The set of tests skipped in the driver-only build is the same as in an
|
||||
equivalent software-based configuration. This is tested automatically by the
|
||||
CI in the "Results analysis" stage, by running
|
||||
`tests/scripts/analyze_outcomes.py`. See the
|
||||
`analyze_driver_vs_reference_xxx` actions in the script and the comments above
|
||||
their declaration for how to do that locally.
|
||||
|
||||
|
||||
Migrating away from the legacy API
|
||||
|
@ -6,7 +6,7 @@ This document is incomplete. You can help by expanding it.
|
||||
|
||||
## Unit tests
|
||||
|
||||
See <https://tls.mbed.org/kb/development/test_suites>
|
||||
See <https://mbed-tls.readthedocs.io/en/latest/kb/development/test_suites>
|
||||
|
||||
### Unit test descriptions
|
||||
|
||||
|
@ -28,9 +28,12 @@ Support description
|
||||
|
||||
- Mbed TLS does not support DHE key establishment.
|
||||
|
||||
- Mbed TLS does not support pre-shared keys, including any form of
|
||||
session resumption. This implies that it does not support sending early
|
||||
data (0-RTT data).
|
||||
- Mbed TLS supports pre-shared keys for key establishment, pre-shared keys
|
||||
provisioned externally as well as provisioned via the ticket mechanism.
|
||||
|
||||
- Mbed TLS supports session resumption via the ticket mechanism.
|
||||
|
||||
- Mbed TLS does not support sending or receiving early data (0-RTT data).
|
||||
|
||||
- Supported cipher suites: depends on the library configuration. Potentially
|
||||
all of them:
|
||||
@ -54,8 +57,8 @@ Support description
|
||||
| server_certificate_type | no |
|
||||
| padding | no |
|
||||
| key_share | YES |
|
||||
| pre_shared_key | no |
|
||||
| psk_key_exchange_modes | no |
|
||||
| pre_shared_key | YES |
|
||||
| psk_key_exchange_modes | YES |
|
||||
| early_data | no |
|
||||
| cookie | no |
|
||||
| supported_versions | YES |
|
||||
@ -118,7 +121,7 @@ Support description
|
||||
| MBEDTLS_SSL_RENEGOTIATION | n/a |
|
||||
| MBEDTLS_SSL_MAX_FRAGMENT_LENGTH | no |
|
||||
| | |
|
||||
| MBEDTLS_SSL_SESSION_TICKETS | no |
|
||||
| MBEDTLS_SSL_SESSION_TICKETS | yes |
|
||||
| MBEDTLS_SSL_SERVER_NAME_INDICATION | yes |
|
||||
| MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH | no |
|
||||
| | |
|
||||
@ -141,10 +144,33 @@ Support description
|
||||
| MBEDTLS_USE_PSA_CRYPTO | yes |
|
||||
|
||||
(1) These options must remain in their default state of enabled.
|
||||
(2) Key exchange configuration options for TLS 1.3 will likely to be
|
||||
organized around the notion of key exchange mode along the line
|
||||
of the MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE/PSK/PSK_EPHEMERAL/EPHEMERAL
|
||||
runtime configuration macros.
|
||||
(2) See the TLS 1.3 specific build options section below.
|
||||
|
||||
- TLS 1.3 specific build options:
|
||||
|
||||
- MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE enables the support for middlebox
|
||||
compatibility mode as defined in section D.4 of RFC 8446.
|
||||
|
||||
- MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED enables the support for
|
||||
the PSK key exchange mode as defined by RFC 8446. If it is the only key
|
||||
exchange mode enabled, the TLS 1.3 implementation does not contain any code
|
||||
related to key exchange protocols, certificates and signatures.
|
||||
|
||||
- MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED enables the
|
||||
support for the ephemeral key exchange mode. If it is the only key exchange
|
||||
mode enabled, the TLS 1.3 implementation does not contain any code related
|
||||
to PSK based key exchange. The ephemeral key exchange mode requires at least
|
||||
one of the key exchange protocol allowed by the TLS 1.3 specification, the
|
||||
parsing and validation of x509 certificates and at least one signature
|
||||
algorithm allowed by the TLS 1.3 specification for signature computing and
|
||||
verification.
|
||||
|
||||
- MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED enables the
|
||||
support for the PSK ephemeral key exchange mode. If it is the only key
|
||||
exchange mode enabled, the TLS 1.3 implementation does not contain any code
|
||||
related to certificates and signatures. The PSK ephemeral key exchange
|
||||
mode requires at least one of the key exchange protocol allowed by the
|
||||
TLS 1.3 specification.
|
||||
|
||||
|
||||
Prototype upstreaming status
|
||||
@ -152,8 +178,7 @@ Prototype upstreaming status
|
||||
|
||||
The following parts of the TLS 1.3 prototype remain to be upstreamed:
|
||||
|
||||
- Pre-shared keys, session resumption and 0-RTT data (both client and server
|
||||
side).
|
||||
- Sending (client) and receiving (server) early data (0-RTT data).
|
||||
|
||||
- New TLS Message Processing Stack (MPS)
|
||||
|
||||
@ -181,7 +206,7 @@ Coding rules checklist for TLS 1.3
|
||||
The following coding rules are aimed to be a checklist for TLS 1.3 upstreaming
|
||||
work to reduce review rounds and the number of comments in each round. They
|
||||
come along (do NOT replace) the project coding rules
|
||||
(https://tls.mbed.org/kb/development/mbedtls-coding-standards). They have been
|
||||
(https://mbed-tls.readthedocs.io/en/latest/kb/development/mbedtls-coding-standards). They have been
|
||||
established and discussed following the review of #4882 that was the
|
||||
PR upstreaming the first part of TLS 1.3 ClientHello writing code.
|
||||
|
||||
@ -453,3 +478,175 @@ outbound message on server side as well.
|
||||
|
||||
* state change: the state change is done in the main state handler to ease
|
||||
the navigation of the state machine transitions.
|
||||
|
||||
|
||||
Writing and reading early or 0-RTT data
|
||||
---------------------------------------
|
||||
|
||||
An application function to write and send a buffer of data to a server through
|
||||
TLS may plausibly look like:
|
||||
|
||||
```
|
||||
int write_data( mbedtls_ssl_context *ssl,
|
||||
const unsigned char *data_to_write,
|
||||
size_t data_to_write_len,
|
||||
size_t *data_written )
|
||||
{
|
||||
*data_written = 0;
|
||||
|
||||
while( *data_written < data_to_write_len )
|
||||
{
|
||||
ret = mbedtls_ssl_write( ssl, data_to_write + *data_written,
|
||||
data_to_write_len - *data_written );
|
||||
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_READ &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
*data_written += ret;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
```
|
||||
where ssl is the SSL context to use, data_to_write the address of the data
|
||||
buffer and data_to_write_len the number of data bytes. The handshake may
|
||||
not be completed, not even started for the SSL context ssl when the function is
|
||||
called and in that case the mbedtls_ssl_write() API takes care transparently of
|
||||
completing the handshake before to write and send data to the server. The
|
||||
mbedtls_ssl_write() may not been able to write and send all data in one go thus
|
||||
the need for a loop calling it as long as there are still data to write and
|
||||
send.
|
||||
|
||||
An application function to write and send early data and only early data,
|
||||
data sent during the first flight of client messages while the handshake is in
|
||||
its initial phase, would look completely similar but the call to
|
||||
mbedtls_ssl_write_early_data() instead of mbedtls_ssl_write().
|
||||
```
|
||||
int write_early_data( mbedtls_ssl_context *ssl,
|
||||
const unsigned char *data_to_write,
|
||||
size_t data_to_write_len,
|
||||
size_t *data_written )
|
||||
{
|
||||
*data_written = 0;
|
||||
|
||||
while( *data_written < data_to_write_len )
|
||||
{
|
||||
ret = mbedtls_ssl_write_early_data( ssl, data_to_write + *data_written,
|
||||
data_to_write_len - *data_written );
|
||||
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_READ &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
*data_written += ret;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
```
|
||||
Note that compared to write_data(), write_early_data() can also return
|
||||
MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA and that should be handled
|
||||
specifically by the user of write_early_data(). A fresh SSL context (typically
|
||||
just after a call to mbedtls_ssl_setup() or mbedtls_ssl_session_reset()) would
|
||||
be expected when calling `write_early_data`.
|
||||
|
||||
All together, code to write and send a buffer of data as long as possible as
|
||||
early data and then as standard post-handshake application data could
|
||||
plausibly look like:
|
||||
|
||||
```
|
||||
ret = write_early_data( ssl, data_to_write, data_to_write_len,
|
||||
&early_data_written );
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = write_data( ssl, data_to_write + early_data_written,
|
||||
data_to_write_len - early_data_written, &data_written );
|
||||
if( ret < 0 )
|
||||
goto error;
|
||||
|
||||
data_written += early_data_written;
|
||||
```
|
||||
|
||||
Finally, taking into account that the server may reject early data, application
|
||||
code to write and send a buffer of data could plausibly look like:
|
||||
```
|
||||
ret = write_early_data( ssl, data_to_write, data_to_write_len,
|
||||
&early_data_written );
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure the handshake is completed as it is a requisite to
|
||||
* mbedtls_ssl_get_early_data_status().
|
||||
*/
|
||||
while( !mbedtls_ssl_is_handshake_over( ssl ) )
|
||||
{
|
||||
ret = mbedtls_ssl_handshake( ssl );
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_READ &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
ret = mbedtls_ssl_get_early_data_status( ssl );
|
||||
if( ret < 0 )
|
||||
goto error;
|
||||
|
||||
if( ret == MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED )
|
||||
early_data_written = 0;
|
||||
|
||||
ret = write_data( ssl, data_to_write + early_data_written,
|
||||
data_to_write_len - early_data_written, &data_written );
|
||||
if( ret < 0 )
|
||||
goto error;
|
||||
|
||||
data_written += early_data_written;
|
||||
```
|
||||
|
||||
Basically, the same holds for reading early data on the server side without the
|
||||
complication of possible rejection. An application function to read early data
|
||||
into a given buffer could plausibly look like:
|
||||
```
|
||||
int read_early_data( mbedtls_ssl_context *ssl,
|
||||
unsigned char *buffer,
|
||||
size_t buffer_size,
|
||||
size_t *data_len )
|
||||
{
|
||||
*data_len = 0;
|
||||
|
||||
while( *data_len < buffer_size )
|
||||
{
|
||||
ret = mbedtls_ssl_read_early_data( ssl, buffer + *data_len,
|
||||
buffer_size - *data_len );
|
||||
|
||||
if( ret < 0 &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_READ &&
|
||||
ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||
{
|
||||
return( ret );
|
||||
}
|
||||
|
||||
*data_len += ret;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
```
|
||||
with again calls to read_early_data() expected to be done with a fresh SSL
|
||||
context.
|
||||
|
@ -1,8 +1,9 @@
|
||||
## Getting started with Mbed Crypto
|
||||
## Getting started with Mbed TLS
|
||||
|
||||
### What is Mbed Crypto?
|
||||
### What is Mbed TLS?
|
||||
|
||||
Mbed Crypto is an open source cryptographic library that supports a wide range of cryptographic operations, including:
|
||||
Mbed TLS is an open source cryptographic library that supports a wide range of
|
||||
cryptographic operations, including:
|
||||
* Key management
|
||||
* Hashing
|
||||
* Symmetric cryptography
|
||||
@ -11,20 +12,25 @@ Mbed Crypto is an open source cryptographic library that supports a wide range o
|
||||
* Key generation and derivation
|
||||
* Authenticated encryption with associated data (AEAD)
|
||||
|
||||
The Mbed Crypto library is a reference implementation of the cryptography interface of the Arm Platform Security Architecture (PSA). It is written in portable C.
|
||||
Mbed TLS provides a reference implementation of the cryptography interface of
|
||||
the Arm Platform Security Architecture (PSA). It is written in portable C.
|
||||
|
||||
The Mbed Crypto library is distributed under the Apache License, version 2.0.
|
||||
Mbed TLS is distributed under the Apache License, version 2.0.
|
||||
|
||||
#### Platform Security Architecture (PSA)
|
||||
|
||||
Arm's Platform Security Architecture (PSA) is a holistic set of threat models,
|
||||
security analyses, hardware and firmware architecture specifications, and an open source firmware reference implementation. PSA provides a recipe, based on industry best practice, that enables you to design security into both hardware and firmware consistently. Part of the API provided by PSA is the cryptography interface, which provides access to a set of primitives.
|
||||
security analyses, hardware and firmware architecture specifications, and an
|
||||
open source firmware reference implementation. PSA provides a recipe, based on
|
||||
industry best practice, that enables you to design security into both hardware
|
||||
and firmware consistently. Part of the API provided by PSA is the cryptography
|
||||
interface, which provides access to a set of primitives.
|
||||
|
||||
### Using Mbed Crypto
|
||||
### Using Mbed TLS
|
||||
|
||||
* [Getting the Mbed Crypto library](#getting-the-mbed-crypto-library)
|
||||
* [Building the Mbed Crypto library](#building-the-mbed-crypto-library)
|
||||
* [Using the Mbed Crypto library](#using-the-mbed-crypto-library)
|
||||
* [Getting the Mbed TLS library](#getting-the-mbed-tls-library)
|
||||
* [Building the Mbed TLS library](#building-the-mbed-tls-library)
|
||||
* [Using the PSA Crypto API](#using-the-psa-crypto-api)
|
||||
* [Importing a key](#importing-a-key)
|
||||
* [Signing a message using RSA](#signing-a-message-using-RSA)
|
||||
* [Encrypting or decrypting using symmetric ciphers](#encrypting-or-decrypting-using-symmetric-ciphers)
|
||||
@ -33,37 +39,45 @@ security analyses, hardware and firmware architecture specifications, and an ope
|
||||
* [Generating a random value](#generating-a-random-value)
|
||||
* [Authenticating and encrypting or decrypting a message](#authenticating-and-encrypting-or-decrypting-a-message)
|
||||
* [Generating and exporting keys](#generating-and-exporting-keys)
|
||||
* [More about the Mbed Crypto library](#more-about-the-mbed-crypto-library)
|
||||
* [More about the PSA Crypto API](#more-about-the-psa-crypto-api)
|
||||
|
||||
### Getting the Mbed Crypto library
|
||||
### Getting the Mbed TLS library
|
||||
|
||||
Mbed Crypto releases are available in the [public GitHub repository](https://github.com/ARMmbed/mbed-crypto).
|
||||
Mbed TLS releases are available in the [public GitHub repository](https://github.com/Mbed-TLS/mbedtls).
|
||||
|
||||
### Building the Mbed Crypto library
|
||||
### Building the Mbed TLS library
|
||||
|
||||
**Prerequisites to building the library with the provided makefiles:**
|
||||
* GNU Make.
|
||||
* A C toolchain (compiler, linker, archiver).
|
||||
* Python 2 or Python 3 (either works) to generate the test code.
|
||||
* A C toolchain (compiler, linker, archiver) that supports C99.
|
||||
* Python 3.6 to generate the test code.
|
||||
* Perl to run the tests.
|
||||
|
||||
If you have a C compiler such as GCC or Clang, just run `make` in the top-level directory to build the library, a set of unit tests and some sample programs.
|
||||
If you have a C compiler such as GCC or Clang, just run `make` in the top-level
|
||||
directory to build the library, a set of unit tests and some sample programs.
|
||||
|
||||
To select a different compiler, set the `CC` variable to the name or path of the compiler and linker (default: `cc`) and set `AR` to a compatible archiver (default: `ar`); for example:
|
||||
To select a different compiler, set the `CC` variable to the name or path of the
|
||||
compiler and linker (default: `cc`) and set `AR` to a compatible archiver
|
||||
(default: `ar`); for example:
|
||||
```
|
||||
make CC=arm-linux-gnueabi-gcc AR=arm-linux-gnueabi-ar
|
||||
```
|
||||
The provided makefiles pass options to the compiler that assume a GCC-like command line syntax. To use a different compiler, you may need to pass different values for `CFLAGS`, `WARNINGS_CFLAGS` and `LDFLAGS`.
|
||||
The provided makefiles pass options to the compiler that assume a GCC-like
|
||||
command line syntax. To use a different compiler, you may need to pass different
|
||||
values for `CFLAGS`, `WARNINGS_CFLAGS` and `LDFLAGS`.
|
||||
|
||||
To run the unit tests on the host machine, run `make test` from the top-level directory. If you are cross-compiling, copy the test executable from the `tests` directory to the target machine.
|
||||
To run the unit tests on the host machine, run `make test` from the top-level
|
||||
directory. If you are cross-compiling, copy the test executable from the `tests`
|
||||
directory to the target machine.
|
||||
|
||||
### Using the Mbed Crypto library
|
||||
### Using the PSA Crypto API
|
||||
|
||||
To use the Mbed Crypto APIs, call `psa_crypto_init()` before calling any other API. This initializes the library.
|
||||
If using PSA Crypto, you must initialize the library by calling
|
||||
`psa_crypto_init()` before any other PSA API.
|
||||
|
||||
### Importing a key
|
||||
|
||||
To use a key for cryptography operations in Mbed Crypto, you need to first
|
||||
To use a key for cryptography operations in PSA, you need to first
|
||||
import it. The import operation returns the identifier of the key for use
|
||||
with other function calls.
|
||||
|
||||
@ -114,7 +128,8 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
||||
|
||||
### Signing a message using RSA
|
||||
|
||||
Mbed Crypto supports encrypting, decrypting, signing and verifying messages using public key signature algorithms, such as RSA or ECDSA.
|
||||
The PSA Crypto API supports encrypting, decrypting, signing and verifying
|
||||
messages using public key signature algorithms, such as RSA or ECDSA.
|
||||
|
||||
**Prerequisites to performing asymmetric signature operations:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
@ -184,21 +199,33 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
||||
|
||||
### Using symmetric ciphers
|
||||
|
||||
Mbed Crypto supports encrypting and decrypting messages using various symmetric cipher algorithms (both block and stream ciphers).
|
||||
The PSA Crypto API supports encrypting and decrypting messages using various
|
||||
symmetric cipher algorithms (both block and stream ciphers).
|
||||
|
||||
**Prerequisites to working with the symmetric cipher API:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
* Have a symmetric key. This key's usage flags must include `PSA_KEY_USAGE_ENCRYPT` to allow encryption or `PSA_KEY_USAGE_DECRYPT` to allow decryption.
|
||||
* Have a symmetric key. This key's usage flags must include
|
||||
`PSA_KEY_USAGE_ENCRYPT` to allow encryption or `PSA_KEY_USAGE_DECRYPT` to
|
||||
allow decryption.
|
||||
|
||||
**To encrypt a message with a symmetric cipher:**
|
||||
1. Allocate an operation (`psa_cipher_operation_t`) structure to pass to the cipher functions.
|
||||
1. Allocate an operation (`psa_cipher_operation_t`) structure to pass to the
|
||||
cipher functions.
|
||||
1. Initialize the operation structure to zero or to `PSA_CIPHER_OPERATION_INIT`.
|
||||
1. Call `psa_cipher_encrypt_setup()` to specify the algorithm and the key to be used.
|
||||
1. Call either `psa_cipher_generate_iv()` or `psa_cipher_set_iv()` to generate or set the initialization vector (IV). We recommend calling `psa_cipher_generate_iv()`, unless you require a specific IV value.
|
||||
1. Call `psa_cipher_update()` with the message to encrypt. You may call this function multiple times, passing successive fragments of the message on successive calls.
|
||||
1. Call `psa_cipher_finish()` to end the operation and output the encrypted message.
|
||||
1. Call `psa_cipher_encrypt_setup()` to specify the algorithm and the key to be
|
||||
used.
|
||||
1. Call either `psa_cipher_generate_iv()` or `psa_cipher_set_iv()` to generate
|
||||
or set the initialization vector (IV). We recommend calling
|
||||
`psa_cipher_generate_iv()`, unless you require a specific IV value.
|
||||
1. Call `psa_cipher_update()` with the message to encrypt. You may call this
|
||||
function multiple times, passing successive fragments of the message on
|
||||
successive calls.
|
||||
1. Call `psa_cipher_finish()` to end the operation and output the encrypted
|
||||
message.
|
||||
|
||||
This example shows how to encrypt data using an AES (Advanced Encryption Standard) key in CBC (Cipher Block Chaining) mode with no padding (assuming all prerequisites have been fulfilled):
|
||||
This example shows how to encrypt data using an AES (Advanced Encryption
|
||||
Standard) key in CBC (Cipher Block Chaining) mode with no padding (assuming all
|
||||
prerequisites have been fulfilled):
|
||||
```c
|
||||
void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
{
|
||||
@ -275,15 +302,20 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
```
|
||||
|
||||
**To decrypt a message with a symmetric cipher:**
|
||||
1. Allocate an operation (`psa_cipher_operation_t`) structure to pass to the cipher functions.
|
||||
1. Allocate an operation (`psa_cipher_operation_t`) structure to pass to the
|
||||
cipher functions.
|
||||
1. Initialize the operation structure to zero or to `PSA_CIPHER_OPERATION_INIT`.
|
||||
1. Call `psa_cipher_decrypt_setup()` to specify the algorithm and the key to be used.
|
||||
1. Call `psa_cipher_decrypt_setup()` to specify the algorithm and the key to be
|
||||
used.
|
||||
1. Call `psa_cipher_set_iv()` with the IV for the decryption.
|
||||
1. Call `psa_cipher_update()` with the message to encrypt. You may call this function multiple times, passing successive fragments of the message on successive calls.
|
||||
1. Call `psa_cipher_finish()` to end the operation and output the decrypted message.
|
||||
1. Call `psa_cipher_update()` with the message to encrypt. You may call this
|
||||
function multiple times, passing successive fragments of the message on
|
||||
successive calls.
|
||||
1. Call `psa_cipher_finish()` to end the operation and output the decrypted
|
||||
message.
|
||||
|
||||
This example shows how to decrypt encrypted data using an AES key in CBC mode with no padding
|
||||
(assuming all prerequisites have been fulfilled):
|
||||
This example shows how to decrypt encrypted data using an AES key in CBC mode
|
||||
with no padding (assuming all prerequisites have been fulfilled):
|
||||
```c
|
||||
void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
{
|
||||
@ -360,34 +392,49 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
||||
|
||||
#### Handling cipher operation contexts
|
||||
|
||||
After you've initialized the operation structure with a successful call to `psa_cipher_encrypt_setup()` or `psa_cipher_decrypt_setup()`, you can terminate the operation at any time by calling `psa_cipher_abort()`.
|
||||
After you've initialized the operation structure with a successful call to
|
||||
`psa_cipher_encrypt_setup()` or `psa_cipher_decrypt_setup()`, you can terminate
|
||||
the operation at any time by calling `psa_cipher_abort()`.
|
||||
|
||||
The call to `psa_cipher_abort()` frees any resources associated with the operation, except for the operation structure itself.
|
||||
The call to `psa_cipher_abort()` frees any resources associated with the
|
||||
operation, except for the operation structure itself.
|
||||
|
||||
Mbed Crypto implicitly calls `psa_cipher_abort()` when:
|
||||
* A call to `psa_cipher_generate_iv()`, `psa_cipher_set_iv()` or `psa_cipher_update()` fails (returning any status other than `PSA_SUCCESS`).
|
||||
The PSA Crypto API implicitly calls `psa_cipher_abort()` when:
|
||||
* A call to `psa_cipher_generate_iv()`, `psa_cipher_set_iv()` or
|
||||
`psa_cipher_update()` fails (returning any status other than `PSA_SUCCESS`).
|
||||
* A call to `psa_cipher_finish()` succeeds or fails.
|
||||
|
||||
After an implicit or explicit call to `psa_cipher_abort()`, the operation structure is invalidated; in other words, you cannot reuse the operation structure for the same operation. You can, however, reuse the operation structure for a different operation by calling either `psa_cipher_encrypt_setup()` or `psa_cipher_decrypt_setup()` again.
|
||||
After an implicit or explicit call to `psa_cipher_abort()`, the operation
|
||||
structure is invalidated; in other words, you cannot reuse the operation
|
||||
structure for the same operation. You can, however, reuse the operation
|
||||
structure for a different operation by calling either
|
||||
`psa_cipher_encrypt_setup()` or `psa_cipher_decrypt_setup()` again.
|
||||
|
||||
You must call `psa_cipher_abort()` at some point for any operation that is initialized successfully (by a successful call to `psa_cipher_encrypt_setup()` or `psa_cipher_decrypt_setup()`).
|
||||
You must call `psa_cipher_abort()` at some point for any operation that is
|
||||
initialized successfully (by a successful call to `psa_cipher_encrypt_setup()`
|
||||
or `psa_cipher_decrypt_setup()`).
|
||||
|
||||
Making multiple sequential calls to `psa_cipher_abort()` on an operation that is terminated (either implicitly or explicitly) is safe and has no effect.
|
||||
Making multiple sequential calls to `psa_cipher_abort()` on an operation that
|
||||
is terminated (either implicitly or explicitly) is safe and has no effect.
|
||||
|
||||
### Hashing a message
|
||||
|
||||
Mbed Crypto lets you compute and verify hashes using various hashing
|
||||
The PSA Crypto API lets you compute and verify hashes using various hashing
|
||||
algorithms.
|
||||
|
||||
**Prerequisites to working with the hash APIs:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
|
||||
**To calculate a hash:**
|
||||
1. Allocate an operation structure (`psa_hash_operation_t`) to pass to the hash functions.
|
||||
1. Allocate an operation structure (`psa_hash_operation_t`) to pass to the hash
|
||||
functions.
|
||||
1. Initialize the operation structure to zero or to `PSA_HASH_OPERATION_INIT`.
|
||||
1. Call `psa_hash_setup()` to specify the hash algorithm.
|
||||
1. Call `psa_hash_update()` with the message to encrypt. You may call this function multiple times, passing successive fragments of the message on successive calls.
|
||||
1. Call `psa_hash_finish()` to calculate the hash, or `psa_hash_verify()` to compare the computed hash with an expected hash value.
|
||||
1. Call `psa_hash_update()` with the message to encrypt. You may call this
|
||||
function multiple times, passing successive fragments of the message on
|
||||
successive calls.
|
||||
1. Call `psa_hash_finish()` to calculate the hash, or `psa_hash_verify()` to
|
||||
compare the computed hash with an expected hash value.
|
||||
|
||||
This example shows how to calculate the SHA-256 hash of a message:
|
||||
```c
|
||||
@ -482,33 +529,46 @@ This example shows how to verify the SHA-256 hash of a message:
|
||||
mbedtls_psa_crypto_free();
|
||||
```
|
||||
|
||||
The API provides the macro `PSA_HASH_LENGTH`, which returns the expected hash length (in bytes) for the specified algorithm.
|
||||
The API provides the macro `PSA_HASH_LENGTH`, which returns the expected hash
|
||||
length (in bytes) for the specified algorithm.
|
||||
|
||||
#### Handling hash operation contexts
|
||||
|
||||
After a successful call to `psa_hash_setup()`, you can terminate the operation at any time by calling `psa_hash_abort()`. The call to `psa_hash_abort()` frees any resources associated with the operation, except for the operation structure itself.
|
||||
After a successful call to `psa_hash_setup()`, you can terminate the operation
|
||||
at any time by calling `psa_hash_abort()`. The call to `psa_hash_abort()` frees
|
||||
any resources associated with the operation, except for the operation structure
|
||||
itself.
|
||||
|
||||
Mbed Crypto implicitly calls `psa_hash_abort()` when:
|
||||
1. A call to `psa_hash_update()` fails (returning any status other than `PSA_SUCCESS`).
|
||||
The PSA Crypto API implicitly calls `psa_hash_abort()` when:
|
||||
1. A call to `psa_hash_update()` fails (returning any status other than
|
||||
`PSA_SUCCESS`).
|
||||
1. A call to `psa_hash_finish()` succeeds or fails.
|
||||
1. A call to `psa_hash_verify()` succeeds or fails.
|
||||
|
||||
After an implicit or explicit call to `psa_hash_abort()`, the operation structure is invalidated; in other words, you cannot reuse the operation structure for the same operation. You can, however, reuse the operation structure for a different operation by calling `psa_hash_setup()` again.
|
||||
After an implicit or explicit call to `psa_hash_abort()`, the operation
|
||||
structure is invalidated; in other words, you cannot reuse the operation
|
||||
structure for the same operation. You can, however, reuse the operation
|
||||
structure for a different operation by calling `psa_hash_setup()` again.
|
||||
|
||||
You must call `psa_hash_abort()` at some point for any operation that is initialized successfully (by a successful call to `psa_hash_setup()`) .
|
||||
You must call `psa_hash_abort()` at some point for any operation that is
|
||||
initialized successfully (by a successful call to `psa_hash_setup()`) .
|
||||
|
||||
Making multiple sequential calls to `psa_hash_abort()` on an operation that has already been terminated (either implicitly or explicitly) is safe and has no effect.
|
||||
Making multiple sequential calls to `psa_hash_abort()` on an operation that has
|
||||
already been terminated (either implicitly or explicitly) is safe and has no
|
||||
effect.
|
||||
|
||||
### Generating a random value
|
||||
|
||||
Mbed Crypto can generate random data.
|
||||
The PSA Crypto API can generate random data.
|
||||
|
||||
**Prerequisites to generating random data:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
|
||||
<span class="notes">**Note:** To generate a random key, use `psa_generate_key()` instead of `psa_generate_random()`.</span>
|
||||
<span class="notes">**Note:** To generate a random key, use `psa_generate_key()`
|
||||
instead of `psa_generate_random()`.</span>
|
||||
|
||||
This example shows how to generate ten bytes of random data by calling `psa_generate_random()`:
|
||||
This example shows how to generate ten bytes of random data by calling
|
||||
`psa_generate_random()`:
|
||||
```C
|
||||
psa_status_t status;
|
||||
uint8_t random[10] = { 0 };
|
||||
@ -537,16 +597,19 @@ This example shows how to generate ten bytes of random data by calling `psa_gene
|
||||
|
||||
### Deriving a new key from an existing key
|
||||
|
||||
Mbed Crypto provides a key derivation API that lets you derive new keys from
|
||||
existing ones. The key derivation API has functions to take inputs, including
|
||||
other keys and data, and functions to generate outputs, such as new keys or
|
||||
other data.
|
||||
The PSA Crypto API provides a key derivation API that lets you derive new keys
|
||||
from existing ones. The key derivation API has functions to take inputs,
|
||||
including other keys and data, and functions to generate outputs, such as
|
||||
new keys or other data.
|
||||
|
||||
You must first initialize and set up a key derivation context,
|
||||
provided with a key and, optionally, other data. Then, use the key derivation context to either read derived data to a buffer or send derived data directly to a key slot.
|
||||
provided with a key and, optionally, other data. Then, use the key derivation
|
||||
context to either read derived data to a buffer or send derived data directly
|
||||
to a key slot.
|
||||
|
||||
See the documentation for the particular algorithm (such as HKDF or the TLS1.2 PRF) for
|
||||
information about which inputs to pass when, and when you can obtain which outputs.
|
||||
See the documentation for the particular algorithm (such as HKDF or the
|
||||
TLS 1.2 PRF) for information about which inputs to pass when, and when you can
|
||||
obtain which outputs.
|
||||
|
||||
**Prerequisites to working with the key derivation APIs:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
@ -563,11 +626,11 @@ with a given key, salt and info:**
|
||||
function, specifying the derivation algorithm `PSA_ALG_HKDF(PSA_ALG_SHA_256)`.
|
||||
1. Provide an optional salt with `psa_key_derivation_input_bytes()`.
|
||||
1. Provide info with `psa_key_derivation_input_bytes()`.
|
||||
1. Provide a secret with `psa_key_derivation_input_key()`, referencing a key that
|
||||
can be used for key derivation.
|
||||
1. Provide a secret with `psa_key_derivation_input_key()`, referencing a key
|
||||
that can be used for key derivation.
|
||||
1. Set the key attributes desired for the new derived key. We'll set
|
||||
the `PSA_KEY_USAGE_ENCRYPT` usage flag and the `PSA_ALG_CTR` algorithm for this
|
||||
example.
|
||||
the `PSA_KEY_USAGE_ENCRYPT` usage flag and the `PSA_ALG_CTR` algorithm for
|
||||
this example.
|
||||
1. Derive the key by calling `psa_key_derivation_output_key()`.
|
||||
1. Clean up the key derivation context.
|
||||
|
||||
@ -675,11 +738,13 @@ derived from the key, salt and info provided:
|
||||
|
||||
### Authenticating and encrypting or decrypting a message
|
||||
|
||||
Mbed Crypto provides a simple way to authenticate and encrypt with associated data (AEAD), supporting the `PSA_ALG_CCM` algorithm.
|
||||
The PSA Crypto API provides a simple way to authenticate and encrypt with
|
||||
associated data (AEAD), supporting the `PSA_ALG_CCM` algorithm.
|
||||
|
||||
**Prerequisites to working with the AEAD cipher APIs:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
* The key attributes for the key used for derivation must have the `PSA_KEY_USAGE_ENCRYPT` or `PSA_KEY_USAGE_DECRYPT` usage flags.
|
||||
* The key attributes for the key used for derivation must have the
|
||||
`PSA_KEY_USAGE_ENCRYPT` or `PSA_KEY_USAGE_DECRYPT` usage flags.
|
||||
|
||||
This example shows how to authenticate and encrypt a message:
|
||||
```C
|
||||
@ -829,7 +894,7 @@ This example shows how to authenticate and decrypt a message:
|
||||
|
||||
### Generating and exporting keys
|
||||
|
||||
Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
The PSA Crypto API provides a simple way to generate a key or key pair.
|
||||
|
||||
**Prerequisites to using key generation and export APIs:**
|
||||
* Initialize the library with a successful call to `psa_crypto_init()`.
|
||||
@ -837,7 +902,9 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
**To generate an ECDSA key:**
|
||||
1. Set the desired key attributes for key generation by calling
|
||||
`psa_set_key_algorithm()` with the chosen ECDSA algorithm (such as
|
||||
`PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256)`). You only want to export the public key, not the key pair (or private key); therefore, do not set `PSA_KEY_USAGE_EXPORT`.
|
||||
`PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256)`). You only want to export the
|
||||
public key, not the key pair (or private key); therefore, do not
|
||||
set `PSA_KEY_USAGE_EXPORT`.
|
||||
1. Generate a key by calling `psa_generate_key()`.
|
||||
1. Export the generated public key by calling `psa_export_public_key()`:
|
||||
```C
|
||||
@ -891,4 +958,5 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
||||
|
||||
### More about the PSA Crypto API
|
||||
|
||||
For more information about the PSA Crypto API, please see the [PSA Cryptography API Specification](https://armmbed.github.io/mbed-crypto/html/index.html).
|
||||
For more information about the PSA Crypto API, please see the
|
||||
[PSA Cryptography API Specification](https://arm-software.github.io/psa-api/crypto/).
|
||||
|
@ -36,6 +36,12 @@ A driver therefore consists of:
|
||||
|
||||
Mbed TLS calls driver entry points [as specified in the PSA Cryptography Driver Interface specification](psa-driver-interface.html#driver-entry-points) except as otherwise indicated in this section.
|
||||
|
||||
## Mbed TLS extensions
|
||||
|
||||
The driver description can include Mbed TLS extensions (marked by the namespace "mbedtls"). Mbed TLS extensions are meant to extend/help integrating the driver into the library's infrastructure.
|
||||
* `"mbedtls/h_condition"` (optional, string) can include complex preprocessor definitions to conditionally include header files for a given driver.
|
||||
* `"mbedtls/c_condition"` (optional, string) can include complex preprocessor definitions to conditionally enable dispatch capabilities for a driver.
|
||||
|
||||
## Building and testing your driver
|
||||
|
||||
<!-- TODO -->
|
||||
|
@ -13,20 +13,28 @@ During the process of implementation there might be minor variations wrt version
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Python3 and Jinja2 rev 2.10.1
|
||||
Python3, Jinja2 rev 2.10.1 and jsonschema rev 3.2.0
|
||||
|
||||
## Feature Version
|
||||
|
||||
1.0
|
||||
1.1
|
||||
|
||||
### What's critical for a migrating user
|
||||
|
||||
The Driver Wrapper auto generation project is designed to use a python templating library ( Jinja2 ) to render templates based on drivers that are defined using a Driver description JSON file(s).
|
||||
|
||||
While that is the larger goal, for version 1.0 here's what's changed
|
||||
While that is the larger goal, for version 1.1 here's what's changed
|
||||
|
||||
#### What's changed
|
||||
|
||||
(1) psa_crypto_driver_wrappers.c will from this point on be auto generated.
|
||||
(2) The auto generation is based on the template file at scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja.
|
||||
(3) So while all driver wrapper templating support is yet to come in, the library user will need to patch into the template file as needed, this could be read as replacing the template file with the current psa_crypto_driver_wrappers.c file maintained by the library user.
|
||||
(2) The auto generation is based on the template file at **scripts/data_files/driver_templates/psa_crypto_driver_wrappers.c.jinja**.
|
||||
(3) The driver JSONS to be used for generating the psa_crypto_driver_wrappers.c file can be found at **scripts/data_files/driver_jsons/** as their default location, this path includes the schemas against which the driver schemas will be validated (driver_opaque_schema.json, driver_transparent_schema.json) and a driverlist.json which specifies the drivers to be considered and the order in which they want to be called into. The default location for driverlist.json and driver JSONS can be overloaded by passing an argument --json-dir while running the script generate_driver_wrappers.py.
|
||||
(4) While the complete driver wrapper templating support is yet to come in, if the library user sees a need to patch psa_crypto_driver_wrappers.c file, the user will need to patch into the template file as needed (psa_crypto_driver_wrappers.c.jinja).
|
||||
|
||||
#### How to set your driver up
|
||||
|
||||
Please refer to psa-driver-interface.md for information on how a driver schema can be written.
|
||||
One can also refer to the example test drivers/ JSON schemas under **scripts/data_files/driver_jsons/**.
|
||||
|
||||
The JSON file 'driverlist.json' is meant to be edited by the user to reflect the drivers one wants to use on a device. The order in which the drivers are passed is also essential if/when there are multiple transparent drivers on a given system to retain the same order in the templating.
|
||||
|
@ -7,9 +7,6 @@ operations, and enables new APIs for using keys handled by PSA Crypto.
|
||||
General considerations
|
||||
----------------------
|
||||
|
||||
**Compile-time:** enabling `MBEDTLS_USE_PSA_CRYPTO` requires
|
||||
`MBEDTLS_ECP_RESTARTABLE` to be disabled.
|
||||
|
||||
**Application code:** when this option is enabled, you need to call
|
||||
`psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK
|
||||
module.
|
||||
@ -86,30 +83,33 @@ is enabled, no change required on the application side.
|
||||
|
||||
Current exceptions:
|
||||
|
||||
- EC J-PAKE (when `MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED` is defined)
|
||||
- finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
|
||||
DHE-PSK)
|
||||
- Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
|
||||
DHE-PSK).
|
||||
- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
|
||||
the documentation of that option).
|
||||
|
||||
Other than the above exceptions, all crypto operations are based on PSA when
|
||||
`MBEDTLS_USE_PSA_CRYPTO` is enabled.
|
||||
|
||||
### X.509: most crypto operations based on PSA
|
||||
|
||||
Current exception:
|
||||
Current exceptions:
|
||||
|
||||
- verification of RSA-PSS signatures with a salt length that is different from
|
||||
the hash length.
|
||||
- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
|
||||
the documentation of that option).
|
||||
|
||||
Other than the above exception, all crypto operations are based on PSA when
|
||||
`MBEDTLS_USE_PSA_CRYPTO` is enabled.
|
||||
|
||||
### PK layer: most crypto operations based on PSA
|
||||
|
||||
Current exception:
|
||||
Current exceptions:
|
||||
|
||||
- verification of RSA-PSS signatures with a salt length that is different from
|
||||
the hash length, or with an MGF hash that's different from the message hash.
|
||||
- Verification of RSA-PSS signatures with an MGF hash that's different from
|
||||
the message hash.
|
||||
- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
|
||||
the documentation of that option).
|
||||
|
||||
Other than the above exception, all crypto operations are based on PSA when
|
||||
Other than the above exceptions, all crypto operations are based on PSA when
|
||||
`MBEDTLS_USE_PSA_CRYPTO` is enabled.
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
* All symmetric encryption algorithms are accessible via the generic cipher layer
|
||||
* (see \c mbedtls_cipher_setup()).
|
||||
*
|
||||
* The asymmetric encryptrion algorithms are accessible via the generic public
|
||||
* The asymmetric encryption algorithms are accessible via the generic public
|
||||
* key layer (see \c mbedtls_pk_init()).
|
||||
*
|
||||
* The following algorithms are provided:
|
||||
|
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage mbed TLS v3.2.1 source code documentation
|
||||
* @mainpage mbed TLS v3.3.0 source code documentation
|
||||
*
|
||||
* This documentation describes the internal structure of mbed TLS. It was
|
||||
* automatically generated from specially formatted comment blocks in
|
||||
|
@ -1,4 +1,4 @@
|
||||
PROJECT_NAME = "mbed TLS v3.2.1"
|
||||
PROJECT_NAME = "mbed TLS v3.3.0"
|
||||
OUTPUT_DIRECTORY = ../apidoc/
|
||||
FULL_PATH_NAMES = NO
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
|
@ -61,11 +61,6 @@
|
||||
/** Invalid input data. */
|
||||
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -77,19 +72,18 @@ extern "C" {
|
||||
/**
|
||||
* \brief The AES context-type definition.
|
||||
*/
|
||||
typedef struct mbedtls_aes_context
|
||||
{
|
||||
typedef struct mbedtls_aes_context {
|
||||
int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */
|
||||
size_t MBEDTLS_PRIVATE(rk_offset); /*!< The offset in array elements to AES
|
||||
round keys in the buffer. */
|
||||
round keys in the buffer. */
|
||||
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
|
||||
used.</li>
|
||||
<li>Simplifying key expansion in the 256-bit
|
||||
case by generating an extra round key.
|
||||
</li></ul> */
|
||||
hold 32 extra Bytes, which can be used for
|
||||
one of the following purposes:
|
||||
<ul><li>Alignment if VIA padlock is
|
||||
used.</li>
|
||||
<li>Simplifying key expansion in the 256-bit
|
||||
case by generating an extra round key.
|
||||
</li></ul> */
|
||||
}
|
||||
mbedtls_aes_context;
|
||||
|
||||
@ -97,12 +91,11 @@ mbedtls_aes_context;
|
||||
/**
|
||||
* \brief The AES XTS context-type definition.
|
||||
*/
|
||||
typedef struct mbedtls_aes_xts_context
|
||||
{
|
||||
typedef struct mbedtls_aes_xts_context {
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(crypt); /*!< The AES context to use for AES block
|
||||
encryption or decryption. */
|
||||
encryption or decryption. */
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(tweak); /*!< The AES context used for tweak
|
||||
computation. */
|
||||
computation. */
|
||||
} mbedtls_aes_xts_context;
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
||||
@ -118,7 +111,7 @@ typedef struct mbedtls_aes_xts_context
|
||||
*
|
||||
* \param ctx The AES context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_aes_init( mbedtls_aes_context *ctx );
|
||||
void mbedtls_aes_init(mbedtls_aes_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified AES context.
|
||||
@ -127,7 +120,7 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx );
|
||||
* If this is \c NULL, this function does nothing.
|
||||
* Otherwise, the context must have been at least initialized.
|
||||
*/
|
||||
void mbedtls_aes_free( mbedtls_aes_context *ctx );
|
||||
void mbedtls_aes_free(mbedtls_aes_context *ctx);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
/**
|
||||
@ -138,7 +131,7 @@ void mbedtls_aes_free( mbedtls_aes_context *ctx );
|
||||
*
|
||||
* \param ctx The AES XTS context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
|
||||
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified AES XTS context.
|
||||
@ -147,7 +140,7 @@ void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
|
||||
* If this is \c NULL, this function does nothing.
|
||||
* Otherwise, the context must have been at least initialized.
|
||||
*/
|
||||
void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
|
||||
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
||||
/**
|
||||
@ -166,8 +159,8 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function sets the decryption key.
|
||||
@ -185,8 +178,8 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
/**
|
||||
@ -206,9 +199,9 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function prepares an XTS context for decryption and
|
||||
@ -227,9 +220,9 @@ int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
|
||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
||||
/**
|
||||
@ -256,10 +249,10 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
@ -304,12 +297,12 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
* on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
@ -349,12 +342,12 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
* length is larger than 2^20 blocks (16 MiB).
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
const unsigned char data_unit[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
const unsigned char data_unit[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
@ -398,13 +391,13 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief This function performs an AES-CFB8 encryption or decryption
|
||||
@ -443,12 +436,12 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /*MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
||||
@ -498,12 +491,12 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
#endif /* MBEDTLS_CIPHER_MODE_OFB */
|
||||
|
||||
@ -581,13 +574,13 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[16],
|
||||
unsigned char stream_block[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[16],
|
||||
unsigned char stream_block[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
/**
|
||||
@ -602,9 +595,9 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
|
||||
/**
|
||||
* \brief Internal AES block decryption function. This is only
|
||||
@ -618,9 +611,9 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
@ -630,7 +623,7 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
int mbedtls_aes_self_test( int verbose );
|
||||
int mbedtls_aes_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -61,8 +61,7 @@ extern "C" {
|
||||
/**
|
||||
* \brief The ARIA context-type definition.
|
||||
*/
|
||||
typedef struct mbedtls_aria_context
|
||||
{
|
||||
typedef struct mbedtls_aria_context {
|
||||
unsigned char MBEDTLS_PRIVATE(nr); /*!< The number of rounds (12, 14 or 16) */
|
||||
/*! The ARIA round keys. */
|
||||
uint32_t MBEDTLS_PRIVATE(rk)[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
|
||||
@ -81,7 +80,7 @@ mbedtls_aria_context;
|
||||
*
|
||||
* \param ctx The ARIA context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_aria_init( mbedtls_aria_context *ctx );
|
||||
void mbedtls_aria_init(mbedtls_aria_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified ARIA context.
|
||||
@ -90,7 +89,7 @@ void mbedtls_aria_init( mbedtls_aria_context *ctx );
|
||||
* case this function returns immediately. If it is not \c NULL,
|
||||
* it must point to an initialized ARIA context.
|
||||
*/
|
||||
void mbedtls_aria_free( mbedtls_aria_context *ctx );
|
||||
void mbedtls_aria_free(mbedtls_aria_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function sets the encryption key.
|
||||
@ -107,9 +106,9 @@ void mbedtls_aria_free( mbedtls_aria_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function sets the decryption key.
|
||||
@ -126,9 +125,9 @@ int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function performs an ARIA single-block encryption or
|
||||
@ -150,9 +149,9 @@ int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
|
||||
const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] );
|
||||
int mbedtls_aria_crypt_ecb(mbedtls_aria_context *ctx,
|
||||
const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
@ -196,12 +195,12 @@ int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aria_crypt_cbc(mbedtls_aria_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
@ -246,13 +245,13 @@ int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aria_crypt_cfb128(mbedtls_aria_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
@ -333,13 +332,13 @@ int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_aria_crypt_ctr(mbedtls_aria_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
@ -348,7 +347,7 @@ int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success, or \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_aria_self_test( int verbose );
|
||||
int mbedtls_aria_self_test(int verbose);
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@ -38,8 +39,9 @@
|
||||
|
||||
/**
|
||||
* \name ASN1 Error codes
|
||||
* These error codes are OR'ed to X509 error codes for
|
||||
* These error codes are combined with other error codes for
|
||||
* higher error granularity.
|
||||
* e.g. X.509 and PKCS #7 error codes
|
||||
* ASN1 is a standard to specify data structures.
|
||||
* \{
|
||||
*/
|
||||
@ -94,15 +96,15 @@
|
||||
|
||||
/* Slightly smaller way to check if tag is a string tag
|
||||
* compared to canonical implementation. */
|
||||
#define MBEDTLS_ASN1_IS_STRING_TAG( tag ) \
|
||||
( ( tag ) < 32u && ( \
|
||||
( ( 1u << ( tag ) ) & ( ( 1u << MBEDTLS_ASN1_BMP_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_UTF8_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_T61_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_IA5_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_UNIVERSAL_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_PRINTABLE_STRING ) | \
|
||||
( 1u << MBEDTLS_ASN1_BIT_STRING ) ) ) != 0 ) )
|
||||
#define MBEDTLS_ASN1_IS_STRING_TAG(tag) \
|
||||
((tag) < 32u && ( \
|
||||
((1u << (tag)) & ((1u << MBEDTLS_ASN1_BMP_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_UTF8_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_T61_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_IA5_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_UNIVERSAL_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_PRINTABLE_STRING) | \
|
||||
(1u << MBEDTLS_ASN1_BIT_STRING))) != 0))
|
||||
|
||||
/*
|
||||
* Bit masks for each of the components of an ASN.1 tag as specified in
|
||||
@ -130,12 +132,12 @@
|
||||
* 'unsigned char *oid' here!
|
||||
*/
|
||||
#define MBEDTLS_OID_CMP(oid_str, oid_buf) \
|
||||
( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \
|
||||
memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 )
|
||||
((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) || \
|
||||
memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0)
|
||||
|
||||
#define MBEDTLS_OID_CMP_RAW(oid_str, oid_buf, oid_buf_len) \
|
||||
( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len) ) || \
|
||||
memcmp( (oid_str), (oid_buf), (oid_buf_len) ) != 0 )
|
||||
((MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len)) || \
|
||||
memcmp((oid_str), (oid_buf), (oid_buf_len)) != 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -149,8 +151,7 @@ extern "C" {
|
||||
/**
|
||||
* Type-length-value structure that allows for ASN1 using DER.
|
||||
*/
|
||||
typedef struct mbedtls_asn1_buf
|
||||
{
|
||||
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. */
|
||||
@ -160,8 +161,7 @@ mbedtls_asn1_buf;
|
||||
/**
|
||||
* Container for ASN1 bit strings.
|
||||
*/
|
||||
typedef struct mbedtls_asn1_bitstring
|
||||
{
|
||||
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 */
|
||||
@ -171,8 +171,7 @@ mbedtls_asn1_bitstring;
|
||||
/**
|
||||
* Container for a sequence of ASN.1 items
|
||||
*/
|
||||
typedef struct mbedtls_asn1_sequence
|
||||
{
|
||||
typedef struct mbedtls_asn1_sequence {
|
||||
mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
|
||||
|
||||
/** The next entry in the sequence.
|
||||
@ -189,8 +188,7 @@ mbedtls_asn1_sequence;
|
||||
/**
|
||||
* Container for a sequence or list of 'named' ASN.1 data items
|
||||
*/
|
||||
typedef struct mbedtls_asn1_named_data
|
||||
{
|
||||
typedef struct mbedtls_asn1_named_data {
|
||||
mbedtls_asn1_buf oid; /**< The object identifier. */
|
||||
mbedtls_asn1_buf val; /**< The named value. */
|
||||
|
||||
@ -230,9 +228,9 @@ mbedtls_asn1_named_data;
|
||||
* would end beyond \p end.
|
||||
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparsable.
|
||||
*/
|
||||
int mbedtls_asn1_get_len( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len );
|
||||
int mbedtls_asn1_get_len(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len);
|
||||
|
||||
/**
|
||||
* \brief Get the tag and length of the element.
|
||||
@ -255,9 +253,9 @@ int mbedtls_asn1_get_len( unsigned char **p,
|
||||
* would end beyond \p end.
|
||||
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparsable.
|
||||
*/
|
||||
int mbedtls_asn1_get_tag( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len, int tag );
|
||||
int mbedtls_asn1_get_tag(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len, int tag);
|
||||
|
||||
/**
|
||||
* \brief Retrieve a boolean ASN.1 tag and its value.
|
||||
@ -274,9 +272,9 @@ int mbedtls_asn1_get_tag( unsigned char **p,
|
||||
* \return An ASN.1 error code if the input does not start with
|
||||
* a valid ASN.1 BOOLEAN.
|
||||
*/
|
||||
int mbedtls_asn1_get_bool( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val );
|
||||
int mbedtls_asn1_get_bool(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val);
|
||||
|
||||
/**
|
||||
* \brief Retrieve an integer ASN.1 tag and its value.
|
||||
@ -295,9 +293,9 @@ int mbedtls_asn1_get_bool( unsigned char **p,
|
||||
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
|
||||
* not fit in an \c int.
|
||||
*/
|
||||
int mbedtls_asn1_get_int( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val );
|
||||
int mbedtls_asn1_get_int(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val);
|
||||
|
||||
/**
|
||||
* \brief Retrieve an enumerated ASN.1 tag and its value.
|
||||
@ -316,9 +314,9 @@ int mbedtls_asn1_get_int( unsigned char **p,
|
||||
* \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does
|
||||
* not fit in an \c int.
|
||||
*/
|
||||
int mbedtls_asn1_get_enum( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val );
|
||||
int mbedtls_asn1_get_enum(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
int *val);
|
||||
|
||||
/**
|
||||
* \brief Retrieve a bitstring ASN.1 tag and its value.
|
||||
@ -337,8 +335,8 @@ int mbedtls_asn1_get_enum( unsigned char **p,
|
||||
* \return An ASN.1 error code if the input does not start with
|
||||
* a valid ASN.1 BIT STRING.
|
||||
*/
|
||||
int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
|
||||
mbedtls_asn1_bitstring *bs );
|
||||
int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end,
|
||||
mbedtls_asn1_bitstring *bs);
|
||||
|
||||
/**
|
||||
* \brief Retrieve a bitstring ASN.1 tag without unused bits and its
|
||||
@ -358,9 +356,9 @@ int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
|
||||
* \return An ASN.1 error code if the input does not start with
|
||||
* a valid ASN.1 BIT STRING.
|
||||
*/
|
||||
int mbedtls_asn1_get_bitstring_null( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len );
|
||||
int mbedtls_asn1_get_bitstring_null(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
size_t *len);
|
||||
|
||||
/**
|
||||
* \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>".
|
||||
@ -409,10 +407,10 @@ int mbedtls_asn1_get_bitstring_null( unsigned char **p,
|
||||
* \return An ASN.1 error code if the input does not start with
|
||||
* a valid ASN.1 SEQUENCE.
|
||||
*/
|
||||
int mbedtls_asn1_get_sequence_of( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_sequence *cur,
|
||||
int tag );
|
||||
int mbedtls_asn1_get_sequence_of(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_sequence *cur,
|
||||
int tag);
|
||||
/**
|
||||
* \brief Free a heap-allocated linked list presentation of
|
||||
* an ASN.1 sequence, including the first element.
|
||||
@ -434,7 +432,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
|
||||
* be \c NULL, in which case this functions returns
|
||||
* immediately.
|
||||
*/
|
||||
void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq );
|
||||
void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq);
|
||||
|
||||
/**
|
||||
* \brief Traverse an ASN.1 SEQUENCE container and
|
||||
@ -526,9 +524,9 @@ int mbedtls_asn1_traverse_sequence_of(
|
||||
const unsigned char *end,
|
||||
unsigned char tag_must_mask, unsigned char tag_must_val,
|
||||
unsigned char tag_may_mask, unsigned char tag_may_val,
|
||||
int (*cb)( void *ctx, int tag,
|
||||
unsigned char* start, size_t len ),
|
||||
void *ctx );
|
||||
int (*cb)(void *ctx, int tag,
|
||||
unsigned char *start, size_t len),
|
||||
void *ctx);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
/**
|
||||
@ -549,9 +547,9 @@ int mbedtls_asn1_traverse_sequence_of(
|
||||
* not fit in an \c int.
|
||||
* \return An MPI error code if the parsed value is too large.
|
||||
*/
|
||||
int mbedtls_asn1_get_mpi( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_mpi *X );
|
||||
int mbedtls_asn1_get_mpi(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_mpi *X);
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
/**
|
||||
@ -570,9 +568,9 @@ int mbedtls_asn1_get_mpi( unsigned char **p,
|
||||
*
|
||||
* \return 0 if successful or a specific ASN.1 or MPI error code.
|
||||
*/
|
||||
int mbedtls_asn1_get_alg( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params );
|
||||
int mbedtls_asn1_get_alg(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params);
|
||||
|
||||
/**
|
||||
* \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no
|
||||
@ -589,9 +587,9 @@ int mbedtls_asn1_get_alg( unsigned char **p,
|
||||
*
|
||||
* \return 0 if successful or a specific ASN.1 or MPI error code.
|
||||
*/
|
||||
int mbedtls_asn1_get_alg_null( unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg );
|
||||
int mbedtls_asn1_get_alg_null(unsigned char **p,
|
||||
const unsigned char *end,
|
||||
mbedtls_asn1_buf *alg);
|
||||
|
||||
/**
|
||||
* \brief Find a specific named_data entry in a sequence or list based on
|
||||
@ -603,27 +601,43 @@ int mbedtls_asn1_get_alg_null( unsigned char **p,
|
||||
*
|
||||
* \return NULL if not found, or a pointer to the existing entry.
|
||||
*/
|
||||
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len );
|
||||
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(const mbedtls_asn1_named_data *list,
|
||||
const char *oid, size_t len);
|
||||
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
/**
|
||||
* \brief Free a mbedtls_asn1_named_data entry
|
||||
*
|
||||
* \deprecated This function is deprecated and will be removed in a
|
||||
* future version of the library.
|
||||
* Please use mbedtls_asn1_free_named_data_list()
|
||||
* or mbedtls_asn1_free_named_data_list_shallow().
|
||||
*
|
||||
* \param entry The named data entry to free.
|
||||
* This function calls mbedtls_free() on
|
||||
* `entry->oid.p` and `entry->val.p`.
|
||||
*/
|
||||
void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry );
|
||||
void MBEDTLS_DEPRECATED mbedtls_asn1_free_named_data(mbedtls_asn1_named_data *entry);
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
|
||||
/**
|
||||
* \brief Free all entries in a mbedtls_asn1_named_data list.
|
||||
*
|
||||
* \param head Pointer to the head of the list of named data entries to free.
|
||||
* This function calls mbedtls_asn1_free_named_data() and
|
||||
* mbedtls_free() on each list element and
|
||||
* sets \c *head to \c NULL.
|
||||
* This function calls mbedtls_free() on
|
||||
* `entry->oid.p` and `entry->val.p` and then on `entry`
|
||||
* for each list entry, and sets \c *head to \c NULL.
|
||||
*/
|
||||
void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head );
|
||||
void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head);
|
||||
|
||||
/**
|
||||
* \brief Free all shallow entries in a mbedtls_asn1_named_data list,
|
||||
* but do not free internal pointer targets.
|
||||
*
|
||||
* \param name Head of the list of named data entries to free.
|
||||
* This function calls mbedtls_free() on each list element.
|
||||
*/
|
||||
void mbedtls_asn1_free_named_data_list_shallow(mbedtls_asn1_named_data *name);
|
||||
|
||||
/** \} name Functions to parse ASN.1 data structures */
|
||||
/** \} addtogroup asn1_module */
|
||||
|
@ -29,11 +29,11 @@
|
||||
#define MBEDTLS_ASN1_CHK_ADD(g, f) \
|
||||
do \
|
||||
{ \
|
||||
if( ( ret = (f) ) < 0 ) \
|
||||
return( ret ); \
|
||||
if ((ret = (f)) < 0) \
|
||||
return ret; \
|
||||
else \
|
||||
(g) += ret; \
|
||||
} while( 0 )
|
||||
(g) += ret; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -51,8 +51,8 @@ extern "C" {
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start,
|
||||
size_t len );
|
||||
int mbedtls_asn1_write_len(unsigned char **p, const unsigned char *start,
|
||||
size_t len);
|
||||
/**
|
||||
* \brief Write an ASN.1 tag in ASN.1 format.
|
||||
*
|
||||
@ -65,8 +65,8 @@ int mbedtls_asn1_write_len( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start,
|
||||
unsigned char tag );
|
||||
int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start,
|
||||
unsigned char tag);
|
||||
|
||||
/**
|
||||
* \brief Write raw buffer data.
|
||||
@ -81,8 +81,8 @@ int mbedtls_asn1_write_tag( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size );
|
||||
int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
/**
|
||||
@ -99,8 +99,8 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, const unsigned char *start
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start,
|
||||
const mbedtls_mpi *X );
|
||||
int mbedtls_asn1_write_mpi(unsigned char **p, const unsigned char *start,
|
||||
const mbedtls_mpi *X);
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start );
|
||||
int mbedtls_asn1_write_null(unsigned char **p, const unsigned char *start);
|
||||
|
||||
/**
|
||||
* \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data
|
||||
@ -131,8 +131,8 @@ int mbedtls_asn1_write_null( unsigned char **p, const unsigned char *start );
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len );
|
||||
int mbedtls_asn1_write_oid(unsigned char **p, const unsigned char *start,
|
||||
const char *oid, size_t oid_len);
|
||||
|
||||
/**
|
||||
* \brief Write an AlgorithmIdentifier sequence in ASN.1 format.
|
||||
@ -149,10 +149,10 @@ int mbedtls_asn1_write_oid( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len );
|
||||
int mbedtls_asn1_write_algorithm_identifier(unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const char *oid, size_t oid_len,
|
||||
size_t par_len);
|
||||
|
||||
/**
|
||||
* \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value
|
||||
@ -167,8 +167,8 @@ int mbedtls_asn1_write_algorithm_identifier( unsigned char **p,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start,
|
||||
int boolean );
|
||||
int mbedtls_asn1_write_bool(unsigned char **p, const unsigned char *start,
|
||||
int boolean);
|
||||
|
||||
/**
|
||||
* \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value
|
||||
@ -184,7 +184,7 @@ int mbedtls_asn1_write_bool( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int val );
|
||||
int mbedtls_asn1_write_int(unsigned char **p, const unsigned char *start, int val);
|
||||
|
||||
/**
|
||||
* \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value
|
||||
@ -199,7 +199,7 @@ int mbedtls_asn1_write_int( unsigned char **p, const unsigned char *start, int v
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int val );
|
||||
int mbedtls_asn1_write_enum(unsigned char **p, const unsigned char *start, int val);
|
||||
|
||||
/**
|
||||
* \brief Write a string in ASN.1 format using a specific
|
||||
@ -218,9 +218,9 @@ int mbedtls_asn1_write_enum( unsigned char **p, const unsigned char *start, int
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *start,
|
||||
int tag, const char *text,
|
||||
size_t text_len );
|
||||
int mbedtls_asn1_write_tagged_string(unsigned char **p, const unsigned char *start,
|
||||
int tag, const char *text,
|
||||
size_t text_len);
|
||||
|
||||
/**
|
||||
* \brief Write a string in ASN.1 format using the PrintableString
|
||||
@ -237,9 +237,9 @@ int mbedtls_asn1_write_tagged_string( unsigned char **p, const unsigned char *st
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_printable_string( unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
int mbedtls_asn1_write_printable_string(unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const char *text, size_t text_len);
|
||||
|
||||
/**
|
||||
* \brief Write a UTF8 string in ASN.1 format using the UTF8String
|
||||
@ -256,8 +256,8 @@ int mbedtls_asn1_write_printable_string( unsigned char **p,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
int mbedtls_asn1_write_utf8_string(unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len);
|
||||
|
||||
/**
|
||||
* \brief Write a string in ASN.1 format using the IA5String
|
||||
@ -274,8 +274,8 @@ int mbedtls_asn1_write_utf8_string( unsigned char **p, const unsigned char *star
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len );
|
||||
int mbedtls_asn1_write_ia5_string(unsigned char **p, const unsigned char *start,
|
||||
const char *text, size_t text_len);
|
||||
|
||||
/**
|
||||
* \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and
|
||||
@ -291,8 +291,8 @@ int mbedtls_asn1_write_ia5_string( unsigned char **p, const unsigned char *start
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t bits );
|
||||
int mbedtls_asn1_write_bitstring(unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t bits);
|
||||
|
||||
/**
|
||||
* \brief This function writes a named bitstring tag
|
||||
@ -311,10 +311,10 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, const unsigned char *start,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const unsigned char *buf,
|
||||
size_t bits );
|
||||
int mbedtls_asn1_write_named_bitstring(unsigned char **p,
|
||||
const unsigned char *start,
|
||||
const unsigned char *buf,
|
||||
size_t bits);
|
||||
|
||||
/**
|
||||
* \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING)
|
||||
@ -330,8 +330,8 @@ int mbedtls_asn1_write_named_bitstring( unsigned char **p,
|
||||
* \return The number of bytes written to \p p on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size );
|
||||
int mbedtls_asn1_write_octet_string(unsigned char **p, const unsigned char *start,
|
||||
const unsigned char *buf, size_t size);
|
||||
|
||||
/**
|
||||
* \brief Create or find a specific named_data entry for writing in a
|
||||
@ -352,12 +352,12 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, const unsigned char *sta
|
||||
* the existing buffer to fit \p val_len.
|
||||
*
|
||||
* \return A pointer to the new / existing entry on success.
|
||||
* \return \c NULL if if there was a memory allocation error.
|
||||
* \return \c NULL if there was a memory allocation error.
|
||||
*/
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
|
||||
const char *oid, size_t oid_len,
|
||||
const unsigned char *val,
|
||||
size_t val_len );
|
||||
mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(mbedtls_asn1_named_data **list,
|
||||
const char *oid, size_t oid_len,
|
||||
const unsigned char *val,
|
||||
size_t val_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ extern "C" {
|
||||
* \note Call this function with dlen = 0 to obtain the
|
||||
* required buffer size in *olen
|
||||
*/
|
||||
int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||
const unsigned char *src, size_t slen );
|
||||
int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen,
|
||||
const unsigned char *src, size_t slen);
|
||||
|
||||
/**
|
||||
* \brief Decode a base64-formatted buffer
|
||||
@ -74,8 +74,8 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||
* \note Call this function with *dst = NULL or dlen = 0 to obtain
|
||||
* the required buffer size in *olen
|
||||
*/
|
||||
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||
const unsigned char *src, size_t slen );
|
||||
int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen,
|
||||
const unsigned char *src, size_t slen);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
@ -83,7 +83,7 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_base64_self_test( int verbose );
|
||||
int mbedtls_base64_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -52,9 +52,9 @@
|
||||
#define MBEDTLS_MPI_CHK(f) \
|
||||
do \
|
||||
{ \
|
||||
if( ( ret = (f) ) != 0 ) \
|
||||
goto cleanup; \
|
||||
} while( 0 )
|
||||
if ((ret = (f)) != 0) \
|
||||
goto cleanup; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Maximum size MPIs are allowed to grow to in number of limbs.
|
||||
@ -85,7 +85,7 @@
|
||||
#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
|
||||
#endif /* !MBEDTLS_MPI_MAX_SIZE */
|
||||
|
||||
#define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */
|
||||
#define MBEDTLS_MPI_MAX_BITS (8 * MBEDTLS_MPI_MAX_SIZE) /**< Maximum number of bits for usable MPIs. */
|
||||
|
||||
/*
|
||||
* When reading from files with mbedtls_mpi_read_file() and writing to files with
|
||||
@ -105,9 +105,11 @@
|
||||
* MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
|
||||
* LabelSize + 6
|
||||
*/
|
||||
#define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS )
|
||||
#define MBEDTLS_MPI_MAX_BITS_SCALE100 (100 * MBEDTLS_MPI_MAX_BITS)
|
||||
#define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
|
||||
#define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
|
||||
#define MBEDTLS_MPI_RW_BUFFER_SIZE (((MBEDTLS_MPI_MAX_BITS_SCALE100 + \
|
||||
MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / \
|
||||
MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6)
|
||||
|
||||
/*
|
||||
* Define the base integer type, architecture-wise.
|
||||
@ -121,64 +123,78 @@
|
||||
*/
|
||||
#if !defined(MBEDTLS_HAVE_INT32)
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
/* Always choose 64-bit when using MSC */
|
||||
/* Always choose 64-bit when using MSC */
|
||||
#if !defined(MBEDTLS_HAVE_INT64)
|
||||
#define MBEDTLS_HAVE_INT64
|
||||
#endif /* !MBEDTLS_HAVE_INT64 */
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
#elif defined(__GNUC__) && ( \
|
||||
defined(__amd64__) || defined(__x86_64__) || \
|
||||
defined(__ppc64__) || defined(__powerpc64__) || \
|
||||
defined(__ia64__) || defined(__alpha__) || \
|
||||
( defined(__sparc__) && defined(__arch64__) ) || \
|
||||
defined(__s390x__) || defined(__mips64) || \
|
||||
defined(__aarch64__) )
|
||||
defined(__amd64__) || defined(__x86_64__) || \
|
||||
defined(__ppc64__) || defined(__powerpc64__) || \
|
||||
defined(__ia64__) || defined(__alpha__) || \
|
||||
(defined(__sparc__) && defined(__arch64__)) || \
|
||||
defined(__s390x__) || defined(__mips64) || \
|
||||
defined(__aarch64__))
|
||||
#if !defined(MBEDTLS_HAVE_INT64)
|
||||
#define MBEDTLS_HAVE_INT64
|
||||
#endif /* MBEDTLS_HAVE_INT64 */
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
|
||||
/* mbedtls_t_udbl defined as 128-bit unsigned int */
|
||||
typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
|
||||
/* mbedtls_t_udbl defined as 128-bit unsigned int */
|
||||
typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
|
||||
#define MBEDTLS_HAVE_UDBL
|
||||
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
|
||||
#elif defined(__ARMCC_VERSION) && defined(__aarch64__)
|
||||
/*
|
||||
* __ARMCC_VERSION is defined for both armcc and armclang and
|
||||
* __aarch64__ is only defined by armclang when compiling 64-bit code
|
||||
*/
|
||||
/*
|
||||
* __ARMCC_VERSION is defined for both armcc and armclang and
|
||||
* __aarch64__ is only defined by armclang when compiling 64-bit code
|
||||
*/
|
||||
#if !defined(MBEDTLS_HAVE_INT64)
|
||||
#define MBEDTLS_HAVE_INT64
|
||||
#endif /* !MBEDTLS_HAVE_INT64 */
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
|
||||
/* mbedtls_t_udbl defined as 128-bit unsigned int */
|
||||
typedef __uint128_t mbedtls_t_udbl;
|
||||
/* mbedtls_t_udbl defined as 128-bit unsigned int */
|
||||
typedef __uint128_t mbedtls_t_udbl;
|
||||
#define MBEDTLS_HAVE_UDBL
|
||||
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
|
||||
#elif defined(MBEDTLS_HAVE_INT64)
|
||||
/* Force 64-bit integers with unknown compiler */
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
/* Force 64-bit integers with unknown compiler */
|
||||
typedef int64_t mbedtls_mpi_sint;
|
||||
typedef uint64_t mbedtls_mpi_uint;
|
||||
#endif
|
||||
#endif /* !MBEDTLS_HAVE_INT32 */
|
||||
|
||||
#if !defined(MBEDTLS_HAVE_INT64)
|
||||
/* Default to 32-bit compilation */
|
||||
/* Default to 32-bit compilation */
|
||||
#if !defined(MBEDTLS_HAVE_INT32)
|
||||
#define MBEDTLS_HAVE_INT32
|
||||
#endif /* !MBEDTLS_HAVE_INT32 */
|
||||
typedef int32_t mbedtls_mpi_sint;
|
||||
typedef uint32_t mbedtls_mpi_uint;
|
||||
typedef int32_t mbedtls_mpi_sint;
|
||||
typedef uint32_t mbedtls_mpi_uint;
|
||||
#if !defined(MBEDTLS_NO_UDBL_DIVISION)
|
||||
typedef uint64_t mbedtls_t_udbl;
|
||||
typedef uint64_t mbedtls_t_udbl;
|
||||
#define MBEDTLS_HAVE_UDBL
|
||||
#endif /* !MBEDTLS_NO_UDBL_DIVISION */
|
||||
#endif /* !MBEDTLS_HAVE_INT64 */
|
||||
|
||||
/** \typedef mbedtls_mpi_uint
|
||||
* \brief The type of machine digits in a bignum, called _limbs_.
|
||||
*
|
||||
* This is always an unsigned integer type with no padding bits. The size
|
||||
* is platform-dependent.
|
||||
*/
|
||||
|
||||
/** \typedef mbedtls_mpi_sint
|
||||
* \brief The signed type corresponding to #mbedtls_mpi_uint.
|
||||
*
|
||||
* This is always an signed integer type with no padding bits. The size
|
||||
* is platform-dependent.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -186,11 +202,28 @@ extern "C" {
|
||||
/**
|
||||
* \brief MPI structure
|
||||
*/
|
||||
typedef struct mbedtls_mpi
|
||||
{
|
||||
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 */
|
||||
typedef struct mbedtls_mpi {
|
||||
/** Sign: -1 if the mpi is negative, 1 otherwise.
|
||||
*
|
||||
* The number 0 must be represented with `s = +1`. Although many library
|
||||
* functions treat all-limbs-zero as equivalent to a valid representation
|
||||
* of 0 regardless of the sign bit, there are exceptions, so bignum
|
||||
* functions and external callers must always set \c s to +1 for the
|
||||
* number zero.
|
||||
*
|
||||
* Note that this implies that calloc() or `... = {0}` does not create
|
||||
* a valid MPI representation. You must call mbedtls_mpi_init().
|
||||
*/
|
||||
int MBEDTLS_PRIVATE(s);
|
||||
|
||||
/** Total number of limbs in \c p. */
|
||||
size_t MBEDTLS_PRIVATE(n);
|
||||
|
||||
/** Pointer to limbs.
|
||||
*
|
||||
* This may be \c NULL if \c n is 0.
|
||||
*/
|
||||
mbedtls_mpi_uint *MBEDTLS_PRIVATE(p);
|
||||
}
|
||||
mbedtls_mpi;
|
||||
|
||||
@ -202,7 +235,7 @@ mbedtls_mpi;
|
||||
*
|
||||
* \param X The MPI context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_mpi_init( mbedtls_mpi *X );
|
||||
void mbedtls_mpi_init(mbedtls_mpi *X);
|
||||
|
||||
/**
|
||||
* \brief This function frees the components of an MPI context.
|
||||
@ -211,7 +244,7 @@ void mbedtls_mpi_init( mbedtls_mpi *X );
|
||||
* in which case this function is a no-op. If it is
|
||||
* not \c NULL, it must point to an initialized MPI.
|
||||
*/
|
||||
void mbedtls_mpi_free( mbedtls_mpi *X );
|
||||
void mbedtls_mpi_free(mbedtls_mpi *X);
|
||||
|
||||
/**
|
||||
* \brief Enlarge an MPI to the specified number of limbs.
|
||||
@ -226,7 +259,7 @@ void mbedtls_mpi_free( mbedtls_mpi *X );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
|
||||
int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs);
|
||||
|
||||
/**
|
||||
* \brief This function resizes an MPI downwards, keeping at least the
|
||||
@ -243,7 +276,7 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
|
||||
* (this can only happen when resizing up).
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
|
||||
int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs);
|
||||
|
||||
/**
|
||||
* \brief Make a copy of an MPI.
|
||||
@ -258,7 +291,7 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y);
|
||||
|
||||
/**
|
||||
* \brief Swap the contents of two MPIs.
|
||||
@ -266,7 +299,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
* \param X The first MPI. It must be initialized.
|
||||
* \param Y The second MPI. It must be initialized.
|
||||
*/
|
||||
void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
|
||||
void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y);
|
||||
|
||||
/**
|
||||
* \brief Perform a safe conditional copy of MPI which doesn't
|
||||
@ -296,7 +329,7 @@ void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
|
||||
int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign);
|
||||
|
||||
/**
|
||||
* \brief Perform a safe conditional swap which doesn't
|
||||
@ -325,7 +358,7 @@ int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swap );
|
||||
int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swap);
|
||||
|
||||
/**
|
||||
* \brief Store integer value in MPI.
|
||||
@ -337,7 +370,7 @@ int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char sw
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
|
||||
int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z);
|
||||
|
||||
/**
|
||||
* \brief Get a specific bit from an MPI.
|
||||
@ -349,7 +382,7 @@ int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
|
||||
* of \c X is unset or set.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
|
||||
int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos);
|
||||
|
||||
/**
|
||||
* \brief Modify a specific bit in an MPI.
|
||||
@ -366,7 +399,7 @@ int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
|
||||
int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val);
|
||||
|
||||
/**
|
||||
* \brief Return the number of bits of value \c 0 before the
|
||||
@ -380,7 +413,7 @@ int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
|
||||
* \return The number of bits of value \c 0 before the least significant
|
||||
* bit of value \c 1 in \p X.
|
||||
*/
|
||||
size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
|
||||
size_t mbedtls_mpi_lsb(const mbedtls_mpi *X);
|
||||
|
||||
/**
|
||||
* \brief Return the number of bits up to and including the most
|
||||
@ -394,7 +427,7 @@ size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
|
||||
* \return The number of bits up to and including the most
|
||||
* significant bit of value \c 1.
|
||||
*/
|
||||
size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
|
||||
size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X);
|
||||
|
||||
/**
|
||||
* \brief Return the total size of an MPI value in bytes.
|
||||
@ -409,7 +442,7 @@ size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
|
||||
* \return The least number of bytes capable of storing
|
||||
* the absolute value of \p X.
|
||||
*/
|
||||
size_t mbedtls_mpi_size( const mbedtls_mpi *X );
|
||||
size_t mbedtls_mpi_size(const mbedtls_mpi *X);
|
||||
|
||||
/**
|
||||
* \brief Import an MPI from an ASCII string.
|
||||
@ -421,7 +454,7 @@ size_t mbedtls_mpi_size( const mbedtls_mpi *X );
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
|
||||
int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s);
|
||||
|
||||
/**
|
||||
* \brief Export an MPI to an ASCII string.
|
||||
@ -445,8 +478,8 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
|
||||
* size of \p buf required for a successful call.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||
char *buf, size_t buflen, size_t *olen );
|
||||
int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix,
|
||||
char *buf, size_t buflen, size_t *olen);
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
@ -470,7 +503,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||
* is too small.
|
||||
* \return Another negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
|
||||
int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin);
|
||||
|
||||
/**
|
||||
* \brief Export an MPI into an opened file.
|
||||
@ -487,8 +520,8 @@ int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X,
|
||||
int radix, FILE *fout );
|
||||
int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X,
|
||||
int radix, FILE *fout);
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
/**
|
||||
@ -503,8 +536,8 @@ int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf,
|
||||
size_t buflen );
|
||||
int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf,
|
||||
size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief Import X from unsigned binary data, little endian
|
||||
@ -518,8 +551,8 @@ int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_read_binary_le( mbedtls_mpi *X,
|
||||
const unsigned char *buf, size_t buflen );
|
||||
int mbedtls_mpi_read_binary_le(mbedtls_mpi *X,
|
||||
const unsigned char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief Export X into unsigned binary data, big endian.
|
||||
@ -536,8 +569,8 @@ int mbedtls_mpi_read_binary_le( mbedtls_mpi *X,
|
||||
* large enough to hold the value of \p X.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf,
|
||||
size_t buflen );
|
||||
int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf,
|
||||
size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief Export X into unsigned binary data, little endian.
|
||||
@ -554,8 +587,8 @@ int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf,
|
||||
* large enough to hold the value of \p X.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X,
|
||||
unsigned char *buf, size_t buflen );
|
||||
int mbedtls_mpi_write_binary_le(const mbedtls_mpi *X,
|
||||
unsigned char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief Perform a left-shift on an MPI: X <<= count
|
||||
@ -567,7 +600,7 @@ int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
|
||||
int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count);
|
||||
|
||||
/**
|
||||
* \brief Perform a right-shift on an MPI: X >>= count
|
||||
@ -579,7 +612,7 @@ int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
|
||||
int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count);
|
||||
|
||||
/**
|
||||
* \brief Compare the absolute values of two MPIs.
|
||||
@ -591,7 +624,7 @@ int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
|
||||
* \return \c -1 if `|X|` is lesser than `|Y|`.
|
||||
* \return \c 0 if `|X|` is equal to `|Y|`.
|
||||
*/
|
||||
int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y);
|
||||
|
||||
/**
|
||||
* \brief Compare two MPIs.
|
||||
@ -603,7 +636,7 @@ int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
* \return \c -1 if \p X is lesser than \p Y.
|
||||
* \return \c 0 if \p X is equal to \p Y.
|
||||
*/
|
||||
int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y);
|
||||
|
||||
/**
|
||||
* \brief Check if an MPI is less than the other in constant time.
|
||||
@ -620,8 +653,8 @@ int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
|
||||
* \return MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the allocated length of
|
||||
* the two input MPIs is not the same.
|
||||
*/
|
||||
int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
|
||||
unsigned *ret );
|
||||
int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, const mbedtls_mpi *Y,
|
||||
unsigned *ret);
|
||||
|
||||
/**
|
||||
* \brief Compare an MPI with an integer.
|
||||
@ -633,7 +666,7 @@ int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
|
||||
* \return \c -1 if \p X is lesser than \p z.
|
||||
* \return \c 0 if \p X is equal to \p z.
|
||||
*/
|
||||
int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
|
||||
int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z);
|
||||
|
||||
/**
|
||||
* \brief Perform an unsigned addition of MPIs: X = |A| + |B|
|
||||
@ -646,8 +679,8 @@ int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform an unsigned subtraction of MPIs: X = |A| - |B|
|
||||
@ -661,8 +694,8 @@ int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a signed addition of MPIs: X = A + B
|
||||
@ -675,8 +708,8 @@ int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a signed subtraction of MPIs: X = A - B
|
||||
@ -689,8 +722,8 @@ int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a signed addition of an MPI and an integer: X = A + b
|
||||
@ -703,8 +736,8 @@ int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b );
|
||||
int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b);
|
||||
|
||||
/**
|
||||
* \brief Perform a signed subtraction of an MPI and an integer:
|
||||
@ -718,8 +751,8 @@ int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b );
|
||||
int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b);
|
||||
|
||||
/**
|
||||
* \brief Perform a multiplication of two MPIs: X = A * B
|
||||
@ -733,8 +766,8 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a multiplication of an MPI with an unsigned integer:
|
||||
@ -749,8 +782,8 @@ int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_uint b );
|
||||
int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_uint b);
|
||||
|
||||
/**
|
||||
* \brief Perform a division with remainder of two MPIs:
|
||||
@ -758,11 +791,11 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
*
|
||||
* \param Q The destination MPI for the quotient.
|
||||
* This may be \c NULL if the value of the
|
||||
* quotient is not needed.
|
||||
* quotient is not needed. This must not alias A or B.
|
||||
* \param R The destination MPI for the remainder value.
|
||||
* This may be \c NULL if the value of the
|
||||
* remainder is not needed.
|
||||
* \param A The dividend. This must point to an initialized MPi.
|
||||
* remainder is not needed. This must not alias A or B.
|
||||
* \param A The dividend. This must point to an initialized MPI.
|
||||
* \param B The divisor. This must point to an initialized MPI.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
@ -770,8 +803,8 @@ int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a division with remainder of an MPI by an integer:
|
||||
@ -779,10 +812,10 @@ int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
*
|
||||
* \param Q The destination MPI for the quotient.
|
||||
* This may be \c NULL if the value of the
|
||||
* quotient is not needed.
|
||||
* quotient is not needed. This must not alias A.
|
||||
* \param R The destination MPI for the remainder value.
|
||||
* This may be \c NULL if the value of the
|
||||
* remainder is not needed.
|
||||
* remainder is not needed. This must not alias A.
|
||||
* \param A The dividend. This must point to an initialized MPi.
|
||||
* \param b The divisor.
|
||||
*
|
||||
@ -791,8 +824,8 @@ int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b );
|
||||
int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b);
|
||||
|
||||
/**
|
||||
* \brief Perform a modular reduction. R = A mod B
|
||||
@ -811,8 +844,8 @@ int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Perform a modular reduction with respect to an integer.
|
||||
@ -830,13 +863,14 @@ int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p b is negative.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b );
|
||||
int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A,
|
||||
mbedtls_mpi_sint b);
|
||||
|
||||
/**
|
||||
* \brief Perform a sliding-window exponentiation: X = A^E mod N
|
||||
*
|
||||
* \param X The destination MPI. This must point to an initialized MPI.
|
||||
* This must not alias E or N.
|
||||
* \param A The base of the exponentiation.
|
||||
* This must point to an initialized MPI.
|
||||
* \param E The exponent MPI. This must point to an initialized MPI.
|
||||
@ -859,9 +893,9 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
|
||||
* \return Another negative error code on different kinds of failures.
|
||||
*
|
||||
*/
|
||||
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *E, const mbedtls_mpi *N,
|
||||
mbedtls_mpi *prec_RR );
|
||||
int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *E, const mbedtls_mpi *N,
|
||||
mbedtls_mpi *prec_RR);
|
||||
|
||||
/**
|
||||
* \brief Fill an MPI with a number of random bytes.
|
||||
@ -880,9 +914,9 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* as a big-endian representation of an MPI; this can
|
||||
* be relevant in applications like deterministic ECDSA.
|
||||
*/
|
||||
int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/** Generate a random number uniformly in a range.
|
||||
*
|
||||
@ -916,11 +950,11 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
|
||||
* for all usual cryptographic applications.
|
||||
* \return Another negative error code on failure.
|
||||
*/
|
||||
int mbedtls_mpi_random( mbedtls_mpi *X,
|
||||
mbedtls_mpi_sint min,
|
||||
const mbedtls_mpi *N,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_mpi_random(mbedtls_mpi *X,
|
||||
mbedtls_mpi_sint min,
|
||||
const mbedtls_mpi *N,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief Compute the greatest common divisor: G = gcd(A, B)
|
||||
@ -933,8 +967,8 @@ int mbedtls_mpi_random( mbedtls_mpi *X,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B );
|
||||
int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *B);
|
||||
|
||||
/**
|
||||
* \brief Compute the modular inverse: X = A^-1 mod N
|
||||
@ -952,8 +986,8 @@ int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p has no modular inverse
|
||||
* with respect to \p N.
|
||||
*/
|
||||
int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *N );
|
||||
int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
const mbedtls_mpi *N);
|
||||
|
||||
/**
|
||||
* \brief Miller-Rabin primality test.
|
||||
@ -982,9 +1016,9 @@ int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
|
||||
* \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
/**
|
||||
* \brief Flags for mbedtls_mpi_gen_prime()
|
||||
*
|
||||
@ -1015,9 +1049,9 @@ typedef enum {
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between
|
||||
* \c 3 and #MBEDTLS_MPI_MAX_BITS.
|
||||
*/
|
||||
int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
@ -1026,7 +1060,7 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_mpi_self_test( int verbose );
|
||||
int mbedtls_mpi_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -6,22 +6,22 @@
|
||||
* Include this file if you need to depend on the
|
||||
* configuration options defined in mbedtls_config.h or MBEDTLS_CONFIG_FILE
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* 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_BUILD_INFO_H
|
||||
#define MBEDTLS_BUILD_INFO_H
|
||||
@ -37,22 +37,28 @@
|
||||
* Major, Minor, Patchlevel
|
||||
*/
|
||||
#define MBEDTLS_VERSION_MAJOR 3
|
||||
#define MBEDTLS_VERSION_MINOR 2
|
||||
#define MBEDTLS_VERSION_PATCH 1
|
||||
#define MBEDTLS_VERSION_MINOR 3
|
||||
#define MBEDTLS_VERSION_PATCH 0
|
||||
|
||||
/**
|
||||
* The single version number has the following structure:
|
||||
* MMNNPP00
|
||||
* Major version | Minor version | Patch version
|
||||
*/
|
||||
#define MBEDTLS_VERSION_NUMBER 0x03020100
|
||||
#define MBEDTLS_VERSION_STRING "3.2.1"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 3.2.1"
|
||||
#define MBEDTLS_VERSION_NUMBER 0x03030000
|
||||
#define MBEDTLS_VERSION_STRING "3.3.0"
|
||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 3.3.0"
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
/* Define `inline` on some non-C99-compliant compilers. */
|
||||
#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/mbedtls_config.h"
|
||||
#else
|
||||
@ -61,7 +67,7 @@
|
||||
|
||||
#if defined(MBEDTLS_CONFIG_VERSION) && ( \
|
||||
MBEDTLS_CONFIG_VERSION < 0x03000000 || \
|
||||
MBEDTLS_CONFIG_VERSION > MBEDTLS_VERSION_NUMBER )
|
||||
MBEDTLS_CONFIG_VERSION > MBEDTLS_VERSION_NUMBER)
|
||||
#error "Invalid config version, defined value of MBEDTLS_CONFIG_VERSION is unsupported"
|
||||
#endif
|
||||
|
||||
@ -74,8 +80,55 @@
|
||||
#include MBEDTLS_USER_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PK_C) && defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
/* The PK wrappers need pk_write functions to format RSA key objects
|
||||
* when they are dispatching to the PSA API. This happens under USE_PSA_CRYPTO,
|
||||
* and also even without USE_PSA_CRYPTO for mbedtls_pk_sign_ext().
|
||||
* PSA crypto also needs pk_write to export RSA keys (otherwise the build
|
||||
* goes through but psa_export_key() and psa_export_public_key() fail on
|
||||
* RSA keys), and pk_parse to work with RSA keys in almost any way.
|
||||
*/
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_RSA_C)
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_WRITE_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#endif
|
||||
|
||||
/* Under MBEDTLS_USE_PSA_CRYPTO, the pk module needs pk_write functions
|
||||
* to pass ECC keys to PSA. */
|
||||
#if defined(MBEDTLS_PK_C) && \
|
||||
defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_ECP_C)
|
||||
#define MBEDTLS_PK_WRITE_C
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
#undef MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
|
||||
#undef MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
|
||||
#endif
|
||||
|
||||
#if !defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
||||
#undef MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
|
||||
#undef MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
|
||||
#undef MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
|
||||
#undef MBEDTLS_SSL_EARLY_DATA
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED) || \
|
||||
defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED)
|
||||
#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED) || \
|
||||
defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED)
|
||||
#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED
|
||||
#endif
|
||||
|
||||
/* Make sure all configuration symbols are set before including check_config.h,
|
||||
|
@ -50,8 +50,7 @@ extern "C" {
|
||||
/**
|
||||
* \brief CAMELLIA context structure
|
||||
*/
|
||||
typedef struct mbedtls_camellia_context
|
||||
{
|
||||
typedef struct mbedtls_camellia_context {
|
||||
int MBEDTLS_PRIVATE(nr); /*!< number of rounds */
|
||||
uint32_t MBEDTLS_PRIVATE(rk)[68]; /*!< CAMELLIA round keys */
|
||||
}
|
||||
@ -67,7 +66,7 @@ mbedtls_camellia_context;
|
||||
* \param ctx The CAMELLIA context to be initialized.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
|
||||
void mbedtls_camellia_init(mbedtls_camellia_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Clear a CAMELLIA context.
|
||||
@ -76,7 +75,7 @@ void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
|
||||
* in which case this function returns immediately. If it is not
|
||||
* \c NULL, it must be initialized.
|
||||
*/
|
||||
void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
|
||||
void mbedtls_camellia_free(mbedtls_camellia_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Perform a CAMELLIA key schedule operation for encryption.
|
||||
@ -90,9 +89,9 @@ void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief Perform a CAMELLIA key schedule operation for decryption.
|
||||
@ -106,9 +105,9 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
|
||||
@ -125,10 +124,10 @@ int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] );
|
||||
int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16]);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
@ -159,12 +158,12 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_camellia_crypt_cbc(mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
||||
@ -205,13 +204,13 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_camellia_crypt_cfb128(mbedtls_camellia_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
size_t *iv_off,
|
||||
unsigned char iv[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
||||
@ -289,13 +288,13 @@ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[16],
|
||||
unsigned char stream_block[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_camellia_crypt_ctr(mbedtls_camellia_context *ctx,
|
||||
size_t length,
|
||||
size_t *nc_off,
|
||||
unsigned char nonce_counter[16],
|
||||
unsigned char stream_block[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
@ -305,7 +304,7 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int mbedtls_camellia_self_test( int verbose );
|
||||
int mbedtls_camellia_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -74,8 +74,7 @@ extern "C" {
|
||||
* \brief The CCM context-type definition. The CCM context is passed
|
||||
* to the APIs called.
|
||||
*/
|
||||
typedef struct mbedtls_ccm_context
|
||||
{
|
||||
typedef struct mbedtls_ccm_context {
|
||||
unsigned char MBEDTLS_PRIVATE(y)[16]; /*!< The Y working buffer */
|
||||
unsigned char MBEDTLS_PRIVATE(ctr)[16]; /*!< The counter buffer */
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
|
||||
@ -90,10 +89,10 @@ typedef struct mbedtls_ccm_context
|
||||
auth data input is finished. */
|
||||
unsigned char MBEDTLS_PRIVATE(q); /*!< The Q working value */
|
||||
unsigned char MBEDTLS_PRIVATE(mode); /*!< The operation to perform:
|
||||
#MBEDTLS_CCM_ENCRYPT or
|
||||
#MBEDTLS_CCM_DECRYPT or
|
||||
#MBEDTLS_CCM_STAR_ENCRYPT or
|
||||
#MBEDTLS_CCM_STAR_DECRYPT. */
|
||||
#MBEDTLS_CCM_ENCRYPT or
|
||||
#MBEDTLS_CCM_DECRYPT or
|
||||
#MBEDTLS_CCM_STAR_ENCRYPT or
|
||||
#MBEDTLS_CCM_STAR_DECRYPT. */
|
||||
int MBEDTLS_PRIVATE(state); /*!< Working value holding context's
|
||||
state. Used for chunked data
|
||||
input */
|
||||
@ -111,7 +110,7 @@ mbedtls_ccm_context;
|
||||
*
|
||||
* \param ctx The CCM context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
|
||||
void mbedtls_ccm_init(mbedtls_ccm_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function initializes the CCM context set in the
|
||||
@ -126,10 +125,10 @@ void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A CCM or cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
|
||||
mbedtls_cipher_id_t cipher,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx,
|
||||
mbedtls_cipher_id_t cipher,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified CCM context
|
||||
@ -138,7 +137,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
|
||||
* \param ctx The CCM context to clear. If this is \c NULL, the function
|
||||
* has no effect. Otherwise, this must be initialized.
|
||||
*/
|
||||
void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
|
||||
void mbedtls_ccm_free(mbedtls_ccm_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function encrypts a buffer using CCM.
|
||||
@ -176,11 +175,11 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A CCM or cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function encrypts a buffer using CCM*.
|
||||
@ -225,11 +224,11 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
||||
* \return \c 0 on success.
|
||||
* \return A CCM or cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function performs a CCM authenticated decryption of a
|
||||
@ -262,11 +261,11 @@ int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
|
||||
* \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
|
||||
* \return A cipher-specific error code on calculation failure.
|
||||
*/
|
||||
int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function performs a CCM* authenticated decryption of a
|
||||
@ -308,11 +307,11 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
* \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
|
||||
* \return A cipher-specific error code on calculation failure.
|
||||
*/
|
||||
int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, unsigned char *output,
|
||||
const unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function starts a CCM encryption or decryption
|
||||
@ -342,10 +341,10 @@ int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
|
||||
* \p iv_len is invalid (lower than \c 7 or greater than
|
||||
* \c 13).
|
||||
*/
|
||||
int mbedtls_ccm_starts( mbedtls_ccm_context *ctx,
|
||||
int mode,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len );
|
||||
int mbedtls_ccm_starts(mbedtls_ccm_context *ctx,
|
||||
int mode,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len);
|
||||
|
||||
/**
|
||||
* \brief This function declares the lengths of the message
|
||||
@ -374,10 +373,10 @@ int mbedtls_ccm_starts( mbedtls_ccm_context *ctx,
|
||||
* \p ctx is in an invalid state,
|
||||
* \p total_ad_len is greater than \c 0xFF00.
|
||||
*/
|
||||
int mbedtls_ccm_set_lengths( mbedtls_ccm_context *ctx,
|
||||
size_t total_ad_len,
|
||||
size_t plaintext_len,
|
||||
size_t tag_len );
|
||||
int mbedtls_ccm_set_lengths(mbedtls_ccm_context *ctx,
|
||||
size_t total_ad_len,
|
||||
size_t plaintext_len,
|
||||
size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer as associated data
|
||||
@ -409,9 +408,9 @@ int mbedtls_ccm_set_lengths( mbedtls_ccm_context *ctx,
|
||||
* \p ctx is in an invalid state,
|
||||
* total input length too long.
|
||||
*/
|
||||
int mbedtls_ccm_update_ad( mbedtls_ccm_context *ctx,
|
||||
const unsigned char *ad,
|
||||
size_t ad_len );
|
||||
int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx,
|
||||
const unsigned char *ad,
|
||||
size_t ad_len);
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer into an ongoing CCM
|
||||
@ -476,10 +475,10 @@ int mbedtls_ccm_update_ad( mbedtls_ccm_context *ctx,
|
||||
* total input length too long,
|
||||
* or \p output_size too small.
|
||||
*/
|
||||
int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
||||
const unsigned char *input, size_t input_len,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_len );
|
||||
int mbedtls_ccm_update(mbedtls_ccm_context *ctx,
|
||||
const unsigned char *input, size_t input_len,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_len);
|
||||
|
||||
/**
|
||||
* \brief This function finishes the CCM operation and generates
|
||||
@ -512,8 +511,8 @@ int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
||||
* mbedtls_ccm_update() was lower than the plaintext length
|
||||
* \c plaintext_len passed to mbedtls_ccm_set_lengths().
|
||||
*/
|
||||
int mbedtls_ccm_finish( mbedtls_ccm_context *ctx,
|
||||
unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_ccm_finish(mbedtls_ccm_context *ctx,
|
||||
unsigned char *tag, size_t tag_len);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
|
||||
/**
|
||||
@ -522,7 +521,7 @@ int mbedtls_ccm_finish( mbedtls_ccm_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_ccm_self_test( int verbose );
|
||||
int mbedtls_ccm_self_test(int verbose);
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -47,8 +47,7 @@ extern "C" {
|
||||
|
||||
#if !defined(MBEDTLS_CHACHA20_ALT)
|
||||
|
||||
typedef struct mbedtls_chacha20_context
|
||||
{
|
||||
typedef struct mbedtls_chacha20_context {
|
||||
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. */
|
||||
@ -74,7 +73,7 @@ mbedtls_chacha20_context;
|
||||
* \param ctx The ChaCha20 context to initialize.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx );
|
||||
void mbedtls_chacha20_init(mbedtls_chacha20_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified
|
||||
@ -85,7 +84,7 @@ void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx );
|
||||
* \c NULL, it must point to an initialized context.
|
||||
*
|
||||
*/
|
||||
void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx );
|
||||
void mbedtls_chacha20_free(mbedtls_chacha20_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function sets the encryption/decryption key.
|
||||
@ -103,8 +102,8 @@ void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or key is NULL.
|
||||
*/
|
||||
int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
|
||||
const unsigned char key[32] );
|
||||
int mbedtls_chacha20_setkey(mbedtls_chacha20_context *ctx,
|
||||
const unsigned char key[32]);
|
||||
|
||||
/**
|
||||
* \brief This function sets the nonce and initial counter value.
|
||||
@ -125,9 +124,9 @@ int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
|
||||
* \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or nonce is
|
||||
* NULL.
|
||||
*/
|
||||
int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
|
||||
const unsigned char nonce[12],
|
||||
uint32_t counter );
|
||||
int mbedtls_chacha20_starts(mbedtls_chacha20_context *ctx,
|
||||
const unsigned char nonce[12],
|
||||
uint32_t counter);
|
||||
|
||||
/**
|
||||
* \brief This function encrypts or decrypts data.
|
||||
@ -158,10 +157,10 @@ int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
|
||||
size_t size,
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_chacha20_update(mbedtls_chacha20_context *ctx,
|
||||
size_t size,
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief This function encrypts or decrypts data with ChaCha20 and
|
||||
@ -191,12 +190,12 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_chacha20_crypt( const unsigned char key[32],
|
||||
const unsigned char nonce[12],
|
||||
uint32_t counter,
|
||||
size_t size,
|
||||
const unsigned char* input,
|
||||
unsigned char* output );
|
||||
int mbedtls_chacha20_crypt(const unsigned char key[32],
|
||||
const unsigned char nonce[12],
|
||||
uint32_t counter,
|
||||
size_t size,
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
@ -205,7 +204,7 @@ int mbedtls_chacha20_crypt( const unsigned char key[32],
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_chacha20_self_test( int verbose );
|
||||
int mbedtls_chacha20_self_test(int verbose);
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -47,8 +47,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_CHACHAPOLY_ENCRYPT, /**< The mode value for performing encryption. */
|
||||
MBEDTLS_CHACHAPOLY_DECRYPT /**< The mode value for performing decryption. */
|
||||
}
|
||||
@ -58,8 +57,7 @@ mbedtls_chachapoly_mode_t;
|
||||
|
||||
#include "mbedtls/chacha20.h"
|
||||
|
||||
typedef struct mbedtls_chachapoly_context
|
||||
{
|
||||
typedef struct mbedtls_chachapoly_context {
|
||||
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. */
|
||||
@ -115,7 +113,7 @@ mbedtls_chachapoly_context;
|
||||
*
|
||||
* \param ctx The ChachaPoly context to initialize. Must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
|
||||
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function releases and clears the specified
|
||||
@ -124,7 +122,7 @@ void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx );
|
||||
* \param ctx The ChachaPoly context to clear. This may be \c NULL, in which
|
||||
* case this function is a no-op.
|
||||
*/
|
||||
void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
|
||||
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function sets the ChaCha20-Poly1305
|
||||
@ -137,8 +135,8 @@ void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char key[32] );
|
||||
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char key[32]);
|
||||
|
||||
/**
|
||||
* \brief This function starts a ChaCha20-Poly1305 encryption or
|
||||
@ -165,9 +163,9 @@ int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char nonce[12],
|
||||
mbedtls_chachapoly_mode_t mode );
|
||||
int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char nonce[12],
|
||||
mbedtls_chachapoly_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief This function feeds additional data to be authenticated
|
||||
@ -208,9 +206,9 @@ int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
|
||||
* if the operations has not been started or has been
|
||||
* finished, or if the AAD has been finished.
|
||||
*/
|
||||
int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char *aad,
|
||||
size_t aad_len );
|
||||
int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx,
|
||||
const unsigned char *aad,
|
||||
size_t aad_len);
|
||||
|
||||
/**
|
||||
* \brief Thus function feeds data to be encrypted or decrypted
|
||||
@ -243,10 +241,10 @@ int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
|
||||
* finished.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
|
||||
size_t len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx,
|
||||
size_t len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief This function finished the ChaCha20-Poly1305 operation and
|
||||
@ -264,8 +262,8 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
|
||||
* finished.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
|
||||
unsigned char mac[16] );
|
||||
int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx,
|
||||
unsigned char mac[16]);
|
||||
|
||||
/**
|
||||
* \brief This function performs a complete ChaCha20-Poly1305
|
||||
@ -296,14 +294,14 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char nonce[12],
|
||||
const unsigned char *aad,
|
||||
size_t aad_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
unsigned char tag[16] );
|
||||
int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char nonce[12],
|
||||
const unsigned char *aad,
|
||||
size_t aad_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
unsigned char tag[16]);
|
||||
|
||||
/**
|
||||
* \brief This function performs a complete ChaCha20-Poly1305
|
||||
@ -330,14 +328,14 @@ int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
|
||||
* if the data was not authentic.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char nonce[12],
|
||||
const unsigned char *aad,
|
||||
size_t aad_len,
|
||||
const unsigned char tag[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char nonce[12],
|
||||
const unsigned char *aad,
|
||||
size_t aad_len,
|
||||
const unsigned char tag[16],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
@ -346,7 +344,7 @@ int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_chachapoly_self_test( int verbose );
|
||||
int mbedtls_chachapoly_self_test(int verbose);
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -23,6 +23,7 @@
|
||||
#ifndef MBEDTLS_CHECK_CONFIG_H
|
||||
#define MBEDTLS_CHECK_CONFIG_H
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/*
|
||||
* We assume CHAR_BIT is 8 in many places. In practice, this is true on our
|
||||
* target platforms, so not an issue, but let's just be extra sure.
|
||||
@ -32,6 +33,8 @@
|
||||
#error "mbed TLS requires a platform with 8-bit chars"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if !defined(MBEDTLS_PLATFORM_C)
|
||||
#error "MBEDTLS_PLATFORM_C is required on Windows"
|
||||
@ -114,15 +117,19 @@
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE) && \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) || \
|
||||
defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \
|
||||
( defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \
|
||||
defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || \
|
||||
defined(MBEDTLS_ECDSA_SIGN_ALT) || \
|
||||
defined(MBEDTLS_ECDSA_VERIFY_ALT) || \
|
||||
defined(MBEDTLS_ECDSA_GENKEY_ALT) || \
|
||||
defined(MBEDTLS_ECP_INTERNAL_ALT) || \
|
||||
defined(MBEDTLS_ECP_ALT) )
|
||||
#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative or PSA-based ECP implementation"
|
||||
#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE) && \
|
||||
!defined(MBEDTLS_ECP_C)
|
||||
#error "MBEDTLS_ECP_RESTARTABLE defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
|
||||
@ -327,7 +334,7 @@
|
||||
|
||||
/* Use of EC J-PAKE in TLS requires SHA-256.
|
||||
* This will be taken from MD if it is present, or from PSA if MD is absent.
|
||||
* Note: ECJPAKE_C depends on MD_C || PSA_CRYPTO_C. */
|
||||
* Note: MBEDTLS_ECJPAKE_C depends on MBEDTLS_MD_C || MBEDTLS_PSA_CRYPTO_C. */
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||
!( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA256_C) ) && \
|
||||
!( !defined(MBEDTLS_MD_C) && defined(PSA_WANT_ALG_SHA_256) )
|
||||
@ -353,6 +360,16 @@
|
||||
#error "MBEDTLS_MD_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_LMS_C) && \
|
||||
! ( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_256) )
|
||||
#error "MBEDTLS_LMS_C requires MBEDTLS_PSA_CRYPTO_C and PSA_WANT_ALG_SHA_256"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_LMS_PRIVATE) && \
|
||||
( !defined(MBEDTLS_LMS_C) )
|
||||
#error "MBEDTLS_LMS_PRIVATE requires MBEDTLS_LMS_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||
@ -523,6 +540,20 @@
|
||||
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
||||
#error "MBEDTLS_PLATFORM_VSNPRINTF_ALT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
||||
#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) &&\
|
||||
( defined(MBEDTLS_PLATFORM_STD_VSNPRINTF) ||\
|
||||
defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) )
|
||||
#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_VSNPRINTF/MBEDTLS_PLATFORM_VSNPRINTF_ALT cannot be defined simultaneously"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
|
||||
!defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
||||
#error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
|
||||
@ -664,10 +695,6 @@
|
||||
#error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA384_C) && !defined(MBEDTLS_SHA512_C)
|
||||
#error "MBEDTLS_SHA384_C defined without MBEDTLS_SHA512_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) && \
|
||||
defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY)
|
||||
#error "Must only define one of MBEDTLS_SHA512_USE_A64_CRYPTO_*"
|
||||
@ -723,14 +750,6 @@
|
||||
#error "MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY defined on non-Aarch64 system"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA224_C) && !defined(MBEDTLS_SHA256_C)
|
||||
#error "MBEDTLS_SHA224_C defined without MBEDTLS_SHA256_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA224_C)
|
||||
#error "MBEDTLS_SHA256_C defined without MBEDTLS_SHA224_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) && \
|
||||
defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY)
|
||||
#error "Must only define one of MBEDTLS_SHA256_USE_A64_CRYPTO_*"
|
||||
@ -782,6 +801,19 @@
|
||||
#endif /* !MBEDTLS_USE_PSA_CRYPTO */
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
|
||||
#if !( defined(MBEDTLS_ECDH_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
( defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_PKCS1_V21) ) )
|
||||
#error "MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED)
|
||||
#if !( defined(MBEDTLS_ECDH_C) )
|
||||
#error "MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The current implementation of TLS 1.3 requires MBEDTLS_SSL_KEEP_PEER_CERTIFICATE.
|
||||
*/
|
||||
@ -805,6 +837,20 @@
|
||||
"but no key exchange methods defined with MBEDTLS_KEY_EXCHANGE_xxxx"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_EARLY_DATA) && \
|
||||
( !defined(MBEDTLS_SSL_SESSION_TICKETS) || \
|
||||
( !defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED) && \
|
||||
!defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED) ) )
|
||||
#error "MBEDTLS_SSL_EARLY_DATA defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_SRV_C) && \
|
||||
( !defined(MBEDTLS_SSL_MAX_EARLY_DATA_SIZE) || \
|
||||
( MBEDTLS_SSL_MAX_EARLY_DATA_SIZE < 0 ) || \
|
||||
( MBEDTLS_SSL_MAX_EARLY_DATA_SIZE > UINT32_MAX ) )
|
||||
#error "MBEDTLS_SSL_MAX_EARLY_DATA_SIZE MUST be defined and in range(0..UINT32_MAX)"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
#error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
|
||||
@ -814,6 +860,10 @@
|
||||
#error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) && !defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#error "MBEDTLS_SSL_ASYNC_PRIVATE defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
|
||||
( !defined(MBEDTLS_MD_C) && !defined(MBEDTLS_USE_PSA_CRYPTO) ) )
|
||||
#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
|
||||
@ -859,6 +909,19 @@
|
||||
#error "MBEDTLS_SSL_CID_OUT_LEN_MAX too large (max 255)"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && \
|
||||
!defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||
#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0
|
||||
#if defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#elif defined(MBEDTLS_DEPRECATED_WARNING)
|
||||
#warning "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS"
|
||||
#endif
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0 */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
|
||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequisites"
|
||||
@ -950,6 +1013,11 @@
|
||||
#error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) && \
|
||||
( !defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||
#error "MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)
|
||||
#error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously"
|
||||
#endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */
|
||||
@ -1018,6 +1086,14 @@
|
||||
#error "MBEDTLS_SSL_TRUNCATED_HMAC was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4341"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PKCS7_C) && ( ( !defined(MBEDTLS_ASN1_PARSE_C) ) || \
|
||||
( !defined(MBEDTLS_OID_C) ) || ( !defined(MBEDTLS_PK_PARSE_C) ) || \
|
||||
( !defined(MBEDTLS_X509_CRT_PARSE_C) ) ||\
|
||||
( !defined(MBEDTLS_X509_CRL_PARSE_C) ) || ( !defined(MBEDTLS_BIGNUM_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) ) )
|
||||
#error "MBEDTLS_PKCS7_C is defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Avoid warning from -pedantic. This is a convenient place for this
|
||||
* workaround since this is included by every single file before the
|
||||
@ -1025,4 +1101,5 @@
|
||||
*/
|
||||
typedef int mbedtls_iso_c_forbids_empty_translation_units;
|
||||
|
||||
/* *INDENT-ON* */
|
||||
#endif /* MBEDTLS_CHECK_CONFIG_H */
|
||||
|
@ -46,11 +46,6 @@
|
||||
#define MBEDTLS_CIPHER_MODE_STREAM
|
||||
#endif
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/** The selected feature is not available. */
|
||||
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080
|
||||
/** Bad input parameters. */
|
||||
@ -76,16 +71,16 @@ extern "C" {
|
||||
/**
|
||||
* \brief Supported cipher types.
|
||||
*
|
||||
* \warning DES is considered weak cipher and its use
|
||||
* constitutes a security risk. Arm recommends considering stronger
|
||||
* \warning DES/3DES are considered weak ciphers and their use
|
||||
* constitutes a security risk. We recommend considering stronger
|
||||
* ciphers instead.
|
||||
*/
|
||||
typedef enum {
|
||||
MBEDTLS_CIPHER_ID_NONE = 0, /**< Placeholder to mark the end of cipher ID lists. */
|
||||
MBEDTLS_CIPHER_ID_NULL, /**< The identity cipher, treated as a stream cipher. */
|
||||
MBEDTLS_CIPHER_ID_AES, /**< The AES cipher. */
|
||||
MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */
|
||||
MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */
|
||||
MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. \warning DES is considered weak. */
|
||||
MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. \warning 3DES is considered weak. */
|
||||
MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */
|
||||
MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */
|
||||
MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */
|
||||
@ -94,8 +89,8 @@ typedef enum {
|
||||
/**
|
||||
* \brief Supported {cipher type, cipher mode} pairs.
|
||||
*
|
||||
* \warning DES is considered weak cipher and its use
|
||||
* constitutes a security risk. Arm recommends considering stronger
|
||||
* \warning DES/3DES are considered weak ciphers and their use
|
||||
* constitutes a security risk. We recommend considering stronger
|
||||
* ciphers instead.
|
||||
*/
|
||||
typedef enum {
|
||||
@ -131,12 +126,12 @@ typedef enum {
|
||||
MBEDTLS_CIPHER_CAMELLIA_128_GCM, /**< Camellia cipher with 128-bit GCM mode. */
|
||||
MBEDTLS_CIPHER_CAMELLIA_192_GCM, /**< Camellia cipher with 192-bit GCM mode. */
|
||||
MBEDTLS_CIPHER_CAMELLIA_256_GCM, /**< Camellia cipher with 256-bit GCM mode. */
|
||||
MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. */
|
||||
MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. */
|
||||
MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. */
|
||||
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_DES_ECB, /**< DES cipher with ECB mode. \warning DES is considered weak. */
|
||||
MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. \warning DES is considered weak. */
|
||||
MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. \warning 3DES is considered weak. */
|
||||
MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. \warning 3DES is considered weak. */
|
||||
MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. \warning 3DES is considered weak. */
|
||||
MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. \warning 3DES is considered weak. */
|
||||
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. */
|
||||
@ -222,11 +217,11 @@ typedef enum {
|
||||
enum {
|
||||
/** Undefined key length. */
|
||||
MBEDTLS_KEY_LENGTH_NONE = 0,
|
||||
/** Key length, in bits (including parity), for DES keys. */
|
||||
/** Key length, in bits (including parity), for DES keys. \warning DES is considered weak. */
|
||||
MBEDTLS_KEY_LENGTH_DES = 64,
|
||||
/** Key length in bits, including parity, for DES in two-key EDE. */
|
||||
/** Key length in bits, including parity, for DES in two-key EDE. \warning 3DES is considered weak. */
|
||||
MBEDTLS_KEY_LENGTH_DES_EDE = 128,
|
||||
/** Key length in bits, including parity, for DES in three-key EDE. */
|
||||
/** Key length in bits, including parity, for DES in three-key EDE. \warning 3DES is considered weak. */
|
||||
MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
|
||||
};
|
||||
|
||||
@ -276,8 +271,7 @@ typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
|
||||
* mbedtls_cipher_info_from_values(),
|
||||
* mbedtls_cipher_info_from_psa().
|
||||
*/
|
||||
typedef struct mbedtls_cipher_info_t
|
||||
{
|
||||
typedef struct mbedtls_cipher_info_t {
|
||||
/** Full cipher identifier. For example,
|
||||
* MBEDTLS_CIPHER_AES_256_CBC.
|
||||
*/
|
||||
@ -293,7 +287,7 @@ typedef struct mbedtls_cipher_info_t
|
||||
unsigned int MBEDTLS_PRIVATE(key_bitlen);
|
||||
|
||||
/** Name of the cipher. */
|
||||
const char * MBEDTLS_PRIVATE(name);
|
||||
const char *MBEDTLS_PRIVATE(name);
|
||||
|
||||
/** IV or nonce size, in Bytes.
|
||||
* For ciphers that accept variable IV sizes,
|
||||
@ -318,8 +312,7 @@ typedef struct mbedtls_cipher_info_t
|
||||
/**
|
||||
* Generic cipher context.
|
||||
*/
|
||||
typedef struct mbedtls_cipher_context_t
|
||||
{
|
||||
typedef struct mbedtls_cipher_context_t {
|
||||
/** Information about the associated cipher. */
|
||||
const mbedtls_cipher_info_t *MBEDTLS_PRIVATE(cipher_info);
|
||||
|
||||
@ -335,8 +328,8 @@ typedef struct mbedtls_cipher_context_t
|
||||
/** Padding functions to use, if relevant for
|
||||
* the specific cipher mode.
|
||||
*/
|
||||
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 );
|
||||
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. */
|
||||
@ -386,7 +379,7 @@ typedef struct mbedtls_cipher_context_t
|
||||
* \return A statically-allocated array of cipher identifiers
|
||||
* of type cipher_type_t. The last entry is zero.
|
||||
*/
|
||||
const int *mbedtls_cipher_list( void );
|
||||
const int *mbedtls_cipher_list(void);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the cipher-information
|
||||
@ -399,7 +392,7 @@ const int *mbedtls_cipher_list( void );
|
||||
* given \p cipher_name.
|
||||
* \return \c NULL if the associated cipher information is not found.
|
||||
*/
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name );
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(const char *cipher_name);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the cipher-information
|
||||
@ -411,7 +404,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher
|
||||
* given \p cipher_type.
|
||||
* \return \c NULL if the associated cipher information is not found.
|
||||
*/
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type );
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(const mbedtls_cipher_type_t cipher_type);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the cipher-information
|
||||
@ -427,9 +420,9 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher
|
||||
* given \p cipher_id.
|
||||
* \return \c NULL if the associated cipher information is not found.
|
||||
*/
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id,
|
||||
int key_bitlen,
|
||||
const mbedtls_cipher_mode_t mode );
|
||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id,
|
||||
int key_bitlen,
|
||||
const mbedtls_cipher_mode_t mode);
|
||||
|
||||
/**
|
||||
* \brief Retrieve the identifier for a cipher info structure.
|
||||
@ -441,12 +434,13 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_ciph
|
||||
* \return #MBEDTLS_CIPHER_NONE if \p info is \c NULL.
|
||||
*/
|
||||
static inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( MBEDTLS_CIPHER_NONE );
|
||||
else
|
||||
return( info->MBEDTLS_PRIVATE(type) );
|
||||
if (info == NULL) {
|
||||
return MBEDTLS_CIPHER_NONE;
|
||||
} else {
|
||||
return info->MBEDTLS_PRIVATE(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -459,12 +453,13 @@ static inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type(
|
||||
* \return #MBEDTLS_MODE_NONE if \p info is \c NULL.
|
||||
*/
|
||||
static inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( MBEDTLS_MODE_NONE );
|
||||
else
|
||||
return( info->MBEDTLS_PRIVATE(mode) );
|
||||
if (info == NULL) {
|
||||
return MBEDTLS_MODE_NONE;
|
||||
} else {
|
||||
return info->MBEDTLS_PRIVATE(mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -479,12 +474,13 @@ static inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode(
|
||||
* \return \c 0 if \p info is \c NULL.
|
||||
*/
|
||||
static inline size_t mbedtls_cipher_info_get_key_bitlen(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( 0 );
|
||||
else
|
||||
return( info->MBEDTLS_PRIVATE(key_bitlen) );
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return info->MBEDTLS_PRIVATE(key_bitlen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -499,12 +495,13 @@ static inline size_t mbedtls_cipher_info_get_key_bitlen(
|
||||
* \return \c NULL if \c info is \p NULL.
|
||||
*/
|
||||
static inline const char *mbedtls_cipher_info_get_name(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( NULL );
|
||||
else
|
||||
return( info->MBEDTLS_PRIVATE(name) );
|
||||
if (info == NULL) {
|
||||
return NULL;
|
||||
} else {
|
||||
return info->MBEDTLS_PRIVATE(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -518,12 +515,13 @@ static inline const char *mbedtls_cipher_info_get_name(
|
||||
* \return \c 0 if \p info is \c NULL.
|
||||
*/
|
||||
static inline size_t mbedtls_cipher_info_get_iv_size(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( 0 );
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return( (size_t) info->MBEDTLS_PRIVATE(iv_size) );
|
||||
return (size_t) info->MBEDTLS_PRIVATE(iv_size);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -537,12 +535,13 @@ static inline size_t mbedtls_cipher_info_get_iv_size(
|
||||
* \return \c 0 if \p info is \c NULL.
|
||||
*/
|
||||
static inline size_t mbedtls_cipher_info_get_block_size(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( 0 );
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return( (size_t) info->MBEDTLS_PRIVATE(block_size) );
|
||||
return (size_t) info->MBEDTLS_PRIVATE(block_size);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -555,12 +554,13 @@ static inline size_t mbedtls_cipher_info_get_block_size(
|
||||
* \return \c 0 if the given pointer is \c NULL.
|
||||
*/
|
||||
static inline int mbedtls_cipher_info_has_variable_key_bitlen(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( 0 );
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN );
|
||||
return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -573,12 +573,13 @@ static inline int mbedtls_cipher_info_has_variable_key_bitlen(
|
||||
* \return \c 0 if the given pointer is \c NULL.
|
||||
*/
|
||||
static inline int mbedtls_cipher_info_has_variable_iv_size(
|
||||
const mbedtls_cipher_info_t *info )
|
||||
const mbedtls_cipher_info_t *info)
|
||||
{
|
||||
if( info == NULL )
|
||||
return( 0 );
|
||||
if (info == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN );
|
||||
return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -586,7 +587,7 @@ static inline int mbedtls_cipher_info_has_variable_iv_size(
|
||||
*
|
||||
* \param ctx The context to be initialized. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
|
||||
void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function frees and clears the cipher-specific
|
||||
@ -597,7 +598,7 @@ void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
|
||||
* function has no effect, otherwise this must point to an
|
||||
* initialized context.
|
||||
*/
|
||||
void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
|
||||
void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx);
|
||||
|
||||
|
||||
/**
|
||||
@ -626,8 +627,8 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
|
||||
* \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
|
||||
* cipher-specific context fails.
|
||||
*/
|
||||
int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
|
||||
const mbedtls_cipher_info_t *cipher_info );
|
||||
int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx,
|
||||
const mbedtls_cipher_info_t *cipher_info);
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
||||
@ -657,8 +658,9 @@ int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
|
||||
* cipher-specific context fails.
|
||||
*/
|
||||
int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx,
|
||||
const mbedtls_cipher_info_t *cipher_info, size_t taglen );
|
||||
int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx,
|
||||
const mbedtls_cipher_info_t *cipher_info,
|
||||
size_t taglen);
|
||||
#endif /* MBEDTLS_DEPRECATED_REMOVED */
|
||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||
|
||||
@ -673,11 +675,12 @@ int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx,
|
||||
* \return \c 0 if \p ctx has not been initialized.
|
||||
*/
|
||||
static inline unsigned int mbedtls_cipher_get_block_size(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(block_size);
|
||||
}
|
||||
@ -692,11 +695,12 @@ static inline unsigned int mbedtls_cipher_get_block_size(
|
||||
* \return #MBEDTLS_MODE_NONE if \p ctx has not been initialized.
|
||||
*/
|
||||
static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, MBEDTLS_MODE_NONE );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, MBEDTLS_MODE_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_MODE_NONE;
|
||||
}
|
||||
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(mode);
|
||||
}
|
||||
@ -712,14 +716,16 @@ static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode(
|
||||
* \return The actual size if an IV has been set.
|
||||
*/
|
||||
static inline int mbedtls_cipher_get_iv_size(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( ctx->MBEDTLS_PRIVATE(iv_size) != 0 )
|
||||
if (ctx->MBEDTLS_PRIVATE(iv_size) != 0) {
|
||||
return (int) ctx->MBEDTLS_PRIVATE(iv_size);
|
||||
}
|
||||
|
||||
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(iv_size);
|
||||
}
|
||||
@ -733,12 +739,13 @@ static inline int mbedtls_cipher_get_iv_size(
|
||||
* \return #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized.
|
||||
*/
|
||||
static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_CIPHER_NONE );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
ctx != NULL, MBEDTLS_CIPHER_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_CIPHER_NONE;
|
||||
}
|
||||
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(type);
|
||||
}
|
||||
@ -753,11 +760,12 @@ static inline mbedtls_cipher_type_t mbedtls_cipher_get_type(
|
||||
* \return NULL if \p ctx has not been not initialized.
|
||||
*/
|
||||
static inline const char *mbedtls_cipher_get_name(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(ctx != NULL, 0);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(name);
|
||||
}
|
||||
@ -772,12 +780,13 @@ static inline const char *mbedtls_cipher_get_name(
|
||||
* initialized.
|
||||
*/
|
||||
static inline int mbedtls_cipher_get_key_bitlen(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_KEY_LENGTH_NONE );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
ctx != NULL, MBEDTLS_KEY_LENGTH_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_KEY_LENGTH_NONE;
|
||||
}
|
||||
|
||||
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen);
|
||||
}
|
||||
@ -791,12 +800,13 @@ static inline int mbedtls_cipher_get_key_bitlen(
|
||||
* \return #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized.
|
||||
*/
|
||||
static inline mbedtls_operation_t mbedtls_cipher_get_operation(
|
||||
const mbedtls_cipher_context_t *ctx )
|
||||
const mbedtls_cipher_context_t *ctx)
|
||||
{
|
||||
MBEDTLS_INTERNAL_VALIDATE_RET(
|
||||
ctx != NULL, MBEDTLS_OPERATION_NONE );
|
||||
if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL )
|
||||
ctx != NULL, MBEDTLS_OPERATION_NONE);
|
||||
if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) {
|
||||
return MBEDTLS_OPERATION_NONE;
|
||||
}
|
||||
|
||||
return ctx->MBEDTLS_PRIVATE(operation);
|
||||
}
|
||||
@ -817,10 +827,10 @@ static inline mbedtls_operation_t mbedtls_cipher_get_operation(
|
||||
* parameter-verification failure.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *key,
|
||||
int key_bitlen,
|
||||
const mbedtls_operation_t operation );
|
||||
int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *key,
|
||||
int key_bitlen,
|
||||
const mbedtls_operation_t operation);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
||||
/**
|
||||
@ -839,8 +849,8 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
|
||||
* does not support padding.
|
||||
*/
|
||||
int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx,
|
||||
mbedtls_cipher_padding_t mode );
|
||||
int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx,
|
||||
mbedtls_cipher_padding_t mode);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
|
||||
|
||||
/**
|
||||
@ -867,9 +877,9 @@ int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
||||
* parameter-verification failure.
|
||||
*/
|
||||
int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len );
|
||||
int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len);
|
||||
|
||||
/**
|
||||
* \brief This function resets the cipher state.
|
||||
@ -903,7 +913,7 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
||||
* parameter-verification failure.
|
||||
*/
|
||||
int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
|
||||
int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx);
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
||||
/**
|
||||
@ -918,8 +928,8 @@ int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *ad, size_t ad_len );
|
||||
int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *ad, size_t ad_len);
|
||||
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
||||
|
||||
/**
|
||||
@ -951,10 +961,10 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
|
||||
* unsupported mode for a cipher.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen, unsigned char *output,
|
||||
size_t *olen );
|
||||
int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input,
|
||||
size_t ilen, unsigned char *output,
|
||||
size_t *olen);
|
||||
|
||||
/**
|
||||
* \brief The generic cipher finalization function. If data still
|
||||
@ -978,8 +988,8 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx,
|
||||
* while decrypting.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *output, size_t *olen );
|
||||
int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *output, size_t *olen);
|
||||
|
||||
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
||||
/**
|
||||
@ -998,8 +1008,8 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function checks the tag for AEAD ciphers.
|
||||
@ -1014,8 +1024,8 @@ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return A specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *tag, size_t tag_len);
|
||||
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
||||
|
||||
/**
|
||||
@ -1051,10 +1061,10 @@ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
||||
* while decrypting.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen );
|
||||
int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t *olen);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
|
||||
/**
|
||||
@ -1101,12 +1111,12 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
||||
* parameter-verification failure.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t output_len,
|
||||
size_t *olen, size_t tag_len );
|
||||
int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t output_len,
|
||||
size_t *olen, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief The authenticated encryption (AEAD/NIST_KW) function.
|
||||
@ -1157,12 +1167,12 @@ int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t output_len,
|
||||
size_t *olen, size_t tag_len );
|
||||
int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *iv, size_t iv_len,
|
||||
const unsigned char *ad, size_t ad_len,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output, size_t output_len,
|
||||
size_t *olen, size_t tag_len);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ extern "C" {
|
||||
/**
|
||||
* The CMAC context structure.
|
||||
*/
|
||||
struct mbedtls_cmac_context_t
|
||||
{
|
||||
struct mbedtls_cmac_context_t {
|
||||
/** The internal state of the CMAC algorithm. */
|
||||
unsigned char MBEDTLS_PRIVATE(state)[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
@ -96,8 +95,8 @@ struct mbedtls_cmac_context_t
|
||||
* \return \c 0 on success.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *key, size_t keybits );
|
||||
int mbedtls_cipher_cmac_starts(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *key, size_t keybits);
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer into an ongoing CMAC
|
||||
@ -121,8 +120,8 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
||||
* if parameter verification fails.
|
||||
*/
|
||||
int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input, size_t ilen );
|
||||
int mbedtls_cipher_cmac_update(mbedtls_cipher_context_t *ctx,
|
||||
const unsigned char *input, size_t ilen);
|
||||
|
||||
/**
|
||||
* \brief This function finishes an ongoing CMAC operation, and
|
||||
@ -140,8 +139,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
||||
* if parameter verification fails.
|
||||
*/
|
||||
int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *output );
|
||||
int mbedtls_cipher_cmac_finish(mbedtls_cipher_context_t *ctx,
|
||||
unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief This function starts a new CMAC operation with the same
|
||||
@ -159,7 +158,7 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
||||
* if parameter verification fails.
|
||||
*/
|
||||
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
||||
int mbedtls_cipher_cmac_reset(mbedtls_cipher_context_t *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function calculates the full generic CMAC
|
||||
@ -188,10 +187,10 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
||||
* if parameter verification fails.
|
||||
*/
|
||||
int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
|
||||
const unsigned char *key, size_t keylen,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output );
|
||||
int mbedtls_cipher_cmac(const mbedtls_cipher_info_t *cipher_info,
|
||||
const unsigned char *key, size_t keylen,
|
||||
const unsigned char *input, size_t ilen,
|
||||
unsigned char *output);
|
||||
|
||||
#if defined(MBEDTLS_AES_C)
|
||||
/**
|
||||
@ -211,12 +210,12 @@ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
||||
const unsigned char *input, size_t in_len,
|
||||
unsigned char output[16] );
|
||||
int mbedtls_aes_cmac_prf_128(const unsigned char *key, size_t key_len,
|
||||
const unsigned char *input, size_t in_len,
|
||||
unsigned char output[16]);
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
|
||||
#if defined(MBEDTLS_SELF_TEST) && (defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C))
|
||||
/**
|
||||
* \brief The CMAC checkup routine.
|
||||
*
|
||||
@ -230,7 +229,7 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_cmac_self_test( int verbose );
|
||||
int mbedtls_cmac_self_test(int verbose);
|
||||
#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -7,7 +7,7 @@
|
||||
* those definitions to define symbols used in the library code.
|
||||
*
|
||||
* Users and integrators should not edit this file, please edit
|
||||
* include/mbedtls/mbedtls_config.h for MBETLS_XXX settings or
|
||||
* include/mbedtls/mbedtls_config.h for MBEDTLS_XXX settings or
|
||||
* include/psa/crypto_config.h for PSA_WANT_XXX settings.
|
||||
*/
|
||||
/*
|
||||
@ -296,9 +296,9 @@ extern "C" {
|
||||
(defined(PSA_WANT_ALG_OFB) && !defined(MBEDTLS_PSA_ACCEL_ALG_OFB)) || \
|
||||
defined(PSA_WANT_ALG_ECB_NO_PADDING) || \
|
||||
(defined(PSA_WANT_ALG_CBC_NO_PADDING) && \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)) || \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING)) || \
|
||||
(defined(PSA_WANT_ALG_CBC_PKCS7) && \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)) || \
|
||||
!defined(MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7)) || \
|
||||
(defined(PSA_WANT_ALG_CMAC) && !defined(MBEDTLS_PSA_ACCEL_ALG_CMAC))
|
||||
#define PSA_HAVE_SOFT_BLOCK_MODE 1
|
||||
#endif
|
||||
@ -843,6 +843,8 @@ extern "C" {
|
||||
|
||||
/* These features are always enabled. */
|
||||
#define PSA_WANT_KEY_TYPE_DERIVE 1
|
||||
#define PSA_WANT_KEY_TYPE_PASSWORD 1
|
||||
#define PSA_WANT_KEY_TYPE_PASSWORD_HASH 1
|
||||
#define PSA_WANT_KEY_TYPE_RAW_DATA 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Constant-time functions
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -38,8 +39,8 @@
|
||||
* \return Zero if the content of the two buffer is the same,
|
||||
* otherwise non-zero.
|
||||
*/
|
||||
int mbedtls_ct_memcmp( const void *a,
|
||||
const void *b,
|
||||
size_t n );
|
||||
int mbedtls_ct_memcmp(const void *a,
|
||||
const void *b,
|
||||
size_t n);
|
||||
|
||||
#endif /* MBEDTLS_CONSTANT_TIME_H */
|
||||
|
@ -77,8 +77,8 @@
|
||||
*/
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */
|
||||
#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */
|
||||
#define MBEDTLS_CTR_DRBG_KEYBITS (MBEDTLS_CTR_DRBG_KEYSIZE * 8) /**< The key size for the DRBG operation, in bits. */
|
||||
#define MBEDTLS_CTR_DRBG_SEEDLEN (MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE) /**< The seed length, calculated as (counter + AES key). */
|
||||
|
||||
/**
|
||||
* \name SECTION: Module settings
|
||||
@ -161,42 +161,41 @@ extern "C" {
|
||||
* the entropy source does not provide enough material to form a nonce.
|
||||
* See the documentation of mbedtls_ctr_drbg_seed() for more information.
|
||||
*/
|
||||
#define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN ( MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1 ) / 2
|
||||
#define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN (MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1) / 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief The CTR_DRBG context structure.
|
||||
*/
|
||||
typedef struct mbedtls_ctr_drbg_context
|
||||
{
|
||||
typedef struct mbedtls_ctr_drbg_context {
|
||||
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.
|
||||
* Before the initial seeding, this field
|
||||
* contains the amount of entropy in bytes
|
||||
* to use as a nonce for the initial seeding,
|
||||
* or -1 if no nonce length has been explicitly
|
||||
* set (see mbedtls_ctr_drbg_set_nonce_len()).
|
||||
*/
|
||||
* This is the number of requests that have
|
||||
* been made since the last (re)seeding,
|
||||
* minus one.
|
||||
* Before the initial seeding, this field
|
||||
* contains the amount of entropy in bytes
|
||||
* to use as a nonce for the initial seeding,
|
||||
* or -1 if no nonce length has been explicitly
|
||||
* set (see mbedtls_ctr_drbg_set_nonce_len()).
|
||||
*/
|
||||
int MBEDTLS_PRIVATE(prediction_resistance); /*!< This determines whether prediction
|
||||
resistance is enabled, that is
|
||||
whether to systematically reseed before
|
||||
each random generation. */
|
||||
resistance is enabled, that is
|
||||
whether to systematically reseed before
|
||||
each random generation. */
|
||||
size_t MBEDTLS_PRIVATE(entropy_len); /*!< The amount of entropy grabbed on each
|
||||
seed or reseed operation, in bytes. */
|
||||
seed or reseed operation, in bytes. */
|
||||
int MBEDTLS_PRIVATE(reseed_interval); /*!< The reseed interval.
|
||||
* This is the maximum number of requests
|
||||
* that can be made between reseedings. */
|
||||
* This is the maximum number of requests
|
||||
* that can be made between reseedings. */
|
||||
|
||||
mbedtls_aes_context MBEDTLS_PRIVATE(aes_ctx); /*!< The AES context. */
|
||||
|
||||
/*
|
||||
* Callbacks (Entropy)
|
||||
*/
|
||||
int (*MBEDTLS_PRIVATE(f_entropy))(void *, unsigned char *, size_t);
|
||||
/*!< The entropy callback function. */
|
||||
int(*MBEDTLS_PRIVATE(f_entropy))(void *, unsigned char *, size_t);
|
||||
/*!< The entropy callback function. */
|
||||
|
||||
void *MBEDTLS_PRIVATE(p_entropy); /*!< The context for the entropy function. */
|
||||
|
||||
@ -225,7 +224,7 @@ mbedtls_ctr_drbg_context;
|
||||
*
|
||||
* \param ctx The CTR_DRBG context to initialize.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
||||
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function seeds and sets up the CTR_DRBG
|
||||
@ -326,11 +325,11 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len );
|
||||
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function resets CTR_DRBG context to the state immediately
|
||||
@ -338,7 +337,7 @@ int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
|
||||
*
|
||||
* \param ctx The CTR_DRBG context to clear.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
|
||||
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function turns prediction resistance on or off.
|
||||
@ -353,8 +352,8 @@ void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
|
||||
int resistance );
|
||||
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx,
|
||||
int resistance);
|
||||
|
||||
/**
|
||||
* \brief This function sets the amount of entropy grabbed on each
|
||||
@ -380,8 +379,8 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
|
||||
* and at most the maximum length accepted by the
|
||||
* entropy function that is set in the context.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
|
||||
size_t len );
|
||||
void mbedtls_ctr_drbg_set_entropy_len(mbedtls_ctr_drbg_context *ctx,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function sets the amount of entropy grabbed
|
||||
@ -402,8 +401,8 @@ void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if the initial seeding has already taken place.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx,
|
||||
size_t len );
|
||||
int mbedtls_ctr_drbg_set_nonce_len(mbedtls_ctr_drbg_context *ctx,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function sets the reseed interval.
|
||||
@ -417,8 +416,8 @@ int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx,
|
||||
* \param ctx The CTR_DRBG context.
|
||||
* \param interval The reseed interval.
|
||||
*/
|
||||
void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
|
||||
int interval );
|
||||
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx,
|
||||
int interval);
|
||||
|
||||
/**
|
||||
* \brief This function reseeds the CTR_DRBG context, that is
|
||||
@ -440,8 +439,8 @@ void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t len );
|
||||
int mbedtls_ctr_drbg_reseed(mbedtls_ctr_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function updates the state of the CTR_DRBG context.
|
||||
@ -463,9 +462,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( 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
|
||||
@ -498,9 +497,9 @@ int mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
const unsigned char *additional, size_t add_len );
|
||||
int mbedtls_ctr_drbg_random_with_add(void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
const unsigned char *additional, size_t add_len);
|
||||
|
||||
/**
|
||||
* \brief This function uses CTR_DRBG to generate random data.
|
||||
@ -526,8 +525,8 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
|
||||
* #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_random( void *p_rng,
|
||||
unsigned char *output, size_t output_len );
|
||||
int mbedtls_ctr_drbg_random(void *p_rng,
|
||||
unsigned char *output, size_t output_len);
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
@ -541,7 +540,7 @@ int mbedtls_ctr_drbg_random( void *p_rng,
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on reseed
|
||||
* failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
|
||||
int mbedtls_ctr_drbg_write_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path);
|
||||
|
||||
/**
|
||||
* \brief This function reads and updates a seed file. The seed
|
||||
@ -557,7 +556,7 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char
|
||||
* \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if the existing
|
||||
* seed file is too large.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
|
||||
int mbedtls_ctr_drbg_update_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path);
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
@ -568,7 +567,7 @@ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_ctr_drbg_self_test( int verbose );
|
||||
int mbedtls_ctr_drbg_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -32,51 +32,51 @@
|
||||
|
||||
#if defined(MBEDTLS_DEBUG_C)
|
||||
|
||||
#define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
|
||||
#define MBEDTLS_DEBUG_STRIP_PARENS(...) __VA_ARGS__
|
||||
|
||||
#define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
|
||||
mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
|
||||
MBEDTLS_DEBUG_STRIP_PARENS args )
|
||||
#define MBEDTLS_SSL_DEBUG_MSG(level, args) \
|
||||
mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, \
|
||||
MBEDTLS_DEBUG_STRIP_PARENS args)
|
||||
|
||||
#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
|
||||
mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
|
||||
#define MBEDTLS_SSL_DEBUG_RET(level, text, ret) \
|
||||
mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret)
|
||||
|
||||
#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
|
||||
mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
|
||||
#define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) \
|
||||
mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len)
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
|
||||
mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
|
||||
#define MBEDTLS_SSL_DEBUG_MPI(level, text, X) \
|
||||
mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
|
||||
mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
|
||||
#define MBEDTLS_SSL_DEBUG_ECP(level, text, X) \
|
||||
mbedtls_debug_print_ecp(ssl, level, __FILE__, __LINE__, text, X)
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
|
||||
mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
|
||||
#define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) \
|
||||
mbedtls_debug_print_crt(ssl, level, __FILE__, __LINE__, text, crt)
|
||||
#else
|
||||
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0)
|
||||
#endif /* MBEDTLS_X509_REMOVE_INFO */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \
|
||||
mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr )
|
||||
#define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) \
|
||||
mbedtls_debug_printf_ecdh(ssl, level, __FILE__, __LINE__, ecdh, attr)
|
||||
#endif
|
||||
|
||||
#else /* MBEDTLS_DEBUG_C */
|
||||
|
||||
#define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 )
|
||||
#define MBEDTLS_SSL_DEBUG_MSG(level, args) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_RET(level, text, ret) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_MPI(level, text, X) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_ECP(level, text, X) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_CRT(level, text, crt) do { } while (0)
|
||||
#define MBEDTLS_SSL_DEBUG_ECDH(level, ecdh, attr) do { } while (0)
|
||||
|
||||
#endif /* MBEDTLS_DEBUG_C */
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
#if __has_attribute(format)
|
||||
#if defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((__format__ (gnu_printf, string_index, first_to_check)))
|
||||
__attribute__((__format__(gnu_printf, string_index, first_to_check)))
|
||||
#else /* defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 1 */
|
||||
#define MBEDTLS_PRINTF_ATTRIBUTE(string_index, first_to_check) \
|
||||
__attribute__((format(printf, string_index, first_to_check)))
|
||||
@ -124,10 +124,12 @@
|
||||
#include <inttypes.h>
|
||||
#define MBEDTLS_PRINTF_SIZET PRIuPTR
|
||||
#define MBEDTLS_PRINTF_LONGLONG "I64d"
|
||||
#else /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
#else \
|
||||
/* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
#define MBEDTLS_PRINTF_SIZET "zu"
|
||||
#define MBEDTLS_PRINTF_LONGLONG "lld"
|
||||
#endif /* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
#endif \
|
||||
/* (defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO == 0) || (defined(_MSC_VER) && _MSC_VER < 1800) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -148,7 +150,7 @@ extern "C" {
|
||||
* - 3 Informational
|
||||
* - 4 Verbose
|
||||
*/
|
||||
void mbedtls_debug_set_threshold( int threshold );
|
||||
void mbedtls_debug_set_threshold(int threshold);
|
||||
|
||||
/**
|
||||
* \brief Print a message to the debug output. This function is always used
|
||||
@ -165,9 +167,9 @@ void mbedtls_debug_set_threshold( int threshold );
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *format, ... ) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
|
||||
void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *format, ...) MBEDTLS_PRINTF_ATTRIBUTE(5, 6);
|
||||
|
||||
/**
|
||||
* \brief Print the return value of a function to the debug output. This
|
||||
@ -184,9 +186,9 @@ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, int ret );
|
||||
void mbedtls_debug_print_ret(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, int ret);
|
||||
|
||||
/**
|
||||
* \brief Output a buffer of size len bytes to the debug output. This function
|
||||
@ -205,9 +207,9 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line, const char *text,
|
||||
const unsigned char *buf, size_t len );
|
||||
void mbedtls_debug_print_buf(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line, const char *text,
|
||||
const unsigned char *buf, size_t len);
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
/**
|
||||
@ -226,9 +228,9 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_mpi *X );
|
||||
void mbedtls_debug_print_mpi(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_mpi *X);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
@ -248,9 +250,9 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_ecp_point *X );
|
||||
void mbedtls_debug_print_ecp(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_ecp_point *X);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||
@ -269,14 +271,13 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_x509_crt *crt );
|
||||
void mbedtls_debug_print_crt(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const char *text, const mbedtls_x509_crt *crt);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_ECDH_C)
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_DEBUG_ECDH_Q,
|
||||
MBEDTLS_DEBUG_ECDH_QP,
|
||||
MBEDTLS_DEBUG_ECDH_Z,
|
||||
@ -298,10 +299,10 @@ typedef enum
|
||||
* \attention This function is intended for INTERNAL usage within the
|
||||
* library only.
|
||||
*/
|
||||
void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const mbedtls_ecdh_context *ecdh,
|
||||
mbedtls_debug_ecdh_attr attr );
|
||||
void mbedtls_debug_printf_ecdh(const mbedtls_ssl_context *ssl, int level,
|
||||
const char *file, int line,
|
||||
const mbedtls_ecdh_context *ecdh,
|
||||
mbedtls_debug_ecdh_attr attr);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* \brief DES block cipher
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
@ -53,21 +53,23 @@ extern "C" {
|
||||
/**
|
||||
* \brief DES context structure
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
typedef struct mbedtls_des_context
|
||||
{
|
||||
typedef struct mbedtls_des_context {
|
||||
uint32_t MBEDTLS_PRIVATE(sk)[32]; /*!< DES subkeys */
|
||||
}
|
||||
mbedtls_des_context;
|
||||
|
||||
/**
|
||||
* \brief Triple-DES context structure
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
typedef struct mbedtls_des3_context
|
||||
{
|
||||
typedef struct mbedtls_des3_context {
|
||||
uint32_t MBEDTLS_PRIVATE(sk)[96]; /*!< 3DES subkeys */
|
||||
}
|
||||
mbedtls_des3_context;
|
||||
@ -81,36 +83,44 @@ mbedtls_des3_context;
|
||||
*
|
||||
* \param ctx DES context to be initialized
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des_init( mbedtls_des_context *ctx );
|
||||
void mbedtls_des_init(mbedtls_des_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Clear DES context
|
||||
*
|
||||
* \param ctx DES context to be cleared
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des_free( mbedtls_des_context *ctx );
|
||||
void mbedtls_des_free(mbedtls_des_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Initialize Triple-DES context
|
||||
*
|
||||
* \param ctx DES3 context to be initialized
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des3_init( mbedtls_des3_context *ctx );
|
||||
void mbedtls_des3_init(mbedtls_des3_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Clear Triple-DES context
|
||||
*
|
||||
* \param ctx DES3 context to be cleared
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des3_free( mbedtls_des3_context *ctx );
|
||||
void mbedtls_des3_free(mbedtls_des3_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Set key parity on the given key to odd.
|
||||
@ -120,11 +130,11 @@ void mbedtls_des3_free( mbedtls_des3_context *ctx );
|
||||
*
|
||||
* \param key 8-byte secret key
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* \brief Check that key parity on the given key is odd.
|
||||
@ -136,12 +146,12 @@ void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
*
|
||||
* \return 0 is parity was ok, 1 if parity was not correct.
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* \brief Check that key is not a weak or semi-weak DES key
|
||||
@ -150,12 +160,12 @@ int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SI
|
||||
*
|
||||
* \return 0 if no weak key was found, 1 if a weak key was identified.
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* \brief DES key schedule (56-bit, encryption)
|
||||
@ -165,12 +175,12 @@ int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* \brief DES key schedule (56-bit, decryption)
|
||||
@ -180,12 +190,12 @@ int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MB
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, encryption)
|
||||
@ -194,10 +204,14 @@ int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MB
|
||||
* \param key 16-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
|
||||
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, decryption)
|
||||
@ -206,10 +220,14 @@ int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
|
||||
* \param key 16-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
|
||||
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, encryption)
|
||||
@ -218,10 +236,14 @@ int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
|
||||
* \param key 24-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
|
||||
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, decryption)
|
||||
@ -230,10 +252,14 @@ int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
|
||||
* \param key 24-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
|
||||
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
||||
|
||||
/**
|
||||
* \brief DES-ECB block encryption/decryption
|
||||
@ -244,14 +270,14 @@ int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8]);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
@ -272,17 +298,17 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
|
||||
* \param input buffer holding the input data
|
||||
* \param output buffer holding the output data
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
/**
|
||||
@ -293,11 +319,15 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
* \param output 64-bit output block
|
||||
*
|
||||
* \return 0 if successful
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8] );
|
||||
int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx,
|
||||
const unsigned char input[8],
|
||||
unsigned char output[8]);
|
||||
|
||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||
/**
|
||||
@ -319,14 +349,18 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
|
||||
* \param output buffer holding the output data
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
|
||||
*
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||
int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
unsigned char iv[8],
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
/**
|
||||
@ -337,12 +371,12 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
* \param SK Round keys
|
||||
* \param key Base key
|
||||
*
|
||||
* \warning DES is considered a weak cipher and its use constitutes a
|
||||
* \warning DES/3DES are considered weak ciphers and their use constitutes a
|
||||
* security risk. We recommend considering stronger ciphers
|
||||
* instead.
|
||||
*/
|
||||
void mbedtls_des_setkey( uint32_t SK[32],
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
|
||||
void mbedtls_des_setkey(uint32_t SK[32],
|
||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
@ -352,7 +386,7 @@ void mbedtls_des_setkey( uint32_t SK[32],
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
MBEDTLS_CHECK_RETURN_CRITICAL
|
||||
int mbedtls_des_self_test( int verbose );
|
||||
int mbedtls_des_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -68,8 +68,7 @@ extern "C" {
|
||||
/**
|
||||
* Defines the source of the imported EC key.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_ECDH_OURS, /**< Our key. */
|
||||
MBEDTLS_ECDH_THEIRS, /**< The key of the peer. */
|
||||
} mbedtls_ecdh_side;
|
||||
@ -81,8 +80,7 @@ typedef enum
|
||||
* Later versions of the library may add new variants, therefore users should
|
||||
* not make any assumptions about them.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_ECDH_VARIANT_NONE = 0, /*!< Implementation not defined. */
|
||||
MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */
|
||||
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
|
||||
@ -97,8 +95,7 @@ typedef enum
|
||||
* should not make any assumptions about the structure of
|
||||
* mbedtls_ecdh_context_mbed.
|
||||
*/
|
||||
typedef struct mbedtls_ecdh_context_mbed
|
||||
{
|
||||
typedef struct mbedtls_ecdh_context_mbed {
|
||||
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. */
|
||||
@ -117,8 +114,7 @@ typedef struct mbedtls_ecdh_context_mbed
|
||||
* should not be shared between multiple threads.
|
||||
* \brief The ECDH context structure.
|
||||
*/
|
||||
typedef struct mbedtls_ecdh_context
|
||||
{
|
||||
typedef struct mbedtls_ecdh_context {
|
||||
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< The elliptic curve used. */
|
||||
mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< The private key. */
|
||||
@ -135,24 +131,23 @@ typedef struct mbedtls_ecdh_context
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
#else
|
||||
uint8_t MBEDTLS_PRIVATE(point_format); /*!< The format of point export in TLS messages
|
||||
as defined in RFC 4492. */
|
||||
as defined in RFC 4492. */
|
||||
mbedtls_ecp_group_id MBEDTLS_PRIVATE(grp_id);/*!< The elliptic curve used. */
|
||||
mbedtls_ecdh_variant MBEDTLS_PRIVATE(var); /*!< The ECDH implementation/structure used. */
|
||||
union
|
||||
{
|
||||
union {
|
||||
mbedtls_ecdh_context_mbed MBEDTLS_PRIVATE(mbed_ecdh);
|
||||
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
|
||||
mbedtls_ecdh_context_everest MBEDTLS_PRIVATE(everest_ecdh);
|
||||
#endif
|
||||
} MBEDTLS_PRIVATE(ctx); /*!< Implementation-specific context. The
|
||||
context in use is specified by the \c var
|
||||
field. */
|
||||
context in use is specified by the \c var
|
||||
field. */
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
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
|
||||
if this flag is set. */
|
||||
an alternative implementation not supporting
|
||||
restartable mode must return
|
||||
MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error
|
||||
if this flag is set. */
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
|
||||
}
|
||||
@ -165,7 +160,7 @@ mbedtls_ecdh_context;
|
||||
*
|
||||
* \return \c 1 if the group can be used, \c 0 otherwise
|
||||
*/
|
||||
int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
|
||||
int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid);
|
||||
|
||||
/**
|
||||
* \brief This function generates an ECDH keypair on an elliptic
|
||||
@ -192,9 +187,9 @@ int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX or
|
||||
* \c MBEDTLS_MPI_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdh_gen_public(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function computes the shared secret.
|
||||
@ -227,17 +222,17 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX or
|
||||
* \c MBEDTLS_MPI_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function initializes an ECDH context.
|
||||
*
|
||||
* \param ctx The ECDH context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
|
||||
void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function sets up the ECDH context with the information
|
||||
@ -255,8 +250,8 @@ void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx,
|
||||
mbedtls_ecp_group_id grp_id );
|
||||
int mbedtls_ecdh_setup(mbedtls_ecdh_context *ctx,
|
||||
mbedtls_ecp_group_id grp_id);
|
||||
|
||||
/**
|
||||
* \brief This function frees a context.
|
||||
@ -265,7 +260,7 @@ int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx,
|
||||
* case this function does nothing. If it is not \c NULL,
|
||||
* it must point to an initialized ECDH context.
|
||||
*/
|
||||
void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
|
||||
void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function generates an EC key pair and exports its
|
||||
@ -292,10 +287,10 @@ void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
|
||||
* operations was reached: see \c mbedtls_ecp_set_max_ops().
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdh_make_params(mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function parses the ECDHE parameters in a
|
||||
@ -321,9 +316,9 @@ int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
|
||||
const unsigned char **buf,
|
||||
const unsigned char *end );
|
||||
int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx,
|
||||
const unsigned char **buf,
|
||||
const unsigned char *end);
|
||||
|
||||
/**
|
||||
* \brief This function sets up an ECDH context from an EC key.
|
||||
@ -344,9 +339,9 @@ int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*
|
||||
*/
|
||||
int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
|
||||
const mbedtls_ecp_keypair *key,
|
||||
mbedtls_ecdh_side side );
|
||||
int mbedtls_ecdh_get_params(mbedtls_ecdh_context *ctx,
|
||||
const mbedtls_ecp_keypair *key,
|
||||
mbedtls_ecdh_side side);
|
||||
|
||||
/**
|
||||
* \brief This function generates a public key and exports it
|
||||
@ -374,10 +369,10 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
|
||||
* operations was reached: see \c mbedtls_ecp_set_max_ops().
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function parses and processes the ECDHE payload of a
|
||||
@ -398,8 +393,8 @@ int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
|
||||
const unsigned char *buf, size_t blen );
|
||||
int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx,
|
||||
const unsigned char *buf, size_t blen);
|
||||
|
||||
/**
|
||||
* \brief This function derives and exports the shared secret.
|
||||
@ -430,10 +425,10 @@ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
|
||||
* operations was reached: see \c mbedtls_ecp_set_max_ops().
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/**
|
||||
@ -448,7 +443,7 @@ int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
|
||||
*
|
||||
* \param ctx The ECDH context to use. This must be initialized.
|
||||
*/
|
||||
void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
|
||||
void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx);
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -53,13 +53,13 @@
|
||||
*
|
||||
* For each of r and s, the value (V) may include an extra initial "0" bit.
|
||||
*/
|
||||
#define MBEDTLS_ECDSA_MAX_SIG_LEN( bits ) \
|
||||
( /*T,L of SEQUENCE*/ ( ( bits ) >= 61 * 8 ? 3 : 2 ) + \
|
||||
/*T,L of r,s*/ 2 * ( ( ( bits ) >= 127 * 8 ? 3 : 2 ) + \
|
||||
/*V of r,s*/ ( ( bits ) + 8 ) / 8 ) )
|
||||
#define MBEDTLS_ECDSA_MAX_SIG_LEN(bits) \
|
||||
(/*T,L of SEQUENCE*/ ((bits) >= 61 * 8 ? 3 : 2) + \
|
||||
/*T,L of r,s*/ 2 * (((bits) >= 127 * 8 ? 3 : 2) + \
|
||||
/*V of r,s*/ ((bits) + 8) / 8))
|
||||
|
||||
/** The maximal size of an ECDSA signature in Bytes. */
|
||||
#define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN( MBEDTLS_ECP_MAX_BITS )
|
||||
#define MBEDTLS_ECDSA_MAX_LEN MBEDTLS_ECDSA_MAX_SIG_LEN(MBEDTLS_ECP_MAX_BITS)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -102,10 +102,9 @@ typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx;
|
||||
/**
|
||||
* \brief General context for resuming ECDSA operations
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
mbedtls_ecp_restart_ctx MBEDTLS_PRIVATE(ecp); /*!< base context for ECP restart and
|
||||
shared administrative info */
|
||||
shared administrative info */
|
||||
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)
|
||||
@ -128,7 +127,7 @@ typedef void mbedtls_ecdsa_restart_ctx;
|
||||
*
|
||||
* \return \c 1 if the group can be used, \c 0 otherwise
|
||||
*/
|
||||
int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
|
||||
int mbedtls_ecdsa_can_do(mbedtls_ecp_group_id gid);
|
||||
|
||||
/**
|
||||
* \brief This function computes the ECDSA signature of a
|
||||
@ -166,9 +165,9 @@ int mbedtls_ecdsa_can_do( mbedtls_ecp_group_id gid );
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX
|
||||
* or \c MBEDTLS_MPI_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
|
||||
|
||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
|
||||
/**
|
||||
@ -210,12 +209,12 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
|
||||
* error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
mbedtls_mpi *s, const mbedtls_mpi *d,
|
||||
const unsigned char *buf, size_t blen,
|
||||
mbedtls_md_type_t md_alg,
|
||||
int (*f_rng_blind)(void *, unsigned char *, size_t),
|
||||
void *p_rng_blind );
|
||||
int mbedtls_ecdsa_sign_det_ext(mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
mbedtls_mpi *s, const mbedtls_mpi *d,
|
||||
const unsigned char *buf, size_t blen,
|
||||
mbedtls_md_type_t md_alg,
|
||||
int (*f_rng_blind)(void *, unsigned char *, size_t),
|
||||
void *p_rng_blind);
|
||||
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
|
||||
/**
|
||||
@ -245,15 +244,13 @@ int mbedtls_ecdsa_sign_det_ext( mbedtls_ecp_group *grp, mbedtls_mpi *r,
|
||||
* This must be initialized.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the signature
|
||||
* is invalid.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
|
||||
* error code on failure for any other reason.
|
||||
* error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
|
||||
const unsigned char *buf, size_t blen,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
|
||||
const mbedtls_mpi *s);
|
||||
int mbedtls_ecdsa_verify(mbedtls_ecp_group *grp,
|
||||
const unsigned char *buf, size_t blen,
|
||||
const mbedtls_ecp_point *Q, const mbedtls_mpi *r,
|
||||
const mbedtls_mpi *s);
|
||||
|
||||
/**
|
||||
* \brief This function computes the ECDSA signature and writes it
|
||||
@ -304,12 +301,12 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
|
||||
* \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
|
||||
mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t sig_size, size_t *slen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecdsa_write_signature(mbedtls_ecdsa_context *ctx,
|
||||
mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t sig_size, size_t *slen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function computes the ECDSA signature and writes it
|
||||
@ -351,13 +348,13 @@ int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx,
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
|
||||
* \c MBEDTLS_ERR_ASN1_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t sig_size, size_t *slen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng,
|
||||
mbedtls_ecdsa_restart_ctx *rs_ctx );
|
||||
int mbedtls_ecdsa_write_signature_restartable(mbedtls_ecdsa_context *ctx,
|
||||
mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
unsigned char *sig, size_t sig_size, size_t *slen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng,
|
||||
mbedtls_ecdsa_restart_ctx *rs_ctx);
|
||||
|
||||
/**
|
||||
* \brief This function reads and verifies an ECDSA signature.
|
||||
@ -386,9 +383,9 @@ int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
|
||||
* error code on failure for any other reason.
|
||||
*/
|
||||
int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
const unsigned char *sig, size_t slen );
|
||||
int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
const unsigned char *sig, size_t slen);
|
||||
|
||||
/**
|
||||
* \brief This function reads and verifies an ECDSA signature,
|
||||
@ -421,10 +418,10 @@ int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
|
||||
* \return Another \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
|
||||
* error code on failure for any other reason.
|
||||
*/
|
||||
int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
const unsigned char *sig, size_t slen,
|
||||
mbedtls_ecdsa_restart_ctx *rs_ctx );
|
||||
int mbedtls_ecdsa_read_signature_restartable(mbedtls_ecdsa_context *ctx,
|
||||
const unsigned char *hash, size_t hlen,
|
||||
const unsigned char *sig, size_t slen,
|
||||
mbedtls_ecdsa_restart_ctx *rs_ctx);
|
||||
|
||||
/**
|
||||
* \brief This function generates an ECDSA keypair on the given curve.
|
||||
@ -442,8 +439,8 @@ int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx,
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
int mbedtls_ecdsa_genkey(mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function sets up an ECDSA context from an EC key pair.
|
||||
@ -460,8 +457,8 @@ int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX code on failure.
|
||||
*/
|
||||
int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,
|
||||
const mbedtls_ecp_keypair *key );
|
||||
int mbedtls_ecdsa_from_keypair(mbedtls_ecdsa_context *ctx,
|
||||
const mbedtls_ecp_keypair *key);
|
||||
|
||||
/**
|
||||
* \brief This function initializes an ECDSA context.
|
||||
@ -469,7 +466,7 @@ int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx,
|
||||
* \param ctx The ECDSA context to initialize.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
|
||||
void mbedtls_ecdsa_init(mbedtls_ecdsa_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function frees an ECDSA context.
|
||||
@ -478,7 +475,7 @@ void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
|
||||
* in which case this function does nothing. If it
|
||||
* is not \c NULL, it must be initialized.
|
||||
*/
|
||||
void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
|
||||
void mbedtls_ecdsa_free(mbedtls_ecdsa_context *ctx);
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/**
|
||||
@ -487,7 +484,7 @@ void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
|
||||
* \param ctx The restart context to initialize.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
|
||||
void mbedtls_ecdsa_restart_init(mbedtls_ecdsa_restart_ctx *ctx);
|
||||
|
||||
/**
|
||||
* \brief Free the components of a restart context.
|
||||
@ -496,7 +493,7 @@ void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx );
|
||||
* in which case this function does nothing. If it
|
||||
* is not \c NULL, it must be initialized.
|
||||
*/
|
||||
void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx );
|
||||
void mbedtls_ecdsa_restart_free(mbedtls_ecdsa_restart_ctx *ctx);
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -68,8 +68,7 @@ typedef enum {
|
||||
* convention from the Thread v1.0 spec. Correspondence is indicated in the
|
||||
* description as a pair C: client name, S: server name
|
||||
*/
|
||||
typedef struct mbedtls_ecjpake_context
|
||||
{
|
||||
typedef struct mbedtls_ecjpake_context {
|
||||
mbedtls_md_type_t MBEDTLS_PRIVATE(md_type); /**< Hash to use */
|
||||
mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /**< Elliptic curve */
|
||||
mbedtls_ecjpake_role MBEDTLS_PRIVATE(role); /**< Are we client or server? */
|
||||
@ -97,7 +96,7 @@ typedef struct mbedtls_ecjpake_context
|
||||
* \param ctx The ECJPAKE context to initialize.
|
||||
* This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
|
||||
void mbedtls_ecjpake_init(mbedtls_ecjpake_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Set up an ECJPAKE context for use.
|
||||
@ -113,19 +112,19 @@ void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
|
||||
* \param curve The identifier of the elliptic curve to use,
|
||||
* for example #MBEDTLS_ECP_DP_SECP256R1.
|
||||
* \param secret The pre-shared secret (passphrase). This must be
|
||||
* a readable buffer of length \p len Bytes. It need
|
||||
* a readable not empty buffer of length \p len Bytes. It need
|
||||
* only be valid for the duration of this call.
|
||||
* \param len The length of the pre-shared secret \p secret.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
|
||||
mbedtls_ecjpake_role role,
|
||||
mbedtls_md_type_t hash,
|
||||
mbedtls_ecp_group_id curve,
|
||||
const unsigned char *secret,
|
||||
size_t len );
|
||||
int mbedtls_ecjpake_setup(mbedtls_ecjpake_context *ctx,
|
||||
mbedtls_ecjpake_role role,
|
||||
mbedtls_md_type_t hash,
|
||||
mbedtls_ecp_group_id curve,
|
||||
const unsigned char *secret,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief Set the point format for future reads and writes.
|
||||
@ -139,8 +138,8 @@ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
|
||||
* \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 );
|
||||
int mbedtls_ecjpake_set_point_format(mbedtls_ecjpake_context *ctx,
|
||||
int point_format);
|
||||
|
||||
/**
|
||||
* \brief Check if an ECJPAKE context is ready for use.
|
||||
@ -151,7 +150,7 @@ int mbedtls_ecjpake_set_point_format( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if the context is ready for use.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise.
|
||||
*/
|
||||
int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
|
||||
int mbedtls_ecjpake_check(const mbedtls_ecjpake_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Generate and write the first round message
|
||||
@ -172,10 +171,10 @@ int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief Read and process the first round message
|
||||
@ -191,9 +190,9 @@ int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
|
||||
const unsigned char *buf,
|
||||
size_t len );
|
||||
int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context *ctx,
|
||||
const unsigned char *buf,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief Generate and write the second round message
|
||||
@ -213,10 +212,10 @@ int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief Read and process the second round message
|
||||
@ -231,9 +230,9 @@ int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
|
||||
const unsigned char *buf,
|
||||
size_t len );
|
||||
int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context *ctx,
|
||||
const unsigned char *buf,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief Derive the shared secret
|
||||
@ -253,10 +252,10 @@ int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief Write the shared key material to be passed to a Key
|
||||
@ -276,10 +275,10 @@ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
|
||||
* \return \c 0 if successful.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecjpake_write_shared_key( mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecjpake_write_shared_key(mbedtls_ecjpake_context *ctx,
|
||||
unsigned char *buf, size_t len, size_t *olen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This clears an ECJPAKE context and frees any
|
||||
@ -289,7 +288,7 @@ int mbedtls_ecjpake_write_shared_key( mbedtls_ecjpake_context *ctx,
|
||||
* in which case this function does nothing. If it is not
|
||||
* \c NULL, it must point to an initialized ECJPAKE context.
|
||||
*/
|
||||
void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
|
||||
void mbedtls_ecjpake_free(mbedtls_ecjpake_context *ctx);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
@ -298,7 +297,7 @@ void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_ecjpake_self_test( int verbose );
|
||||
int mbedtls_ecjpake_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -110,8 +110,7 @@ extern "C" {
|
||||
* - Add the curve to applicable profiles in x509_crt.c.
|
||||
* - Add the curve to applicable presets in ssl_tls.c.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */
|
||||
MBEDTLS_ECP_DP_SECP192R1, /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */
|
||||
MBEDTLS_ECP_DP_SECP224R1, /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */
|
||||
@ -136,8 +135,7 @@ typedef enum
|
||||
/*
|
||||
* Curve types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
MBEDTLS_ECP_TYPE_NONE = 0,
|
||||
MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS, /* y^2 = x^3 + a x + b */
|
||||
MBEDTLS_ECP_TYPE_MONTGOMERY, /* y^2 = x^3 + a x^2 + x */
|
||||
@ -150,8 +148,7 @@ typedef enum
|
||||
* accessed directly by applications. Future versions of the library may
|
||||
* add extra fields or reorder existing fields.
|
||||
*/
|
||||
typedef struct mbedtls_ecp_curve_info
|
||||
{
|
||||
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. */
|
||||
@ -169,8 +166,7 @@ typedef struct mbedtls_ecp_curve_info
|
||||
* Otherwise, \p X and \p Y are its standard (affine)
|
||||
* coordinates.
|
||||
*/
|
||||
typedef struct mbedtls_ecp_point
|
||||
{
|
||||
typedef struct mbedtls_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. */
|
||||
@ -224,8 +220,7 @@ mbedtls_ecp_point;
|
||||
* 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
|
||||
{
|
||||
typedef struct mbedtls_ecp_group {
|
||||
mbedtls_ecp_group_id id; /*!< An internal group identifier. */
|
||||
mbedtls_mpi P; /*!< The prime modulus of the base field. */
|
||||
mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. For
|
||||
@ -241,10 +236,10 @@ typedef struct mbedtls_ecp_group
|
||||
/* 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 (*MBEDTLS_PRIVATE(t_pre))(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
int (*MBEDTLS_PRIVATE(t_post))(mbedtls_ecp_point *, void *); /*!< Unused. */
|
||||
int(*MBEDTLS_PRIVATE(modp))(mbedtls_mpi *); /*!< The function for fast pseudo-reduction
|
||||
mod \p P (see above).*/
|
||||
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. */
|
||||
@ -343,8 +338,8 @@ mbedtls_ecp_group;
|
||||
#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 )
|
||||
#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)
|
||||
|
||||
@ -365,8 +360,7 @@ typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx;
|
||||
/**
|
||||
* \brief General context for resuming ECC operations
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
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 */
|
||||
@ -392,18 +386,18 @@ typedef struct
|
||||
* \return \c 0 if doing \p ops basic ops is still allowed,
|
||||
* \return #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise.
|
||||
*/
|
||||
int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx,
|
||||
unsigned ops );
|
||||
int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx,
|
||||
unsigned ops);
|
||||
|
||||
/* Utility macro for checking and updating ops budget */
|
||||
#define MBEDTLS_ECP_BUDGET( ops ) \
|
||||
MBEDTLS_MPI_CHK( mbedtls_ecp_check_budget( grp, rs_ctx, \
|
||||
(unsigned) (ops) ) );
|
||||
#define MBEDTLS_ECP_BUDGET(ops) \
|
||||
MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \
|
||||
(unsigned) (ops)));
|
||||
|
||||
#else /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
#define MBEDTLS_ECP_BUDGET( ops ) /* no-op; for compatibility */
|
||||
#define MBEDTLS_ECP_BUDGET(ops) /* no-op; for compatibility */
|
||||
|
||||
/* We want to declare restartable versions of existing functions anyway */
|
||||
typedef void mbedtls_ecp_restart_ctx;
|
||||
@ -418,8 +412,7 @@ typedef void mbedtls_ecp_restart_ctx;
|
||||
* \note Members are deliberately in the same order as in the
|
||||
* ::mbedtls_ecdsa_context structure.
|
||||
*/
|
||||
typedef struct mbedtls_ecp_keypair
|
||||
{
|
||||
typedef struct mbedtls_ecp_keypair {
|
||||
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 */
|
||||
@ -495,7 +488,7 @@ mbedtls_ecp_keypair;
|
||||
*
|
||||
* \note This setting is currently ignored by Curve25519.
|
||||
*/
|
||||
void mbedtls_ecp_set_max_ops( unsigned max_ops );
|
||||
void mbedtls_ecp_set_max_ops(unsigned max_ops);
|
||||
|
||||
/**
|
||||
* \brief Check if restart is enabled (max_ops != 0)
|
||||
@ -503,13 +496,13 @@ void mbedtls_ecp_set_max_ops( unsigned max_ops );
|
||||
* \return \c 0 if \c max_ops == 0 (restart disabled)
|
||||
* \return \c 1 otherwise (restart enabled)
|
||||
*/
|
||||
int mbedtls_ecp_restart_is_enabled( void );
|
||||
int mbedtls_ecp_restart_is_enabled(void);
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
/*
|
||||
* Get the type of a curve
|
||||
*/
|
||||
mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp );
|
||||
mbedtls_ecp_curve_type mbedtls_ecp_get_type(const mbedtls_ecp_group *grp);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the information defined in
|
||||
@ -523,7 +516,7 @@ mbedtls_ecp_curve_type mbedtls_ecp_get_type( const mbedtls_ecp_group *grp );
|
||||
*
|
||||
* \return A statically allocated array. The last entry is 0.
|
||||
*/
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list(void);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves the list of internal group
|
||||
@ -539,7 +532,7 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
|
||||
* \return A statically allocated array,
|
||||
* terminated with MBEDTLS_ECP_DP_NONE.
|
||||
*/
|
||||
const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
|
||||
const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list(void);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves curve information from an internal
|
||||
@ -550,7 +543,7 @@ const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
|
||||
* \return The associated curve information on success.
|
||||
* \return NULL on failure.
|
||||
*/
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id );
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves curve information from a TLS
|
||||
@ -561,7 +554,7 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_gr
|
||||
* \return The associated curve information on success.
|
||||
* \return NULL on failure.
|
||||
*/
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id);
|
||||
|
||||
/**
|
||||
* \brief This function retrieves curve information from a
|
||||
@ -572,14 +565,14 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_i
|
||||
* \return The associated curve information on success.
|
||||
* \return NULL on failure.
|
||||
*/
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
|
||||
const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name(const char *name);
|
||||
|
||||
/**
|
||||
* \brief This function initializes a point as zero.
|
||||
*
|
||||
* \param pt The point to initialize.
|
||||
*/
|
||||
void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
|
||||
void mbedtls_ecp_point_init(mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function initializes an ECP group context
|
||||
@ -590,21 +583,21 @@ void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
|
||||
* mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group()
|
||||
* functions.
|
||||
*/
|
||||
void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
|
||||
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp);
|
||||
|
||||
/**
|
||||
* \brief This function initializes a key pair as an invalid one.
|
||||
*
|
||||
* \param key The key pair to initialize.
|
||||
*/
|
||||
void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
|
||||
void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key);
|
||||
|
||||
/**
|
||||
* \brief This function frees the components of a point.
|
||||
*
|
||||
* \param pt The point to free.
|
||||
*/
|
||||
void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
|
||||
void mbedtls_ecp_point_free(mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function frees the components of an ECP group.
|
||||
@ -613,7 +606,7 @@ void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
|
||||
* case this function returns immediately. If it is not
|
||||
* \c NULL, it must point to an initialized ECP group.
|
||||
*/
|
||||
void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
|
||||
void mbedtls_ecp_group_free(mbedtls_ecp_group *grp);
|
||||
|
||||
/**
|
||||
* \brief This function frees the components of a key pair.
|
||||
@ -622,7 +615,7 @@ void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
|
||||
* case this function returns immediately. If it is not
|
||||
* \c NULL, it must point to an initialized ECP key pair.
|
||||
*/
|
||||
void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
|
||||
void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key);
|
||||
|
||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
/**
|
||||
@ -631,7 +624,7 @@ void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
|
||||
* \param ctx The restart context to initialize. This must
|
||||
* not be \c NULL.
|
||||
*/
|
||||
void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx );
|
||||
void mbedtls_ecp_restart_init(mbedtls_ecp_restart_ctx *ctx);
|
||||
|
||||
/**
|
||||
* \brief Free the components of a restart context.
|
||||
@ -640,7 +633,7 @@ void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx );
|
||||
* case this function returns immediately. If it is not
|
||||
* \c NULL, it must point to an initialized restart context.
|
||||
*/
|
||||
void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx );
|
||||
void mbedtls_ecp_restart_free(mbedtls_ecp_restart_ctx *ctx);
|
||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||
|
||||
/**
|
||||
@ -654,7 +647,7 @@ void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
|
||||
* \return Another negative error code for other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
|
||||
int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q);
|
||||
|
||||
/**
|
||||
* \brief This function copies the contents of group \p src into
|
||||
@ -667,8 +660,8 @@ int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst,
|
||||
const mbedtls_ecp_group *src );
|
||||
int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst,
|
||||
const mbedtls_ecp_group *src);
|
||||
|
||||
/**
|
||||
* \brief This function sets a point to the point at infinity.
|
||||
@ -679,7 +672,7 @@ int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
|
||||
int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function checks if a point is the point at infinity.
|
||||
@ -690,7 +683,7 @@ int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
|
||||
* \return \c 0 if the point is non-zero.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
|
||||
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function compares two points.
|
||||
@ -704,8 +697,8 @@ int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
|
||||
* \return \c 0 if the points are equal.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal.
|
||||
*/
|
||||
int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
|
||||
const mbedtls_ecp_point *Q );
|
||||
int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P,
|
||||
const mbedtls_ecp_point *Q);
|
||||
|
||||
/**
|
||||
* \brief This function imports a non-zero point from two ASCII
|
||||
@ -719,8 +712,8 @@ int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
|
||||
* \return \c 0 on success.
|
||||
* \return An \c MBEDTLS_ERR_MPI_XXX error code on failure.
|
||||
*/
|
||||
int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
|
||||
const char *x, const char *y );
|
||||
int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix,
|
||||
const char *x, const char *y);
|
||||
|
||||
/**
|
||||
* \brief This function exports a point into unsigned binary data.
|
||||
@ -747,10 +740,10 @@ int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
|
||||
* or the export for the given group is not implemented.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *P,
|
||||
int format, size_t *olen,
|
||||
unsigned char *buf, size_t buflen );
|
||||
int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *P,
|
||||
int format, size_t *olen,
|
||||
unsigned char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief This function imports a point from unsigned binary data.
|
||||
@ -774,9 +767,9 @@ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp,
|
||||
* \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the import for the
|
||||
* given group is not implemented.
|
||||
*/
|
||||
int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *P,
|
||||
const unsigned char *buf, size_t ilen );
|
||||
int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *P,
|
||||
const unsigned char *buf, size_t ilen);
|
||||
|
||||
/**
|
||||
* \brief This function imports a point from a TLS ECPoint record.
|
||||
@ -796,9 +789,9 @@ int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp,
|
||||
* failure.
|
||||
* \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid.
|
||||
*/
|
||||
int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *pt,
|
||||
const unsigned char **buf, size_t len );
|
||||
int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp,
|
||||
mbedtls_ecp_point *pt,
|
||||
const unsigned char **buf, size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function exports a point as a TLS ECPoint record
|
||||
@ -822,10 +815,10 @@ int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp,
|
||||
* is too small to hold the exported point.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *pt,
|
||||
int format, size_t *olen,
|
||||
unsigned char *buf, size_t blen );
|
||||
int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *pt,
|
||||
int format, size_t *olen,
|
||||
unsigned char *buf, size_t blen);
|
||||
|
||||
/**
|
||||
* \brief This function sets up an ECP group context
|
||||
@ -844,7 +837,7 @@ int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp,
|
||||
* correspond to a known group.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
|
||||
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id);
|
||||
|
||||
/**
|
||||
* \brief This function sets up an ECP group context from a TLS
|
||||
@ -863,8 +856,8 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
|
||||
* recognized.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp,
|
||||
const unsigned char **buf, size_t len );
|
||||
int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp,
|
||||
const unsigned char **buf, size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function extracts an elliptic curve group ID from a
|
||||
@ -884,9 +877,9 @@ int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp,
|
||||
* recognized.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp,
|
||||
const unsigned char **buf,
|
||||
size_t len );
|
||||
int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp,
|
||||
const unsigned char **buf,
|
||||
size_t len);
|
||||
/**
|
||||
* \brief This function exports an elliptic curve as a TLS
|
||||
* ECParameters record as defined in RFC 4492, Section 5.4.
|
||||
@ -905,9 +898,9 @@ int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp,
|
||||
* buffer is too small to hold the exported group.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
|
||||
size_t *olen,
|
||||
unsigned char *buf, size_t blen );
|
||||
int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp,
|
||||
size_t *olen,
|
||||
unsigned char *buf, size_t blen);
|
||||
|
||||
/**
|
||||
* \brief This function performs a scalar multiplication of a point
|
||||
@ -938,9 +931,9 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp,
|
||||
* \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||
int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function performs multiplication of a point by
|
||||
@ -972,10 +965,10 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
* operations was reached: see \c mbedtls_ecp_set_max_ops().
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx );
|
||||
int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx);
|
||||
|
||||
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
|
||||
/**
|
||||
@ -1013,9 +1006,9 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
* designate a short Weierstrass curve.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
|
||||
int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q);
|
||||
|
||||
/**
|
||||
* \brief This function performs multiplication and addition of two
|
||||
@ -1058,10 +1051,10 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_muladd_restartable(
|
||||
mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx );
|
||||
mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
|
||||
mbedtls_ecp_restart_ctx *rs_ctx);
|
||||
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
|
||||
|
||||
/**
|
||||
@ -1091,8 +1084,8 @@ int mbedtls_ecp_muladd_restartable(
|
||||
* a valid public key for the given curve.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *pt );
|
||||
int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *pt);
|
||||
|
||||
/**
|
||||
* \brief This function checks that an \p mbedtls_mpi is a
|
||||
@ -1113,8 +1106,8 @@ int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp,
|
||||
* private key for the given curve.
|
||||
* \return Another negative error code on other kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp,
|
||||
const mbedtls_mpi *d );
|
||||
int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp,
|
||||
const mbedtls_mpi *d);
|
||||
|
||||
/**
|
||||
* \brief This function generates a private key.
|
||||
@ -1131,10 +1124,10 @@ int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
|
||||
* on failure.
|
||||
*/
|
||||
int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
|
||||
mbedtls_mpi *d,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp,
|
||||
mbedtls_mpi *d,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function generates a keypair with a configurable base
|
||||
@ -1163,11 +1156,11 @@ int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
|
||||
* on failure.
|
||||
*/
|
||||
int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *G,
|
||||
mbedtls_mpi *d, mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp,
|
||||
const mbedtls_ecp_point *G,
|
||||
mbedtls_mpi *d, mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function generates an ECP keypair.
|
||||
@ -1192,10 +1185,10 @@ int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
|
||||
* on failure.
|
||||
*/
|
||||
int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d,
|
||||
mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, mbedtls_mpi *d,
|
||||
mbedtls_ecp_point *Q,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function generates an ECP key.
|
||||
@ -1210,9 +1203,9 @@ int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d,
|
||||
* \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code
|
||||
* on failure.
|
||||
*/
|
||||
int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function reads an elliptic curve private key.
|
||||
@ -1232,8 +1225,8 @@ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
* the group is not implemented.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
const unsigned char *buf, size_t buflen );
|
||||
int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
const unsigned char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief This function exports an elliptic curve private key.
|
||||
@ -1251,8 +1244,8 @@ int mbedtls_ecp_read_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
|
||||
* the group is not implemented.
|
||||
* \return Another negative error code on different kinds of failure.
|
||||
*/
|
||||
int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
|
||||
unsigned char *buf, size_t buflen );
|
||||
int mbedtls_ecp_write_key(mbedtls_ecp_keypair *key,
|
||||
unsigned char *buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief This function checks that the keypair objects
|
||||
@ -1275,8 +1268,8 @@ int mbedtls_ecp_write_key( mbedtls_ecp_keypair *key,
|
||||
* error code on calculation failure.
|
||||
*/
|
||||
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 );
|
||||
const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
|
||||
|
||||
/**
|
||||
* \brief This function exports generic key-pair parameters.
|
||||
@ -1306,7 +1299,7 @@ int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp,
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_ecp_self_test( int verbose );
|
||||
int mbedtls_ecp_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -99,15 +99,14 @@ extern "C" {
|
||||
* MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise
|
||||
*/
|
||||
typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
|
||||
size_t *olen);
|
||||
size_t *olen);
|
||||
|
||||
/**
|
||||
* \brief Entropy source state
|
||||
*/
|
||||
typedef struct mbedtls_entropy_source_state
|
||||
{
|
||||
typedef struct mbedtls_entropy_source_state {
|
||||
mbedtls_entropy_f_source_ptr MBEDTLS_PRIVATE(f_source); /**< The entropy source callback */
|
||||
void * MBEDTLS_PRIVATE(p_source); /**< The callback data pointer */
|
||||
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? */
|
||||
@ -117,11 +116,10 @@ mbedtls_entropy_source_state;
|
||||
/**
|
||||
* \brief Entropy context structure
|
||||
*/
|
||||
typedef struct mbedtls_entropy_context
|
||||
{
|
||||
typedef struct mbedtls_entropy_context {
|
||||
int MBEDTLS_PRIVATE(accumulator_started); /* 0 after init.
|
||||
* 1 after the first update.
|
||||
* -1 after free. */
|
||||
* 1 after the first update.
|
||||
* -1 after free. */
|
||||
#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
|
||||
mbedtls_sha512_context MBEDTLS_PRIVATE(accumulator);
|
||||
#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
|
||||
@ -142,8 +140,8 @@ mbedtls_entropy_context;
|
||||
/**
|
||||
* \brief Platform-specific entropy poll callback
|
||||
*/
|
||||
int mbedtls_platform_entropy_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen );
|
||||
int mbedtls_platform_entropy_poll(void *data,
|
||||
unsigned char *output, size_t len, size_t *olen);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -151,14 +149,14 @@ int mbedtls_platform_entropy_poll( void *data,
|
||||
*
|
||||
* \param ctx Entropy context to initialize
|
||||
*/
|
||||
void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
|
||||
void mbedtls_entropy_init(mbedtls_entropy_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Free the data in the context
|
||||
*
|
||||
* \param ctx Entropy context to free
|
||||
*/
|
||||
void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
|
||||
void mbedtls_entropy_free(mbedtls_entropy_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Adds an entropy source to poll
|
||||
@ -177,9 +175,9 @@ void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
|
||||
*
|
||||
* \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES
|
||||
*/
|
||||
int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
|
||||
mbedtls_entropy_f_source_ptr f_source, void *p_source,
|
||||
size_t threshold, int strong );
|
||||
int mbedtls_entropy_add_source(mbedtls_entropy_context *ctx,
|
||||
mbedtls_entropy_f_source_ptr f_source, void *p_source,
|
||||
size_t threshold, int strong);
|
||||
|
||||
/**
|
||||
* \brief Trigger an extra gather poll for the accumulator
|
||||
@ -189,7 +187,7 @@ int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
|
||||
*/
|
||||
int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
|
||||
int mbedtls_entropy_gather(mbedtls_entropy_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief Retrieve entropy from the accumulator
|
||||
@ -202,7 +200,7 @@ int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
|
||||
*
|
||||
* \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
|
||||
*/
|
||||
int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
|
||||
int mbedtls_entropy_func(void *data, unsigned char *output, size_t len);
|
||||
|
||||
/**
|
||||
* \brief Add data to the accumulator manually
|
||||
@ -214,8 +212,8 @@ int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
|
||||
const unsigned char *data, size_t len );
|
||||
int mbedtls_entropy_update_manual(mbedtls_entropy_context *ctx,
|
||||
const unsigned char *data, size_t len);
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_NV_SEED)
|
||||
/**
|
||||
@ -226,7 +224,7 @@ int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
|
||||
int mbedtls_entropy_update_nv_seed(mbedtls_entropy_context *ctx);
|
||||
#endif /* MBEDTLS_ENTROPY_NV_SEED */
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
@ -240,7 +238,7 @@ int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
|
||||
* MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, or
|
||||
* MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
|
||||
*/
|
||||
int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
|
||||
int mbedtls_entropy_write_seed_file(mbedtls_entropy_context *ctx, const char *path);
|
||||
|
||||
/**
|
||||
* \brief Read and update a seed file. Seed is added to this
|
||||
@ -254,7 +252,7 @@ int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *p
|
||||
* MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error,
|
||||
* MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
|
||||
*/
|
||||
int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
|
||||
int mbedtls_entropy_update_seed_file(mbedtls_entropy_context *ctx, const char *path);
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
@ -266,7 +264,7 @@ int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_entropy_self_test( int verbose );
|
||||
int mbedtls_entropy_self_test(int verbose);
|
||||
|
||||
#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
|
||||
/**
|
||||
@ -282,7 +280,7 @@ int mbedtls_entropy_self_test( int verbose );
|
||||
*
|
||||
* \return 0 if successful, or 1 if a test failed
|
||||
*/
|
||||
int mbedtls_entropy_source_self_test( int verbose );
|
||||
int mbedtls_entropy_source_self_test(int verbose);
|
||||
#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -26,11 +26,6 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Error code layout.
|
||||
*
|
||||
@ -83,6 +78,7 @@
|
||||
* POLY1305 3 0x0057-0x005B
|
||||
* CHACHAPOLY 2 0x0054-0x0056
|
||||
* PLATFORM 2 0x0070-0x0072
|
||||
* LMS 5 0x0011-0x0019
|
||||
*
|
||||
* High-level module nr (3 bits - 0x0...-0x7...)
|
||||
* Name ID Nr of Errors
|
||||
@ -96,6 +92,7 @@
|
||||
* ECP 4 10 (Started from top)
|
||||
* MD 5 5
|
||||
* HKDF 5 1 (Started from top)
|
||||
* PKCS7 5 12 (Started from 0x5300)
|
||||
* SSL 5 2 (Started from 0x5F00)
|
||||
* CIPHER 6 8 (Started from 0x6080)
|
||||
* SSL 6 22 (Started from top, plus 0x6000)
|
||||
@ -125,15 +122,15 @@ extern "C" {
|
||||
* Wrapper macro for mbedtls_error_add(). See that function for
|
||||
* more details.
|
||||
*/
|
||||
#define MBEDTLS_ERROR_ADD( high, low ) \
|
||||
mbedtls_error_add( high, low, __FILE__, __LINE__ )
|
||||
#define MBEDTLS_ERROR_ADD(high, low) \
|
||||
mbedtls_error_add(high, low, __FILE__, __LINE__)
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
/**
|
||||
* \brief Testing hook called before adding/combining two error codes together.
|
||||
* Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS.
|
||||
*/
|
||||
extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
|
||||
extern void (*mbedtls_test_hook_error_add)(int, int, const char *, int);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -154,17 +151,18 @@ extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int );
|
||||
* \param file file where this error code addition occurred.
|
||||
* \param line line where this error code addition occurred.
|
||||
*/
|
||||
static inline int mbedtls_error_add( int high, int low,
|
||||
const char *file, int line )
|
||||
static inline int mbedtls_error_add(int high, int low,
|
||||
const char *file, int line)
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
if( *mbedtls_test_hook_error_add != NULL )
|
||||
( *mbedtls_test_hook_error_add )( high, low, file, line );
|
||||
if (*mbedtls_test_hook_error_add != NULL) {
|
||||
(*mbedtls_test_hook_error_add)(high, low, file, line);
|
||||
}
|
||||
#endif
|
||||
(void)file;
|
||||
(void)line;
|
||||
(void) file;
|
||||
(void) line;
|
||||
|
||||
return( high + low );
|
||||
return high + low;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +174,7 @@ static inline int mbedtls_error_add( int high, int low,
|
||||
* \param buffer buffer to place representation in
|
||||
* \param buflen length of the buffer
|
||||
*/
|
||||
void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
|
||||
void mbedtls_strerror(int errnum, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* \brief Translate the high-level part of an Mbed TLS error code into a string
|
||||
@ -191,7 +189,7 @@ void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
|
||||
* \return The string representation of the error code, or \c NULL if the error
|
||||
* code is unknown.
|
||||
*/
|
||||
const char * mbedtls_high_level_strerr( int error_code );
|
||||
const char *mbedtls_high_level_strerr(int error_code);
|
||||
|
||||
/**
|
||||
* \brief Translate the low-level part of an Mbed TLS error code into a string
|
||||
@ -206,7 +204,7 @@ const char * mbedtls_high_level_strerr( int error_code );
|
||||
* \return The string representation of the error code, or \c NULL if the error
|
||||
* code is unknown.
|
||||
*/
|
||||
const char * mbedtls_low_level_strerr( int error_code );
|
||||
const char *mbedtls_low_level_strerr(int error_code);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ extern "C" {
|
||||
/**
|
||||
* \brief The GCM context structure.
|
||||
*/
|
||||
typedef struct mbedtls_gcm_context
|
||||
{
|
||||
typedef struct mbedtls_gcm_context {
|
||||
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. */
|
||||
@ -68,8 +67,8 @@ typedef struct mbedtls_gcm_context
|
||||
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. */
|
||||
#MBEDTLS_GCM_ENCRYPT or
|
||||
#MBEDTLS_GCM_DECRYPT. */
|
||||
}
|
||||
mbedtls_gcm_context;
|
||||
|
||||
@ -88,7 +87,7 @@ mbedtls_gcm_context;
|
||||
*
|
||||
* \param ctx The GCM context to initialize. This must not be \c NULL.
|
||||
*/
|
||||
void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
|
||||
void mbedtls_gcm_init(mbedtls_gcm_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief This function associates a GCM context with a
|
||||
@ -106,10 +105,10 @@ void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return A cipher-specific error code on failure.
|
||||
*/
|
||||
int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
|
||||
mbedtls_cipher_id_t cipher,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits );
|
||||
int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx,
|
||||
mbedtls_cipher_id_t cipher,
|
||||
const unsigned char *key,
|
||||
unsigned int keybits);
|
||||
|
||||
/**
|
||||
* \brief This function performs GCM encryption or decryption of a buffer.
|
||||
@ -162,17 +161,17 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
|
||||
* not valid or a cipher-specific error code if the encryption
|
||||
* or decryption failed.
|
||||
*/
|
||||
int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len,
|
||||
const unsigned char *add,
|
||||
size_t add_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
size_t tag_len,
|
||||
unsigned char *tag );
|
||||
int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx,
|
||||
int mode,
|
||||
size_t length,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len,
|
||||
const unsigned char *add,
|
||||
size_t add_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output,
|
||||
size_t tag_len,
|
||||
unsigned char *tag);
|
||||
|
||||
/**
|
||||
* \brief This function performs a GCM authenticated decryption of a
|
||||
@ -207,16 +206,16 @@ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
|
||||
* not valid or a cipher-specific error code if the decryption
|
||||
* failed.
|
||||
*/
|
||||
int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len,
|
||||
const unsigned char *add,
|
||||
size_t add_len,
|
||||
const unsigned char *tag,
|
||||
size_t tag_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output );
|
||||
int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx,
|
||||
size_t length,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len,
|
||||
const unsigned char *add,
|
||||
size_t add_len,
|
||||
const unsigned char *tag,
|
||||
size_t tag_len,
|
||||
const unsigned char *input,
|
||||
unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief This function starts a GCM encryption or decryption
|
||||
@ -231,10 +230,10 @@ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
|
||||
int mode,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len );
|
||||
int mbedtls_gcm_starts(mbedtls_gcm_context *ctx,
|
||||
int mode,
|
||||
const unsigned char *iv,
|
||||
size_t iv_len);
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer as associated data
|
||||
@ -256,9 +255,9 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx,
|
||||
const unsigned char *add,
|
||||
size_t add_len );
|
||||
int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx,
|
||||
const unsigned char *add,
|
||||
size_t add_len);
|
||||
|
||||
/**
|
||||
* \brief This function feeds an input buffer into an ongoing GCM
|
||||
@ -311,10 +310,10 @@ int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx,
|
||||
* unsupported input/output buffer overlap detected,
|
||||
* or \p output_size too small.
|
||||
*/
|
||||
int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
|
||||
const unsigned char *input, size_t input_length,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_length );
|
||||
int mbedtls_gcm_update(mbedtls_gcm_context *ctx,
|
||||
const unsigned char *input, size_t input_length,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_length);
|
||||
|
||||
/**
|
||||
* \brief This function finishes the GCM operation and generates
|
||||
@ -349,10 +348,10 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
|
||||
* invalid value of \p tag_len,
|
||||
* or \p output_size too small.
|
||||
*/
|
||||
int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_length,
|
||||
unsigned char *tag, size_t tag_len );
|
||||
int mbedtls_gcm_finish(mbedtls_gcm_context *ctx,
|
||||
unsigned char *output, size_t output_size,
|
||||
size_t *output_length,
|
||||
unsigned char *tag, size_t tag_len);
|
||||
|
||||
/**
|
||||
* \brief This function clears a GCM context and the underlying
|
||||
@ -361,7 +360,7 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
|
||||
* \param ctx The GCM context to clear. If this is \c NULL, the call has
|
||||
* no effect. Otherwise, this must be initialized.
|
||||
*/
|
||||
void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
|
||||
void mbedtls_gcm_free(mbedtls_gcm_context *ctx);
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
@ -371,7 +370,7 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
|
||||
* \return \c 0 on success.
|
||||
* \return \c 1 on failure.
|
||||
*/
|
||||
int mbedtls_gcm_self_test( int verbose );
|
||||
int mbedtls_gcm_self_test(int verbose);
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
||||
|
@ -65,10 +65,10 @@ extern "C" {
|
||||
* \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
|
||||
* MD layer.
|
||||
*/
|
||||
int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt,
|
||||
size_t salt_len, const unsigned char *ikm, size_t ikm_len,
|
||||
const unsigned char *info, size_t info_len,
|
||||
unsigned char *okm, size_t okm_len );
|
||||
int mbedtls_hkdf(const mbedtls_md_info_t *md, const unsigned char *salt,
|
||||
size_t salt_len, const unsigned char *ikm, size_t ikm_len,
|
||||
const unsigned char *info, size_t info_len,
|
||||
unsigned char *okm, size_t okm_len);
|
||||
|
||||
/**
|
||||
* \brief Take the input keying material \p ikm and extract from it a
|
||||
@ -94,10 +94,10 @@ int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt,
|
||||
* \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
|
||||
* MD layer.
|
||||
*/
|
||||
int mbedtls_hkdf_extract( const mbedtls_md_info_t *md,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *ikm, size_t ikm_len,
|
||||
unsigned char *prk );
|
||||
int mbedtls_hkdf_extract(const mbedtls_md_info_t *md,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *ikm, size_t ikm_len,
|
||||
unsigned char *prk);
|
||||
|
||||
/**
|
||||
* \brief Expand the supplied \p prk into several additional pseudorandom
|
||||
@ -125,9 +125,9 @@ int mbedtls_hkdf_extract( const mbedtls_md_info_t *md,
|
||||
* \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying
|
||||
* MD layer.
|
||||
*/
|
||||
int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk,
|
||||
size_t prk_len, const unsigned char *info,
|
||||
size_t info_len, unsigned char *okm, size_t okm_len );
|
||||
int mbedtls_hkdf_expand(const mbedtls_md_info_t *md, const unsigned char *prk,
|
||||
size_t prk_len, const unsigned char *info,
|
||||
size_t info_len, unsigned char *okm, size_t okm_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ extern "C" {
|
||||
/**
|
||||
* HMAC_DRBG context.
|
||||
*/
|
||||
typedef struct mbedtls_hmac_drbg_context
|
||||
{
|
||||
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 MBEDTLS_PRIVATE(md_ctx); /*!< HMAC context (inc. K) */
|
||||
@ -94,11 +93,11 @@ typedef struct mbedtls_hmac_drbg_context
|
||||
/* Administrative state */
|
||||
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) */
|
||||
reseed before every random generation) */
|
||||
int MBEDTLS_PRIVATE(reseed_interval); /*!< reseed interval */
|
||||
|
||||
/* Callbacks */
|
||||
int (*MBEDTLS_PRIVATE(f_entropy))(void *, unsigned char *, size_t); /*!< 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)
|
||||
@ -126,7 +125,7 @@ typedef struct mbedtls_hmac_drbg_context
|
||||
*
|
||||
* \param ctx HMAC_DRBG context to be initialized.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
|
||||
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx);
|
||||
|
||||
/**
|
||||
* \brief HMAC_DRBG initial seeding.
|
||||
@ -196,12 +195,12 @@ void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if the call to \p f_entropy failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t * md_info,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len );
|
||||
int mbedtls_hmac_drbg_seed(mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t *md_info,
|
||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||
void *p_entropy,
|
||||
const unsigned char *custom,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief Initialisation of simplified HMAC_DRBG (never reseeds).
|
||||
@ -231,9 +230,9 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
|
||||
* \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough
|
||||
* memory to allocate context data.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t * md_info,
|
||||
const unsigned char *data, size_t data_len );
|
||||
int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context *ctx,
|
||||
const mbedtls_md_info_t *md_info,
|
||||
const unsigned char *data, size_t data_len);
|
||||
|
||||
/**
|
||||
* \brief This function turns prediction resistance on or off.
|
||||
@ -248,8 +247,8 @@ int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param resistance #MBEDTLS_HMAC_DRBG_PR_ON or #MBEDTLS_HMAC_DRBG_PR_OFF.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
|
||||
int resistance );
|
||||
void mbedtls_hmac_drbg_set_prediction_resistance(mbedtls_hmac_drbg_context *ctx,
|
||||
int resistance);
|
||||
|
||||
/**
|
||||
* \brief This function sets the amount of entropy grabbed on each
|
||||
@ -260,8 +259,8 @@ void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param len The amount of entropy to grab, in bytes.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
|
||||
size_t len );
|
||||
void mbedtls_hmac_drbg_set_entropy_len(mbedtls_hmac_drbg_context *ctx,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* \brief Set the reseed interval.
|
||||
@ -275,8 +274,8 @@ void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
|
||||
* \param ctx The HMAC_DRBG context.
|
||||
* \param interval The reseed interval.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
|
||||
int interval );
|
||||
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx,
|
||||
int interval);
|
||||
|
||||
/**
|
||||
* \brief This function updates the state of the HMAC_DRBG context.
|
||||
@ -295,8 +294,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( 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
|
||||
@ -322,8 +321,8 @@ int mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
|
||||
* if a call to the entropy function failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t len );
|
||||
int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context *ctx,
|
||||
const unsigned char *additional, size_t len);
|
||||
|
||||
/**
|
||||
* \brief This function updates an HMAC_DRBG instance with additional
|
||||
@ -356,10 +355,10 @@ int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if
|
||||
* \p add_len > #MBEDTLS_HMAC_DRBG_MAX_INPUT.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_random_with_add( void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
const unsigned char *additional,
|
||||
size_t add_len );
|
||||
int mbedtls_hmac_drbg_random_with_add(void *p_rng,
|
||||
unsigned char *output, size_t output_len,
|
||||
const unsigned char *additional,
|
||||
size_t add_len);
|
||||
|
||||
/**
|
||||
* \brief This function uses HMAC_DRBG to generate random data.
|
||||
@ -388,7 +387,7 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng,
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG if
|
||||
* \p out_len > #MBEDTLS_HMAC_DRBG_MAX_REQUEST.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
|
||||
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len);
|
||||
|
||||
/**
|
||||
* \brief This function resets HMAC_DRBG context to the state immediately
|
||||
@ -396,7 +395,7 @@ int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len
|
||||
*
|
||||
* \param ctx The HMAC_DRBG context to free.
|
||||
*/
|
||||
void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
|
||||
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx);
|
||||
|
||||
#if defined(MBEDTLS_FS_IO)
|
||||
/**
|
||||
@ -410,7 +409,7 @@ void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED on reseed
|
||||
* failure.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
|
||||
int mbedtls_hmac_drbg_write_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path);
|
||||
|
||||
/**
|
||||
* \brief This function reads and updates a seed file. The seed
|
||||
@ -426,7 +425,7 @@ int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const cha
|
||||
* \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if the existing
|
||||
* seed file is too large.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
|
||||
int mbedtls_hmac_drbg_update_seed_file(mbedtls_hmac_drbg_context *ctx, const char *path);
|
||||
#endif /* MBEDTLS_FS_IO */
|
||||
|
||||
|
||||
@ -437,7 +436,7 @@ int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const ch
|
||||
* \return \c 0 if successful.
|
||||
* \return \c 1 if the test failed.
|
||||
*/
|
||||
int mbedtls_hmac_drbg_self_test( int verbose );
|
||||
int mbedtls_hmac_drbg_self_test(int verbose);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,7 +1,10 @@
|
||||
/**
|
||||
* Macros to express dependencies for code and tests that may use either the
|
||||
* legacy API or PSA in various builds; mostly for internal use.
|
||||
*
|
||||
* legacy API or PSA in various builds. This whole header file is currently
|
||||
* for internal use only and both the header file and the macros it defines
|
||||
* may change or be removed without notice.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -61,7 +64,7 @@
|
||||
* The naming scheme for these macros is:
|
||||
* MBEDTLS_HAS_feature_VIA_legacy_OR_PSA(_condition)
|
||||
* where:
|
||||
* - feature is expressed the same way as in PSA_WANT macros, for example:
|
||||
* - feature is expressed the same way as in PSA_WANT_xxx macros, for example:
|
||||
* KEY_TYPE_AES, ALG_SHA_256, ECC_SECP_R1_256;
|
||||
* - legacy is either LOWLEVEL or the name of the layer: MD, CIPHER;
|
||||
* - condition is omitted if it's based on availability, else it's
|
||||
@ -107,105 +110,105 @@
|
||||
|
||||
/* Hashes using low-level or PSA based on availability */
|
||||
#if defined(MBEDTLS_MD5_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_MD5) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_MD5))
|
||||
#define MBEDTLS_HAS_ALG_MD5_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_RIPEMD160_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_RIPEMD160) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_RIPEMD160))
|
||||
#define MBEDTLS_HAS_ALG_RIPEMD160_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA1_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_1) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_1))
|
||||
#define MBEDTLS_HAS_ALG_SHA_1_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA224_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_224) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_224))
|
||||
#define MBEDTLS_HAS_ALG_SHA_224_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA256_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_256) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_256))
|
||||
#define MBEDTLS_HAS_ALG_SHA_256_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA384_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_384) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_384))
|
||||
#define MBEDTLS_HAS_ALG_SHA_384_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
#if defined(MBEDTLS_SHA512_C) || \
|
||||
( defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_512) )
|
||||
(defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_512))
|
||||
#define MBEDTLS_HAS_ALG_SHA_512_VIA_LOWLEVEL_OR_PSA
|
||||
#endif
|
||||
|
||||
/* Hashes using MD or PSA based on availability */
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_MD5_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_MD5) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_MD5_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_MD5))
|
||||
#define MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_RIPEMD160_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_RIPEMD160) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_RIPEMD160_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_RIPEMD160))
|
||||
#define MBEDTLS_HAS_ALG_RIPEMD160_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA1_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_1) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA1_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_1))
|
||||
#define MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA224_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_224) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA224_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_224))
|
||||
#define MBEDTLS_HAS_ALG_SHA_224_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA256_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_256) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA256_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_256))
|
||||
#define MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA384_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_384) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA384_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_384))
|
||||
#define MBEDTLS_HAS_ALG_SHA_384_VIA_MD_OR_PSA
|
||||
#endif
|
||||
#if ( defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA512_C) ) || \
|
||||
( !defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_512) )
|
||||
#if (defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA512_C)) || \
|
||||
(!defined(MBEDTLS_MD_C) && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_WANT_ALG_SHA_512))
|
||||
#define MBEDTLS_HAS_ALG_SHA_512_VIA_MD_OR_PSA
|
||||
#endif
|
||||
|
||||
/* Hashes using MD or PSA based on MBEDTLS_USE_PSA_CRYPTO */
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_MD5_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_MD5) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_MD5_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_MD5))
|
||||
#define MBEDTLS_HAS_ALG_MD5_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_RIPEMD160_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_RIPEMD160) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_RIPEMD160_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_RIPEMD160))
|
||||
#define MBEDTLS_HAS_ALG_RIPEMD160_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA1_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_1) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA1_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_1))
|
||||
#define MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA224_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_224) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA224_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_224))
|
||||
#define MBEDTLS_HAS_ALG_SHA_224_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA256_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_256) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA256_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_256))
|
||||
#define MBEDTLS_HAS_ALG_SHA_256_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA384_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_384) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA384_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_384))
|
||||
#define MBEDTLS_HAS_ALG_SHA_384_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA512_C) ) || \
|
||||
( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_512) )
|
||||
#if (!defined(MBEDTLS_USE_PSA_CRYPTO) && \
|
||||
defined(MBEDTLS_MD_C) && defined(MBEDTLS_SHA512_C)) || \
|
||||
(defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_512))
|
||||
#define MBEDTLS_HAS_ALG_SHA_512_VIA_MD_OR_PSA_BASED_ON_USE_PSA
|
||||
#endif
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user