From c470b6b021150788860ad9aa08202249663dbc75 Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Thu, 31 Jan 2019 08:20:20 -0500 Subject: [PATCH] Merge development commit 8e76332 into development-psa Additional changes to temporarily enable running tests: ssl_srv.c and test_suite_ecdh use mbedtls_ecp_group_load instead of mbedtls_ecdh_setup test_suite_ctr_drbg uses mbedtls_ctr_drbg_update instead of mbedtls_ctr_drbg_update_ret --- CONTRIBUTING.md | 4 +- ChangeLog | 126 +++- doxygen/input/doc_mainpage.h | 2 +- doxygen/mbedtls.doxyfile | 2 +- include/mbedtls/aes.h | 72 +- include/mbedtls/aesni.h | 52 +- include/mbedtls/arc4.h | 4 + include/mbedtls/aria.h | 96 ++- include/mbedtls/asn1write.h | 6 + include/mbedtls/base64.h | 9 + include/mbedtls/bignum.h | 754 ++++++++++++-------- include/mbedtls/blowfish.h | 137 ++-- include/mbedtls/bn_mul.h | 28 +- include/mbedtls/camellia.h | 208 ++++-- include/mbedtls/ccm.h | 116 +-- include/mbedtls/certs.h | 6 + include/mbedtls/chacha20.h | 48 +- include/mbedtls/chachapoly.h | 83 +-- include/mbedtls/check_config.h | 5 + include/mbedtls/cipher.h | 225 +++--- include/mbedtls/cmac.h | 6 + include/mbedtls/compat-1.3.h | 6 + include/mbedtls/config.h | 139 +++- include/mbedtls/ctr_drbg.h | 57 +- include/mbedtls/debug.h | 36 + include/mbedtls/des.h | 4 + include/mbedtls/dhm.h | 170 +++-- include/mbedtls/ecdh.h | 257 +++++-- include/mbedtls/ecdsa.h | 233 ++++-- include/mbedtls/ecjpake.h | 148 ++-- include/mbedtls/ecp.h | 511 ++++++++----- include/mbedtls/ecp_internal.h | 6 + include/mbedtls/error.h | 12 +- include/mbedtls/gcm.h | 101 ++- include/mbedtls/havege.h | 6 + include/mbedtls/hkdf.h | 6 + include/mbedtls/hmac_drbg.h | 36 +- include/mbedtls/md2.h | 4 + include/mbedtls/md4.h | 4 + include/mbedtls/md5.h | 4 + include/mbedtls/net.h | 5 + include/mbedtls/nist_kw.h | 6 + include/mbedtls/padlock.h | 40 +- include/mbedtls/pem.h | 6 + include/mbedtls/pk.h | 132 ++-- include/mbedtls/pkcs12.h | 10 + include/mbedtls/pkcs5.h | 14 + include/mbedtls/platform_util.h | 86 ++- include/mbedtls/poly1305.h | 49 +- include/mbedtls/ripemd160.h | 4 + include/mbedtls/rsa.h | 527 ++++++++------ include/mbedtls/sha1.h | 65 +- include/mbedtls/sha256.h | 92 ++- include/mbedtls/sha512.h | 93 ++- include/mbedtls/ssl.h | 8 + include/mbedtls/ssl_cache.h | 6 + include/mbedtls/ssl_ciphersuites.h | 6 + include/mbedtls/ssl_cookie.h | 6 + include/mbedtls/ssl_internal.h | 6 + include/mbedtls/ssl_ticket.h | 6 + include/mbedtls/version.h | 10 +- include/mbedtls/x509.h | 4 + include/mbedtls/x509_crt.h | 37 +- include/mbedtls/xtea.h | 4 + library/CMakeLists.txt | 6 +- library/aes.c | 121 +++- library/aria.c | 57 +- library/asn1write.c | 26 +- library/bignum.c | 304 +++++++- library/blowfish.c | 58 +- library/camellia.c | 70 +- library/ccm.c | 37 + library/chacha20.c | 48 +- library/chachapoly.c | 111 ++- library/cipher.c | 128 ++-- library/ctr_drbg.c | 112 +-- library/debug.c | 50 ++ library/dhm.c | 58 +- library/ecdh.c | 411 +++++++++-- library/ecdsa.c | 86 ++- library/ecjpake.c | 38 +- library/ecp.c | 207 +++++- library/ecp_curves.c | 8 + library/entropy_poll.c | 57 +- library/error.c | 22 +- library/gcm.c | 45 +- library/hmac_drbg.c | 124 +++- library/nist_kw.c | 4 +- library/pem.c | 6 +- library/pk.c | 73 +- library/pkcs12.c | 4 + library/pkcs5.c | 17 +- library/pkparse.c | 53 +- library/pkwrite.c | 32 +- library/platform_util.c | 1 + library/poly1305.c | 48 +- library/rsa.c | 451 ++++++++++-- library/sha1.c | 24 + library/sha256.c | 25 + library/sha512.c | 25 + library/ssl_cli.c | 22 +- library/ssl_srv.c | 12 +- library/ssl_ticket.c | 14 +- library/ssl_tls.c | 13 +- library/version_features.c | 3 + library/x509_crt.c | 2 +- library/x509_csr.c | 15 +- programs/aes/aescrypt2.c | 14 + programs/aes/crypt_and_hash.c | 14 + programs/hash/generic_sum.c | 14 + programs/hash/hello.c | 14 + programs/pkey/dh_client.c | 14 + programs/pkey/dh_genprime.c | 13 + programs/pkey/dh_server.c | 14 + programs/pkey/ecdh_curve25519.c | 17 +- programs/pkey/ecdsa.c | 13 + programs/pkey/gen_key.c | 20 +- programs/pkey/key_app.c | 14 + programs/pkey/key_app_writer.c | 22 +- programs/pkey/mpi_demo.c | 14 + programs/pkey/pk_decrypt.c | 14 + programs/pkey/pk_encrypt.c | 14 + programs/pkey/pk_sign.c | 13 + programs/pkey/pk_verify.c | 13 + programs/pkey/rsa_decrypt.c | 13 + programs/pkey/rsa_encrypt.c | 13 + programs/pkey/rsa_genkey.c | 14 + programs/pkey/rsa_sign.c | 13 + programs/pkey/rsa_sign_pss.c | 14 +- programs/pkey/rsa_verify.c | 13 + programs/pkey/rsa_verify_pss.c | 13 + programs/random/gen_entropy.c | 14 + programs/random/gen_random_ctr_drbg.c | 14 + programs/random/gen_random_havege.c | 14 + programs/ssl/dtls_client.c | 15 + programs/ssl/dtls_server.c | 15 + programs/ssl/mini_client.c | 36 +- programs/ssl/ssl_client1.c | 13 + programs/ssl/ssl_client2.c | 15 + programs/ssl/ssl_fork_server.c | 13 + programs/ssl/ssl_mail_client.c | 13 + programs/ssl/ssl_pthread_server.c | 16 + programs/ssl/ssl_server.c | 15 + programs/ssl/ssl_server2.c | 15 + programs/test/benchmark.c | 18 +- programs/test/selftest.c | 12 + programs/test/ssl_cert_test.c | 13 + programs/util/pem2der.c | 14 + programs/x509/cert_app.c | 13 + programs/x509/cert_req.c | 12 + programs/x509/cert_write.c | 13 + programs/x509/crl_app.c | 13 + programs/x509/req_app.c | 13 + tests/CMakeLists.txt | 2 + tests/data_files/server1-ms.req.sha256 | 16 + tests/git-scripts/pre-push.sh | 1 + tests/scripts/all.sh | 26 + tests/scripts/basic-build-test.sh | 5 +- tests/scripts/check-files.py | 31 +- tests/scripts/generate_test_code.py | 25 +- tests/scripts/mbedtls_test.py | 2 +- tests/scripts/run-test-suites.pl | 36 +- tests/ssl-opt.sh | 6 + tests/suites/helpers.function | 197 ++++- tests/suites/host_test.function | 1 + tests/suites/main_test.function | 34 +- tests/suites/test_suite_aes.function | 272 ++++++- tests/suites/test_suite_aes.rest.data | 6 + tests/suites/test_suite_aria.data | 6 + tests/suites/test_suite_aria.function | 189 +++++ tests/suites/test_suite_asn1write.function | 2 +- tests/suites/test_suite_blowfish.data | 14 +- tests/suites/test_suite_blowfish.function | 158 ++++ tests/suites/test_suite_camellia.data | 10 +- tests/suites/test_suite_camellia.function | 166 +++++ tests/suites/test_suite_ccm.data | 7 + tests/suites/test_suite_ccm.function | 213 ++++++ tests/suites/test_suite_chacha20.function | 58 +- tests/suites/test_suite_chachapoly.function | 162 ++--- tests/suites/test_suite_cipher.function | 486 +++++++++++-- tests/suites/test_suite_cipher.misc.data | 5 + tests/suites/test_suite_cipher.padding.data | 3 - tests/suites/test_suite_dhm.data | 3 + tests/suites/test_suite_dhm.function | 107 +++ tests/suites/test_suite_ecdh.data | 10 + tests/suites/test_suite_ecdh.function | 213 +++++- tests/suites/test_suite_ecdsa.data | 3 + tests/suites/test_suite_ecdsa.function | 197 ++++- tests/suites/test_suite_ecjpake.data | 3 + tests/suites/test_suite_ecjpake.function | 131 ++++ tests/suites/test_suite_ecp.data | 10 +- tests/suites/test_suite_ecp.function | 343 +++++++++ tests/suites/test_suite_gcm.function | 169 +++++ tests/suites/test_suite_gcm.misc.data | 5 + tests/suites/test_suite_mpi.data | 6 + tests/suites/test_suite_mpi.function | 214 ++++++ tests/suites/test_suite_pk.data | 10 + tests/suites/test_suite_pk.function | 422 +++++++++++ tests/suites/test_suite_pkcs1_v15.data | 90 +++ tests/suites/test_suite_pkcs1_v15.function | 148 ++++ tests/suites/test_suite_pkwrite.function | 2 +- tests/suites/test_suite_poly1305.function | 51 +- tests/suites/test_suite_rsa.data | 16 +- tests/suites/test_suite_rsa.function | 448 ++++++++++++ tests/suites/test_suite_shax.data | 18 + tests/suites/test_suite_shax.function | 159 +++++ tests/suites/test_suite_version.data | 4 +- tests/suites/test_suite_x509parse.data | 4 + 208 files changed, 11024 insertions(+), 2553 deletions(-) create mode 100644 tests/data_files/server1-ms.req.sha256 create mode 100644 tests/suites/test_suite_cipher.misc.data create mode 100644 tests/suites/test_suite_gcm.misc.data diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3433ed001..010dffc63 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,9 +56,9 @@ It would be highly appreciated if contributions are backported to LTS branches i Currently maintained LTS branches are: -1. [mbedtls-2.1](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.1) +1. [mbedtls-2.7](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.7) -2. [mbedtls-2.7](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.7) +1. [mbedtls-2.16](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.16) Tests diff --git a/ChangeLog b/ChangeLog index 010f9e880..35478b90f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,23 +1,125 @@ mbed TLS ChangeLog (Sorted per branch, date) -= mbed TLS 2.15.1 branch released 2018-11-30 += mbed TLS 2.x.x branch released xxxx-xx-xx + +Bugfix + * Fix a compilation issue with mbedtls_ecp_restart_ctx not being defined + when MBEDTLS_ECP_ALT is defined. Reported by jwhui. Fixes #2242. + * Run the AD too long test only if MBEDTLS_CCM_ALT is not defined. + Raised as a comment in #1996. + * Reduce the stack consumption of mbedtls_mpi_fill_random() which could + previously lead to a stack overflow on constrained targets. + * Add `MBEDTLS_SELF_TEST` for the mbedtls_self_test functions + in the header files, which missed the precompilation check. #971 + * Fix returning the value 1 when mbedtls_ecdsa_genkey failed. + * Remove a duplicate #include in a sample program. Fixed by Masashi Honma #2326. + * Remove the mbedtls namespacing from the header file, to fix a "file not found" + build error. Fixed by Haijun Gu #2319. Changes + * Include configuration file in all header files that use configuration, + instead of relying on other header files that they include. + Inserted as an enhancement for #1371 + * Add support for alternative CSR headers, as used by Microsoft and defined + in RFC 7468. Found by Michael Ernst. Fixes #767. * Update the Mbed Crypto submodule to version 0.1.0b2. - -= mbed TLS 2.15.0 branch released 2018-11-23 - -Features - * Add an experimental build option, USE_CRYPTO_SUBMODULE, to enable use of - Mbed Crypto as the source of the cryptography implementation. - * Add an experimental configuration option, MBEDTLS_PSA_CRYPTO_C, to enable - the PSA Crypto API from Mbed Crypto when additionally used with the - USE_CRYPTO_SUBMODULE build option. - -Changes * Add unit tests for AES-GCM when called through mbedtls_cipher_auth_xxx() from the cipher abstraction layer. Fixes #2198. +Features + * Add an experimental build option, USE_CRYPTO_SUBMODULE, to enable use of + Mbed Crypto as the source of the cryptography implementation. + * Add an experimental configuration option, MBEDTLS_PSA_CRYPTO_C, to enable + the PSA Crypto API from Mbed Crypto when additionally used with the + USE_CRYPTO_SUBMODULE build option. + += mbed TLS 2.16.0 branch released 2018-12-21 + +Features + * Add a new config.h option of MBEDTLS_CHECK_PARAMS that enables validation + of parameters in the API. This allows detection of obvious misuses of the + API, such as passing NULL pointers. The API of existing functions hasn't + changed, but requirements on parameters have been made more explicit in + the documentation. See the corresponding API documentation for each + function to see for which parameter values it is defined. This feature is + disabled by default. See its API documentation in config.h for additional + steps you have to take when enabling it. + +API Changes + * The following functions in the random generator modules have been + deprecated and replaced as shown below. The new functions change + the return type from void to int to allow returning error codes when + using MBEDTLS__ALT for the underlying AES or message digest + primitive. Fixes #1798. + mbedtls_ctr_drbg_update() -> mbedtls_ctr_drbg_update_ret() + mbedtls_hmac_drbg_update() -> mbedtls_hmac_drbg_update_ret() + * Extend ECDH interface to enable alternative implementations. + * Deprecate error codes of the form MBEDTLS_ERR_xxx_INVALID_KEY_LENGTH for + ARIA, CAMELLIA and Blowfish. These error codes will be replaced by + the more generic per-module error codes MBEDTLS_ERR_xxx_BAD_INPUT_DATA. + * Additional parameter validation checks have been added for the following + modules - AES, ARIA, Blowfish, CAMELLIA, CCM, GCM, DHM, ECP, ECDSA, ECDH, + ECJPAKE, SHA, Chacha20 and Poly1305, cipher, pk, RSA, and MPI. + Where modules have had parameter validation added, existing parameter + checks may have changed. Some modules, such as Chacha20 had existing + parameter validation whereas other modules had little. This has now been + changed so that the same level of validation is present in all modules, and + that it is now optional with the MBEDTLS_CHECK_PARAMS flag which by default + is off. That means that checks which were previously present by default + will no longer be. + +New deprecations + * Deprecate mbedtls_ctr_drbg_update and mbedtls_hmac_drbg_update + in favor of functions that can return an error code. + +Bugfix + * Fix for Clang, which was reporting a warning for the bignum.c inline + assembly for AMD64 targets creating string literals greater than those + permitted by the ISO C99 standard. Found by Aaron Jones. Fixes #482. + * Fix runtime error in `mbedtls_platform_entropy_poll()` when run + through qemu user emulation. Reported and fix suggested by randombit + in #1212. Fixes #1212. + * Fix an unsafe bounds check when restoring an SSL session from a ticket. + This could lead to a buffer overflow, but only in case ticket authentication + was broken. Reported and fix suggested by Guido Vranken in #659. + * Add explicit integer to enumeration type casts to example program + programs/pkey/gen_key which previously led to compilation failure + on some toolchains. Reported by phoenixmcallister. Fixes #2170. + * Fix double initialization of ECC hardware that made some accelerators + hang. + * Clarify documentation of mbedtls_ssl_set_own_cert() regarding the absence + of check for certificate/key matching. Reported by Attila Molnar, #507. + += mbed TLS 2.14.1 branch released 2018-11-30 + +Security + * Fix timing variations and memory access variations in RSA PKCS#1 v1.5 + decryption that could lead to a Bleichenbacher-style padding oracle + attack. In TLS, this affects servers that accept ciphersuites based on + RSA decryption (i.e. ciphersuites whose name contains RSA but not + (EC)DH(E)). Discovered by Eyal Ronen (Weizmann Institute), Robert Gillham + (University of Adelaide), Daniel Genkin (University of Michigan), + Adi Shamir (Weizmann Institute), David Wong (NCC Group), and Yuval Yarom + (University of Adelaide, Data61). The attack is described in more detail + in the paper available here: http://cat.eyalro.net/cat.pdf CVE-2018-19608 + * In mbedtls_mpi_write_binary(), don't leak the exact size of the number + via branching and memory access patterns. An attacker who could submit + a plaintext for RSA PKCS#1 v1.5 decryption but only observe the timing + of the decryption and not its result could nonetheless decrypt RSA + plaintexts and forge RSA signatures. Other asymmetric algorithms may + have been similarly vulnerable. Reported by Eyal Ronen, Robert Gillham, + Daniel Genkin, Adi Shamir, David Wong and Yuval Yarom. + * Wipe sensitive buffers on the stack in the CTR_DRBG and HMAC_DRBG + modules. + +API Changes + * The new functions mbedtls_ctr_drbg_update_ret() and + mbedtls_hmac_drbg_update_ret() are similar to mbedtls_ctr_drbg_update() + and mbedtls_hmac_drbg_update() respectively, but the new functions + report errors whereas the old functions return void. We recommend that + applications use the new functions. +>>>>>>> development + = mbed TLS 2.14.0 branch released 2018-11-19 Security diff --git a/doxygen/input/doc_mainpage.h b/doxygen/input/doc_mainpage.h index b8e16a51d..ffc3cecbe 100644 --- a/doxygen/input/doc_mainpage.h +++ b/doxygen/input/doc_mainpage.h @@ -24,7 +24,7 @@ */ /** - * @mainpage mbed TLS v2.15.1 source code documentation + * @mainpage mbed TLS v2.16.0 source code documentation * * This documentation describes the internal structure of mbed TLS. It was * automatically generated from specially formatted comment blocks in diff --git a/doxygen/mbedtls.doxyfile b/doxygen/mbedtls.doxyfile index 8b9c252be..574db8d46 100644 --- a/doxygen/mbedtls.doxyfile +++ b/doxygen/mbedtls.doxyfile @@ -28,7 +28,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = "mbed TLS v2.15.1" +PROJECT_NAME = "mbed TLS v2.16.0" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/include/mbedtls/aes.h b/include/mbedtls/aes.h index cfb20c4fc..94e7282d3 100644 --- a/include/mbedtls/aes.h +++ b/include/mbedtls/aes.h @@ -121,7 +121,7 @@ typedef struct mbedtls_aes_xts_context * It must be the first API called before using * the context. * - * \param ctx The AES context to initialize. + * \param ctx The AES context to initialize. This must not be \c NULL. */ void mbedtls_aes_init( mbedtls_aes_context *ctx ); @@ -129,6 +129,8 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx ); * \brief This function releases and clears the specified AES context. * * \param ctx The AES context to clear. + * If this is \c NULL, this function does nothing. + * Otherwise, the context must have been at least initialized. */ void mbedtls_aes_free( mbedtls_aes_context *ctx ); @@ -139,7 +141,7 @@ void mbedtls_aes_free( mbedtls_aes_context *ctx ); * It must be the first API called before using * the context. * - * \param ctx The AES XTS context to initialize. + * \param ctx The AES XTS context to initialize. This must not be \c NULL. */ void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ); @@ -147,6 +149,8 @@ void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ); * \brief This function releases and clears the specified AES XTS context. * * \param ctx The AES XTS context to clear. + * If this is \c NULL, this function does nothing. + * Otherwise, the context must have been at least initialized. */ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -155,7 +159,9 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); * \brief This function sets the encryption key. * * \param ctx The AES context to which the key should be bound. + * It must be initialized. * \param key The encryption key. + * This must be a readable buffer of size \p keybits bits. * \param keybits The size of data passed in bits. Valid options are: *