Merge pull request #4317 from yanesca/psa-jpake-interface
J-PAKE interface definition for PSA Crypto
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..b9f1468
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,35 @@
+---
+name: Bug report
+about: To report a bug, please fill this form.
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+### Summary
+
+
+
+### System information
+
+Mbed TLS version (number or commit id):
+Operating system and version:
+Configuration (if not default, please attach `config.h`):
+Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
+Additional environment information:
+
+### Expected behavior
+
+
+
+### Actual behavior
+
+
+
+### Steps to reproduce
+
+
+
+### Additional information
+
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..63076f4
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,8 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Mbed TLS security team
+ url: mailto:mbed-tls-security@lists.trustedfirmware.org
+ about: Report a security vulnerability.
+ - name: Mbed TLS mailing list
+ url: https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
+ about: Mbed TLS community support and general discussion.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 0000000..3b51513
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,17 @@
+---
+name: Enhancement request
+about: To request an enhancement, please fill this form.
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+### Suggested enhancement
+
+
+
+### Justification
+
+Mbed TLS needs this because
+
diff --git a/.github/issue_template.md b/.github/issue_template.md
deleted file mode 100644
index 370066f..0000000
--- a/.github/issue_template.md
+++ /dev/null
@@ -1,46 +0,0 @@
-_Note:_ this is a template, please remove the parts that are not
-applicable (these initial notes, and the "Bug" section for a Feature request
-and vice-versa).
-
-**Note:** to report a security vulnerability, see
-[SECURITY.md](../SECURITY.md). Please do not use github issues for
-vulnerabilities.
-
-_Note:_ to get support, see [SUPPORT.md](../SUPPORT.md). Please do not use
-github issues for questions.
-
----------------------------------------------------------------
-### Description
-- Type: Bug | Enhancement / Feature Request
-- Priority: Blocker | Major | Minor
-
----------------------------------------------------------------
-## Bug
-
-**OS**
-Mbed OS|linux|windows|
-
-**mbed TLS build:**
-Version: x.x.x or git commit id
-OS version: x.x.x
-Configuration: please attach config.h file where possible
-Compiler and options (if you used a pre-built binary, please indicate how you obtained it):
-Additional environment information:
-
-**Peer device TLS stack and version**
-OpenSSL|GnuTls|Chrome|NSS(Firefox)|SecureChannel (IIS/Internet Explorer/Edge)|Other
-Version:
-
-**Expected behavior**
-
-**Actual behavior**
-
-**Steps to reproduce**
-
-----------------------------------------------------------------
-## Enhancement / Feature Request
-
-**Suggested enhancement**
-
-**Justification - why does the library need this feature?**
-
diff --git a/.travis.yml b/.travis.yml
index 542f705..48faa48 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,12 +28,6 @@
script:
- tests/scripts/all.sh -k test_full_cmake_gcc_asan
- - name: macOS
- os: osx
- compiler: clang
- script:
- - tests/scripts/all.sh -k test_default_out_of_box
-
- name: Windows
os: windows
before_install:
diff --git a/BRANCHES.md b/BRANCHES.md
index 8486ef0..b9926ac 100644
--- a/BRANCHES.md
+++ b/BRANCHES.md
@@ -16,9 +16,10 @@
these only get bug fixes and security fixes.
We use [Semantic Versioning](https://semver.org/). In particular, we maintain
-API compatibility in the `master` branch between major version changes. We
-also maintain ABI compatibility within LTS branches; see the next section for
-details.
+API compatibility in the `master` branch across minor version changes (e.g.
+the API of 3.(x+1) is backward compatible with 3.x). We only break API
+compatibility on major version changes (e.g. from 3.x to 4.0). We also maintain
+ABI compatibility within LTS branches; see the next section for details.
## Backwards Compatibility
@@ -28,11 +29,28 @@
modification with any later release x.y'.z' with the same major version
number, and your code will still build, be secure, and work.
-There are rare exceptions: code that was relying on something that became
-insecure in the meantime (for example, crypto that was found to be weak) may
-need to be changed. In case security comes in conflict with backwards
-compatibility, we will put security first, but always attempt to provide a
-compatibility option.
+Note that new releases of Mbed TLS may extend the API. Here are some
+examples of changes that are common in minor releases of Mbed TLS, and are
+not considered API compatibility breaks:
+
+* Adding or reordering fields in a structure or union.
+* Removing a field from a structure, unless the field is documented as public.
+* Adding items to an enum.
+* Returning an error code that was not previously documented for a function
+ when a new error condition arises.
+* Changing which error code is returned in a case where multiple error
+ conditions apply.
+* Changing the behavior of a function from failing to succeeding, when the
+ change is a reasonable extension of the current behavior, i.e. the
+ addition of a new feature.
+
+There are rare exceptions where we break API compatibility: code that was
+relying on something that became insecure in the meantime (for example,
+crypto that was found to be weak) may need to be changed. In case security
+comes in conflict with backwards compatibility, we will put security first,
+but always attempt to provide a compatibility option.
+
+## Long-time support branches
For the LTS branches, additionally we try very hard to also maintain ABI
compatibility (same definition as API except with re-linking instead of
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f648f22..efe3cab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,9 @@
# mbedtls, mbedx509, mbedcrypto and apidoc targets.
#
-cmake_minimum_required(VERSION 2.8.12)
+# We specify a minimum requirement of 3.10.2, but for now use 3.5.1 here
+# until our infrastructure catches up.
+cmake_minimum_required(VERSION 3.5.1)
# https://cmake.org/cmake/help/latest/policy/CMP0011.html
# Setting this policy is required in CMake >= 3.18.0, otherwise a warning is generated. The OLD
diff --git a/ChangeLog.d/fix-ssl-cf-hmac-alt.txt b/ChangeLog.d/fix-ssl-cf-hmac-alt.txt
new file mode 100644
index 0000000..57ffa02
--- /dev/null
+++ b/ChangeLog.d/fix-ssl-cf-hmac-alt.txt
@@ -0,0 +1,5 @@
+Bugfix
+ * Fix a regression introduced in 2.24.0 which broke (D)TLS CBC ciphersuites
+ (when the encrypt-then-MAC extension is not in use) with some ALT
+ implementations of the underlying hash (SHA-1, SHA-256, SHA-384), causing
+ the affected side to wrongly reject valid messages. Fixes #4118.
diff --git a/ChangeLog.d/issue4286.txt b/ChangeLog.d/issue4286.txt
index 813b2ec..75d2f09 100644
--- a/ChangeLog.d/issue4286.txt
+++ b/ChangeLog.d/issue4286.txt
@@ -1,11 +1,10 @@
Removals
- * Remove the TLS 1.0, TLS 1.1 and DTLS 1.0 support by removing the following
- library constants: MBEDTLS_SSL_PROTO_TLS1,
- MBEDTLS_SSL_PROTO_TLS1_1, MBEDTLS_SSL_CBC_RECORD_SPLITTING,
- MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED,
- MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED,
- MBEDTLS_SSL_FALLBACK_SCSV, MBEDTLS_SSL_FALLBACK_SCSV_VALUE,
- MBEDTLS_SSL_IS_FALLBACK, MBEDTLS_SSL_IS_NOT_FALLBACK, and functions:
+ * Remove support for TLS 1.0, TLS 1.1 and DTLS 1.0, as well as support for
+ CBC record splitting, fallback SCSV, and the ability to configure
+ ciphersuites per version, which are no longer relevant. This removes the
+ configuration options MBEDTLS_SSL_PROTO_TLS1,
+ MBEDTLS_SSL_PROTO_TLS1_1, MBEDTLS_SSL_CBC_RECORD_SPLITTING and
+ MBEDTLS_SSL_FALLBACK_SCSV as well as the functions
mbedtls_ssl_conf_cbc_record_splitting(),
- mbedtls_ssl_get_key_exchange_md_ssl_tls(), mbedtls_ssl_conf_fallback().
- Fixes #4286.
+ mbedtls_ssl_get_key_exchange_md_ssl_tls(), mbedtls_ssl_conf_fallback(),
+ and mbedtls_ssl_conf_ciphersuites_for_version(). Fixes #4286.
diff --git a/ChangeLog.d/issue4313.txt b/ChangeLog.d/issue4313.txt
new file mode 100644
index 0000000..1fb6123
--- /dev/null
+++ b/ChangeLog.d/issue4313.txt
@@ -0,0 +1,4 @@
+Removals
+ * Remove the following macros: MBEDTLS_CHECK_PARAMS,
+ MBEDTLS_CHECK_PARAMS_ASSERT, MBEDTLS_PARAM_FAILED,
+ MBEDTLS_PARAM_FAILED_ALT. Fixes #4313.
diff --git a/ChangeLog.d/issue4378.txt b/ChangeLog.d/issue4378.txt
new file mode 100644
index 0000000..9a7522b
--- /dev/null
+++ b/ChangeLog.d/issue4378.txt
@@ -0,0 +1,4 @@
+Removals
+ * Remove the MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION config.h
+ option. The mbedtls_x509_crt_parse_der_with_ext_cb() is the way to go for
+ migration path. Fixes #4378.
diff --git a/ChangeLog.d/issue4405.txt b/ChangeLog.d/issue4405.txt
new file mode 100644
index 0000000..c36aefa
--- /dev/null
+++ b/ChangeLog.d/issue4405.txt
@@ -0,0 +1,4 @@
+Removals
+ * Remove the MBEDTLS_X509_CHECK_KEY_USAGE and
+ MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE config.h options and let the code
+ behave as if they were always enabled. Fixes #4405.
diff --git a/ChangeLog.d/max-record-payload-api.txt b/ChangeLog.d/max-record-payload-api.txt
new file mode 100644
index 0000000..02b47e4
--- /dev/null
+++ b/ChangeLog.d/max-record-payload-api.txt
@@ -0,0 +1,9 @@
+API changes
+ * Remove the SSL APIs mbedtls_ssl_get_input_max_frag_len() and
+ mbedtls_ssl_get_output_max_frag_len(), and add a new API
+ mbedtls_ssl_get_max_in_record_payload(), complementing the existing
+ mbedtls_ssl_get_max_out_record_payload().
+ Uses of mbedtls_ssl_get_input_max_frag_len() and
+ mbedtls_ssl_get_input_max_frag_len() should be replaced by
+ mbedtls_ssl_get_max_in_record_payload() and
+ mbedtls_ssl_get_max_out_record_payload(), respectively.
diff --git a/ChangeLog.d/mbed-can-do-timing.txt b/ChangeLog.d/mbed-can-do-timing.txt
new file mode 100644
index 0000000..d83da02
--- /dev/null
+++ b/ChangeLog.d/mbed-can-do-timing.txt
@@ -0,0 +1,3 @@
+Bugfix
+ * Remove outdated check-config.h check that prevented implementing the
+ timing module on Mbed OS. Fixes #4633.
diff --git a/ChangeLog.d/mpi_random.txt b/ChangeLog.d/mpi_random.txt
new file mode 100644
index 0000000..9e6a416
--- /dev/null
+++ b/ChangeLog.d/mpi_random.txt
@@ -0,0 +1,3 @@
+Features
+ * The new function mbedtls_mpi_random() generates a random value in a
+ given range uniformly.
diff --git a/ChangeLog.d/random-range.txt b/ChangeLog.d/random-range.txt
new file mode 100644
index 0000000..dc35ec6
--- /dev/null
+++ b/ChangeLog.d/random-range.txt
@@ -0,0 +1,4 @@
+Security
+* Fix a bias in the generation of finite-field Diffie-Hellman-Merkle (DHM)
+ private keys and of blinding values for DHM and elliptic curves (ECP)
+ computations. Reported by FlorianF89 in #4245.
diff --git a/ChangeLog.d/rm-ecdh-legacy-context-option.txt b/ChangeLog.d/rm-ecdh-legacy-context-option.txt
new file mode 100644
index 0000000..d5a527b
--- /dev/null
+++ b/ChangeLog.d/rm-ecdh-legacy-context-option.txt
@@ -0,0 +1,3 @@
+Removals
+ * Remove MBEDTLS_ECDH_LEGACY_CONTEXT config option since this was purely for
+ backward compatibility which is no longer supported. Addresses #4404.
diff --git a/ChangeLog.d/rsa-padding.txt b/ChangeLog.d/rsa-padding.txt
new file mode 100644
index 0000000..5f9c11f
--- /dev/null
+++ b/ChangeLog.d/rsa-padding.txt
@@ -0,0 +1,5 @@
+API changes
+ * mbedtls_rsa_init() now always selects the PKCS#1v1.5 encoding for an RSA
+ key. To use an RSA key with PSS or OAEP, call mbedtls_rsa_set_padding()
+ after initializing the context. mbedtls_rsa_set_padding() now returns an
+ error if its parameters are invalid.
diff --git a/ChangeLog.d/tool-versions.txt b/ChangeLog.d/tool-versions.txt
new file mode 100644
index 0000000..b89b384
--- /dev/null
+++ b/ChangeLog.d/tool-versions.txt
@@ -0,0 +1,4 @@
+Requirement changes
+ * Refresh the minimum supported versions of tools to build the
+ library. CMake versions older than 3.10.2 and Python older
+ than 3.6 are no longer supported.
diff --git a/README.md b/README.md
index 3f41a0d..78d3c30 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@
To generate a local copy of the library documentation in HTML format, tailored to your compile-time configuration:
-1. Make sure that [Doxygen](http://www.doxygen.nl/) is installed. We use version 1.8.11 but slightly older or more recent versions should work.
+1. Make sure that [Doxygen](http://www.doxygen.nl/) is installed.
1. Run `make apidoc`.
1. Browse `apidoc/index.html` or `apidoc/modules.html`.
@@ -39,7 +39,7 @@
- GNU Make
- CMake
-- Microsoft Visual Studio (Microsoft Visual Studio 2013 or later)
+- Microsoft Visual Studio
The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically.
@@ -49,10 +49,13 @@
You need the following tools to build the library with the provided makefiles:
-* GNU Make or a build tool that CMake supports.
-* A C99 toolchain (compiler, linker, archiver). We actively test with GCC 5.4, Clang 3.8, IAR8 and Visual Studio 2013. More recent versions should work. Slightly older versions may work.
-* Python 3 to generate the test code, and to generate sample programs in the development branch.
+* GNU Make 3.82 or a build tool that CMake supports.
+* A C99 toolchain (compiler, linker, archiver). We actively test with GCC 5.4, Clang 3.8, IAR 8 and Visual Studio 2013. More recent versions should work. Slightly older versions may work.
+* Python 3.6 to generate the test code, and to generate sample programs in the development branch.
* Perl to run the tests, and to generate some source files in the development branch.
+* CMake 3.10.2 or later (if using CMake).
+* Microsoft Visual Studio 2013 or later (if using Visual Studio).
+* Doxygen 1.8.11 or later (if building the documentation; slightly older versions should work).
### Generated source files in the development branch
diff --git a/configs/config-no-entropy.h b/configs/config-no-entropy.h
index 09b3cf5..7ca33c3 100644
--- a/configs/config-no-entropy.h
+++ b/configs/config-no-entropy.h
@@ -49,8 +49,6 @@
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_SELF_TEST
#define MBEDTLS_VERSION_FEATURES
-#define MBEDTLS_X509_CHECK_KEY_USAGE
-#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
/* mbed TLS modules */
#define MBEDTLS_AES_C
diff --git a/docs/3.0-migration-guide.d/max-record-payload-api.md b/docs/3.0-migration-guide.d/max-record-payload-api.md
new file mode 100644
index 0000000..0b34915
--- /dev/null
+++ b/docs/3.0-migration-guide.d/max-record-payload-api.md
@@ -0,0 +1,11 @@
+Remove MaximumFragmentLength (MFL) query API
+-----------------------------------------------------------------
+
+This affects users which use the MFL query APIs
+`mbedtls_ssl_get_{input,output}_max_frag_len()` to
+infer upper bounds on the plaintext size of incoming and
+outgoing record.
+
+Users should switch to `mbedtls_ssl_get_max_{in,out}_record_payload()`
+instead, which also provides such upper bounds but takes more factors
+than just the MFL configuration into account.
diff --git a/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION.md b/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION.md
new file mode 100644
index 0000000..738fa81
--- /dev/null
+++ b/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION.md
@@ -0,0 +1,17 @@
+Remove the config option MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
+--------------------------------------------------------------------------
+
+This change does not affect users of the default configuration; it only affect
+users who enable this option.
+
+The X.509 standard says that implementations must reject critical extensions that
+they don't recognize, and this is what Mbed TLS does by default. This option
+allowed to continue parsing those certificates but didn't provide a convenient
+way to handle those extensions.
+
+The migration path from that option is to use the
+`mbedtls_x509_crt_parse_der_with_ext_cb()` function which is functionally
+equivalent to `mbedtls_x509_crt_parse_der()`, and/or
+`mbedtls_x509_crt_parse_der_nocopy()` but it calls the callback with every
+unsupported certificate extension and additionally the "certificate policies"
+extension if it contains any unsupported certificate policies.
diff --git a/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_CHECK_x_KEY_USAGE_options.md b/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_CHECK_x_KEY_USAGE_options.md
new file mode 100644
index 0000000..2acb3bf
--- /dev/null
+++ b/docs/3.0-migration-guide.d/remove_MBEDTLS_X509_CHECK_x_KEY_USAGE_options.md
@@ -0,0 +1,18 @@
+Remove `MBEDTLS_X509_CHECK_*_KEY_USAGE` options from `config.h`
+-------------------------------------------------------------------
+
+This change affects users who have chosen the configuration options to disable the
+library's verification of the `keyUsage` and `extendedKeyUsage` fields of x509
+certificates.
+
+The `MBEDTLS_X509_CHECK_KEY_USAGE` and `MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE`
+configuration options are removed and the X509 code now behaves as if they were
+always enabled. It is consequently not possible anymore to disable at compile
+time the verification of the `keyUsage` and `extendedKeyUsage` fields of X509
+certificates.
+
+The verification of the `keyUsage` and `extendedKeyUsage` fields is important,
+disabling it can cause security issues and it is thus not recommended. If the
+verification is for some reason undesirable, it can still be disabled by means
+of the verification callback function passed to `mbedtls_x509_crt_verify()` (see
+the documentation of this function for more information).
diff --git a/docs/3.0-migration-guide.d/remove_deprecated_functions_and_constants.md b/docs/3.0-migration-guide.d/remove_deprecated_functions_and_constants.md
index b18b310..31c2ce8 100644
--- a/docs/3.0-migration-guide.d/remove_deprecated_functions_and_constants.md
+++ b/docs/3.0-migration-guide.d/remove_deprecated_functions_and_constants.md
@@ -50,7 +50,9 @@
`mbedtls_ssl_conf_dh_param_bin()` or `mbedtls_ssl_conf_dh_param_ctx()` instead.
The function `mbedtls_ssl_get_max_frag_len()` was removed. Please use
-`mbedtls_ssl_get_output_max_frag_len()` instead.
+`mbedtls_ssl_get_max_out_record_payload()` and
+`mbedtls_ssl_get_max_in_record_payload()`
+instead.
Deprecated hex-encoded primes were removed from DHM
---------------------------------------------------
diff --git a/docs/3.0-migration-guide.d/remove_mbedtls_check_params_option.md b/docs/3.0-migration-guide.d/remove_mbedtls_check_params_option.md
new file mode 100644
index 0000000..6f43aa3
--- /dev/null
+++ b/docs/3.0-migration-guide.d/remove_mbedtls_check_params_option.md
@@ -0,0 +1,33 @@
+Remove MBEDTLS_CHECK_PARAMS option
+----------------------------------
+
+This change does not affect users who use the default configuration; it only
+affects users who enabled that option.
+
+The option `MBEDTLS_CHECK_PARAMS` (disabled by default) enabled certain kinds
+of “parameter validation”. It covered two kinds of validations:
+
+- In some functions that require a valid pointer, “parameter validation” checks
+that the pointer is non-null. With the feature disabled, a null pointer is not
+treated differently from any other invalid pointer, and typically leads to a
+runtime crash. 90% of the uses of the feature are of this kind.
+- In some functions that take an enum-like argument, “parameter validation”
+checks that the value is a valid one. With the feature disabled, an invalid
+value causes a silent default to one of the valid values.
+
+The default reaction to a failed check was to call a function
+`mbedtls_param_failed()` which the application had to provide. If this function
+returned, its caller returned an error `MBEDTLS_ERR_xxx_BAD_INPUT_DATA`.
+
+This feature was only used in some classic (non-PSA) cryptography modules. It was
+not used in X.509, TLS or in PSA crypto, and it was not implemented in all
+classic crypto modules.
+
+This feature has been removed. The library no longer checks for NULL pointers;
+checks for enum-like arguments will be kept or re-introduced on a case-by-case
+basis, but their presence will no longer be dependent on a compile-time option.
+
+Validation of enum-like values is somewhat useful, but not extremely important,
+because the parameters concerned are usually constants in applications.
+
+For more information see issue #4313.
diff --git a/docs/3.0-migration-guide.d/remove_support_for_tls_1.0_1.1_and_dtls_1.0.md b/docs/3.0-migration-guide.d/remove_support_for_tls_1.0_1.1_and_dtls_1.0.md
index 4beebe2..73d621f 100644
--- a/docs/3.0-migration-guide.d/remove_support_for_tls_1.0_1.1_and_dtls_1.0.md
+++ b/docs/3.0-migration-guide.d/remove_support_for_tls_1.0_1.1_and_dtls_1.0.md
@@ -3,9 +3,25 @@
This change affects users of the TLS 1.0, 1.1 and DTLS 1.0 protocols.
-The versions of (D)TLS that are being removed are not as secure as the latest
-versions. Keeping them in the library creates opportunities for misconfiguration
+These versions have been deprecated by RFC 8996.
+Keeping them in the library creates opportunities for misconfiguration
and possibly downgrade attacks. More generally, more code means a larger attack
surface, even if the code is supposedly not used.
The migration path is to adopt the latest versions of the protocol.
+
+As a consequence of removing TLS 1.0, support for CBC record splitting was
+also removed, as it was a work-around for a weakness in this particular
+version. There is no migration path since the feature is no longer relevant.
+
+As a consequence of currently supporting only one version of (D)TLS (and in the
+future 1.3 which will have a different version negociation mechanism), support
+for fallback SCSV (RFC 7507) was also removed. There is no migration path as
+it's no longer useful with TLS 1.2 and later.
+
+As a consequence of currently supporting only one version of (D)TLS (and in the
+future 1.3 which will have a different concept of ciphersuites), support for
+configuring ciphersuites separately for each version via
+`mbedtls_ssl_conf_ciphersuites_for_version()` was removed. Use
+`mbedtls_ssl_conf_ciphersuites()` to configure ciphersuites to use with (D)TLS
+1.2; in the future a different API will be added for (D)TLS 1.3.
diff --git a/docs/3.0-migration-guide.d/rsa-padding.md b/docs/3.0-migration-guide.d/rsa-padding.md
new file mode 100644
index 0000000..f10ece6
--- /dev/null
+++ b/docs/3.0-migration-guide.d/rsa-padding.md
@@ -0,0 +1,29 @@
+Remove the padding parameters from mbedtls_rsa_init()
+-----------------------------------------------------
+
+This affects all users who use the RSA encryption, decryption, sign and
+verify APIs.
+
+The function mbedtls_rsa_init() no longer supports selecting the PKCS#1 v2.1
+encoding and its hash. It just selects the PKCS#1 v1.5 encoding by default. If
+you were using the PKCS#1 v2.1 encoding you now need, subsequently to the call
+to mbedtls_rsa_init(), to call mbedtls_rsa_set_padding() to set it.
+
+To choose the padding type when initializing a context, instead of
+```C
+ mbedtls_rsa_init(ctx, padding, hash_id);
+```
+, use
+```C
+ mbedtls_rsa_init(ctx);
+ mbedtls_rsa_set_padding(ctx, padding, hash_id);
+```
+
+To use PKCS#1 v1.5 padding, instead of
+```C
+ mbedtls_rsa_init(ctx, MBEDTLS_RSA_PKCS_V15, <ignored>);
+```
+, just use
+```C
+ mbedtls_rsa_init(ctx);
+```
diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h
index 073b4a4..6a79024 100644
--- a/include/mbedtls/bignum.h
+++ b/include/mbedtls/bignum.h
@@ -871,6 +871,44 @@
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
+/** Generate a random number uniformly in a range.
+ *
+ * This function generates a random number between \p min inclusive and
+ * \p N exclusive.
+ *
+ * The procedure complies with RFC 6979 §3.3 (deterministic ECDSA)
+ * when the RNG is a suitably parametrized instance of HMAC_DRBG
+ * and \p min is \c 1.
+ *
+ * \note There are `N - min` possible outputs. The lower bound
+ * \p min can be reached, but the upper bound \p N cannot.
+ *
+ * \param X The destination MPI. This must point to an initialized MPI.
+ * \param min The minimum value to return.
+ * It must be nonnegative.
+ * \param N The upper bound of the range, exclusive.
+ * In other words, this is one plus the maximum value to return.
+ * \p N must be strictly larger than \p min.
+ * \param f_rng The RNG function to use. This must not be \c NULL.
+ * \param p_rng The RNG parameter to be passed to \p f_rng.
+ *
+ * \return \c 0 if successful.
+ * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.
+ * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p min or \p N is invalid
+ * or if they are incompatible.
+ * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was
+ * unable to find a suitable value within a limited number
+ * of attempts. This has a negligible probability if \p N
+ * is significantly larger than \p min, which is the case
+ * for all usual cryptographic applications.
+ * \return Another negative error code on failure.
+ */
+int mbedtls_mpi_random( mbedtls_mpi *X,
+ mbedtls_mpi_sint min,
+ const mbedtls_mpi *N,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
/**
* \brief Compute the greatest common divisor: G = gcd(A, B)
*
diff --git a/include/mbedtls/check_config.h b/include/mbedtls/check_config.h
index 8501fb6..90dee6c 100644
--- a/include/mbedtls/check_config.h
+++ b/include/mbedtls/check_config.h
@@ -55,9 +55,8 @@
#endif
#endif /* _WIN32 */
-#if defined(TARGET_LIKE_MBED) && \
- ( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
-#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
+#if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C)
+#error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS"
#endif
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
@@ -130,16 +129,6 @@
#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative or PSA-based ECP implementation"
#endif
-#if defined(MBEDTLS_ECP_RESTARTABLE) && \
- ! defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
-#error "MBEDTLS_ECP_RESTARTABLE defined, but not MBEDTLS_ECDH_LEGACY_CONTEXT"
-#endif
-
-#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) && \
- defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
-#error "MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED defined, but MBEDTLS_ECDH_LEGACY_CONTEXT not disabled"
-#endif
-
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
#endif
@@ -836,6 +825,10 @@
#error "MBEDTLS_SSL_PROTO_TLS1_1 (TLS v1.1 support) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4286"
#endif
+#if defined(MBEDTLS_CHECK_PARAMS) //no-check-names
+#error "MBEDTLS_CHECK_PARAMS was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4313"
+#endif
+
#if defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) //no-check-names
#error "MBEDTLS_SSL_CID_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335"
#endif
diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h
index fb57818..3139b22 100644
--- a/include/mbedtls/config.h
+++ b/include/mbedtls/config.h
@@ -255,72 +255,6 @@
*/
//#define MBEDTLS_DEPRECATED_REMOVED
-/**
- * \def MBEDTLS_CHECK_PARAMS
- *
- * This configuration option controls whether the library validates more of
- * the parameters passed to it.
- *
- * When this flag is not defined, the library only attempts to validate an
- * input parameter if: (1) they may come from the outside world (such as the
- * network, the filesystem, etc.) or (2) not validating them could result in
- * internal memory errors such as overflowing a buffer controlled by the
- * library. On the other hand, it doesn't attempt to validate parameters whose
- * values are fully controlled by the application (such as pointers).
- *
- * When this flag is defined, the library additionally attempts to validate
- * parameters that are fully controlled by the application, and should always
- * be valid if the application code is fully correct and trusted.
- *
- * For example, when a function accepts as input a pointer to a buffer that may
- * contain untrusted data, and its documentation mentions that this pointer
- * must not be NULL:
- * - The pointer is checked to be non-NULL only if this option is enabled.
- * - The content of the buffer is always validated.
- *
- * When this flag is defined, if a library function receives a parameter that
- * is invalid:
- * 1. The function will invoke the macro MBEDTLS_PARAM_FAILED().
- * 2. If MBEDTLS_PARAM_FAILED() did not terminate the program, the function
- * will immediately return. If the function returns an Mbed TLS error code,
- * the error code in this case is MBEDTLS_ERR_xxx_BAD_INPUT_DATA.
- *
- * When defining this flag, you also need to arrange a definition for
- * MBEDTLS_PARAM_FAILED(). You can do this by any of the following methods:
- * - By default, the library defines MBEDTLS_PARAM_FAILED() to call a
- * function mbedtls_param_failed(), but the library does not define this
- * function. If you do not make any other arrangements, you must provide
- * the function mbedtls_param_failed() in your application.
- * See `platform_util.h` for its prototype.
- * - If you enable the macro #MBEDTLS_CHECK_PARAMS_ASSERT, then the
- * library defines MBEDTLS_PARAM_FAILED(\c cond) to be `assert(cond)`.
- * You can still supply an alternative definition of
- * MBEDTLS_PARAM_FAILED(), which may call `assert`.
- * - If you define a macro MBEDTLS_PARAM_FAILED() before including `config.h`
- * or you uncomment the definition of MBEDTLS_PARAM_FAILED() in `config.h`,
- * the library will call the macro that you defined and will not supply
- * its own version. Note that if MBEDTLS_PARAM_FAILED() calls `assert`,
- * you need to enable #MBEDTLS_CHECK_PARAMS_ASSERT so that library source
- * files include `<assert.h>`.
- *
- * Uncomment to enable validation of application-controlled parameters.
- */
-//#define MBEDTLS_CHECK_PARAMS
-
-/**
- * \def MBEDTLS_CHECK_PARAMS_ASSERT
- *
- * Allow MBEDTLS_PARAM_FAILED() to call `assert`, and make it default to
- * `assert`. This macro is only used if #MBEDTLS_CHECK_PARAMS is defined.
- *
- * If this macro is not defined, then MBEDTLS_PARAM_FAILED() defaults to
- * calling a function mbedtls_param_failed(). See the documentation of
- * #MBEDTLS_CHECK_PARAMS for details.
- *
- * Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`.
- */
-//#define MBEDTLS_CHECK_PARAMS_ASSERT
-
/* \} name SECTION: System support */
/**
@@ -759,40 +693,11 @@
*
* \note This option only works with the default software implementation of
* elliptic curve functionality. It is incompatible with
- * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT
- * and MBEDTLS_ECDH_LEGACY_CONTEXT.
+ * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT, MBEDTLS_ECDSA_XXX_ALT.
*/
//#define MBEDTLS_ECP_RESTARTABLE
/**
- * \def MBEDTLS_ECDH_LEGACY_CONTEXT
- *
- * Use a backward compatible ECDH context.
- *
- * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
- * defined in `ecdh.h`). For most applications, the choice of format makes
- * no difference, since all library functions can work with either format,
- * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
-
- * The new format used when this option is disabled is smaller
- * (56 bytes on a 32-bit platform). In future versions of the library, it
- * will support alternative implementations of ECDH operations.
- * The new format is incompatible with applications that access
- * context fields directly and with restartable ECP operations.
- *
- * Define this macro if you enable MBEDTLS_ECP_RESTARTABLE or if you
- * want to access ECDH context fields directly. Otherwise you should
- * comment out this macro definition.
- *
- * This option has no effect if #MBEDTLS_ECDH_C is not enabled.
- *
- * \note This configuration option is experimental. Future versions of the
- * library may modify the way the ECDH context layout is configured
- * and may modify the layout of the new context type.
- */
-#define MBEDTLS_ECDH_LEGACY_CONTEXT
-
-/**
* \def MBEDTLS_ECDSA_DETERMINISTIC
*
* Enable deterministic ECDSA (RFC 6979).
@@ -1909,18 +1814,6 @@
#define MBEDTLS_VERSION_FEATURES
/**
- * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
- *
- * If set, the X509 parser will not break-off when parsing an X509 certificate
- * and encountering an unknown critical extension.
- *
- * \warning Depending on your PKI use, enabling this can be a security risk!
- *
- * Uncomment to prevent an error.
- */
-//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
-
-/**
* \def MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
*
* If set, this enables the X.509 API `mbedtls_x509_crt_verify_with_ca_cb()`
@@ -1940,33 +1833,6 @@
//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
/**
- * \def MBEDTLS_X509_CHECK_KEY_USAGE
- *
- * Enable verification of the keyUsage extension (CA and leaf certificates).
- *
- * Disabling this avoids problems with mis-issued and/or misused
- * (intermediate) CA and leaf certificates.
- *
- * \warning Depending on your PKI use, disabling this can be a security risk!
- *
- * Comment to skip keyUsage checking for both CA and leaf certificates.
- */
-#define MBEDTLS_X509_CHECK_KEY_USAGE
-
-/**
- * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
- *
- * Enable verification of the extendedKeyUsage extension (leaf certificates).
- *
- * Disabling this avoids problems with mis-issued and/or misused certificates.
- *
- * \warning Depending on your PKI use, disabling this can be a security risk!
- *
- * Comment to skip extendedKeyUsage checking for certificates.
- */
-#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
-
-/**
* \def MBEDTLS_X509_REMOVE_INFO
*
* Disable mbedtls_x509_*_info() and related APIs.
@@ -3332,42 +3198,6 @@
//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
-/**
- * \brief This macro is invoked by the library when an invalid parameter
- * is detected that is only checked with #MBEDTLS_CHECK_PARAMS
- * (see the documentation of that option for context).
- *
- * When you leave this undefined here, the library provides
- * a default definition. If the macro #MBEDTLS_CHECK_PARAMS_ASSERT
- * is defined, the default definition is `assert(cond)`,
- * otherwise the default definition calls a function
- * mbedtls_param_failed(). This function is declared in
- * `platform_util.h` for the benefit of the library, but
- * you need to define in your application.
- *
- * When you define this here, this replaces the default
- * definition in platform_util.h (which no longer declares the
- * function mbedtls_param_failed()) and it is your responsibility
- * to make sure this macro expands to something suitable (in
- * particular, that all the necessary declarations are visible
- * from within the library - you can ensure that by providing
- * them in this file next to the macro definition).
- * If you define this macro to call `assert`, also define
- * #MBEDTLS_CHECK_PARAMS_ASSERT so that library source files
- * include `<assert.h>`.
- *
- * Note that you may define this macro to expand to nothing, in
- * which case you don't have to worry about declarations or
- * definitions. However, you will then be notified about invalid
- * parameters only in non-void functions, and void function will
- * just silently return early on invalid parameters, which
- * partially negates the benefits of enabling
- * #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged.
- *
- * \param cond The expression that should evaluate to true, but doesn't.
- */
-//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
-
/* PSA options */
/**
* Use HMAC_DRBG with the specified hash algorithm for HMAC_DRBG for the
diff --git a/include/mbedtls/ecdh.h b/include/mbedtls/ecdh.h
index 05855cd..765ac5e 100644
--- a/include/mbedtls/ecdh.h
+++ b/include/mbedtls/ecdh.h
@@ -40,6 +40,25 @@
#include "mbedtls/ecp.h"
+/*
+ * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
+ * defined in `ecdh.h`). For most applications, the choice of format makes
+ * no difference, since all library functions can work with either format,
+ * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
+
+ * The new format used when this option is disabled is smaller
+ * (56 bytes on a 32-bit platform). In future versions of the library, it
+ * will support alternative implementations of ECDH operations.
+ * The new format is incompatible with applications that access
+ * context fields directly and with restartable ECP operations.
+ */
+
+#if defined(MBEDTLS_ECP_RESTARTABLE)
+#define MBEDTLS_ECDH_LEGACY_CONTEXT
+#else
+#undef MBEDTLS_ECDH_LEGACY_CONTEXT
+#endif
+
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
#undef MBEDTLS_ECDH_LEGACY_CONTEXT
#include "everest/everest.h"
diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h
index fbc2a0d..6d9cfec 100644
--- a/include/mbedtls/platform_util.h
+++ b/include/mbedtls/platform_util.h
@@ -39,78 +39,10 @@
extern "C" {
#endif
-#if defined(MBEDTLS_CHECK_PARAMS)
-
-#if defined(MBEDTLS_CHECK_PARAMS_ASSERT)
-/* Allow the user to define MBEDTLS_PARAM_FAILED to something like assert
- * (which is what our config.h suggests). */
-#include <assert.h>
-#endif /* MBEDTLS_CHECK_PARAMS_ASSERT */
-
-#if defined(MBEDTLS_PARAM_FAILED)
-/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h.
- *
- * This flag can be used to check whether it is safe to assume that
- * MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed().
- */
-#define MBEDTLS_PARAM_FAILED_ALT
-
-#elif defined(MBEDTLS_CHECK_PARAMS_ASSERT)
-#define MBEDTLS_PARAM_FAILED( cond ) assert( cond )
-#define MBEDTLS_PARAM_FAILED_ALT
-
-#else /* MBEDTLS_PARAM_FAILED */
-#define MBEDTLS_PARAM_FAILED( cond ) \
- mbedtls_param_failed( #cond, __FILE__, __LINE__ )
-
-/**
- * \brief User supplied callback function for parameter validation failure.
- * See #MBEDTLS_CHECK_PARAMS for context.
- *
- * This function will be called unless an alternative treatement
- * is defined through the #MBEDTLS_PARAM_FAILED macro.
- *
- * This function can return, and the operation will be aborted, or
- * alternatively, through use of setjmp()/longjmp() can resume
- * execution in the application code.
- *
- * \param failure_condition The assertion that didn't hold.
- * \param file The file where the assertion failed.
- * \param line The line in the file where the assertion failed.
- */
-void mbedtls_param_failed( const char *failure_condition,
- const char *file,
- int line );
-#endif /* MBEDTLS_PARAM_FAILED */
-
-/* Internal macro meant to be called only from within the library. */
-#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \
- do { \
- if( !(cond) ) \
- { \
- MBEDTLS_PARAM_FAILED( cond ); \
- return( ret ); \
- } \
- } while( 0 )
-
-/* Internal macro meant to be called only from within the library. */
-#define MBEDTLS_INTERNAL_VALIDATE( cond ) \
- do { \
- if( !(cond) ) \
- { \
- MBEDTLS_PARAM_FAILED( cond ); \
- return; \
- } \
- } while( 0 )
-
-#else /* MBEDTLS_CHECK_PARAMS */
-
/* Internal macros meant to be called only from within the library. */
#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 )
#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 )
-#endif /* MBEDTLS_CHECK_PARAMS */
-
/* Internal helper macros for deprecating API constants. */
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
#if defined(MBEDTLS_DEPRECATED_WARNING)
diff --git a/include/mbedtls/rsa.h b/include/mbedtls/rsa.h
index ba00bff..34174b6 100644
--- a/include/mbedtls/rsa.h
+++ b/include/mbedtls/rsa.h
@@ -134,33 +134,51 @@
/**
* \brief This function initializes an RSA context.
*
+ * \note This function initializes the padding and the hash
+ * identifier to respectively #MBEDTLS_RSA_PKCS_V15 and
+ * #MBEDTLS_MD_NONE. See mbedtls_rsa_set_padding() for more
+ * information about those parameters.
+ *
+ * \param ctx The RSA context to initialize. This must not be \c NULL.
+ */
+void mbedtls_rsa_init( mbedtls_rsa_context *ctx );
+
+/**
+ * \brief This function sets padding for an already initialized RSA
+ * context.
+ *
* \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
* encryption scheme and the RSASSA-PSS signature scheme.
*
* \note The \p hash_id parameter is ignored when using
* #MBEDTLS_RSA_PKCS_V15 padding.
*
- * \note The choice of padding mode is strictly enforced for private key
- * operations, since there might be security concerns in
+ * \note The choice of padding mode is strictly enforced for private
+ * key operations, since there might be security concerns in
* mixing padding modes. For public key operations it is
* a default value, which can be overridden by calling specific
- * \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
+ * \c mbedtls_rsa_rsaes_xxx or \c mbedtls_rsa_rsassa_xxx
+ * functions.
*
* \note The hash selected in \p hash_id is always used for OEAP
* encryption. For PSS signatures, it is always used for
* making signatures, but can be overridden for verifying them.
* If set to #MBEDTLS_MD_NONE, it is always overridden.
*
- * \param ctx The RSA context to initialize. This must not be \c NULL.
+ * \param ctx The initialized RSA context to be configured.
* \param padding The padding mode to use. This must be either
* #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
- * \param hash_id The hash identifier of ::mbedtls_md_type_t type, if
- * \p padding is #MBEDTLS_RSA_PKCS_V21. It is unused
- * otherwise.
+ * \param hash_id The hash identifier for PSS or OAEP, if \p padding is
+ * #MBEDTLS_RSA_PKCS_V21. #MBEDTLS_MD_NONE is accepted by this
+ * function but may be not suitable for some operations.
+ * Ignored if \p padding is #MBEDTLS_RSA_PKCS_V15.
+ *
+ * \return \c 0 on success.
+ * \return #MBEDTLS_ERR_RSA_INVALID_PADDING failure:
+ * \p padding or \p hash_id is invalid.
*/
-void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
- int padding,
- int hash_id );
+int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
+ mbedtls_md_type_t hash_id );
/**
* \brief This function imports a set of core parameters into an
@@ -392,18 +410,6 @@
mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
/**
- * \brief This function sets padding for an already initialized RSA
- * context. See mbedtls_rsa_init() for details.
- *
- * \param ctx The initialized RSA context to be configured.
- * \param padding The padding mode to use. This must be either
- * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
- * \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
- */
-void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
- int hash_id );
-
-/**
* \brief This function retrieves the length of RSA modulus in Bytes.
*
* \param ctx The initialized RSA context.
diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h
index 677ed98..c293b88 100644
--- a/include/mbedtls/ssl.h
+++ b/include/mbedtls/ssl.h
@@ -125,14 +125,10 @@
*/
/* These are the high an low bytes of ProtocolVersion as defined by:
- * - RFC 2246: ProtocolVersion version = { 3, 1 }; // TLS v1.0
- * - RFC 4346: ProtocolVersion version = { 3, 2 }; // TLS v1.1
* - RFC 5246: ProtocolVersion version = { 3, 3 }; // TLS v1.2
* - RFC 8446: see section 4.2.1
*/
#define MBEDTLS_SSL_MAJOR_VERSION_3 3
-#define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 deprecated */
-#define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 deprecated */
#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
#define MBEDTLS_SSL_MINOR_VERSION_4 4 /*!< TLS v1.3 (experimental) */
@@ -976,10 +972,8 @@
* Pointers
*/
- /** Allowed ciphersuites per version. To access list's elements, please use
- * \c mbedtls_ssl_get_protocol_version_ciphersuites
- */
- const int *ciphersuite_list[3];
+ /** Allowed ciphersuites for (D)TLS 1.2 (0-terminated) */
+ const int *ciphersuite_list;
/** Callback for printing debug output */
void (*f_dbg)(void *, int, const char *, int, const char *);
@@ -2508,17 +2502,6 @@
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
const int *ciphersuites );
-/**
- * \brief Get ciphersuite for given protocol's minor version.
- *
- * \param conf The SSL configuration.
- * \param prot_version Protocol version. One of MBEDTLS_SSL_MINOR_VERSION_x macros.
- * \return Ciphersuites pointer if successful.
- * \return \c NULL if no ciphersuites where found.
- */
-const int *mbedtls_ssl_get_protocol_version_ciphersuites(
- const mbedtls_ssl_config *conf, int prot_version );
-
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
@@ -2558,27 +2541,6 @@
int ignore_other_cids );
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
-/**
- * \brief Set the list of allowed ciphersuites and the
- * preference order for a specific version of the protocol.
- * (Only useful on the server side)
- *
- * The ciphersuites array is not copied, and must remain
- * valid for the lifetime of the ssl_config.
- *
- * \param conf SSL configuration
- * \param ciphersuites 0-terminated list of allowed ciphersuites
- * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
- * supported)
- * \param minor Minor version number (only MBEDTLS_SSL_MINOR_VERSION_3
- * supported)
- *
- * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
- */
-void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
- const int *ciphersuites,
- int major, int minor );
-
#if defined(MBEDTLS_X509_CRT_PARSE_C)
/**
* \brief Set the X.509 security profile used for verification
@@ -3229,8 +3191,7 @@
*
* \param conf SSL configuration
* \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
- * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
- * MBEDTLS_SSL_MINOR_VERSION_3 supported)
+ * \param minor Minor version number (only MBEDTLS_SSL_MINOR_VERSION_3 supported)
*/
void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
@@ -3245,9 +3206,7 @@
*
* \param conf SSL configuration
* \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
- * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_1,
- * MBEDTLS_SSL_MINOR_VERSION_2,
- * MBEDTLS_SSL_MINOR_VERSION_3 supported)
+ * \param minor Minor version number (only MBEDTLS_SSL_MINOR_VERSION_3 supported)
*/
void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
@@ -3577,45 +3536,15 @@
*/
int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
-#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
-/**
- * \brief Return the maximum fragment length (payload, in bytes) for
- * the output buffer. For the client, this is the configured
- * value. For the server, it is the minimum of two - the
- * configured value and the negotiated one.
- *
- * \sa mbedtls_ssl_conf_max_frag_len()
- * \sa mbedtls_ssl_get_max_record_payload()
- *
- * \param ssl SSL context
- *
- * \return Current maximum fragment length for the output buffer.
- */
-size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl );
-
-/**
- * \brief Return the maximum fragment length (payload, in bytes) for
- * the input buffer. This is the negotiated maximum fragment
- * length, or, if there is none, MBEDTLS_SSL_IN_CONTENT_LEN.
- * If it is not defined either, the value is 2^14. This function
- * works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
- *
- * \sa mbedtls_ssl_conf_max_frag_len()
- * \sa mbedtls_ssl_get_max_record_payload()
- *
- * \param ssl SSL context
- *
- * \return Current maximum fragment length for the output buffer.
- */
-size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl );
-#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
-
/**
* \brief Return the current maximum outgoing record payload in bytes.
- * This takes into account the config.h setting \c
- * MBEDTLS_SSL_OUT_CONTENT_LEN, the configured and negotiated
- * max fragment length extension if used, and for DTLS the
- * path MTU as configured and current record expansion.
+ *
+ * \note The logic to determine the maximum outgoing record payload is
+ * version-specific. It takes into account various factors, such as
+ * the config.h setting \c MBEDTLS_SSL_OUT_CONTENT_LEN, extensions
+ * such as the max fragment length or record size limit extension if
+ * used, and for DTLS the path MTU as configured and current
+ * record expansion.
*
* \note With DTLS, \c mbedtls_ssl_write() will return an error if
* called with a larger length value.
@@ -3624,9 +3553,7 @@
* to the caller to call \c mbedtls_ssl_write() again in
* order to send the remaining bytes if any.
*
- * \sa mbedtls_ssl_set_mtu()
- * \sa mbedtls_ssl_get_output_max_frag_len()
- * \sa mbedtls_ssl_get_input_max_frag_len()
+ * \sa mbedtls_ssl_get_max_out_record_payload()
* \sa mbedtls_ssl_get_record_expansion()
*
* \param ssl SSL context
@@ -3636,6 +3563,26 @@
*/
int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl );
+/**
+ * \brief Return the current maximum incoming record payload in bytes.
+ *
+ * \note The logic to determine the maximum outgoing record payload is
+ * version-specific. It takes into account various factors, such as
+ * the config.h setting \c MBEDTLS_SSL_IN_CONTENT_LEN, extensions
+ * such as the max fragment length extension or record size limit
+ * extension if used, and the current record expansion.
+ *
+ * \sa mbedtls_ssl_set_mtu()
+ * \sa mbedtls_ssl_get_max_in_record_payload()
+ * \sa mbedtls_ssl_get_record_expansion()
+ *
+ * \param ssl SSL context
+ *
+ * \return Current maximum payload for an outgoing record,
+ * or a negative error code.
+ */
+int mbedtls_ssl_get_max_in_record_payload( const mbedtls_ssl_context *ssl );
+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
/**
* \brief Return the peer certificate from the current connection.
@@ -3934,7 +3881,7 @@
* or negotiated with the peer), then:
* - with TLS, less bytes than requested are written.
* - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
- * \c mbedtls_ssl_get_output_max_frag_len() may be used to
+ * \c mbedtls_ssl_get_max_out_record_payload() may be used to
* query the active maximum fragment length.
*
* \note Attempting to write 0 bytes will result in an empty TLS
diff --git a/include/mbedtls/x509_crt.h b/include/mbedtls/x509_crt.h
index 23a20d1..18b0373 100644
--- a/include/mbedtls/x509_crt.h
+++ b/include/mbedtls/x509_crt.h
@@ -827,7 +827,6 @@
#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
/**
* \brief Check usage of certificate against keyUsage extension.
*
@@ -851,9 +850,7 @@
*/
int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
unsigned int usage );
-#endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
-#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
/**
* \brief Check usage of certificate against extendedKeyUsage.
*
@@ -870,7 +867,6 @@
int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
const char *usage_oid,
size_t usage_len );
-#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
#if defined(MBEDTLS_X509_CRL_PARSE_C)
/**
diff --git a/library/bignum.c b/library/bignum.c
index c20c6b7..c49d63e 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -181,6 +181,27 @@
return( 0 );
}
+/* Resize X to have exactly n limbs and set it to 0. */
+static int mbedtls_mpi_resize_clear( mbedtls_mpi *X, size_t limbs )
+{
+ if( limbs == 0 )
+ {
+ mbedtls_mpi_free( X );
+ return( 0 );
+ }
+ else if( X->n == limbs )
+ {
+ memset( X->p, 0, limbs * ciL );
+ X->s = 1;
+ return( 0 );
+ }
+ else
+ {
+ mbedtls_mpi_free( X );
+ return( mbedtls_mpi_grow( X, limbs ) );
+ }
+}
+
/*
* Copy the contents of Y into X
*/
@@ -838,14 +859,7 @@
size_t const limbs = CHARS_TO_LIMBS( buflen );
/* Ensure that target MPI has exactly the necessary number of limbs */
- if( X->n != limbs )
- {
- mbedtls_mpi_free( X );
- mbedtls_mpi_init( X );
- MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, limbs ) );
- }
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) );
for( i = 0; i < buflen; i++ )
X->p[i / ciL] |= ((mbedtls_mpi_uint) buf[i]) << ((i % ciL) << 3);
@@ -874,17 +888,11 @@
MPI_VALIDATE_RET( buflen == 0 || buf != NULL );
/* Ensure that target MPI has exactly the necessary number of limbs */
- if( X->n != limbs )
- {
- mbedtls_mpi_free( X );
- mbedtls_mpi_init( X );
- MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, limbs ) );
- }
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) );
- /* Avoid calling `memcpy` with NULL source argument,
+ /* Avoid calling `memcpy` with NULL source or destination argument,
* even if buflen is 0. */
- if( buf != NULL )
+ if( buflen != 0 )
{
Xp = (unsigned char*) X->p;
memcpy( Xp + overhead, buf, buflen );
@@ -2395,6 +2403,33 @@
return( ret );
}
+/* Fill X with n_bytes random bytes.
+ * X must already have room for those bytes.
+ * The ordering of the bytes returned from the RNG is suitable for
+ * deterministic ECDSA (see RFC 6979 §3.3 and mbedtls_mpi_random()).
+ * The size and sign of X are unchanged.
+ * n_bytes must not be 0.
+ */
+static int mpi_fill_random_internal(
+ mbedtls_mpi *X, size_t n_bytes,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
+{
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
+ const size_t limbs = CHARS_TO_LIMBS( n_bytes );
+ const size_t overhead = ( limbs * ciL ) - n_bytes;
+
+ if( X->n < limbs )
+ return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+
+ memset( X->p, 0, overhead );
+ memset( (unsigned char *) X->p + limbs * ciL, 0, ( X->n - limbs ) * ciL );
+ MBEDTLS_MPI_CHK( f_rng( p_rng, (unsigned char *) X->p + overhead, n_bytes ) );
+ mpi_bigendian_to_host( X->p, limbs );
+
+cleanup:
+ return( ret );
+}
+
/*
* Fill X with size bytes of random.
*
@@ -2408,25 +2443,84 @@
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
size_t const limbs = CHARS_TO_LIMBS( size );
- size_t const overhead = ( limbs * ciL ) - size;
- unsigned char *Xp;
MPI_VALIDATE_RET( X != NULL );
MPI_VALIDATE_RET( f_rng != NULL );
/* Ensure that target MPI has exactly the necessary number of limbs */
- if( X->n != limbs )
+ MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) );
+ if( size == 0 )
+ return( 0 );
+
+ ret = mpi_fill_random_internal( X, size, f_rng, p_rng );
+
+cleanup:
+ return( ret );
+}
+
+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 ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
+ int count;
+ unsigned cmp = 0;
+ size_t n_bits = mbedtls_mpi_bitlen( N );
+ size_t n_bytes = ( n_bits + 7 ) / 8;
+
+ if( min < 0 )
+ return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ if( mbedtls_mpi_cmp_int( N, min ) <= 0 )
+ return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+
+ /*
+ * When min == 0, each try has at worst a probability 1/2 of failing
+ * (the msb has a probability 1/2 of being 0, and then the result will
+ * be < N), so after 30 tries failure probability is a most 2**(-30).
+ *
+ * When N is just below a power of 2, as is the case when generating
+ * a random scalar on most elliptic curves, 1 try is enough with
+ * overwhelming probability. When N is just above a power of 2,
+ * as when generating a random scalar on secp224k1, each try has
+ * a probability of failing that is almost 1/2.
+ *
+ * The probabilities are almost the same if min is nonzero but negligible
+ * compared to N. This is always the case when N is crypto-sized, but
+ * it's convenient to support small N for testing purposes. When N
+ * is small, use a higher repeat count, otherwise the probability of
+ * failure is macroscopic.
+ */
+ count = ( n_bytes > 4 ? 30 : 250 );
+
+ /* Ensure that target MPI has exactly the same number of limbs
+ * as the upper bound, even if the upper bound has leading zeros.
+ * This is necessary for the mbedtls_mpi_lt_mpi_ct() check. */
+ MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, N->n ) );
+
+ /*
+ * Match the procedure given in RFC 6979 §3.3 (deterministic ECDSA)
+ * when f_rng is a suitably parametrized instance of HMAC_DRBG:
+ * - use the same byte ordering;
+ * - keep the leftmost n_bits bits of the generated octet string;
+ * - try until result is in the desired range.
+ * This also avoids any bias, which is especially important for ECDSA.
+ */
+ do
{
- mbedtls_mpi_free( X );
- mbedtls_mpi_init( X );
- MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, limbs ) );
+ MBEDTLS_MPI_CHK( mpi_fill_random_internal( X, n_bytes, f_rng, p_rng ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( X, 8 * n_bytes - n_bits ) );
+
+ if( --count == 0 )
+ {
+ ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE;
+ goto cleanup;
+ }
+
+ MBEDTLS_MPI_CHK( mbedtls_mpi_lt_mpi_ct( X, N, &cmp ) );
}
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) );
-
- Xp = (unsigned char*) X->p;
- MBEDTLS_MPI_CHK( f_rng( p_rng, Xp + overhead, size ) );
-
- mpi_bigendian_to_host( X->p, limbs );
+ while( mbedtls_mpi_cmp_int( X, min ) < 0 || cmp != 1 );
cleanup:
return( ret );
diff --git a/library/dhm.c b/library/dhm.c
index 9758af7..accd5a8 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -100,22 +100,21 @@
*/
static int dhm_check_range( const mbedtls_mpi *param, const mbedtls_mpi *P )
{
- mbedtls_mpi L, U;
+ mbedtls_mpi U;
int ret = 0;
- mbedtls_mpi_init( &L ); mbedtls_mpi_init( &U );
+ mbedtls_mpi_init( &U );
- MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &L, 2 ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &U, P, 2 ) );
- if( mbedtls_mpi_cmp_mpi( param, &L ) < 0 ||
+ if( mbedtls_mpi_cmp_int( param, 2 ) < 0 ||
mbedtls_mpi_cmp_mpi( param, &U ) > 0 )
{
ret = MBEDTLS_ERR_DHM_BAD_INPUT_DATA;
}
cleanup:
- mbedtls_mpi_free( &L ); mbedtls_mpi_free( &U );
+ mbedtls_mpi_free( &U );
return( ret );
}
@@ -151,38 +150,44 @@
}
/*
- * Setup and write the ServerKeyExchange parameters
+ * Pick a random R in the range [2, M-2] for blinding or key generation.
*/
-int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
- unsigned char *output, size_t *olen,
- int (*f_rng)(void *, unsigned char *, size_t),
- void *p_rng )
+static int dhm_random_below( mbedtls_mpi *R, const mbedtls_mpi *M,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
- int ret, count = 0;
- size_t n1, n2, n3;
- unsigned char *p;
- DHM_VALIDATE_RET( ctx != NULL );
- DHM_VALIDATE_RET( output != NULL );
- DHM_VALIDATE_RET( olen != NULL );
- DHM_VALIDATE_RET( f_rng != NULL );
+ int ret;
+
+ MBEDTLS_MPI_CHK( mbedtls_mpi_random( R, 3, M, f_rng, p_rng ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( R, R, 1 ) );
+
+cleanup:
+ return( ret );
+}
+
+static int dhm_make_common( mbedtls_dhm_context *ctx, int x_size,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng )
+{
+ int ret = 0;
if( mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 )
return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
+ if( x_size < 0 )
+ return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
- /*
- * Generate X as large as possible ( < P )
- */
- do
+ if( (unsigned) x_size < mbedtls_mpi_size( &ctx->P ) )
{
MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &ctx->X, x_size, f_rng, p_rng ) );
-
- while( mbedtls_mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &ctx->X, 1 ) );
-
- if( count++ > 10 )
- return( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED );
}
- while( dhm_check_range( &ctx->X, &ctx->P ) != 0 );
+ else
+ {
+ /* Generate X as large as possible ( <= P - 2 ) */
+ ret = dhm_random_below( &ctx->X, &ctx->P, f_rng, p_rng );
+ if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE )
+ return( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED );
+ if( ret != 0 )
+ return( ret );
+ }
/*
* Calculate GX = G^X mod P
@@ -193,8 +198,33 @@
if( ( ret = dhm_check_range( &ctx->GX, &ctx->P ) ) != 0 )
return( ret );
+cleanup:
+ return( ret );
+}
+
+/*
+ * Setup and write the ServerKeyExchange parameters
+ */
+int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
+ unsigned char *output, size_t *olen,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng )
+{
+ int ret;
+ size_t n1, n2, n3;
+ unsigned char *p;
+ DHM_VALIDATE_RET( ctx != NULL );
+ DHM_VALIDATE_RET( output != NULL );
+ DHM_VALIDATE_RET( olen != NULL );
+ DHM_VALIDATE_RET( f_rng != NULL );
+
+ ret = dhm_make_common( ctx, x_size, f_rng, p_rng );
+ if( ret != 0 )
+ goto cleanup;
+
/*
- * export P, G, GX
+ * Export P, G, GX. RFC 5246 §4.4 states that "leading zero octets are
+ * not required". We omit leading zeros for compactness.
*/
#define DHM_MPI_EXPORT( X, n ) \
do { \
@@ -220,11 +250,9 @@
ctx->len = n1;
cleanup:
-
- if( ret != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED, ret ) );
-
- return( 0 );
+ if( ret != 0 && ret > -128 )
+ ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED, ret );
+ return( ret );
}
/*
@@ -276,7 +304,7 @@
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng )
{
- int ret, count = 0;
+ int ret;
DHM_VALIDATE_RET( ctx != NULL );
DHM_VALIDATE_RET( output != NULL );
DHM_VALIDATE_RET( f_rng != NULL );
@@ -284,62 +312,17 @@
if( olen < 1 || olen > ctx->len )
return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
- if( mbedtls_mpi_cmp_int( &ctx->P, 0 ) == 0 )
- return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
-
- /*
- * generate X and calculate GX = G^X mod P
- */
- do
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &ctx->X, x_size, f_rng, p_rng ) );
-
- while( mbedtls_mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &ctx->X, 1 ) );
-
- if( count++ > 10 )
- return( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED );
- }
- while( dhm_check_range( &ctx->X, &ctx->P ) != 0 );
-
- MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &ctx->GX, &ctx->G, &ctx->X,
- &ctx->P , &ctx->RP ) );
-
- if( ( ret = dhm_check_range( &ctx->GX, &ctx->P ) ) != 0 )
- return( ret );
+ ret = dhm_make_common( ctx, x_size, f_rng, p_rng );
+ if( ret == MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED )
+ return( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED );
+ if( ret != 0 )
+ goto cleanup;
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->GX, output, olen ) );
cleanup:
-
- if( ret != 0 )
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED, ret ) );
-
- return( 0 );
-}
-
-/*
- * Pick a random R in the range [2, M) for blinding purposes
- */
-static int dhm_random_below( mbedtls_mpi *R, const mbedtls_mpi *M,
- int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
-{
- int ret, count;
-
- count = 0;
- do
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( R, mbedtls_mpi_size( M ), f_rng, p_rng ) );
-
- while( mbedtls_mpi_cmp_mpi( R, M ) >= 0 )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( R, 1 ) );
-
- if( count++ > 10 )
- return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE );
- }
- while( mbedtls_mpi_cmp_int( R, 1 ) <= 0 );
-
-cleanup:
+ if( ret != 0 && ret > -128 )
+ ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED, ret );
return( ret );
}
@@ -390,7 +373,7 @@
* We need to generate blinding values from scratch
*/
- /* Vi = random( 2, P-1 ) */
+ /* Vi = random( 2, P-2 ) */
MBEDTLS_MPI_CHK( dhm_random_below( &ctx->Vi, &ctx->P, f_rng, p_rng ) );
/* Vf = Vi^-X mod P
@@ -454,8 +437,9 @@
MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->K, &ctx->K, &ctx->P ) );
}
+ /* Output the secret without any leading zero byte. This is mandatory
+ * for TLS per RFC 5246 §8.1.2. */
*olen = mbedtls_mpi_size( &ctx->K );
-
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->K, output, *olen ) );
cleanup:
diff --git a/library/ecp.c b/library/ecp.c
index 1ad5b67..f450056 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -1713,26 +1713,11 @@
#else
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
mbedtls_mpi l, ll;
- int count = 0;
- size_t p_size = ( grp->pbits + 7 ) / 8;
mbedtls_mpi_init( &l ); mbedtls_mpi_init( &ll );
/* Generate l such that 1 < l < p */
- do
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &l, p_size, f_rng, p_rng ) );
-
- while( mbedtls_mpi_cmp_mpi( &l, &grp->P ) >= 0 )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &l, 1 ) );
-
- if( count++ > 10 )
- {
- ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
- goto cleanup;
- }
- }
- while( mbedtls_mpi_cmp_int( &l, 1 ) <= 0 );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_random( &l, 2, &grp->P, f_rng, p_rng ) );
/* Z = l * Z */
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mod( grp, &pt->Z, &pt->Z, &l ) );
@@ -1748,6 +1733,8 @@
cleanup:
mbedtls_mpi_free( &l ); mbedtls_mpi_free( &ll );
+ if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE )
+ ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
return( ret );
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) */
}
@@ -2502,25 +2489,10 @@
#else
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
mbedtls_mpi l;
- int count = 0;
- size_t p_size = ( grp->pbits + 7 ) / 8;
mbedtls_mpi_init( &l );
/* Generate l such that 1 < l < p */
- do
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &l, p_size, f_rng, p_rng ) );
-
- while( mbedtls_mpi_cmp_mpi( &l, &grp->P ) >= 0 )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &l, 1 ) );
-
- if( count++ > 10 )
- {
- ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
- goto cleanup;
- }
- }
- while( mbedtls_mpi_cmp_int( &l, 1 ) <= 0 );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_random( &l, 2, &grp->P, f_rng, p_rng ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mod( grp, &P->X, &P->X, &l ) );
MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mod( grp, &P->Z, &P->Z, &l ) );
@@ -2528,6 +2500,8 @@
cleanup:
mbedtls_mpi_free( &l );
+ if( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE )
+ ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
return( ret );
#endif /* !defined(MBEDTLS_ECP_NO_FALLBACK) || !defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) */
}
@@ -3057,6 +3031,56 @@
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
}
+#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+MBEDTLS_STATIC_TESTABLE
+int mbedtls_ecp_gen_privkey_mx( size_t high_bit,
+ mbedtls_mpi *d,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng )
+{
+ int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+ size_t n_random_bytes = high_bit / 8 + 1;
+
+ /* [Curve25519] page 5 */
+ /* Generate a (high_bit+1)-bit random number by generating just enough
+ * random bytes, then shifting out extra bits from the top (necessary
+ * when (high_bit+1) is not a multiple of 8). */
+ MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( d, n_random_bytes,
+ f_rng, p_rng ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( d, 8 * n_random_bytes - high_bit - 1 ) );
+
+ MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, high_bit, 1 ) );
+
+ /* Make sure the last two bits are unset for Curve448, three bits for
+ Curve25519 */
+ MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 0, 0 ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 1, 0 ) );
+ if( high_bit == 254 )
+ {
+ MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 2, 0 ) );
+ }
+
+cleanup:
+ return( ret );
+}
+#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+
+#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
+static int mbedtls_ecp_gen_privkey_sw(
+ const mbedtls_mpi *N, mbedtls_mpi *d,
+ int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
+{
+ int ret = mbedtls_mpi_random( d, 1, N, f_rng, p_rng );
+ switch( ret )
+ {
+ case MBEDTLS_ERR_MPI_NOT_ACCEPTABLE:
+ return( MBEDTLS_ERR_ECP_RANDOM_FAILED );
+ default:
+ return( ret );
+ }
+}
+#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
+
/*
* Generate a private key
*/
@@ -3065,89 +3089,21 @@
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng )
{
- int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
- size_t n_size;
-
ECP_VALIDATE_RET( grp != NULL );
ECP_VALIDATE_RET( d != NULL );
ECP_VALIDATE_RET( f_rng != NULL );
- n_size = ( grp->nbits + 7 ) / 8;
-
#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY )
- {
- /* [M225] page 5 */
- size_t b;
-
- do {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( d, n_size, f_rng, p_rng ) );
- } while( mbedtls_mpi_bitlen( d ) == 0);
-
- /* Make sure the most significant bit is nbits */
- b = mbedtls_mpi_bitlen( d ) - 1; /* mbedtls_mpi_bitlen is one-based */
- if( b > grp->nbits )
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( d, b - grp->nbits ) );
- else
- MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, grp->nbits, 1 ) );
-
- /* Make sure the last two bits are unset for Curve448, three bits for
- Curve25519 */
- MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 0, 0 ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 1, 0 ) );
- if( grp->nbits == 254 )
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( d, 2, 0 ) );
- }
- }
+ return( mbedtls_ecp_gen_privkey_mx( grp->nbits, d, f_rng, p_rng ) );
#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
if( mbedtls_ecp_get_type( grp ) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS )
- {
- /* SEC1 3.2.1: Generate d such that 1 <= n < N */
- int count = 0;
- unsigned cmp = 0;
-
- /*
- * Match the procedure given in RFC 6979 (deterministic ECDSA):
- * - use the same byte ordering;
- * - keep the leftmost nbits bits of the generated octet string;
- * - try until result is in the desired range.
- * This also avoids any biais, which is especially important for ECDSA.
- */
- do
- {
- MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( d, n_size, f_rng, p_rng ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( d, 8 * n_size - grp->nbits ) );
-
- /*
- * Each try has at worst a probability 1/2 of failing (the msb has
- * a probability 1/2 of being 0, and then the result will be < N),
- * so after 30 tries failure probability is a most 2**(-30).
- *
- * For most curves, 1 try is enough with overwhelming probability,
- * since N starts with a lot of 1s in binary, but some curves
- * such as secp224k1 are actually very close to the worst case.
- */
- if( ++count > 30 )
- {
- ret = MBEDTLS_ERR_ECP_RANDOM_FAILED;
- goto cleanup;
- }
-
- ret = mbedtls_mpi_lt_mpi_ct( d, &grp->N, &cmp );
- if( ret != 0 )
- {
- goto cleanup;
- }
- }
- while( mbedtls_mpi_cmp_int( d, 1 ) < 0 || cmp != 1 );
- }
+ return( mbedtls_ecp_gen_privkey_sw( &grp->N, d, f_rng, p_rng ) );
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
-cleanup:
- return( ret );
+ return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
}
/*
diff --git a/library/ecp_invasive.h b/library/ecp_invasive.h
index b523967..71c7702 100644
--- a/library/ecp_invasive.h
+++ b/library/ecp_invasive.h
@@ -27,6 +27,7 @@
#define MBEDTLS_ECP_INVASIVE_H
#include "common.h"
+#include "mbedtls/bignum.h"
#include "mbedtls/ecp.h"
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ECP_C)
@@ -46,6 +47,35 @@
void mbedtls_ecp_fix_negative( mbedtls_mpi *N, signed char c, size_t bits );
#endif
+#if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
+/** Generate a private key on a Montgomery curve (Curve25519 or Curve448).
+ *
+ * This function implements key generation for the set of secret keys
+ * specified in [Curve25519] p. 5 and in [Curve448]. The resulting value
+ * has the lower bits masked but is not necessarily canonical.
+ *
+ * \note - [Curve25519] http://cr.yp.to/ecdh/curve25519-20060209.pdf
+ * - [RFC7748] https://tools.ietf.org/html/rfc7748
+ *
+ * \p high_bit The position of the high-order bit of the key to generate.
+ * This is the bit-size of the key minus 1:
+ * 254 for Curve25519 or 447 for Curve448.
+ * \param d The randomly generated key. This is a number of size
+ * exactly \p n_bits + 1 bits, with the least significant bits
+ * masked as specified in [Curve25519] and in [RFC7748] §5.
+ * \param f_rng The RNG function.
+ * \param p_rng The RNG context to be passed to \p f_rng.
+ *
+ * \return \c 0 on success.
+ * \return \c MBEDTLS_ERR_ECP_xxx or MBEDTLS_ERR_MPI_xxx on failure.
+ */
+int mbedtls_ecp_gen_privkey_mx( size_t n_bits,
+ mbedtls_mpi *d,
+ int (*f_rng)(void *, unsigned char *, size_t),
+ void *p_rng );
+
+#endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */
+
#endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_ECP_C */
#endif /* MBEDTLS_ECP_INVASIVE_H */
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index c351113..ec0ff45 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -165,7 +165,7 @@
void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) );
if( ctx != NULL )
- mbedtls_rsa_init( (mbedtls_rsa_context *) ctx, 0, 0 );
+ mbedtls_rsa_init( (mbedtls_rsa_context *) ctx );
return( ctx );
}
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 3fe2a88..7921eb2 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1019,18 +1019,8 @@
{
psa_status_t status = psa_remove_key_data_from_memory( slot );
- /*
- * As the return error code may not be handled in case of multiple errors,
- * do our best to report an unexpected lock counter: if available
- * call MBEDTLS_PARAM_FAILED that may terminate execution (if called as
- * part of the execution of a test suite this will stop the test suite
- * execution).
- */
if( slot->lock_count != 1 )
{
-#ifdef MBEDTLS_CHECK_PARAMS
- MBEDTLS_PARAM_FAILED( slot->lock_count == 1 );
-#endif
status = PSA_ERROR_CORRUPTION_DETECTED;
}
@@ -2848,13 +2838,14 @@
}
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
-static void psa_rsa_oaep_set_padding_mode( psa_algorithm_t alg,
- mbedtls_rsa_context *rsa )
+static int psa_rsa_oaep_set_padding_mode( psa_algorithm_t alg,
+ mbedtls_rsa_context *rsa )
{
psa_algorithm_t hash_alg = PSA_ALG_RSA_OAEP_GET_HASH( alg );
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg );
mbedtls_md_type_t md_alg = mbedtls_md_get_type( md_info );
- mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
+
+ return( mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg ) );
}
#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) */
@@ -2927,7 +2918,11 @@
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
if( PSA_ALG_IS_RSA_OAEP( alg ) )
{
- psa_rsa_oaep_set_padding_mode( alg, rsa );
+ status = mbedtls_to_psa_error(
+ psa_rsa_oaep_set_padding_mode( alg, rsa ) );
+ if( status != PSA_SUCCESS )
+ goto rsa_exit;
+
status = mbedtls_to_psa_error(
mbedtls_rsa_rsaes_oaep_encrypt( rsa,
mbedtls_psa_get_random,
@@ -3033,7 +3028,11 @@
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP)
if( PSA_ALG_IS_RSA_OAEP( alg ) )
{
- psa_rsa_oaep_set_padding_mode( alg, rsa );
+ status = mbedtls_to_psa_error(
+ psa_rsa_oaep_set_padding_mode( alg, rsa ) );
+ if( status != PSA_SUCCESS )
+ goto rsa_exit;
+
status = mbedtls_to_psa_error(
mbedtls_rsa_rsaes_oaep_decrypt( rsa,
mbedtls_psa_get_random,
diff --git a/library/psa_crypto_rsa.c b/library/psa_crypto_rsa.c
index b5aec20..f2e9a1c 100644
--- a/library/psa_crypto_rsa.c
+++ b/library/psa_crypto_rsa.c
@@ -317,7 +317,7 @@
if( status != PSA_SUCCESS )
return( status );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE );
+ mbedtls_rsa_init( &rsa );
ret = mbedtls_rsa_gen_key( &rsa,
mbedtls_psa_get_random,
MBEDTLS_PSA_RANDOM_STATE,
@@ -416,29 +416,36 @@
#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN)
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
{
- mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
- MBEDTLS_MD_NONE );
- ret = mbedtls_rsa_pkcs1_sign( rsa,
- mbedtls_psa_get_random,
- MBEDTLS_PSA_RANDOM_STATE,
- md_alg,
- (unsigned int) hash_length,
- hash,
- signature );
+ ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
+ MBEDTLS_MD_NONE );
+ if( ret == 0 )
+ {
+ ret = mbedtls_rsa_pkcs1_sign( rsa,
+ mbedtls_psa_get_random,
+ MBEDTLS_PSA_RANDOM_STATE,
+ md_alg,
+ (unsigned int) hash_length,
+ hash,
+ signature );
+ }
}
else
#endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */
#if defined(BUILTIN_ALG_RSA_PSS)
if( PSA_ALG_IS_RSA_PSS( alg ) )
{
- mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
- ret = mbedtls_rsa_rsassa_pss_sign( rsa,
- mbedtls_psa_get_random,
- MBEDTLS_PSA_RANDOM_STATE,
- MBEDTLS_MD_NONE,
- (unsigned int) hash_length,
- hash,
- signature );
+ ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
+
+ if( ret == 0 )
+ {
+ ret = mbedtls_rsa_rsassa_pss_sign( rsa,
+ mbedtls_psa_get_random,
+ MBEDTLS_PSA_RANDOM_STATE,
+ MBEDTLS_MD_NONE,
+ (unsigned int) hash_length,
+ hash,
+ signature );
+ }
}
else
#endif /* BUILTIN_ALG_RSA_PSS */
@@ -489,25 +496,31 @@
#if defined(BUILTIN_ALG_RSA_PKCS1V15_SIGN)
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) )
{
- mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
- MBEDTLS_MD_NONE );
- ret = mbedtls_rsa_pkcs1_verify( rsa,
- md_alg,
- (unsigned int) hash_length,
- hash,
- signature );
+ ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V15,
+ MBEDTLS_MD_NONE );
+ if( ret == 0 )
+ {
+ ret = mbedtls_rsa_pkcs1_verify( rsa,
+ md_alg,
+ (unsigned int) hash_length,
+ hash,
+ signature );
+ }
}
else
#endif /* BUILTIN_ALG_RSA_PKCS1V15_SIGN */
#if defined(BUILTIN_ALG_RSA_PSS)
if( PSA_ALG_IS_RSA_PSS( alg ) )
{
- mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
- ret = mbedtls_rsa_rsassa_pss_verify( rsa,
- MBEDTLS_MD_NONE,
- (unsigned int) hash_length,
- hash,
- signature );
+ ret = mbedtls_rsa_set_padding( rsa, MBEDTLS_RSA_PKCS_V21, md_alg );
+ if( ret == 0 )
+ {
+ ret = mbedtls_rsa_rsassa_pss_verify( rsa,
+ MBEDTLS_MD_NONE,
+ (unsigned int) hash_length,
+ hash,
+ signature );
+ }
}
else
#endif /* BUILTIN_ALG_RSA_PSS */
diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c
index 0b1a3c1..4cf32db 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -409,17 +409,6 @@
return( PSA_SUCCESS );
}
- /*
- * As the return error code may not be handled in case of multiple errors,
- * do our best to report if the lock counter is equal to zero: if
- * available call MBEDTLS_PARAM_FAILED that may terminate execution (if
- * called as part of the execution of a unit test suite this will stop the
- * test suite execution).
- */
-#ifdef MBEDTLS_CHECK_PARAMS
- MBEDTLS_PARAM_FAILED( slot->lock_count > 0 );
-#endif
-
return( PSA_ERROR_CORRUPTION_DETECTED );
}
diff --git a/library/rsa.c b/library/rsa.c
index 36424bd..a788337 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -477,17 +477,14 @@
/*
* Initialize an RSA context
*/
-void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
- int padding,
- int hash_id )
+void mbedtls_rsa_init( mbedtls_rsa_context *ctx )
{
RSA_VALIDATE( ctx != NULL );
- RSA_VALIDATE( padding == MBEDTLS_RSA_PKCS_V15 ||
- padding == MBEDTLS_RSA_PKCS_V21 );
memset( ctx, 0, sizeof( mbedtls_rsa_context ) );
- mbedtls_rsa_set_padding( ctx, padding, hash_id );
+ ctx->padding = MBEDTLS_RSA_PKCS_V15;
+ ctx->hash_id = MBEDTLS_MD_NONE;
#if defined(MBEDTLS_THREADING_C)
/* Set ctx->ver to nonzero to indicate that the mutex has been
@@ -500,15 +497,38 @@
/*
* Set padding for an existing RSA context
*/
-void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
- int hash_id )
+int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
+ mbedtls_md_type_t hash_id )
{
- RSA_VALIDATE( ctx != NULL );
- RSA_VALIDATE( padding == MBEDTLS_RSA_PKCS_V15 ||
- padding == MBEDTLS_RSA_PKCS_V21 );
+ switch( padding )
+ {
+#if defined(MBEDTLS_PKCS1_V15)
+ case MBEDTLS_RSA_PKCS_V15:
+ break;
+#endif
+
+#if defined(MBEDTLS_PKCS1_V21)
+ case MBEDTLS_RSA_PKCS_V21:
+ break;
+#endif
+ default:
+ return( MBEDTLS_ERR_RSA_INVALID_PADDING );
+ }
+
+ if( ( padding == MBEDTLS_RSA_PKCS_V21 ) &&
+ ( hash_id != MBEDTLS_MD_NONE ) )
+ {
+ const mbedtls_md_info_t *md_info;
+
+ md_info = mbedtls_md_info_from_type( hash_id );
+ if( md_info == NULL )
+ return( MBEDTLS_ERR_RSA_INVALID_PADDING );
+ }
ctx->padding = padding;
ctx->hash_id = hash_id;
+
+ return( 0 );
}
/*
@@ -2580,7 +2600,7 @@
mbedtls_mpi K;
mbedtls_mpi_init( &K );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_N ) );
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, &K, NULL, NULL, NULL, NULL ) );
diff --git a/library/ssl_ciphersuites.c b/library/ssl_ciphersuites.c
index 00dcd07..1bda9c0 100644
--- a/library/ssl_ciphersuites.c
+++ b/library/ssl_ciphersuites.c
@@ -31,6 +31,7 @@
#include "mbedtls/ssl_ciphersuites.h"
#include "mbedtls/ssl.h"
+#include "ssl_misc.h"
#include <string.h>
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 6cf283e..12ed0fb 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -1155,8 +1155,7 @@
/*
* Ciphersuite list
*/
- ciphersuites = mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf,
- ssl->minor_ver );
+ ciphersuites = ssl->conf->ciphersuite_list;
/* Skip writing ciphersuite length for now */
n = 0;
@@ -2244,7 +2243,7 @@
i = 0;
while( 1 )
{
- if( mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver )[i] == 0 )
+ if( ssl->conf->ciphersuite_list[i] == 0 )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
mbedtls_ssl_send_alert_message(
@@ -2254,7 +2253,7 @@
return( MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO );
}
- if( mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver )[i++] ==
+ if( ssl->conf->ciphersuite_list[i++] ==
ssl->session_negotiate->ciphersuite )
{
break;
diff --git a/library/ssl_misc.h b/library/ssl_misc.h
index 73ffdef..d25bc55 100644
--- a/library/ssl_misc.h
+++ b/library/ssl_misc.h
@@ -65,6 +65,16 @@
#define inline __inline
#endif
+/* Legacy minor version numbers as defined by:
+ * - RFC 2246: ProtocolVersion version = { 3, 1 }; // TLS v1.0
+ * - RFC 4346: ProtocolVersion version = { 3, 2 }; // TLS v1.1
+ *
+ * We no longer support these versions, but some code still references those
+ * constants, for keep them for now until we clean up that code.
+ */
+#define MBEDTLS_SSL_MINOR_VERSION_1 1
+#define MBEDTLS_SSL_MINOR_VERSION_2 2
+
/* Determine minimum supported version */
#define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
@@ -245,6 +255,39 @@
+ ( MBEDTLS_SSL_CID_OUT_LEN_MAX ) )
#endif
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+/**
+ * \brief Return the maximum fragment length (payload, in bytes) for
+ * the output buffer. For the client, this is the configured
+ * value. For the server, it is the minimum of two - the
+ * configured value and the negotiated one.
+ *
+ * \sa mbedtls_ssl_conf_max_frag_len()
+ * \sa mbedtls_ssl_get_max_out_record_payload()
+ *
+ * \param ssl SSL context
+ *
+ * \return Current maximum fragment length for the output buffer.
+ */
+size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl );
+
+/**
+ * \brief Return the maximum fragment length (payload, in bytes) for
+ * the input buffer. This is the negotiated maximum fragment
+ * length, or, if there is none, MBEDTLS_SSL_IN_CONTENT_LEN.
+ * If it is not defined either, the value is 2^14. This function
+ * works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
+ *
+ * \sa mbedtls_ssl_conf_max_frag_len()
+ * \sa mbedtls_ssl_get_max_in_record_payload()
+ *
+ * \param ssl SSL context
+ *
+ * \return Current maximum fragment length for the output buffer.
+ */
+size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl );
+#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
+
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
static inline size_t mbedtls_ssl_get_output_buflen( const mbedtls_ssl_context *ctx )
{
diff --git a/library/ssl_msg.c b/library/ssl_msg.c
index c1648bc..0fa206b 100644
--- a/library/ssl_msg.c
+++ b/library/ssl_msg.c
@@ -1148,6 +1148,9 @@
MD_CHK( mbedtls_md_update( ctx, data + offset, 1 ) );
}
+ /* The context needs to finish() before it starts() again */
+ MD_CHK( mbedtls_md_finish( ctx, aux_out ) );
+
/* Now compute HASH(okey + inner_hash) */
MD_CHK( mbedtls_md_starts( ctx ) );
MD_CHK( mbedtls_md_update( ctx, okey, block_size ) );
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 8f13a2c..4fe6b02 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -1870,7 +1870,7 @@
* and certificate from the SNI callback triggered by the SNI extension.)
*/
got_common_suite = 0;
- ciphersuites = mbedtls_ssl_get_protocol_version_ciphersuites( ssl->conf, ssl->minor_ver );
+ ciphersuites = ssl->conf->ciphersuite_list;
ciphersuite_info = NULL;
#if defined(MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
for( j = 0, p = buf + ciph_offset + 2; j < ciph_len; j += 2, p += 2 )
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 342832f..3bdc1cf 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -3514,73 +3514,10 @@
}
#endif /* MBEDTLS_SSL_CLI_C */
-static int protocol_version_to_ciphersuites_list_index(int prot_version)
-{
- switch(prot_version) {
- case MBEDTLS_SSL_MINOR_VERSION_1:
- return 0;
- case MBEDTLS_SSL_MINOR_VERSION_2:
- return 1;
- case MBEDTLS_SSL_MINOR_VERSION_3:
- return 2;
- default:
- return -1;
- };
-}
-
-static void set_protocol_version_ciphersuites( mbedtls_ssl_config *conf,
- int prot_version,
- const int* ciphersuites )
-{
- int ciphersuite_list_index =
- protocol_version_to_ciphersuites_list_index(prot_version);
- if ( ciphersuite_list_index >= 0 &&
- (unsigned int)ciphersuite_list_index <
- sizeof(conf->ciphersuite_list)/sizeof(conf->ciphersuite_list[0]) )
- {
- conf->ciphersuite_list[ciphersuite_list_index] = ciphersuites;
- }
-}
-
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
const int *ciphersuites )
{
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
- ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
- ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
- ciphersuites);
-}
-
-const int *mbedtls_ssl_get_protocol_version_ciphersuites(
- const mbedtls_ssl_config *conf, int prot_version )
-{
- int ciphersuite_list_index =
- protocol_version_to_ciphersuites_list_index(prot_version);
- if ( ciphersuite_list_index >= 0 &&
- (unsigned int)ciphersuite_list_index <
- sizeof(conf->ciphersuite_list)/sizeof(conf->ciphersuite_list[0]) )
- {
- return conf->ciphersuite_list[ciphersuite_list_index];
- }
- else
- {
- return NULL;
- }
-}
-
-void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
- const int *ciphersuites,
- int major, int minor )
-{
- if( major != MBEDTLS_SSL_MAJOR_VERSION_3 )
- return;
-
- if( minor != MBEDTLS_SSL_MINOR_VERSION_3 )
- return;
-
- set_protocol_version_ciphersuites(conf, minor, ciphersuites);
+ conf->ciphersuite_list = ciphersuites;
}
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -4490,6 +4427,24 @@
return( (int) max_len );
}
+int mbedtls_ssl_get_max_in_record_payload( const mbedtls_ssl_context *ssl )
+{
+ size_t max_len = MBEDTLS_SSL_IN_CONTENT_LEN;
+
+#if !defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+ (void) ssl;
+#endif
+
+#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
+ const size_t mfl = mbedtls_ssl_get_input_max_frag_len( ssl );
+
+ if( max_len > mfl )
+ max_len = mfl;
+#endif
+
+ return( (int) max_len );
+}
+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl )
{
@@ -6278,12 +6233,7 @@
conf->max_major_ver = MBEDTLS_SSL_MAX_MAJOR_VERSION;
conf->max_minor_ver = MBEDTLS_SSL_MAX_MINOR_VERSION;
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
- ssl_preset_suiteb_ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
- ssl_preset_suiteb_ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
- ssl_preset_suiteb_ciphersuites);
+ conf->ciphersuite_list = ssl_preset_suiteb_ciphersuites;
#if defined(MBEDTLS_X509_CRT_PARSE_C)
conf->cert_profile = &mbedtls_x509_crt_profile_suiteb;
@@ -6317,13 +6267,7 @@
if( transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
conf->min_minor_ver = MBEDTLS_SSL_MINOR_VERSION_3;
#endif
- const int* default_ciphersuites = mbedtls_ssl_list_ciphersuites();
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_1,
- default_ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_2,
- default_ciphersuites);
- set_protocol_version_ciphersuites(conf, MBEDTLS_SSL_MINOR_VERSION_3,
- default_ciphersuites);
+ conf->ciphersuite_list = mbedtls_ssl_list_ciphersuites();
#if defined(MBEDTLS_X509_CRT_PARSE_C)
conf->cert_profile = &mbedtls_x509_crt_profile_default;
@@ -6600,22 +6544,10 @@
uint32_t *flags )
{
int ret = 0;
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
int usage = 0;
-#endif
-#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
const char *ext_oid;
size_t ext_len;
-#endif
-#if !defined(MBEDTLS_X509_CHECK_KEY_USAGE) && \
- !defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
- ((void) cert);
- ((void) cert_endpoint);
- ((void) flags);
-#endif
-
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
if( cert_endpoint == MBEDTLS_SSL_IS_SERVER )
{
/* Server part of the key exchange */
@@ -6657,11 +6589,7 @@
*flags |= MBEDTLS_X509_BADCERT_KEY_USAGE;
ret = -1;
}
-#else
- ((void) ciphersuite);
-#endif /* MBEDTLS_X509_CHECK_KEY_USAGE */
-#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
if( cert_endpoint == MBEDTLS_SSL_IS_SERVER )
{
ext_oid = MBEDTLS_OID_SERVER_AUTH;
@@ -6678,7 +6606,6 @@
*flags |= MBEDTLS_X509_BADCERT_EXT_KEY_USAGE;
ret = -1;
}
-#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
return( ret );
}
diff --git a/library/ssl_tls13_keys.c b/library/ssl_tls13_keys.c
index 4e8fb43..f1c8a12 100644
--- a/library/ssl_tls13_keys.c
+++ b/library/ssl_tls13_keys.c
@@ -24,6 +24,7 @@
#include "mbedtls/hkdf.h"
#include "ssl_misc.h"
#include "ssl_tls13_keys.h"
+#include "mbedtls/debug.h"
#include <stdint.h>
#include <string.h>
@@ -346,4 +347,356 @@
return( ret );
}
+int mbedtls_ssl_tls1_3_derive_early_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *early_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_early_secrets *derived )
+{
+ int ret;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ /*
+ * 0
+ * |
+ * v
+ * PSK -> HKDF-Extract = Early Secret
+ * |
+ * +-----> Derive-Secret(., "c e traffic", ClientHello)
+ * | = client_early_traffic_secret
+ * |
+ * +-----> Derive-Secret(., "e exp master", ClientHello)
+ * | = early_exporter_master_secret
+ * v
+ */
+
+ /* Create client_early_traffic_secret */
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ early_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( c_e_traffic ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->client_early_traffic_secret,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ /* Create early exporter */
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ early_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( e_exp_master ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->early_exporter_master_secret,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ return( 0 );
+}
+
+int mbedtls_ssl_tls1_3_derive_handshake_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *handshake_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_handshake_secrets *derived )
+{
+ int ret;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ /*
+ *
+ * Handshake Secret
+ * |
+ * +-----> Derive-Secret( ., "c hs traffic",
+ * | ClientHello...ServerHello )
+ * | = client_handshake_traffic_secret
+ * |
+ * +-----> Derive-Secret( ., "s hs traffic",
+ * | ClientHello...ServerHello )
+ * | = server_handshake_traffic_secret
+ *
+ */
+
+ /*
+ * Compute client_handshake_traffic_secret with
+ * Derive-Secret( ., "c hs traffic", ClientHello...ServerHello )
+ */
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ handshake_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( c_hs_traffic ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->client_handshake_traffic_secret,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ /*
+ * Compute server_handshake_traffic_secret with
+ * Derive-Secret( ., "s hs traffic", ClientHello...ServerHello )
+ */
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ handshake_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( s_hs_traffic ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->server_handshake_traffic_secret,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ return( 0 );
+}
+
+int mbedtls_ssl_tls1_3_derive_application_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *application_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_application_secrets *derived )
+{
+ int ret;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ /* Generate {client,server}_application_traffic_secret_0
+ *
+ * Master Secret
+ * |
+ * +-----> Derive-Secret( ., "c ap traffic",
+ * | ClientHello...server Finished )
+ * | = client_application_traffic_secret_0
+ * |
+ * +-----> Derive-Secret( ., "s ap traffic",
+ * | ClientHello...Server Finished )
+ * | = server_application_traffic_secret_0
+ * |
+ * +-----> Derive-Secret( ., "exp master",
+ * | ClientHello...server Finished)
+ * | = exporter_master_secret
+ *
+ */
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ application_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( c_ap_traffic ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->client_application_traffic_secret_N,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ application_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( s_ap_traffic ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->server_application_traffic_secret_N,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ application_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( exp_master ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->exporter_master_secret,
+ md_size );
+ if( ret != 0 )
+ return( ret );
+
+ return( 0 );
+}
+
+/* Generate resumption_master_secret for use with the ticket exchange.
+ *
+ * This is not integrated with mbedtls_ssl_tls1_3_derive_application_secrets()
+ * because it uses the transcript hash up to and including ClientFinished. */
+int mbedtls_ssl_tls1_3_derive_resumption_master_secret(
+ mbedtls_md_type_t md_type,
+ unsigned char const *application_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_application_secrets *derived )
+{
+ int ret;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ application_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( res_master ),
+ transcript, transcript_len,
+ MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED,
+ derived->resumption_master_secret,
+ md_size );
+
+ if( ret != 0 )
+ return( ret );
+
+ return( 0 );
+}
+
+static int ssl_tls1_3_calc_finished_core( mbedtls_md_type_t md_type,
+ unsigned char const *base_key,
+ unsigned char const *transcript,
+ unsigned char *dst )
+{
+ const mbedtls_md_info_t* const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ unsigned char finished_key[MBEDTLS_MD_MAX_SIZE];
+ int ret;
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ /* TLS 1.3 Finished message
+ *
+ * struct {
+ * opaque verify_data[Hash.length];
+ * } Finished;
+ *
+ * verify_data =
+ * HMAC( finished_key,
+ * Hash( Handshake Context +
+ * Certificate* +
+ * CertificateVerify* )
+ * )
+ *
+ * finished_key =
+ * HKDF-Expand-Label( BaseKey, "finished", "", Hash.length )
+ */
+
+ ret = mbedtls_ssl_tls1_3_hkdf_expand_label(
+ md_type, base_key, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( finished ),
+ NULL, 0,
+ finished_key, md_size );
+ if( ret != 0 )
+ goto exit;
+
+ ret = mbedtls_md_hmac( md_info, finished_key, md_size, transcript, md_size, dst );
+ if( ret != 0 )
+ goto exit;
+
+exit:
+
+ mbedtls_platform_zeroize( finished_key, sizeof( finished_key ) );
+ return( ret );
+}
+
+int mbedtls_ssl_tls1_3_create_psk_binder( mbedtls_ssl_context *ssl,
+ const mbedtls_md_type_t md_type,
+ unsigned char const *psk, size_t psk_len,
+ int psk_type,
+ unsigned char const *transcript,
+ unsigned char *result )
+{
+ int ret = 0;
+ unsigned char binder_key[MBEDTLS_MD_MAX_SIZE];
+ unsigned char early_secret[MBEDTLS_MD_MAX_SIZE];
+ mbedtls_md_info_t const *md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+
+#if !defined(MBEDTLS_DEBUG_C)
+ ssl = NULL; /* make sure we don't use it except for debug */
+ ((void) ssl);
+#endif
+
+ /* We should never call this function with an unknown hash,
+ * but add an assertion anyway. */
+ if( md_info == 0 )
+ return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
+
+ /*
+ * 0
+ * |
+ * v
+ * PSK -> HKDF-Extract = Early Secret
+ * |
+ * +-----> Derive-Secret(., "ext binder" | "res binder", "")
+ * | = binder_key
+ * v
+ */
+
+ ret = mbedtls_ssl_tls1_3_evolve_secret( md_type,
+ NULL, /* Old secret */
+ psk, psk_len, /* Input */
+ early_secret );
+ if( ret != 0 )
+ {
+ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_tls1_3_evolve_secret", ret );
+ goto exit;
+ }
+
+ if( psk_type == MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION )
+ {
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ early_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( res_binder ),
+ NULL, 0, MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED,
+ binder_key, md_size );
+ MBEDTLS_SSL_DEBUG_MSG( 4, ( "Derive Early Secret with 'res binder'" ) );
+ }
+ else
+ {
+ ret = mbedtls_ssl_tls1_3_derive_secret( md_type,
+ early_secret, md_size,
+ MBEDTLS_SSL_TLS1_3_LBL_WITH_LEN( ext_binder ),
+ NULL, 0, MBEDTLS_SSL_TLS1_3_CONTEXT_UNHASHED,
+ binder_key, md_size );
+ MBEDTLS_SSL_DEBUG_MSG( 4, ( "Derive Early Secret with 'ext binder'" ) );
+ }
+
+ if( ret != 0 )
+ {
+ MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ssl_tls1_3_derive_secret", ret );
+ goto exit;
+ }
+
+ /*
+ * The binding_value is computed in the same way as the Finished message
+ * but with the BaseKey being the binder_key.
+ */
+
+ ret = ssl_tls1_3_calc_finished_core( md_type, binder_key, transcript, result );
+ if( ret != 0 )
+ goto exit;
+
+ MBEDTLS_SSL_DEBUG_BUF( 3, "psk binder", result, md_size );
+
+exit:
+
+ mbedtls_platform_zeroize( early_secret, sizeof( early_secret ) );
+ mbedtls_platform_zeroize( binder_key, sizeof( binder_key ) );
+ return( ret );
+}
+
#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
diff --git a/library/ssl_tls13_keys.h b/library/ssl_tls13_keys.h
index 7089049..3b96998 100644
--- a/library/ssl_tls13_keys.h
+++ b/library/ssl_tls13_keys.h
@@ -70,6 +70,27 @@
#define MBEDTLS_SSL_TLS1_3_KEY_SCHEDULE_MAX_CONTEXT_LEN \
MBEDTLS_MD_MAX_SIZE
+typedef struct
+{
+ unsigned char binder_key [ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char client_early_traffic_secret [ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char early_exporter_master_secret[ MBEDTLS_MD_MAX_SIZE ];
+} mbedtls_ssl_tls1_3_early_secrets;
+
+typedef struct
+{
+ unsigned char client_handshake_traffic_secret[ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char server_handshake_traffic_secret[ MBEDTLS_MD_MAX_SIZE ];
+} mbedtls_ssl_tls1_3_handshake_secrets;
+
+typedef struct
+{
+ unsigned char client_application_traffic_secret_N[ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char server_application_traffic_secret_N[ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char exporter_master_secret [ MBEDTLS_MD_MAX_SIZE ];
+ unsigned char resumption_master_secret [ MBEDTLS_MD_MAX_SIZE ];
+} mbedtls_ssl_tls1_3_application_secrets;
+
/* Maximum desired length for expanded key material generated
* by HKDF-Expand-Label.
*
@@ -199,6 +220,179 @@
unsigned char *dstbuf, size_t buflen );
/**
+ * \brief Derive TLS 1.3 early data key material from early secret.
+ *
+ * This is a small wrapper invoking mbedtls_ssl_tls1_3_derive_secret()
+ * with the appropriate labels.
+ *
+ * <tt>
+ * Early Secret
+ * |
+ * +-----> Derive-Secret(., "c e traffic", ClientHello)
+ * | = client_early_traffic_secret
+ * |
+ * +-----> Derive-Secret(., "e exp master", ClientHello)
+ * . = early_exporter_master_secret
+ * .
+ * .
+ * </tt>
+ *
+ * \note To obtain the actual key and IV for the early data traffic,
+ * the client secret derived by this function need to be
+ * further processed by mbedtls_ssl_tls1_3_make_traffic_keys().
+ *
+ * \note The binder key, which is also generated from the early secret,
+ * is omitted here. Its calculation is part of the separate routine
+ * mbedtls_ssl_tls1_3_create_psk_binder().
+ *
+ * \param md_type The hash algorithm associated with the PSK for which
+ * early data key material is being derived.
+ * \param early_secret The early secret from which the early data key material
+ * should be derived. This must be a readable buffer whose
+ * length is the digest size of the hash algorithm
+ * represented by \p md_size.
+ * \param transcript The transcript of the handshake so far, calculated with
+ * respect to \p md_type. This must be a readable buffer
+ * whose length is the digest size of the hash algorithm
+ * represented by \p md_size.
+ * \param derived The address of the structure in which to store
+ * the early data key material.
+ *
+ * \returns \c 0 on success.
+ * \returns A negative error code on failure.
+ */
+int mbedtls_ssl_tls1_3_derive_early_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *early_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_early_secrets *derived );
+
+/**
+ * \brief Derive TLS 1.3 handshake key material from the handshake secret.
+ *
+ * This is a small wrapper invoking mbedtls_ssl_tls1_3_derive_secret()
+ * with the appropriate labels from the standard.
+ *
+ * <tt>
+ * Handshake Secret
+ * |
+ * +-----> Derive-Secret( ., "c hs traffic",
+ * | ClientHello...ServerHello )
+ * | = client_handshake_traffic_secret
+ * |
+ * +-----> Derive-Secret( ., "s hs traffic",
+ * . ClientHello...ServerHello )
+ * . = server_handshake_traffic_secret
+ * .
+ * </tt>
+ *
+ * \note To obtain the actual key and IV for the encrypted handshake traffic,
+ * the client and server secret derived by this function need to be
+ * further processed by mbedtls_ssl_tls1_3_make_traffic_keys().
+ *
+ * \param md_type The hash algorithm associated with the ciphersuite
+ * that's being used for the connection.
+ * \param handshake_secret The handshake secret from which the handshake key
+ * material should be derived. This must be a readable
+ * buffer whose length is the digest size of the hash
+ * algorithm represented by \p md_size.
+ * \param transcript The transcript of the handshake so far, calculated
+ * with respect to \p md_type. This must be a readable
+ * buffer whose length is the digest size of the hash
+ * algorithm represented by \p md_size.
+ * \param derived The address of the structure in which to
+ * store the handshake key material.
+ *
+ * \returns \c 0 on success.
+ * \returns A negative error code on failure.
+ */
+int mbedtls_ssl_tls1_3_derive_handshake_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *handshake_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_handshake_secrets *derived );
+
+/**
+ * \brief Derive TLS 1.3 application key material from the master secret.
+ *
+ * This is a small wrapper invoking mbedtls_ssl_tls1_3_derive_secret()
+ * with the appropriate labels from the standard.
+ *
+ * <tt>
+ * Master Secret
+ * |
+ * +-----> Derive-Secret( ., "c ap traffic",
+ * | ClientHello...server Finished )
+ * | = client_application_traffic_secret_0
+ * |
+ * +-----> Derive-Secret( ., "s ap traffic",
+ * | ClientHello...Server Finished )
+ * | = server_application_traffic_secret_0
+ * |
+ * +-----> Derive-Secret( ., "exp master",
+ * . ClientHello...server Finished)
+ * . = exporter_master_secret
+ * .
+ * </tt>
+ *
+ * \note To obtain the actual key and IV for the (0-th) application traffic,
+ * the client and server secret derived by this function need to be
+ * further processed by mbedtls_ssl_tls1_3_make_traffic_keys().
+ *
+ * \param md_type The hash algorithm associated with the ciphersuite
+ * that's being used for the connection.
+ * \param master_secret The master secret from which the application key
+ * material should be derived. This must be a readable
+ * buffer whose length is the digest size of the hash
+ * algorithm represented by \p md_size.
+ * \param transcript The transcript of the handshake up to and including
+ * the ServerFinished message, calculated with respect
+ * to \p md_type. This must be a readable buffer whose
+ * length is the digest size of the hash algorithm
+ * represented by \p md_type.
+ * \param derived The address of the structure in which to
+ * store the application key material.
+ *
+ * \returns \c 0 on success.
+ * \returns A negative error code on failure.
+ */
+int mbedtls_ssl_tls1_3_derive_application_secrets(
+ mbedtls_md_type_t md_type,
+ unsigned char const *master_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_application_secrets *derived );
+
+/**
+ * \brief Derive TLS 1.3 resumption master secret from the master secret.
+ *
+ * This is a small wrapper invoking mbedtls_ssl_tls1_3_derive_secret()
+ * with the appropriate labels from the standard.
+ *
+ * \param md_type The hash algorithm used in the application for which
+ * key material is being derived.
+ * \param application_secret The application secret from which the resumption master
+ * secret should be derived. This must be a readable
+ * buffer whose length is the digest size of the hash
+ * algorithm represented by \p md_size.
+ * \param transcript The transcript of the handshake up to and including
+ * the ClientFinished message, calculated with respect
+ * to \p md_type. This must be a readable buffer whose
+ * length is the digest size of the hash algorithm
+ * represented by \p md_type.
+ * \param transcript_len The length of \p transcript in Bytes.
+ * \param derived The address of the structure in which to
+ * store the resumption master secret.
+ *
+ * \returns \c 0 on success.
+ * \returns A negative error code on failure.
+ */
+int mbedtls_ssl_tls1_3_derive_resumption_master_secret(
+ mbedtls_md_type_t md_type,
+ unsigned char const *application_secret,
+ unsigned char const *transcript, size_t transcript_len,
+ mbedtls_ssl_tls1_3_application_secrets *derived );
+
+/**
* \brief Compute the next secret in the TLS 1.3 key schedule
*
* The TLS 1.3 key schedule proceeds as follows to compute
@@ -271,4 +465,37 @@
const unsigned char *input, size_t input_len,
unsigned char *secret_new );
+#define MBEDTLS_SSL_TLS1_3_PSK_EXTERNAL 0
+#define MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION 1
+
+/**
+ * \brief Calculate a TLS 1.3 PSK binder.
+ *
+ * \param ssl The SSL context. This is used for debugging only and may
+ * be \c NULL if MBEDTLS_DEBUG_C is disabled.
+ * \param md_type The hash algorithm associated to the PSK \p psk.
+ * \param psk The buffer holding the PSK for which to create a binder.
+ * \param psk_len The size of \p psk in bytes.
+ * \param psk_type This indicates whether the PSK \p psk is externally
+ * provisioned (#MBEDTLS_SSL_TLS1_3_PSK_EXTERNAL) or a
+ * resumption PSK (#MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION).
+ * \param transcript The handshake transcript up to the point where the
+ * PSK binder calculation happens. This must be readable,
+ * and its size must be equal to the digest size of
+ * the hash algorithm represented by \p md_type.
+ * \param result The address at which to store the PSK binder on success.
+ * This must be writable, and its size must be equal to the
+ * digest size of the hash algorithm represented by
+ * \p md_type.
+ *
+ * \returns \c 0 on success.
+ * \returns A negative error code on failure.
+ */
+int mbedtls_ssl_tls1_3_create_psk_binder( mbedtls_ssl_context *ssl,
+ const mbedtls_md_type_t md_type,
+ unsigned char const *psk, size_t psk_len,
+ int psk_type,
+ unsigned char const *transcript,
+ unsigned char *result );
+
#endif /* MBEDTLS_SSL_TLS1_3_KEYS_H */
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 8387de6..d4e0ffd 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -818,8 +818,7 @@
{
/*
* Set the parsing return code but continue parsing, in case this
- * extension is critical and MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
- * is configured.
+ * extension is critical.
*/
parse_ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
}
@@ -961,14 +960,12 @@
/* No parser found, skip extension */
*p = end_ext_octet;
-#if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
if( is_critical )
{
/* Data is marked as critical: fail */
return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_EXTENSIONS,
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) );
}
-#endif
continue;
}
@@ -1027,11 +1024,9 @@
start_ext_octet, end_ext_octet ) == 0 )
break;
-#if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
if( is_critical )
return( ret );
else
-#endif
/*
* If MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE is returned, then we
* cannot interpret or enforce the policy. However, it is up to
@@ -1049,11 +1044,9 @@
* supports, but there isn't an x509 parser for it,
* skip the extension.
*/
-#if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
if( is_critical )
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
else
-#endif
*p = end_ext_octet;
}
}
@@ -2238,7 +2231,6 @@
}
#endif /* MBEDTLS_X509_REMOVE_INFO */
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
unsigned int usage )
{
@@ -2261,9 +2253,7 @@
return( 0 );
}
-#endif
-#if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
const char *usage_oid,
size_t usage_len )
@@ -2293,7 +2283,6 @@
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
}
-#endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
#if defined(MBEDTLS_X509_CRL_PARSE_C)
/*
@@ -2344,14 +2333,12 @@
/*
* Check if the CA is configured to sign CRLs
*/
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
if( mbedtls_x509_crt_check_key_usage( ca,
MBEDTLS_X509_KU_CRL_SIGN ) != 0 )
{
flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED;
break;
}
-#endif
/*
* Check if CRL is correctly signed by the trusted CA
@@ -2488,13 +2475,11 @@
if( need_ca_bit && ! parent->ca_istrue )
return( -1 );
-#if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
if( need_ca_bit &&
mbedtls_x509_crt_check_key_usage( parent, MBEDTLS_X509_KU_KEY_CERT_SIGN ) != 0 )
{
return( -1 );
}
-#endif
return( 0 );
}
diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c
index c6b3132..3abf49e 100644
--- a/programs/pkey/dh_client.c
+++ b/programs/pkey/dh_client.c
@@ -92,7 +92,6 @@
mbedtls_aes_context aes;
mbedtls_net_init( &server_fd );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_SHA256 );
mbedtls_dhm_init( &dhm );
mbedtls_aes_init( &aes );
mbedtls_ctr_drbg_init( &ctr_drbg );
@@ -125,7 +124,7 @@
goto exit;
}
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
if( ( ret = mbedtls_mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
( ret = mbedtls_mpi_read_file( &rsa.E, 16, f ) ) != 0 )
diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c
index 63df77e..d87f75a 100644
--- a/programs/pkey/dh_server.c
+++ b/programs/pkey/dh_server.c
@@ -95,7 +95,6 @@
mbedtls_net_init( &listen_fd );
mbedtls_net_init( &client_fd );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_SHA256 );
mbedtls_dhm_init( &dhm );
mbedtls_aes_init( &aes );
mbedtls_ctr_drbg_init( &ctr_drbg );
@@ -131,7 +130,7 @@
goto exit;
}
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
if( ( ret = mbedtls_mpi_read_file( &N , 16, f ) ) != 0 ||
( ret = mbedtls_mpi_read_file( &E , 16, f ) ) != 0 ||
diff --git a/programs/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c
index 1ba8c73..88b80d1 100644
--- a/programs/pkey/rsa_decrypt.c
+++ b/programs/pkey/rsa_decrypt.c
@@ -90,7 +90,7 @@
mbedtls_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
diff --git a/programs/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c
index 6c654ad..1113622 100644
--- a/programs/pkey/rsa_encrypt.c
+++ b/programs/pkey/rsa_encrypt.c
@@ -87,7 +87,7 @@
fflush( stdout );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
diff --git a/programs/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c
index 26a8925..1dcfc52 100644
--- a/programs/pkey/rsa_genkey.c
+++ b/programs/pkey/rsa_genkey.c
@@ -75,7 +75,7 @@
const char *pers = "rsa_genkey";
mbedtls_ctr_drbg_init( &ctr_drbg );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP );
mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP );
diff --git a/programs/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c
index 1cfa0a8..427554f 100644
--- a/programs/pkey/rsa_sign.c
+++ b/programs/pkey/rsa_sign.c
@@ -67,7 +67,7 @@
char filename[512];
mbedtls_mpi N, P, Q, D, E, DP, DQ, QP;
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP );
diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c
index 9d5053a..26056dd 100644
--- a/programs/pkey/rsa_sign_pss.c
+++ b/programs/pkey/rsa_sign_pss.c
@@ -115,7 +115,13 @@
goto exit;
}
- mbedtls_rsa_set_padding( mbedtls_pk_rsa( pk ), MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA256 );
+ if( ( ret = mbedtls_rsa_set_padding( mbedtls_pk_rsa( pk ),
+ MBEDTLS_RSA_PKCS_V21,
+ MBEDTLS_MD_SHA256 ) ) != 0 )
+ {
+ mbedtls_printf( " failed\n ! Padding not supported\n" );
+ goto exit;
+ }
/*
* Compute the SHA-256 hash of the input file,
diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c
index 6aca171..0cd17b0 100644
--- a/programs/pkey/rsa_verify.c
+++ b/programs/pkey/rsa_verify.c
@@ -66,7 +66,7 @@
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
if( argc != 2 )
{
diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c
index 81b0fd6..527d799 100644
--- a/programs/pkey/rsa_verify_pss.c
+++ b/programs/pkey/rsa_verify_pss.c
@@ -98,7 +98,13 @@
goto exit;
}
- mbedtls_rsa_set_padding( mbedtls_pk_rsa( pk ), MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA256 );
+ if( ( ret = mbedtls_rsa_set_padding( mbedtls_pk_rsa( pk ),
+ MBEDTLS_RSA_PKCS_V21,
+ MBEDTLS_MD_SHA256 ) ) != 0 )
+ {
+ mbedtls_printf( " failed\n ! Invalid padding\n" );
+ goto exit;
+ }
/*
* Extract the RSA signature from the file
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 12b4bdf..1b53291 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -2021,10 +2021,10 @@
mbedtls_printf( " [ Record expansion is unknown ]\n" );
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- mbedtls_printf( " [ Maximum input fragment length is %u ]\n",
- (unsigned int) mbedtls_ssl_get_input_max_frag_len( &ssl ) );
- mbedtls_printf( " [ Maximum output fragment length is %u ]\n",
- (unsigned int) mbedtls_ssl_get_output_max_frag_len( &ssl ) );
+ mbedtls_printf( " [ Maximum incoming record payload length is %u ]\n",
+ (unsigned int) mbedtls_ssl_get_max_in_record_payload( &ssl ) );
+ mbedtls_printf( " [ Maximum outgoing record payload length is %u ]\n",
+ (unsigned int) mbedtls_ssl_get_max_out_record_payload( &ssl ) );
#endif
#if defined(MBEDTLS_SSL_ALPN)
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index ef55a7c..9a71140 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -93,7 +93,6 @@
#define DFL_ECJPAKE_PW NULL
#define DFL_PSK_LIST NULL
#define DFL_FORCE_CIPHER 0
-#define DFL_VERSION_SUITES NULL
#define DFL_RENEGOTIATION MBEDTLS_SSL_RENEGOTIATION_DISABLED
#define DFL_ALLOW_LEGACY -2
#define DFL_RENEGOTIATE 0
@@ -501,9 +500,6 @@
" force_version=%%s default: \"\" (none)\n" \
" options: tls1_2, dtls1_2\n" \
"\n" \
- " version_suites=a,b,c per-version ciphersuites\n" \
- " in order from tls1 to tls1_2\n" \
- " default: all enabled\n" \
" force_ciphersuite=<name> default: all enabled\n" \
" query_config=<name> return 0 if the specified\n" \
" configuration macro is defined and 1\n" \
@@ -565,7 +561,6 @@
char *psk_list; /* list of PSK id/key pairs for callback */
const char *ecjpake_pw; /* the EC J-PAKE password */
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
- const char *version_suites; /* per-version ciphersuites */
int renegotiation; /* enable / disable renegotiation */
int allow_legacy; /* allow legacy renegotiation */
int renegotiate; /* attempt renegotiation? */
@@ -1253,7 +1248,6 @@
{
int ret = 0, len, written, frags, exchanges_left;
int query_config_ret = 0;
- int version_suites[3][2];
io_ctx_t io_ctx;
unsigned char* buf = 0;
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
@@ -1481,7 +1475,6 @@
opt.psk_list = DFL_PSK_LIST;
opt.ecjpake_pw = DFL_ECJPAKE_PW;
opt.force_ciphersuite[0]= DFL_FORCE_CIPHER;
- opt.version_suites = DFL_VERSION_SUITES;
opt.renegotiation = DFL_RENEGOTIATION;
opt.allow_legacy = DFL_ALLOW_LEGACY;
opt.renegotiate = DFL_RENEGOTIATE;
@@ -1669,8 +1662,6 @@
}
else if( strcmp( p, "curves" ) == 0 )
opt.curves = q;
- else if( strcmp( p, "version_suites" ) == 0 )
- opt.version_suites = q;
else if( strcmp( p, "renegotiation" ) == 0 )
{
opt.renegotiation = (atoi( q )) ?
@@ -2036,10 +2027,6 @@
if( opt.min_version < ciphersuite_info->min_minor_ver )
{
opt.min_version = ciphersuite_info->min_minor_ver;
- /* DTLS starts with TLS 1.1 */
- if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
- opt.min_version < MBEDTLS_SSL_MINOR_VERSION_2 )
- opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
}
#if defined(MBEDTLS_USE_PSA_CRYPTO)
@@ -2067,47 +2054,6 @@
#endif /* MBEDTLS_USE_PSA_CRYPTO */
}
- if( opt.version_suites != NULL )
- {
- const char *name[3] = { 0 };
-
- /* Parse 4-element coma-separated list */
- for( i = 0, p = (char *) opt.version_suites;
- i < 3 && *p != '\0';
- i++ )
- {
- name[i] = p;
-
- /* Terminate the current string and move on to next one */
- while( *p != ',' && *p != '\0' )
- p++;
- if( *p == ',' )
- *p++ = '\0';
- }
-
- if( i != 3 )
- {
- mbedtls_printf( "too few values for version_suites\n" );
- ret = 1;
- goto exit;
- }
-
- memset( version_suites, 0, sizeof( version_suites ) );
-
- /* Get the suites identifiers from their name */
- for( i = 0; i < 3; i++ )
- {
- version_suites[i][0] = mbedtls_ssl_get_ciphersuite_id( name[i] );
-
- if( version_suites[i][0] == 0 )
- {
- mbedtls_printf( "unknown ciphersuite: '%s'\n", name[i] );
- ret = 2;
- goto usage;
- }
- }
- }
-
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
if( mbedtls_test_unhexify( cid, sizeof( cid ),
opt.cid_val, &cid_len ) != 0 )
@@ -2689,19 +2635,6 @@
if( opt.force_ciphersuite[0] != DFL_FORCE_CIPHER )
mbedtls_ssl_conf_ciphersuites( &conf, opt.force_ciphersuite );
- if( opt.version_suites != NULL )
- {
- mbedtls_ssl_conf_ciphersuites_for_version( &conf, version_suites[0],
- MBEDTLS_SSL_MAJOR_VERSION_3,
- MBEDTLS_SSL_MINOR_VERSION_1 );
- mbedtls_ssl_conf_ciphersuites_for_version( &conf, version_suites[1],
- MBEDTLS_SSL_MAJOR_VERSION_3,
- MBEDTLS_SSL_MINOR_VERSION_2 );
- mbedtls_ssl_conf_ciphersuites_for_version( &conf, version_suites[2],
- MBEDTLS_SSL_MAJOR_VERSION_3,
- MBEDTLS_SSL_MINOR_VERSION_3 );
- }
-
if( opt.allow_legacy != DFL_ALLOW_LEGACY )
mbedtls_ssl_conf_legacy_renegotiation( &conf, opt.allow_legacy );
#if defined(MBEDTLS_SSL_RENEGOTIATION)
@@ -3133,10 +3066,10 @@
mbedtls_printf( " [ Record expansion is unknown ]\n" );
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
- mbedtls_printf( " [ Maximum input fragment length is %u ]\n",
- (unsigned int) mbedtls_ssl_get_input_max_frag_len( &ssl ) );
- mbedtls_printf( " [ Maximum output fragment length is %u ]\n",
- (unsigned int) mbedtls_ssl_get_output_max_frag_len( &ssl ) );
+ mbedtls_printf( " [ Maximum incoming record payload length is %u ]\n",
+ (unsigned int) mbedtls_ssl_get_max_in_record_payload( &ssl ) );
+ mbedtls_printf( " [ Maximum outgoing record payload length is %u ]\n",
+ (unsigned int) mbedtls_ssl_get_max_out_record_payload( &ssl ) );
#endif
#if defined(MBEDTLS_SSL_ALPN)
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index e123453..5aa31f7 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -786,7 +786,7 @@
{
mbedtls_snprintf( title, sizeof( title ), "RSA-%d", keysize );
- mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &rsa );
mbedtls_rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 );
TIME_PUBLIC( title, " public",
diff --git a/scripts/config.py b/scripts/config.py
index 94fbdef..b85745a 100755
--- a/scripts/config.py
+++ b/scripts/config.py
@@ -192,7 +192,6 @@
'MBEDTLS_RSA_NO_CRT', # influences the use of RSA in X.509 and TLS
'MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN', # build dependency (clang+memsan)
'MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND', # build dependency (valgrind headers)
- 'MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION', # influences the use of X.509 in TLS
'MBEDTLS_X509_REMOVE_INFO', # removes a feature
])
diff --git a/scripts/generate_query_config.pl b/scripts/generate_query_config.pl
index 8c8c188..7276049 100755
--- a/scripts/generate_query_config.pl
+++ b/scripts/generate_query_config.pl
@@ -50,7 +50,6 @@
# throw errors.
my @excluded = qw(
MBEDTLS_SSL_CIPHERSUITES
-MBEDTLS_PARAM_FAILED
);
my $excluded_re = join '|', @excluded;
diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h
index 9bfe085..087f2de 100644
--- a/tests/include/test/helpers.h
+++ b/tests/include/test/helpers.h
@@ -175,95 +175,6 @@
int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
uint32_t a_len, uint32_t b_len );
-#if defined(MBEDTLS_CHECK_PARAMS)
-
-typedef struct
-{
- const char *failure_condition;
- const char *file;
- int line;
-}
-mbedtls_test_param_failed_location_record_t;
-
-/**
- * \brief Get the location record of the last call to
- * mbedtls_test_param_failed().
- *
- * \note The call expectation is set up and active until the next call to
- * mbedtls_test_param_failed_check_expected_call() or
- * mbedtls_param_failed() that cancels it.
- */
-void mbedtls_test_param_failed_get_location_record(
- mbedtls_test_param_failed_location_record_t *location_record );
-
-/**
- * \brief State that a call to mbedtls_param_failed() is expected.
- *
- * \note The call expectation is set up and active until the next call to
- * mbedtls_test_param_failed_check_expected_call() or
- * mbedtls_param_failed that cancel it.
- */
-void mbedtls_test_param_failed_expect_call( void );
-
-/**
- * \brief Check whether mbedtls_param_failed() has been called as expected.
- *
- * \note Check whether mbedtls_param_failed() has been called between the
- * last call to mbedtls_test_param_failed_expect_call() and the call
- * to this function.
- *
- * \return \c 0 Since the last call to mbedtls_param_failed_expect_call(),
- * mbedtls_param_failed() has been called.
- * \c -1 Otherwise.
- */
-int mbedtls_test_param_failed_check_expected_call( void );
-
-/**
- * \brief Get the address of the object of type jmp_buf holding the execution
- * state information used by mbedtls_param_failed() to do a long jump.
- *
- * \note If a call to mbedtls_param_failed() is not expected in the sense
- * that there is no call to mbedtls_test_param_failed_expect_call()
- * preceding it, then mbedtls_param_failed() will try to restore the
- * execution to the state stored in the jmp_buf object whose address
- * is returned by the present function.
- *
- * \note This function is intended to provide the parameter of the
- * setjmp() function to set-up where mbedtls_param_failed() should
- * long-jump if it has to. It is foreseen to be used as:
- *
- * setjmp( mbedtls_test_param_failed_get_state_buf() ).
- *
- * \note The type of the returned value is not jmp_buf as jmp_buf is an
- * an array type (C specification) and a function cannot return an
- * array type.
- *
- * \note The type of the returned value is not jmp_buf* as then the return
- * value couldn't be used by setjmp(), as its parameter's type is
- * jmp_buf.
- *
- * \return Address of the object of type jmp_buf holding the execution state
- * information used by mbedtls_param_failed() to do a long jump.
- */
-void* mbedtls_test_param_failed_get_state_buf( void );
-
-/**
- * \brief Reset the execution state used by mbedtls_param_failed() to do a
- * long jump.
- *
- * \note If a call to mbedtls_param_failed() is not expected in the sense
- * that there is no call to mbedtls_test_param_failed_expect_call()
- * preceding it, then mbedtls_param_failed() will try to restore the
- * execution state that this function reset.
- *
- * \note It is recommended to reset the execution state when the state
- * is not relevant anymore. That way an unexpected call to
- * mbedtls_param_failed() will not trigger a long jump with
- * undefined behavior but rather a long jump that will rather fault.
- */
-void mbedtls_test_param_failed_reset_state( void );
-#endif /* MBEDTLS_CHECK_PARAMS */
-
#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
#include "test/fake_external_rng_for_test.h"
#endif
diff --git a/tests/include/test/macros.h b/tests/include/test/macros.h
index b7b6e8f..87e86d3 100644
--- a/tests/include/test/macros.h
+++ b/tests/include/test/macros.h
@@ -58,13 +58,6 @@
* It allows a library function to return a value and return an error
* code that can be tested.
*
- * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
- * callback, MBEDTLS_PARAM_FAILED(), will be assumed to be a test
- * failure.
- *
- * This macro is not suitable for negative parameter validation tests,
- * as it assumes the test step will not create an error.
- *
* Failing the test means:
* - Mark this test case as failed.
* - Print a message identifying the failure.
@@ -181,107 +174,6 @@
} \
} while( 0 )
-#if defined(MBEDTLS_CHECK_PARAMS) && !defined(MBEDTLS_PARAM_FAILED_ALT)
-/**
- * \brief This macro tests the statement passed to it as a test step or
- * individual test in a test case. The macro assumes the test will fail
- * and will generate an error.
- *
- * It allows a library function to return a value and tests the return
- * code on return to confirm the given error code was returned.
- *
- * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
- * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
- * expected failure, and the test will pass.
- *
- * This macro is intended for negative parameter validation tests,
- * where the failing function may return an error value or call
- * MBEDTLS_PARAM_FAILED() to indicate the error.
- *
- * \param PARAM_ERROR_VALUE The expected error code.
- *
- * \param TEST The test expression to be tested.
- */
-#define TEST_INVALID_PARAM_RET( PARAM_ERR_VALUE, TEST ) \
- do { \
- mbedtls_test_param_failed_expect_call( ); \
- if( ( ( TEST ) != ( PARAM_ERR_VALUE ) ) || \
- ( mbedtls_test_param_failed_check_expected_call( ) != 0 ) ) \
- { \
- mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
- goto exit; \
- } \
- mbedtls_test_param_failed_check_expected_call( ); \
- } while( 0 )
-
-/**
- * \brief This macro tests the statement passed to it as a test step or
- * individual test in a test case. The macro assumes the test will fail
- * and will generate an error.
- *
- * It assumes the library function under test cannot return a value and
- * assumes errors can only be indicated byt calls to
- * MBEDTLS_PARAM_FAILED().
- *
- * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
- * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
- * expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
- * can be made.
- *
- * This macro is intended for negative parameter validation tests,
- * where the failing function can only return an error by calling
- * MBEDTLS_PARAM_FAILED() to indicate the error.
- *
- * \param TEST The test expression to be tested.
- */
-#define TEST_INVALID_PARAM( TEST ) \
- do { \
- memcpy( jmp_tmp, mbedtls_test_param_failed_get_state_buf( ), \
- sizeof( jmp_tmp ) ); \
- if( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) \
- { \
- TEST; \
- mbedtls_test_fail( #TEST, __LINE__, __FILE__ ); \
- goto exit; \
- } \
- mbedtls_test_param_failed_reset_state( ); \
- } while( 0 )
-#endif /* MBEDTLS_CHECK_PARAMS && !MBEDTLS_PARAM_FAILED_ALT */
-
-/**
- * \brief This macro tests the statement passed to it as a test step or
- * individual test in a test case. The macro assumes the test will not fail.
- *
- * It assumes the library function under test cannot return a value and
- * assumes errors can only be indicated by calls to
- * MBEDTLS_PARAM_FAILED().
- *
- * When MBEDTLS_CHECK_PARAMS is enabled, calls to the parameter failure
- * callback, MBEDTLS_PARAM_FAILED(), are assumed to indicate the
- * expected failure. If MBEDTLS_CHECK_PARAMS is not enabled, no test
- * can be made.
- *
- * This macro is intended to test that functions returning void
- * accept all of the parameter values they're supposed to accept - eg
- * that they don't call MBEDTLS_PARAM_FAILED() when a parameter
- * that's allowed to be NULL happens to be NULL.
- *
- * Note: for functions that return something other that void,
- * checking that they accept all the parameters they're supposed to
- * accept is best done by using TEST_ASSERT() and checking the return
- * value as well.
- *
- * Note: this macro is available even when #MBEDTLS_CHECK_PARAMS is
- * disabled, as it makes sense to check that the functions accept all
- * legal values even if this option is disabled - only in that case,
- * the test is more about whether the function segfaults than about
- * whether it invokes MBEDTLS_PARAM_FAILED().
- *
- * \param TEST The test expression to be tested.
- */
-#define TEST_VALID_PARAM( TEST ) \
- TEST_ASSERT( ( TEST, 1 ) );
-
#define TEST_HELPER_ASSERT(a) if( !( a ) ) \
{ \
mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
diff --git a/tests/include/test/random.h b/tests/include/test/random.h
index 5e7e4e6..6428280 100644
--- a/tests/include/test/random.h
+++ b/tests/include/test/random.h
@@ -36,8 +36,11 @@
typedef struct
{
- unsigned char *buf;
+ unsigned char *buf; /* Pointer to a buffer of length bytes. */
size_t length;
+ /* If fallback_f_rng is NULL, fail after delivering length bytes. */
+ int ( *fallback_f_rng )( void*, unsigned char *, size_t );
+ void *fallback_p_rng;
} mbedtls_test_rnd_buf_info;
/**
@@ -67,24 +70,25 @@
size_t len );
/**
- * This function only returns zeros
+ * This function only returns zeros.
*
- * rng_state shall be NULL.
+ * \p rng_state shall be \c NULL.
*/
int mbedtls_test_rnd_zero_rand( void *rng_state,
unsigned char *output,
size_t len );
/**
- * This function returns random based on a buffer it receives.
+ * This function returns random data based on a buffer it receives.
*
- * rng_state shall be a pointer to a rnd_buf_info structure.
+ * \p rng_state shall be a pointer to a #mbedtls_test_rnd_buf_info structure.
*
* The number of bytes released from the buffer on each call to
- * the random function is specified by per_call. (Can be between
- * 1 and 4)
+ * the random function is specified by \p len.
*
- * After the buffer is empty it will return rand();
+ * After the buffer is empty, this function will call the fallback RNG in the
+ * #mbedtls_test_rnd_buf_info structure if there is one, and
+ * will return #MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise.
*/
int mbedtls_test_rnd_buffer_rand( void *rng_state,
unsigned char *output,
@@ -96,7 +100,7 @@
* Pseudo random is based on the XTEA encryption algorithm to
* generate pseudorandom.
*
- * rng_state shall be a pointer to a rnd_pseudo_info structure.
+ * \p rng_state shall be a pointer to a #mbedtls_test_rnd_pseudo_info structure.
*/
int mbedtls_test_rnd_pseudo_rand( void *rng_state,
unsigned char *output,
diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh
index 8e163a9..2df65a5 100755
--- a/tests/scripts/all.sh
+++ b/tests/scripts/all.sh
@@ -1085,26 +1085,8 @@
# no SSL tests as they all depend on having a DRBG
}
-component_test_new_ecdh_context () {
- msg "build: new ECDH context (ASan build)" # ~ 6 min
- scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
- CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
- make
-
- msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
- make test
-
- msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
- if_build_succeeded tests/ssl-opt.sh -f ECDH
-
- msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
- # Exclude some symmetric ciphers that are redundant here to gain time.
- if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
-}
-
component_test_everest () {
msg "build: Everest ECDH context (ASan build)" # ~ 6 min
- scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
make
@@ -1122,7 +1104,6 @@
component_test_everest_curve25519_only () {
msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
- scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
scripts/config.py unset MBEDTLS_ECDSA_C
scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
@@ -1853,38 +1834,6 @@
make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
}
-component_test_check_params_functionality () {
- msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
- scripts/config.py full # includes CHECK_PARAMS
- # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
- scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
- make CC=gcc CFLAGS='-Werror -O1' all test
-}
-
-component_test_check_params_without_platform () {
- msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
- scripts/config.py full # includes CHECK_PARAMS
- # Keep MBEDTLS_PARAM_FAILED as assert.
- scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
- scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
- scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
- scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
- scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
- scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
- scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
- scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
- scripts/config.py unset MBEDTLS_PLATFORM_C
- make CC=gcc CFLAGS='-Werror -O1' all test
-}
-
-component_test_check_params_silent () {
- msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
- scripts/config.py full # includes CHECK_PARAMS
- # Set MBEDTLS_PARAM_FAILED to nothing.
- sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
- make CC=gcc CFLAGS='-Werror -O1' all test
-}
-
component_test_no_platform () {
# Full configuration build, without platform support, file IO and net sockets.
# This should catch missing mbedtls_printf definitions, and by disabling file
@@ -2326,7 +2275,6 @@
component_test_m32_everest () {
msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
- scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
diff --git a/tests/src/helpers.c b/tests/src/helpers.c
index b7c9867..cac6d4c 100644
--- a/tests/src/helpers.c
+++ b/tests/src/helpers.c
@@ -19,27 +19,9 @@
#include <test/macros.h>
#include <string.h>
-#if defined(MBEDTLS_CHECK_PARAMS)
-#include <setjmp.h>
-#endif
-
/*----------------------------------------------------------------------------*/
/* Static global variables */
-#if defined(MBEDTLS_CHECK_PARAMS)
-typedef struct
-{
- uint8_t expected_call;
- uint8_t expected_call_happened;
-
- jmp_buf state;
-
- mbedtls_test_param_failed_location_record_t location_record;
-}
-param_failed_ctx_t;
-static param_failed_ctx_t param_failed_ctx;
-#endif
-
#if defined(MBEDTLS_PLATFORM_C)
static mbedtls_platform_context platform_ctx;
#endif
@@ -222,67 +204,6 @@
return ret;
}
-#if defined(MBEDTLS_CHECK_PARAMS)
-void mbedtls_test_param_failed_get_location_record(
- mbedtls_test_param_failed_location_record_t *location_record )
-{
- *location_record = param_failed_ctx.location_record;
-}
-
-void mbedtls_test_param_failed_expect_call( void )
-{
- param_failed_ctx.expected_call_happened = 0;
- param_failed_ctx.expected_call = 1;
-}
-
-int mbedtls_test_param_failed_check_expected_call( void )
-{
- param_failed_ctx.expected_call = 0;
-
- if( param_failed_ctx.expected_call_happened != 0 )
- return( 0 );
-
- return( -1 );
-}
-
-void* mbedtls_test_param_failed_get_state_buf( void )
-{
- return ¶m_failed_ctx.state;
-}
-
-void mbedtls_test_param_failed_reset_state( void )
-{
- memset( param_failed_ctx.state, 0, sizeof( param_failed_ctx.state ) );
-}
-
-void mbedtls_param_failed( const char *failure_condition,
- const char *file,
- int line )
-{
- /* Record the location of the failure */
- param_failed_ctx.location_record.failure_condition = failure_condition;
- param_failed_ctx.location_record.file = file;
- param_failed_ctx.location_record.line = line;
-
- /* If we are testing the callback function... */
- if( param_failed_ctx.expected_call != 0 )
- {
- param_failed_ctx.expected_call = 0;
- param_failed_ctx.expected_call_happened = 1;
- }
- else
- {
- /* ...else try a long jump. If the execution state has not been set-up
- * or reset then the long jump buffer is all zero's and the call will
- * with high probability fault, emphasizing there is something to look
- * at.
- */
-
- longjmp( param_failed_ctx.state, 1 );
- }
-}
-#endif /* MBEDTLS_CHECK_PARAMS */
-
#if defined(MBEDTLS_TEST_HOOKS)
void mbedtls_test_err_add_check( int high, int low,
const char *file, int line )
diff --git a/tests/src/random.c b/tests/src/random.c
index e01bd4d..7f3f401 100644
--- a/tests/src/random.c
+++ b/tests/src/random.c
@@ -35,6 +35,8 @@
#include <test/random.h>
#include <string.h>
+#include <mbedtls/entropy.h>
+
int mbedtls_test_rnd_std_rand( void *rng_state,
unsigned char *output,
size_t len )
@@ -91,8 +93,16 @@
}
if( len - use_len > 0 )
- return( mbedtls_test_rnd_std_rand( NULL, output + use_len,
- len - use_len ) );
+ {
+ if( info->fallback_f_rng != NULL )
+ {
+ return( info->fallback_f_rng( info->fallback_p_rng,
+ output + use_len,
+ len - use_len ) );
+ }
+ else
+ return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
+ }
return( 0 );
}
diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh
index 1d49dc5..d122111 100755
--- a/tests/ssl-opt.sh
+++ b/tests/ssl-opt.sh
@@ -2872,10 +2872,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3" \
0 \
- -c "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -c "Maximum output fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum output fragment length is $MAX_CONTENT_LEN" \
+ -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
-C "client hello, adding max_fragment_length extension" \
-S "found max fragment length extension" \
-S "server hello, max_fragment_length extension" \
@@ -2886,10 +2886,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
0 \
- -c "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -c "Maximum output fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum output fragment length is $MAX_CONTENT_LEN" \
+ -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
-C "client hello, adding max_fragment_length extension" \
-S "found max fragment length extension" \
-S "server hello, max_fragment_length extension" \
@@ -2903,10 +2903,10 @@
"$P_SRV debug_level=3 dtls=1" \
"$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
1 \
- -c "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -c "Maximum output fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum output fragment length is $MAX_CONTENT_LEN" \
+ -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
-C "client hello, adding max_fragment_length extension" \
-S "found max fragment length extension" \
-S "server hello, max_fragment_length extension" \
@@ -2922,10 +2922,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3 request_size=$(( $MAX_CONTENT_LEN + 1))" \
0 \
- -C "Maximum input fragment length is 16384" \
- -C "Maximum output fragment length is 16384" \
- -S "Maximum input fragment length is 16384" \
- -S "Maximum output fragment length is 16384" \
+ -C "Maximum incoming record payload length is 16384" \
+ -C "Maximum outgoing record payload length is 16384" \
+ -S "Maximum incoming record payload length is 16384" \
+ -S "Maximum outgoing record payload length is 16384" \
-c "$(( $MAX_CONTENT_LEN + 1)) bytes written in 2 fragments" \
-s "$MAX_CONTENT_LEN bytes read" \
-s "1 bytes read"
@@ -2935,10 +2935,10 @@
"$P_SRV debug_level=3 dtls=1" \
"$P_CLI debug_level=3 dtls=1 request_size=$(( $MAX_CONTENT_LEN + 1))" \
1 \
- -C "Maximum input fragment length is 16384" \
- -C "Maximum output fragment length is 16384" \
- -S "Maximum input fragment length is 16384" \
- -S "Maximum output fragment length is 16384" \
+ -C "Maximum incoming record payload length is 16384" \
+ -C "Maximum outgoing record payload length is 16384" \
+ -S "Maximum incoming record payload length is 16384" \
+ -S "Maximum outgoing record payload length is 16384" \
-c "fragment larger than.*maximum "
requires_config_enabled MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
@@ -2946,10 +2946,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3 max_frag_len=4096" \
0 \
- -c "Maximum input fragment length is 4096" \
- -c "Maximum output fragment length is 4096" \
- -s "Maximum input fragment length is 4096" \
- -s "Maximum output fragment length is 4096" \
+ -c "Maximum incoming record payload length is 4096" \
+ -c "Maximum outgoing record payload length is 4096" \
+ -s "Maximum incoming record payload length is 4096" \
+ -s "Maximum outgoing record payload length is 4096" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -2960,10 +2960,10 @@
"$P_SRV debug_level=3 max_frag_len=1024" \
"$P_CLI debug_level=3 max_frag_len=512" \
0 \
- -c "Maximum input fragment length is 512" \
- -c "Maximum output fragment length is 512" \
- -s "Maximum input fragment length is 512" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 512" \
+ -c "Maximum outgoing record payload length is 512" \
+ -s "Maximum incoming record payload length is 512" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -2974,10 +2974,10 @@
"$P_SRV debug_level=3 max_frag_len=2048" \
"$P_CLI debug_level=3 max_frag_len=512" \
0 \
- -c "Maximum input fragment length is 512" \
- -c "Maximum output fragment length is 512" \
- -s "Maximum input fragment length is 512" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 512" \
+ -c "Maximum outgoing record payload length is 512" \
+ -s "Maximum incoming record payload length is 512" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -2988,10 +2988,10 @@
"$P_SRV debug_level=3 max_frag_len=4096" \
"$P_CLI debug_level=3 max_frag_len=512" \
0 \
- -c "Maximum input fragment length is 512" \
- -c "Maximum output fragment length is 512" \
- -s "Maximum input fragment length is 512" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 512" \
+ -c "Maximum outgoing record payload length is 512" \
+ -s "Maximum incoming record payload length is 512" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3002,10 +3002,10 @@
"$P_SRV debug_level=3 max_frag_len=512" \
"$P_CLI debug_level=3 max_frag_len=1024" \
0 \
- -c "Maximum input fragment length is 1024" \
- -c "Maximum output fragment length is 1024" \
- -s "Maximum input fragment length is 1024" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 1024" \
+ -c "Maximum outgoing record payload length is 1024" \
+ -s "Maximum incoming record payload length is 1024" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3016,10 +3016,10 @@
"$P_SRV debug_level=3 max_frag_len=2048" \
"$P_CLI debug_level=3 max_frag_len=1024" \
0 \
- -c "Maximum input fragment length is 1024" \
- -c "Maximum output fragment length is 1024" \
- -s "Maximum input fragment length is 1024" \
- -s "Maximum output fragment length is 1024" \
+ -c "Maximum incoming record payload length is 1024" \
+ -c "Maximum outgoing record payload length is 1024" \
+ -s "Maximum incoming record payload length is 1024" \
+ -s "Maximum outgoing record payload length is 1024" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3030,10 +3030,10 @@
"$P_SRV debug_level=3 max_frag_len=4096" \
"$P_CLI debug_level=3 max_frag_len=1024" \
0 \
- -c "Maximum input fragment length is 1024" \
- -c "Maximum output fragment length is 1024" \
- -s "Maximum input fragment length is 1024" \
- -s "Maximum output fragment length is 1024" \
+ -c "Maximum incoming record payload length is 1024" \
+ -c "Maximum outgoing record payload length is 1024" \
+ -s "Maximum incoming record payload length is 1024" \
+ -s "Maximum outgoing record payload length is 1024" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3044,10 +3044,10 @@
"$P_SRV debug_level=3 max_frag_len=512" \
"$P_CLI debug_level=3 max_frag_len=2048" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3058,10 +3058,10 @@
"$P_SRV debug_level=3 max_frag_len=1024" \
"$P_CLI debug_level=3 max_frag_len=2048" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 1024" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 1024" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3072,10 +3072,10 @@
"$P_SRV debug_level=3 max_frag_len=4096" \
"$P_CLI debug_level=3 max_frag_len=2048" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 2048" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 2048" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3086,10 +3086,10 @@
"$P_SRV debug_level=3 max_frag_len=512" \
"$P_CLI debug_level=3 max_frag_len=4096" \
0 \
- -c "Maximum input fragment length is 4096" \
- -c "Maximum output fragment length is 4096" \
- -s "Maximum input fragment length is 4096" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 4096" \
+ -c "Maximum outgoing record payload length is 4096" \
+ -s "Maximum incoming record payload length is 4096" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3100,10 +3100,10 @@
"$P_SRV debug_level=3 max_frag_len=1024" \
"$P_CLI debug_level=3 max_frag_len=4096" \
0 \
- -c "Maximum input fragment length is 4096" \
- -c "Maximum output fragment length is 4096" \
- -s "Maximum input fragment length is 4096" \
- -s "Maximum output fragment length is 1024" \
+ -c "Maximum incoming record payload length is 4096" \
+ -c "Maximum outgoing record payload length is 4096" \
+ -s "Maximum incoming record payload length is 4096" \
+ -s "Maximum outgoing record payload length is 1024" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3114,10 +3114,10 @@
"$P_SRV debug_level=3 max_frag_len=2048" \
"$P_CLI debug_level=3 max_frag_len=4096" \
0 \
- -c "Maximum input fragment length is 4096" \
- -c "Maximum output fragment length is 4096" \
- -s "Maximum input fragment length is 4096" \
- -s "Maximum output fragment length is 2048" \
+ -c "Maximum incoming record payload length is 4096" \
+ -c "Maximum outgoing record payload length is 4096" \
+ -s "Maximum incoming record payload length is 4096" \
+ -s "Maximum outgoing record payload length is 2048" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3128,10 +3128,10 @@
"$P_SRV debug_level=3 max_frag_len=4096" \
"$P_CLI debug_level=3" \
0 \
- -c "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -c "Maximum output fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum input fragment length is $MAX_CONTENT_LEN" \
- -s "Maximum output fragment length is 4096" \
+ -c "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -c "Maximum outgoing record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum incoming record payload length is $MAX_CONTENT_LEN" \
+ -s "Maximum outgoing record payload length is 4096" \
-C "client hello, adding max_fragment_length extension" \
-S "found max fragment length extension" \
-S "server hello, max_fragment_length extension" \
@@ -3143,8 +3143,8 @@
"$G_SRV" \
"$P_CLI debug_level=3 max_frag_len=4096" \
0 \
- -c "Maximum input fragment length is 4096" \
- -c "Maximum output fragment length is 4096" \
+ -c "Maximum incoming record payload length is 4096" \
+ -c "Maximum outgoing record payload length is 4096" \
-c "client hello, adding max_fragment_length extension" \
-c "found max_fragment_length extension"
@@ -3153,10 +3153,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3 max_frag_len=2048 request_size=2048" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 2048" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 2048" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3169,10 +3169,10 @@
"$P_SRV debug_level=3" \
"$P_CLI debug_level=3 max_frag_len=2048 request_size=2345" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 2048" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 2048" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3186,10 +3186,10 @@
"$P_SRV debug_level=3 dtls=1" \
"$P_CLI debug_level=3 dtls=1 max_frag_len=2048 request_size=2345" \
1 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 2048" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 2048" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -3296,10 +3296,10 @@
"$P_SRV debug_level=3 exchanges=2 renegotiation=1 auth_mode=optional renegotiate=1 max_frag_len=512" \
"$P_CLI debug_level=3 exchanges=2 renegotiation=1 renegotiate=1 max_frag_len=2048 force_ciphersuite=TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8" \
0 \
- -c "Maximum input fragment length is 2048" \
- -c "Maximum output fragment length is 2048" \
- -s "Maximum input fragment length is 2048" \
- -s "Maximum output fragment length is 512" \
+ -c "Maximum incoming record payload length is 2048" \
+ -c "Maximum outgoing record payload length is 2048" \
+ -s "Maximum incoming record payload length is 2048" \
+ -s "Maximum outgoing record payload length is 512" \
-c "client hello, adding max_fragment_length extension" \
-s "found max fragment length extension" \
-s "server hello, max_fragment_length extension" \
@@ -5614,17 +5614,6 @@
force_ciphersuite=TLS-ECJPAKE-WITH-AES-128-CCM-8" \
0
-# Tests for ciphersuites per version
-
-requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
-requires_config_enabled MBEDTLS_CAMELLIA_C
-requires_config_enabled MBEDTLS_AES_C
-run_test "Per-version suites: TLS 1.2" \
- "$P_SRV version_suites=TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \
- "$P_CLI force_version=tls1_2" \
- 0 \
- -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256"
-
# Test for ClientHello without extensions
requires_gnutls
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index 2ef07fa..89ba0b0 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -28,11 +28,6 @@
#include "mbedtls/memory_buffer_alloc.h"
#endif
-#if defined(MBEDTLS_CHECK_PARAMS)
-#include "mbedtls/platform_util.h"
-#include <setjmp.h>
-#endif
-
#ifdef _MSC_VER
#include <basetsd.h>
typedef UINT8 uint8_t;
@@ -78,10 +73,6 @@
/*----------------------------------------------------------------------------*/
/* Global variables */
-#if defined(MBEDTLS_CHECK_PARAMS)
-jmp_buf jmp_tmp;
-#endif
-
/*----------------------------------------------------------------------------*/
/* Helper flags for complex dependencies */
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index ac00f45..491de6d 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -159,50 +159,6 @@
};
/**
- * \brief Execute the test function.
- *
- * This is a wrapper function around the test function execution
- * to allow the setjmp() call used to catch any calls to the
- * parameter failure callback, to be used. Calls to setjmp()
- * can invalidate the state of any local auto variables.
- *
- * \param fp Function pointer to the test function.
- * \param params Parameters to pass to the #TestWrapper_t wrapper function.
- *
- */
-void execute_function_ptr(TestWrapper_t fp, void **params)
-{
-#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
- mbedtls_test_enable_insecure_external_rng( );
-#endif
-
-#if defined(MBEDTLS_CHECK_PARAMS)
- mbedtls_test_param_failed_location_record_t location_record;
-
- if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
- {
- fp( params );
- }
- else
- {
- /* Unexpected parameter validation error */
- mbedtls_test_param_failed_get_location_record( &location_record );
- mbedtls_test_fail( location_record.failure_condition,
- location_record.line,
- location_record.file );
- }
-
- mbedtls_test_param_failed_reset_state( );
-#else
- fp( params );
-#endif
-
-#if defined(MBEDTLS_TEST_MUTEX_USAGE)
- mbedtls_test_mutex_usage_check( );
-#endif /* MBEDTLS_TEST_MUTEX_USAGE */
-}
-
-/**
* \brief Dispatches test functions based on function index.
*
* \param func_idx Test function index.
@@ -222,7 +178,17 @@
{
fp = test_funcs[func_idx];
if ( fp )
- execute_function_ptr(fp, params);
+ {
+ #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
+ mbedtls_test_enable_insecure_external_rng( );
+ #endif
+
+ fp( params );
+
+ #if defined(MBEDTLS_TEST_MUTEX_USAGE)
+ mbedtls_test_mutex_usage_check( );
+ #endif /* MBEDTLS_TEST_MUTEX_USAGE */
+ }
else
ret = DISPATCH_UNSUPPORTED_SUITE;
}
diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function
index 754a167..aa3df92 100644
--- a/tests/suites/test_suite_aes.function
+++ b/tests/suites/test_suite_aes.function
@@ -206,9 +206,6 @@
mbedtls_aes_xts_init( &ctx );
memset( data_unit, 0x00, sizeof( data_unit ) );
-
- /* Valid pointers are passed for builds with MBEDTLS_CHECK_PARAMS, as
- * otherwise we wouldn't get to the size check we're interested in. */
TEST_ASSERT( mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, length, data_unit, src, output ) == retval );
}
/* END_CASE */
@@ -359,194 +356,41 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void aes_check_params( )
+/* BEGIN_CASE depends_on:NOT_DEFINED */
+void aes_invalid_mode( )
{
mbedtls_aes_context aes_ctx;
-#if defined(MBEDTLS_CIPHER_MODE_XTS)
- mbedtls_aes_xts_context xts_ctx;
-#endif
- const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
const unsigned char in[16] = { 0 };
unsigned char out[16];
- size_t size;
- const int valid_mode = MBEDTLS_AES_ENCRYPT;
const int invalid_mode = 42;
- TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) );
-#if defined(MBEDTLS_CIPHER_MODE_XTS)
- TEST_INVALID_PARAM( mbedtls_aes_xts_init( NULL ) );
-#endif
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_setkey_enc( NULL, key, 128 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_setkey_enc( &aes_ctx, NULL, 128 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_setkey_dec( NULL, key, 128 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_setkey_dec( &aes_ctx, NULL, 128 ) );
-
-#if defined(MBEDTLS_CIPHER_MODE_XTS)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_xts_setkey_enc( NULL, key, 128 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_xts_setkey_enc( &xts_ctx, NULL, 128 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_xts_setkey_dec( NULL, key, 128 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) );
-#endif
-
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ecb( NULL,
- valid_mode, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ecb( &aes_ctx,
- invalid_mode, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ecb( &aes_ctx,
- valid_mode, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ecb( &aes_ctx,
- valid_mode, in, NULL ) );
+ TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_ecb( &aes_ctx, invalid_mode, in, out ) );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( NULL,
- valid_mode, 16,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( &aes_ctx,
- invalid_mode, 16,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( &aes_ctx,
- valid_mode, 16,
- NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( &aes_ctx,
- valid_mode, 16,
- out, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cbc( &aes_ctx,
- valid_mode, 16,
- out, in, NULL ) );
+ TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cbc( &aes_ctx, invalid_mode, 16,
+ out, in, out ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_XTS)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( NULL,
- valid_mode, 16,
- in, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( &xts_ctx,
- invalid_mode, 16,
- in, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( &xts_ctx,
- valid_mode, 16,
- NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( &xts_ctx,
- valid_mode, 16,
- in, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_xts( &xts_ctx,
- valid_mode, 16,
- in, in, NULL ) );
+ mbedtls_aes_xts_context xts_ctx;
+
+ TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_xts( &xts_ctx, invalid_mode, 16,
+ in, in, out ) );
#endif /* MBEDTLS_CIPHER_MODE_XTS */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( NULL,
- valid_mode, 16,
- &size, out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx,
- invalid_mode, 16,
- &size, out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx,
- valid_mode, 16,
- NULL, out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx,
- valid_mode, 16,
- &size, NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx,
- valid_mode, 16,
- &size, out, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb128( &aes_ctx,
- valid_mode, 16,
- &size, out, in, NULL ) );
+ size_t size;
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( NULL,
- valid_mode, 16,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( &aes_ctx,
- invalid_mode, 16,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( &aes_ctx,
- valid_mode, 16,
- NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( &aes_ctx,
- valid_mode, 16,
- out, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_cfb8( &aes_ctx,
- valid_mode, 16,
- out, in, NULL ) );
+ TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cfb128( &aes_ctx, invalid_mode, 16,
+ &size, out, in, out ) );
+ TEST_EQUAL( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_crypt_cfb8( &aes_ctx, invalid_mode, 16,
+ out, in, out ) );
#endif /* MBEDTLS_CIPHER_MODE_CFB */
-
-#if defined(MBEDTLS_CIPHER_MODE_OFB)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ofb( NULL, 16,
- &size, out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ofb( &aes_ctx, 16,
- NULL, out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ofb( &aes_ctx, 16,
- &size, NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ofb( &aes_ctx, 16,
- &size, out, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ofb( &aes_ctx, 16,
- &size, out, in, NULL ) );
-#endif /* MBEDTLS_CIPHER_MODE_OFB */
-
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( NULL, 16, &size, out,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( &aes_ctx, 16, NULL, out,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, NULL,
- out, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
- NULL, in, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
- out, NULL, out ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
- mbedtls_aes_crypt_ctr( &aes_ctx, 16, &size, out,
- out, in, NULL ) );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
}
/* END_CASE */
@@ -569,12 +413,6 @@
size_t size;
#endif
- /* These calls accept NULL */
- TEST_VALID_PARAM( mbedtls_aes_free( NULL ) );
-#if defined(MBEDTLS_CIPHER_MODE_XTS)
- TEST_VALID_PARAM( mbedtls_aes_xts_free( NULL ) );
-#endif
-
#if defined(MBEDTLS_CIPHER_MODE_CBC)
TEST_ASSERT( mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_ENCRYPT,
15,
@@ -609,6 +447,14 @@
TEST_ASSERT( mbedtls_aes_crypt_ofb( &aes_ctx, 16, &size, out, in, out )
== MBEDTLS_ERR_AES_BAD_INPUT_DATA );
#endif
+
+/*
+ * The following line needs to be added to make the code compilable
+ * when all the conditions above will be not define in a specific
+ * choice of features.
+ */
+ TEST_ASSERT( 1 );
+/* TODO: It will be removed when the whole test will be reworked */
}
/* END_CASE */
diff --git a/tests/suites/test_suite_aes.rest.data b/tests/suites/test_suite_aes.rest.data
index 6a76b43..3b43c90 100644
--- a/tests/suites/test_suite_aes.rest.data
+++ b/tests/suites/test_suite_aes.rest.data
@@ -10,8 +10,8 @@
AES-256-CBC Decrypt (Invalid input length)
aes_decrypt_cbc:"0000000000000000000000000000000000000000000000000000000000000000":"00000000000000000000000000000000":"623a52fcea5d443e48d9181ab32c74":"":MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
-AES - Optional Parameter Validation (MBEDTLS_CHECK_PARAMS)
-aes_check_params:
+AES - Mode Parameter Validation
+aes_invalid_mode:
AES - Mandatory Parameter Validation and Valid Parameters
aes_misc_params:
diff --git a/tests/suites/test_suite_aria.data b/tests/suites/test_suite_aria.data
index 8848978..94b6e7e 100644
--- a/tests/suites/test_suite_aria.data
+++ b/tests/suites/test_suite_aria.data
@@ -1,6 +1,3 @@
-ARIA - Valid parameters
-aria_valid_param:
-
ARIA - Invalid parameters
aria_invalid_param:
diff --git a/tests/suites/test_suite_aria.function b/tests/suites/test_suite_aria.function
index 6d6a203..0426324 100644
--- a/tests/suites/test_suite_aria.function
+++ b/tests/suites/test_suite_aria.function
@@ -16,18 +16,10 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE */
-void aria_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_aria_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void aria_invalid_param( )
{
mbedtls_aria_context ctx;
- unsigned char key[128 / 8] = { 0 };
unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
@@ -35,78 +27,22 @@
((void) iv_off);
((void) iv);
-
- TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_enc( NULL, key,
- sizeof( key ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_enc( &ctx, NULL,
- sizeof( key ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_dec( NULL, key,
- sizeof( key ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_dec( &ctx, NULL,
- sizeof( key ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ecb( NULL, input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ecb( &ctx, NULL, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ecb( &ctx, input, NULL ) );
+ ((void) ctx);
+ ((void) input);
+ ((void) output);
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cbc( NULL,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
mbedtls_aria_crypt_cbc( &ctx,
42 /* invalid mode */,
sizeof( input ),
iv,
input,
output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cbc( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- NULL,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cbc( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- iv,
- NULL,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cbc( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- iv,
- input,
- NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( NULL,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- &iv_off,
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
mbedtls_aria_crypt_cfb128( &ctx,
42, /* invalid mode */
sizeof( input ),
@@ -114,91 +50,8 @@
iv,
input,
output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- NULL,
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- &iv_off,
- NULL,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- &iv_off,
- iv,
- NULL,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_cfb128( &ctx,
- MBEDTLS_ARIA_ENCRYPT,
- sizeof( input ),
- &iv_off,
- iv,
- input,
- NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CFB */
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( NULL,
- sizeof( input ),
- &iv_off,
- iv,
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( &ctx,
- sizeof( input ),
- NULL,
- iv,
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( &ctx,
- sizeof( input ),
- &iv_off,
- NULL,
- iv,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( &ctx,
- sizeof( input ),
- &iv_off,
- iv,
- NULL,
- input,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( &ctx,
- sizeof( input ),
- &iv_off,
- iv,
- iv,
- NULL,
- output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_crypt_ctr( &ctx,
- sizeof( input ),
- &iv_off,
- iv,
- iv,
- input,
- NULL ) );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
exit:
return;
diff --git a/tests/suites/test_suite_blowfish.data b/tests/suites/test_suite_blowfish.data
index c9639f6..0ebb642 100644
--- a/tests/suites/test_suite_blowfish.data
+++ b/tests/suites/test_suite_blowfish.data
@@ -1,6 +1,3 @@
-BLOWFISH - Valid parameters
-blowfish_valid_param:
-
BLOWFISH - Invalid parameters
blowfish_invalid_param:
diff --git a/tests/suites/test_suite_blowfish.function b/tests/suites/test_suite_blowfish.function
index f89353c..1fa59ee 100644
--- a/tests/suites/test_suite_blowfish.function
+++ b/tests/suites/test_suite_blowfish.function
@@ -7,159 +7,37 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE */
-void blowfish_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_blowfish_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void blowfish_invalid_param( )
{
mbedtls_blowfish_context ctx;
unsigned char buf[16] = { 0 };
- size_t const valid_keylength = sizeof( buf ) * 8;
- size_t valid_mode = MBEDTLS_BLOWFISH_ENCRYPT;
size_t invalid_mode = 42;
size_t off;
((void) off);
- TEST_INVALID_PARAM( mbedtls_blowfish_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_blowfish_free( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_setkey( NULL,
- buf,
- valid_keylength ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_setkey( &ctx,
- NULL,
- valid_keylength ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ecb( NULL,
- valid_mode,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
mbedtls_blowfish_crypt_ecb( &ctx,
invalid_mode,
buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ecb( &ctx,
- valid_mode,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ecb( &ctx,
- valid_mode,
- buf, NULL ) );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cbc( NULL,
- valid_mode,
- sizeof( buf ),
- buf, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
mbedtls_blowfish_crypt_cbc( &ctx,
invalid_mode,
sizeof( buf ),
buf, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- NULL, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- buf, NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- buf, buf, NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cfb64( NULL,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
mbedtls_blowfish_crypt_cfb64( &ctx,
invalid_mode,
sizeof( buf ),
&off, buf,
buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cfb64( &ctx,
- valid_mode,
- sizeof( buf ),
- NULL, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cfb64( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, NULL,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cfb64( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_cfb64( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- buf, NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CFB */
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( NULL,
- sizeof( buf ),
- &off,
- buf, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( &ctx,
- sizeof( buf ),
- NULL,
- buf, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- NULL, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, NULL,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, buf,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA,
- mbedtls_blowfish_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, buf,
- buf, NULL ) );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
exit:
return;
}
diff --git a/tests/suites/test_suite_camellia.data b/tests/suites/test_suite_camellia.data
index 3d11b8c..3f73abc 100644
--- a/tests/suites/test_suite_camellia.data
+++ b/tests/suites/test_suite_camellia.data
@@ -1,6 +1,3 @@
-Camellia - Valid parameters
-camellia_valid_param:
-
Camellia - Invalid parameters
camellia_invalid_param:
diff --git a/tests/suites/test_suite_camellia.function b/tests/suites/test_suite_camellia.function
index 312495c..cc18d5b 100644
--- a/tests/suites/test_suite_camellia.function
+++ b/tests/suites/test_suite_camellia.function
@@ -7,167 +7,37 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE */
-void camellia_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_camellia_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void camellia_invalid_param( )
{
mbedtls_camellia_context ctx;
unsigned char buf[16] = { 0 };
- const size_t valid_keybits = 128;
const int invalid_mode = 42;
- const int valid_mode = MBEDTLS_CAMELLIA_ENCRYPT;
size_t off;
((void) off);
- TEST_INVALID_PARAM( mbedtls_camellia_init( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_setkey_enc( NULL,
- buf,
- valid_keybits ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_setkey_enc( &ctx,
- NULL,
- valid_keybits ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_setkey_dec( NULL,
- buf,
- valid_keybits ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_setkey_dec( &ctx,
- NULL,
- valid_keybits ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ecb( NULL,
- valid_mode,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( &ctx,
invalid_mode,
buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ecb( &ctx,
- valid_mode,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ecb( &ctx,
- valid_mode,
- buf, NULL ) );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cbc( NULL,
- valid_mode,
- sizeof( buf ),
- buf, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( &ctx,
invalid_mode,
sizeof( buf ),
buf, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- NULL, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- buf, NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cbc( &ctx,
- valid_mode,
- sizeof( buf ),
- buf, buf, NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
#if defined(MBEDTLS_CIPHER_MODE_CFB)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( NULL,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
invalid_mode,
sizeof( buf ),
&off, buf,
buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( &ctx,
- valid_mode,
- sizeof( buf ),
- NULL, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, NULL,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_cfb128( &ctx,
- valid_mode,
- sizeof( buf ),
- &off, buf,
- buf, NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CFB */
-#if defined(MBEDTLS_CIPHER_MODE_CTR)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( NULL,
- sizeof( buf ),
- &off,
- buf, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( &ctx,
- sizeof( buf ),
- NULL,
- buf, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- NULL, buf,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, NULL,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, buf,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
- mbedtls_camellia_crypt_ctr( &ctx,
- sizeof( buf ),
- &off,
- buf, buf,
- buf, NULL ) );
-#endif /* MBEDTLS_CIPHER_MODE_CTR */
-
exit:
return;
}
diff --git a/tests/suites/test_suite_ccm.data b/tests/suites/test_suite_ccm.data
index 4f83468..459683b 100644
--- a/tests/suites/test_suite_ccm.data
+++ b/tests/suites/test_suite_ccm.data
@@ -1,12 +1,6 @@
CCM self test
mbedtls_ccm_self_test:
-CCM - Invalid parameters
-ccm_invalid_param:
-
-CCM - Valid parameters
-ccm_valid_param:
-
CCM init #1 AES-128: OK
depends_on:MBEDTLS_AES_C
mbedtls_ccm_setkey:MBEDTLS_CIPHER_ID_AES:128:0
diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function
index 5a3726e..840583c 100644
--- a/tests/suites/test_suite_ccm.function
+++ b/tests/suites/test_suite_ccm.function
@@ -291,216 +291,3 @@
mbedtls_ccm_free( &ctx );
}
/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void ccm_invalid_param( )
-{
- struct mbedtls_ccm_context ctx;
- unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
- mbedtls_cipher_id_t valid_cipher = MBEDTLS_CIPHER_ID_AES;
- int valid_len = sizeof(valid_buffer);
- int valid_bitlen = valid_len * 8;
-
- mbedtls_ccm_init( &ctx );
-
- /* mbedtls_ccm_init() */
- TEST_INVALID_PARAM( mbedtls_ccm_init( NULL ) );
-
- /* mbedtls_ccm_setkey() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_setkey( NULL, valid_cipher, valid_buffer, valid_bitlen ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_setkey( &ctx, valid_cipher, NULL, valid_bitlen ) );
-
- /* mbedtls_ccm_encrypt_and_tag() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( &ctx, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- NULL, valid_len ) );
-
- /* mbedtls_ccm_star_encrypt_and_tag() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( &ctx, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_encrypt_and_tag( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- NULL, valid_len ) );
-
- /* mbedtls_ccm_auth_decrypt() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( &ctx, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- NULL, valid_len ) );
-
- /* mbedtls_ccm_star_auth_decrypt() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( &ctx, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL,
- valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CCM_BAD_INPUT,
- mbedtls_ccm_star_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- NULL, valid_len ) );
-
-exit:
- mbedtls_ccm_free( &ctx );
- return;
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
-void ccm_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_ccm_free( NULL ) );
-exit:
- return;
-}
-/* END_CASE */
diff --git a/tests/suites/test_suite_chacha20.data b/tests/suites/test_suite_chacha20.data
index 3f9033e..8609460 100644
--- a/tests/suites/test_suite_chacha20.data
+++ b/tests/suites/test_suite_chacha20.data
@@ -22,8 +22,5 @@
ChaCha20 RFC 7539 Test Vector #3 (Decrypt)
chacha20_crypt:"1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0":"000000000000000000000002":42:"62e6347f95ed87a45ffae7426f27a1df5fb69110044c0d73118effa95b01e5cf166d3df2d721caf9b21e5fb14c616871fd84c54f9d65b283196c7fe4f60553ebf39c6402c42234e32a356b3e764312a61a5532055716ead6962568f87d3f3f7704c6a8d1bcd1bf4d50d6154b6da731b187b58dfd728afa36757a797ac188d1":"2754776173206272696c6c69672c20616e642074686520736c6974687920746f7665730a446964206779726520616e642067696d626c6520696e2074686520776162653a0a416c6c206d696d737920776572652074686520626f726f676f7665732c0a416e6420746865206d6f6d65207261746873206f757467726162652e"
-ChaCha20 Paremeter Validation
-chacha20_bad_params:
-
ChaCha20 Selftest
chacha20_self_test:
diff --git a/tests/suites/test_suite_chacha20.function b/tests/suites/test_suite_chacha20.function
index 67c8de2..9afadb7 100644
--- a/tests/suites/test_suite_chacha20.function
+++ b/tests/suites/test_suite_chacha20.function
@@ -66,52 +66,6 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void chacha20_bad_params()
-{
- unsigned char key[32];
- unsigned char nonce[12];
- unsigned char src[1];
- unsigned char dst[1];
- uint32_t counter = 0;
- size_t len = sizeof( src );
- mbedtls_chacha20_context ctx;
-
- TEST_INVALID_PARAM( mbedtls_chacha20_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_chacha20_free( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_setkey( NULL, key ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_setkey( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_starts( NULL, nonce, counter ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_starts( &ctx, NULL, counter ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_update( NULL, 0, src, dst ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_update( &ctx, len, NULL, dst ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_update( &ctx, len, src, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_crypt( NULL, nonce, counter, 0, src, dst ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_crypt( key, NULL, counter, 0, src, dst ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_crypt( key, nonce, counter, len, NULL, dst ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA,
- mbedtls_chacha20_crypt( key, nonce, counter, len, src, NULL ) );
-
-exit:
- return;
-
-}
-/* END_CASE */
-
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void chacha20_self_test()
{
diff --git a/tests/suites/test_suite_chachapoly.data b/tests/suites/test_suite_chachapoly.data
index 34cb568..02c7bf3 100644
--- a/tests/suites/test_suite_chachapoly.data
+++ b/tests/suites/test_suite_chachapoly.data
@@ -19,9 +19,6 @@
ChaCha20-Poly1305 State Flow
chachapoly_state:
-ChaCha20-Poly1305 Parameter Validation
-chachapoly_bad_params:
-
ChaCha20-Poly1305 Selftest
depends_on:MBEDTLS_SELF_TEST
chachapoly_selftest:
diff --git a/tests/suites/test_suite_chachapoly.function b/tests/suites/test_suite_chachapoly.function
index 96128e4..2e1e7b2 100644
--- a/tests/suites/test_suite_chachapoly.function
+++ b/tests/suites/test_suite_chachapoly.function
@@ -66,137 +66,6 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void chachapoly_bad_params()
-{
- unsigned char key[32];
- unsigned char nonce[12];
- unsigned char aad[1];
- unsigned char input[1];
- unsigned char output[1];
- unsigned char mac[16];
- size_t input_len = sizeof( input );
- size_t aad_len = sizeof( aad );
- mbedtls_chachapoly_context ctx;
-
- memset( key, 0x00, sizeof( key ) );
- memset( nonce, 0x00, sizeof( nonce ) );
- memset( aad, 0x00, sizeof( aad ) );
- memset( input, 0x00, sizeof( input ) );
- memset( output, 0x00, sizeof( output ) );
- memset( mac, 0x00, sizeof( mac ) );
-
- TEST_INVALID_PARAM( mbedtls_chachapoly_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_chachapoly_free( NULL ) );
-
- /* setkey */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_setkey( NULL, key ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_setkey( &ctx, NULL ) );
-
- /* encrypt_and_tag */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( NULL,
- 0, nonce,
- aad, 0,
- input, output, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( &ctx,
- 0, NULL,
- aad, 0,
- input, output, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( &ctx,
- 0, nonce,
- NULL, aad_len,
- input, output, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( &ctx,
- input_len, nonce,
- aad, 0,
- NULL, output, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( &ctx,
- input_len, nonce,
- aad, 0,
- input, NULL, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_encrypt_and_tag( &ctx,
- 0, nonce,
- aad, 0,
- input, output, NULL ) );
-
- /* auth_decrypt */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( NULL,
- 0, nonce,
- aad, 0,
- mac, input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( &ctx,
- 0, NULL,
- aad, 0,
- mac, input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( &ctx,
- 0, nonce,
- NULL, aad_len,
- mac, input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( &ctx,
- 0, nonce,
- aad, 0,
- NULL, input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( &ctx,
- input_len, nonce,
- aad, 0,
- mac, NULL, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_auth_decrypt( &ctx,
- input_len, nonce,
- aad, 0,
- mac, input, NULL ) );
-
- /* starts */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_starts( NULL, nonce,
- MBEDTLS_CHACHAPOLY_ENCRYPT ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_starts( &ctx, NULL,
- MBEDTLS_CHACHAPOLY_ENCRYPT ) );
-
- /* update_aad */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_update_aad( NULL, aad,
- aad_len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_update_aad( &ctx, NULL,
- aad_len ) );
-
- /* update */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_update( NULL, input_len,
- input, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_update( &ctx, input_len,
- NULL, output ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_update( &ctx, input_len,
- input, NULL ) );
-
- /* finish */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_finish( NULL, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_chachapoly_finish( &ctx, NULL ) );
-
-exit:
- return;
-}
-/* END_CASE */
-
/* BEGIN_CASE */
void chachapoly_state()
{
diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function
index 3d3f6a3..674349f 100644
--- a/tests/suites/test_suite_cipher.function
+++ b/tests/suites/test_suite_cipher.function
@@ -207,327 +207,27 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void cipher_invalid_param_conditional( )
{
mbedtls_cipher_context_t valid_ctx;
- mbedtls_operation_t valid_operation = MBEDTLS_ENCRYPT;
mbedtls_operation_t invalid_operation = 100;
- mbedtls_cipher_padding_t valid_mode = MBEDTLS_PADDING_ZEROS;
unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
int valid_size = sizeof(valid_buffer);
int valid_bitlen = valid_size * 8;
const mbedtls_cipher_info_t *valid_info = mbedtls_cipher_info_from_type(
*( mbedtls_cipher_list() ) );
- size_t size_t_var;
-
- (void)valid_mode; /* In some configurations this is unused */
-
- /* mbedtls_cipher_init() */
- TEST_VALID_PARAM( mbedtls_cipher_init( &valid_ctx ) );
- TEST_INVALID_PARAM( mbedtls_cipher_init( NULL ) );
-
- /* mbedtls_cipher_setup() */
- TEST_VALID_PARAM( mbedtls_cipher_setup( &valid_ctx, valid_info ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_setup( NULL, valid_info ) );
-
- /* mbedtls_cipher_get_block_size() */
- TEST_INVALID_PARAM_RET( 0, mbedtls_cipher_get_block_size( NULL ) );
-
- /* mbedtls_cipher_get_cipher_mode() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_MODE_NONE,
- mbedtls_cipher_get_cipher_mode( NULL ) );
-
- /* mbedtls_cipher_get_iv_size() */
- TEST_INVALID_PARAM_RET( 0, mbedtls_cipher_get_iv_size( NULL ) );
-
- /* mbedtls_cipher_get_type() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_CIPHER_NONE,
- mbedtls_cipher_get_type( NULL ) );
-
- /* mbedtls_cipher_get_name() */
- TEST_INVALID_PARAM_RET( 0, mbedtls_cipher_get_name( NULL ) );
-
- /* mbedtls_cipher_get_key_bitlen() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_KEY_LENGTH_NONE,
- mbedtls_cipher_get_key_bitlen( NULL ) );
-
- /* mbedtls_cipher_get_operation() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_OPERATION_NONE,
- mbedtls_cipher_get_operation( NULL ) );
-
- /* mbedtls_cipher_setkey() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_setkey( NULL,
- valid_buffer,
- valid_bitlen,
- valid_operation ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_setkey( &valid_ctx,
- NULL,
- valid_bitlen,
- valid_operation ) );
- TEST_INVALID_PARAM_RET(
+ TEST_EQUAL(
MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
mbedtls_cipher_setkey( &valid_ctx,
valid_buffer,
valid_bitlen,
invalid_operation ) );
- /* mbedtls_cipher_set_iv() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_set_iv( NULL,
- valid_buffer,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_set_iv( &valid_ctx,
- NULL,
- valid_size ) );
-
- /* mbedtls_cipher_reset() */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_reset( NULL ) );
-
-#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- /* mbedtls_cipher_update_ad() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update_ad( NULL,
- valid_buffer,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update_ad( &valid_ctx,
- NULL,
- valid_size ) );
-#endif /* defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) */
-
-#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
- /* mbedtls_cipher_set_padding_mode() */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_set_padding_mode( NULL, valid_mode ) );
-#endif
-
- /* mbedtls_cipher_update() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update( NULL,
- valid_buffer,
- valid_size,
- valid_buffer,
- &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update( &valid_ctx,
- NULL, valid_size,
- valid_buffer,
- &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update( &valid_ctx,
- valid_buffer, valid_size,
- NULL,
- &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_update( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer,
- NULL ) );
-
- /* mbedtls_cipher_finish() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_finish( NULL,
- valid_buffer,
- &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_finish( &valid_ctx,
- NULL,
- &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_finish( &valid_ctx,
- valid_buffer,
- NULL ) );
-
-#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
- /* mbedtls_cipher_write_tag() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_write_tag( NULL,
- valid_buffer,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_write_tag( &valid_ctx,
- NULL,
- valid_size ) );
-
- /* mbedtls_cipher_check_tag() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_check_tag( NULL,
- valid_buffer,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_check_tag( &valid_ctx,
- NULL,
- valid_size ) );
-#endif /* defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) */
-
- /* mbedtls_cipher_crypt() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_crypt( NULL,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_crypt( &valid_ctx,
- NULL, valid_size,
- valid_buffer, valid_size,
- valid_buffer, &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_crypt( &valid_ctx,
- valid_buffer, valid_size,
- NULL, valid_size,
- valid_buffer, &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_crypt( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- NULL, &size_t_var ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_crypt( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, NULL ) );
-
-#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
- /* mbedtls_cipher_auth_encrypt_ext */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( NULL,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( &valid_ctx,
- NULL, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- NULL, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- NULL, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- NULL, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_encrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, NULL,
- valid_size ) );
-
- /* mbedtls_cipher_auth_decrypt_ext */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( NULL,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( &valid_ctx,
- NULL, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- NULL, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- NULL, valid_size,
- valid_buffer, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- NULL, valid_size, &size_t_var,
- valid_size ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA,
- mbedtls_cipher_auth_decrypt_ext( &valid_ctx,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size,
- valid_buffer, valid_size, NULL,
- valid_size ) );
-#endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
-
- /* mbedtls_cipher_free() */
- TEST_VALID_PARAM( mbedtls_cipher_free( NULL ) );
exit:
- TEST_VALID_PARAM( mbedtls_cipher_free( &valid_ctx ) );
+ ;
}
/* END_CASE */
diff --git a/tests/suites/test_suite_dhm.data b/tests/suites/test_suite_dhm.data
index c4795b6..e5fb428 100644
--- a/tests/suites/test_suite_dhm.data
+++ b/tests/suites/test_suite_dhm.data
@@ -1,26 +1,89 @@
-Diffie-Hellman parameter validation
-dhm_invalid_params:
+Diffie-Hellman full exchange: tiny x_size
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
-Diffie-Hellman full exchange #1
-dhm_do_dhm:10:"23":10:"5":0
+Diffie-Hellman full exchange: 5-bit, x_size=3
+dhm_do_dhm:10:"23":3:10:"5":0
-Diffie-Hellman full exchange #2
-dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622":0
+Diffie-Hellman full exchange: 5-bit, x_size=2
+dhm_do_dhm:10:"23":2:10:"5":0
-Diffie-Hellman full exchange #3
-dhm_do_dhm:10:"93450983094850938450983409623982317398171298719873918739182739712938719287391879381271":10:"9345098309485093845098340962223981329819812792137312973297123912791271":0
+## Repeat this test case and a few similar ones several times. The RNG state
+## changes, so we get to exercise the code with a few different values.
+Diffie-Hellman full exchange: 5-bit #1
+dhm_do_dhm:10:"23":1:10:"5":0
+
+Diffie-Hellman full exchange: 5-bit #2
+dhm_do_dhm:10:"23":1:10:"5":0
+
+Diffie-Hellman full exchange: 5-bit #3
+dhm_do_dhm:10:"23":1:10:"5":0
+
+Diffie-Hellman full exchange: 5-bit #4
+dhm_do_dhm:10:"23":1:10:"5":0
+
+Diffie-Hellman full exchange: 5-bit #5
+dhm_do_dhm:10:"23":1:10:"5":0
+
+## This is x_size = P_size + 1. Arguably x_size > P_size makes no sense,
+## but it's the current undocumented behavior to treat it the same as when
+## x_size = P_size. If this behavior changes in the future, change the expected
+## return status from 0 to MBEDTLS_ERR_DHM_BAD_INPUT_DATA.
+Diffie-Hellman full exchange: 97-bit, x_size=14
+dhm_do_dhm:10:"93450983094850938450983409623":14:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit #1
+dhm_do_dhm:10:"93450983094850938450983409623":13:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit #2
+dhm_do_dhm:10:"93450983094850938450983409623":13:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit #3
+dhm_do_dhm:10:"93450983094850938450983409623":13:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit #4
+dhm_do_dhm:10:"93450983094850938450983409623":13:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit #5
+dhm_do_dhm:10:"93450983094850938450983409623":13:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=12
+dhm_do_dhm:10:"93450983094850938450983409623":12:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=11
+dhm_do_dhm:10:"93450983094850938450983409623":11:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=1 #1
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=1 #2
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=1 #3
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=1 #4
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 97-bit, x_size=1 #5
+dhm_do_dhm:10:"93450983094850938450983409623":1:10:"9345098304850938450983409622":0
+
+Diffie-Hellman full exchange: 286-bit
+dhm_do_dhm:10:"93450983094850938450983409623982317398171298719873918739182739712938719287391879381271":36:10:"9345098309485093845098340962223981329819812792137312973297123912791271":0
Diffie-Hellman trivial subgroup #1
-dhm_do_dhm:10:"23":10:"1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
+dhm_do_dhm:10:"23":1:10:"1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
Diffie-Hellman trivial subgroup #2
-dhm_do_dhm:10:"23":10:"-1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
+dhm_do_dhm:10:"23":1:10:"-1":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
Diffie-Hellman small modulus
-dhm_do_dhm:10:"3":10:"5":MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED
+dhm_do_dhm:10:"3":1:10:"5":MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED+MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Diffie-Hellman zero modulus
-dhm_do_dhm:10:"0":10:"5":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
+dhm_do_dhm:10:"0":1:10:"5":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
+
+Diffie-Hellman: x_size < 0
+dhm_do_dhm:10:"93450983094850938450983409623":-1:10:"9345098304850938450983409622":MBEDTLS_ERR_DHM_BAD_INPUT_DATA
Diffie-Hellman MPI_MAX_SIZE modulus
dhm_make_public:MBEDTLS_MPI_MAX_SIZE:10:"5":0
diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function
index 1726b9e..c4d78de 100644
--- a/tests/suites/test_suite_dhm.function
+++ b/tests/suites/test_suite_dhm.function
@@ -1,5 +1,68 @@
/* BEGIN_HEADER */
#include "mbedtls/dhm.h"
+
+/* Sanity checks on a Diffie-Hellman parameter: check the length-value
+ * syntax and check that the value is the expected one (taken from the
+ * DHM context by the caller). */
+static int check_dhm_param_output( const mbedtls_mpi *expected,
+ const unsigned char *buffer,
+ size_t size,
+ size_t *offset )
+{
+ size_t n;
+ mbedtls_mpi actual;
+ int ok = 0;
+ mbedtls_mpi_init( &actual );
+
+ ++mbedtls_test_info.step;
+
+ TEST_ASSERT( size >= *offset + 2 );
+ n = ( buffer[*offset] << 8 ) | buffer[*offset + 1];
+ *offset += 2;
+ /* The DHM param output from Mbed TLS has leading zeros stripped, as
+ * permitted but not required by RFC 5246 \S4.4. */
+ TEST_EQUAL( n, mbedtls_mpi_size( expected ) );
+ TEST_ASSERT( size >= *offset + n );
+ TEST_EQUAL( 0, mbedtls_mpi_read_binary( &actual, buffer + *offset, n ) );
+ TEST_EQUAL( 0, mbedtls_mpi_cmp_mpi( expected, &actual ) );
+ *offset += n;
+
+ ok = 1;
+exit:
+ mbedtls_mpi_free( &actual );
+ return( ok );
+}
+
+/* Sanity checks on Diffie-Hellman parameters: syntax, range, and comparison
+ * against the context. */
+static int check_dhm_params( const mbedtls_dhm_context *ctx,
+ size_t x_size,
+ const unsigned char *ske, size_t ske_len )
+{
+ size_t offset = 0;
+
+ /* Check that ctx->X and ctx->GX are within range. */
+ TEST_ASSERT( mbedtls_mpi_cmp_int( &ctx->X, 1 ) > 0 );
+ TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx->X, &ctx->P ) < 0 );
+ TEST_ASSERT( mbedtls_mpi_size( &ctx->X ) <= x_size );
+ TEST_ASSERT( mbedtls_mpi_cmp_int( &ctx->GX, 1 ) > 0 );
+ TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx->GX, &ctx->P ) < 0 );
+
+ /* Check ske: it must contain P, G and G^X, each prefixed with a
+ * 2-byte size. */
+ if( !check_dhm_param_output( &ctx->P, ske, ske_len, &offset ) )
+ goto exit;
+ if( !check_dhm_param_output( &ctx->G, ske, ske_len, &offset ) )
+ goto exit;
+ if( !check_dhm_param_output( &ctx->GX, ske, ske_len, &offset ) )
+ goto exit;
+ TEST_EQUAL( offset, ske_len );
+
+ return( 1 );
+exit:
+ return( 0 );
+}
+
/* END_HEADER */
/* BEGIN_DEPENDENCIES
@@ -7,115 +70,8 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void dhm_invalid_params( )
-{
- mbedtls_dhm_context ctx;
- unsigned char buf[42] = { 0 };
- unsigned char *buf_null = NULL;
- mbedtls_mpi X;
- size_t const buflen = sizeof( buf );
- size_t len;
-
- TEST_INVALID_PARAM( mbedtls_dhm_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_dhm_free( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_params( NULL,
- (unsigned char**) &buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_params( &ctx, &buf_null, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_params( &ctx, NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_params( &ctx,
- (unsigned char**) &buf,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_params( NULL, buflen,
- buf, &len,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_params( &ctx, buflen,
- NULL, &len,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_params( &ctx, buflen,
- buf, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_params( &ctx, buflen,
- buf, &len,
- NULL,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_set_group( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_set_group( &ctx, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_set_group( &ctx, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_public( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_read_public( &ctx, NULL, buflen ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_public( NULL, buflen,
- buf, buflen,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_public( &ctx, buflen,
- NULL, buflen,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_make_public( &ctx, buflen,
- buf, buflen,
- NULL,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_calc_secret( NULL, buf, buflen, &len,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_calc_secret( &ctx, NULL, buflen, &len,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_calc_secret( &ctx, buf, buflen, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
-
-#if defined(MBEDTLS_ASN1_PARSE_C)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_parse_dhm( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_parse_dhm( &ctx, NULL, buflen ) );
-
-#if defined(MBEDTLS_FS_IO)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_parse_dhmfile( NULL, "" ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
- mbedtls_dhm_parse_dhmfile( &ctx, NULL ) );
-#endif /* MBEDTLS_FS_IO */
-#endif /* MBEDTLS_ASN1_PARSE_C */
-
-exit:
- return;
-}
-/* END_CASE */
-
/* BEGIN_CASE */
-void dhm_do_dhm( int radix_P, char *input_P,
+void dhm_do_dhm( int radix_P, char *input_P, int x_size,
int radix_G, char *input_G, int result )
{
mbedtls_dhm_context ctx_srv;
@@ -129,7 +85,7 @@
size_t pub_cli_len = 0;
size_t sec_srv_len;
size_t sec_cli_len;
- int x_size, i;
+ int i;
mbedtls_test_rnd_pseudo_info rnd_info;
mbedtls_dhm_init( &ctx_srv );
@@ -145,17 +101,19 @@
*/
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.P, radix_P, input_P ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.G, radix_G, input_G ) == 0 );
- x_size = mbedtls_mpi_size( &ctx_srv.P );
- pub_cli_len = x_size;
+ pub_cli_len = mbedtls_mpi_size( &ctx_srv.P );
/*
* First key exchange
*/
+ mbedtls_test_set_step( 10 );
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len,
&mbedtls_test_rnd_pseudo_rand,
&rnd_info ) == result );
if ( result != 0 )
goto exit;
+ if( !check_dhm_params( &ctx_srv, x_size, ske, ske_len ) )
+ goto exit;
ske[ske_len++] = 0;
ske[ske_len++] = 0;
@@ -179,6 +137,7 @@
/* Re-do calc_secret on server a few times to test update of blinding values */
for( i = 0; i < 3; i++ )
{
+ mbedtls_test_set_step( 20 + i );
sec_srv_len = 1000;
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv,
sizeof( sec_srv ), &sec_srv_len,
@@ -195,9 +154,12 @@
*/
p = ske;
+ mbedtls_test_set_step( 30 );
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len,
&mbedtls_test_rnd_pseudo_rand,
&rnd_info ) == 0 );
+ if( !check_dhm_params( &ctx_srv, x_size, ske, ske_len ) )
+ goto exit;
ske[ske_len++] = 0;
ske[ske_len++] = 0;
TEST_ASSERT( mbedtls_dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
diff --git a/tests/suites/test_suite_ecdh.data b/tests/suites/test_suite_ecdh.data
index fb4a232..cc58432 100644
--- a/tests/suites/test_suite_ecdh.data
+++ b/tests/suites/test_suite_ecdh.data
@@ -1,6 +1,3 @@
-ECDH - Valid parameters
-ecdh_valid_param:
-
ECDH - Invalid parameters
ecdh_invalid_param:
@@ -76,10 +73,6 @@
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
ecdh_restart:MBEDTLS_ECP_DP_SECP256R1:"C88F01F510D9AC3F70A292DAA2316DE544E9AAB8AFE84049C62A9C57862D1433":"C6EF9C5D78AE012A011164ACB397CE2088685D8F06BF9BE0B283AB46476BEE53":"D6840F6B42F6EDAFD13116E0E12565202FEF8E9ECE7DCE03812464D04B9442DE":0:250:0:0
-ECDH exchange legacy context
-depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
-ecdh_exchange_legacy:MBEDTLS_ECP_DP_SECP192R1
-
ECDH calc_secret: ours first, SECP256R1 (RFC 5903)
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397ce2088685d8f06bf9be0b283ab46476bee53":"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":0:"d6840f6b42f6edafd13116e0e12565202fef8e9ece7dce03812464d04b9442de"
diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function
index 3ab96fa..6e8459d 100644
--- a/tests/suites/test_suite_ecdh.function
+++ b/tests/suites/test_suite_ecdh.function
@@ -43,141 +43,17 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE */
-void ecdh_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_ecdh_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void ecdh_invalid_param( )
{
- mbedtls_ecp_group grp;
mbedtls_ecdh_context ctx;
- mbedtls_mpi m;
- mbedtls_ecp_point P;
mbedtls_ecp_keypair kp;
- size_t olen;
- unsigned char buf[42] = { 0 };
- const unsigned char *buf_null = NULL;
- size_t const buflen = sizeof( buf );
int invalid_side = 42;
- mbedtls_ecp_group_id valid_grp = MBEDTLS_ECP_DP_SECP192R1;
- TEST_INVALID_PARAM( mbedtls_ecdh_init( NULL ) );
-
-#if defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_INVALID_PARAM( mbedtls_ecdh_enable_restart( NULL ) );
-#endif /* MBEDTLS_ECP_RESTARTABLE */
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_gen_public( NULL, &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_gen_public( &grp, NULL, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_gen_public( &grp, &m, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_gen_public( &grp, &m, &P,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_compute_shared( NULL, &m, &P, &m,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_compute_shared( &grp, NULL, &P, &m,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_compute_shared( &grp, &m, NULL, &m,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_compute_shared( &grp, &m, &P, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_setup( NULL, valid_grp ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_params( NULL, &olen, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_params( &ctx, NULL, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_params( &ctx, &olen, NULL, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_params( &ctx, &olen, buf, buflen, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_params( NULL,
- (const unsigned char**) &buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_params( &ctx, &buf_null,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_params( &ctx, NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_params( &ctx,
- (const unsigned char**) &buf,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_get_params( NULL, &kp,
- MBEDTLS_ECDH_OURS ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_get_params( &ctx, NULL,
- MBEDTLS_ECDH_OURS ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
mbedtls_ecdh_get_params( &ctx, &kp,
invalid_side ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_public( NULL, &olen, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_public( &ctx, NULL, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_public( &ctx, &olen, NULL, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_make_public( &ctx, &olen, buf, buflen, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_public( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_read_public( &ctx, NULL, buflen ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_calc_secret( NULL, &olen, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_calc_secret( &ctx, NULL, buf, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdh_calc_secret( &ctx, &olen, NULL, buflen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
exit:
return;
}
@@ -240,6 +116,8 @@
rnd_info_A.buf = rnd_buf_A->x;
rnd_info_A.length = rnd_buf_A->len;
+ rnd_info_A.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ rnd_info_A.fallback_p_rng = NULL;
/* Fix rnd_buf_A->x by shifting it left if necessary */
if( grp.nbits % 8 != 0 )
@@ -256,6 +134,8 @@
rnd_info_B.buf = rnd_buf_B->x;
rnd_info_B.length = rnd_buf_B->len;
+ rnd_info_B.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ rnd_info_B.fallback_p_rng = NULL;
/* Fix rnd_buf_B->x by shifting it left if necessary */
if( grp.nbits % 8 != 0 )
@@ -362,9 +242,13 @@
mbedtls_ecdh_init( &srv );
mbedtls_ecdh_init( &cli );
+ rnd_info_A.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ rnd_info_A.fallback_p_rng = NULL;
rnd_info_A.buf = dA->x;
rnd_info_A.length = dA->len;
+ rnd_info_B.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ rnd_info_B.fallback_p_rng = NULL;
rnd_info_B.buf = dB->x;
rnd_info_B.length = dB->len;
@@ -465,47 +349,6 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_ECDH_LEGACY_CONTEXT */
-void ecdh_exchange_legacy( int id )
-{
- mbedtls_ecdh_context srv, cli;
- unsigned char buf[1000];
- const unsigned char *vbuf;
- size_t len;
-
- mbedtls_test_rnd_pseudo_info rnd_info;
-
- mbedtls_ecdh_init( &srv );
- mbedtls_ecdh_init( &cli );
- memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
-
- TEST_ASSERT( mbedtls_ecp_group_load( &srv.grp, id ) == 0 );
-
- memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
- TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
-
- memset( buf, 0x00, sizeof( buf ) );
- TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
-
- TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
- &mbedtls_test_rnd_pseudo_rand,
- &rnd_info ) == 0 );
- TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &len, buf, 1000, NULL,
- NULL ) == 0 );
- TEST_ASSERT( mbedtls_mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
-
-exit:
- mbedtls_ecdh_free( &srv );
- mbedtls_ecdh_free( &cli );
-}
-/* END_CASE */
-
/* BEGIN_CASE */
void ecdh_exchange_calc_secret( int grp_id,
data_t *our_private_key,
diff --git a/tests/suites/test_suite_ecdsa.data b/tests/suites/test_suite_ecdsa.data
index e510c50..95efc73 100644
--- a/tests/suites/test_suite_ecdsa.data
+++ b/tests/suites/test_suite_ecdsa.data
@@ -1,6 +1,3 @@
-ECDSA Parameter validation
-ecdsa_invalid_param:
-
ECDSA primitive hash zero #1
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
ecdsa_prim_zero:MBEDTLS_ECP_DP_SECP192R1
diff --git a/tests/suites/test_suite_ecdsa.function b/tests/suites/test_suite_ecdsa.function
index 58cedc1..354f178 100644
--- a/tests/suites/test_suite_ecdsa.function
+++ b/tests/suites/test_suite_ecdsa.function
@@ -7,203 +7,6 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void ecdsa_invalid_param( )
-{
- mbedtls_ecdsa_context ctx;
- mbedtls_ecp_keypair key;
- mbedtls_ecp_group grp;
- mbedtls_ecp_group_id valid_group = MBEDTLS_ECP_DP_SECP192R1;
- mbedtls_ecp_point P;
- mbedtls_md_type_t valid_md = MBEDTLS_MD_SHA256;
- mbedtls_mpi m;
- size_t slen;
- unsigned char buf[42] = { 0 };
-
- TEST_INVALID_PARAM( mbedtls_ecdsa_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_ecdsa_free( NULL ) );
-
-#if defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_INVALID_PARAM( mbedtls_ecdsa_restart_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_ecdsa_restart_free( NULL ) );
-#endif /* MBEDTLS_ECP_RESTARTABLE */
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( NULL, &m, &m, &m,
- buf, sizeof( buf ),
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( &grp, NULL, &m, &m,
- buf, sizeof( buf ),
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( &grp, &m, NULL, &m,
- buf, sizeof( buf ),
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( &grp, &m, &m, NULL,
- buf, sizeof( buf ),
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( &grp, &m, &m, &m,
- NULL, sizeof( buf ),
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign( &grp, &m, &m, &m,
- buf, sizeof( buf ),
- NULL, NULL ) );
-
-#if defined(MBEDTLS_ECDSA_DETERMINISTIC)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign_det_ext( NULL, &m, &m, &m,
- buf, sizeof( buf ),
- valid_md,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign_det_ext( &grp, NULL, &m, &m,
- buf, sizeof( buf ),
- valid_md,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign_det_ext( &grp, &m, NULL, &m,
- buf, sizeof( buf ),
- valid_md,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign_det_ext( &grp, &m, &m, NULL,
- buf, sizeof( buf ),
- valid_md,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_sign_det_ext( &grp, &m, &m, &m,
- NULL, sizeof( buf ),
- valid_md,
- mbedtls_test_rnd_std_rand,
- NULL ) );
-#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_verify( NULL,
- buf, sizeof( buf ),
- &P, &m, &m ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_verify( &grp,
- NULL, sizeof( buf ),
- &P, &m, &m ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_verify( &grp,
- buf, sizeof( buf ),
- NULL, &m, &m ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_verify( &grp,
- buf, sizeof( buf ),
- &P, NULL, &m ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_verify( &grp,
- buf, sizeof( buf ),
- &P, &m, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature( NULL, valid_md, buf, sizeof( buf ),
- buf, &slen, mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature( &ctx, valid_md, NULL, sizeof( buf ),
- buf, &slen, mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature( &ctx, valid_md, buf, sizeof( buf ),
- NULL, &slen, mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature( &ctx, valid_md, buf, sizeof( buf ),
- buf, NULL, mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature_restartable( NULL, valid_md, buf,
- sizeof( buf ), buf, &slen,
- mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature_restartable( &ctx, valid_md, NULL,
- sizeof( buf ), buf, &slen,
- mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature_restartable( &ctx, valid_md, buf,
- sizeof( buf ), NULL, &slen,
- mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_write_signature_restartable( &ctx, valid_md, buf,
- sizeof( buf ), buf, NULL,
- mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature( NULL,
- buf, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature( &ctx,
- NULL, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature( &ctx,
- buf, sizeof( buf ),
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature_restartable( NULL,
- buf, sizeof( buf ),
- buf, sizeof( buf ),
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature_restartable( &ctx,
- NULL, sizeof( buf ),
- buf, sizeof( buf ),
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_read_signature_restartable( &ctx,
- buf, sizeof( buf ),
- NULL, sizeof( buf ),
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_genkey( NULL, valid_group,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_genkey( &ctx, valid_group,
- NULL, NULL ) );
-
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_from_keypair( NULL, &key ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecdsa_from_keypair( &ctx, NULL ) );
-
-exit:
- return;
-}
-/* END_CASE */
-
/* BEGIN_CASE */
void ecdsa_prim_zero( int id )
{
@@ -292,6 +95,8 @@
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 );
+ rnd_info.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ rnd_info.fallback_p_rng = NULL;
rnd_info.buf = rnd_buf->x;
rnd_info.length = rnd_buf->len;
diff --git a/tests/suites/test_suite_ecjpake.function b/tests/suites/test_suite_ecjpake.function
index ab672a8..311733b 100644
--- a/tests/suites/test_suite_ecjpake.function
+++ b/tests/suites/test_suite_ecjpake.function
@@ -98,100 +98,22 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void ecjpake_invalid_param( )
{
mbedtls_ecjpake_context ctx;
unsigned char buf[42] = { 0 };
- size_t olen;
size_t const len = sizeof( buf );
- mbedtls_ecjpake_role valid_role = MBEDTLS_ECJPAKE_SERVER;
mbedtls_ecjpake_role invalid_role = (mbedtls_ecjpake_role) 42;
mbedtls_md_type_t valid_md = MBEDTLS_MD_SHA256;
mbedtls_ecp_group_id valid_group = MBEDTLS_ECP_DP_SECP256R1;
- TEST_INVALID_PARAM( mbedtls_ecjpake_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_ecjpake_free( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_setup( NULL,
- valid_role,
- valid_md,
- valid_group,
- buf, len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
mbedtls_ecjpake_setup( &ctx,
invalid_role,
valid_md,
valid_group,
buf, len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_setup( &ctx,
- valid_role,
- valid_md,
- valid_group,
- NULL, len ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_check( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_one( NULL, buf, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_one( &ctx, NULL, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_one( &ctx, buf, len, NULL,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_one( &ctx, buf, len, &olen, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_two( NULL, buf, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_two( &ctx, NULL, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_two( &ctx, buf, len, NULL,
- mbedtls_test_rnd_std_rand, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_write_round_two( &ctx, buf, len, &olen, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_read_round_one( NULL,
- buf, len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_read_round_one( &ctx,
- NULL, len ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_read_round_two( NULL,
- buf, len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_read_round_two( &ctx,
- NULL, len ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_derive_secret( NULL, buf, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_derive_secret( &ctx, NULL, len, &olen,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_derive_secret( &ctx, buf, len, NULL,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecjpake_derive_secret( &ctx, buf, len, &olen, NULL, NULL ) );
exit:
return;
diff --git a/tests/suites/test_suite_ecp.data b/tests/suites/test_suite_ecp.data
index 106791c..485046f 100644
--- a/tests/suites/test_suite_ecp.data
+++ b/tests/suites/test_suite_ecp.data
@@ -1,6 +1,3 @@
-ECP valid params
-ecp_valid_param:
-
ECP invalid params
ecp_invalid_param:
@@ -276,6 +273,42 @@
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
mbedtls_ecp_gen_key:MBEDTLS_ECP_DP_SECP192R1
+ECP generate Montgomery key: Curve25519, random in range
+genkey_mx_known_answer:254:"9e020406080a0c0e10121416181a1c1e20222426282a2c2e30323436383a3df0":"4f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1ef8"
+
+ECP generate Montgomery key: Curve25519, clear higher bit
+genkey_mx_known_answer:254:"ff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1ef8":"7f808101820283038404850586068707880889098a0a8b0b8c0c8d0d8e0e8f78"
+
+ECP generate Montgomery key: Curve25519, clear low bits
+genkey_mx_known_answer:254:"9e020406080a0c0e10121416181a1c1e20222426282a2c2e30323436383a3dff":"4f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1ef8"
+
+ECP generate Montgomery key: Curve25519, random = all-bits-zero
+genkey_mx_known_answer:254:"0000000000000000000000000000000000000000000000000000000000000000":"4000000000000000000000000000000000000000000000000000000000000000"
+
+ECP generate Montgomery key: Curve25519, random = all-bits-one
+genkey_mx_known_answer:254:"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff":"7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8"
+
+ECP generate Montgomery key: Curve25519, not enough entropy
+genkey_mx_known_answer:254:"4f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e":""
+
+ECP generate Montgomery key: Curve448, random in range
+genkey_mx_known_answer:447:"cf0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536fc":"cf0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536fc"
+
+ECP generate Montgomery key: Curve448, set high bit
+genkey_mx_known_answer:447:"0f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536fc":"8f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536fc"
+
+ECP generate Montgomery key: Curve448, clear low bits
+genkey_mx_known_answer:447:"cf0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536ff":"cf0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536fc"
+
+ECP generate Montgomery key: Curve448, random = all-bits-zero
+genkey_mx_known_answer:447:"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000":"8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
+
+ECP generate Montgomery key: Curve448, random = all-bits-one
+genkey_mx_known_answer:447:"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff":"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"
+
+ECP generate Montgomery key: Curve448, not enough entropy
+genkey_mx_known_answer:447:"4f0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536":""
+
ECP read key #1 (short weierstrass, too small)
depends_on:MBEDTLS_ECP_DP_SECP192R1_ENABLED
mbedtls_ecp_read_key:MBEDTLS_ECP_DP_SECP192R1:"00":MBEDTLS_ERR_ECP_INVALID_KEY:0
diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function
index 6d23377..a697e72 100644
--- a/tests/suites/test_suite_ecp.function
+++ b/tests/suites/test_suite_ecp.function
@@ -15,6 +15,7 @@
#define ECP_PT_RESET( x ) \
mbedtls_ecp_point_free( x ); \
mbedtls_ecp_point_init( x );
+
/* END_HEADER */
/* BEGIN_DEPENDENCIES
@@ -22,347 +23,26 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE */
-void ecp_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_ecp_group_free( NULL ) );
- TEST_VALID_PARAM( mbedtls_ecp_keypair_free( NULL ) );
- TEST_VALID_PARAM( mbedtls_ecp_point_free( NULL ) );
-
-#if defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_VALID_PARAM( mbedtls_ecp_restart_free( NULL ) );
-#endif /* MBEDTLS_ECP_RESTARTABLE */
-
-exit:
- return;
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void ecp_invalid_param( )
{
mbedtls_ecp_group grp;
- mbedtls_ecp_keypair kp;
mbedtls_ecp_point P;
- mbedtls_mpi m;
- const char *x = "deadbeef";
- int valid_fmt = MBEDTLS_ECP_PF_UNCOMPRESSED;
int invalid_fmt = 42;
size_t olen;
unsigned char buf[42] = { 0 };
- const unsigned char *null_buf = NULL;
- mbedtls_ecp_group_id valid_group = MBEDTLS_ECP_DP_SECP192R1;
-#if defined(MBEDTLS_ECP_RESTARTABLE)
- mbedtls_ecp_restart_ctx restart_ctx;
-#endif /* MBEDTLS_ECP_RESTARTABLE */
- TEST_INVALID_PARAM( mbedtls_ecp_point_init( NULL ) );
- TEST_INVALID_PARAM( mbedtls_ecp_keypair_init( NULL ) );
- TEST_INVALID_PARAM( mbedtls_ecp_group_init( NULL ) );
-
-#if defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_INVALID_PARAM( mbedtls_ecp_restart_init( NULL ) );
- TEST_INVALID_PARAM( mbedtls_ecp_check_budget( NULL, &restart_ctx, 42 ) );
-#endif /* MBEDTLS_ECP_RESTARTABLE */
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_copy( NULL, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_copy( &P, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_group_copy( NULL, &grp ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_group_copy( &grp, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_privkey( NULL,
- &m,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_privkey( &grp,
- NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_privkey( &grp,
- &m,
- NULL,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_set_zero( NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_is_zero( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_cmp( NULL, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_cmp( &P, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_string( NULL, 2,
- x, x ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_string( &P, 2,
- NULL, x ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_string( &P, 2,
- x, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_write_binary( NULL, &P,
- valid_fmt,
- &olen,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_write_binary( &grp, NULL,
- valid_fmt,
- &olen,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
mbedtls_ecp_point_write_binary( &grp, &P,
invalid_fmt,
&olen,
buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_write_binary( &grp, &P,
- valid_fmt,
- NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_write_binary( &grp, &P,
- valid_fmt,
- &olen,
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_binary( NULL, &P, buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_binary( &grp, NULL, buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_point_read_binary( &grp, &P, NULL,
- sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_point( NULL, &P,
- (const unsigned char **) &buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_point( &grp, NULL,
- (const unsigned char **) &buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_point( &grp, &P, &null_buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_point( &grp, &P, NULL,
- sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_point( NULL, &P,
- valid_fmt,
- &olen,
- buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_point( &grp, NULL,
- valid_fmt,
- &olen,
- buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
mbedtls_ecp_tls_write_point( &grp, &P,
invalid_fmt,
&olen,
buf,
sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_point( &grp, &P,
- valid_fmt,
- NULL,
- buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_point( &grp, &P,
- valid_fmt,
- &olen,
- NULL,
- sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_group_load( NULL, valid_group ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group( NULL,
- (const unsigned char **) &buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group( &grp, NULL,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group( &grp, &null_buf,
- sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group_id( NULL,
- (const unsigned char **) &buf,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group_id( &valid_group, NULL,
- sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_read_group_id( &valid_group,
- &null_buf,
- sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_group( NULL, &olen,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_group( &grp, NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_tls_write_group( &grp, &olen,
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul( NULL, &P, &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul( &grp, NULL, &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul( &grp, &P, NULL, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul( &grp, &P, &m, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul_restartable( NULL, &P, &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL , NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul_restartable( &grp, NULL, &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL , NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul_restartable( &grp, &P, NULL, &P,
- mbedtls_test_rnd_std_rand,
- NULL , NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_mul_restartable( &grp, &P, &m, NULL,
- mbedtls_test_rnd_std_rand,
- NULL , NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( NULL, &P, &m, &P,
- &m, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( &grp, NULL, &m, &P,
- &m, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( &grp, &P, NULL, &P,
- &m, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( &grp, &P, &m, NULL,
- &m, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( &grp, &P, &m, &P,
- NULL, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd( &grp, &P, &m, &P,
- &m, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( NULL, &P, &m, &P,
- &m, &P, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( &grp, NULL, &m, &P,
- &m, &P, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( &grp, &P, NULL, &P,
- &m, &P, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( &grp, &P, &m, NULL,
- &m, &P, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( &grp, &P, &m, &P,
- NULL, &P, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_muladd_restartable( &grp, &P, &m, &P,
- &m, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_pubkey( NULL, &P ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_pubkey( &grp, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_pub_priv( NULL, &kp ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_pub_priv( &kp, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_privkey( NULL, &m ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_check_privkey( &grp, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair_base( NULL, &P, &m, &P,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair_base( &grp, NULL, &m, &P,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair_base( &grp, &P, NULL, &P,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair_base( &grp, &P, &m, NULL,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair_base( &grp, &P, &m, &P, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair( NULL,
- &m, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair( &grp,
- NULL, &P,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair( &grp,
- &m, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_keypair( &grp,
- &m, &P,
- NULL,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_key( valid_group, NULL,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
- mbedtls_ecp_gen_key( valid_group, &kp,
- NULL, NULL ) );
exit:
return;
@@ -1237,6 +917,55 @@
}
/* END_CASE */
+/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS:MBEDTLS_ECP_MONTGOMERY_ENABLED */
+void genkey_mx_known_answer( int bits, data_t *seed, data_t *expected )
+{
+ mbedtls_test_rnd_buf_info rnd_info;
+ mbedtls_mpi d;
+ int ret;
+ uint8_t *actual = NULL;
+
+ mbedtls_mpi_init( &d );
+ rnd_info.buf = seed->x;
+ rnd_info.length = seed->len;
+ rnd_info.fallback_f_rng = NULL;
+ rnd_info.fallback_p_rng = NULL;
+
+ ASSERT_ALLOC( actual, expected->len );
+
+ ret = mbedtls_ecp_gen_privkey_mx( bits, &d,
+ mbedtls_test_rnd_buffer_rand, &rnd_info );
+
+ if( expected->len == 0 )
+ {
+ /* Expecting an error (happens if there isn't enough randomness) */
+ TEST_ASSERT( ret != 0 );
+ }
+ else
+ {
+ TEST_EQUAL( ret, 0 );
+ TEST_EQUAL( (size_t) bits + 1, mbedtls_mpi_bitlen( &d ) );
+ TEST_EQUAL( 0, mbedtls_mpi_write_binary( &d, actual, expected->len ) );
+ /* Test the exact result. This assumes that the output of the
+ * RNG is used in a specific way, which is overly constraining.
+ * The advantage is that it's easier to test the expected properties
+ * of the generated key:
+ * - The most significant bit must be at a specific positions
+ * (can be enforced by checking the bit-length).
+ * - The least significant bits must have specific values
+ * (can be enforced by checking these bits).
+ * - Other bits must be random (by testing with different RNG outputs,
+ * we validate that those bits are indeed influenced by the RNG). */
+ ASSERT_COMPARE( expected->x, expected->len,
+ actual, expected->len );
+ }
+
+exit:
+ mbedtls_free( actual );
+ mbedtls_mpi_free( &d );
+}
+/* END_CASE */
+
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void ecp_selftest( )
{
diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function
index 9733eb2..a6b0a4c 100644
--- a/tests/suites/test_suite_gcm.function
+++ b/tests/suites/test_suite_gcm.function
@@ -181,178 +181,26 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:NOT_DEFINED */
void gcm_invalid_param( )
{
mbedtls_gcm_context ctx;
unsigned char valid_buffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
mbedtls_cipher_id_t valid_cipher = MBEDTLS_CIPHER_ID_AES;
- int valid_mode = MBEDTLS_GCM_ENCRYPT;
- int valid_len = sizeof(valid_buffer);
- int valid_bitlen = 128, invalid_bitlen = 1;
- size_t olen;
+ int invalid_bitlen = 1;
mbedtls_gcm_init( &ctx );
- /* mbedtls_gcm_init() */
- TEST_INVALID_PARAM( mbedtls_gcm_init( NULL ) );
-
/* mbedtls_gcm_setkey */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_setkey( NULL, valid_cipher, valid_buffer, valid_bitlen ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_setkey( &ctx, valid_cipher, NULL, valid_bitlen ) );
- TEST_INVALID_PARAM_RET(
+ TEST_EQUAL(
MBEDTLS_ERR_GCM_BAD_INPUT,
mbedtls_gcm_setkey( &ctx, valid_cipher, valid_buffer, invalid_bitlen ) );
- /* mbedtls_gcm_crypt_and_tag() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( NULL, valid_mode, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_len, valid_buffer ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_len, valid_buffer ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer,
- valid_len, valid_buffer ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer,
- valid_len, valid_buffer ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL,
- valid_len, valid_buffer ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_crypt_and_tag( &ctx, valid_mode, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer,
- valid_len, NULL ) );
-
- /* mbedtls_gcm_auth_decrypt() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( &ctx, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_buffer) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_len,
- valid_buffer, valid_buffer) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- NULL, valid_buffer) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_auth_decrypt( &ctx, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, valid_len,
- valid_buffer, NULL) );
-
- /* mbedtls_gcm_starts() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_starts( NULL, valid_mode,
- valid_buffer, valid_len ) );
-
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_starts( &ctx, valid_mode,
- NULL, valid_len ) );
-
- /* mbedtls_gcm_update_ad() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_update_ad( &ctx,
- NULL, valid_len ) );
-
- /* mbedtls_gcm_update() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_update( NULL, valid_buffer, valid_len,
- valid_buffer, valid_len, &olen ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_update( &ctx, NULL, valid_len,
- valid_buffer, valid_len, &olen ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_update( &ctx, valid_buffer, valid_len,
- NULL, valid_len, &olen ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_update( &ctx, valid_buffer, valid_len,
- valid_buffer, valid_len, NULL ) );
-
- /* mbedtls_gcm_finish() */
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_finish( NULL, NULL, 0, valid_buffer, valid_len ) );
- TEST_INVALID_PARAM_RET(
- MBEDTLS_ERR_GCM_BAD_INPUT,
- mbedtls_gcm_finish( &ctx, NULL, 0, NULL, valid_len ) );
-
exit:
mbedtls_gcm_free( &ctx );
}
/* END_CASE */
-/* BEGIN_CASE */
-void gcm_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_gcm_free( NULL ) );
-exit:
- return;
-}
-/* END_CASE */
-
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void gcm_selftest( )
{
diff --git a/tests/suites/test_suite_gcm.misc.data b/tests/suites/test_suite_gcm.misc.data
index cf01526..f22b7a3 100644
--- a/tests/suites/test_suite_gcm.misc.data
+++ b/tests/suites/test_suite_gcm.misc.data
@@ -1,5 +1,2 @@
GCM - Invalid parameters
gcm_invalid_param:
-
-GCM - Valid parameters
-gcm_valid_param:
diff --git a/tests/suites/test_suite_mpi.data b/tests/suites/test_suite_mpi.data
index 59fd782..553b8eb 100644
--- a/tests/suites/test_suite_mpi.data
+++ b/tests/suites/test_suite_mpi.data
@@ -1,9 +1,3 @@
-MPI - Valid parameters
-mpi_valid_param:
-
-MPI - Invalid parameters
-mpi_invalid_param:
-
Arguments with no value
mpi_null:
@@ -992,46 +986,246 @@
mbedtls_mpi_set_bit:16:"00":5:2:16:"00":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
Fill random: 0 bytes
-mpi_fill_random:0:0:0
+mpi_fill_random:0:0:0:0
Fill random: 1 byte, good
-mpi_fill_random:1:1:0
+mpi_fill_random:1:1:0:0
Fill random: 2 bytes, good, no leading zero
-mpi_fill_random:2:2:0
+mpi_fill_random:2:2:0:0
Fill random: 2 bytes, good, 1 leading zero
-mpi_fill_random:2:256:0
+mpi_fill_random:2:256:0:0
Fill random: MAX_SIZE - 7, good
-mpi_fill_random:MBEDTLS_MPI_MAX_SIZE - 7:MBEDTLS_MPI_MAX_SIZE - 7:0
+mpi_fill_random:MBEDTLS_MPI_MAX_SIZE - 7:MBEDTLS_MPI_MAX_SIZE - 7:0:0
Fill random: MAX_SIZE, good
-mpi_fill_random:MBEDTLS_MPI_MAX_SIZE:MBEDTLS_MPI_MAX_SIZE:0
+mpi_fill_random:MBEDTLS_MPI_MAX_SIZE:MBEDTLS_MPI_MAX_SIZE:0:0
+
+Fill random: 0 bytes, previously small >0
+mpi_fill_random:0:0:1:0
+
+Fill random: 0 bytes, previously small <0
+mpi_fill_random:0:0:-1:0
+
+Fill random: 0 bytes, previously large >0
+mpi_fill_random:0:0:65:0
+
+Fill random: 0 bytes, previously large <0
+mpi_fill_random:0:0:-65:0
+
+Fill random: 1 byte, previously small >0
+mpi_fill_random:1:1:1:0
+
+Fill random: 1 byte, previously small <0
+mpi_fill_random:1:1:-1:0
+
+Fill random: 1 byte, previously large >0
+mpi_fill_random:1:1:65:0
+
+Fill random: 1 byte, previously large <0
+mpi_fill_random:1:1:-65:0
+
+Fill random: 9 bytes, previously small >0
+mpi_fill_random:1:1:1:0
+
+Fill random: 9 bytes, previously small <0
+mpi_fill_random:1:1:-1:0
Fill random: 1 byte, RNG failure
-mpi_fill_random:1:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:1:0:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 2 bytes, RNG failure after 1 byte
-mpi_fill_random:2:1:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:2:1:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 4 bytes, RNG failure after 3 bytes
-mpi_fill_random:4:3:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:4:3:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 8 bytes, RNG failure after 7 bytes
-mpi_fill_random:8:7:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:8:7:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 16 bytes, RNG failure after 1 bytes
-mpi_fill_random:16:1:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:16:1:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 16 bytes, RNG failure after 8 bytes
-mpi_fill_random:16:8:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:16:8:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: 16 bytes, RNG failure after 15 bytes
-mpi_fill_random:16:15:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:16:15:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
Fill random: MAX_SIZE bytes, RNG failure after MAX_SIZE-1 bytes
-mpi_fill_random:MBEDTLS_MPI_MAX_SIZE:MBEDTLS_MPI_MAX_SIZE-1:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+mpi_fill_random:MBEDTLS_MPI_MAX_SIZE:MBEDTLS_MPI_MAX_SIZE-1:0:MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
+
+MPI random in range: 1..2
+mpi_random_many:1:"02":1000
+
+MPI random in range: 1..3
+mpi_random_many:1:"03":1000
+
+MPI random in range: 1..4
+mpi_random_many:1:"04":1000
+
+MPI random in range: 1..5
+mpi_random_many:1:"05":1000
+
+MPI random in range: 1..6
+mpi_random_many:1:"06":1000
+
+MPI random in range: 1..7
+mpi_random_many:1:"07":1000
+
+MPI random in range: 1..8
+mpi_random_many:1:"08":1000
+
+MPI random in range: 1..9
+mpi_random_many:1:"09":1000
+
+MPI random in range: 1..10
+mpi_random_many:1:"0a":1000
+
+MPI random in range: 1..11
+mpi_random_many:1:"0b":1000
+
+MPI random in range: 1..12
+mpi_random_many:1:"0c":1000
+
+MPI random in range: 1..255
+mpi_random_many:1:"ff":100
+
+MPI random in range: 1..256
+mpi_random_many:1:"0100":100
+
+MPI random in range: 1..257
+mpi_random_many:1:"0101":100
+
+MPI random in range: 1..272
+mpi_random_many:1:"0110":100
+
+MPI random in range: 1..2^64-1
+mpi_random_many:1:"ffffffffffffffff":100
+
+MPI random in range: 1..2^64
+mpi_random_many:1:"010000000000000000":100
+
+MPI random in range: 1..2^64+1
+mpi_random_many:1:"010000000000000001":100
+
+MPI random in range: 1..2^64+2^63
+mpi_random_many:1:"018000000000000000":100
+
+MPI random in range: 1..2^65-1
+mpi_random_many:1:"01ffffffffffffffff":100
+
+MPI random in range: 1..2^65
+mpi_random_many:1:"020000000000000000":100
+
+MPI random in range: 1..2^65+1
+mpi_random_many:1:"020000000000000001":100
+
+MPI random in range: 1..2^65+2^64
+mpi_random_many:1:"030000000000000000":100
+
+MPI random in range: 1..2^66+2^65
+mpi_random_many:1:"060000000000000000":100
+
+MPI random in range: 1..2^71-1
+mpi_random_many:1:"7fffffffffffffffff":100
+
+MPI random in range: 1..2^71
+mpi_random_many:1:"800000000000000000":100
+
+MPI random in range: 1..2^71+1
+mpi_random_many:1:"800000000000000001":100
+
+MPI random in range: 1..2^71+2^70
+mpi_random_many:1:"c00000000000000000":100
+
+MPI random in range: 1..2^72-1
+mpi_random_many:1:"ffffffffffffffffff":100
+
+MPI random in range: 1..2^72
+mpi_random_many:1:"01000000000000000000":100
+
+MPI random in range: 1..2^72+1
+mpi_random_many:1:"01000000000000000001":100
+
+MPI random in range: 1..2^72+2^71
+mpi_random_many:1:"01800000000000000000":100
+
+MPI random in range: 0..1
+mpi_random_many:0:"04":10000
+
+MPI random in range: 0..4
+mpi_random_many:0:"04":10000
+
+MPI random in range: 2..4
+mpi_random_many:2:"04":10000
+
+MPI random in range: 3..4
+mpi_random_many:3:"04":10000
+
+MPI random in range: smaller result
+mpi_random_sizes:1:"aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb":1:0
+
+MPI random in range: same size result (32-bit limbs)
+mpi_random_sizes:1:"aaaaaaaaaaaaaaaa":2:0
+
+MPI random in range: same size result (64-bit limbs)
+mpi_random_sizes:1:"aaaaaaaaaaaaaaaa":1:0
+
+MPI random in range: larger result
+mpi_random_sizes:1:"aaaaaaaaaaaaaaaa":3:0
+
+## The "0 limb in upper bound" tests rely on the fact that
+## mbedtls_mpi_read_binary() bases the size of the MPI on the size of
+## the input, without first checking for leading zeros. If this was
+## not the case, the tests would still pass, but would not exercise
+## the advertised behavior.
+MPI random in range: leading 0 limb in upper bound #0
+mpi_random_sizes:1:"00aaaaaaaaaaaaaaaa":0:0
+
+MPI random in range: leading 0 limb in upper bound #1
+mpi_random_sizes:1:"00aaaaaaaaaaaaaaaa":1:0
+
+MPI random in range: leading 0 limb in upper bound #2
+mpi_random_sizes:1:"00aaaaaaaaaaaaaaaa":2:0
+
+MPI random in range: leading 0 limb in upper bound #3
+mpi_random_sizes:1:"00aaaaaaaaaaaaaaaa":3:0
+
+MPI random in range: leading 0 limb in upper bound #4
+mpi_random_sizes:1:"00aaaaaaaaaaaaaaaa":4:0
+
+MPI random in range: previously small >0
+mpi_random_sizes:1:"1234567890":4:1
+
+MPI random in range: previously small <0
+mpi_random_sizes:1:"1234567890":4:-1
+
+MPI random in range: previously large >0
+mpi_random_sizes:1:"1234":4:65
+
+MPI random in range: previously large <0
+mpi_random_sizes:1:"1234":4:-65
+
+MPI random bad arguments: min < 0
+mpi_random_fail:-1:"04":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
+
+MPI random bad arguments: min = N = 0
+mpi_random_fail:0:"00":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
+
+MPI random bad arguments: min = N = 1
+mpi_random_fail:1:"01":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
+
+MPI random bad arguments: min > N = 0
+mpi_random_fail:1:"00":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
+
+MPI random bad arguments: min > N = 1
+mpi_random_fail:2:"01":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
+
+MPI random bad arguments: min > N = 1, 0 limb in upper bound
+mpi_random_fail:2:"000000000000000001":MBEDTLS_ERR_MPI_BAD_INPUT_DATA
MPI Selftest
depends_on:MBEDTLS_SELF_TEST
diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function
index c5bb5a6..eb918b3 100644
--- a/tests/suites/test_suite_mpi.function
+++ b/tests/suites/test_suite_mpi.function
@@ -64,6 +64,50 @@
return( 0 );
}
+/* Test whether bytes represents (in big-endian base 256) a number b that
+ * is significantly above a power of 2. That is, b must not have a long run
+ * of unset bits after the most significant bit.
+ *
+ * Let n be the bit-size of b, i.e. the integer such that 2^n <= b < 2^{n+1}.
+ * This function returns 1 if, when drawing a number between 0 and b,
+ * the probability that this number is at least 2^n is not negligible.
+ * This probability is (b - 2^n) / b and this function checks that this
+ * number is above some threshold A. The threshold value is heuristic and
+ * based on the needs of mpi_random_many().
+ */
+static int is_significantly_above_a_power_of_2( data_t *bytes )
+{
+ const uint8_t *p = bytes->x;
+ size_t len = bytes->len;
+ unsigned x;
+
+ /* Skip leading null bytes */
+ while( len > 0 && p[0] == 0 )
+ {
+ ++p;
+ --len;
+ }
+ /* 0 is not significantly above a power of 2 */
+ if( len == 0 )
+ return( 0 );
+ /* Extract the (up to) 2 most significant bytes */
+ if( len == 1 )
+ x = p[0];
+ else
+ x = ( p[0] << 8 ) | p[1];
+
+ /* Shift the most significant bit of x to position 8 and mask it out */
+ while( ( x & 0xfe00 ) != 0 )
+ x >>= 1;
+ x &= 0x00ff;
+
+ /* At this point, x = floor((b - 2^n) / 2^(n-8)). b is significantly above
+ * a power of 2 iff x is significantly above 0 compared to 2^8.
+ * Testing x >= 2^4 amounts to picking A = 1/16 in the function
+ * description above. */
+ return( x >= 0x10 );
+}
+
/* END_HEADER */
/* BEGIN_DEPENDENCIES
@@ -72,221 +116,6 @@
*/
/* BEGIN_CASE */
-void mpi_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_mpi_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void mpi_invalid_param( )
-{
- mbedtls_mpi X;
- const char *s_in = "00101000101010";
- char s_out[16] = { 0 };
- unsigned char u_out[16] = { 0 };
- unsigned char u_in[16] = { 0 };
- size_t olen;
- mbedtls_mpi_uint mpi_uint;
-
- TEST_INVALID_PARAM( mbedtls_mpi_init( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_grow( NULL, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_copy( NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_copy( &X, NULL ) );
-
- TEST_INVALID_PARAM( mbedtls_mpi_swap( NULL, &X ) );
- TEST_INVALID_PARAM( mbedtls_mpi_swap( &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_safe_cond_assign( NULL, &X, 0 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_safe_cond_assign( &X, NULL, 0 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_safe_cond_swap( NULL, &X, 0 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_safe_cond_swap( &X, NULL, 0 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_lset( NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_get_bit( NULL, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_set_bit( NULL, 42, 0 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_string( NULL, 2, s_in ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_string( &X, 2, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_string( NULL, 2,
- s_out, sizeof( s_out ),
- &olen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_string( &X, 2,
- NULL, sizeof( s_out ),
- &olen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_string( &X, 2,
- s_out, sizeof( s_out ),
- NULL ) );
-
-#if defined(MBEDTLS_FS_IO)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_file( NULL, 2, stdin ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_file( &X, 2, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_file( "", NULL, 2, NULL ) );
-#endif /* MBEDTLS_FS_IO */
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_binary( NULL, u_in,
- sizeof( u_in ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_read_binary( &X, NULL,
- sizeof( u_in ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_binary( NULL, u_out,
- sizeof( u_out ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_write_binary( &X, NULL,
- sizeof( u_out ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_shift_l( NULL, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_shift_r( NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_cmp_abs( NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_cmp_abs( &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_cmp_mpi( NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_cmp_mpi( &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_cmp_int( NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_abs( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_abs( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_abs( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_abs( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_abs( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_abs( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_mpi( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_mpi( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_mpi( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_mpi( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_mpi( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_mpi( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_int( NULL, &X, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_add_int( &X, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_int( NULL, &X, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_sub_int( &X, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mul_mpi( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mul_mpi( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mul_mpi( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mul_int( NULL, &X, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mul_int( &X, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_div_mpi( &X, &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_div_mpi( &X, &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_div_int( &X, &X, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( 0, mbedtls_mpi_lsb( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_mpi( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_mpi( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_mpi( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_int( NULL, &X, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_mod_int( &mpi_uint, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_exp_mod( NULL, &X, &X, &X, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_exp_mod( &X, NULL, &X, &X, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_exp_mod( &X, &X, NULL, &X, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_exp_mod( &X, &X, &X, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_fill_random( NULL, 42,
- mbedtls_test_rnd_std_rand,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_fill_random( &X, 42, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_gcd( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_gcd( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_gcd( &X, &X, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_inv_mod( NULL, &X, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_inv_mod( &X, NULL, &X ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
- mbedtls_mpi_inv_mod( &X, &X, NULL ) );
-
-exit:
- return;
-}
-/* END_CASE */
-
-/* BEGIN_CASE */
void mpi_null( )
{
mbedtls_mpi X, Y, Z;
@@ -1366,13 +1195,23 @@
/* END_CASE */
/* BEGIN_CASE */
-void mpi_fill_random( int wanted_bytes, int rng_bytes, int expected_ret )
+void mpi_fill_random( int wanted_bytes, int rng_bytes,
+ int before, int expected_ret )
{
mbedtls_mpi X;
int ret;
size_t bytes_left = rng_bytes;
mbedtls_mpi_init( &X );
+ if( before != 0 )
+ {
+ /* Set X to sign(before) * 2^(|before|-1) */
+ TEST_ASSERT( mbedtls_mpi_lset( &X, before > 0 ? 1 : -1 ) == 0 );
+ if( before < 0 )
+ before = - before;
+ TEST_ASSERT( mbedtls_mpi_shift_l( &X, before - 1 ) == 0 );
+ }
+
ret = mbedtls_mpi_fill_random( &X, wanted_bytes,
f_rng_bytes_left, &bytes_left );
TEST_ASSERT( ret == expected_ret );
@@ -1396,6 +1235,168 @@
}
/* END_CASE */
+/* BEGIN_CASE */
+void mpi_random_many( int min, data_t *bound_bytes, int iterations )
+{
+ /* Generate numbers in the range 1..bound-1. Do it iterations times.
+ * This function assumes that the value of bound is at least 2 and
+ * that iterations is large enough that a one-in-2^iterations chance
+ * effectively never occurs.
+ */
+
+ mbedtls_mpi upper_bound;
+ size_t n_bits;
+ mbedtls_mpi result;
+ size_t b;
+ /* If upper_bound is small, stats[b] is the number of times the value b
+ * has been generated. Otherwise stats[b] is the number of times a
+ * value with bit b set has been generated. */
+ size_t *stats = NULL;
+ size_t stats_len;
+ int full_stats;
+ size_t i;
+
+ mbedtls_mpi_init( &upper_bound );
+ mbedtls_mpi_init( &result );
+
+ TEST_EQUAL( 0, mbedtls_mpi_read_binary( &upper_bound,
+ bound_bytes->x, bound_bytes->len ) );
+ n_bits = mbedtls_mpi_bitlen( &upper_bound );
+ /* Consider a bound "small" if it's less than 2^5. This value is chosen
+ * to be small enough that the probability of missing one value is
+ * negligible given the number of iterations. It must be less than
+ * 256 because some of the code below assumes that "small" values
+ * fit in a byte. */
+ if( n_bits <= 5 )
+ {
+ full_stats = 1;
+ stats_len = bound_bytes->x[bound_bytes->len - 1];
+ }
+ else
+ {
+ full_stats = 0;
+ stats_len = n_bits;
+ }
+ ASSERT_ALLOC( stats, stats_len );
+
+ for( i = 0; i < (size_t) iterations; i++ )
+ {
+ mbedtls_test_set_step( i );
+ TEST_EQUAL( 0, mbedtls_mpi_random( &result, min, &upper_bound,
+ mbedtls_test_rnd_std_rand, NULL ) );
+
+ TEST_ASSERT( mbedtls_mpi_cmp_mpi( &result, &upper_bound ) < 0 );
+ TEST_ASSERT( mbedtls_mpi_cmp_int( &result, min ) >= 0 );
+ if( full_stats )
+ {
+ uint8_t value;
+ TEST_EQUAL( 0, mbedtls_mpi_write_binary( &result, &value, 1 ) );
+ TEST_ASSERT( value < stats_len );
+ ++stats[value];
+ }
+ else
+ {
+ for( b = 0; b < n_bits; b++ )
+ stats[b] += mbedtls_mpi_get_bit( &result, b );
+ }
+ }
+
+ if( full_stats )
+ {
+ for( b = min; b < stats_len; b++ )
+ {
+ mbedtls_test_set_step( 1000000 + b );
+ /* Assert that each value has been reached at least once.
+ * This is almost guaranteed if the iteration count is large
+ * enough. This is a very crude way of checking the distribution.
+ */
+ TEST_ASSERT( stats[b] > 0 );
+ }
+ }
+ else
+ {
+ int statistically_safe_all_the_way =
+ is_significantly_above_a_power_of_2( bound_bytes );
+ for( b = 0; b < n_bits; b++ )
+ {
+ mbedtls_test_set_step( 1000000 + b );
+ /* Assert that each bit has been set in at least one result and
+ * clear in at least one result. Provided that iterations is not
+ * too small, it would be extremely unlikely for this not to be
+ * the case if the results are uniformly distributed.
+ *
+ * As an exception, the top bit may legitimately never be set
+ * if bound is a power of 2 or only slightly above.
+ */
+ if( statistically_safe_all_the_way || b != n_bits - 1 )
+ {
+ TEST_ASSERT( stats[b] > 0 );
+ }
+ TEST_ASSERT( stats[b] < (size_t) iterations );
+ }
+ }
+
+exit:
+ mbedtls_mpi_free( &upper_bound );
+ mbedtls_mpi_free( &result );
+ mbedtls_free( stats );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void mpi_random_sizes( int min, data_t *bound_bytes, int nlimbs, int before )
+{
+ mbedtls_mpi upper_bound;
+ mbedtls_mpi result;
+
+ mbedtls_mpi_init( &upper_bound );
+ mbedtls_mpi_init( &result );
+
+ if( before != 0 )
+ {
+ /* Set result to sign(before) * 2^(|before|-1) */
+ TEST_ASSERT( mbedtls_mpi_lset( &result, before > 0 ? 1 : -1 ) == 0 );
+ if( before < 0 )
+ before = - before;
+ TEST_ASSERT( mbedtls_mpi_shift_l( &result, before - 1 ) == 0 );
+ }
+
+ TEST_EQUAL( 0, mbedtls_mpi_grow( &result, nlimbs ) );
+ TEST_EQUAL( 0, mbedtls_mpi_read_binary( &upper_bound,
+ bound_bytes->x, bound_bytes->len ) );
+ TEST_EQUAL( 0, mbedtls_mpi_random( &result, min, &upper_bound,
+ mbedtls_test_rnd_std_rand, NULL ) );
+ TEST_ASSERT( mbedtls_mpi_cmp_mpi( &result, &upper_bound ) < 0 );
+ TEST_ASSERT( mbedtls_mpi_cmp_int( &result, min ) >= 0 );
+
+exit:
+ mbedtls_mpi_free( &upper_bound );
+ mbedtls_mpi_free( &result );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void mpi_random_fail( int min, data_t *bound_bytes, int expected_ret )
+{
+ mbedtls_mpi upper_bound;
+ mbedtls_mpi result;
+ int actual_ret;
+
+ mbedtls_mpi_init( &upper_bound );
+ mbedtls_mpi_init( &result );
+
+ TEST_EQUAL( 0, mbedtls_mpi_read_binary( &upper_bound,
+ bound_bytes->x, bound_bytes->len ) );
+ actual_ret = mbedtls_mpi_random( &result, min, &upper_bound,
+ mbedtls_test_rnd_std_rand, NULL );
+ TEST_EQUAL( expected_ret, actual_ret );
+
+exit:
+ mbedtls_mpi_free( &upper_bound );
+ mbedtls_mpi_free( &result );
+}
+/* END_CASE */
+
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void mpi_selftest( )
{
diff --git a/tests/suites/test_suite_pk.data b/tests/suites/test_suite_pk.data
index 9ebdc7e..5eb145d 100644
--- a/tests/suites/test_suite_pk.data
+++ b/tests/suites/test_suite_pk.data
@@ -1,6 +1,3 @@
-PK invalid parameters
-invalid_parameters:
-
PK valid parameters
valid_parameters:
diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function
index ddef836..573c9d4 100644
--- a/tests/suites/test_suite_pk.function
+++ b/tests/suites/test_suite_pk.function
@@ -211,12 +211,6 @@
mbedtls_pk_init( &pk );
- TEST_VALID_PARAM( mbedtls_pk_free( NULL ) );
-
-#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_VALID_PARAM( mbedtls_pk_restart_free( NULL ) );
-#endif
-
TEST_ASSERT( mbedtls_pk_setup( &pk, NULL ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
@@ -323,275 +317,6 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void invalid_parameters( )
-{
- size_t len;
- unsigned char *null_buf = NULL;
- unsigned char buf[1];
- unsigned char *p = buf;
- char str[1] = {0};
- mbedtls_pk_context pk;
- mbedtls_md_type_t valid_md = MBEDTLS_MD_SHA256;
- void *options = buf;
-
- (void) null_buf;
- (void) p;
- (void) str;
-
- mbedtls_pk_init( &pk );
-
- TEST_INVALID_PARAM( mbedtls_pk_init( NULL ) );
-
-#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
- TEST_INVALID_PARAM( mbedtls_pk_restart_init( NULL ) );
-#endif
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_setup( NULL, NULL ) );
-
-#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_setup_rsa_alt( NULL, buf,
- NULL, NULL, NULL ) );
-#endif
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( NULL,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- buf, sizeof( buf ),
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( &pk,
- MBEDTLS_MD_NONE,
- NULL, sizeof( buf ),
- buf, sizeof( buf ),
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( &pk,
- valid_md,
- NULL, 0,
- buf, sizeof( buf ),
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_restartable( &pk,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- NULL, sizeof( buf ),
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify( NULL,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify( &pk,
- MBEDTLS_MD_NONE,
- NULL, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify( &pk,
- valid_md,
- NULL, 0,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify( &pk,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( MBEDTLS_PK_NONE, options,
- NULL,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( MBEDTLS_PK_NONE, options,
- &pk,
- MBEDTLS_MD_NONE,
- NULL, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( MBEDTLS_PK_NONE, options,
- &pk,
- valid_md,
- NULL, 0,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_verify_ext( MBEDTLS_PK_NONE, options,
- &pk,
- MBEDTLS_MD_NONE,
- buf, sizeof( buf ),
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( NULL, MBEDTLS_MD_NONE, buf, sizeof( buf ),
- buf, &len, mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( &pk, MBEDTLS_MD_NONE, NULL, sizeof( buf ),
- buf, &len, mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( &pk, valid_md, NULL, 0, buf, &len,
- mbedtls_test_rnd_std_rand, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign_restartable( &pk, MBEDTLS_MD_NONE, buf, sizeof( buf ),
- NULL, &len, mbedtls_test_rnd_std_rand,
- NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign( NULL, MBEDTLS_MD_NONE, buf, sizeof( buf ),
- buf, &len, mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign( &pk, MBEDTLS_MD_NONE, NULL, sizeof( buf ),
- buf, &len, mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign( &pk, valid_md, NULL, 0, buf, &len,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_sign( &pk, MBEDTLS_MD_NONE, buf, sizeof( buf ), NULL, &len,
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_decrypt( NULL, buf, sizeof( buf ), buf, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_decrypt( &pk, NULL, sizeof( buf ), buf, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_decrypt( &pk, buf, sizeof( buf ), NULL, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_decrypt( &pk, buf, sizeof( buf ), buf, NULL, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_encrypt( NULL, buf, sizeof( buf ), buf, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_encrypt( &pk, NULL, sizeof( buf ), buf, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_encrypt( &pk, buf, sizeof( buf ), NULL, &len, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_encrypt( &pk, buf, sizeof( buf ), buf, NULL, sizeof( buf ),
- mbedtls_test_rnd_std_rand, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_check_pair( NULL, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_check_pair( &pk, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_debug( NULL, NULL ) );
-
-#if defined(MBEDTLS_PK_PARSE_C)
-#if defined(MBEDTLS_FS_IO)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_load_file( NULL, &p, &len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_load_file( str, NULL, &len ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_load_file( str, &p, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_keyfile( NULL, str, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_keyfile( &pk, NULL, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_public_keyfile( NULL, str ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_public_keyfile( &pk, NULL ) );
-#endif
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_subpubkey( NULL, buf, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_subpubkey( &null_buf, buf, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_subpubkey( &p, NULL, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_subpubkey( &p, buf, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_key( NULL,
- buf, sizeof( buf ),
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_key( &pk,
- NULL, sizeof( buf ),
- buf, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_public_key( NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_parse_public_key( &pk,
- NULL, sizeof( buf ) ) );
-#endif /* MBEDTLS_PK_PARSE_C */
-
-#if defined(MBEDTLS_PK_WRITE_C)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey( NULL, p, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey( &null_buf, p, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey( &p, NULL, &pk ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey( &p, p, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey_der( NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey_der( &pk,
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_key_der( NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_key_der( &pk,
- NULL, sizeof( buf ) ) );
-
-#if defined(MBEDTLS_PEM_WRITE_C)
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey_pem( NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_pubkey_pem( &pk,
- NULL, sizeof( buf ) ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_key_pem( NULL,
- buf, sizeof( buf ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
- mbedtls_pk_write_key_pem( &pk,
- NULL, sizeof( buf ) ) );
-#endif /* MBEDTLS_PEM_WRITE_C */
-
-#endif /* MBEDTLS_PK_WRITE_C */
-}
-/* END_CASE */
-
/* BEGIN_CASE */
void pk_utils( int type, int parameter, int bitlen, int len, char * name )
{
@@ -1138,7 +863,7 @@
size_t sig_len, ciph_len, test_len;
int ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
- mbedtls_rsa_init( &raw, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE );
+ mbedtls_rsa_init( &raw );
mbedtls_pk_init( &rsa ); mbedtls_pk_init( &alt );
memset( hash, 0x2a, sizeof hash );
diff --git a/tests/suites/test_suite_pkcs1_v15.function b/tests/suites/test_suite_pkcs1_v15.function
index d1c0fc1..d78ee88 100644
--- a/tests/suites/test_suite_pkcs1_v15.function
+++ b/tests/suites/test_suite_pkcs1_v15.function
@@ -19,11 +19,15 @@
mbedtls_test_rnd_buf_info info;
mbedtls_mpi N, E;
+ info.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ info.fallback_p_rng = NULL;
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -69,7 +73,9 @@
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
memset( output, 0x00, sizeof( output ) );
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
@@ -191,7 +197,7 @@
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
mbedtls_mpi_init( &Nmpi ); mbedtls_mpi_init( &Empi );
mbedtls_mpi_init( &Pmpi ); mbedtls_mpi_init( &Qmpi );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &ctx );
TEST_ASSERT( mbedtls_mpi_read_binary( &Nmpi, N, sizeof( N ) ) == 0 );
TEST_ASSERT( mbedtls_mpi_read_binary( &Empi, E, sizeof( E ) ) == 0 );
@@ -268,12 +274,16 @@
mbedtls_mpi N, P, Q, E;
mbedtls_test_rnd_buf_info info;
+ info.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ info.fallback_p_rng = NULL;
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( output, 0x00, sizeof( output ) );
@@ -321,7 +331,9 @@
((void) salt);
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V15, hash ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
diff --git a/tests/suites/test_suite_pkcs1_v21.function b/tests/suites/test_suite_pkcs1_v21.function
index 8f22f20..ec5591f 100644
--- a/tests/suites/test_suite_pkcs1_v21.function
+++ b/tests/suites/test_suite_pkcs1_v21.function
@@ -18,11 +18,15 @@
mbedtls_test_rnd_buf_info info;
mbedtls_mpi N, E;
+ info.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ info.fallback_p_rng = NULL;
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
@@ -65,7 +69,9 @@
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
memset( output, 0x00, sizeof( output ) );
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
@@ -122,12 +128,16 @@
mbedtls_test_rnd_buf_info info;
mbedtls_mpi N, P, Q, E;
+ info.fallback_f_rng = mbedtls_test_rnd_std_rand;
+ info.fallback_p_rng = NULL;
info.buf = rnd_buf->x;
info.length = rnd_buf->len;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( output, 0x00, sizeof( output ) );
@@ -185,7 +195,9 @@
((void) salt);
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21, hash ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
@@ -221,7 +233,9 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, ctx_hash );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21, ctx_hash ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
TEST_ASSERT( mbedtls_mpi_read_binary( &N, input_N->x, input_N->len ) == 0 );
diff --git a/tests/suites/test_suite_poly1305.data b/tests/suites/test_suite_poly1305.data
index 13912e9..eb9712c 100644
--- a/tests/suites/test_suite_poly1305.data
+++ b/tests/suites/test_suite_poly1305.data
@@ -34,9 +34,6 @@
Poly1305 RFC 7539 Test Vector #11
mbedtls_poly1305:"0100000000000000040000000000000000000000000000000000000000000000":"13000000000000000000000000000000":"e33594d7505e43b900000000000000003394d7505e4379cd010000000000000000000000000000000000000000000000"
-Poly1305 Parameter validation
-poly1305_bad_params:
-
Poly1305 Selftest
depends_on:MBEDTLS_SELF_TEST
poly1305_selftest:
diff --git a/tests/suites/test_suite_poly1305.function b/tests/suites/test_suite_poly1305.function
index 4b8995b..59e9277 100644
--- a/tests/suites/test_suite_poly1305.function
+++ b/tests/suites/test_suite_poly1305.function
@@ -79,45 +79,6 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void poly1305_bad_params()
-{
- unsigned char src[1];
- unsigned char key[32];
- unsigned char mac[16];
- size_t src_len = sizeof( src );
- mbedtls_poly1305_context ctx;
-
- TEST_INVALID_PARAM( mbedtls_poly1305_init( NULL ) );
- TEST_VALID_PARAM( mbedtls_poly1305_free( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_starts( NULL, key ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_starts( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_update( NULL, src, 0 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_update( &ctx, NULL, src_len ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_finish( NULL, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_finish( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_mac( NULL, src, 0, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_mac( key, NULL, src_len, mac ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA,
- mbedtls_poly1305_mac( key, src, 0, NULL ) );
-
-exit:
- return;
-}
-/* END_CASE */
-
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void poly1305_selftest()
{
diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function
index efea5c1..14b4afc 100644
--- a/tests/suites/test_suite_rsa.function
+++ b/tests/suites/test_suite_rsa.function
@@ -17,349 +17,41 @@
* END_DEPENDENCIES
*/
-/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE */
void rsa_invalid_param( )
{
mbedtls_rsa_context ctx;
- const int valid_padding = MBEDTLS_RSA_PKCS_V21;
const int invalid_padding = 42;
- unsigned char buf[42] = { 0 };
- size_t olen;
+ const int invalid_hash_id = 0xff;
- TEST_INVALID_PARAM( mbedtls_rsa_init( NULL, valid_padding, 0 ) );
- TEST_INVALID_PARAM( mbedtls_rsa_init( &ctx, invalid_padding, 0 ) );
- TEST_VALID_PARAM( mbedtls_rsa_free( NULL ) );
+ mbedtls_rsa_init( &ctx );
- /* No more variants because only the first argument must be non-NULL. */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_import( NULL, NULL, NULL,
- NULL, NULL, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_import_raw( NULL,
- NULL, 0,
- NULL, 0,
- NULL, 0,
- NULL, 0,
- NULL, 0 ) );
+ TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
+ invalid_padding,
+ MBEDTLS_MD_NONE ),
+ MBEDTLS_ERR_RSA_INVALID_PADDING );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_complete( NULL ) );
+ TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21,
+ invalid_hash_id ),
+ MBEDTLS_ERR_RSA_INVALID_PADDING );
- /* No more variants because only the first argument must be non-NULL. */
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_export( NULL, NULL, NULL,
- NULL, NULL, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_export_raw( NULL,
- NULL, 0,
- NULL, 0,
- NULL, 0,
- NULL, 0,
- NULL, 0 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_export_crt( NULL, NULL, NULL, NULL ) );
+#if !defined(MBEDTLS_PKCS1_V15)
+ TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V15,
+ MBEDTLS_MD_NONE ),
+ MBEDTLS_ERR_RSA_INVALID_PADDING );
+#endif
- TEST_INVALID_PARAM( mbedtls_rsa_set_padding( NULL,
- valid_padding, 0 ) );
- TEST_INVALID_PARAM( mbedtls_rsa_set_padding( &ctx,
- invalid_padding, 0 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_gen_key( NULL,
- mbedtls_test_rnd_std_rand,
- NULL, 0, 0 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_gen_key( &ctx, NULL,
- NULL, 0, 0 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_check_pubkey( NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_check_privkey( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_check_pub_priv( NULL, &ctx ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_check_pub_priv( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_public( NULL, buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_public( &ctx, NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_public( &ctx, buf, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_private( NULL, NULL, NULL,
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_private( &ctx, NULL, NULL,
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_private( &ctx, NULL, NULL,
- buf, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_encrypt( NULL, NULL, NULL,
- sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_encrypt( &ctx, NULL, NULL,
- sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_encrypt( &ctx, NULL, NULL,
- sizeof( buf ), buf,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_encrypt( NULL, NULL,
- NULL, sizeof( buf ),
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx, NULL,
- NULL, sizeof( buf ),
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx, NULL,
- NULL, sizeof( buf ),
- buf, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_encrypt( NULL, NULL, NULL,
- buf, sizeof( buf ),
- sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_encrypt( &ctx, NULL, NULL,
- NULL, sizeof( buf ),
- sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_encrypt( &ctx, NULL, NULL,
- buf, sizeof( buf ),
- sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_encrypt( &ctx, NULL, NULL,
- buf, sizeof( buf ),
- sizeof( buf ), buf,
- NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_decrypt( NULL, NULL, NULL,
- &olen,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_decrypt( &ctx, NULL, NULL,
- NULL,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_decrypt( &ctx, NULL, NULL,
- &olen,
- NULL, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_decrypt( &ctx, NULL, NULL,
- &olen,
- buf, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_decrypt( NULL, NULL,
- NULL, &olen,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_decrypt( &ctx, NULL,
- NULL, NULL,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_decrypt( &ctx, NULL,
- NULL, &olen,
- NULL, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_pkcs1_v15_decrypt( &ctx, NULL,
- NULL, &olen,
- buf, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_decrypt( NULL, NULL, NULL,
- buf, sizeof( buf ),
- &olen,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_decrypt( &ctx, NULL, NULL,
- NULL, sizeof( buf ),
- NULL,
- buf, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_decrypt( &ctx, NULL, NULL,
- buf, sizeof( buf ),
- &olen,
- NULL, buf, 42 ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsaes_oaep_decrypt( &ctx, NULL, NULL,
- buf, sizeof( buf ),
- &olen,
- buf, NULL, 42 ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_sign( NULL, NULL, NULL,
- 0, sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), buf,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_sign( &ctx, NULL, NULL,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_sign( NULL, NULL, NULL,
- 0, sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), buf,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_sign( &ctx, NULL, NULL,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign( NULL, NULL, NULL,
- 0, sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign( &ctx, NULL, NULL,
- 0, sizeof( buf ), buf,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign( &ctx, NULL, NULL,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign_ext( NULL, NULL, NULL,
- 0, sizeof( buf ), buf,
- MBEDTLS_RSA_SALT_LEN_ANY,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign_ext( &ctx, NULL, NULL,
- 0, sizeof( buf ), NULL,
- MBEDTLS_RSA_SALT_LEN_ANY,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign_ext( &ctx, NULL, NULL,
- 0, sizeof( buf ), buf,
- MBEDTLS_RSA_SALT_LEN_ANY,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_sign_ext( &ctx, NULL, NULL,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- MBEDTLS_RSA_SALT_LEN_ANY,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_verify( NULL,
- 0, sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_verify( &ctx,
- 0, sizeof( buf ), NULL,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_verify( &ctx,
- 0, sizeof( buf ), buf,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_pkcs1_verify( &ctx,
- MBEDTLS_MD_SHA1, 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_verify( NULL,
- 0, sizeof( buf ), buf,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_verify( &ctx,
- 0, sizeof( buf ),
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_verify( &ctx,
- 0, sizeof( buf ), buf,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pkcs1_v15_verify( &ctx,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify( NULL,
- 0, sizeof( buf ),
- buf, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify( &ctx,
- 0, sizeof( buf ),
- NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify( &ctx,
- 0, sizeof( buf ),
- buf, NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify( &ctx,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify_ext( NULL,
- 0, sizeof( buf ),
- buf,
- 0, 0,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify_ext( &ctx,
- 0, sizeof( buf ),
- NULL, 0, 0,
- buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify_ext( &ctx,
- 0, sizeof( buf ),
- buf, 0, 0,
- NULL ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_rsassa_pss_verify_ext( &ctx,
- MBEDTLS_MD_SHA1,
- 0, NULL,
- 0, 0,
- buf ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_copy( NULL, &ctx ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
- mbedtls_rsa_copy( &ctx, NULL ) );
+#if !defined(MBEDTLS_PKCS1_V21)
+ TEST_EQUAL( mbedtls_rsa_set_padding( &ctx,
+ MBEDTLS_RSA_PKCS_V21,
+ MBEDTLS_MD_NONE ),
+ MBEDTLS_ERR_RSA_INVALID_PADDING );
+#endif
exit:
- return;
+ mbedtls_rsa_free( &ctx );
}
/* END_CASE */
@@ -373,11 +65,11 @@
* unconditionally on an error path without checking whether it has
* already been called in the success path. */
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
mbedtls_rsa_free( &ctx );
if( reinit )
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
mbedtls_rsa_free( &ctx );
/* This test case always succeeds, functionally speaking. A plausible
@@ -401,7 +93,9 @@
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx,padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
memset( output, 0x00, sizeof( output ) );
@@ -450,7 +144,9 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( hash_result, 0x00, sizeof( hash_result ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -484,7 +180,9 @@
mbedtls_mpi N, P, Q, E;
mbedtls_test_rnd_pseudo_info rnd_info;
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
@@ -531,7 +229,9 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -565,7 +265,9 @@
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -606,7 +308,9 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -651,7 +355,9 @@
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, padding_mode, 0 );
+ mbedtls_rsa_init( &ctx );
+ TEST_ASSERT( mbedtls_rsa_set_padding( &ctx, padding_mode,
+ MBEDTLS_MD_NONE ) == 0 );
memset( output, 0x00, sizeof( output ) );
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
@@ -699,8 +405,8 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
- mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init( &ctx2 );
memset( output, 0x00, sizeof( output ) );
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
@@ -757,8 +463,8 @@
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
- mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &ctx );
+ mbedtls_rsa_init( &ctx2 );
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
@@ -834,7 +540,7 @@
mbedtls_mpi N, E;
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &ctx );
if( strlen( input_N ) )
{
@@ -865,7 +571,7 @@
{
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &ctx );
ctx.len = mod / 8;
if( strlen( input_P ) )
@@ -926,8 +632,8 @@
{
mbedtls_rsa_context pub, prv;
- mbedtls_rsa_init( &pub, MBEDTLS_RSA_PKCS_V15, 0 );
- mbedtls_rsa_init( &prv, MBEDTLS_RSA_PKCS_V15, 0 );
+ mbedtls_rsa_init( &pub );
+ mbedtls_rsa_init( &prv );
pub.len = mod / 8;
prv.len = mod / 8;
@@ -998,7 +704,7 @@
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
- mbedtls_rsa_init ( &ctx, 0, 0 );
+ mbedtls_rsa_init ( &ctx );
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func,
&entropy, (const unsigned char *) pers,
@@ -1150,7 +856,7 @@
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
mbedtls_mpi_init( &N );
mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
@@ -1291,7 +997,7 @@
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
mbedtls_mpi_init( &N );
mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q );
@@ -1471,7 +1177,7 @@
mbedtls_rsa_context ctx;
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
/* Setup RSA context */
TEST_ASSERT( mbedtls_rsa_import_raw( &ctx,
@@ -1573,7 +1279,7 @@
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
- mbedtls_rsa_init( &ctx, 0, 0 );
+ mbedtls_rsa_init( &ctx );
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func,
&entropy, (const unsigned char *) pers,
diff --git a/tests/suites/test_suite_shax.data b/tests/suites/test_suite_shax.data
index 12eec84..3552346 100644
--- a/tests/suites/test_suite_shax.data
+++ b/tests/suites/test_suite_shax.data
@@ -1,9 +1,3 @@
-SHA-1 - Valid parameters
-sha1_valid_param:
-
-SHA-1 - Invalid parameters
-sha1_invalid_param:
-
# Test the operation of SHA-1 and SHA-2
SHA-1 Test Vector NIST CAVS #1
depends_on:MBEDTLS_SHA1_C
@@ -45,9 +39,6 @@
depends_on:MBEDTLS_SHA1_C
mbedtls_sha1:"8236153781bd2f1b81ffe0def1beb46f5a70191142926651503f1b3bb1016acdb9e7f7acced8dd168226f118ff664a01a8800116fd023587bfba52a2558393476f5fc69ce9c65001f23e70476d2cc81c97ea19caeb194e224339bcb23f77a83feac5096f9b3090c51a6ee6d204b735aa71d7e996d380b80822e4dfd43683af9c7442498cacbea64842dfda238cb099927c6efae07fdf7b23a4e4456e0152b24853fe0d5de4179974b2b9d4a1cdbefcbc01d8d311b5dda059136176ea698ab82acf20dd490be47130b1235cb48f8a6710473cfc923e222d94b582f9ae36d4ca2a32d141b8e8cc36638845fbc499bce17698c3fecae2572dbbd470552430d7ef30c238c2124478f1f780483839b4fb73d63a9460206824a5b6b65315b21e3c2f24c97ee7c0e78faad3df549c7ca8ef241876d9aafe9a309f6da352bec2caaa92ee8dca392899ba67dfed90aef33d41fc2494b765cb3e2422c8e595dabbfaca217757453fb322a13203f425f6073a9903e2dc5818ee1da737afc345f0057744e3a56e1681c949eb12273a3bfc20699e423b96e44bd1ff62e50a848a890809bfe1611c6787d3d741103308f849a790f9c015098286dbacfc34c1718b2c2b77e32194a75dda37954a320fa68764027852855a7e5b5274eb1e2cbcd27161d98b59ad245822015f48af82a45c0ed59be94f9af03d9736048570d6e3ef63b1770bc98dfb77de84b1bb1708d872b625d9ab9b06c18e5dbbf34399391f0f8aa26ec0dac7ff4cb8ec97b52bcb942fa6db2385dcd1b3b9d567aaeb425d567b0ebe267235651a1ed9bf78fd93d3c1dd077fe340bb04b00529c58f45124b717c168d07e9826e33376988bc5cf62845c2009980a4dfa69fbc7e5a0b1bb20a5958ca967aec68eb31dd8fccca9afcd30a26bab26279f1bf6724ff":"11863b483809ef88413ca9b0084ac4a5390640af"
-SHA-256 Valid parameters
-sha256_valid_param:
-
SHA-256 Invalid parameters
sha256_invalid_param:
@@ -110,9 +101,6 @@
SHA-512 Invalid parameters
sha512_invalid_param:
-SHA-512 Valid parameters
-sha512_valid_param:
-
SHA-384 Test Vector NIST CAVS #1
depends_on:MBEDTLS_SHA384_C
sha384:"":"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"
diff --git a/tests/suites/test_suite_shax.function b/tests/suites/test_suite_shax.function
index 1d4cf71..35fecce 100644
--- a/tests/suites/test_suite_shax.function
+++ b/tests/suites/test_suite_shax.function
@@ -5,53 +5,6 @@
/* END_HEADER */
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
-void sha1_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_sha1_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
-void sha1_invalid_param( )
-{
- mbedtls_sha1_context ctx;
- unsigned char buf[64] = { 0 };
- size_t const buflen = sizeof( buf );
-
- TEST_INVALID_PARAM( mbedtls_sha1_init( NULL ) );
-
- TEST_INVALID_PARAM( mbedtls_sha1_clone( NULL, &ctx ) );
- TEST_INVALID_PARAM( mbedtls_sha1_clone( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_starts_ret( NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_update_ret( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_update_ret( &ctx, NULL, buflen ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_finish_ret( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_finish_ret( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_internal_sha1_process( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_internal_sha1_process( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_ret( NULL, buflen, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA1_BAD_INPUT_DATA,
- mbedtls_sha1_ret( buf, buflen, NULL ) );
-
-exit:
- return;
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
void mbedtls_sha1( data_t * src_str, data_t * hash )
{
unsigned char output[41];
@@ -65,14 +18,7 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
-void sha256_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_sha256_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:NOT_DEFINED */
void sha256_invalid_param( )
{
mbedtls_sha256_context ctx;
@@ -81,38 +27,10 @@
int valid_type = 0;
int invalid_type = 42;
- TEST_INVALID_PARAM( mbedtls_sha256_init( NULL ) );
-
- TEST_INVALID_PARAM( mbedtls_sha256_clone( NULL, &ctx ) );
- TEST_INVALID_PARAM( mbedtls_sha256_clone( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_starts_ret( NULL, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
mbedtls_sha256_starts_ret( &ctx, invalid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_update_ret( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_update_ret( &ctx, NULL, buflen ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_finish_ret( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_finish_ret( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_internal_sha256_process( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_internal_sha256_process( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_ret( NULL, buflen,
- buf, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
- mbedtls_sha256_ret( buf, buflen,
- NULL, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_SHA256_BAD_INPUT_DATA,
mbedtls_sha256_ret( buf, buflen,
buf, invalid_type ) );
@@ -149,14 +67,7 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
-void sha512_valid_param( )
-{
- TEST_VALID_PARAM( mbedtls_sha512_free( NULL ) );
-}
-/* END_CASE */
-
-/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
+/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:NOT_DEFINED */
void sha512_invalid_param( )
{
mbedtls_sha512_context ctx;
@@ -165,38 +76,10 @@
int valid_type = 0;
int invalid_type = 42;
- TEST_INVALID_PARAM( mbedtls_sha512_init( NULL ) );
-
- TEST_INVALID_PARAM( mbedtls_sha512_clone( NULL, &ctx ) );
- TEST_INVALID_PARAM( mbedtls_sha512_clone( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_starts_ret( NULL, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
mbedtls_sha512_starts_ret( &ctx, invalid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_update_ret( NULL, buf, buflen ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_update_ret( &ctx, NULL, buflen ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_finish_ret( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_finish_ret( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_internal_sha512_process( NULL, buf ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_internal_sha512_process( &ctx, NULL ) );
-
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_ret( NULL, buflen,
- buf, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
- mbedtls_sha512_ret( buf, buflen,
- NULL, valid_type ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
+ TEST_EQUAL( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA,
mbedtls_sha512_ret( buf, buflen,
buf, invalid_type ) );
diff --git a/tests/suites/test_suite_ssl.data b/tests/suites/test_suite_ssl.data
index 141f672..a497076 100644
--- a/tests/suites/test_suite_ssl.data
+++ b/tests/suites/test_suite_ssl.data
@@ -9253,6 +9253,28 @@
# Vector from RFC 8448
ssl_tls1_3_derive_secret:MBEDTLS_MD_SHA256:"e2d32d4ed66dd37897a0e80c84107503ce58bf8aad4cb55a5002d77ecb890ece":tls1_3_label_res_master:"c3c122e0bd907a4a3ff6112d8fd53dbf89c773d9552e8b6b9d56d361b3a97bf6":32:MBEDTLS_SSL_TLS1_3_CONTEXT_HASHED:"5e95bdf1f89005ea2e9aa0ba85e728e3c19c5fe0c699e3f5bee59faebd0b5406"
+SSL TLS 1.3 Key schedule: Early secrets derivation helper
+# Vector from RFC 8448
+ssl_tls1_3_derive_early_secrets:MBEDTLS_MD_SHA256:"9b2188e9b2fc6d64d71dc329900e20bb41915000f678aa839cbb797cb7d8332c":"08ad0fa05d7c7233b1775ba2ff9f4c5b8b59276b7f227f13a976245f5d960913":"3fbbe6a60deb66c30a32795aba0eff7eaa10105586e7be5c09678d63b6caab62":"b2026866610937d7423e5be90862ccf24c0e6091186d34f812089ff5be2ef7df"
+
+SSL TLS 1.3 Key schedule: Handshake secrets derivation helper
+# Vector from RFC 8448
+ssl_tls1_3_derive_handshake_secrets:MBEDTLS_MD_SHA256:"005cb112fd8eb4ccc623bb88a07c64b3ede1605363fc7d0df8c7ce4ff0fb4ae6":"f736cb34fe25e701551bee6fd24c1cc7102a7daf9405cb15d97aafe16f757d03":"2faac08f851d35fea3604fcb4de82dc62c9b164a70974d0462e27f1ab278700f":"fe927ae271312e8bf0275b581c54eef020450dc4ecffaa05a1a35d27518e7803"
+
+SSL TLS 1.3 Key schedule: Application secrets derivation helper
+# Vector from RFC 8448
+ssl_tls1_3_derive_application_secrets:MBEDTLS_MD_SHA256:"e2d32d4ed66dd37897a0e80c84107503ce58bf8aad4cb55a5002d77ecb890ece":"b0aeffc46a2cfe33114e6fd7d51f9f04b1ca3c497dab08934a774a9d9ad7dbf3":"2abbf2b8e381d23dbebe1dd2a7d16a8bf484cb4950d23fb7fb7fa8547062d9a1":"cc21f1bf8feb7dd5fa505bd9c4b468a9984d554a993dc49e6d285598fb672691":"3fd93d4ffddc98e64b14dd107aedf8ee4add23f4510f58a4592d0b201bee56b4"
+
+SSL TLS 1.3 Key schedule: Resumption secrets derivation helper
+# Vector from RFC 8448
+ssl_tls1_3_derive_resumption_secrets:MBEDTLS_MD_SHA256:"e2d32d4ed66dd37897a0e80c84107503ce58bf8aad4cb55a5002d77ecb890ece":"c3c122e0bd907a4a3ff6112d8fd53dbf89c773d9552e8b6b9d56d361b3a97bf6":"5e95bdf1f89005ea2e9aa0ba85e728e3c19c5fe0c699e3f5bee59faebd0b5406"
+
+SSL TLS 1.3 Key schedule: PSK binder
+# Vector from RFC 8448
+# For the resumption PSK, see Section 3, 'generate resumption secret "tls13 resumption"'
+# For all other data, see Section 4, 'construct a ClientHello handshake message:'
+ssl_tls1_3_create_psk_binder:MBEDTLS_MD_SHA256:"4ecd0eb6ec3b4d87f5d6028f922ca4c5851a277fd41311c9e62d2c9492e1c4f3":MBEDTLS_SSL_TLS1_3_PSK_RESUMPTION:"63224b2e4573f2d3454ca84b9d009a04f6be9e05711a8396473aefa01e924a14":"3add4fb2d8fdf822a0ca3cf7678ef5e88dae990141c5924d57bb6fa31b9e5f9d"
+
SSL TLS_PRF MBEDTLS_SSL_TLS_PRF_NONE
ssl_tls_prf:MBEDTLS_SSL_TLS_PRF_NONE:"":"":"test tls_prf label":"":MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function
index 16a9d9e..c555d74 100644
--- a/tests/suites/test_suite_ssl.function
+++ b/tests/suites/test_suite_ssl.function
@@ -3796,6 +3796,156 @@
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
+void ssl_tls1_3_derive_early_secrets( int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *traffic_expected,
+ data_t *exporter_expected )
+{
+ mbedtls_ssl_tls1_3_early_secrets secrets;
+
+ /* Double-check that we've passed sane parameters. */
+ mbedtls_md_type_t md_type = (mbedtls_md_type_t) hash_alg;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ TEST_ASSERT( md_info != 0 &&
+ secret->len == md_size &&
+ transcript->len == md_size &&
+ traffic_expected->len == md_size &&
+ exporter_expected->len == md_size );
+
+ TEST_ASSERT( mbedtls_ssl_tls1_3_derive_early_secrets(
+ md_type, secret->x, transcript->x, transcript->len,
+ &secrets ) == 0 );
+
+ ASSERT_COMPARE( secrets.client_early_traffic_secret, md_size,
+ traffic_expected->x, traffic_expected->len );
+ ASSERT_COMPARE( secrets.early_exporter_master_secret, md_size,
+ exporter_expected->x, exporter_expected->len );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
+void ssl_tls1_3_derive_handshake_secrets( int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *client_expected,
+ data_t *server_expected )
+{
+ mbedtls_ssl_tls1_3_handshake_secrets secrets;
+
+ /* Double-check that we've passed sane parameters. */
+ mbedtls_md_type_t md_type = (mbedtls_md_type_t) hash_alg;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ TEST_ASSERT( md_info != 0 &&
+ secret->len == md_size &&
+ transcript->len == md_size &&
+ client_expected->len == md_size &&
+ server_expected->len == md_size );
+
+ TEST_ASSERT( mbedtls_ssl_tls1_3_derive_handshake_secrets(
+ md_type, secret->x, transcript->x, transcript->len,
+ &secrets ) == 0 );
+
+ ASSERT_COMPARE( secrets.client_handshake_traffic_secret, md_size,
+ client_expected->x, client_expected->len );
+ ASSERT_COMPARE( secrets.server_handshake_traffic_secret, md_size,
+ server_expected->x, server_expected->len );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
+void ssl_tls1_3_derive_application_secrets( int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *client_expected,
+ data_t *server_expected,
+ data_t *exporter_expected )
+{
+ mbedtls_ssl_tls1_3_application_secrets secrets;
+
+ /* Double-check that we've passed sane parameters. */
+ mbedtls_md_type_t md_type = (mbedtls_md_type_t) hash_alg;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ TEST_ASSERT( md_info != 0 &&
+ secret->len == md_size &&
+ transcript->len == md_size &&
+ client_expected->len == md_size &&
+ server_expected->len == md_size &&
+ exporter_expected->len == md_size );
+
+ TEST_ASSERT( mbedtls_ssl_tls1_3_derive_application_secrets(
+ md_type, secret->x, transcript->x, transcript->len,
+ &secrets ) == 0 );
+
+ ASSERT_COMPARE( secrets.client_application_traffic_secret_N, md_size,
+ client_expected->x, client_expected->len );
+ ASSERT_COMPARE( secrets.server_application_traffic_secret_N, md_size,
+ server_expected->x, server_expected->len );
+ ASSERT_COMPARE( secrets.exporter_master_secret, md_size,
+ exporter_expected->x, exporter_expected->len );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
+void ssl_tls1_3_derive_resumption_secrets( int hash_alg,
+ data_t *secret,
+ data_t *transcript,
+ data_t *resumption_expected )
+{
+ mbedtls_ssl_tls1_3_application_secrets secrets;
+
+ /* Double-check that we've passed sane parameters. */
+ mbedtls_md_type_t md_type = (mbedtls_md_type_t) hash_alg;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ TEST_ASSERT( md_info != 0 &&
+ secret->len == md_size &&
+ transcript->len == md_size &&
+ resumption_expected->len == md_size );
+
+ TEST_ASSERT( mbedtls_ssl_tls1_3_derive_resumption_master_secret(
+ md_type, secret->x, transcript->x, transcript->len,
+ &secrets ) == 0 );
+
+ ASSERT_COMPARE( secrets.resumption_master_secret, md_size,
+ resumption_expected->x, resumption_expected->len );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
+void ssl_tls1_3_create_psk_binder( int hash_alg,
+ data_t *psk,
+ int psk_type,
+ data_t *transcript,
+ data_t *binder_expected )
+{
+ unsigned char binder[ MBEDTLS_MD_MAX_SIZE ];
+
+ /* Double-check that we've passed sane parameters. */
+ mbedtls_md_type_t md_type = (mbedtls_md_type_t) hash_alg;
+ mbedtls_md_info_t const * const md_info = mbedtls_md_info_from_type( md_type );
+ size_t const md_size = mbedtls_md_get_size( md_info );
+ TEST_ASSERT( md_info != 0 &&
+ transcript->len == md_size &&
+ binder_expected->len == md_size );
+
+ TEST_ASSERT( mbedtls_ssl_tls1_3_create_psk_binder(
+ NULL, /* SSL context for debugging only */
+ md_type,
+ psk->x, psk->len,
+ psk_type,
+ transcript->x,
+ binder ) == 0 );
+
+ ASSERT_COMPARE( binder, md_size,
+ binder_expected->x, binder_expected->len );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */
void ssl_tls1_3_key_evolution( int hash_alg,
data_t *secret,
data_t *input,
diff --git a/tests/suites/test_suite_x509parse.data b/tests/suites/test_suite_x509parse.data
index 59acc66..dc81afb 100644
--- a/tests/suites/test_suite_x509parse.data
+++ b/tests/suites/test_suite_x509parse.data
@@ -720,7 +720,7 @@
x509_verify:"data_files/server5.crt":"data_files/test-ca2.ku-crt_crl.crt":"data_files/crl-ec-sha256.pem":"NULL":0:0:"compat":"NULL"
X509 CRT verification #53 (CA keyUsage missing cRLSign)
-depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_X509_CHECK_KEY_USAGE:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
+depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
x509_verify:"data_files/server5.crt":"data_files/test-ca2.ku-crt.crt":"data_files/crl-ec-sha256.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCRL_NOT_TRUSTED:"compat":"NULL"
X509 CRT verification #54 (CA keyUsage missing cRLSign, no CRL)
@@ -728,11 +728,11 @@
x509_verify:"data_files/server5.crt":"data_files/test-ca2.ku-crt.crt":"data_files/crl.pem":"NULL":0:0:"compat":"NULL"
X509 CRT verification #55 (CA keyUsage missing keyCertSign)
-depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_X509_CHECK_KEY_USAGE:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
+depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
x509_verify:"data_files/server5.crt":"data_files/test-ca2.ku-crl.crt":"data_files/crl-ec-sha256.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_NOT_TRUSTED:"compat":"NULL"
X509 CRT verification #56 (CA keyUsage plain wrong)
-depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_X509_CHECK_KEY_USAGE:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
+depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECDSA_C:MBEDTLS_SHA256_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_SECP384R1_ENABLED
x509_verify:"data_files/server5.crt":"data_files/test-ca2.ku-ds.crt":"data_files/crl-ec-sha256.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_NOT_TRUSTED:"compat":"NULL"
X509 CRT verification #57 (Valid, RSASSA-PSS, SHA-1)
@@ -1783,7 +1783,7 @@
x509parse_crt:"3081ad308197a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa100a200a311300f300d0603551d200406300430020601300d06092a864886f70d01010b0500030200ff":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA
X509 CRT ASN1 (TBSCertificate v3, inv CertificatePolicies, unknown critical policy)
-depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C:!MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
+depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C
x509parse_crt:"3081b130819ba0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa100a200a315301330110603551d20010101040730053003060100300d06092a864886f70d01010b0500030200ff":"":MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE
X509 CRT ASN1 (TBSCertificate v3, inv CertificatePolicies, policy qualifier invalid tag)
@@ -2001,7 +2001,7 @@
x509parse_crt:"3081e430819f020104300d06092a864886f70d0101050500300f310d300b0603550403130454657374301e170d3133303731303135303233375a170d3233303730383135303233375a300f310d300b06035504031304546573743049301306072a8648ce3d020106082a8648ce3d03010103320004e962551a325b21b50cf6b990e33d4318fd16677130726357a196e3efe7107bcb6bdc6d9db2a4df7c964acfe81798433d300d06092a864886f70d01010505000331001a6c18cd1e457474b2d3912743f44b571341a7859a0122774a8e19a671680878936949f904c9255bdd6fffdb33a7e6d8":"cert. version \: 1\nserial number \: 04\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 15\:02\:37\nexpires on \: 2023-07-08 15\:02\:37\nsigned using \: RSA with SHA1\nEC key size \: 192 bits\n":0
X509 CRT ASN1 (Unsupported critical extension)
-depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C:!MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
+depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C
x509parse_crt:"308203353082021da00302010202104d3ebbb8a870f9c78c55a8a7e12fd516300d06092a864886f70d01010b05003010310e300c06035504030c0564756d6d79301e170d3230303432383137343234335a170d3230303632373137343234335a3010310e300c06035504030c0564756d6d7930820122300d06092a864886f70d01010105000382010f003082010a0282010100a51b75b3f7da2d60ea1b0fc077f0dbb2bbb6fe1b474028368af8dc2664672896efff171033b0aede0b323a89d5c6db4d517404bc97b65264e41b9e9e86a6f40ace652498d4b3b859544d1bacfd7f86325503eed046f517406545c0ffb5560f83446dedce0fcafcc41ac8495488a6aa912ae45192ef7e3efa20d0f7403b0baa62c7e2e5404c620c5793623132aa20f624f08d88fbf0985af39433f5a24d0b908e5219d8ba6a404d3ee8418203b62a40c8eb18837354d50281a6a2bf5012e505c419482787b7a81e5935613ceea0c6d93e86f76282b6aa406fb3a1796c56b32e8a22afc3f7a3c9daa8f0e2846ff0d50abfc862a52f6cf0aaece6066c860376f3ed0203010001a3818a308187300c0603551d13040530030101ff30130603551d110101ff04093007820564756d6d79301206082b0601050507011f0101ff0403040100300e0603551d0f0101ff040403020184301d0603551d0e04160414e6e451ec8d19d9677b2d272a9d73b939fa2d915a301f0603551d23041830168014e6e451ec8d19d9677b2d272a9d73b939fa2d915a300d06092a864886f70d01010b0500038201010056d06047b7f48683e2347ca726997d9700b4f2cf1d8bc0ef17addac8445d38ffd7f8079055ead878b6a74c8384d0e30150c8990aa74f59cda6ebcb49465d8991ffa16a4c927a26e4639d1875a3ac396c7455c7eda40dbe66054a03d27f961c15e86bd5b06db6b26572977bcda93453b6b6a88ef96b31996a7bd17323525b33050d28deec9c33a3f9765a11fb99d0e222bd39a6db3a788474c9ca347377688f837d42f5841667bffcbe6b473e6f229f286a0829963e591a99aa7f67e9d20c36ccd2ac84cb85b7a8b3396a6cbe59a573ffff726f373197c230de5c92a52c5bc87e29c20bdf6e89609764a60c649022aabd768f3557661b083ae00e6afc8a5bf2ed":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
X509 CRT ASN1 (Unsupported critical extension recognized by callback)
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index a6361d8..fea02f3 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -1173,7 +1173,7 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_KEY_USAGE */
+/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
void x509_check_key_usage( char * crt_file, int usage, int ret )
{
mbedtls_x509_crt crt;
@@ -1189,7 +1189,7 @@
}
/* END_CASE */
-/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
+/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
void x509_check_extended_key_usage( char * crt_file, data_t * oid, int ret
)
{