License: Expat
Files: pdns/ext/polarssl*
-Copyright: 2006-2014, Brainspark B.V.
+Copyright (C) 2006-2014, ARM Limited
License: GPL-2+
License: Expat
License: Expat
Files: pdns/ext/polarssl*
-Copyright: 2006-2010, Brainspark B.V.
+Copyright (C) 2006-2014, ARM Limited
License: GPL-2+
Files: pdns/ext/yahttp*
mkdir -p $DIRNAME/ext/rapidjson/include/rapidjson/internal
cp -a ../ext/rapidjson/include/rapidjson/*.h $DIRNAME/ext/rapidjson/include/rapidjson/
cp -a ../ext/rapidjson/include/rapidjson/internal/*.h $DIRNAME/ext/rapidjson/include/rapidjson/internal
-mkdir -p $DIRNAME/ext/polarssl/include/polarssl
-cp -a ../ext/polarssl/include/polarssl/config.h ../ext/polarssl/include/polarssl/check_config.h ../ext/polarssl/include/polarssl/aes.h ../ext/polarssl/include/polarssl/base64.h ../ext/polarssl/include/polarssl/platform.h ../ext/polarssl/include/polarssl/version.h $DIRNAME/ext/polarssl/include/polarssl
-mkdir -p $DIRNAME/ext/polarssl/library
-cp -a ../ext/polarssl/library/aes.c ../ext/polarssl/library/base64.c $DIRNAME/ext/polarssl/library
+mkdir -p $DIRNAME/ext/mbedtls/include/polarssl
+cp -a ../ext/mbedtls/include/polarssl/config.h ../ext/mbedtls/include/polarssl/check_config.h ../ext/mbedtls/include/polarssl/aes.h ../ext/mbedtls/include/polarssl/base64.h ../ext/mbedtls/include/polarssl/platform.h ../ext/mbedtls/include/polarssl/version.h $DIRNAME/ext/mbedtls/include/polarssl
+mkdir -p $DIRNAME/ext/mbedtls/library
+cp -a ../ext/mbedtls/library/aes.c ../ext/mbedtls/library/base64.c $DIRNAME/ext/mbedtls/library
cp -a ../ext/yahttp/ $DIRNAME/ext/yahttp
echo '#include "../../../config.h"' > $DIRNAME/ext/yahttp/yahttp/yahttp-config.h
mkdir $DIRNAME/rrd
ext/Makefile
ext/yahttp/Makefile
ext/yahttp/yahttp/Makefile
- ext/polarssl/Makefile
- ext/polarssl/library/Makefile
+ ext/mbedtls/Makefile
+ ext/mbedtls/library/Makefile
ext/rapidjson/Makefile
ext/json11/Makefile
modules/bindbackend/Makefile
json11
DIST_SUBDIRS = \
- polarssl \
+ mbedtls \
yahttp \
rapidjson \
json11
--- /dev/null
+cmake_minimum_required(VERSION 2.6)
+project(MBEDTLS C)
+
+string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ # some warnings we want are not available with old GCC versions
+ # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
+ OUTPUT_VARIABLE GCC_VERSION)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings")
+ if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
+ endif()
+ set(CMAKE_C_FLAGS_RELEASE "-O2")
+ set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
+ set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
+ set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -O3")
+ set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
+ set(CMAKE_C_FLAGS_CHECK "-Werror -O1")
+ set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
+endif(CMAKE_COMPILER_IS_GNUCC)
+
+if(CMAKE_COMPILER_IS_CLANG)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith")
+ set(CMAKE_C_FLAGS_RELEASE "-O2")
+ set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
+ set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")
+ set(CMAKE_C_FLAGS_ASAN "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O3")
+ set(CMAKE_C_FLAGS_ASANDBG "-Werror -fsanitize=address -fno-common -fsanitize=undefined -fno-sanitize-recover -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
+ set(CMAKE_C_FLAGS_MEMSAN "-Werror -fsanitize=memory -O3")
+ set(CMAKE_C_FLAGS_MEMSANDBG "-Werror -fsanitize=memory -O1 -g3 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2")
+ set(CMAKE_C_FLAGS_CHECK "-Werror -O1")
+endif(CMAKE_COMPILER_IS_CLANG)
+
+set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
+ CACHE STRING "Choose the type of build: None Debug Release Coverage ASan ASanDbg MemSan MemSanDbg Check CheckFull"
+ FORCE)
+
+if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
+ if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
+ endif(CMAKE_COMPILER_IS_GNUCC)
+ if(CMAKE_COMPILER_IS_CLANG)
+ set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
+ endif(CMAKE_COMPILER_IS_CLANG)
+endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
+
+option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF)
+
+option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
+option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
+option(ENABLE_TESTING "Build mbed TLS tests." ON)
+
+if(ENABLE_TESTING)
+ enable_testing()
+endif()
+
+if(LIB_INSTALL_DIR)
+else()
+set(LIB_INSTALL_DIR lib)
+endif()
+
+include_directories(include/)
+
+if(ENABLE_ZLIB_SUPPORT)
+ find_package(ZLIB)
+
+ if(ZLIB_FOUND)
+ include_directories(${ZLIB_INCLUDE_DIR})
+ endif(ZLIB_FOUND)
+endif(ENABLE_ZLIB_SUPPORT)
+
+add_subdirectory(library)
+add_subdirectory(include)
+
+if(ENABLE_TESTING)
+ if(CMAKE_COMPILER_IS_GNUCC)
+ add_subdirectory(tests)
+ endif(CMAKE_COMPILER_IS_GNUCC)
+ if(CMAKE_COMPILER_IS_CLANG)
+ add_subdirectory(tests)
+ endif(CMAKE_COMPILER_IS_CLANG)
+endif()
+
+if(ENABLE_PROGRAMS)
+ add_subdirectory(programs)
+endif()
+
+ADD_CUSTOM_TARGET(apidoc
+ COMMAND doxygen doxygen/mbedtls.doxyfile
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+if(ENABLE_TESTING)
+ ADD_CUSTOM_TARGET(test-ref-config
+ COMMAND tests/scripts/test-ref-configs.pl
+ )
+
+ ADD_CUSTOM_TARGET(covtest
+ COMMAND make test
+ COMMAND programs/test/selftest
+ COMMAND cd tests && ./compat.sh
+ COMMAND cd tests && ./ssl-opt.sh
+ )
+
+ ADD_CUSTOM_TARGET(lcov
+ COMMAND rm -rf Coverage
+ COMMAND lcov --capture --initial --directory library/CMakeFiles/mbedtls.dir -o files.info
+ COMMAND lcov --capture --directory library/CMakeFiles/mbedtls.dir -o tests.info
+ COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
+ COMMAND lcov --remove all.info -o final.info '*.h'
+ COMMAND gendesc tests/Descriptions.txt -o descriptions
+ COMMAND genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
+ COMMAND rm -f files.info tests.info all.info final.info descriptions
+ )
+
+ ADD_CUSTOM_TARGET(memcheck
+ COMMAND sed -i.bak s+/usr/bin/valgrind+`which valgrind`+ DartConfiguration.tcl
+ COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
+ COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
+ COMMAND rm -f memcheck.log
+ COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl
+ )
+endif()
-PolarSSL ChangeLog (Sorted per branch, date)
+mbed TLS ChangeLog (Sorted per branch, date)
+
+= mbed TLS 1.3.12 released 2015-08-11
+
+Security
+ * Increase the minimum size of Diffie-Hellman parameters accepted by the
+ client to 1024 bits, to protect against Logjam attack.
+ * Increase the size of default Diffie-Hellman parameters on the server to
+ 2048 bits. This can be changed with ssl_set_dh_params().
+
+Bugfix
+ * Fix thread-safety issue in SSL debug module (found by Edwin van Vliet).
+ * Some example programs were not built using make, not included in Visual
+ Studio projects (found by Kristian Bendiksen).
+ * Fix build error with CMake and pre-4.5 versions of GCC (found by Hugo
+ Leisink).
+ * Fix missing -static-ligcc when building shared libraries for Windows with
+ make.
+ * Fix compile error with armcc5 --gnu.
+
+Changes
+ * Add SSL_MIN_DHM_BYTES configuration parameter in config.h to choose the
+ minimum size of Diffie-Hellman parameters accepted by the client.
+ * The PEM parser now accepts a trailing space at end of lines (#226).
+
+= mbed TLS 1.3.11 released 2015-06-04
+
+Security
+ * With authmode set to SSL_VERIFY_OPTIONAL, verification of keyUsage and
+ extendedKeyUsage on the leaf certificate was lost (results not accessible
+ via ssl_get_verify_results()).
+ * Add countermeasure against "Lucky 13 strikes back" cache-based attack,
+ https://dl.acm.org/citation.cfm?id=2714625
+
+Features
+ * Improve ECC performance by using more efficient doubling formulas
+ (contributed by Peter Dettman).
+ * Add x509_crt_verify_info() to display certificate verification results.
+ * Add support for reading DH parameters with privateValueLength included
+ (contributed by Daniel Kahn Gillmor).
+ * Add support for bit strings in X.509 names (request by Fredrik Axelsson).
+ * Add support for id-at-uniqueIdentifier in X.509 names.
+ * Add support for overriding snprintf() (except on Windows) and exit() in
+ the platform layer.
+ * Add an option to use macros instead of function pointers in the platform
+ layer (helps get rid of unwanted references).
+ * Improved Makefiles for Windows targets by fixing library targets and making
+ cross-compilation easier (thanks to Alon Bar-Lev).
+ * The benchmark program also prints heap usage for public-key primitives
+ if POLARSSL_MEMORY_BUFFER_ALLOC_C and POLARSSL_MEMORY_DEBUG are defined.
+ * New script ecc-heap.sh helps measuring the impact of ECC parameters on
+ speed and RAM (heap only for now) usage.
+ * New script memory.sh helps measuring the ROM and RAM requirements of two
+ reduced configurations (PSK-CCM and NSA suite B).
+ * Add config flag POLARSSL_DEPRECATED_WARNING (off by default) to produce
+ warnings on use of deprecated functions (with GCC and Clang only).
+ * Add config flag POLARSSL_DEPRECATED_REMOVED (off by default) to produce
+ errors on use of deprecated functions.
+
+Bugfix
+ * Fix compile errors with PLATFORM_NO_STD_FUNCTIONS.
+ * Fix compile error with PLATFORM_EXIT_ALT (thanks to Rafał Przywara).
+ * Fix bug in entropy.c when THREADING_C is also enabled that caused
+ entropy_free() to crash (thanks to Rafał Przywara).
+ * Fix memory leak when gcm_setkey() and ccm_setkey() are used more than
+ once on the same context.
+ * Fix bug in ssl_mail_client when password is longer that username (found
+ by Bruno Pape).
+ * Fix undefined behaviour (memcmp( NULL, NULL, 0 );) in X.509 modules
+ (detected by Clang's 3.6 UBSan).
+ * mpi_size() and mpi_msb() would segfault when called on an mpi that is
+ initialized but not set (found by pravic).
+ * Fix detection of support for getrandom() on Linux (reported by syzzer) by
+ doing it at runtime (using uname) rather that compile time.
+ * Fix handling of symlinks by "make install" (found by Gaël PORTAY).
+ * Fix potential NULL pointer dereference (not trigerrable remotely) when
+ ssl_write() is called before the handshake is finished (introduced in
+ 1.3.10) (first reported by Martin Blumenstingl).
+ * Fix bug in pk_parse_key() that caused some valid private EC keys to be
+ rejected.
+ * Fix bug in Via Padlock support (found by Nikos Mavrogiannopoulos).
+ * Fix thread safety bug in RSA operations (found by Fredrik Axelsson).
+ * Fix hardclock() (only used in the benchmarking program) with some
+ versions of mingw64 (found by kxjhlele).
+ * Fix warnings from mingw64 in timing.c (found by kxjklele).
+ * Fix potential unintended sign extension in asn1_get_len() on 64-bit
+ platforms.
+ * Fix potential memory leak in ssl_set_psk() (found by Mansour Moufid).
+ * Fix compile error when POLARSSL_SSL_DISABLE_RENEGOTATION and
+ POLARSSL_SSL_SSESSION_TICKETS where both enabled in config.h (introduced
+ in 1.3.10).
+ * Add missing extern "C" guard in aesni.h (reported by amir zamani).
+ * Add missing dependency on SHA-256 in some x509 programs (reported by
+ Gergely Budai).
+ * Fix bug related to ssl_set_curves(): the client didn't check that the
+ curve picked by the server was actually allowed.
+
+Changes
+ * Remove bias in mpi_gen_prime (contributed by Pascal Junod).
+ * Remove potential sources of timing variations (some contributed by Pascal
+ Junod).
+ * Options POLARSSL_HAVE_INT8 and POLARSSL_HAVE_INT16 are deprecated.
+ * Enabling POLARSSL_NET_C without POLARSSL_HAVE_IPV6 is deprecated.
+ * compat-1.2.h and openssl.h are deprecated.
+ * Adjusting/overriding CFLAGS and LDFLAGS with the make build system is now
+ more flexible (warning: OFLAGS is not used any more) (see the README)
+ (contributed by Alon Bar-Lev).
+ * ssl_set_own_cert() no longer calls pk_check_pair() since the
+ performance impact was bad for some users (this was introduced in 1.3.10).
+ * Move from SHA-1 to SHA-256 in example programs using signatures
+ (suggested by Thorsten Mühlfelder).
+ * Remove some unneeded inclusions of header files from the standard library
+ "minimize" others (eg use stddef.h if only size_t is needed).
+ * Change #include lines in test files to use double quotes instead of angle
+ brackets for uniformity with the rest of the code.
+ * Remove dependency on sscanf() in X.509 parsing modules.
+
+= mbed TLS 1.3.10 released 2015-02-09
+Security
+ * NULL pointer dereference in the buffer-based allocator when the buffer is
+ full and polarssl_free() is called (found by Mark Hasemeyer)
+ (only possible if POLARSSL_MEMORY_BUFFER_ALLOC_C is enabled, which it is
+ not by default).
+ * Fix remotely-triggerable uninitialised pointer dereference caused by
+ crafted X.509 certificate (TLS server is not affected if it doesn't ask for a
+ client certificate) (found using Codenomicon Defensics).
+ * Fix remotely-triggerable memory leak caused by crafted X.509 certificates
+ (TLS server is not affected if it doesn't ask for a client certificate)
+ (found using Codenomicon Defensics).
+ * Fix potential stack overflow while parsing crafted X.509 certificates
+ (TLS server is not affected if it doesn't ask for a client certificate)
+ (found using Codenomicon Defensics).
+ * Fix timing difference that could theoretically lead to a
+ Bleichenbacher-style attack in the RSA and RSA-PSK key exchanges
+ (reported by Sebastian Schinzel).
+
+Features
+ * Add support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv).
+ * Add support for Extended Master Secret (draft-ietf-tls-session-hash).
+ * Add support for Encrypt-then-MAC (RFC 7366).
+ * Add function pk_check_pair() to test if public and private keys match.
+ * Add x509_crl_parse_der().
+ * Add compile-time option POLARSSL_X509_MAX_INTERMEDIATE_CA to limit the
+ length of an X.509 verification chain.
+ * Support for renegotiation can now be disabled at compile-time
+ * Support for 1/n-1 record splitting, a countermeasure against BEAST.
+ * Certificate selection based on signature hash, preferring SHA-1 over SHA-2
+ for pre-1.2 clients when multiple certificates are available.
+ * Add support for getrandom() syscall on recent Linux kernels with Glibc or
+ a compatible enough libc (eg uClibc).
+ * Add ssl_set_arc4_support() to make it easier to disable RC4 at runtime
+ while using the default ciphersuite list.
+ * Added new error codes and debug messages about selection of
+ ciphersuite/certificate.
+
+Bugfix
+ * Stack buffer overflow if ctr_drbg_update() is called with too large
+ add_len (found by Jean-Philippe Aumasson) (not triggerable remotely).
+ * Possible buffer overflow of length at most POLARSSL_MEMORY_ALIGN_MULTIPLE
+ if memory_buffer_alloc_init() was called with buf not aligned and len not
+ a multiple of POLARSSL_MEMORY_ALIGN_MULTIPLE (not triggerable remotely).
+ * User set CFLAGS were ignored by Cmake with gcc (introduced in 1.3.9, found
+ by Julian Ospald).
+ * Fix potential undefined behaviour in Camellia.
+ * Fix potential failure in ECDSA signatures when POLARSSL_ECP_MAX_BITS is a
+ multiple of 8 (found by Gergely Budai).
+ * Fix unchecked return code in x509_crt_parse_path() on Windows (found by
+ Peter Vaskovic).
+ * Fix assembly selection for MIPS64 (thanks to James Cowgill).
+ * ssl_get_verify_result() now works even if the handshake was aborted due
+ to a failed verification (found by Fredrik Axelsson).
+ * Skip writing and parsing signature_algorithm extension if none of the
+ key exchanges enabled needs certificates. This fixes a possible interop
+ issue with some servers when a zero-length extension was sent. (Reported
+ by Peter Dettman.)
+ * On a 0-length input, base64_encode() did not correctly set output length
+ (found by Hendrik van den Boogaard).
+
+Changes
+ * Use deterministic nonces for AEAD ciphers in TLS by default (possible to
+ switch back to random with POLARSSL_SSL_AEAD_RANDOM_IV in config.h).
+ * Blind RSA private operations even when POLARSSL_RSA_NO_CRT is defined.
+ * ssl_set_own_cert() now returns an error on key-certificate mismatch.
+ * Forbid repeated extensions in X.509 certificates.
+ * debug_print_buf() now prints a text view in addition to hexadecimal.
+ * A specific error is now returned when there are ciphersuites in common
+ but none of them is usable due to external factors such as no certificate
+ with a suitable (extended)KeyUsage or curve or no PSK set.
+ * It is now possible to disable negotiation of truncated HMAC server-side
+ at runtime with ssl_set_truncated_hmac().
+ * Example programs for SSL client and server now disable SSLv3 by default.
+ * Example programs for SSL client and server now disable RC4 by default.
+ * Use platform.h in all test suites and programs.
= PolarSSL 1.3.9 released 2014-10-20
Security
* RSA blinding on CRT operations to counter timing attacks
(found by Cyril Arnaud and Pierre-Alain Fouque)
+
+= Version 1.2.14 released 2015-05-??
+
+Security
+ * Fix potential invalid memory read in the server, that allows a client to
+ crash it remotely (found by Caj Larsson).
+ * Fix potential invalid memory read in certificate parsing, that allows a
+ client to crash the server remotely if client authentication is enabled
+ (found using Codenomicon Defensics).
+ * Add countermeasure against "Lucky 13 strikes back" cache-based attack,
+ https://dl.acm.org/citation.cfm?id=2714625
+
+Bugfix
+ * Fix bug in Via Padlock support (found by Nikos Mavrogiannopoulos).
+ * Fix hardclock() (only used in the benchmarking program) with some
+ versions of mingw64 (found by kxjhlele).
+ * Fix warnings from mingw64 in timing.c (found by kxjklele).
+ * Fix potential unintended sign extension in asn1_get_len() on 64-bit
+ platforms (found with Coverity Scan).
+
+= Version 1.2.13 released 2015-02-16
+Note: Although PolarSSL has been renamed to mbed TLS, no changes reflecting
+ this will be made in the 1.2 branch at this point.
+
+Security
+ * Fix remotely-triggerable uninitialised pointer dereference caused by
+ crafted X.509 certificate (TLS server is not affected if it doesn't ask
+ for a client certificate) (found using Codenomicon Defensics).
+ * Fix remotely-triggerable memory leak caused by crafted X.509 certificates
+ (TLS server is not affected if it doesn't ask for a client certificate)
+ (found using Codenomicon Defensics).
+ * Fix potential stack overflow while parsing crafted X.509 certificates
+ (TLS server is not affected if it doesn't ask for a client certificate)
+ found using Codenomicon Defensics).
+ * Fix buffer overread of size 1 when parsing crafted X.509 certificates
+ (TLS server is not affected if it doesn't ask for a client certificate).
+
+Bugfix
+ * Fix potential undefined behaviour in Camellia.
+ * Fix memory leaks in PKCS#5 and PKCS#12.
+ * Stack buffer overflow if ctr_drbg_update() is called with too large
+ add_len (found by Jean-Philippe Aumasson) (not triggerable remotely).
+ * Fix bug in MPI/bignum on s390/s390x (reported by Dan Horák) (introduced
+ in 1.2.12).
+ * Fix unchecked return code in x509_crt_parse_path() on Windows (found by
+ Peter Vaskovic).
+ * Fix assembly selection for MIPS64 (thanks to James Cowgill).
+ * ssl_get_verify_result() now works even if the handshake was aborted due
+ to a failed verification (found by Fredrik Axelsson).
+ * Skip writing and parsing signature_algorithm extension if none of the
+ key exchanges enabled needs certificates. This fixes a possible interop
+ issue with some servers when a zero-length extension was sent. (Reported
+ by Peter Dettman.)
+ * On a 0-length input, base64_encode() did not correctly set output length
+ (found by Hendrik van den Boogaard).
+
+Changes
+ * Blind RSA private operations even when POLARSSL_RSA_NO_CRT is defined.
+ * Forbid repeated extensions in X.509 certificates.
+ * Add compile-time option POLARSSL_X509_MAX_INTERMEDIATE_CA to limit the
+ length of an X.509 verification chain (default = 8).
+= Version 1.2.12 released 2014-10-24
+
+Security
+ * Remotely-triggerable memory leak when parsing some X.509 certificates
+ (server is not affected if it doesn't ask for a client certificate).
+ (Found using Codenomicon Defensics.)
+
+Bugfix
+ * Fix potential bad read in parsing ServerHello (found by Adrien
+ Vialletelle).
+ * ssl_close_notify() could send more than one message in some circumstances
+ with non-blocking I/O.
+ * x509_crt_parse() did not increase total_failed on PEM error
+ * Fix compiler warnings on iOS (found by Sander Niemeijer).
+ * Don't print uninitialised buffer in ssl_mail_client (found by Marc Abel).
+ * Fix net_accept() regarding non-blocking sockets (found by Luca Pesce).
+ * ssl_read() could return non-application data records on server while
+ renegotation was pending, and on client when a HelloRequest was received.
+ * Fix warnings from Clang's scan-build (contributed by Alfred Klomp).
+
+Changes
+ * X.509 certificates with more than one AttributeTypeAndValue per
+ RelativeDistinguishedName are not accepted any more.
+ * ssl_read() now returns POLARSSL_ERR_NET_WANT_READ rather than
+ POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE on harmless alerts.
+ * Accept spaces at end of line or end of buffer in base64_decode().
+
= Version 1.2.11 released 2014-07-11
Features
* Entropy module now supports seed writing and reading
Site: localhost
-BuildName: PolarSSL-test
+BuildName: mbed TLS-test
CoverageCommand: /usr/bin/gcov
MemoryCheckCommand: /usr/bin/valgrind
===================
-README for PolarSSL
+README for mbed TLS
===================
+Configuration
+=============
+
+mbed TLS should build out of the box on most systems. Some platform specific options are available in the fully-documented configuration file *include/polarssl/config.h*, which is also the place where features can be selected.
+This file can be edited manually, or in a more programmatic way using the Perl
+script *scripts/config.pl* (use *--help* for usage instructions).
+
+Compiler options can be set using standard variables such as *CC* and *CFLAGS* when using the Make and CMake build system (see below).
+
Compiling
=========
-There are currently three active build systems within the PolarSSL releases:
+There are currently three active build systems within the mbed TLS releases:
- Make
- CMake
make check
-Depending on your platform, you might run into some issues. Please check the Makefiles in *library/*, *programs/* and *tests/* for options to manually add or remove for specific platforms. You can also check `the PolarSSL Knowledge Base <https://polarssl.org/kb>`_ for articles on your platform or issue.
+In order to build for a Windows platform, you should use WINDOWS_BUILD=1 if the target is Windows but the build environment is Unix-like (eg when cross-compiling, or compiling from an MSYS shell), and WINDOWS=1 if the build environment is a Windows shell.
+
+Setting the variable SHARED in your environment will build a shared library in addition to the static library. Setting DEBUG gives you a debug build. You can override CFLAGS and LDFLAGS by setting them in your environment or on the make command line; if you do so, essential parts such as -I will still be preserved. Warning options may be overridden separately using WARNING_CFLAGS.
+
+Depending on your platform, you might run into some issues. Please check the Makefiles in *library/*, *programs/* and *tests/* for options to manually add or remove for specific platforms. You can also check `the mbed TLS Knowledge Base <https://tls.mbed.org/kb>`_ for articles on your platform or issue.
In case you find that you need to do something else as well, please let us know what, so we can add it to the KB.
make
-There are 5 different active build modes specified within the CMake buildsystem:
+There are many different build modes available within the CMake buildsystem. Most of them are available for gcc and clang, though some are compiler-specific:
- Release.
This generates the default code without any unnecessary information in the binary files.
This generates code coverage information in addition to debug information.
- ASan.
This instruments the code with AddressSanitizer to check for memory errors.
+ (This includes LeakSanitizer, with recent version of gcc and clang.)
+ (With recent version of clang, this mode also instruments the code with
+ UndefinedSanitizer to check for undefined behaviour.)
+- ASanDbg.
+ Same as ASan but slower, with debug information and better stack traces.
+- MemSan.
+ This instruments the code with MemorySanitizer to check for uninitialised
+ memory reads. Experimental, needs recent clang on Linux/x86_64.
+- MemSanDbg.
+ Same as ASan but slower, with debug information, better stack traces and
+ origin tracking.
- Check.
- This activates more compiler warnings and treats them as errors.
+ This activates the compiler warnings that depend on optimization and treats
+ all warnings as errors.
Switching build modes in CMake is simple. For debug mode, enter at the command line:
cmake -D CMAKE_BUILD_TYPE:String="Debug" .
+Note that, with CMake, if you want to change the compiler or its options after you already ran CMake, you need to clear its cache first, eg (using GNU find)::
+
+ find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
+ CC=gcc CFLAGS='-fstack-protector-strong -Wa,--noexecstack' cmake .
+
In order to run the tests, enter::
make test
Tests
=====
-PolarSSL includes an elaborate test suite in *tests/* that initially requires Perl to generate the tests files (e.g. *test_suite_mpi.c*). These files are generates from a **function file** (e.g. *suites/test_suite_mpi.function*) and a **data file** (e.g. *suites/test_suite_mpi.data*). The **function file** contains the template for each test function. The **data file** contains the test cases, specified as parameters that should be pushed into a template function.
+mbed TLS includes an elaborate test suite in *tests/* that initially requires Perl to generate the tests files (e.g. *test_suite_mpi.c*). These files are generates from a **function file** (e.g. *suites/test_suite_mpi.function*) and a **data file** (e.g. *suites/test_suite_mpi.data*). The **function file** contains the template for each test function. The **data file** contains the test cases, specified as parameters that should be pushed into a template function.
+
+For machines with a Unix shell and OpenSSL (and optionally GnuTLS) installed, additional test scripts are available:
+
+- *tests/ssl-opt.sh* runs integration tests for various TLS options (renegotiation, resumption, etc.) and tests interoperability of these options with other implementations.
+- *tests/compat.sh* tests interoperability of every ciphersuite with other implementations.
+- *tests/scripts/test-ref-configs.pl* test builds in various reduced configurations.
+- *tests/scripts/all.sh* runs a combination of the above tests with various build options (eg ASan).
Configurations
==============
Process
-------
-#. `Check for open issues <https://github.com/polarssl/polarssl/issues>`_ or
- `start a discussion <https://polarssl.org/discussions>`_ around a feature
+#. `Check for open issues <https://github.com/ARMmbed/mbedtls/issues>`_ or
+ `start a discussion <https://tls.mbed.org/discussions>`_ around a feature
idea or a bug.
-#. Fork the `PolarSSL repository on Github <https://github.com/polarssl/polarssl>`_
+#. Fork the `mbed TLS repository on Github <https://github.com/ARMmbed/mbedtls>`_
to start making your changes.
#. Write a test which shows that the bug was fixed or that the feature works
as expected.
--- /dev/null
+Makefile
+*.sln
+*.vcxproj
+polarssl/check_config
-option(INSTALL_POLARSSL_HEADERS "Install PolarSSL headers." ON)
+option(INSTALL_MBEDTLS_HEADERS "Install mbed TLS headers." ON)
-if(INSTALL_POLARSSL_HEADERS)
+if(INSTALL_MBEDTLS_HEADERS)
file(GLOB headers "polarssl/*.h")
DESTINATION include/polarssl
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
-endif(INSTALL_POLARSSL_HEADERS)
+endif(INSTALL_MBEDTLS_HEADERS)
*
* \brief AES block cipher
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
* Length should be a multiple of the block
* size (16 bytes)
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx AES context
* \param mode AES_ENCRYPT or AES_DECRYPT
* \param length length of the input data
* both encryption and decryption. So a context initialized with
* aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx AES context
* \param mode AES_ENCRYPT or AES_DECRYPT
* \param length length of the input data
* both encryption and decryption. So a context initialized with
* aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx AES context
* \param mode AES_ENCRYPT or AES_DECRYPT
* \param length length of the input data
*
* \brief AES-NI for hardware AES acceleration on some Intel processors
*
- * Copyright (C) 2013, Brainspark B.V.
+ * Copyright (C) 2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_HAVE_X86_64)
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief AES-NI features detection routine
*
const unsigned char *key,
size_t bits );
+#ifdef __cplusplus
+}
+#endif
+
#endif /* POLARSSL_HAVE_X86_64 */
#endif /* POLARSSL_AESNI_H */
*
* \brief The ARCFOUR stream cipher
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if !defined(POLARSSL_ARC4_ALT)
// Regular implementation
*
* \brief Generic ASN.1 parsing
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
+#include <stddef.h>
+
#if defined(POLARSSL_BIGNUM_C)
#include "bignum.h"
#endif
-#include <string.h>
-
/**
* \addtogroup asn1_module
* \{
asn1_buf oid; /**< The object identifier. */
asn1_buf val; /**< The named value. */
struct _asn1_named_data *next; /**< The next entry in the sequence. */
+ unsigned char next_merged; /**< Merge next item into the current one? */
}
asn1_named_data;
*
* \brief ASN.1 buffer writing functionality
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief RFC 1521 base64 encoding/decoding
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_BASE64_H
#define POLARSSL_BASE64_H
-#include <string.h>
+#include <stddef.h>
#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
#define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
*
* \brief Multi-precision integer library
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_BIGNUM_H
#define POLARSSL_BIGNUM_H
-#include <stdio.h>
-#include <string.h>
-
#if !defined(POLARSSL_CONFIG_FILE)
#include "config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif
+#include <stddef.h>
+
+#if defined(POLARSSL_FS_IO)
+#include <stdio.h>
+#endif
+
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
#if (_MSC_VER <= 1200)
defined(__ppc64__) || defined(__powerpc64__) || \
defined(__ia64__) || defined(__alpha__) || \
(defined(__sparc__) && defined(__arch64__)) || \
- defined(__s390x__) ) )
+ defined(__s390x__) || defined(__mips64) ) )
#define POLARSSL_HAVE_INT64
typedef int64_t t_sint;
typedef uint64_t t_uint;
mpi;
/**
- * \brief Initialize one MPI
+ * \brief Initialize one MPI (make internal references valid)
+ * This just makes it ready to be set or freed,
+ * but does not define a value for the MPI.
*
* \param X One MPI to initialize.
*/
*
* \brief Blowfish block cipher
*
- * Copyright (C) 2012-2014, Brainspark B.V.
+ * Copyright (C) 2012-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
* Length should be a multiple of the block
* size (8 bytes)
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx Blowfish context
* \param mode BLOWFISH_ENCRYPT or BLOWFISH_DECRYPT
* \param length length of the input data
/**
* \brief Blowfish CFB buffer encryption/decryption.
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx Blowfish context
* \param mode BLOWFISH_ENCRYPT or BLOWFISH_DECRYPT
* \param length length of the input data
*
* \brief Multi-precision integer library
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2010, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_HAVE_ASM)
-#if defined(__GNUC__)
+/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
+#if defined(__GNUC__) && \
+ ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
#if defined(__i386__)
#define MULADDC_INIT \
);
#endif /* Alpha */
-#if defined(__mips__) && !defined(__mips64__)
+#if defined(__mips__) && !defined(__mips64)
#define MULADDC_INIT \
asm( \
*
* \brief Camellia block cipher
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
* Length should be a multiple of the block
* size (16 bytes)
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx CAMELLIA context
* \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
* \param length length of the input data
* both encryption and decryption. So a context initialized with
* camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT.
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx CAMELLIA context
* \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
* \param length length of the input data
*
* \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers
*
- * Copyright (C) 2014, Brainspark B.V.
+ * Copyright (C) 2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief Sample certificates and DHM parameters for testing
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * Copyright (C) 2006-2010, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief Consistency checks for configuration options
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_CHECK_CONFIG_H
#define POLARSSL_CHECK_CONFIG_H
+#if defined(POLARSSL_DEPRECATED_WARNING) && \
+ !defined(__GNUC__) && !defined(__clang__)
+#error "POLARSSL_DEPRECATED_WARNING only works with GCC and Clang"
+#endif
+
+#if defined(POLARSSL_NET_C) && !defined(POLARSSL_HAVE_IPV6)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "Using POLARSSL_NET_C without POLARSSL_HAVE_IPV6 is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#define POLARSSL_HAVE_IPV6
+#endif
+#endif /* POLARSSL_NET_C && !POLARSSL_HAVE_IPV6 */
+
+#if defined(POLARSSL_ERROR_STRERROR_BC)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "POLARSSL_ERROR_STRERROR_BC is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#error "POLARSSL_ERROR_STRERROR_BC is deprecated"
+#endif
+#endif /* POLARSSL_ERROR_STRERROR_BC */
+
+#if defined(POLARSSL_MEMORY_C)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "POLARSSL_MEMORY_C is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#error "POLARSSL_MEMORY_C is deprecated"
+#endif
+#endif /* POLARSSL_MEMORY_C */
+
+#if defined(POLARSSL_PBKDF2_C)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "POLARSSL_PBKDF2_C is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#error "POLARSSL_PBKDF2_C is deprecated"
+#endif
+#endif /* POLARSSL_PBKDF2_C */
+
+#if defined(POLARSSL_HAVE_INT8)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "POLARSSL_HAVE_INT8 is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#error "POLARSSL_HAVE_INT8 is deprecated"
+#endif
+#endif /* POLARSSL_HAVE_INT8 */
+
+#if defined(POLARSSL_HAVE_INT16)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "POLARSSL_HAVE_INT16 is deprecated"
+#endif
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+#error "POLARSSL_HAVE_INT16 is deprecated"
+#endif
+#endif /* POLARSSL_HAVE_INT16 */
+
#if defined(POLARSSL_AESNI_C) && !defined(POLARSSL_HAVE_ASM)
#error "POLARSSL_AESNI_C defined, but not all prerequisites"
#endif
#endif
#if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
- ( !defined(POLARSSL_RSA_C) || !defined(POLARSSL_X509_CRT_PARSE_C) ||\
+ ( !defined(POLARSSL_RSA_C) || !defined(POLARSSL_X509_CRT_PARSE_C) || \
!defined(POLARSSL_PKCS1_V15) )
#error "POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
#endif
#if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) && \
- ( !defined(POLARSSL_RSA_C) || !defined(POLARSSL_X509_CRT_PARSE_C) ||\
+ ( !defined(POLARSSL_RSA_C) || !defined(POLARSSL_X509_CRT_PARSE_C) || \
!defined(POLARSSL_PKCS1_V15) )
#error "POLARSSL_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
#endif
+#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_MEMORY_C defined, but not all prerequisites"
+#endif
+
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && \
( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
#error "POLARSSL_PEM_WRITE_C defined, but not all prerequisites"
#endif
+#if defined(POLARSSL_PK_C) && \
+ ( !defined(POLARSSL_RSA_C) && !defined(POLARSSL_ECP_C) )
+#error "POLARSSL_PK_C defined, but not all prerequisites"
+#endif
+
#if defined(POLARSSL_PK_PARSE_C) && !defined(POLARSSL_PK_C)
#error "POLARSSL_PK_PARSE_C defined, but not all prerequisites"
#endif
#error "POLARSSL_PKCS11_C defined, but not all prerequisites"
#endif
+#if defined(POLARSSL_PLATFORM_EXIT_ALT) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_EXIT_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_EXIT_MACRO) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_EXIT_MACRO) &&\
+ ( defined(POLARSSL_PLATFORM_STD_EXIT) ||\
+ defined(POLARSSL_PLATFORM_EXIT_ALT) )
+#error "POLARSSL_PLATFORM_EXIT_MACRO and POLARSSL_PLATFORM_STD_EXIT/POLARSSL_PLATFORM_EXIT_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FPRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) &&\
+ ( defined(POLARSSL_PLATFORM_STD_FPRINTF) ||\
+ defined(POLARSSL_PLATFORM_FPRINTF_ALT) )
+#error "POLARSSL_PLATFORM_FPRINTF_MACRO and POLARSSL_PLATFORM_STD_FPRINTF/POLARSSL_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
+ ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
+#error "POLARSSL_PLATFORM_FREE_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
+ defined(POLARSSL_PLATFORM_STD_FREE)
+#error "POLARSSL_PLATFORM_FREE_MACRO and POLARSSL_PLATFORM_STD_FREE cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_FREE_MACRO) && !defined(POLARSSL_PLATFORM_MALLOC_MACRO)
+#error "POLARSSL_PLATFORM_MALLOC_MACRO must be defined if POLARSSL_PLATFORM_FREE_MACRO is"
+#endif
+
+#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) &&\
+ ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
+#error "POLARSSL_PLATFORM_MALLOC_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) &&\
+ defined(POLARSSL_PLATFORM_STD_MALLOC)
+#error "POLARSSL_PLATFORM_MALLOC_MACRO and POLARSSL_PLATFORM_STD_MALLOC cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) && !defined(POLARSSL_PLATFORM_FREE_MACRO)
+#error "POLARSSL_PLATFORM_FREE_MACRO must be defined if POLARSSL_PLATFORM_MALLOC_MACRO is"
+#endif
+
+#if defined(POLARSSL_PLATFORM_MEMORY) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_MEMORY defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_PRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) &&\
+ ( defined(POLARSSL_PLATFORM_STD_PRINTF) ||\
+ defined(POLARSSL_PLATFORM_PRINTF_ALT) )
+#error "POLARSSL_PLATFORM_PRINTF_MACRO and POLARSSL_PLATFORM_STD_PRINTF/POLARSSL_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT) && ( defined(_WIN32)\
+ && !defined(EFIX64) && !defined(EFI32) )
+#error "POLARSSL_PLATFORM_SNPRINTF_ALT defined but not available on Windows"
+#endif
+
+#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
+#error "POLARSSL_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) &&\
+ ( defined(POLARSSL_PLATFORM_STD_SNPRINTF) ||\
+ defined(POLARSSL_PLATFORM_SNPRINTF_ALT) )
+#error "POLARSSL_PLATFORM_SNPRINTF_MACRO and POLARSSL_PLATFORM_STD_SNPRINTF/POLARSSL_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_MEM_HDR) &&\
+ !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
+#error "POLARSSL_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_MALLOC) && !defined(POLARSSL_PLATFORM_MEMORY)
+#error "POLARSSL_PLATFORM_STD_MALLOC defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_MALLOC) && !defined(POLARSSL_PLATFORM_MEMORY)
+#error "POLARSSL_PLATFORM_STD_MALLOC defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_FREE) && !defined(POLARSSL_PLATFORM_MEMORY)
+#error "POLARSSL_PLATFORM_STD_FREE defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_EXIT) &&\
+ !defined(POLARSSL_PLATFORM_EXIT_ALT)
+#error "POLARSSL_PLATFORM_STD_EXIT defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_FPRINTF) &&\
+ !defined(POLARSSL_PLATFORM_FPRINTF_ALT)
+#error "POLARSSL_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_PRINTF) &&\
+ !defined(POLARSSL_PLATFORM_PRINTF_ALT)
+#error "POLARSSL_PLATFORM_STD_PRINTF defined, but not all prerequisites"
+#endif
+
+#if defined(POLARSSL_PLATFORM_STD_SNPRINTF) &&\
+ !defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
+#error "POLARSSL_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
+#endif
+
#if defined(POLARSSL_RSA_C) && ( !defined(POLARSSL_BIGNUM_C) || \
!defined(POLARSSL_OID_C) )
#error "POLARSSL_RSA_C defined, but not all prerequisites"
#error "Illegal protocol selection"
#endif
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1_1) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1_2)
+#error "POLARSSL_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
+#endif
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1_1) && \
+ !defined(POLARSSL_SSL_PROTO_TLS1_2)
+#error "POLARSSL_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
+#endif
+
#if defined(POLARSSL_SSL_SESSION_TICKETS) && defined(POLARSSL_SSL_TLS_C) && \
( !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C) || \
!defined(POLARSSL_CIPHER_MODE_CBC) )
#error "POLARSSL_SSL_SESSION_TICKETS_C defined, but not all prerequisites"
#endif
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING) && \
+ !defined(POLARSSL_SSL_PROTO_SSL3) && !defined(POLARSSL_SSL_PROTO_TLS1)
+#error "POLARSSL_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
+#endif
+
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION) && \
!defined(POLARSSL_X509_CRT_PARSE_C)
#error "POLARSSL_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
+#include <stddef.h>
+
#if defined(POLARSSL_GCM_C) || defined(POLARSSL_CCM_C)
#define POLARSSL_CIPHER_MODE_AEAD
#endif
#define POLARSSL_CIPHER_MODE_WITH_PADDING
#endif
-#include <string.h>
+#if defined(POLARSSL_ARC4_C)
+#define POLARSSL_CIPHER_MODE_STREAM
+#endif
#if defined(_MSC_VER) && !defined(inline)
#define inline _inline
POLARSSL_CIPHER_ID_NULL,
POLARSSL_CIPHER_ID_AES,
POLARSSL_CIPHER_ID_DES,
- POLARSSL_CIPHER_ID_3DES,
+ POLARSSL_CIPHER_ID_3DES, /* Unused! */
POLARSSL_CIPHER_ID_CAMELLIA,
POLARSSL_CIPHER_ID_BLOWFISH,
POLARSSL_CIPHER_ID_ARC4,
int (*ecb_func)( void *ctx, operation_t mode,
const unsigned char *input, unsigned char *output );
+#if defined(POLARSSL_CIPHER_MODE_CBC)
/** Encrypt using CBC */
int (*cbc_func)( void *ctx, operation_t mode, size_t length,
unsigned char *iv, const unsigned char *input,
unsigned char *output );
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
/** Encrypt using CFB (Full length) */
int (*cfb_func)( void *ctx, operation_t mode, size_t length, size_t *iv_off,
unsigned char *iv, const unsigned char *input,
unsigned char *output );
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
/** Encrypt using CTR */
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
unsigned char *nonce_counter, unsigned char *stream_block,
const unsigned char *input, unsigned char *output );
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
/** Encrypt using STREAM */
int (*stream_func)( void *ctx, size_t length,
const unsigned char *input, unsigned char *output );
+#endif
/** Set key for encryption purposes */
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
/** Operation that the context's key has been initialised for */
operation_t operation;
+#if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
/** Padding functions to use, if relevant for cipher mode */
void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
+#endif
/** Buffer for data that hasn't been encrypted yet */
unsigned char unprocessed_data[POLARSSL_MAX_BLOCK_LENGTH];
*/
int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info );
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
/**
* \brief Free the cipher-specific context of ctx. Freeing ctx
* itself remains the responsibility of the caller.
*
- * \note Deprecated: Redirects to cipher_free()
+ * \deprecated Use cipher_free() instead
*
* \param ctx Free the cipher-specific context
*
* \returns 0
*/
-int cipher_free_ctx( cipher_context_t *ctx );
+int cipher_free_ctx( cipher_context_t *ctx ) DEPRECATED;
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
/**
* \brief Returns the block size of the given cipher.
* POLARSSL_KEY_LENGTH_NONE if ctx has not been
* initialised.
*/
-static inline int cipher_get_key_size ( const cipher_context_t *ctx )
+static inline int cipher_get_key_size( const cipher_context_t *ctx )
{
if( NULL == ctx || NULL == ctx->cipher_info )
return POLARSSL_KEY_LENGTH_NONE;
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#else
#include POLARSSL_CONFIG_FILE
#endif
+
#include "cipher.h"
#ifdef __cplusplus
*
* \brief Backwards compatibility header for PolarSSL-1.2 from PolarSSL-1.3
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * \deprecated Use native PolarSSL 1.3 functions instead.
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "Including compat-1.2.h is deprecated"
+#endif
+
#ifndef POLARSSL_COMPAT_1_2_H
#define POLARSSL_COMPAT_1_2_H
}
#endif /* POLARSSL_PK_WRITE_C && POLARSSL_RSA_C */
#endif /* compat-1.2.h */
+#endif /* POLARSSL_DEPRECATED_REMOVED */
*
* \brief Configuration options (set of defines)
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* The system uses 8-bit wide native integers.
*
+ * \deprecated The compiler should be able to generate code for 32-bit
+ * arithmetic (required by C89). This code is likely to be at least as
+ * efficient as ours.
+ *
* Uncomment if native integers are 8-bit wide.
*/
//#define POLARSSL_HAVE_INT8
*
* The system uses 16-bit wide native integers.
*
+ * \deprecated The compiler should be able to generate code for 32-bit
+ * arithmetic (required by C89). This code is likely to be at least as
+ * efficient as ours.
+ *
* Uncomment if native integers are 16-bit wide.
*/
//#define POLARSSL_HAVE_INT16
*
* Note: on Windows/MingW, XP or higher is required.
*
+ * \warning As of 1.3.11, *not* using this flag when POLARSSL_NET_C is
+ * defined, is deprecated. The alternative legacy code will be removed in 2.0.
+ *
* Comment if your system does not support the IPv6 socket interface
*/
#define POLARSSL_HAVE_IPV6
*
* Enable the memory allocation layer.
*
- * By default PolarSSL uses the system-provided malloc() and free().
+ * By default mbed TLS uses the system-provided malloc() and free().
* This allows different allocators (self-implemented or provided) to be
* provided to the platform abstraction layer.
*
- * Enabling POLARSSL_PLATFORM_MEMORY will provide "platform_set_malloc_free()"
- * to allow you to set an alternative malloc() and free() function pointer.
+ * Enabling POLARSSL_PLATFORM_MEMORY without the
+ * POLARSSL_PLATFORM_{FREE,MALLOC}_MACROs will provide
+ * "platform_set_malloc_free()" allowing you to set an alternative malloc() and
+ * free() function pointer at runtime.
+ *
+ * Enabling POLARSSL_PLATFORM_MEMORY and specifying
+ * POLARSSL_PLATFORM_{MALLOC,FREE}_MACROs will allow you to specify the
+ * alternate function at compile time.
*
* Requires: POLARSSL_PLATFORM_C
*
* This makes sure there are no linking errors on platforms that do not support
* these functions. You will HAVE to provide alternatives, either at runtime
* via the platform_set_xxx() functions or at compile time by setting
- * the POLARSSL_PLATFORM_STD_XXX defines.
+ * the POLARSSL_PLATFORM_STD_XXX defines, or enabling a
+ * POLARSSL_PLATFORM_XXX_MACRO.
*
* Requires: POLARSSL_PLATFORM_C
*
/**
* \def POLARSSL_PLATFORM_XXX_ALT
*
- * Uncomment a macro to let PolarSSL support the function in the platform
+ * Uncomment a macro to let mbed TLS support the function in the platform
* abstraction layer.
*
- * Example: In case you uncomment POLARSSL_PLATFORM_PRINTF_ALT, PolarSSL will
+ * Example: In case you uncomment POLARSSL_PLATFORM_PRINTF_ALT, mbed TLS will
* provide a function "platform_set_printf()" that allows you to set an
* alternative printf function pointer.
*
* All these define require POLARSSL_PLATFORM_C to be defined!
*
+ * WARNING: POLARSSL_PLATFORM_SNPRINTF_ALT is not available on Windows
+ * for compatibility reasons.
+ *
+ * WARNING: POLARSSL_PLATFORM_XXX_ALT cannot be defined at the same time as
+ * POLARSSL_PLATFORM_XXX_MACRO!
+ *
* Uncomment a macro to enable alternate implementation of specific base
* platform function
*/
-//#define POLARSSL_PLATFORM_PRINTF_ALT
+//#define POLARSSL_PLATFORM_EXIT_ALT
//#define POLARSSL_PLATFORM_FPRINTF_ALT
+//#define POLARSSL_PLATFORM_PRINTF_ALT
+//#define POLARSSL_PLATFORM_SNPRINTF_ALT
+
+/**
+ * \def POLARSSL_DEPRECATED_WARNING
+ *
+ * Mark deprecated functions so that they generate a warning if used.
+ * Functions deprecated in one version will usually be removed in the next
+ * version. You can enable this to help you prepare the transition to a new
+ * major version by making sure your code is not using these functions.
+ *
+ * This only works with GCC and Clang. With other compilers, you may want to
+ * use POLARSSL_DEPRECATED_REMOVED
+ *
+ * Uncomment to get warnings on using deprecated functions.
+ */
+//#define POLARSSL_DEPRECATED_WARNING
+
+/**
+ * \def POLARSSL_DEPRECATED_REMOVED
+ *
+ * Remove deprecated functions so that they generate an error if used.
+ * Functions deprecated in one version will usually be removed in the next
+ * version. You can enable this to help you prepare the transition to a new
+ * major version by making sure your code is not using these functions.
+ *
+ * Uncomment to get errors on using deprecated functions.
+ */
+//#define POLARSSL_DEPRECATED_REMOVED
+
/* \} name SECTION: System support */
/**
- * \name SECTION: PolarSSL feature support
+ * \name SECTION: mbed TLS feature support
*
* This section sets support for features that are or are not needed
* within the modules that are enabled.
/**
* \def POLARSSL_XXX_ALT
*
- * Uncomment a macro to let PolarSSL use your alternate core implementation of
+ * Uncomment a macro to let mbed TLS use your alternate core implementation of
* a symmetric or hash algorithm (e.g. platform specific assembly optimized
* implementations). Keep in mind that the function prototypes should remain
* the same.
*
- * Example: In case you uncomment POLARSSL_AES_ALT, PolarSSL will no longer
+ * Example: In case you uncomment POLARSSL_AES_ALT, mbed TLS will no longer
* provide the "struct aes_context" definition and omit the base function
* declarations and implementations. "aes_alt.h" will be included from
* "aes.h" to include the new function definitions.
* Store the AES tables in ROM.
*
* Uncomment this macro to store the AES tables in ROM.
- *
*/
//#define POLARSSL_AES_ROM_TABLES
+/**
+ * \def POLARSSL_CAMELLIA_SMALL_MEMORY
+ *
+ * Use less ROM for the Camellia implementation (saves about 768 bytes).
+ *
+ * Uncomment this macro to use less memory for Camellia.
+ */
+//#define POLARSSL_CAMELLIA_SMALL_MEMORY
+
/**
* \def POLARSSL_CIPHER_MODE_CBC
*
* Make available the backward compatible error_strerror() next to the
* current polarssl_strerror().
*
- * For new code, it is recommended to use polarssl_strerror() instead and
- * disable this.
+ * \deprecated Do not define this and use polarssl_strerror() instead
*
- * Disable if you run into name conflicts and want to really remove the
- * error_strerror()
+ * Disable if you want to really remove the error_strerror() name
*/
#define POLARSSL_ERROR_STRERROR_BC
*/
#define POLARSSL_SELF_TEST
+/**
+ * \def POLARSSL_SSL_AEAD_RANDOM_IV
+ *
+ * Generate a random IV rather than using the record sequence number as a
+ * nonce for ciphersuites using and AEAD algorithm (GCM or CCM).
+ *
+ * Using the sequence number is generally recommended.
+ *
+ * Uncomment this macro to always use random IVs with AEAD ciphersuites.
+ */
+//#define POLARSSL_SSL_AEAD_RANDOM_IV
+
/**
* \def POLARSSL_SSL_ALL_ALERT_MESSAGES
*
* Enable sending of alert messages in case of encountered errors as per RFC.
- * If you choose not to send the alert messages, PolarSSL can still communicate
+ * If you choose not to send the alert messages, mbed TLS can still communicate
* with other servers, only debugging of failures is harder.
*
* The advantage of not sending alert messages, is that no information is given
*/
//#define POLARSSL_SSL_DEBUG_ALL
+/** \def POLARSSL_SSL_ENCRYPT_THEN_MAC
+ *
+ * Enable support for Encrypt-then-MAC, RFC 7366.
+ *
+ * This allows peers that both support it to use a more robust protection for
+ * ciphersuites using CBC, providing deep resistance against timing attacks
+ * on the padding or underlying cipher.
+ *
+ * This only affects CBC ciphersuites, and is useless if none is defined.
+ *
+ * Requires: POLARSSL_SSL_PROTO_TLS1 or
+ * POLARSSL_SSL_PROTO_TLS1_1 or
+ * POLARSSL_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for Encrypt-then-MAC
+ */
+#define POLARSSL_SSL_ENCRYPT_THEN_MAC
+
+/** \def POLARSSL_SSL_EXTENDED_MASTER_SECRET
+ *
+ * Enable support for Extended Master Secret, aka Session Hash
+ * (draft-ietf-tls-session-hash-02).
+ *
+ * This was introduced as "the proper fix" to the Triple Handshake familiy of
+ * attacks, but it is recommended to always use it (even if you disable
+ * renegotiation), since it actually fixes a more fundamental issue in the
+ * original SSL/TLS design, and has implications beyond Triple Handshake.
+ *
+ * Requires: POLARSSL_SSL_PROTO_TLS1 or
+ * POLARSSL_SSL_PROTO_TLS1_1 or
+ * POLARSSL_SSL_PROTO_TLS1_2
+ *
+ * Comment this macro to disable support for Extended Master Secret.
+ */
+#define POLARSSL_SSL_EXTENDED_MASTER_SECRET
+
+/**
+ * \def POLARSSL_SSL_FALLBACK_SCSV
+ *
+ * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00).
+ *
+ * For servers, it is recommended to always enable this, unless you support
+ * only one version of TLS, or know for sure that none of your clients
+ * implements a fallback strategy.
+ *
+ * For clients, you only need this if you're using a fallback strategy, which
+ * is not recommended in the first place, unless you absolutely need it to
+ * interoperate with buggy (version-intolerant) servers.
+ *
+ * Comment this macro to disable support for FALLBACK_SCSV
+ */
+#define POLARSSL_SSL_FALLBACK_SCSV
+
/**
* \def POLARSSL_SSL_HW_RECORD_ACCEL
*
*/
//#define POLARSSL_SSL_HW_RECORD_ACCEL
+/**
+ * \def POLARSSL_SSL_CBC_RECORD_SPLITTING
+ *
+ * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
+ *
+ * This is a countermeasure to the BEAST attack, which also minimizes the risk
+ * of interoperability issues compared to sending 0-length records.
+ *
+ * Comment this macro to disable 1/n-1 record splitting.
+ */
+#define POLARSSL_SSL_CBC_RECORD_SPLITTING
+
+/**
+ * \def POLARSSL_SSL_DISABLE_RENEGOTIATION
+ *
+ * Disable support for TLS renegotiation.
+ *
+ * The two main uses of renegotiation are (1) refresh keys on long-lived
+ * connections and (2) client authentication after the initial handshake.
+ * If you don't need renegotiation, it's probably better to disable it, since
+ * it has been associated with security issues in the past and is easy to
+ * misuse/misunderstand.
+ *
+ * Warning: in the next stable branch, this switch will be replaced by
+ * POLARSSL_SSL_RENEGOTIATION to enable support for renegotiation.
+ *
+ * Uncomment this to disable support for renegotiation.
+ */
+//#define POLARSSL_SSL_DISABLE_RENEGOTIATION
+
/**
* \def POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
*
/**
* \def POLARSSL_SSL_ALPN
*
- * Enable support for Application Layer Protocol Negotiation.
- * draft-ietf-tls-applayerprotoneg-05
+ * Enable support for RFC 7301 Application Layer Protocol Negotiation.
*
* Comment this macro to disable support for ALPN.
*/
*
* Enable support for RFC 6066 server name indication (SNI) in SSL.
*
+ * Requires: POLARSSL_X509_CRT_PARSE_C
+ *
* Comment this macro to disable support for server name indication in SSL
*/
#define POLARSSL_SSL_SERVER_NAME_INDICATION
* Uncomment to enable use of ZLIB
*/
//#define POLARSSL_ZLIB_SUPPORT
-/* \} name SECTION: PolarSSL feature support */
+/* \} name SECTION: mbed TLS feature support */
/**
- * \name SECTION: PolarSSL modules
+ * \name SECTION: mbed TLS modules
*
- * This section enables or disables entire modules in PolarSSL
+ * This section enables or disables entire modules in mbed TLS
* \{
*/
*
* This modules adds support for the AES-NI instructions on x86-64
*/
-//#define POLARSSL_AESNI_C
+#define POLARSSL_AESNI_C
/**
* \def POLARSSL_AES_C
/**
* \def POLARSSL_MEMORY_C
- * Deprecated since 1.3.5. Please use POLARSSL_PLATFORM_MEMORY instead.
+ *
+ * \deprecated Use POLARSSL_PLATFORM_MEMORY instead.
+ *
+ * Depends on: POLARSSL_PLATFORM_C
*/
//#define POLARSSL_MEMORY_C
* Module: library/memory_buffer_alloc.c
*
* Requires: POLARSSL_PLATFORM_C
- * POLARSSL_PLATFORM_MEMORY (to use it within PolarSSL)
+ * POLARSSL_PLATFORM_MEMORY (to use it within mbed TLS)
*
* Enable this module to enable the buffer memory allocator.
*/
*
* Enable the TCP/IP networking routines.
*
+ * \warning As of 1.3.11, it is deprecated to enable this module without
+ * POLARSSL_HAVE_IPV6. The alternative legacy code will be removed in 2.0.
+ *
* Module: library/net.c
*
* This module provides TCP/IP networking routines.
*
* This modules adds support for the VIA PadLock on x86.
*/
-//#define POLARSSL_PADLOCK_C
+#define POLARSSL_PADLOCK_C
/**
* \def POLARSSL_PBKDF2_C
*
* Enable PKCS#5 PBKDF2 key derivation function.
- * DEPRECATED: Use POLARSSL_PKCS5_C instead
+ *
+ * \deprecated Use POLARSSL_PKCS5_C instead
*
* Module: library/pbkdf2.c
*
* \def POLARSSL_PLATFORM_C
*
* Enable the platform abstraction layer that allows you to re-assign
- * functions like malloc(), free(), printf(), fprintf()
+ * functions like malloc(), free(), snprintf(), printf(), fprintf(), exit()
+ *
+ * Enabling POLARSSL_PLATFORM_C enables to use of POLARSSL_PLATFORM_XXX_ALT
+ * or POLARSSL_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
+ * above to be specified at runtime or compile time respectively.
*
* Module: library/platform.c
* Caller: Most other .c files
* \def POLARSSL_THREADING_C
*
* Enable the threading abstraction layer.
- * By default PolarSSL assumes it is used in a non-threaded environment or that
+ * By default mbed TLS assumes it is used in a non-threaded environment or that
* contexts are not shared between threads. If you do intend to use contexts
* between threads, you will need to enable this layer to prevent race
* conditions.
* You will have to enable either POLARSSL_THREADING_ALT or
* POLARSSL_THREADING_PTHREAD.
*
- * Enable this layer to allow use of mutexes within PolarSSL
+ * Enable this layer to allow use of mutexes within mbed TLS
*/
//#define POLARSSL_THREADING_C
*/
#define POLARSSL_XTEA_C
-/* \} name SECTION: PolarSSL modules */
+/* \} name SECTION: mbed TLS modules */
/**
* \name SECTION: Module configuration options
//#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
/* Platform options */
-//#define POLARSSL_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if POLARSSL_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
-//#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use, can be undefined */
-//#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
-//#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
-//#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if POLARSSL_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
+//#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
+//#define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
+
+/* To Use Function Macros POLARSSL_PLATFORM_C must be enabled */
+/* POLARSSL_PLATFORM_XXX_MACRO and POLARSSL_PLATFORM_XXX_ALT cannot both be defined */
+//#define POLARSSL_PLATFORM_MALLOC_MACRO malloc /**< Default allocator macro to use, can be undefined */
+//#define POLARSSL_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
+//#define POLARSSL_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
+//#define POLARSSL_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
+//#define POLARSSL_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
+//#define POLARSSL_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
/* SSL Cache options */
//#define SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
/* SSL options */
//#define SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
+//#define SSL_MIN_DHM_BYTES 128 /**< Min size of the Diffie-Hellman prime */
//#define SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
//#define POLARSSL_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */
/* Debug options */
//#define POLARSSL_DEBUG_DFL_MODE POLARSSL_DEBUG_LOG_FULL /**< Default log: Full or Raw */
+/* X509 options */
+//#define POLARSSL_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
+
/* \} name SECTION: Module configuration options */
#include "check_config.h"
*
* \brief CTR_DRBG based on AES-256 (NIST SP 800-90)
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_CTR_DRBG_H
#define POLARSSL_CTR_DRBG_H
-#include <string.h>
-
#include "aes.h"
#define POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */
* \param ctx CTR_DRBG context
* \param additional Additional data to update state with
* \param add_len Length of additional data
+ *
+ * \note If add_len is greater than CTR_DRBG_MAX_SEED_INPUT,
+ * only the first CTR_DRBG_MAX_SEED_INPUT bytes are used,
+ * the remaining ones are silently discarded.
*/
void ctr_drbg_update( ctr_drbg_context *ctx,
const unsigned char *additional, size_t add_len );
*
* \brief Debug functions
*
- * Copyright (C) 2006-2011, Brainspark B.V.
+ * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#else
#include POLARSSL_CONFIG_FILE
#endif
+
#include "ssl.h"
+
#if defined(POLARSSL_ECP_C)
#include "ecp.h"
#endif
#define SSL_DEBUG_MSG( level, args ) \
- debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
+ debug_print_msg_free( ssl, level, __FILE__, __LINE__, debug_fmt args );
#define SSL_DEBUG_RET( level, text, ret ) \
debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret );
char *debug_fmt( const char *format, ... );
+void debug_print_msg_free( const ssl_context *ssl, int level,
+ const char *file, int line, char *text );
+
void debug_print_msg( const ssl_context *ssl, int level,
const char *file, int line, const char *text );
*
* \brief DES block cipher
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
/**
* \brief DES-CBC buffer encryption/decryption
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx DES context
* \param mode DES_ENCRYPT or DES_DECRYPT
* \param length length of the input data
/**
* \brief 3DES-CBC buffer encryption/decryption
*
+ * \note Upon exit, the content of the IV is updated so that you can
+ * call the function same function again on the following
+ * block(s) of data and get the same result as if it was
+ * encrypted in one call. This allows a "streaming" usage.
+ * If on the other hand you need to retain the contents of the
+ * IV, you should either save it manually or use the cipher
+ * module instead.
+ *
* \param ctx 3DES context
* \param mode DES_ENCRYPT or DES_DECRYPT
* \param length length of the input data
*
* \brief Diffie-Hellman-Merkle key exchange
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief Elliptic curve Diffie-Hellman
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief Elliptic curve DSA
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define POLARSSL_ECDSA_H
#include "ecp.h"
-
-#if defined(POLARSSL_ECDSA_DETERMINISTIC)
#include "md.h"
-#endif
/**
* \brief ECDSA context structure
*
* \brief Elliptic curves over GF(p)
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* \param buf $(Start of input buffer)
* \param len Buffer length
*
- * \return O if successful,
+ * \note buf is updated to point right after the ECPoint on exit
+ *
+ * \return 0 if successful,
* POLARSSL_ERR_MPI_XXX if initialization failed
* POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
*/
* \param grp Destination group
* \param index Index in the list of well-known domain parameters
*
- * \return O if successful,
+ * \return 0 if successful,
* POLARSSL_ERR_MPI_XXX if initialization failed
* POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups
*
* \param buf &(Start of input buffer)
* \param len Buffer length
*
- * \return O if successful,
+ * \note buf is updated to point right after ECParameters on exit
+ *
+ * \return 0 if successful,
* POLARSSL_ERR_MPI_XXX if initialization failed
* POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
*/
int ecp_gen_key( ecp_group_id grp_id, ecp_keypair *key,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+/**
+ * \brief Check a public-private key pair
+ *
+ * \param pub Keypair structure holding a public key
+ * \param prv Keypair structure holding a private (plus public) key
+ *
+ * \return 0 if successful (keys are valid and match), or
+ * POLARSSL_ERR_ECP_BAD_INPUT_DATA, or
+ * a POLARSSL_ERR_ECP_XXX or POLARSSL_ERR_MPI_XXX code.
+ */
+int ecp_check_pub_priv( const ecp_keypair *pub, const ecp_keypair *prv );
+
#if defined(POLARSSL_SELF_TEST)
/**
* \brief Checkup routine
*
* \brief Entropy accumulator implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_ENTROPY_H
#define POLARSSL_ENTROPY_H
-#include <string.h>
-
#if !defined(POLARSSL_CONFIG_FILE)
#include "config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif
+#include <stddef.h>
+
#if defined(POLARSSL_SHA512_C) && !defined(POLARSSL_ENTROPY_FORCE_SHA256)
#include "sha512.h"
#define POLARSSL_ENTROPY_SHA512_ACCUMULATOR
*
* \brief Platform-specific and custom entropy polling functions
*
- * Copyright (C) 2006-2011, Brainspark B.V.
+ * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_ENTROPY_POLL_H
#define POLARSSL_ENTROPY_POLL_H
-#include <string.h>
-
#if !defined(POLARSSL_CONFIG_FILE)
#include "config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
*
* \brief Error to string translation
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_ERROR_H
#define POLARSSL_ERROR_H
-#include <string.h>
+#include <stddef.h>
/**
* Error code layout.
* ECP 4 8 (Started from top)
* MD 5 4
* CIPHER 6 6
- * SSL 6 10 (Started from top)
+ * SSL 6 11 (Started from top)
* SSL 7 31
*
* Module dependent error code (5 bits 0x.00.-0x.F8.)
#endif
/**
- * \brief Translate a PolarSSL error code into a string representation,
+ * \brief Translate a mbed TLS error code into a string representation,
* Result is truncated if necessary and always includes a terminating
* null byte.
*
*
* \brief Galois/Counter mode for 128-bit block ciphers
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_HAVEGE_H
#define POLARSSL_HAVEGE_H
-#include <string.h>
+#include <stddef.h>
#define COLLECT_SIZE 1024
*
* \brief HMAC_DRBG (NIST SP 800-90A)
*
- * Copyright (C) 2014, Brainspark B.V.
+ * Copyright (C) 2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_MD_H
#define POLARSSL_MD_H
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(inline)
#define inline _inline
*/
int md_init_ctx( md_context_t *ctx, const md_info_t *md_info );
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
/**
* \brief Free the message-specific context of ctx. Freeing ctx itself
* remains the responsibility of the caller.
*
- * \note Deprecated: Redirects to md_free()
+ * \deprecated Use md_free() instead
*
* \param ctx Free the message-specific context
*
* \returns 0
*/
-int md_free_ctx( md_context_t *ctx );
+int md_free_ctx( md_context_t *ctx ) DEPRECATED;
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
/**
* \brief Returns the size of the message digest output.
*
* \brief MD2 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
*
* \brief MD4 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
*
* \brief MD5 message digest algorithm (hash function)
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2011, Brainspark B.V.
+ * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#else
#include POLARSSL_CONFIG_FILE
#endif
+
#include "md.h"
#ifdef __cplusplus
/**
* \file memory.h
*
- * \brief Memory allocation layer (Deprecated to platform layer)
+ * \brief Memory allocation layer
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * \deprecated Use the platform layer instead
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <stdlib.h>
-#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
-#define POLARSSL_PLATFORM_MEMORY
-#endif
-
#include "platform.h"
#include "memory_buffer_alloc.h"
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
+/**
+ * \brief Set malloc() / free() callback
+ *
+ * \deprecated Use platform_set_malloc_free instead
+ */
+int memory_set_own( void * (*malloc_func)( size_t ),
+ void (*free_func)( void * ) ) DEPRECATED;
int memory_set_own( void * (*malloc_func)( size_t ),
void (*free_func)( void * ) )
{
return platform_set_malloc_free( malloc_func, free_func );
}
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
#endif /* memory.h */
*
* \brief Buffer-based memory allocator
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <stdlib.h>
+#include <stddef.h>
/**
* \name SECTION: Module settings
* trace if POLARSSL_MEMORY_BACKTRACE is defined.
*/
void memory_buffer_alloc_status( void );
+
+/**
+ * \brief Get the peak heap usage so far
+ *
+ * \param max_used Peak number of bytes reauested by the application
+ * \param max_blocks Peak number of blocks reauested by the application
+ */
+void memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks );
+
+/**
+ * \brief Reset peak statistics
+ */
+void memory_buffer_alloc_max_reset( void );
+
+/**
+ * \brief Get the current heap usage
+ *
+ * \param cur_used Number of bytes reauested by the application
+ * \param cur_blocks Number of blocks reauested by the application
+ */
+void memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks );
#endif /* POLARSSL_MEMORY_DEBUG */
/**
*/
int memory_buffer_alloc_verify( void );
+#if defined(POLARSSL_SELF_TEST)
+/**
+ * \brief Checkup routine
+ *
+ * \return 0 if successful, or 1 if a test failed
+ */
+int memory_buffer_alloc_self_test( int verbose );
+#endif
+
#ifdef __cplusplus
}
#endif
*
* \brief Network communication functions
*
- * Copyright (C) 2006-2011, Brainspark B.V.
+ * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_NET_H
#define POLARSSL_NET_H
-#include <string.h>
+#include <stddef.h>
#define POLARSSL_ERR_NET_UNKNOWN_HOST -0x0056 /**< Failed to get an IP address for the given hostname. */
#define POLARSSL_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */
*
* \brief Object Identifier (OID) database
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_OID_H
#define POLARSSL_OID_H
-#include <string.h>
#if !defined(POLARSSL_CONFIG_FILE)
#include "config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif
+
#include "asn1.h"
#include "pk.h"
+
+#include <stddef.h>
+
#if defined(POLARSSL_CIPHER_C)
#include "cipher.h"
#endif
#define OID_AT_GIVEN_NAME OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */
#define OID_AT_INITIALS OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */
#define OID_AT_GENERATION_QUALIFIER OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */
+#define OID_AT_UNIQUE_IDENTIFIER OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} */
#define OID_AT_DN_QUALIFIER OID_AT "\x2E" /**< id-at-dnQualifier AttributeType:= {id-at 46} */
#define OID_AT_PSEUDONYM OID_AT "\x41" /**< id-at-pseudonym AttributeType:= {id-at 65} */
* \param oid OID to translate
*
* \return Length of the string written (excluding final NULL) or
- * POLARSSL_ERR_OID_BUF_TO_SMALL in case of error
+ * POLARSSL_ERR_OID_BUF_TOO_SMALL in case of error
*/
int oid_get_numeric_string( char *buf, size_t size, const asn1_buf *oid );
*
* \brief OpenSSL wrapper (definitions, inline functions).
*
- * Copyright (C) 2006-2010, Brainspark B.V.
+ * \deprecated Use native mbed TLS functions instead
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ * Copyright (C) 2006-2010, ARM Limited, All Rights Reserved
*
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+
/*
* OpenSSL wrapper contributed by David Barett
*/
+
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#warning "Including openssl.h is deprecated"
+#endif
+
#ifndef POLARSSL_OPENSSL_H
#define POLARSSL_OPENSSL_H
#endif
#endif /* openssl.h */
+#endif /* POLARSSL_DEPRECATED_REMOVED */
* \brief VIA PadLock ACE for HW encryption/decryption supported by some
* processors
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
-#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+#define POLARSSL_HAVE_ASAN
+#endif
+#endif
+
+/* Some versions of ASan result in errors about not enough registers */
+#if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
+ !defined(POLARSSL_HAVE_ASAN)
#ifndef POLARSSL_HAVE_X86
#define POLARSSL_HAVE_X86
#include <inttypes.h>
#endif
-
#define PADLOCK_RNG 0x000C
#define PADLOCK_ACE 0x00C0
#define PADLOCK_PHE 0x0C00
* \file pbkdf2.h
*
* \brief Password-Based Key Derivation Function 2 (from PKCS#5)
- * DEPRECATED: use pkcs5.h instead.
*
- * \author Mathias Olsson <mathias@kompetensum.com>
+ * \deprecated Use pkcs5.h instead.
*
- * Copyright (C) 2006-2012, Brainspark B.V.
+ * \author Mathias Olsson <mathias@kompetensum.com>
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ * Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
*
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_PBKDF2_H
#define POLARSSL_PBKDF2_H
-#include <string.h>
-
#include "md.h"
+#include <stddef.h>
+
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
typedef UINT32 uint32_t;
extern "C" {
#endif
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
/**
* \brief PKCS#5 PBKDF2 using HMAC
- * DEPRECATED: Use pkcs5_pbkdf2_hmac() instead!
+ *
+ * \deprecated Use pkcs5_pbkdf2_hmac() instead
*
* \param ctx Generic HMAC context
* \param password Password to use when generating key
* \param key_length Length of generated key
* \param output Generated key. Must be at least as big as key_length
*
- * \returns 0 on success, or a PolarSSL error code if verification fails.
+ * \returns 0 on success, or a POLARSSL_ERR_xxx code if verification fails.
*/
int pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
size_t plen, const unsigned char *salt, size_t slen,
unsigned int iteration_count,
- uint32_t key_length, unsigned char *output );
+ uint32_t key_length, unsigned char *output ) DEPRECATED;
/**
* \brief Checkup routine
- * DEPRECATED: Use pkcs5_self_test() instead!
+ *
+ * \deprecated Use pkcs5_self_test() instead
*
* \return 0 if successful, or 1 if the test failed
*/
-int pbkdf2_self_test( int verbose );
+int pbkdf2_self_test( int verbose ) DEPRECATED;
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
#ifdef __cplusplus
}
*
* \brief Privacy Enhanced Mail (PEM) decoding
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_PEM_H
#define POLARSSL_PEM_H
-#include <string.h>
+#include <stddef.h>
/**
* \name PEM Error codes
*
* \brief Public Key abstraction layer
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
+ /** Check public-private key pair */
+ int (*check_pair_func)( const void *pub, const void *prv );
+
/** Allocate a new context */
void * (*ctx_alloc_func)( void );
unsigned char *output, size_t *olen, size_t osize,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
+/**
+ * \brief Check if a public-private pair of keys matches.
+ *
+ * \param pub Context holding a public key.
+ * \param prv Context holding a private (and public) key.
+ *
+ * \return 0 on success or POLARSSL_ERR_PK_BAD_INPUT_DATA
+ */
+int pk_check_pair( const pk_context *pub, const pk_context *prv );
+
/**
* \brief Export debug information
*
const pk_context *key );
#endif /* POLARSSL_PK_WRITE_C */
+/*
+ * Internal module functions. You probably do not want to use these unless you
+ * know you do.
+ */
+#if defined(POLARSSL_FS_IO)
+int pk_load_file( const char *path, unsigned char **buf, size_t *n );
+#endif
+
#ifdef __cplusplus
}
#endif
*
* \brief Public Key abstraction layer: wrapper functions
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
} pkcs11_context;
/**
- * Fill in a PolarSSL certificate, based on the given PKCS11 helper certificate.
+ * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
*
* \param cert X.509 certificate to fill
* \param pkcs11h_cert PKCS #11 helper certificate
*
* \brief PKCS#12 Personal Information Exchange Syntax
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_PKCS12_H
#define POLARSSL_PKCS12_H
-#include <string.h>
-
#include "md.h"
#include "cipher.h"
#include "asn1.h"
+#include <stddef.h>
+
#define POLARSSL_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
#define POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
#define POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
* \param len data length
* \param output the output buffer
*
- * \return 0 if successful, or a PolarSSL error code
+ * \return 0 if successful, or a POLARSSL_ERR_xxx code
*/
int pkcs12_pbe_sha1_rc4_128( asn1_buf *pbe_params, int mode,
const unsigned char *pwd, size_t pwdlen,
* \param len data length
* \param output the output buffer
*
- * \return 0 if successful, or a PolarSSL error code
+ * \return 0 if successful, or a POLARSSL_ERR_xxx code
*/
int pkcs12_pbe( asn1_buf *pbe_params, int mode,
cipher_type_t cipher_type, md_type_t md_type,
*
* \author Mathias Olsson <mathias@kompetensum.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef POLARSSL_PKCS5_H
#define POLARSSL_PKCS5_H
-#include <string.h>
-
#include "asn1.h"
#include "md.h"
+#include <stddef.h>
+
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
typedef UINT32 uint32_t;
* \param datalen length of data
* \param output output buffer
*
- * \returns 0 on success, or a PolarSSL error code if verification fails.
+ * \returns 0 on success, or a POLARSSL_ERR_xxx code if verification fails.
*/
int pkcs5_pbes2( asn1_buf *pbe_params, int mode,
const unsigned char *pwd, size_t pwdlen,
* \param key_length Length of generated key
* \param output Generated key. Must be at least as big as key_length
*
- * \returns 0 on success, or a PolarSSL error code if verification fails.
+ * \returns 0 on success, or a POLARSSL_ERR_xxx code if verification fails.
*/
int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
size_t plen, const unsigned char *salt, size_t slen,
/**
* \file platform.h
*
- * \brief PolarSSL Platform abstraction layer
+ * \brief mbed TLS Platform abstraction layer
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <stdio.h>
+/* Temporary compatibility hack for to keep MEMORY_C working */
+#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
+#define POLARSSL_PLATFORM_MEMORY
+#endif
#ifdef __cplusplus
extern "C" {
*/
#if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
+#include <stdio.h>
#include <stdlib.h>
+#if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
+#define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
+#endif
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
#endif
#if !defined(POLARSSL_PLATFORM_STD_FREE)
#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
#endif
+#if !defined(POLARSSL_PLATFORM_STD_EXIT)
+#define POLARSSL_PLATFORM_STD_EXIT exit /**< Default free to use */
+#endif
#else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
#include POLARSSL_PLATFORM_STD_MEM_HDR
* The function pointers for malloc and free
*/
#if defined(POLARSSL_PLATFORM_MEMORY)
+#if defined(POLARSSL_PLATFORM_FREE_MACRO) && \
+ defined(POLARSSL_PLATFORM_MALLOC_MACRO)
+#define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
+#define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
+#else
+/* For size_t */
+#include <stddef.h>
extern void * (*polarssl_malloc)( size_t len );
extern void (*polarssl_free)( void *ptr );
*/
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
void (*free_func)( void * ) );
-#else /* POLARSSL_PLATFORM_ENTROPY */
-#define polarssl_malloc malloc
+#endif /* POLARSSL_PLATFORM_FREE_MACRO && POLARSSL_PLATFORM_MALLOC_MACRO */
+#else /* !POLARSSL_PLATFORM_MEMORY */
#define polarssl_free free
-#endif /* POLARSSL_PLATFORM_ENTROPY */
+#define polarssl_malloc malloc
+#endif /* POLARSSL_PLATFORM_MEMORY && !POLARSSL_PLATFORM_{FREE,MALLOC}_MACRO */
+
+/*
+ * The function pointers for fprintf
+ */
+#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
+/* We need FILE * */
+#include <stdio.h>
+extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
+
+/**
+ * \brief Set your own fprintf function pointer
+ *
+ * \param fprintf_func the fprintf function implementation
+ *
+ * \return 0
+ */
+int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
+ ... ) );
+#else
+#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
+#define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
+#else
+#define polarssl_fprintf fprintf
+#endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
+#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
/*
* The function pointers for printf
* \return 0
*/
int platform_set_printf( int (*printf_func)( const char *, ... ) );
-#else /* POLARSSL_PLATFORM_PRINTF_ALT */
+#else /* !POLARSSL_PLATFORM_PRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
+#define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
+#else
#define polarssl_printf printf
+#endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
/*
- * The function pointers for fprintf
+ * The function pointers for snprintf
*/
-#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
-extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
+extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
-int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
- ... ) );
+/**
+ * \brief Set your own snprintf function pointer
+ *
+ * \param snprintf_func the snprintf function implementation
+ *
+ * \return 0
+ */
+int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
+ const char * format, ... ) );
+#else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
+#define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
#else
-#define polarssl_fprintf fprintf
-#endif
+#define polarssl_snprintf snprintf
+#endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
+#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+
+/*
+ * The function pointers for exit
+ */
+#if defined(POLARSSL_PLATFORM_EXIT_ALT)
+extern void (*polarssl_exit)( int status );
+
+/**
+ * \brief Set your own exit function pointer
+ *
+ * \param exit_func the exit function implementation
+ *
+ * \return 0
+ */
+int platform_set_exit( void (*exit_func)( int status ) );
+#else
+#if defined(POLARSSL_PLATFORM_EXIT_MACRO)
+#define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
+#else
+#define polarssl_exit exit
+#endif /* POLARSSL_PLATFORM_EXIT_MACRO */
+#endif /* POLARSSL_PLATFORM_EXIT_ALT */
#ifdef __cplusplus
}
*
* \brief RIPE MD-160 message digest
*
- * Copyright (C) 2014-2014, Brainspark B.V.
+ * Copyright (C) 2014-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
*
* \brief The RSA public-key cryptosystem
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
#define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
#define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
-#define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the libraries validity check. */
+#define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the library's validity check. */
#define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
#define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
#define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
mpi RP; /*!< cached R^2 mod P */
mpi RQ; /*!< cached R^2 mod Q */
-#if !defined(POLARSSL_RSA_NO_CRT)
mpi Vi; /*!< cached blinding value */
mpi Vf; /*!< cached un-blinding value */
-#endif
int padding; /*!< RSA_PKCS_V15 for 1.5 padding and
RSA_PKCS_v21 for OAEP/PSS */
*/
int rsa_check_privkey( const rsa_context *ctx );
+/**
+ * \brief Check a public-private RSA key pair.
+ * Check each of the contexts, and make sure they match.
+ *
+ * \param pub RSA context holding the public key
+ * \param prv RSA context holding the private key
+ *
+ * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code
+ */
+int rsa_check_pub_priv( const rsa_context *pub, const rsa_context *prv );
+
/**
* \brief Do an RSA public key operation
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param input input buffer
/**
* \brief Do an RSA private key operation
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for blinding)
* \brief Generic wrapper to perform a PKCS#1 encryption using the
* mode from the context. Add the message padding, then do an
* RSA operation.
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding
/**
* \brief Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for padding and RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding
* \brief Generic wrapper to perform a PKCS#1 decryption using the
* mode from the context. Do an RSA operation, then remove
* the message padding
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
* \brief Generic wrapper to perform a PKCS#1 signature using the
* mode from the context. Do a private RSA operation to sign
* a message digest
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for
/**
* \brief Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx RSA context
* \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for
* \brief Generic wrapper to perform a PKCS#1 verification using the
* mode from the context. Do a public RSA operation and check
* the message digest
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx points to an RSA public key
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx points to an RSA public key
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY)
* (This is the "simple" version.)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx points to an RSA public key
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
/**
* \brief Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY)
* (This is the version with "full" options.)
+ * (Thread-safe if POLARSSL_THREADING_C is enabled)
*
* \param ctx points to an RSA public key
* \param f_rng RNG function (Only needed for RSA_PRIVATE)
*
* \brief SHA-1 cryptographic hash function
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
*
* \brief SHA-224 and SHA-256 cryptographic hash function
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
*
* \brief SHA-384 and SHA-512 cryptographic hash function
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) || defined(__WATCOMC__)
- #define UL64(x) x##ui64
typedef unsigned __int64 uint64_t;
#else
#include <inttypes.h>
- #define UL64(x) x##ULL
#endif
#define POLARSSL_ERR_SHA512_FILE_IO_ERROR -0x007A /**< Read/write error in file. */
*
* \brief SSL/TLS functions.
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#else
#include POLARSSL_CONFIG_FILE
#endif
+
+/* Temporary compatibility trick for the current stable branch */
+#if !defined(POLARSSL_SSL_DISABLE_RENEGOTIATION)
+#define POLARSSL_SSL_RENEGOTIATION
+#endif
+
#include "net.h"
#include "bignum.h"
#include "ecp.h"
#define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
#define POLARSSL_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
#define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
-#define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message.*/
+#define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
#define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
#define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
#define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
#define POLARSSL_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
#define POLARSSL_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
#define POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
+#define POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6A80 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
/*
* Various constants
#define SSL_IS_CLIENT 0
#define SSL_IS_SERVER 1
+#define SSL_IS_NOT_FALLBACK 0
+#define SSL_IS_FALLBACK 1
+
+#define SSL_EXTENDED_MS_DISABLED 0
+#define SSL_EXTENDED_MS_ENABLED 1
+
+#define SSL_ETM_DISABLED 0
+#define SSL_ETM_ENABLED 1
+
#define SSL_COMPRESS_NULL 0
#define SSL_COMPRESS_DEFLATE 1
#define SSL_SESSION_TICKETS_DISABLED 0
#define SSL_SESSION_TICKETS_ENABLED 1
+#define SSL_CBC_RECORD_SPLITTING_DISABLED -1
+#define SSL_CBC_RECORD_SPLITTING_ENABLED 0
+
+#define SSL_ARC4_ENABLED 0
+#define SSL_ARC4_DISABLED 1
+
/**
* \name SECTION: Module settings
*
#define SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
#endif
+/*
+ * Minimum size of the Diffie-Hellman parameters to accept from a server.
+ * The default is 1024 bits (128 bytes) for compatibility reasons.
+ * From a purely security perspective, 2048 bits would be better.
+ */
+#define SSL_MIN_DHM_BYTES 128 /**< Min size of the Diffie-Hellman prime */
/* \} name SECTION: Module settings */
/*
+ SSL_PADDING_ADD \
)
+/*
+ * Length of the verify data for secure renegotiation
+ */
+#if defined(POLARSSL_SSL_PROTO_SSL3)
+#define SSL_VERIFY_DATA_MAX_LEN 36
+#else
+#define SSL_VERIFY_DATA_MAX_LEN 12
+#endif
+
/*
* Signaling ciphersuite values (SCSV)
*/
#define SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
+#define SSL_FALLBACK_SCSV 0x5600 /**< draft-ietf-tls-downgrade-scsv-00 */
/*
* Supported Signature and Hash algorithms (For TLS 1.2)
#define SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
#define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
#define SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
+#define SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
#define SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
#define SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
#define SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
#define TLS_EXT_ALPN 16
+#define TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
+#define TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
+
#define TLS_EXT_SESSION_TICKET 35
#define TLS_EXT_RENEGOTIATION_INFO 0xFF01
#if defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED)
unsigned char _pms_rsa_psk[52 + POLARSSL_PSK_MAX_LEN]; /* RFC 4279 4 */
#endif
-#if defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED)
+#if defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
unsigned char _pms_ecdhe_psk[4 + POLARSSL_ECP_MAX_BYTES
+ POLARSSL_PSK_MAX_LEN]; /* RFC 5489 2 */
#endif
#if defined(POLARSSL_SSL_TRUNCATED_HMAC)
int trunc_hmac; /*!< flag for truncated hmac activation */
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ int encrypt_then_mac; /*!< flag for EtM activation */
+#endif
};
/*
#if defined(POLARSSL_SSL_SESSION_TICKETS)
int new_session_ticket; /*!< use NewSessionTicket? */
#endif /* POLARSSL_SSL_SESSION_TICKETS */
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ int extended_ms; /*!< use Extended Master Secret? */
+#endif
};
#if defined(POLARSSL_SSL_SESSION_TICKETS)
*/
int state; /*!< SSL handshake: current state */
int renegotiation; /*!< Initial or renegotiation */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
int renego_records_seen; /*!< Records since renego request */
+#endif
int major_ver; /*!< equal to SSL_MAJOR_VERSION_3 */
int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
int min_major_ver; /*!< min. major version used */
int min_minor_ver; /*!< min. minor version used */
+#if defined(POLARSSL_SSL_FALLBACK_SCSV) && defined(POLARSSL_SSL_CLI_C)
+ char fallback; /*!< flag for fallback connections */
+#endif
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ char encrypt_then_mac; /*!< flag for encrypt-then-mac */
+#endif
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ char extended_ms; /*!< flag for extended master secret */
+#endif
+ char arc4_disabled; /*!< flag for disabling RC4 */
+
/*
* Callbacks (RNG, debug, I/O, verification)
*/
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
unsigned char mfl_code; /*!< MaxFragmentLength chosen by us */
#endif /* POLARSSL_SSL_MAX_FRAGMENT_LENGTH */
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+ signed char split_done; /*!< flag for record splitting:
+ -1 disabled, 0 todo, 1 done */
+#endif
/*
* PKI layer
int authmode; /*!< verification mode */
int client_auth; /*!< flag for client auth. */
int verify_result; /*!< verification result */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
int disable_renegotiation; /*!< enable/disable renegotiation */
- int allow_legacy_renegotiation; /*!< allow legacy renegotiation */
int renego_max_records; /*!< grace period for renegotiation */
+ unsigned char renego_period[8]; /*!< value of the record counters
+ that triggers renegotiation */
+#endif
+ int allow_legacy_renegotiation; /*!< allow legacy renegotiation */
const int *ciphersuite_list[4]; /*!< allowed ciphersuites / version */
#if defined(POLARSSL_SSL_SET_CURVES)
const ecp_group_id *curve_list; /*!< allowed curves */
*/
int secure_renegotiation; /*!< does peer support legacy or
secure renegotiation */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
size_t verify_data_len; /*!< length of verify data stored */
- char own_verify_data[36]; /*!< previous handshake verify data */
- char peer_verify_data[36]; /*!< previous handshake verify data */
+ char own_verify_data[SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
+ char peer_verify_data[SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
+#endif
};
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
int (*f_recv)(void *, unsigned char *, size_t), void *p_recv,
int (*f_send)(void *, const unsigned char *, size_t), void *p_send );
+#if defined(POLARSSL_SSL_SRV_C)
/**
* \brief Set the session cache callbacks (server-side only)
- * If not set, no session resuming is done.
+ * If not set, no session resuming is done (except if session
+ * tickets are enabled too).
*
* The session cache has the responsibility to check for stale
* entries based on timeout. See RFC 5246 for recommendations.
void ssl_set_session_cache( ssl_context *ssl,
int (*f_get_cache)(void *, ssl_session *), void *p_get_cache,
int (*f_set_cache)(void *, const ssl_session *), void *p_set_cache );
+#endif /* POLARSSL_SSL_SRV_C */
+#if defined(POLARSSL_SSL_CLI_C)
/**
* \brief Request resumption of session (client-side only)
* Session data is copied from presented session structure.
* \sa ssl_get_session()
*/
int ssl_set_session( ssl_context *ssl, const ssl_session *session );
+#endif /* POLARSSL_SSL_CLI_C */
/**
* \brief Set the list of allowed ciphersuites and the preference
* order. First in the list has the highest preference.
* (Overrides all version specific lists)
*
- * Note: The PolarSSL SSL server uses its own preferences
- * over the preference of the connection SSL client unless
+ * The ciphersuites array is not copied, and must remain
+ * valid for the lifetime of the ssl_context.
+ *
+ * Note: The server uses its own preferences
+ * over the preference of the client unless
* POLARSSL_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
*
* \param ssl SSL context
int ssl_set_own_cert( ssl_context *ssl, x509_crt *own_cert,
pk_context *pk_key );
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
#if defined(POLARSSL_RSA_C)
/**
* \brief Set own certificate chain and private RSA key
* up your certificate chain. The top certificate (self-signed)
* can be omitted.
*
- * \warning This backwards-compatibility function is deprecated!
- * Please use \c ssl_set_own_cert() instead.
+ * \deprecated Please use \c ssl_set_own_cert() instead.
*
* \param ssl SSL context
* \param own_cert own public certificate chain
* \return 0 on success, or a specific error code.
*/
int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
- rsa_context *rsa_key );
+ rsa_context *rsa_key ) DEPRECATED;
#endif /* POLARSSL_RSA_C */
/**
- * \brief Set own certificate and alternate non-PolarSSL RSA private
+ * \brief Set own certificate and external RSA private
* key and handling callbacks, such as the PKCS#11 wrappers
* or any other external private key handler.
* (see the respective RSA functions in rsa.h for documentation
* up your certificate chain. The top certificate (self-signed)
* can be omitted.
*
- * \warning This backwards-compatibility function is deprecated!
- * Please use \c pk_init_ctx_rsa_alt()
+ * \deprecated Please use \c pk_init_ctx_rsa_alt()
* and \c ssl_set_own_cert() instead.
*
* \param ssl SSL context
void *rsa_key,
rsa_decrypt_func rsa_decrypt,
rsa_sign_func rsa_sign,
- rsa_key_len_func rsa_key_len );
+ rsa_key_len_func rsa_key_len ) DEPRECATED;
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
#endif /* POLARSSL_X509_CRT_PARSE_C */
#if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
/**
* \brief Set the Diffie-Hellman public P and G values,
* read as hexadecimal strings (server-side only)
- * (Default: POLARSSL_DHM_RFC5114_MODP_1024_[PG])
+ * (Default: POLARSSL_DHM_RFC5114_MODP_2048_[PG])
*
* \param ssl SSL context
* \param dhm_P Diffie-Hellman-Merkle modulus
*/
void ssl_set_max_version( ssl_context *ssl, int major, int minor );
-
/**
* \brief Set the minimum accepted SSL/TLS protocol version
* (Default: SSL_MIN_MAJOR_VERSION, SSL_MIN_MINOR_VERSION)
*
- * Note: Input outside of the SSL_MAX_XXXXX_VERSION and
- * SSL_MIN_XXXXX_VERSION range is ignored.
+ * \note Input outside of the SSL_MAX_XXXXX_VERSION and
+ * SSL_MIN_XXXXX_VERSION range is ignored.
+ *
+ * \note SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
*
* \param ssl SSL context
* \param major Major version number (only SSL_MAJOR_VERSION_3 supported)
*/
void ssl_set_min_version( ssl_context *ssl, int major, int minor );
+#if defined(POLARSSL_SSL_FALLBACK_SCSV) && defined(POLARSSL_SSL_CLI_C)
+/**
+ * \brief Set the fallback flag (client-side only).
+ * (Default: SSL_IS_NOT_FALLBACK).
+ *
+ * \note Set to SSL_IS_FALLBACK when preparing a fallback
+ * connection, that is a connection with max_version set to a
+ * lower value than the value you're willing to use. Such
+ * fallback connections are not recommended but are sometimes
+ * necessary to interoperate with buggy (version-intolerant)
+ * servers.
+ *
+ * \warning You should NOT set this to SSL_IS_FALLBACK for
+ * non-fallback connections! This would appear to work for a
+ * while, then cause failures when the server is upgraded to
+ * support a newer TLS version.
+ *
+ * \param ssl SSL context
+ * \param fallback SSL_IS_NOT_FALLBACK or SSL_IS_FALLBACK
+ */
+void ssl_set_fallback( ssl_context *ssl, char fallback );
+#endif /* POLARSSL_SSL_FALLBACK_SCSV && POLARSSL_SSL_CLI_C */
+
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+/**
+ * \brief Enable or disable Encrypt-then-MAC
+ * (Default: SSL_ETM_ENABLED)
+ *
+ * \note This should always be enabled, it is a security
+ * improvement, and should not cause any interoperability
+ * issue (used only if the peer supports it too).
+ *
+ * \param ssl SSL context
+ * \param etm SSL_ETM_ENABLED or SSL_ETM_DISABLED
+ */
+void ssl_set_encrypt_then_mac( ssl_context *ssl, char etm );
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+/**
+ * \brief Enable or disable Extended Master Secret negotiation.
+ * (Default: SSL_EXTENDED_MS_ENABLED)
+ *
+ * \note This should always be enabled, it is a security fix to the
+ * protocol, and should not cause any interoperability issue
+ * (used only if the peer supports it too).
+ *
+ * \param ssl SSL context
+ * \param ems SSL_EXTENDED_MS_ENABLED or SSL_EXTENDED_MS_DISABLED
+ */
+void ssl_set_extended_master_secret( ssl_context *ssl, char ems );
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
+/**
+ * \brief Disable or enable support for RC4
+ * (Default: SSL_ARC4_ENABLED)
+ *
+ * \note Though the default is RC4 for compatibility reasons in the
+ * 1.3 branch, the recommended value is SSL_ARC4_DISABLED.
+ *
+ * \note This function will likely be removed in future versions as
+ * RC4 will then be disabled by default at compile time.
+ *
+ * \param ssl SSL context
+ * \param arc4 SSL_ARC4_ENABLED or SSL_ARC4_DISABLED
+ */
+void ssl_set_arc4_support( ssl_context *ssl, char arc4 );
+
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
/**
* \brief Set the maximum fragment length to emit and/or negotiate
* SSL_MAX_FRAG_LEN_512, SSL_MAX_FRAG_LEN_1024,
* SSL_MAX_FRAG_LEN_2048, SSL_MAX_FRAG_LEN_4096)
*
- * \return O if successful or POLARSSL_ERR_SSL_BAD_INPUT_DATA
+ * \return 0 if successful or POLARSSL_ERR_SSL_BAD_INPUT_DATA
*/
int ssl_set_max_frag_len( ssl_context *ssl, unsigned char mfl_code );
#endif /* POLARSSL_SSL_MAX_FRAGMENT_LENGTH */
#if defined(POLARSSL_SSL_TRUNCATED_HMAC)
/**
- * \brief Activate negotiation of truncated HMAC (Client only)
- * (Default: SSL_TRUNC_HMAC_ENABLED)
+ * \brief Activate negotiation of truncated HMAC
+ * (Default: SSL_TRUNC_HMAC_DISABLED on client,
+ * SSL_TRUNC_HMAC_ENABLED on server.)
*
* \param ssl SSL context
* \param truncate Enable or disable (SSL_TRUNC_HMAC_ENABLED or
* SSL_TRUNC_HMAC_DISABLED)
*
- * \return O if successful,
- * POLARSSL_ERR_SSL_BAD_INPUT_DATA if used server-side
+ * \return Always 0.
*/
int ssl_set_truncated_hmac( ssl_context *ssl, int truncate );
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+/**
+ * \brief Enable / Disable 1/n-1 record splitting
+ * (Default: SSL_CBC_RECORD_SPLITTING_ENABLED)
+ *
+ * \note Only affects SSLv3 and TLS 1.0, not higher versions.
+ * Does not affect non-CBC ciphersuites in any version.
+ *
+ * \param ssl SSL context
+ * \param split SSL_CBC_RECORD_SPLITTING_ENABLED or
+ * SSL_CBC_RECORD_SPLITTING_DISABLED
+ */
+void ssl_set_cbc_record_splitting( ssl_context *ssl, char split );
+#endif /* POLARSSL_SSL_CBC_RECORD_SPLITTING */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
/**
* \brief Enable / Disable session tickets
* \param use_tickets Enable or disable (SSL_SESSION_TICKETS_ENABLED or
* SSL_SESSION_TICKETS_DISABLED)
*
- * \return O if successful,
+ * \return 0 if successful,
* or a specific error code (server only).
*/
int ssl_set_session_tickets( ssl_context *ssl, int use_tickets );
void ssl_set_session_ticket_lifetime( ssl_context *ssl, int lifetime );
#endif /* POLARSSL_SSL_SESSION_TICKETS */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
/**
* \brief Enable / Disable renegotiation support for connection when
* initiated by peer
* SSL_RENEGOTIATION_DISABLED)
*/
void ssl_set_renegotiation( ssl_context *ssl, int renegotiation );
+#endif /* POLARSSL_SSL_RENEGOTIATION */
/**
* \brief Prevent or allow legacy renegotiation.
*/
void ssl_legacy_renegotiation( ssl_context *ssl, int allow_legacy );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
/**
- * \brief Enforce server-requested renegotiation.
+ * \brief Enforce requested renegotiation.
* (Default: enforced, max_records = 16)
*
* When we request a renegotiation, the peer can comply or
*/
void ssl_set_renegotiation_enforced( ssl_context *ssl, int max_records );
+/**
+ * \brief Set record counter threshold for periodic renegotiation.
+ * (Default: 2^64 - 256.)
+ *
+ * Renegotiation is automatically triggered when a record
+ * counter (outgoing or ingoing) crosses the defined
+ * threshold. The default value is meant to prevent the
+ * connection from being closed when the counter is about to
+ * reached its maximal value (it is not allowed to wrap).
+ *
+ * Lower values can be used to enforce policies such as "keys
+ * must be refreshed every N packets with cipher X".
+ *
+ * \param ssl SSL context
+ * \param period The threshold value: a big-endian 64-bit number.
+ * Set to 2^64 - 1 to disable periodic renegotiation
+ */
+void ssl_set_renegotiation_period( ssl_context *ssl,
+ const unsigned char period[8] );
+#endif /* POLARSSL_SSL_RENEGOTIATION */
+
/**
* \brief Return the number of data bytes available to read
*
*
* \param ssl SSL context
*
- * \return 0 if successful, or a combination of:
- * BADCERT_EXPIRED
- * BADCERT_REVOKED
- * BADCERT_CN_MISMATCH
- * BADCERT_NOT_TRUSTED
+ * \return 0 if successful,
+ * -1 if result is not available (eg because the handshake was
+ * aborted too early), or
+ * a combination of BADCERT_xxx and BADCRL_xxx flags, see
+ * x509.h
*/
int ssl_get_verify_result( const ssl_context *ssl );
const x509_crt *ssl_get_peer_cert( const ssl_context *ssl );
#endif /* POLARSSL_X509_CRT_PARSE_C */
+#if defined(POLARSSL_SSL_CLI_C)
/**
* \brief Save session in order to resume it later (client-side only)
* Session data is copied to presented session structure.
* \sa ssl_set_session()
*/
int ssl_get_session( const ssl_context *ssl, ssl_session *session );
+#endif /* POLARSSL_SSL_CLI_C */
/**
* \brief Perform the SSL handshake
*/
int ssl_handshake_step( ssl_context *ssl );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
/**
* \brief Initiate an SSL renegotiation on the running connection.
* Client: perform the renegotiation right now.
* \return 0 if successful, or any ssl_handshake() return value.
*/
int ssl_renegotiate( ssl_context *ssl );
+#endif /* POLARSSL_SSL_RENEGOTIATION */
/**
* \brief Read at most 'len' application data bytes
* \note When this function returns POLARSSL_ERR_NET_WANT_WRITE,
* it must be called later with the *same* arguments,
* until it returns a positive value.
+ *
+ * \note This function may write less than the number of bytes
+ * requested if len is greater than the maximum record length.
+ * For arbitrary-sized messages, it should be called in a loop.
*/
int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len );
*/
int ssl_check_cert_usage( const x509_crt *cert,
const ssl_ciphersuite_t *ciphersuite,
- int cert_endpoint );
+ int cert_endpoint,
+ int *flags );
#endif /* POLARSSL_X509_CRT_PARSE_C */
/* constant-time buffer comparison */
*
* \brief SSL session cache implementation
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* \file ssl_ciphersuites.h
*
- * \brief SSL Ciphersuites for PolarSSL
+ * \brief SSL Ciphersuites for mbed TLS
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE /**< TLS 1.2 */
#define TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF /**< TLS 1.2 */
-/* Reminder: update _ssl_premaster_secret when adding a new key exchange */
+/* Reminder: update _ssl_premaster_secret when adding a new key exchange.
+ * Reminder: update POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED below.
+ */
typedef enum {
POLARSSL_KEY_EXCHANGE_NONE = 0,
POLARSSL_KEY_EXCHANGE_RSA,
POLARSSL_KEY_EXCHANGE_ECDH_ECDSA,
} key_exchange_type_t;
+#if defined(POLARSSL_KEY_EXCHANGE_RSA_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
+ defined(POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
+#define POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED
+#endif
+
typedef struct _ssl_ciphersuite_t ssl_ciphersuite_t;
#define POLARSSL_CIPHERSUITE_WEAK 0x01 /**< Weak ciphersuite flag */
*
* \brief Threading abstraction layer
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* \brief Portable interface to the CPU cycle counter
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* \brief Setup an alarm clock
*
* \param seconds delay before the "alarmed" flag is set
+ *
+ * \warning Only one alarm at a time is supported. In a threaded
+ * context, this means one for the whole process, not one per
+ * thread.
*/
void set_alarm( int seconds );
*
* \brief Run-time version information
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
/*
* This set of compile-time defines and run-time variables can be used to
- * determine the version number of the PolarSSL library used.
+ * determine the version number of the mbed TLS library used.
*/
#ifndef POLARSSL_VERSION_H
#define POLARSSL_VERSION_H
*/
#define POLARSSL_VERSION_MAJOR 1
#define POLARSSL_VERSION_MINOR 3
-#define POLARSSL_VERSION_PATCH 9
+#define POLARSSL_VERSION_PATCH 12
/**
* The single version number has the following structure:
* MMNNPP00
* Major version | Minor version | Patch version
*/
-#define POLARSSL_VERSION_NUMBER 0x01030900
-#define POLARSSL_VERSION_STRING "1.3.9"
-#define POLARSSL_VERSION_STRING_FULL "PolarSSL 1.3.9"
+#define POLARSSL_VERSION_NUMBER 0x01030C00
+#define POLARSSL_VERSION_STRING "1.3.12"
+#define POLARSSL_VERSION_STRING_FULL "mbed TLS 1.3.12"
#if defined(POLARSSL_VERSION_C)
void version_get_string( char *string );
/**
- * Get the full version string ("PolarSSL x.y.z").
+ * Get the full version string ("mbed TLS x.y.z").
*
- * \param string The string that will receive the value. The PolarSSL version
+ * \param string The string that will receive the value. The mbed TLS version
* string will use 18 bytes AT MOST including a terminating
* null byte.
* (So the buffer should be at least 18 bytes to receive this
/**
* \brief Check if support for a feature was compiled into this
- * PolarSSL binary. This allows you to see at runtime if the
+ * mbed TLS binary. This allows you to see at runtime if the
* library was for instance compiled with or without
* Multi-threading support.
*
* Note: only checks against defines in the sections "System
- * support", "PolarSSL modules" and "PolarSSL feature
+ * support", "mbed TLS modules" and "mbed TLS feature
* support" in config.h
*
* \param feature The string for the define to check (e.g. "POLARSSL_AES_C")
*
* \brief X.509 generic defines and structures
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* \{
*/
+#if !defined(POLARSSL_X509_MAX_INTERMEDIATE_CA)
+/**
+ * Maximum number of intermediate CAs in a verification chain.
+ * That is, maximum length of the chain, excluding the end-entity certificate
+ * and the trusted root certificate.
+ *
+ * Set this to a low value to prevent an adversary from making you waste
+ * resources verifying an overlong certificate chain.
+ */
+#define POLARSSL_X509_MAX_INTERMEDIATE_CA 8
+#endif
+
/**
* \name X509 Error codes
* \{
* \name X509 Verify codes
* \{
*/
+/* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
#define BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
#define BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
#define BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
#define BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
-#define BADCRL_NOT_TRUSTED 0x10 /**< CRL is not correctly signed by the trusted CA. */
-#define BADCRL_EXPIRED 0x20 /**< CRL is expired. */
+#define BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
+#define BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
#define BADCERT_MISSING 0x40 /**< Certificate was missing. */
#define BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
#define BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
#define BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
#define BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
+#define BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
+#define BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
+#define BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
/* \} name */
/* \} addtogroup x509_module */
*/
int x509_serial_gets( char *buf, size_t size, const x509_buf *serial );
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
+#if defined(POLARSSL_DEPRECATED_WARNING)
+#define DEPRECATED __attribute__((deprecated))
+#else
+#define DEPRECATED
+#endif
/**
* \brief Give an known OID, return its descriptive string.
- * (Deprecated. Use oid_get_extended_key_usage() instead.)
- * Warning: only works for extended_key_usage OIDs!
+ *
+ * \deprecated Use oid_get_extended_key_usage() instead.
+ *
+ * \warning Only works for extended_key_usage OIDs!
*
* \param oid buffer containing the oid
*
* \return Return a string if the OID is known,
* or NULL otherwise.
*/
-const char *x509_oid_get_description( x509_buf *oid );
+const char *x509_oid_get_description( x509_buf *oid ) DEPRECATED;
/**
* \brief Give an OID, return a string version of its OID number.
- * (Deprecated. Use oid_get_numeric_string() instead)
+ *
+ * \deprecated Use oid_get_numeric_string() instead.
*
* \param buf Buffer to write to
* \param size Maximum size of buffer
* \return Length of the string written (excluding final NULL) or
* POLARSSL_ERR_OID_BUF_TO_SMALL in case of error
*/
-int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid );
+int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid ) DEPRECATED;
+#undef DEPRECATED
+#endif /* POLARSSL_DEPRECATED_REMOVED */
/**
* \brief Check a given x509_time against the system time and check
x509_buf *serial );
int x509_get_ext( unsigned char **p, const unsigned char *end,
x509_buf *ext, int tag );
-int x509_load_file( const char *path, unsigned char **buf, size_t *n );
int x509_sig_alg_gets( char *buf, size_t size, const x509_buf *sig_oid,
pk_type_t pk_alg, md_type_t md_alg,
const void *sig_opts );
*
* \brief X.509 certificate revocation list parsing
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
x509_crl;
/**
- * \brief Parse one or more CRLs and add them
- * to the chained list
+ * \brief Parse a DER-encoded CRL and append it to the chained list
+ *
+ * \param chain points to the start of the chain
+ * \param buf buffer holding the CRL data in DER format
+ * \param buflen size of the buffer
+ *
+ * \return 0 if successful, or a specific X509 or PEM error code
+ */
+int x509_crl_parse_der( x509_crl *chain,
+ const unsigned char *buf, size_t buflen );
+/**
+ * \brief Parse one or more CRLs and append them to the chained list
+ *
+ * \note Mutliple CRLs are accepted only if using PEM format
*
* \param chain points to the start of the chain
- * \param buf buffer holding the CRL data
+ * \param buf buffer holding the CRL data in PEM or DER format
* \param buflen size of the buffer
*
* \return 0 if successful, or a specific X509 or PEM error code
#if defined(POLARSSL_FS_IO)
/**
- * \brief Load one or more CRLs and add them
- * to the chained list
+ * \brief Load one or more CRLs and append them to the chained list
+ *
+ * \note Mutliple CRLs are accepted only if using PEM format
*
* \param chain points to the start of the chain
- * \param path filename to read the CRLs from
+ * \param path filename to read the CRLs from (in PEM or DER encoding)
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
*
* \brief X.509 certificate parsing and writing
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
#include "x509.h"
-
#include "x509_crl.h"
/**
int x509_crt_info( char *buf, size_t size, const char *prefix,
const x509_crt *crt );
+/**
+ * \brief Returns an informational string about the
+ * verification status of a certificate.
+ *
+ * \param buf Buffer to write to
+ * \param size Maximum size of buffer
+ * \param prefix A line prefix
+ * \param flags Verification flags created by x509_crt_verify()
+ *
+ * \return The amount of data written to the buffer, or -1 in
+ * case of an error.
+ */
+int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
+ int flags );
+
/**
* \brief Verify the certificate signature
*
* are also returned to the application. The function should
* return 0 for anything but a fatal error.
*
+ * \note In case verification failed, the results can be displayed
+ * using \c x509_crt_verify_info()
+ *
* \param crt a certificate to be verified
* \param trust_ca the trusted CA chain
* \param ca_crl the CRL chain for trusted CA's
* \param p_vrfy verification parameter
*
* \return 0 if successful or POLARSSL_ERR_X509_SIG_VERIFY_FAILED,
- * in which case *flags will have one or more of
- * the following values set:
- * BADCERT_EXPIRED --
- * BADCERT_REVOKED --
- * BADCERT_CN_MISMATCH --
- * BADCERT_NOT_TRUSTED
+ * in which case *flags will have one or more BADCERT_XXX or
+ * BADCRL_XXX flags set,
* or another error in case of a fatal error encountered
* during the verification process.
*/
* \brief Set the issuer name for a Certificate
* Issuer names should contain a comma-separated list
* of OID types and values:
- * e.g. "C=NL,O=Offspark,CN=PolarSSL CA"
+ * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
*
* \param ctx CRT context to use
* \param issuer_name issuer name to set
* \brief Set the subject name for a Certificate
* Subject names should contain a comma-separated list
* of OID types and values:
- * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
+ * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
*
* \param ctx CRT context to use
* \param subject_name subject name to set
*
* \brief X.509 certificate signing request parsing and writing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* \brief Set the subject name for a CSR
* Subject names should contain a comma-separated list
* of OID types and values:
- * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1"
+ * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
*
* \param ctx CSR context to use
* \param subject_name subject name to set
*
* \brief XTEA block cipher (32-bit)
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include POLARSSL_CONFIG_FILE
#endif
-#include <string.h>
+#include <stddef.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
--- /dev/null
+*.o
+libpolarssl.*
+libmbedtls.*
+*.sln
+*.vcxproj
+Makefile.am
\ No newline at end of file
--- /dev/null
+option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
+option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
+option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
+
+set(src
+ aes.c
+ aesni.c
+ arc4.c
+ asn1parse.c
+ asn1write.c
+ base64.c
+ bignum.c
+ blowfish.c
+ camellia.c
+ ccm.c
+ certs.c
+ cipher.c
+ cipher_wrap.c
+ ctr_drbg.c
+ debug.c
+ des.c
+ dhm.c
+ ecp.c
+ ecp_curves.c
+ ecdh.c
+ ecdsa.c
+ entropy.c
+ entropy_poll.c
+ error.c
+ gcm.c
+ havege.c
+ hmac_drbg.c
+ md.c
+ md_wrap.c
+ md2.c
+ md4.c
+ md5.c
+ memory_buffer_alloc.c
+ net.c
+ oid.c
+ padlock.c
+ pbkdf2.c
+ pem.c
+ pkcs5.c
+ pkcs11.c
+ pkcs12.c
+ pk.c
+ pk_wrap.c
+ pkparse.c
+ pkwrite.c
+ platform.c
+ ripemd160.c
+ rsa.c
+ sha1.c
+ sha256.c
+ sha512.c
+ ssl_cache.c
+ ssl_ciphersuites.c
+ ssl_cli.c
+ ssl_srv.c
+ ssl_tls.c
+ threading.c
+ timing.c
+ version.c
+ version_features.c
+ x509.c
+ x509_crt.c
+ x509_crl.c
+ x509_csr.c
+ x509_create.c
+ x509write_crt.c
+ x509write_csr.c
+ xtea.c
+)
+
+if(WIN32)
+set(libs ws2_32)
+endif(WIN32)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
+endif(CMAKE_COMPILER_IS_GNUCC)
+
+if(CMAKE_COMPILER_IS_CLANG)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
+endif(CMAKE_COMPILER_IS_CLANG)
+
+if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
+ message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
+endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
+
+if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
+ # if we build both static an shared, then let
+ # tests and programs link to the shared lib target
+ set(mbedtls_static_target "mbedtls_static")
+elseif(USE_STATIC_MBEDTLS_LIBRARY)
+ set(mbedtls_static_target "mbedtls")
+endif()
+
+if(USE_STATIC_MBEDTLS_LIBRARY)
+ add_library(${mbedtls_static_target} STATIC ${src})
+ set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
+ target_link_libraries(${mbedtls_static_target} ${libs})
+
+ if(ZLIB_FOUND)
+ target_link_libraries(${mbedtls_static_target} ${ZLIB_LIBRARIES})
+ endif(ZLIB_FOUND)
+
+ if(LINK_WITH_PTHREAD)
+ target_link_libraries(${mbedtls_static_target} pthread)
+ endif()
+
+ install(TARGETS ${mbedtls_static_target}
+ DESTINATION ${LIB_INSTALL_DIR}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+endif()
+
+if(USE_SHARED_MBEDTLS_LIBRARY)
+ add_library(mbedtls SHARED ${src})
+ set_target_properties(mbedtls PROPERTIES VERSION 1.3.12 SOVERSION 9)
+
+ target_link_libraries(mbedtls ${libs})
+
+ if(ZLIB_FOUND)
+ target_link_libraries(mbedtls ${ZLIB_LIBRARIES})
+ endif(ZLIB_FOUND)
+
+ if(LINK_WITH_PTHREAD)
+ target_link_libraries(mbedtls pthread)
+ endif()
+
+ install(TARGETS mbedtls
+ DESTINATION ${LIB_INSTALL_DIR}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+endif(USE_SHARED_MBEDTLS_LIBRARY)
+
+if(UNIX)
+ add_custom_target(polarssl
+ DEPENDS mbedtls # TODO: and mbedtls_static is shared is defined
+ COMMAND ${CMAKE_SOURCE_DIR}/scripts/polarssl_symlinks.sh ${CMAKE_BINARY_DIR}/library
+ )
+
+ if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
+ add_dependencies(polarssl mbedtls_static)
+ endif()
+
+ add_custom_target(polarssl-clean
+ COMMAND make clean
+ COMMAND rm -f ${CMAKE_BINARY_DIR}/library/libpolarssl.*
+ )
+
+ add_custom_target(polarssl-install
+ COMMAND make install
+ COMMAND ${CMAKE_SOURCE_DIR}/scripts/polarssl_symlinks.sh ${DESTDIR}/${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}
+ )
+endif(UNIX)
/*
* FIPS-197 compliant AES implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_AES_C)
+#include <string.h>
+
#include "polarssl/aes.h"
#if defined(POLARSSL_PADLOCK_C)
#include "polarssl/padlock.h"
#include "polarssl/aesni.h"
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
#if !defined(POLARSSL_AES_ALT)
#endif
#ifndef PUT_UINT32_LE
-#define PUT_UINT32_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( (n) ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
+#define PUT_UINT32_LE(n,b,i) \
+{ \
+ (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
+ (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
+ (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
+ (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
}
#endif
/*
* AES-CFB8 buffer encryption/decryption
*/
-#include <stdio.h>
int aes_crypt_cfb8( aes_context *ctx,
int mode,
size_t length,
#endif /* !POLARSSL_AES_ALT */
#if defined(POLARSSL_SELF_TEST)
-
-#include <stdio.h>
-
/*
* AES test vectors from:
*
/*
* AES-NI support functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_AESNI_C)
#include "polarssl/aesni.h"
-#include <stdio.h>
+
+#include <string.h>
#if defined(POLARSSL_HAVE_X86_64)
/*
* An implementation of the ARCFOUR algorithm
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/arc4.h"
+#include <string.h>
+
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
#if !defined(POLARSSL_ARC4_ALT)
#endif /* !POLARSSL_ARC4_ALT */
#if defined(POLARSSL_SELF_TEST)
-
-#include <string.h>
-#include <stdio.h>
-
/*
* ARC4 tests vectors as posted by Eric Rescorla in sep. 1994:
*
/*
* Generic ASN.1 parsing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1.h"
+#include <string.h>
+
#if defined(POLARSSL_BIGNUM_C)
#include "polarssl/bignum.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <string.h>
-#include <stdlib.h>
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
if( ( end - *p ) < 3 )
return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
- *len = ( (*p)[1] << 8 ) | (*p)[2];
+ *len = ( (size_t)(*p)[1] << 8 ) | (*p)[2];
(*p) += 3;
break;
if( ( end - *p ) < 4 )
return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
- *len = ( (*p)[1] << 16 ) | ( (*p)[2] << 8 ) | (*p)[3];
+ *len = ( (size_t)(*p)[1] << 16 ) |
+ ( (size_t)(*p)[2] << 8 ) | (*p)[3];
(*p) += 4;
break;
if( ( end - *p ) < 5 )
return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
- *len = ( (*p)[1] << 24 ) | ( (*p)[2] << 16 ) | ( (*p)[3] << 8 ) |
- (*p)[4];
+ *len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) |
+ ( (size_t)(*p)[3] << 8 ) | (*p)[4];
(*p) += 5;
break;
/* Allocate and assign next pointer */
if( *p < end )
{
- cur->next = (asn1_sequence *) polarssl_malloc(
- sizeof( asn1_sequence ) );
+ cur->next = polarssl_malloc( sizeof( asn1_sequence ) );
if( cur->next == NULL )
return( POLARSSL_ERR_ASN1_MALLOC_FAILED );
+ memset( cur->next, 0, sizeof( asn1_sequence ) );
+
cur = cur->next;
}
}
/*
* ASN.1 buffer writing functionality
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1write.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
return( NULL );
}
+ memcpy( cur->oid.p, oid, oid_len );
+
cur->val.len = val_len;
cur->val.p = polarssl_malloc( val_len );
if( cur->val.p == NULL )
return( NULL );
}
- memcpy( cur->oid.p, oid, oid_len );
-
cur->next = *head;
*head = cur;
}
/*
* RFC 1521 base64 encoding/decoding
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <inttypes.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
+#include <string.h>
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
static const unsigned char base64_enc_map[64] =
{
unsigned char *p;
if( slen == 0 )
+ {
+ *dlen = 0;
return( 0 );
+ }
n = ( slen << 3 ) / 6;
#if defined(POLARSSL_SELF_TEST)
-#include <string.h>
-#include <stdio.h>
-
static const unsigned char base64_test_dec[64] =
{
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
/*
* Multi-precision integer library
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/bignum.h"
#include "polarssl/bn_mul.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
+#include <stdlib.h>
#define polarssl_printf printf
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
if( X->n < nblimbs )
{
- if( ( p = (t_uint *) polarssl_malloc( nblimbs * ciL ) ) == NULL )
+ if( ( p = polarssl_malloc( nblimbs * ciL ) ) == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
memset( p, 0, nblimbs * ciL );
if( i < nblimbs )
i = nblimbs;
- if( ( p = (t_uint *) polarssl_malloc( i * ciL ) ) == NULL )
+ if( ( p = polarssl_malloc( i * ciL ) ) == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
memset( p, 0, i * ciL );
int ret = 0;
size_t i;
- /* make sure assign is 0 or 1 */
- assign = ( assign != 0 );
+ /* make sure assign is 0 or 1 in a time-constant manner */
+ assign = (assign | (unsigned char)-assign) >> 7;
MPI_CHK( mpi_grow( X, Y->n ) );
if( X == Y )
return( 0 );
- /* make sure swap is 0 or 1 */
- swap = ( swap != 0 );
+ /* make sure swap is 0 or 1 in a time-constant manner */
+ swap = (swap | (unsigned char)-swap) >> 7;
MPI_CHK( mpi_grow( X, Y->n ) );
MPI_CHK( mpi_grow( Y, X->n ) );
{
size_t i, j;
+ if( X->n == 0 )
+ return( 0 );
+
for( i = X->n - 1; i > 0; i-- )
if( X->p[i] != 0 )
break;
Z.p[i - t - 1] = ~0;
else
{
- /*
- * The version of Clang shipped by Apple with Mavericks around
- * 2014-03 can't handle 128-bit division properly. Disable
- * 128-bits division for this version. Let's be optimistic and
- * assume it'll be fixed in the next minor version (next
- * patchlevel is probably a bit too optimistic).
- */
-#if defined(POLARSSL_HAVE_UDBL) && \
- ! ( defined(__x86_64__) && defined(__APPLE__) && \
- defined(__clang_major__) && __clang_major__ == 5 && \
- defined(__clang_minor__) && __clang_minor__ == 0 )
+#if defined(POLARSSL_HAVE_UDBL)
t_udbl r;
r = (t_udbl) X.p[i] << biL;
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng )
{
- int ret;
- size_t i, j, n, s;
+ int ret, count;
+ size_t i, j, k, n, s;
mpi W, R, T, A, RR;
mpi_init( &W ); mpi_init( &R ); mpi_init( &T ); mpi_init( &A );
/*
* pick a random A, 1 < A < |X| - 1
*/
- MPI_CHK( mpi_fill_random( &A, X->n * ciL, f_rng, p_rng ) );
- if( mpi_cmp_mpi( &A, &W ) >= 0 )
- {
- j = mpi_msb( &A ) - mpi_msb( &W );
- MPI_CHK( mpi_shift_r( &A, j + 1 ) );
- }
- A.p[0] |= 3;
+ count = 0;
+ do {
+ MPI_CHK( mpi_fill_random( &A, X->n * ciL, f_rng, p_rng ) );
+
+ j = mpi_msb( &A );
+ k = mpi_msb( &W );
+ if (j > k) {
+ MPI_CHK( mpi_shift_r( &A, j - k ) );
+ }
+
+ if (count++ > 30) {
+ return POLARSSL_ERR_MPI_NOT_ACCEPTABLE;
+ }
+
+ } while ( (mpi_cmp_mpi( &A, &W ) >= 0) ||
+ (mpi_cmp_int( &A, 1 ) <= 0) );
/*
* A = A^R mod |X|
MPI_CHK( mpi_fill_random( X, n * ciL, f_rng, p_rng ) );
k = mpi_msb( X );
- if( k < nbits ) MPI_CHK( mpi_shift_l( X, nbits - k ) );
- if( k > nbits ) MPI_CHK( mpi_shift_r( X, k - nbits ) );
+ if( k > nbits ) MPI_CHK( mpi_shift_r( X, k - nbits + 1 ) );
+
+ mpi_set_bit( X, nbits-1, 1 );
- X->p[0] |= 3;
+ X->p[0] |= 1;
if( dh_flag == 0 )
{
* is X = 2 mod 3 (which is equivalent to Y = 2 mod 3).
* Make sure it is satisfied, while keeping X = 3 mod 4
*/
+
+ X->p[0] |= 2;
+
MPI_CHK( mpi_mod_int( &r, X, 3 ) );
if( r == 0 )
MPI_CHK( mpi_add_int( X, X, 8 ) );
/*
* Blowfish implementation
*
- * Copyright (C) 2012-2014, Brainspark B.V.
+ * Copyright (C) 2012-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/blowfish.h"
+#include <string.h>
+
#if !defined(POLARSSL_BLOWFISH_ALT)
/* Implementation that should never be optimized out by the compiler */
/*
* Camellia implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/camellia.h"
+#if defined(POLARSSL_SELF_TEST)
+#include <string.h>
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
#if !defined(POLARSSL_CAMELLIA_ALT)
I0 = x[0] ^ k[0];
I1 = x[1] ^ k[1];
- I0 = (SBOX1((I0 >> 24) & 0xFF) << 24) |
- (SBOX2((I0 >> 16) & 0xFF) << 16) |
- (SBOX3((I0 >> 8) & 0xFF) << 8) |
- (SBOX4((I0 ) & 0xFF) );
- I1 = (SBOX2((I1 >> 24) & 0xFF) << 24) |
- (SBOX3((I1 >> 16) & 0xFF) << 16) |
- (SBOX4((I1 >> 8) & 0xFF) << 8) |
- (SBOX1((I1 ) & 0xFF) );
+ I0 = ((uint32_t) SBOX1((I0 >> 24) & 0xFF) << 24) |
+ ((uint32_t) SBOX2((I0 >> 16) & 0xFF) << 16) |
+ ((uint32_t) SBOX3((I0 >> 8) & 0xFF) << 8) |
+ ((uint32_t) SBOX4((I0 ) & 0xFF) );
+ I1 = ((uint32_t) SBOX2((I1 >> 24) & 0xFF) << 24) |
+ ((uint32_t) SBOX3((I1 >> 16) & 0xFF) << 16) |
+ ((uint32_t) SBOX4((I1 >> 8) & 0xFF) << 8) |
+ ((uint32_t) SBOX1((I1 ) & 0xFF) );
I0 ^= (I1 << 8) | (I1 >> 24);
I1 ^= (I0 << 16) | (I0 >> 16);
camellia_init( &cty );
/* Also checks keysize */
- if( ( ret = camellia_setkey_enc( &cty, key, keysize ) ) )
+ if( ( ret = camellia_setkey_enc( &cty, key, keysize ) ) != 0 )
goto exit;
ctx->nr = cty.nr;
#if defined(POLARSSL_SELF_TEST)
-#include <stdio.h>
-
/*
* Camellia test vectors from:
*
/*
* NIST SP800-38C compliant CCM implementation
*
- * Copyright (C) 2014, Brainspark B.V.
+ * Copyright (C) 2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ccm.h"
+#include <string.h>
+
+#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#include <stdio.h>
+#define polarssl_printf printf
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
+
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
if( cipher_info->block_size != 16 )
return( POLARSSL_ERR_CCM_BAD_INPUT );
+ cipher_free( &ctx->cipher_ctx );
+
if( ( ret = cipher_init_ctx( &ctx->cipher_ctx, cipher_info ) ) != 0 )
return( ret );
#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
-
-#if defined(POLARSSL_PLATFORM_C)
-#include "polarssl/platform.h"
-#else
-#include <stdio.h>
-#define polarssl_printf printf
-#endif
-
/*
* Examples 1 to 3 from SP800-38C Appendix C
*/
/*
* X.509 test certificates
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* \file cipher.c
*
- * \brief Generic cipher wrapper for PolarSSL
+ * \brief Generic cipher wrapper for mbed TLS
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/cipher.h"
#include "polarssl/cipher_wrap.h"
+#include <stdlib.h>
+#include <string.h>
+
#if defined(POLARSSL_GCM_C)
#include "polarssl/gcm.h"
#endif
#include "polarssl/ccm.h"
#endif
-#include <stdlib.h>
-
#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER)
#define POLARSSL_CIPHER_MODE_STREAM
#endif
return( 0 );
}
-/* Deprecated, redirects to cipher_free() */
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
int cipher_free_ctx( cipher_context_t *ctx )
{
cipher_free( ctx );
return( 0 );
}
+#endif
int cipher_setkey( cipher_context_t *ctx, const unsigned char *key,
int key_length, const operation_t operation )
/**
* \file cipher_wrap.c
*
- * \brief Generic cipher wrapper for PolarSSL
+ * \brief Generic cipher wrapper for mbed TLS
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ccm.h"
#endif
+#if defined(POLARSSL_CIPHER_NULL_CIPHER)
+#include <string.h>
+#endif
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
#if defined(POLARSSL_GCM_C)
/* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void )
return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
}
+#if defined(POLARSSL_CIPHER_MODE_CBC)
static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CBC)
return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
}
+#endif /* POLARSSL_CIPHER_MODE_CBC */
+#if defined(POLARSSL_CIPHER_MODE_CFB)
static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
size_t length, size_t *iv_off, unsigned char *iv,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CFB)
return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
input, output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv_off);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CFB */
}
+#endif /* POLARSSL_CIPHER_MODE_CFB */
+#if defined(POLARSSL_CIPHER_MODE_CTR)
static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
unsigned char *nonce_counter, unsigned char *stream_block,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CTR)
return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
stream_block, input, output );
-#else
- ((void) ctx);
- ((void) length);
- ((void) nc_off);
- ((void) nonce_counter);
- ((void) stream_block);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CTR */
}
+#endif /* POLARSSL_CIPHER_MODE_CTR */
static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
static void * aes_ctx_alloc( void )
{
- aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
+ aes_context *aes = polarssl_malloc( sizeof( aes_context ) );
if( aes == NULL )
return( NULL );
polarssl_free( ctx );
}
-const cipher_base_t aes_info = {
+static const cipher_base_t aes_info = {
POLARSSL_CIPHER_ID_AES,
aes_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
aes_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
aes_crypt_cfb128_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
aes_crypt_ctr_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
aes_setkey_enc_wrap,
aes_setkey_dec_wrap,
aes_ctx_alloc,
aes_ctx_free
};
-const cipher_info_t aes_128_ecb_info = {
+static const cipher_info_t aes_128_ecb_info = {
POLARSSL_CIPHER_AES_128_ECB,
POLARSSL_MODE_ECB,
128,
&aes_info
};
-const cipher_info_t aes_192_ecb_info = {
+static const cipher_info_t aes_192_ecb_info = {
POLARSSL_CIPHER_AES_192_ECB,
POLARSSL_MODE_ECB,
192,
&aes_info
};
-const cipher_info_t aes_256_ecb_info = {
+static const cipher_info_t aes_256_ecb_info = {
POLARSSL_CIPHER_AES_256_ECB,
POLARSSL_MODE_ECB,
256,
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t aes_128_cbc_info = {
+static const cipher_info_t aes_128_cbc_info = {
POLARSSL_CIPHER_AES_128_CBC,
POLARSSL_MODE_CBC,
128,
&aes_info
};
-const cipher_info_t aes_192_cbc_info = {
+static const cipher_info_t aes_192_cbc_info = {
POLARSSL_CIPHER_AES_192_CBC,
POLARSSL_MODE_CBC,
192,
&aes_info
};
-const cipher_info_t aes_256_cbc_info = {
+static const cipher_info_t aes_256_cbc_info = {
POLARSSL_CIPHER_AES_256_CBC,
POLARSSL_MODE_CBC,
256,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
-const cipher_info_t aes_128_cfb128_info = {
+static const cipher_info_t aes_128_cfb128_info = {
POLARSSL_CIPHER_AES_128_CFB128,
POLARSSL_MODE_CFB,
128,
&aes_info
};
-const cipher_info_t aes_192_cfb128_info = {
+static const cipher_info_t aes_192_cfb128_info = {
POLARSSL_CIPHER_AES_192_CFB128,
POLARSSL_MODE_CFB,
192,
&aes_info
};
-const cipher_info_t aes_256_cfb128_info = {
+static const cipher_info_t aes_256_cfb128_info = {
POLARSSL_CIPHER_AES_256_CFB128,
POLARSSL_MODE_CFB,
256,
#endif /* POLARSSL_CIPHER_MODE_CFB */
#if defined(POLARSSL_CIPHER_MODE_CTR)
-const cipher_info_t aes_128_ctr_info = {
+static const cipher_info_t aes_128_ctr_info = {
POLARSSL_CIPHER_AES_128_CTR,
POLARSSL_MODE_CTR,
128,
&aes_info
};
-const cipher_info_t aes_192_ctr_info = {
+static const cipher_info_t aes_192_ctr_info = {
POLARSSL_CIPHER_AES_192_CTR,
POLARSSL_MODE_CTR,
192,
&aes_info
};
-const cipher_info_t aes_256_ctr_info = {
+static const cipher_info_t aes_256_ctr_info = {
POLARSSL_CIPHER_AES_256_CTR,
POLARSSL_MODE_CTR,
256,
key, key_length );
}
-const cipher_base_t gcm_aes_info = {
+static const cipher_base_t gcm_aes_info = {
POLARSSL_CIPHER_ID_AES,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
gcm_aes_setkey_wrap,
gcm_aes_setkey_wrap,
gcm_ctx_alloc,
gcm_ctx_free,
};
-const cipher_info_t aes_128_gcm_info = {
+static const cipher_info_t aes_128_gcm_info = {
POLARSSL_CIPHER_AES_128_GCM,
POLARSSL_MODE_GCM,
128,
&gcm_aes_info
};
-const cipher_info_t aes_192_gcm_info = {
+static const cipher_info_t aes_192_gcm_info = {
POLARSSL_CIPHER_AES_192_GCM,
POLARSSL_MODE_GCM,
192,
&gcm_aes_info
};
-const cipher_info_t aes_256_gcm_info = {
+static const cipher_info_t aes_256_gcm_info = {
POLARSSL_CIPHER_AES_256_GCM,
POLARSSL_MODE_GCM,
256,
key, key_length );
}
-const cipher_base_t ccm_aes_info = {
+static const cipher_base_t ccm_aes_info = {
POLARSSL_CIPHER_ID_AES,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
ccm_aes_setkey_wrap,
ccm_aes_setkey_wrap,
ccm_ctx_alloc,
ccm_ctx_free,
};
-const cipher_info_t aes_128_ccm_info = {
+static const cipher_info_t aes_128_ccm_info = {
POLARSSL_CIPHER_AES_128_CCM,
POLARSSL_MODE_CCM,
128,
&ccm_aes_info
};
-const cipher_info_t aes_192_ccm_info = {
+static const cipher_info_t aes_192_ccm_info = {
POLARSSL_CIPHER_AES_192_CCM,
POLARSSL_MODE_CCM,
192,
&ccm_aes_info
};
-const cipher_info_t aes_256_ccm_info = {
+static const cipher_info_t aes_256_ccm_info = {
POLARSSL_CIPHER_AES_256_CCM,
POLARSSL_MODE_CCM,
256,
output );
}
+#if defined(POLARSSL_CIPHER_MODE_CBC)
static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
size_t length, unsigned char *iv,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CBC)
return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
input, output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
}
+#endif /* POLARSSL_CIPHER_MODE_CBC */
+#if defined(POLARSSL_CIPHER_MODE_CFB)
static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
size_t length, size_t *iv_off, unsigned char *iv,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CFB)
return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
iv_off, iv, input, output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv_off);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CFB */
}
+#endif /* POLARSSL_CIPHER_MODE_CFB */
+#if defined(POLARSSL_CIPHER_MODE_CTR)
static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
unsigned char *nonce_counter, unsigned char *stream_block,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CTR)
return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
nonce_counter, stream_block, input, output );
-#else
- ((void) ctx);
- ((void) length);
- ((void) nc_off);
- ((void) nonce_counter);
- ((void) stream_block);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CTR */
}
+#endif /* POLARSSL_CIPHER_MODE_CTR */
static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
static void * camellia_ctx_alloc( void )
{
camellia_context *ctx;
- ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
+ ctx = polarssl_malloc( sizeof( camellia_context ) );
if( ctx == NULL )
return( NULL );
polarssl_free( ctx );
}
-const cipher_base_t camellia_info = {
+static const cipher_base_t camellia_info = {
POLARSSL_CIPHER_ID_CAMELLIA,
camellia_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
camellia_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
camellia_crypt_cfb128_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
camellia_crypt_ctr_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
camellia_setkey_enc_wrap,
camellia_setkey_dec_wrap,
camellia_ctx_alloc,
camellia_ctx_free
};
-const cipher_info_t camellia_128_ecb_info = {
+static const cipher_info_t camellia_128_ecb_info = {
POLARSSL_CIPHER_CAMELLIA_128_ECB,
POLARSSL_MODE_ECB,
128,
&camellia_info
};
-const cipher_info_t camellia_192_ecb_info = {
+static const cipher_info_t camellia_192_ecb_info = {
POLARSSL_CIPHER_CAMELLIA_192_ECB,
POLARSSL_MODE_ECB,
192,
&camellia_info
};
-const cipher_info_t camellia_256_ecb_info = {
+static const cipher_info_t camellia_256_ecb_info = {
POLARSSL_CIPHER_CAMELLIA_256_ECB,
POLARSSL_MODE_ECB,
256,
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t camellia_128_cbc_info = {
+static const cipher_info_t camellia_128_cbc_info = {
POLARSSL_CIPHER_CAMELLIA_128_CBC,
POLARSSL_MODE_CBC,
128,
&camellia_info
};
-const cipher_info_t camellia_192_cbc_info = {
+static const cipher_info_t camellia_192_cbc_info = {
POLARSSL_CIPHER_CAMELLIA_192_CBC,
POLARSSL_MODE_CBC,
192,
&camellia_info
};
-const cipher_info_t camellia_256_cbc_info = {
+static const cipher_info_t camellia_256_cbc_info = {
POLARSSL_CIPHER_CAMELLIA_256_CBC,
POLARSSL_MODE_CBC,
256,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
-const cipher_info_t camellia_128_cfb128_info = {
+static const cipher_info_t camellia_128_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_128_CFB128,
POLARSSL_MODE_CFB,
128,
&camellia_info
};
-const cipher_info_t camellia_192_cfb128_info = {
+static const cipher_info_t camellia_192_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_192_CFB128,
POLARSSL_MODE_CFB,
192,
&camellia_info
};
-const cipher_info_t camellia_256_cfb128_info = {
+static const cipher_info_t camellia_256_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_256_CFB128,
POLARSSL_MODE_CFB,
256,
#endif /* POLARSSL_CIPHER_MODE_CFB */
#if defined(POLARSSL_CIPHER_MODE_CTR)
-const cipher_info_t camellia_128_ctr_info = {
+static const cipher_info_t camellia_128_ctr_info = {
POLARSSL_CIPHER_CAMELLIA_128_CTR,
POLARSSL_MODE_CTR,
128,
&camellia_info
};
-const cipher_info_t camellia_192_ctr_info = {
+static const cipher_info_t camellia_192_ctr_info = {
POLARSSL_CIPHER_CAMELLIA_192_CTR,
POLARSSL_MODE_CTR,
192,
&camellia_info
};
-const cipher_info_t camellia_256_ctr_info = {
+static const cipher_info_t camellia_256_ctr_info = {
POLARSSL_CIPHER_CAMELLIA_256_CTR,
POLARSSL_MODE_CTR,
256,
key, key_length );
}
-const cipher_base_t gcm_camellia_info = {
+static const cipher_base_t gcm_camellia_info = {
POLARSSL_CIPHER_ID_CAMELLIA,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
gcm_camellia_setkey_wrap,
gcm_camellia_setkey_wrap,
gcm_ctx_alloc,
gcm_ctx_free,
};
-const cipher_info_t camellia_128_gcm_info = {
+static const cipher_info_t camellia_128_gcm_info = {
POLARSSL_CIPHER_CAMELLIA_128_GCM,
POLARSSL_MODE_GCM,
128,
&gcm_camellia_info
};
-const cipher_info_t camellia_192_gcm_info = {
+static const cipher_info_t camellia_192_gcm_info = {
POLARSSL_CIPHER_CAMELLIA_192_GCM,
POLARSSL_MODE_GCM,
192,
&gcm_camellia_info
};
-const cipher_info_t camellia_256_gcm_info = {
+static const cipher_info_t camellia_256_gcm_info = {
POLARSSL_CIPHER_CAMELLIA_256_GCM,
POLARSSL_MODE_GCM,
256,
key, key_length );
}
-const cipher_base_t ccm_camellia_info = {
+static const cipher_base_t ccm_camellia_info = {
POLARSSL_CIPHER_ID_CAMELLIA,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
ccm_camellia_setkey_wrap,
ccm_camellia_setkey_wrap,
ccm_ctx_alloc,
ccm_ctx_free,
};
-const cipher_info_t camellia_128_ccm_info = {
+static const cipher_info_t camellia_128_ccm_info = {
POLARSSL_CIPHER_CAMELLIA_128_CCM,
POLARSSL_MODE_CCM,
128,
&ccm_camellia_info
};
-const cipher_info_t camellia_192_ccm_info = {
+static const cipher_info_t camellia_192_ccm_info = {
POLARSSL_CIPHER_CAMELLIA_192_CCM,
POLARSSL_MODE_CCM,
192,
&ccm_camellia_info
};
-const cipher_info_t camellia_256_ccm_info = {
+static const cipher_info_t camellia_256_ccm_info = {
POLARSSL_CIPHER_CAMELLIA_256_CCM,
POLARSSL_MODE_CCM,
256,
return des3_crypt_ecb( (des3_context *) ctx, input, output );
}
+#if defined(POLARSSL_CIPHER_MODE_CBC)
static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CBC)
return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
}
+#endif /* POLARSSL_CIPHER_MODE_CBC */
+#if defined(POLARSSL_CIPHER_MODE_CBC)
static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
unsigned char *iv, const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CBC)
return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
}
+#endif /* POLARSSL_CIPHER_MODE_CBC */
static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
static void * des_ctx_alloc( void )
{
- des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
+ des_context *des = polarssl_malloc( sizeof( des_context ) );
if( des == NULL )
return( NULL );
static void * des3_ctx_alloc( void )
{
des3_context *des3;
- des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
+ des3 = polarssl_malloc( sizeof( des3_context ) );
if( des3 == NULL )
return( NULL );
polarssl_free( ctx );
}
-const cipher_base_t des_info = {
+static const cipher_base_t des_info = {
POLARSSL_CIPHER_ID_DES,
des_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
des_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
des_setkey_enc_wrap,
des_setkey_dec_wrap,
des_ctx_alloc,
des_ctx_free
};
-const cipher_info_t des_ecb_info = {
+static const cipher_info_t des_ecb_info = {
POLARSSL_CIPHER_DES_ECB,
POLARSSL_MODE_ECB,
POLARSSL_KEY_LENGTH_DES,
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t des_cbc_info = {
+static const cipher_info_t des_cbc_info = {
POLARSSL_CIPHER_DES_CBC,
POLARSSL_MODE_CBC,
POLARSSL_KEY_LENGTH_DES,
};
#endif /* POLARSSL_CIPHER_MODE_CBC */
-const cipher_base_t des_ede_info = {
+static const cipher_base_t des_ede_info = {
POLARSSL_CIPHER_ID_DES,
des3_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
des3_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
des3_set2key_enc_wrap,
des3_set2key_dec_wrap,
des3_ctx_alloc,
des3_ctx_free
};
-const cipher_info_t des_ede_ecb_info = {
+static const cipher_info_t des_ede_ecb_info = {
POLARSSL_CIPHER_DES_EDE_ECB,
POLARSSL_MODE_ECB,
POLARSSL_KEY_LENGTH_DES_EDE,
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t des_ede_cbc_info = {
+static const cipher_info_t des_ede_cbc_info = {
POLARSSL_CIPHER_DES_EDE_CBC,
POLARSSL_MODE_CBC,
POLARSSL_KEY_LENGTH_DES_EDE,
};
#endif /* POLARSSL_CIPHER_MODE_CBC */
-const cipher_base_t des_ede3_info = {
+static const cipher_base_t des_ede3_info = {
POLARSSL_CIPHER_ID_DES,
des3_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
des3_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
des3_set3key_enc_wrap,
des3_set3key_dec_wrap,
des3_ctx_alloc,
des3_ctx_free
};
-const cipher_info_t des_ede3_ecb_info = {
+static const cipher_info_t des_ede3_ecb_info = {
POLARSSL_CIPHER_DES_EDE3_ECB,
POLARSSL_MODE_ECB,
POLARSSL_KEY_LENGTH_DES_EDE3,
&des_ede3_info
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t des_ede3_cbc_info = {
+static const cipher_info_t des_ede3_cbc_info = {
POLARSSL_CIPHER_DES_EDE3_CBC,
POLARSSL_MODE_CBC,
POLARSSL_KEY_LENGTH_DES_EDE3,
output );
}
+#if defined(POLARSSL_CIPHER_MODE_CBC)
static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
size_t length, unsigned char *iv, const unsigned char *input,
unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CBC)
return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
input, output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
}
+#endif /* POLARSSL_CIPHER_MODE_CBC */
+#if defined(POLARSSL_CIPHER_MODE_CFB)
static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
size_t length, size_t *iv_off, unsigned char *iv,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CFB)
return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
iv_off, iv, input, output );
-#else
- ((void) ctx);
- ((void) operation);
- ((void) length);
- ((void) iv_off);
- ((void) iv);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CFB */
}
+#endif /* POLARSSL_CIPHER_MODE_CFB */
+#if defined(POLARSSL_CIPHER_MODE_CTR)
static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
unsigned char *nonce_counter, unsigned char *stream_block,
const unsigned char *input, unsigned char *output )
{
-#if defined(POLARSSL_CIPHER_MODE_CTR)
return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
nonce_counter, stream_block, input, output );
-#else
- ((void) ctx);
- ((void) length);
- ((void) nc_off);
- ((void) nonce_counter);
- ((void) stream_block);
- ((void) input);
- ((void) output);
-
- return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
-#endif /* POLARSSL_CIPHER_MODE_CTR */
}
+#endif /* POLARSSL_CIPHER_MODE_CTR */
static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
static void * blowfish_ctx_alloc( void )
{
blowfish_context *ctx;
- ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
+ ctx = polarssl_malloc( sizeof( blowfish_context ) );
if( ctx == NULL )
return( NULL );
polarssl_free( ctx );
}
-const cipher_base_t blowfish_info = {
+static const cipher_base_t blowfish_info = {
POLARSSL_CIPHER_ID_BLOWFISH,
blowfish_crypt_ecb_wrap,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
blowfish_crypt_cbc_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
blowfish_crypt_cfb64_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
blowfish_crypt_ctr_wrap,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
NULL,
+#endif
blowfish_setkey_wrap,
blowfish_setkey_wrap,
blowfish_ctx_alloc,
blowfish_ctx_free
};
-const cipher_info_t blowfish_ecb_info = {
+static const cipher_info_t blowfish_ecb_info = {
POLARSSL_CIPHER_BLOWFISH_ECB,
POLARSSL_MODE_ECB,
128,
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
-const cipher_info_t blowfish_cbc_info = {
+static const cipher_info_t blowfish_cbc_info = {
POLARSSL_CIPHER_BLOWFISH_CBC,
POLARSSL_MODE_CBC,
128,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
-const cipher_info_t blowfish_cfb64_info = {
+static const cipher_info_t blowfish_cfb64_info = {
POLARSSL_CIPHER_BLOWFISH_CFB64,
POLARSSL_MODE_CFB,
128,
#endif /* POLARSSL_CIPHER_MODE_CFB */
#if defined(POLARSSL_CIPHER_MODE_CTR)
-const cipher_info_t blowfish_ctr_info = {
+static const cipher_info_t blowfish_ctr_info = {
POLARSSL_CIPHER_BLOWFISH_CTR,
POLARSSL_MODE_CTR,
128,
static void * arc4_ctx_alloc( void )
{
arc4_context *ctx;
- ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
+ ctx = polarssl_malloc( sizeof( arc4_context ) );
if( ctx == NULL )
return( NULL );
polarssl_free( ctx );
}
-const cipher_base_t arc4_base_info = {
+static const cipher_base_t arc4_base_info = {
POLARSSL_CIPHER_ID_ARC4,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
arc4_crypt_stream_wrap,
+#endif
arc4_setkey_wrap,
arc4_setkey_wrap,
arc4_ctx_alloc,
arc4_ctx_free
};
-const cipher_info_t arc4_128_info = {
+static const cipher_info_t arc4_128_info = {
POLARSSL_CIPHER_ARC4_128,
POLARSSL_MODE_STREAM,
128,
((void) ctx);
}
-const cipher_base_t null_base_info = {
+static const cipher_base_t null_base_info = {
POLARSSL_CIPHER_ID_NULL,
NULL,
+#if defined(POLARSSL_CIPHER_MODE_CBC)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CFB)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_CTR)
NULL,
+#endif
+#if defined(POLARSSL_CIPHER_MODE_STREAM)
null_crypt_stream,
+#endif
null_setkey,
null_setkey,
null_ctx_alloc,
null_ctx_free
};
-const cipher_info_t null_cipher_info = {
+static const cipher_info_t null_cipher_info = {
POLARSSL_CIPHER_NULL,
POLARSSL_MODE_STREAM,
0,
{ POLARSSL_CIPHER_NULL, &null_cipher_info },
#endif /* POLARSSL_CIPHER_NULL_CIPHER */
- { 0, NULL }
+ { POLARSSL_CIPHER_NONE, NULL }
};
#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
/*
* CTR_DRBG implementation based on AES-256 (NIST SP 800-90)
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ctr_drbg.h"
+#include <string.h>
+
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
int i, j;
size_t buf_len, use_len;
+ if( data_len > CTR_DRBG_MAX_SEED_INPUT )
+ return( POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG );
+
memset( buf, 0, CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16 );
aes_init( &aes_ctx );
if( add_len > 0 )
{
+ /* MAX_INPUT would be more logical here, but we have to match
+ * block_cipher_df()'s limits since we can't propagate errors */
+ if( add_len > CTR_DRBG_MAX_SEED_INPUT )
+ add_len = CTR_DRBG_MAX_SEED_INPUT;
+
block_cipher_df( add_input, additional, add_len );
ctr_drbg_update_internal( ctx, add_input );
}
#if defined(POLARSSL_SELF_TEST)
-#include <stdio.h>
-
-static unsigned char entropy_source_pr[96] =
+static const unsigned char entropy_source_pr[96] =
{ 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16,
0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02,
0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b,
0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56,
0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 };
-static unsigned char entropy_source_nopr[64] =
+static const unsigned char entropy_source_nopr[64] =
{ 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14,
0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe,
0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d,
test_offset = 0;
CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy,
- entropy_source_pr, nonce_pers_pr, 16, 32 ) );
+ (void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) );
ctr_drbg_set_prediction_resistance( &ctx, CTR_DRBG_PR_ON );
CHK( ctr_drbg_random( &ctx, buf, CTR_DRBG_BLOCKSIZE ) );
CHK( ctr_drbg_random( &ctx, buf, CTR_DRBG_BLOCKSIZE ) );
test_offset = 0;
CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy,
- entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
+ (void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) );
CHK( ctr_drbg_random( &ctx, buf, 16 ) );
CHK( ctr_drbg_reseed( &ctx, NULL, 0 ) );
CHK( ctr_drbg_random( &ctx, buf, 16 ) );
/*
* Debugging routines
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/debug.h"
#include <stdarg.h>
-#include <stdlib.h>
-
-#if defined(EFIX64) || defined(EFI32)
#include <stdio.h>
-#endif
+#include <string.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#if !defined snprintf
#endif
#endif /* _MSC_VER */
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_snprintf snprintf
+#define polarssl_malloc malloc
+#define polarssl_free free
+#endif
+
+#define DEBUG_BUF_SIZE 512
+
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
static int debug_threshold = 0;
char *debug_fmt( const char *format, ... )
{
va_list argp;
- static char str[512];
- int maxlen = sizeof( str ) - 1;
+#if defined(POLARSSL_THREADING_C)
+ char *str = polarssl_malloc( DEBUG_BUF_SIZE );
+
+ if( str == NULL )
+ return( NULL );
+#else
+ static char str[DEBUG_BUF_SIZE];
+#endif
va_start( argp, format );
- vsnprintf( str, maxlen, format, argp );
+ vsnprintf( str, DEBUG_BUF_SIZE - 1, format, argp );
va_end( argp );
- str[maxlen] = '\0';
+ str[DEBUG_BUF_SIZE - 1] = '\0';
return( str );
}
+void debug_print_msg_free( const ssl_context *ssl, int level,
+ const char *file, int line, char *text )
+{
+ if( text != NULL )
+ debug_print_msg( ssl, level, file, line, text );
+
+#if defined(POLARSSL_THREADING_C)
+ polarssl_free( text );
+#endif
+}
+
void debug_print_msg( const ssl_context *ssl, int level,
const char *file, int line, const char *text )
{
return;
}
- snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
+ polarssl_snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
}
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
text, ret, -ret );
str[maxlen] = '\0';
unsigned char *buf, size_t len )
{
char str[512];
+ char txt[17];
size_t i, maxlen = sizeof( str ) - 1, idx = 0;
if( ssl->f_dbg == NULL || level > debug_threshold )
return;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
text, (unsigned int) len );
str[maxlen] = '\0';
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
+ memset( txt, 0, sizeof( txt ) );
for( i = 0; i < len; i++ )
{
if( i >= 4096 )
{
if( i > 0 )
{
- snprintf( str + idx, maxlen - idx, "\n" );
+ polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
+
idx = 0;
+ memset( txt, 0, sizeof( txt ) );
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- idx += snprintf( str + idx, maxlen - idx, "%04x: ",
+ idx += polarssl_snprintf( str + idx, maxlen - idx, "%04x: ",
(unsigned int) i );
}
- idx += snprintf( str + idx, maxlen - idx, " %02x",
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x",
(unsigned int) buf[i] );
+ txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
}
if( len > 0 )
{
- snprintf( str + idx, maxlen - idx, "\n" );
+ for( /* i = i */; i % 16 != 0; i++ )
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " " );
+
+ polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
ssl->f_dbg( ssl->p_dbg, level, str );
}
}
if( ssl->f_dbg == NULL || level > debug_threshold )
return;
- snprintf( str, maxlen, "%s(X)", text );
+ polarssl_snprintf( str, maxlen, "%s(X)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->X );
- snprintf( str, maxlen, "%s(Y)", text );
+ polarssl_snprintf( str, maxlen, "%s(Y)", text );
str[maxlen] = '\0';
debug_print_mpi( ssl, level, file, line, str, &X->Y );
}
break;
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
+ polarssl_snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
str[maxlen] = '\0';
{
if( j > 0 )
{
- snprintf( str + idx, maxlen - idx, "\n" );
+ polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
idx = 0;
}
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
- idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++;
{
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
}
- idx += snprintf( str + idx, maxlen - idx, " 00" );
+ idx += polarssl_snprintf( str + idx, maxlen - idx, " 00" );
}
- snprintf( str + idx, maxlen - idx, "\n" );
+ polarssl_snprintf( str + idx, maxlen - idx, "\n" );
ssl->f_dbg( ssl->p_dbg, level, str );
}
#endif /* POLARSSL_BIGNUM_C */
if( items[i].type == POLARSSL_PK_DEBUG_NONE )
return;
- snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
+ polarssl_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
name[sizeof( name ) - 1] = '\0';
if( items[i].type == POLARSSL_PK_DEBUG_MPI )
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
{
- snprintf( prefix, maxlen, "%s(%04d): ", file, line );
+ polarssl_snprintf( prefix, maxlen, "%s(%04d): ", file, line );
prefix[maxlen] = '\0';
}
else
x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
- idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
+ idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
- snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
+ polarssl_snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
text, ++i, buf );
str[maxlen] = '\0';
/*
* FIPS-46-3 compliant Triple-DES implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/des.h"
+#include <string.h>
+
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
#if !defined(POLARSSL_DES_ALT)
#endif /* !POLARSSL_DES_ALT */
#if defined(POLARSSL_SELF_TEST)
-
-#include <stdio.h>
-
/*
* DES and 3DES test vectors from:
*
/*
* Diffie-Hellman-Merkle key exchange
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/dhm.h"
+#include <string.h>
+
#if defined(POLARSSL_PEM_PARSE_C)
#include "polarssl/pem.h"
#endif
#include "polarssl/platform.h"
#else
#include <stdlib.h>
+#include <stdio.h>
#define polarssl_printf printf
#define polarssl_malloc malloc
#define polarssl_free free
/*
* DHParams ::= SEQUENCE {
- * prime INTEGER, -- P
- * generator INTEGER, -- g
+ * prime INTEGER, -- P
+ * generator INTEGER, -- g
+ * privateValueLength INTEGER OPTIONAL
* }
*/
if( ( ret = asn1_get_tag( &p, end, &len,
if( p != end )
{
- ret = POLARSSL_ERR_DHM_INVALID_FORMAT +
- POLARSSL_ERR_ASN1_LENGTH_MISMATCH;
- goto exit;
+ /* this might be the optional privateValueLength; If so, we
+ can cleanly discard it; */
+ mpi rec;
+ mpi_init( &rec );
+ ret = asn1_get_mpi( &p, end, &rec );
+ mpi_free( &rec );
+ if ( ret != 0 )
+ {
+ ret = POLARSSL_ERR_DHM_INVALID_FORMAT + ret;
+ goto exit;
+ }
+ if ( p != end )
+ {
+ ret = POLARSSL_ERR_DHM_INVALID_FORMAT +
+ POLARSSL_ERR_ASN1_LENGTH_MISMATCH;
+ goto exit;
+ }
}
ret = 0;
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
+ ( *buf = polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( POLARSSL_ERR_DHM_MALLOC_FAILED );
/*
* Elliptic curve Diffie-Hellman
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ecdh.h"
+#include <string.h>
+
/*
* Generate public key: simple wrapper around ecp_gen_keypair
*/
/*
* Elliptic curve DSA
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ecdsa.h"
#include "polarssl/asn1write.h"
+#include <string.h>
+
#if defined(POLARSSL_ECDSA_DETERMINISTIC)
#include "polarssl/hmac_drbg.h"
#endif
for( md_alg = md_list(); *md_alg != 0; md_alg++ )
{
- if( ( md_cur = md_info_from_type( *md_alg ) ) == NULL ||
+ if( ( md_cur = md_info_from_type( (md_type_t) *md_alg ) ) == NULL ||
(size_t) md_cur->size < min_size ||
( md_picked != NULL && md_cur->size > md_picked->size ) )
continue;
#if POLARSSL_ECP_MAX_BYTES > 124
#error "POLARSSL_ECP_MAX_BYTES bigger than expected, please fix MAX_SIG_LEN"
#endif
-#define MAX_SIG_LEN ( 3 + 2 * ( 2 + POLARSSL_ECP_MAX_BYTES ) )
+#define MAX_SIG_LEN ( 3 + 2 * ( 3 + POLARSSL_ECP_MAX_BYTES ) )
/*
* Convert a signature (given by context) to ASN.1
/*
* Elliptic curves over GF(p): generic functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ecp.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
+#include <stdio.h>
#define polarssl_printf printf
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
#if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
!defined(EFI32)
#define strcasecmp _stricmp
if( t_len < 2 )
return( ecp_normalize_jac( grp, *T ) );
- if( ( c = (mpi *) polarssl_malloc( t_len * sizeof( mpi ) ) ) == NULL )
+ if( ( c = polarssl_malloc( t_len * sizeof( mpi ) ) ) == NULL )
return( POLARSSL_ERR_ECP_MALLOC_FAILED );
mpi_init( &u ); mpi_init( &Zi ); mpi_init( &ZZi );
/*
* Point doubling R = 2 P, Jacobian coordinates
*
- * http://www.hyperelliptic.org/EFD/g1p/auto-code/shortw/jacobian/doubling/dbl-2007-bl.op3
- * with heavy variable renaming, some reordering and one minor modification
- * (a = 2 * b, c = d - 2a replaced with c = d, c = c - b, c = c - b)
- * in order to use a lot less intermediate variables (6 vs 25).
+ * Based on http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html#doubling-dbl-1998-cmo-2 .
*
- * Cost: 1D := 2M + 8S
+ * We follow the variable naming fairly closely. The formula variations that trade a MUL for a SQR
+ * (plus a few ADDs) aren't useful as our bignum implementation doesn't distinguish squaring.
+ *
+ * Standard optimizations are applied when curve parameter A is one of { 0, -3 }.
+ *
+ * Cost: 1D := 3M + 4S (A == 0)
+ * 4M + 4S (A == -3)
+ * 3M + 6S + 1a otherwise
*/
static int ecp_double_jac( const ecp_group *grp, ecp_point *R,
const ecp_point *P )
{
int ret;
- mpi T1, T2, T3, X3, Y3, Z3;
+ mpi M, S, T, U;
#if defined(POLARSSL_SELF_TEST)
dbl_count++;
#endif
- mpi_init( &T1 ); mpi_init( &T2 ); mpi_init( &T3 );
- mpi_init( &X3 ); mpi_init( &Y3 ); mpi_init( &Z3 );
-
- MPI_CHK( mpi_mul_mpi( &T3, &P->X, &P->X ) ); MOD_MUL( T3 );
- MPI_CHK( mpi_mul_mpi( &T2, &P->Y, &P->Y ) ); MOD_MUL( T2 );
- MPI_CHK( mpi_mul_mpi( &Y3, &T2, &T2 ) ); MOD_MUL( Y3 );
- MPI_CHK( mpi_add_mpi( &X3, &P->X, &T2 ) ); MOD_ADD( X3 );
- MPI_CHK( mpi_mul_mpi( &X3, &X3, &X3 ) ); MOD_MUL( X3 );
- MPI_CHK( mpi_sub_mpi( &X3, &X3, &Y3 ) ); MOD_SUB( X3 );
- MPI_CHK( mpi_sub_mpi( &X3, &X3, &T3 ) ); MOD_SUB( X3 );
- MPI_CHK( mpi_mul_int( &T1, &X3, 2 ) ); MOD_ADD( T1 );
- MPI_CHK( mpi_mul_mpi( &Z3, &P->Z, &P->Z ) ); MOD_MUL( Z3 );
- MPI_CHK( mpi_mul_mpi( &X3, &Z3, &Z3 ) ); MOD_MUL( X3 );
- MPI_CHK( mpi_mul_int( &T3, &T3, 3 ) ); MOD_ADD( T3 );
+ mpi_init( &M ); mpi_init( &S ); mpi_init( &T ); mpi_init( &U );
/* Special case for A = -3 */
if( grp->A.p == NULL )
{
- MPI_CHK( mpi_mul_int( &X3, &X3, 3 ) );
- X3.s = -1; /* mpi_mul_int doesn't handle negative numbers */
- MOD_SUB( X3 );
+ /* M = 3(X + Z^2)(X - Z^2) */
+ MPI_CHK( mpi_mul_mpi( &S, &P->Z, &P->Z ) ); MOD_MUL( S );
+ MPI_CHK( mpi_add_mpi( &T, &P->X, &S ) ); MOD_ADD( T );
+ MPI_CHK( mpi_sub_mpi( &U, &P->X, &S ) ); MOD_SUB( U );
+ MPI_CHK( mpi_mul_mpi( &S, &T, &U ) ); MOD_MUL( S );
+ MPI_CHK( mpi_mul_int( &M, &S, 3 ) ); MOD_ADD( M );
}
else
{
- MPI_CHK( mpi_mul_mpi( &X3, &X3, &grp->A ) ); MOD_MUL( X3 );
+ /* M = 3.X^2 */
+ MPI_CHK( mpi_mul_mpi( &S, &P->X, &P->X ) ); MOD_MUL( S );
+ MPI_CHK( mpi_mul_int( &M, &S, 3 ) ); MOD_ADD( M );
+
+ /* Optimize away for "koblitz" curves with A = 0 */
+ if( mpi_cmp_int( &grp->A, 0 ) != 0 )
+ {
+ /* M += A.Z^4 */
+ MPI_CHK( mpi_mul_mpi( &S, &P->Z, &P->Z ) ); MOD_MUL( S );
+ MPI_CHK( mpi_mul_mpi( &T, &S, &S ) ); MOD_MUL( T );
+ MPI_CHK( mpi_mul_mpi( &S, &T, &grp->A ) ); MOD_MUL( S );
+ MPI_CHK( mpi_add_mpi( &M, &M, &S ) ); MOD_ADD( M );
+ }
}
- MPI_CHK( mpi_add_mpi( &T3, &T3, &X3 ) ); MOD_ADD( T3 );
- MPI_CHK( mpi_mul_mpi( &X3, &T3, &T3 ) ); MOD_MUL( X3 );
- MPI_CHK( mpi_sub_mpi( &X3, &X3, &T1 ) ); MOD_SUB( X3 );
- MPI_CHK( mpi_sub_mpi( &X3, &X3, &T1 ) ); MOD_SUB( X3 );
- MPI_CHK( mpi_sub_mpi( &T1, &T1, &X3 ) ); MOD_SUB( T1 );
- MPI_CHK( mpi_mul_mpi( &T1, &T3, &T1 ) ); MOD_MUL( T1 );
- MPI_CHK( mpi_mul_int( &T3, &Y3, 8 ) ); MOD_ADD( T3 );
- MPI_CHK( mpi_sub_mpi( &Y3, &T1, &T3 ) ); MOD_SUB( Y3 );
- MPI_CHK( mpi_add_mpi( &T1, &P->Y, &P->Z ) ); MOD_ADD( T1 );
- MPI_CHK( mpi_mul_mpi( &T1, &T1, &T1 ) ); MOD_MUL( T1 );
- MPI_CHK( mpi_sub_mpi( &T1, &T1, &T2 ) ); MOD_SUB( T1 );
- MPI_CHK( mpi_sub_mpi( &Z3, &T1, &Z3 ) ); MOD_SUB( Z3 );
-
- MPI_CHK( mpi_copy( &R->X, &X3 ) );
- MPI_CHK( mpi_copy( &R->Y, &Y3 ) );
- MPI_CHK( mpi_copy( &R->Z, &Z3 ) );
+ /* S = 4.X.Y^2 */
+ MPI_CHK( mpi_mul_mpi( &T, &P->Y, &P->Y ) ); MOD_MUL( T );
+ MPI_CHK( mpi_shift_l( &T, 1 ) ); MOD_ADD( T );
+ MPI_CHK( mpi_mul_mpi( &S, &P->X, &T ) ); MOD_MUL( S );
+ MPI_CHK( mpi_shift_l( &S, 1 ) ); MOD_ADD( S );
+
+ /* U = 8.Y^4 */
+ MPI_CHK( mpi_mul_mpi( &U, &T, &T ) ); MOD_MUL( U );
+ MPI_CHK( mpi_shift_l( &U, 1 ) ); MOD_ADD( U );
+
+ /* T = M^2 - 2.S */
+ MPI_CHK( mpi_mul_mpi( &T, &M, &M ) ); MOD_MUL( T );
+ MPI_CHK( mpi_sub_mpi( &T, &T, &S ) ); MOD_SUB( T );
+ MPI_CHK( mpi_sub_mpi( &T, &T, &S ) ); MOD_SUB( T );
+
+ /* S = M(S - T) - U */
+ MPI_CHK( mpi_sub_mpi( &S, &S, &T ) ); MOD_SUB( S );
+ MPI_CHK( mpi_mul_mpi( &S, &S, &M ) ); MOD_MUL( S );
+ MPI_CHK( mpi_sub_mpi( &S, &S, &U ) ); MOD_SUB( S );
+
+ /* U = 2.Y.Z */
+ MPI_CHK( mpi_mul_mpi( &U, &P->Y, &P->Z ) ); MOD_MUL( U );
+ MPI_CHK( mpi_shift_l( &U, 1 ) ); MOD_ADD( U );
+
+ MPI_CHK( mpi_copy( &R->X, &T ) );
+ MPI_CHK( mpi_copy( &R->Y, &S ) );
+ MPI_CHK( mpi_copy( &R->Z, &U ) );
cleanup:
- mpi_free( &T1 ); mpi_free( &T2 ); mpi_free( &T3 );
- mpi_free( &X3 ); mpi_free( &Y3 ); mpi_free( &Z3 );
+ mpi_free( &M ); mpi_free( &S ); mpi_free( &T ); mpi_free( &U );
return( ret );
}
if( T == NULL )
{
- T = (ecp_point *) polarssl_malloc( pre_len * sizeof( ecp_point ) );
+ T = polarssl_malloc( pre_len * sizeof( ecp_point ) );
if( T == NULL )
{
ret = POLARSSL_ERR_ECP_MALLOC_FAILED;
return( ecp_gen_keypair( &key->grp, &key->d, &key->Q, f_rng, p_rng ) );
}
+/*
+ * Check a public-private key pair
+ */
+int ecp_check_pub_priv( const ecp_keypair *pub, const ecp_keypair *prv )
+{
+ int ret;
+ ecp_point Q;
+ ecp_group grp;
+
+ if( pub->grp.id == POLARSSL_ECP_DP_NONE ||
+ pub->grp.id != prv->grp.id ||
+ mpi_cmp_mpi( &pub->Q.X, &prv->Q.X ) ||
+ mpi_cmp_mpi( &pub->Q.Y, &prv->Q.Y ) ||
+ mpi_cmp_mpi( &pub->Q.Z, &prv->Q.Z ) )
+ {
+ return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
+ }
+
+ ecp_point_init( &Q );
+ ecp_group_init( &grp );
+
+ /* ecp_mul() needs a non-const group... */
+ ecp_group_copy( &grp, &prv->grp );
+
+ /* Also checks d is valid */
+ MPI_CHK( ecp_mul( &grp, &Q, &prv->d, &prv->grp.G, NULL, NULL ) );
+
+ if( mpi_cmp_mpi( &Q.X, &prv->Q.X ) ||
+ mpi_cmp_mpi( &Q.Y, &prv->Q.Y ) ||
+ mpi_cmp_mpi( &Q.Z, &prv->Q.Z ) )
+ {
+ ret = POLARSSL_ERR_ECP_BAD_INPUT_DATA;
+ goto cleanup;
+ }
+
+cleanup:
+ ecp_point_free( &Q );
+ ecp_group_free( &grp );
+
+ return( ret );
+}
+
#if defined(POLARSSL_SELF_TEST)
/*
/*
* Elliptic curves over GF(p): curve-specific data and functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ecp.h"
+#include <string.h>
+
#if defined(_MSC_VER) && !defined(inline)
#define inline _inline
#else
/*
* Entropy accumulator implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/entropy.h"
#include "polarssl/entropy_poll.h"
+#include <string.h>
+
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#include <stdio.h>
+#define polarssl_printf printf
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
+
#if defined(POLARSSL_HAVEGE_C)
#include "polarssl/havege.h"
#endif
#if defined(POLARSSL_HAVEGE_C)
havege_free( &ctx->havege_data );
#endif
- polarssl_zeroize( ctx, sizeof( entropy_context ) );
#if defined(POLARSSL_THREADING_C)
polarssl_mutex_free( &ctx->mutex );
#endif
+ polarssl_zeroize( ctx, sizeof( entropy_context ) );
}
int entropy_add_source( entropy_context *ctx,
#endif /* POLARSSL_FS_IO */
#if defined(POLARSSL_SELF_TEST)
-
-#if defined(POLARSSL_PLATFORM_C)
-#include "polarssl/platform.h"
-#else
-#include <stdio.h>
-#define polarssl_printf printf
-#endif
-
/*
* Dummy source function
*/
/*
* Platform-specific and custom entropy polling functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/entropy_poll.h"
#if defined(POLARSSL_TIMING_C)
+#include <string.h>
#include "polarssl/timing.h"
#endif
#if defined(POLARSSL_HAVEGE_C)
}
#else /* _WIN32 && !EFIX64 && !EFI32 */
+/*
+ * Test for Linux getrandom() support.
+ * Since there is no wrapper in the libc yet, use the generic syscall wrapper
+ * available in GNU libc and compatible libc's (eg uClibc).
+ */
+#if defined(__linux__) && defined(__GLIBC__)
+#include <linux/version.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#if defined(SYS_getrandom)
+#define HAVE_GETRANDOM
+static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags )
+{
+ return( syscall( SYS_getrandom, buf, buflen, flags ) );
+}
+
+#include <sys/utsname.h>
+/* Check if version is at least 3.17.0 */
+static int check_version_3_17_plus( void )
+{
+ int minor;
+ struct utsname un;
+ const char *ver;
+
+ /* Get version information */
+ uname(&un);
+ ver = un.release;
+
+ /* Check major version; assume a single digit */
+ if( ver[0] < '3' || ver[0] > '9' || ver [1] != '.' )
+ return( -1 );
+
+ if( ver[0] - '0' > 3 )
+ return( 0 );
+
+ /* Ok, so now we know major == 3, check minor.
+ * Assume 1 or 2 digits. */
+ if( ver[2] < '0' || ver[2] > '9' )
+ return( -1 );
+
+ minor = ver[2] - '0';
+
+ if( ver[3] >= '0' && ver[3] <= '9' )
+ minor = 10 * minor + ver[3] - '0';
+ else if( ver [3] != '.' )
+ return( -1 );
+
+ if( minor < 17 )
+ return( -1 );
+
+ return( 0 );
+}
+static int has_getrandom = -1;
+#endif /* SYS_getrandom */
+#endif /* __linux__ */
+
#include <stdio.h>
int platform_entropy_poll( void *data,
size_t ret;
((void) data);
+#if defined(HAVE_GETRANDOM)
+ if( has_getrandom == -1 )
+ has_getrandom = ( check_version_3_17_plus() == 0 );
+
+ if( has_getrandom )
+ {
+ int ret;
+
+ if( ( ret = getrandom_wrapper( output, len, 0 ) ) < 0 )
+ return( POLARSSL_ERR_ENTROPY_SOURCE_FAILED );
+
+ *olen = ret;
+ return( 0 );
+ }
+#endif /* HAVE_GETRANDOM */
+
*olen = 0;
file = fopen( "/dev/urandom", "rb" );
/*
* Error message information
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_ERROR_C) || defined(POLARSSL_ERROR_STRERROR_DUMMY)
#include "polarssl/error.h"
+#include <string.h>
+#endif
+
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_ERROR_C)
+#include <stdio.h>
+
#if defined(POLARSSL_AES_C)
#include "polarssl/aes.h"
#endif
#include "polarssl/xtea.h"
#endif
-
-#include <string.h>
-
#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
!defined(EFI32)
#define snprintf _snprintf
// BEGIN generated code
#if defined(POLARSSL_CIPHER_C)
if( use_ret == -(POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
+ polarssl_snprintf( buf, buflen, "CIPHER - The selected feature is not available" );
if( use_ret == -(POLARSSL_ERR_CIPHER_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "CIPHER - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_CIPHER_ALLOC_FAILED) )
- snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
+ polarssl_snprintf( buf, buflen, "CIPHER - Failed to allocate memory" );
if( use_ret == -(POLARSSL_ERR_CIPHER_INVALID_PADDING) )
- snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
+ polarssl_snprintf( buf, buflen, "CIPHER - Input data contains invalid padding and is rejected" );
if( use_ret == -(POLARSSL_ERR_CIPHER_FULL_BLOCK_EXPECTED) )
- snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
+ polarssl_snprintf( buf, buflen, "CIPHER - Decryption of block requires a full block" );
if( use_ret == -(POLARSSL_ERR_CIPHER_AUTH_FAILED) )
- snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
+ polarssl_snprintf( buf, buflen, "CIPHER - Authentication failed (for AEAD modes)" );
#endif /* POLARSSL_CIPHER_C */
#if defined(POLARSSL_DHM_C)
if( use_ret == -(POLARSSL_ERR_DHM_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "DHM - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "DHM - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_DHM_READ_PARAMS_FAILED) )
- snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Reading of the DHM parameters failed" );
if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED) )
- snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Making of the DHM parameters failed" );
if( use_ret == -(POLARSSL_ERR_DHM_READ_PUBLIC_FAILED) )
- snprintf( buf, buflen, "DHM - Reading of the public values failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Reading of the public values failed" );
if( use_ret == -(POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED) )
- snprintf( buf, buflen, "DHM - Making of the public value failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Making of the public value failed" );
if( use_ret == -(POLARSSL_ERR_DHM_CALC_SECRET_FAILED) )
- snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Calculation of the DHM secret failed" );
if( use_ret == -(POLARSSL_ERR_DHM_INVALID_FORMAT) )
- snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
+ polarssl_snprintf( buf, buflen, "DHM - The ASN.1 data is not formatted correctly" );
if( use_ret == -(POLARSSL_ERR_DHM_MALLOC_FAILED) )
- snprintf( buf, buflen, "DHM - Allocation of memory failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Allocation of memory failed" );
if( use_ret == -(POLARSSL_ERR_DHM_FILE_IO_ERROR) )
- snprintf( buf, buflen, "DHM - Read/write of file failed" );
+ polarssl_snprintf( buf, buflen, "DHM - Read/write of file failed" );
#endif /* POLARSSL_DHM_C */
#if defined(POLARSSL_ECP_C)
if( use_ret == -(POLARSSL_ERR_ECP_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "ECP - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "ECP - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
- snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
+ polarssl_snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "ECP - Requested curve not available" );
+ polarssl_snprintf( buf, buflen, "ECP - Requested curve not available" );
if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
- snprintf( buf, buflen, "ECP - The signature is not valid" );
+ polarssl_snprintf( buf, buflen, "ECP - The signature is not valid" );
if( use_ret == -(POLARSSL_ERR_ECP_MALLOC_FAILED) )
- snprintf( buf, buflen, "ECP - Memory allocation failed" );
+ polarssl_snprintf( buf, buflen, "ECP - Memory allocation failed" );
if( use_ret == -(POLARSSL_ERR_ECP_RANDOM_FAILED) )
- snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
+ polarssl_snprintf( buf, buflen, "ECP - Generation of random value, such as (ephemeral) key, failed" );
if( use_ret == -(POLARSSL_ERR_ECP_INVALID_KEY) )
- snprintf( buf, buflen, "ECP - Invalid private or public key" );
+ polarssl_snprintf( buf, buflen, "ECP - Invalid private or public key" );
if( use_ret == -(POLARSSL_ERR_ECP_SIG_LEN_MISMATCH) )
- snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
+ polarssl_snprintf( buf, buflen, "ECP - Signature is valid but shorter than the user-supplied length" );
#endif /* POLARSSL_ECP_C */
#if defined(POLARSSL_MD_C)
if( use_ret == -(POLARSSL_ERR_MD_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "MD - The selected feature is not available" );
+ polarssl_snprintf( buf, buflen, "MD - The selected feature is not available" );
if( use_ret == -(POLARSSL_ERR_MD_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "MD - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "MD - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_MD_ALLOC_FAILED) )
- snprintf( buf, buflen, "MD - Failed to allocate memory" );
+ polarssl_snprintf( buf, buflen, "MD - Failed to allocate memory" );
if( use_ret == -(POLARSSL_ERR_MD_FILE_IO_ERROR) )
- snprintf( buf, buflen, "MD - Opening or reading of file failed" );
+ polarssl_snprintf( buf, buflen, "MD - Opening or reading of file failed" );
#endif /* POLARSSL_MD_C */
#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
if( use_ret == -(POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT) )
- snprintf( buf, buflen, "PEM - No PEM header or footer found" );
+ polarssl_snprintf( buf, buflen, "PEM - No PEM header or footer found" );
if( use_ret == -(POLARSSL_ERR_PEM_INVALID_DATA) )
- snprintf( buf, buflen, "PEM - PEM string is not as expected" );
+ polarssl_snprintf( buf, buflen, "PEM - PEM string is not as expected" );
if( use_ret == -(POLARSSL_ERR_PEM_MALLOC_FAILED) )
- snprintf( buf, buflen, "PEM - Failed to allocate memory" );
+ polarssl_snprintf( buf, buflen, "PEM - Failed to allocate memory" );
if( use_ret == -(POLARSSL_ERR_PEM_INVALID_ENC_IV) )
- snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
+ polarssl_snprintf( buf, buflen, "PEM - RSA IV is not in hex-format" );
if( use_ret == -(POLARSSL_ERR_PEM_UNKNOWN_ENC_ALG) )
- snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
+ polarssl_snprintf( buf, buflen, "PEM - Unsupported key encryption algorithm" );
if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_REQUIRED) )
- snprintf( buf, buflen, "PEM - Private key password can't be empty" );
+ polarssl_snprintf( buf, buflen, "PEM - Private key password can't be empty" );
if( use_ret == -(POLARSSL_ERR_PEM_PASSWORD_MISMATCH) )
- snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
+ polarssl_snprintf( buf, buflen, "PEM - Given private key password does not allow for correct decryption" );
if( use_ret == -(POLARSSL_ERR_PEM_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
+ polarssl_snprintf( buf, buflen, "PEM - Unavailable feature, e.g. hashing/encryption combination" );
if( use_ret == -(POLARSSL_ERR_PEM_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "PEM - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "PEM - Bad input parameters to function" );
#endif /* POLARSSL_PEM_PARSE_C || POLARSSL_PEM_WRITE_C */
#if defined(POLARSSL_PK_C)
if( use_ret == -(POLARSSL_ERR_PK_MALLOC_FAILED) )
- snprintf( buf, buflen, "PK - Memory alloation failed" );
+ polarssl_snprintf( buf, buflen, "PK - Memory alloation failed" );
if( use_ret == -(POLARSSL_ERR_PK_TYPE_MISMATCH) )
- snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
+ polarssl_snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "PK - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "PK - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
- snprintf( buf, buflen, "PK - Read/write of file failed" );
+ polarssl_snprintf( buf, buflen, "PK - Read/write of file failed" );
if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
- snprintf( buf, buflen, "PK - Unsupported key version" );
+ polarssl_snprintf( buf, buflen, "PK - Unsupported key version" );
if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
- snprintf( buf, buflen, "PK - Invalid key tag or value" );
+ polarssl_snprintf( buf, buflen, "PK - Invalid key tag or value" );
if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
- snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
+ polarssl_snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
- snprintf( buf, buflen, "PK - Private key password can't be empty" );
+ polarssl_snprintf( buf, buflen, "PK - Private key password can't be empty" );
if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
- snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
+ polarssl_snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
- snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
+ polarssl_snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
- snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
- snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
+ polarssl_snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
+ polarssl_snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
if( use_ret == -(POLARSSL_ERR_PK_SIG_LEN_MISMATCH) )
- snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
+ polarssl_snprintf( buf, buflen, "PK - The signature is valid but its length is less than expected" );
#endif /* POLARSSL_PK_C */
#if defined(POLARSSL_PKCS12_C)
if( use_ret == -(POLARSSL_ERR_PKCS12_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "PKCS12 - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
+ polarssl_snprintf( buf, buflen, "PKCS12 - Feature not available, e.g. unsupported encryption scheme" );
if( use_ret == -(POLARSSL_ERR_PKCS12_PBE_INVALID_FORMAT) )
- snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
+ polarssl_snprintf( buf, buflen, "PKCS12 - PBE ASN.1 data not as expected" );
if( use_ret == -(POLARSSL_ERR_PKCS12_PASSWORD_MISMATCH) )
- snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
+ polarssl_snprintf( buf, buflen, "PKCS12 - Given private key password does not allow for correct decryption" );
#endif /* POLARSSL_PKCS12_C */
#if defined(POLARSSL_PKCS5_C)
if( use_ret == -(POLARSSL_ERR_PKCS5_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "PKCS5 - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_PKCS5_INVALID_FORMAT) )
- snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
+ polarssl_snprintf( buf, buflen, "PKCS5 - Unexpected ASN.1 data" );
if( use_ret == -(POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
+ polarssl_snprintf( buf, buflen, "PKCS5 - Requested encryption or digest alg not available" );
if( use_ret == -(POLARSSL_ERR_PKCS5_PASSWORD_MISMATCH) )
- snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
+ polarssl_snprintf( buf, buflen, "PKCS5 - Given private key password does not allow for correct decryption" );
#endif /* POLARSSL_PKCS5_C */
#if defined(POLARSSL_RSA_C)
if( use_ret == -(POLARSSL_ERR_RSA_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "RSA - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "RSA - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_RSA_INVALID_PADDING) )
- snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
+ polarssl_snprintf( buf, buflen, "RSA - Input data contains invalid padding and is rejected" );
if( use_ret == -(POLARSSL_ERR_RSA_KEY_GEN_FAILED) )
- snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
+ polarssl_snprintf( buf, buflen, "RSA - Something failed during generation of a key" );
if( use_ret == -(POLARSSL_ERR_RSA_KEY_CHECK_FAILED) )
- snprintf( buf, buflen, "RSA - Key failed to pass the libraries validity check" );
+ polarssl_snprintf( buf, buflen, "RSA - Key failed to pass the library's validity check" );
if( use_ret == -(POLARSSL_ERR_RSA_PUBLIC_FAILED) )
- snprintf( buf, buflen, "RSA - The public key operation failed" );
+ polarssl_snprintf( buf, buflen, "RSA - The public key operation failed" );
if( use_ret == -(POLARSSL_ERR_RSA_PRIVATE_FAILED) )
- snprintf( buf, buflen, "RSA - The private key operation failed" );
+ polarssl_snprintf( buf, buflen, "RSA - The private key operation failed" );
if( use_ret == -(POLARSSL_ERR_RSA_VERIFY_FAILED) )
- snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
+ polarssl_snprintf( buf, buflen, "RSA - The PKCS#1 verification failed" );
if( use_ret == -(POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE) )
- snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
+ polarssl_snprintf( buf, buflen, "RSA - The output buffer for decryption is not large enough" );
if( use_ret == -(POLARSSL_ERR_RSA_RNG_FAILED) )
- snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
+ polarssl_snprintf( buf, buflen, "RSA - The random generator failed to generate non-zeros" );
#endif /* POLARSSL_RSA_C */
#if defined(POLARSSL_SSL_TLS_C)
if( use_ret == -(POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "SSL - The requested feature is not available" );
+ polarssl_snprintf( buf, buflen, "SSL - The requested feature is not available" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "SSL - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "SSL - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_SSL_INVALID_MAC) )
- snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Verification of the message MAC failed" );
if( use_ret == -(POLARSSL_ERR_SSL_INVALID_RECORD) )
- snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
+ polarssl_snprintf( buf, buflen, "SSL - An invalid SSL record was received" );
if( use_ret == -(POLARSSL_ERR_SSL_CONN_EOF) )
- snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
+ polarssl_snprintf( buf, buflen, "SSL - The connection indicated an EOF" );
if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_CIPHER) )
- snprintf( buf, buflen, "SSL - An unknown cipher was received" );
+ polarssl_snprintf( buf, buflen, "SSL - An unknown cipher was received" );
if( use_ret == -(POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN) )
- snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
+ polarssl_snprintf( buf, buflen, "SSL - The server has no ciphersuites in common with the client" );
if( use_ret == -(POLARSSL_ERR_SSL_NO_RNG) )
- snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
+ polarssl_snprintf( buf, buflen, "SSL - No RNG was provided to the SSL module" );
if( use_ret == -(POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE) )
- snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
+ polarssl_snprintf( buf, buflen, "SSL - No client certification received from the client, but required by the authentication mode" );
if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE) )
- snprintf( buf, buflen, "SSL - DESCRIPTION MISSING" );
+ polarssl_snprintf( buf, buflen, "SSL - Our own certificate(s) is/are too large to send in an SSL message" );
if( use_ret == -(POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED) )
- snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
+ polarssl_snprintf( buf, buflen, "SSL - The own certificate is not set, but needed by the server" );
if( use_ret == -(POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED) )
- snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
+ polarssl_snprintf( buf, buflen, "SSL - The own private key or pre-shared key is not set, but needed" );
if( use_ret == -(POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED) )
- snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
+ polarssl_snprintf( buf, buflen, "SSL - No CA Chain is set, but required to operate" );
if( use_ret == -(POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE) )
- snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
+ polarssl_snprintf( buf, buflen, "SSL - An unexpected message was received from our peer" );
if( use_ret == -(POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE) )
{
- snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
+ polarssl_snprintf( buf, buflen, "SSL - A fatal alert message was received from our peer" );
return;
}
if( use_ret == -(POLARSSL_ERR_SSL_PEER_VERIFY_FAILED) )
- snprintf( buf, buflen, "SSL - Verification of our peer failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Verification of our peer failed" );
if( use_ret == -(POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) )
- snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
+ polarssl_snprintf( buf, buflen, "SSL - The peer notified us that the connection is going to be closed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO) )
- snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientHello handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO) )
- snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerHello handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE) )
- snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the Certificate handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST) )
- snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the CertificateRequest handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE) )
- snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerKeyExchange handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE) )
- snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ServerHelloDone handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE) )
- snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP) )
- snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS) )
- snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY) )
- snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the CertificateVerify handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC) )
- snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the ChangeCipherSpec handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_FINISHED) )
- snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the Finished handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_MALLOC_FAILED) )
- snprintf( buf, buflen, "SSL - Memory allocation failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Memory allocation failed" );
if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FAILED) )
- snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
+ polarssl_snprintf( buf, buflen, "SSL - Hardware acceleration function returned with error" );
if( use_ret == -(POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH) )
- snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
+ polarssl_snprintf( buf, buflen, "SSL - Hardware acceleration function skipped / left alone data" );
if( use_ret == -(POLARSSL_ERR_SSL_COMPRESSION_FAILED) )
- snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the compression / decompression failed" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION) )
- snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
+ polarssl_snprintf( buf, buflen, "SSL - Handshake protocol not within min/max boundaries" );
if( use_ret == -(POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET) )
- snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
+ polarssl_snprintf( buf, buflen, "SSL - Processing of the NewSessionTicket handshake message failed" );
if( use_ret == -(POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED) )
- snprintf( buf, buflen, "SSL - Session ticket has expired" );
+ polarssl_snprintf( buf, buflen, "SSL - Session ticket has expired" );
if( use_ret == -(POLARSSL_ERR_SSL_PK_TYPE_MISMATCH) )
- snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
+ polarssl_snprintf( buf, buflen, "SSL - Public key type mismatch (eg, asked for RSA key exchange and presented EC key)" );
if( use_ret == -(POLARSSL_ERR_SSL_UNKNOWN_IDENTITY) )
- snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
+ polarssl_snprintf( buf, buflen, "SSL - Unknown identity received (eg, PSK identity)" );
if( use_ret == -(POLARSSL_ERR_SSL_INTERNAL_ERROR) )
- snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
+ polarssl_snprintf( buf, buflen, "SSL - Internal error (eg, unexpected failure in lower-level module)" );
if( use_ret == -(POLARSSL_ERR_SSL_COUNTER_WRAPPING) )
- snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
+ polarssl_snprintf( buf, buflen, "SSL - A counter would wrap (eg, too many messages exchanged)" );
if( use_ret == -(POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO) )
- snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
+ polarssl_snprintf( buf, buflen, "SSL - Unexpected message at ServerHello in renegotiation" );
+ if( use_ret == -(POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE) )
+ polarssl_snprintf( buf, buflen, "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages)" );
#endif /* POLARSSL_SSL_TLS_C */
#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
if( use_ret == -(POLARSSL_ERR_X509_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
+ polarssl_snprintf( buf, buflen, "X509 - Unavailable feature, e.g. RSA hashing/encryption combination" );
if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_OID) )
- snprintf( buf, buflen, "X509 - Requested OID is unknown" );
+ polarssl_snprintf( buf, buflen, "X509 - Requested OID is unknown" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_FORMAT) )
- snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
+ polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR format is invalid, e.g. different type expected" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_VERSION) )
- snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The CRT/CRL/CSR version element is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_SERIAL) )
- snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The serial tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_ALG) )
- snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The algorithm tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_NAME) )
- snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_DATE) )
- snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_SIGNATURE) )
- snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_EXTENSIONS) )
- snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - The extension tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_VERSION) )
- snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
+ polarssl_snprintf( buf, buflen, "X509 - CRT/CRL/CSR has an unsupported version number" );
if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_SIG_ALG) )
- snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
+ polarssl_snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
if( use_ret == -(POLARSSL_ERR_X509_SIG_MISMATCH) )
- snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
+ polarssl_snprintf( buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::x509_crt sig_oid)" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
- snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
+ polarssl_snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
- snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
+ polarssl_snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
if( use_ret == -(POLARSSL_ERR_X509_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "X509 - Input invalid" );
+ polarssl_snprintf( buf, buflen, "X509 - Input invalid" );
if( use_ret == -(POLARSSL_ERR_X509_MALLOC_FAILED) )
- snprintf( buf, buflen, "X509 - Allocation of memory failed" );
+ polarssl_snprintf( buf, buflen, "X509 - Allocation of memory failed" );
if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
- snprintf( buf, buflen, "X509 - Read/write of file failed" );
+ polarssl_snprintf( buf, buflen, "X509 - Read/write of file failed" );
#endif /* POLARSSL_X509_USE,X509_CREATE_C */
// END generated code
if( strlen( buf ) == 0 )
- snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
+ polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
}
use_ret = ret & ~0xFF80;
if( buflen - len < 5 )
return;
- snprintf( buf + len, buflen - len, " : " );
+ polarssl_snprintf( buf + len, buflen - len, " : " );
buf += len + 3;
buflen -= len + 3;
// BEGIN generated code
#if defined(POLARSSL_AES_C)
if( use_ret == -(POLARSSL_ERR_AES_INVALID_KEY_LENGTH) )
- snprintf( buf, buflen, "AES - Invalid key length" );
+ polarssl_snprintf( buf, buflen, "AES - Invalid key length" );
if( use_ret == -(POLARSSL_ERR_AES_INVALID_INPUT_LENGTH) )
- snprintf( buf, buflen, "AES - Invalid data input length" );
+ polarssl_snprintf( buf, buflen, "AES - Invalid data input length" );
#endif /* POLARSSL_AES_C */
#if defined(POLARSSL_ASN1_PARSE_C)
if( use_ret == -(POLARSSL_ERR_ASN1_OUT_OF_DATA) )
- snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Out of data when parsing an ASN1 data structure" );
if( use_ret == -(POLARSSL_ERR_ASN1_UNEXPECTED_TAG) )
- snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
+ polarssl_snprintf( buf, buflen, "ASN1 - ASN1 tag was of an unexpected value" );
if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_LENGTH) )
- snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Error when trying to determine the length or invalid length" );
if( use_ret == -(POLARSSL_ERR_ASN1_LENGTH_MISMATCH) )
- snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Actual length differs from expected length" );
if( use_ret == -(POLARSSL_ERR_ASN1_INVALID_DATA) )
- snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Data is invalid. (not used)" );
if( use_ret == -(POLARSSL_ERR_ASN1_MALLOC_FAILED) )
- snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Memory allocation failed" );
if( use_ret == -(POLARSSL_ERR_ASN1_BUF_TOO_SMALL) )
- snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
+ polarssl_snprintf( buf, buflen, "ASN1 - Buffer too small when writing ASN.1 data structure" );
#endif /* POLARSSL_ASN1_PARSE_C */
#if defined(POLARSSL_BASE64_C)
if( use_ret == -(POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) )
- snprintf( buf, buflen, "BASE64 - Output buffer too small" );
+ polarssl_snprintf( buf, buflen, "BASE64 - Output buffer too small" );
if( use_ret == -(POLARSSL_ERR_BASE64_INVALID_CHARACTER) )
- snprintf( buf, buflen, "BASE64 - Invalid character in input" );
+ polarssl_snprintf( buf, buflen, "BASE64 - Invalid character in input" );
#endif /* POLARSSL_BASE64_C */
#if defined(POLARSSL_BIGNUM_C)
if( use_ret == -(POLARSSL_ERR_MPI_FILE_IO_ERROR) )
- snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - An error occurred while reading from or writing to a file" );
if( use_ret == -(POLARSSL_ERR_MPI_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_MPI_INVALID_CHARACTER) )
- snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - There is an invalid character in the digit string" );
if( use_ret == -(POLARSSL_ERR_MPI_BUFFER_TOO_SMALL) )
- snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - The buffer is too small to write to" );
if( use_ret == -(POLARSSL_ERR_MPI_NEGATIVE_VALUE) )
- snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are negative or result in illegal output" );
if( use_ret == -(POLARSSL_ERR_MPI_DIVISION_BY_ZERO) )
- snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - The input argument for division is zero, which is not allowed" );
if( use_ret == -(POLARSSL_ERR_MPI_NOT_ACCEPTABLE) )
- snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - The input arguments are not acceptable" );
if( use_ret == -(POLARSSL_ERR_MPI_MALLOC_FAILED) )
- snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
+ polarssl_snprintf( buf, buflen, "BIGNUM - Memory allocation failed" );
#endif /* POLARSSL_BIGNUM_C */
#if defined(POLARSSL_BLOWFISH_C)
if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH) )
- snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
+ polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid key length" );
if( use_ret == -(POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH) )
- snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
+ polarssl_snprintf( buf, buflen, "BLOWFISH - Invalid data input length" );
#endif /* POLARSSL_BLOWFISH_C */
#if defined(POLARSSL_CAMELLIA_C)
if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH) )
- snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
+ polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid key length" );
if( use_ret == -(POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH) )
- snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
+ polarssl_snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
#endif /* POLARSSL_CAMELLIA_C */
#if defined(POLARSSL_CCM_C)
if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
- snprintf( buf, buflen, "CCM - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "CCM - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
- snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
+ polarssl_snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
#endif /* POLARSSL_CCM_C */
#if defined(POLARSSL_CTR_DRBG_C)
if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
- snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
+ polarssl_snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
if( use_ret == -(POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG) )
- snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
+ polarssl_snprintf( buf, buflen, "CTR_DRBG - Too many random requested in single call" );
if( use_ret == -(POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG) )
- snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
+ polarssl_snprintf( buf, buflen, "CTR_DRBG - Input too large (Entropy + additional)" );
if( use_ret == -(POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR) )
- snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "CTR_DRBG - Read/write error in file" );
#endif /* POLARSSL_CTR_DRBG_C */
#if defined(POLARSSL_DES_C)
if( use_ret == -(POLARSSL_ERR_DES_INVALID_INPUT_LENGTH) )
- snprintf( buf, buflen, "DES - The data input has an invalid length" );
+ polarssl_snprintf( buf, buflen, "DES - The data input has an invalid length" );
#endif /* POLARSSL_DES_C */
#if defined(POLARSSL_ENTROPY_C)
if( use_ret == -(POLARSSL_ERR_ENTROPY_SOURCE_FAILED) )
- snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
+ polarssl_snprintf( buf, buflen, "ENTROPY - Critical entropy source failure" );
if( use_ret == -(POLARSSL_ERR_ENTROPY_MAX_SOURCES) )
- snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
+ polarssl_snprintf( buf, buflen, "ENTROPY - No more sources can be added" );
if( use_ret == -(POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED) )
- snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
+ polarssl_snprintf( buf, buflen, "ENTROPY - No sources have been added to poll" );
if( use_ret == -(POLARSSL_ERR_ENTROPY_FILE_IO_ERROR) )
- snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "ENTROPY - Read/write error in file" );
#endif /* POLARSSL_ENTROPY_C */
#if defined(POLARSSL_GCM_C)
if( use_ret == -(POLARSSL_ERR_GCM_AUTH_FAILED) )
- snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
+ polarssl_snprintf( buf, buflen, "GCM - Authenticated decryption failed" );
if( use_ret == -(POLARSSL_ERR_GCM_BAD_INPUT) )
- snprintf( buf, buflen, "GCM - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "GCM - Bad input parameters to function" );
#endif /* POLARSSL_GCM_C */
#if defined(POLARSSL_HMAC_DRBG_C)
if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG) )
- snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
+ polarssl_snprintf( buf, buflen, "HMAC_DRBG - Too many random requested in single call" );
if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG) )
- snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
+ polarssl_snprintf( buf, buflen, "HMAC_DRBG - Input too large (Entropy + additional)" );
if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR) )
- snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "HMAC_DRBG - Read/write error in file" );
if( use_ret == -(POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED) )
- snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
+ polarssl_snprintf( buf, buflen, "HMAC_DRBG - The entropy source failed" );
#endif /* POLARSSL_HMAC_DRBG_C */
#if defined(POLARSSL_MD2_C)
if( use_ret == -(POLARSSL_ERR_MD2_FILE_IO_ERROR) )
- snprintf( buf, buflen, "MD2 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "MD2 - Read/write error in file" );
#endif /* POLARSSL_MD2_C */
#if defined(POLARSSL_MD4_C)
if( use_ret == -(POLARSSL_ERR_MD4_FILE_IO_ERROR) )
- snprintf( buf, buflen, "MD4 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "MD4 - Read/write error in file" );
#endif /* POLARSSL_MD4_C */
#if defined(POLARSSL_MD5_C)
if( use_ret == -(POLARSSL_ERR_MD5_FILE_IO_ERROR) )
- snprintf( buf, buflen, "MD5 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "MD5 - Read/write error in file" );
#endif /* POLARSSL_MD5_C */
#if defined(POLARSSL_NET_C)
if( use_ret == -(POLARSSL_ERR_NET_UNKNOWN_HOST) )
- snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
+ polarssl_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
if( use_ret == -(POLARSSL_ERR_NET_SOCKET_FAILED) )
- snprintf( buf, buflen, "NET - Failed to open a socket" );
+ polarssl_snprintf( buf, buflen, "NET - Failed to open a socket" );
if( use_ret == -(POLARSSL_ERR_NET_CONNECT_FAILED) )
- snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
+ polarssl_snprintf( buf, buflen, "NET - The connection to the given server / port failed" );
if( use_ret == -(POLARSSL_ERR_NET_BIND_FAILED) )
- snprintf( buf, buflen, "NET - Binding of the socket failed" );
+ polarssl_snprintf( buf, buflen, "NET - Binding of the socket failed" );
if( use_ret == -(POLARSSL_ERR_NET_LISTEN_FAILED) )
- snprintf( buf, buflen, "NET - Could not listen on the socket" );
+ polarssl_snprintf( buf, buflen, "NET - Could not listen on the socket" );
if( use_ret == -(POLARSSL_ERR_NET_ACCEPT_FAILED) )
- snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
+ polarssl_snprintf( buf, buflen, "NET - Could not accept the incoming connection" );
if( use_ret == -(POLARSSL_ERR_NET_RECV_FAILED) )
- snprintf( buf, buflen, "NET - Reading information from the socket failed" );
+ polarssl_snprintf( buf, buflen, "NET - Reading information from the socket failed" );
if( use_ret == -(POLARSSL_ERR_NET_SEND_FAILED) )
- snprintf( buf, buflen, "NET - Sending information through the socket failed" );
+ polarssl_snprintf( buf, buflen, "NET - Sending information through the socket failed" );
if( use_ret == -(POLARSSL_ERR_NET_CONN_RESET) )
- snprintf( buf, buflen, "NET - Connection was reset by peer" );
+ polarssl_snprintf( buf, buflen, "NET - Connection was reset by peer" );
if( use_ret == -(POLARSSL_ERR_NET_WANT_READ) )
- snprintf( buf, buflen, "NET - Connection requires a read call" );
+ polarssl_snprintf( buf, buflen, "NET - Connection requires a read call" );
if( use_ret == -(POLARSSL_ERR_NET_WANT_WRITE) )
- snprintf( buf, buflen, "NET - Connection requires a write call" );
+ polarssl_snprintf( buf, buflen, "NET - Connection requires a write call" );
#endif /* POLARSSL_NET_C */
#if defined(POLARSSL_OID_C)
if( use_ret == -(POLARSSL_ERR_OID_NOT_FOUND) )
- snprintf( buf, buflen, "OID - OID is not found" );
+ polarssl_snprintf( buf, buflen, "OID - OID is not found" );
if( use_ret == -(POLARSSL_ERR_OID_BUF_TOO_SMALL) )
- snprintf( buf, buflen, "OID - output buffer is too small" );
+ polarssl_snprintf( buf, buflen, "OID - output buffer is too small" );
#endif /* POLARSSL_OID_C */
#if defined(POLARSSL_PADLOCK_C)
if( use_ret == -(POLARSSL_ERR_PADLOCK_DATA_MISALIGNED) )
- snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
+ polarssl_snprintf( buf, buflen, "PADLOCK - Input data should be aligned" );
#endif /* POLARSSL_PADLOCK_C */
#if defined(POLARSSL_PBKDF2_C)
if( use_ret == -(POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "PBKDF2 - Bad input parameters to function" );
#endif /* POLARSSL_PBKDF2_C */
#if defined(POLARSSL_RIPEMD160_C)
if( use_ret == -(POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR) )
- snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "RIPEMD160 - Read/write error in file" );
#endif /* POLARSSL_RIPEMD160_C */
#if defined(POLARSSL_SHA1_C)
if( use_ret == -(POLARSSL_ERR_SHA1_FILE_IO_ERROR) )
- snprintf( buf, buflen, "SHA1 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "SHA1 - Read/write error in file" );
#endif /* POLARSSL_SHA1_C */
#if defined(POLARSSL_SHA256_C)
if( use_ret == -(POLARSSL_ERR_SHA256_FILE_IO_ERROR) )
- snprintf( buf, buflen, "SHA256 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "SHA256 - Read/write error in file" );
#endif /* POLARSSL_SHA256_C */
#if defined(POLARSSL_SHA512_C)
if( use_ret == -(POLARSSL_ERR_SHA512_FILE_IO_ERROR) )
- snprintf( buf, buflen, "SHA512 - Read/write error in file" );
+ polarssl_snprintf( buf, buflen, "SHA512 - Read/write error in file" );
#endif /* POLARSSL_SHA512_C */
#if defined(POLARSSL_THREADING_C)
if( use_ret == -(POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE) )
- snprintf( buf, buflen, "THREADING - The selected feature is not available" );
+ polarssl_snprintf( buf, buflen, "THREADING - The selected feature is not available" );
if( use_ret == -(POLARSSL_ERR_THREADING_BAD_INPUT_DATA) )
- snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
+ polarssl_snprintf( buf, buflen, "THREADING - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_THREADING_MUTEX_ERROR) )
- snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
+ polarssl_snprintf( buf, buflen, "THREADING - Locking / unlocking / free failed with error code" );
#endif /* POLARSSL_THREADING_C */
#if defined(POLARSSL_XTEA_C)
if( use_ret == -(POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH) )
- snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
+ polarssl_snprintf( buf, buflen, "XTEA - The data input has an invalid length" );
#endif /* POLARSSL_XTEA_C */
// END generated code
if( strlen( buf ) != 0 )
return;
- snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
+ polarssl_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret );
}
#if defined(POLARSSL_ERROR_STRERROR_BC)
#if defined(POLARSSL_ERROR_STRERROR_DUMMY)
-#include <string.h>
-
/*
* Provide an non-function in case POLARSSL_ERROR_C is not defined
*/
/*
* NIST SP800-38D compliant GCM implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/gcm.h"
+#include <string.h>
+
#if defined(POLARSSL_AESNI_C)
#include "polarssl/aesni.h"
#endif
+#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
/*
* 32-bit integer manipulation macros (big endian)
ctx->HH[i] = vh;
}
- for( i = 2; i < 16; i <<= 1 )
+ for( i = 2; i <= 8; i *= 2 )
{
uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i;
vh = *HiH;
if( cipher_info->block_size != 16 )
return( POLARSSL_ERR_GCM_BAD_INPUT );
+ cipher_free( &ctx->cipher_ctx );
+
if( ( ret = cipher_init_ctx( &ctx->cipher_ctx, cipher_info ) ) != 0 )
return( ret );
}
#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
-
-#include <stdio.h>
-
/*
* AES-GCM test vectors from:
*
*/
#define MAX_TESTS 6
-int key_index[MAX_TESTS] =
+static const int key_index[MAX_TESTS] =
{ 0, 0, 1, 1, 1, 1 };
-unsigned char key[MAX_TESTS][32] =
+static const unsigned char key[MAX_TESTS][32] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
};
-size_t iv_len[MAX_TESTS] =
+static const size_t iv_len[MAX_TESTS] =
{ 12, 12, 12, 12, 8, 60 };
-int iv_index[MAX_TESTS] =
+static const int iv_index[MAX_TESTS] =
{ 0, 0, 1, 1, 1, 2 };
-unsigned char iv[MAX_TESTS][64] =
+static const unsigned char iv[MAX_TESTS][64] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 },
0xa6, 0x37, 0xb3, 0x9b },
};
-size_t add_len[MAX_TESTS] =
+static const size_t add_len[MAX_TESTS] =
{ 0, 0, 0, 20, 20, 20 };
-int add_index[MAX_TESTS] =
+static const int add_index[MAX_TESTS] =
{ 0, 0, 0, 1, 1, 1 };
-unsigned char additional[MAX_TESTS][64] =
+static const unsigned char additional[MAX_TESTS][64] =
{
{ 0x00 },
{ 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
0xab, 0xad, 0xda, 0xd2 },
};
-size_t pt_len[MAX_TESTS] =
+static const size_t pt_len[MAX_TESTS] =
{ 0, 16, 64, 60, 60, 60 };
-int pt_index[MAX_TESTS] =
+static const int pt_index[MAX_TESTS] =
{ 0, 0, 1, 1, 1, 1 };
-unsigned char pt[MAX_TESTS][64] =
+static const unsigned char pt[MAX_TESTS][64] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
};
-unsigned char ct[MAX_TESTS * 3][64] =
+static const unsigned char ct[MAX_TESTS * 3][64] =
{
{ 0x00 },
{ 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
0x44, 0xae, 0x7e, 0x3f },
};
-unsigned char tag[MAX_TESTS * 3][16] =
+static const unsigned char tag[MAX_TESTS * 3][16] =
{
{ 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a },
return( 0 );
}
-
-
#endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
#endif /* POLARSSL_GCM_C */
/**
* \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
* HMAC_DRBG implementation (NIST SP 800-90)
*
- * Copyright (C) 2014, Brainspark B.V.
+ * Copyright (C) 2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/hmac_drbg.h"
+#include <string.h>
+
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_SELF_TEST */
+#endif /* POLARSSL_PLATFORM_C */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
if( ctx == NULL )
return;
- md_free_ctx( &ctx->md_ctx );
+ md_free( &ctx->md_ctx );
polarssl_zeroize( ctx, sizeof( hmac_drbg_context ) );
}
#if defined(POLARSSL_SELF_TEST)
-#include <stdio.h>
-
#if !defined(POLARSSL_SHA1_C)
/* Dummy checkup routine */
int hmac_drbg_self_test( int verbose )
#define OUTPUT_LEN 80
/* From a NIST PR=true test vector */
-static unsigned char entropy_pr[] = {
+static const unsigned char entropy_pr[] = {
0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f,
0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11,
0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42,
0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44 };
/* From a NIST PR=false test vector */
-static unsigned char entropy_nopr[] = {
+static const unsigned char entropy_nopr[] = {
0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66,
0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8,
0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3,
test_offset = 0;
CHK( hmac_drbg_init( &ctx, md_info,
- hmac_drbg_self_test_entropy, entropy_pr,
+ hmac_drbg_self_test_entropy, (void *) entropy_pr,
NULL, 0 ) );
hmac_drbg_set_prediction_resistance( &ctx, POLARSSL_HMAC_DRBG_PR_ON );
CHK( hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
test_offset = 0;
CHK( hmac_drbg_init( &ctx, md_info,
- hmac_drbg_self_test_entropy, entropy_nopr,
+ hmac_drbg_self_test_entropy, (void *) entropy_nopr,
NULL, 0 ) );
CHK( hmac_drbg_reseed( &ctx, NULL, 0 ) );
CHK( hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) );
/**
* \file md.c
*
- * \brief Generic message digest wrapper for PolarSSL
+ * \brief Generic message digest wrapper for mbed TLS
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/md_wrap.h"
#include <stdlib.h>
+#include <string.h>
#if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
!defined(EFI32)
return( 0 );
}
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
int md_free_ctx( md_context_t *ctx )
{
md_free( ctx );
return( 0 );
}
+#endif
int md_starts( md_context_t *ctx )
{
/*
* RFC 1115/1319 compliant MD2 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/md2.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
/*
* RFC 1186/1320 compliant MD4 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/md4.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
#endif
#ifndef PUT_UINT32_LE
-#define PUT_UINT32_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( (n) ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
+#define PUT_UINT32_LE(n,b,i) \
+{ \
+ (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
+ (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
+ (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
+ (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
}
#endif
/*
* RFC 1321 compliant MD5 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/md5.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
#endif
#ifndef PUT_UINT32_LE
-#define PUT_UINT32_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( (n) ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
+#define PUT_UINT32_LE(n,b,i) \
+{ \
+ (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
+ (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
+ (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
+ (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
}
#endif
/*
* RFC 1321 test vectors
*/
-static unsigned char md5_test_buf[7][81] =
+static const unsigned char md5_test_buf[7][81] =
{
{ "" },
{ "a" },
/*
* RFC 2202 test vectors
*/
-static unsigned char md5_hmac_test_key[7][26] =
+static const unsigned char md5_hmac_test_key[7][26] =
{
{ "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B" },
{ "Jefe" },
16, 4, 16, 25, 16, 80, 80
};
-static unsigned char md5_hmac_test_buf[7][74] =
+static const unsigned char md5_hmac_test_buf[7][74] =
{
{ "Hi There" },
{ "what do ya want for nothing?" },
if( i == 5 || i == 6 )
{
- memset( buf, '\xAA', buflen = 80 );
+ memset( buf, 0xAA, buflen = 80 );
md5_hmac_starts( &ctx, buf, buflen );
}
else
/**
* \file md_wrap.c
- * \brief Generic message digest wrapper for PolarSSL
+ * \brief Generic message digest wrapper for mbed TLS
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
static void * ripemd160_ctx_alloc( void )
{
ripemd160_context *ctx;
- ctx = (ripemd160_context *) polarssl_malloc( sizeof( ripemd160_context ) );
+ ctx = polarssl_malloc( sizeof( ripemd160_context ) );
if( ctx == NULL )
return( NULL );
static void * sha1_ctx_alloc( void )
{
sha1_context *ctx;
- ctx = (sha1_context *) polarssl_malloc( sizeof( sha1_context ) );
+ ctx = polarssl_malloc( sizeof( sha1_context ) );
if( ctx == NULL )
return( NULL );
static void * sha256_ctx_alloc( void )
{
sha256_context *ctx;
- ctx = (sha256_context *) polarssl_malloc( sizeof( sha256_context ) );
+ ctx = polarssl_malloc( sizeof( sha256_context ) );
if( ctx == NULL )
return( NULL );
static void * sha512_ctx_alloc( void )
{
sha512_context *ctx;
- ctx = (sha512_context *) polarssl_malloc( sizeof( sha512_context ) );
+ ctx = polarssl_malloc( sizeof( sha512_context ) );
if( ctx == NULL )
return( NULL );
/*
* Buffer-based memory allocator
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-
#include "polarssl/memory_buffer_alloc.h"
+/* No need for the header guard as POLARSSL_MEMORY_BUFFER_ALLOC_C
+ is dependent upon POLARSSL_PLATFORM_C */
+#include "polarssl/platform.h"
+
#include <string.h>
-#if defined(POLARSSL_MEMORY_DEBUG)
-#include <stdio.h>
-#endif
#if defined(POLARSSL_MEMORY_BACKTRACE)
#include <execinfo.h>
#endif
#include "polarssl/threading.h"
#endif
-#if defined(POLARSSL_PLATFORM_C)
-#include "polarssl/platform.h"
-#else
-#define polarssl_fprintf fprintf
-#endif
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
size_t len;
memory_header *first;
memory_header *first_free;
- size_t current_alloc_size;
int verify;
#if defined(POLARSSL_MEMORY_DEBUG)
size_t malloc_count;
polarssl_fprintf( stderr, "FATAL: block in free_list but allocated "
"data\n" );
#endif
- exit( 1 );
+ polarssl_exit( 1 );
}
#if defined(POLARSSL_MEMORY_DEBUG)
#endif
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
}
#endif
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
}
polarssl_fprintf( stderr, "FATAL: polarssl_free() outside of managed "
"space\n" );
#endif
- exit( 1 );
+ polarssl_exit( 1 );
}
p -= sizeof(memory_header);
hdr = (memory_header *) p;
if( verify_header( hdr ) != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
if( hdr->alloc != 1 )
{
polarssl_fprintf( stderr, "FATAL: polarssl_free() on unallocated "
"data\n" );
#endif
- exit( 1 );
+ polarssl_exit( 1 );
}
hdr->alloc = 0;
if( old == NULL )
{
hdr->next_free = heap.first_free;
- heap.first_free->prev_free = hdr;
+ if( heap.first_free != NULL )
+ heap.first_free->prev_free = hdr;
heap.first_free = hdr;
}
#endif
if( ( heap.verify & MEMORY_VERIFY_FREE ) && verify_chain() != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
}
void memory_buffer_set_verify( int verify )
debug_chain();
}
}
+
+void memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks )
+{
+ *max_used = heap.maximum_used;
+ *max_blocks = heap.maximum_header_count;
+}
+
+void memory_buffer_alloc_max_reset( void )
+{
+ heap.maximum_used = 0;
+ heap.maximum_header_count = 0;
+}
+
+void memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks )
+{
+ *cur_used = heap.total_used;
+ *cur_blocks = heap.header_count;
+}
#endif /* POLARSSL_MEMORY_DEBUG */
#if defined(POLARSSL_THREADING_C)
if( (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE )
{
+ /* Adjust len first since buf is used in the computation */
+ len -= POLARSSL_MEMORY_ALIGN_MULTIPLE
+ - (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE;
buf += POLARSSL_MEMORY_ALIGN_MULTIPLE
- (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE;
- len -= (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE;
}
heap.buf = buf;
polarssl_zeroize( &heap, sizeof(buffer_alloc_ctx) );
}
+#if defined(POLARSSL_SELF_TEST)
+static int check_pointer( void *p )
+{
+ if( p == NULL )
+ return( -1 );
+
+ if( (size_t) p % POLARSSL_MEMORY_ALIGN_MULTIPLE != 0 )
+ return( -1 );
+
+ return( 0 );
+}
+
+static int check_all_free( )
+{
+ if(
+#if defined(POLARSSL_MEMORY_DEBUG)
+ heap.total_used != 0 ||
+#endif
+ heap.first != heap.first_free ||
+ (void *) heap.first != (void *) heap.buf )
+ {
+ return( -1 );
+ }
+
+ return( 0 );
+}
+
+#define TEST_ASSERT( condition ) \
+ if( ! (condition) ) \
+ { \
+ if( verbose != 0 ) \
+ polarssl_printf( "failed\n" ); \
+ \
+ ret = 1; \
+ goto cleanup; \
+ }
+
+int memory_buffer_alloc_self_test( int verbose )
+{
+ unsigned char buf[1024];
+ unsigned char *p, *q, *r, *end;
+ int ret = 0;
+
+ if( verbose != 0 )
+ polarssl_printf( " MBA test #1 (basic alloc-free cycle): " );
+
+ memory_buffer_alloc_init( buf, sizeof( buf ) );
+
+ p = polarssl_malloc( 1 );
+ q = polarssl_malloc( 128 );
+ r = polarssl_malloc( 16 );
+
+ TEST_ASSERT( check_pointer( p ) == 0 &&
+ check_pointer( q ) == 0 &&
+ check_pointer( r ) == 0 );
+
+ polarssl_free( r );
+ polarssl_free( q );
+ polarssl_free( p );
+
+ TEST_ASSERT( check_all_free( ) == 0 );
+
+ /* Memorize end to compare with the next test */
+ end = heap.buf + heap.len;
+
+ memory_buffer_alloc_free( );
+
+ if( verbose != 0 )
+ polarssl_printf( "passed\n" );
+
+ if( verbose != 0 )
+ polarssl_printf( " MBA test #2 (buf not aligned): " );
+
+ memory_buffer_alloc_init( buf + 1, sizeof( buf ) - 1 );
+
+ TEST_ASSERT( heap.buf + heap.len == end );
+
+ p = polarssl_malloc( 1 );
+ q = polarssl_malloc( 128 );
+ r = polarssl_malloc( 16 );
+
+ TEST_ASSERT( check_pointer( p ) == 0 &&
+ check_pointer( q ) == 0 &&
+ check_pointer( r ) == 0 );
+
+ polarssl_free( r );
+ polarssl_free( q );
+ polarssl_free( p );
+
+ TEST_ASSERT( check_all_free( ) == 0 );
+
+ memory_buffer_alloc_free( );
+
+ if( verbose != 0 )
+ polarssl_printf( "passed\n" );
+
+ if( verbose != 0 )
+ polarssl_printf( " MBA test #3 (full): " );
+
+ memory_buffer_alloc_init( buf, sizeof( buf ) );
+
+ p = polarssl_malloc( sizeof( buf ) - sizeof( memory_header ) );
+
+ TEST_ASSERT( check_pointer( p ) == 0 );
+ TEST_ASSERT( polarssl_malloc( 1 ) == NULL );
+
+ polarssl_free( p );
+
+ p = polarssl_malloc( sizeof( buf ) - 2 * sizeof( memory_header ) - 16 );
+ q = polarssl_malloc( 16 );
+
+ TEST_ASSERT( check_pointer( p ) == 0 && check_pointer( q ) == 0 );
+ TEST_ASSERT( polarssl_malloc( 1 ) == NULL );
+
+ polarssl_free( q );
+
+ TEST_ASSERT( polarssl_malloc( 17 ) == NULL );
+
+ polarssl_free( p );
+
+ TEST_ASSERT( check_all_free( ) == 0 );
+
+ memory_buffer_alloc_free( );
+
+ if( verbose != 0 )
+ polarssl_printf( "passed\n" );
+
+cleanup:
+ memory_buffer_alloc_free( );
+
+ return( ret );
+}
+#endif /* POLARSSL_SELF_TEST */
+
#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */
/*
* TCP networking functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/net.h"
+#include <string.h>
+
#if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(EFIX64) && \
!defined(EFI32)
(((unsigned long )(n) & 0xFF000000) >> 24))
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_snprintf snprintf
+#endif
+
unsigned short net_htons( unsigned short n );
unsigned long net_htonl( unsigned long n );
#define net_htons(n) POLARSSL_HTONS(n)
/* getaddrinfo expects port as a string */
memset( port_str, 0, sizeof( port_str ) );
- snprintf( port_str, sizeof( port_str ), "%d", port );
+ polarssl_snprintf( port_str, sizeof( port_str ), "%d", port );
/* Do name resolution with both IPv6 and IPv4, but only TCP */
memset( &hints, 0, sizeof( hints ) );
/* getaddrinfo expects port as a string */
memset( port_str, 0, sizeof( port_str ) );
- snprintf( port_str, sizeof( port_str ), "%d", port );
+ polarssl_snprintf( port_str, sizeof( port_str ), "%d", port );
/* Bind to IPv6 and/or IPv4, but only in TCP */
memset( &hints, 0, sizeof( hints ) );
void net_usleep( unsigned long usec )
{
struct timeval tv;
- tv.tv_sec = 0;
+ tv.tv_sec = usec / 1000000;
#if !defined(_WIN32) && ( defined(__unix__) || defined(__unix) || \
( defined(__APPLE__) && defined(__MACH__) ) )
- tv.tv_usec = (suseconds_t) usec;
+ tv.tv_usec = (suseconds_t) usec % 1000000;
#else
- tv.tv_usec = usec;
+ tv.tv_usec = usec % 1000000;
#endif
select( 0, NULL, NULL, NULL, &tv );
}
*
* \brief Object Identifier (OID) database
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/oid.h"
#include "polarssl/rsa.h"
+#include <stdio.h>
+#include <string.h>
+
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_snprintf snprintf
+#endif
+
#if defined(POLARSSL_X509_USE_C) || defined(POLARSSL_X509_CREATE_C)
#include "polarssl/x509.h"
#endif
-#include <stdio.h>
-
/*
* Macro to automatically add the size of #define'd OIDs
*/
{ ADD_LEN( OID_DOMAIN_COMPONENT ), "id-domainComponent", "Domain component" },
"DC",
},
+ {
+ { ADD_LEN( OID_AT_UNIQUE_IDENTIFIER ), "id-at-uniqueIdentifier", "Unique Identifier" },
+ "uniqueIdentifier",
+ },
{
{ NULL, 0, NULL, NULL },
NULL,
},
{
{ NULL, 0, NULL, NULL },
- 0, 0,
+ POLARSSL_MD_NONE, POLARSSL_PK_NONE,
},
};
},
{
{ NULL, 0, NULL, NULL },
- 0,
+ POLARSSL_PK_NONE,
},
};
},
{
{ NULL, 0, NULL, NULL },
- 0,
+ POLARSSL_ECP_DP_NONE,
},
};
},
{
{ NULL, 0, NULL, NULL },
- 0,
+ POLARSSL_CIPHER_NONE,
},
};
},
{
{ NULL, 0, NULL, NULL },
- 0,
+ POLARSSL_MD_NONE,
},
};
},
{
{ NULL, 0, NULL, NULL },
- 0, 0,
+ POLARSSL_MD_NONE, POLARSSL_CIPHER_NONE,
},
};
/* First byte contains first two dots */
if( oid->len > 0 )
{
- ret = snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
+ ret = polarssl_snprintf( p, n, "%d.%d", oid->p[0] / 40, oid->p[0] % 40 );
SAFE_SNPRINTF();
}
if( !( oid->p[i] & 0x80 ) )
{
/* Last byte */
- ret = snprintf( p, n, ".%d", value );
+ ret = polarssl_snprintf( p, n, ".%d", value );
SAFE_SNPRINTF();
value = 0;
}
/*
* VIA PadLock support functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/padlock.h"
+#include <string.h>
+
#if defined(POLARSSL_HAVE_X86)
/*
"movl %1, %%ebx \n\t"
: "=m" (ebx)
: "m" (ebx), "m" (ctrl), "m" (rk), "m" (blk)
- : "ecx", "edx", "esi", "edi" );
+ : "memory", "ecx", "edx", "esi", "edi" );
memcpy( output, blk, 16 );
: "=m" (ebx)
: "m" (ebx), "m" (count), "m" (ctrl),
"m" (rk), "m" (input), "m" (output), "m" (iw)
- : "eax", "ecx", "edx", "esi", "edi" );
+ : "memory", "eax", "ecx", "edx", "esi", "edi" );
memcpy( iv, iw, 16 );
/**
* \file pbkdf2.c
*
- * \brief Password-Based Key Derivation Function 2 (from PKCS#5)
- * DEPRECATED: Use pkcs5.c instead
+ * \brief Compatibility wrappers for pkcs5.c
*
* \author Mathias Olsson <mathias@kompetensum.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/pbkdf2.h"
#include "polarssl/pkcs5.h"
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
int pbkdf2_hmac( md_context_t *ctx, const unsigned char *password, size_t plen,
const unsigned char *salt, size_t slen,
unsigned int iteration_count,
return pkcs5_pbkdf2_hmac( ctx, password, plen, salt, slen, iteration_count,
key_length, output );
}
+#endif
#if defined(POLARSSL_SELF_TEST)
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
int pbkdf2_self_test( int verbose )
{
return pkcs5_self_test( verbose );
}
+#endif
#endif /* POLARSSL_SELF_TEST */
#endif /* POLARSSL_PBKDF2_C */
/*
* Privacy Enhanced Mail (PEM) decoding
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
#if defined(POLARSSL_PEM_PARSE_C) || defined(POLARSSL_PEM_WRITE_C)
+
#include "polarssl/pem.h"
#include "polarssl/base64.h"
#include "polarssl/des.h"
#include "polarssl/md5.h"
#include "polarssl/cipher.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
return( POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT );
s1 += strlen( header );
+ if( *s1 == ' ' ) s1++;
if( *s1 == '\r' ) s1++;
if( *s1 == '\n' ) s1++;
else return( POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT );
end = s2;
end += strlen( footer );
+ if( *end == ' ' ) end++;
if( *end == '\r' ) end++;
if( *end == '\n' ) end++;
*use_len = end - data;
if( ret == POLARSSL_ERR_BASE64_INVALID_CHARACTER )
return( POLARSSL_ERR_PEM_INVALID_DATA + ret );
- if( ( buf = (unsigned char *) polarssl_malloc( len ) ) == NULL )
+ if( ( buf = polarssl_malloc( len ) ) == NULL )
return( POLARSSL_ERR_PEM_MALLOC_FAILED );
if( ( ret = base64_decode( buf, &len, s1, s2 - s1 ) ) != 0 )
/*
* Public Key abstraction layer
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
#if defined(POLARSSL_PK_C)
-
#include "polarssl/pk.h"
#include "polarssl/pk_wrap.h"
output, olen, osize, f_rng, p_rng ) );
}
+/*
+ * Check public-private key pair
+ */
+int pk_check_pair( const pk_context *pub, const pk_context *prv )
+{
+ if( pub == NULL || pub->pk_info == NULL ||
+ prv == NULL || prv->pk_info == NULL ||
+ prv->pk_info->check_pair_func == NULL )
+ {
+ return( POLARSSL_ERR_PK_BAD_INPUT_DATA );
+ }
+
+ if( prv->pk_info->type == POLARSSL_PK_RSA_ALT )
+ {
+ if( pub->pk_info->type != POLARSSL_PK_RSA )
+ return( POLARSSL_ERR_PK_TYPE_MISMATCH );
+ }
+ else
+ {
+ if( pub->pk_info != prv->pk_info )
+ return( POLARSSL_ERR_PK_TYPE_MISMATCH );
+ }
+
+ return( prv->pk_info->check_pair_func( pub->pk_ctx, prv->pk_ctx ) );
+}
+
/*
* Get key size in bits
*/
/*
* Public Key abstraction layer: wrapper functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif
#if defined(POLARSSL_PK_C)
-
#include "polarssl/pk_wrap.h"
/* Even if RSA not activated, for the sake of RSA-alt */
#include "polarssl/rsa.h"
+#include <string.h>
+
#if defined(POLARSSL_ECP_C)
#include "polarssl/ecp.h"
#endif
unsigned char *output, size_t *olen, size_t osize,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
- ((void) osize);
-
*olen = ((rsa_context *) ctx)->len;
+ if( *olen > osize )
+ return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
+
return( rsa_pkcs1_encrypt( (rsa_context *) ctx,
f_rng, p_rng, RSA_PUBLIC, ilen, input, output ) );
}
+static int rsa_check_pair_wrap( const void *pub, const void *prv )
+{
+ return( rsa_check_pub_priv( (const rsa_context *) pub,
+ (const rsa_context *) prv ) );
+}
+
static void *rsa_alloc_wrap( void )
{
void *ctx = polarssl_malloc( sizeof( rsa_context ) );
rsa_sign_wrap,
rsa_decrypt_wrap,
rsa_encrypt_wrap,
+ rsa_check_pair_wrap,
rsa_alloc_wrap,
rsa_free_wrap,
rsa_debug,
#endif /* POLARSSL_ECDSA_C */
+static int eckey_check_pair( const void *pub, const void *prv )
+{
+ return( ecp_check_pub_priv( (const ecp_keypair *) pub,
+ (const ecp_keypair *) prv ) );
+}
+
static void *eckey_alloc_wrap( void )
{
void *ctx = polarssl_malloc( sizeof( ecp_keypair ) );
#endif
NULL,
NULL,
+ eckey_check_pair,
eckey_alloc_wrap,
eckey_free_wrap,
eckey_debug,
NULL,
NULL,
NULL,
+ eckey_check_pair,
eckey_alloc_wrap, /* Same underlying key structure */
eckey_free_wrap, /* Same underlying key structure */
eckey_debug, /* Same underlying key structure */
ecdsa_sign_wrap,
NULL,
NULL,
+ eckey_check_pair, /* Compatible key structures */
ecdsa_alloc_wrap,
ecdsa_free_wrap,
eckey_debug, /* Compatible key structures */
RSA_PRIVATE, olen, input, output, osize ) );
}
+#if defined(POLARSSL_RSA_C)
+static int rsa_alt_check_pair( const void *pub, const void *prv )
+{
+ unsigned char sig[POLARSSL_MPI_MAX_SIZE];
+ unsigned char hash[32];
+ size_t sig_len = 0;
+ int ret;
+
+ if( rsa_alt_get_size( prv ) != rsa_get_size( pub ) )
+ return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
+
+ memset( hash, 0x2a, sizeof( hash ) );
+
+ if( ( ret = rsa_alt_sign_wrap( (void *) prv, POLARSSL_MD_NONE,
+ hash, sizeof( hash ),
+ sig, &sig_len, NULL, NULL ) ) != 0 )
+ {
+ return( ret );
+ }
+
+ if( rsa_verify_wrap( (void *) pub, POLARSSL_MD_NONE,
+ hash, sizeof( hash ), sig, sig_len ) != 0 )
+ {
+ return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
+ }
+
+ return( 0 );
+}
+#endif /* POLARSSL_RSA_C */
+
static void *rsa_alt_alloc_wrap( void )
{
void *ctx = polarssl_malloc( sizeof( rsa_alt_context ) );
rsa_alt_sign_wrap,
rsa_alt_decrypt_wrap,
NULL,
+#if defined(POLARSSL_RSA_C)
+ rsa_alt_check_pair,
+#else
+ NULL,
+#endif
rsa_alt_alloc_wrap,
rsa_alt_free_wrap,
NULL,
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/pkcs11.h"
#if defined(POLARSSL_PKCS11_C)
+
#include "polarssl/md.h"
#include "polarssl/oid.h"
#include "polarssl/x509_crt.h"
/*
* PKCS#12 Personal Information Exchange Syntax
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1.h"
#include "polarssl/cipher.h"
+#include <string.h>
+
#if defined(POLARSSL_ARC4_C)
#include "polarssl/arc4.h"
#endif
if( ( ret = cipher_init_ctx( &cipher_ctx, cipher_info ) ) != 0 )
goto exit;
- if( ( ret = cipher_setkey( &cipher_ctx, key, 8 * keylen, mode ) ) != 0 )
+ if( ( ret = cipher_setkey( &cipher_ctx, key, 8 * keylen, (operation_t) mode ) ) != 0 )
goto exit;
if( ( ret = cipher_set_iv( &cipher_ctx, iv, cipher_info->iv_size ) ) != 0 )
*
* \author Mathias Olsson <mathias@kompetensum.com>
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/cipher.h"
#include "polarssl/oid.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
#endif
if( ( ret = cipher_init_ctx( &cipher_ctx, cipher_info ) ) != 0 )
goto exit;
- if( ( ret = cipher_setkey( &cipher_ctx, key, 8 * keylen, mode ) ) != 0 )
+ if( ( ret = cipher_setkey( &cipher_ctx, key, 8 * keylen, (operation_t) mode ) ) != 0 )
goto exit;
if( ( ret = cipher_crypt( &cipher_ctx, iv, enc_scheme_params.len,
}
#else
-#include <stdio.h>
-
#define MAX_TESTS 6
-size_t plen[MAX_TESTS] =
- { 8, 8, 8, 8, 24, 9 };
+static const size_t plen[MAX_TESTS] =
+ { 8, 8, 8, 24, 9 };
-unsigned char password[MAX_TESTS][32] =
+static const unsigned char password[MAX_TESTS][32] =
{
"password",
"password",
"password",
- "password",
"passwordPASSWORDpassword",
"pass\0word",
};
-size_t slen[MAX_TESTS] =
- { 4, 4, 4, 4, 36, 5 };
+static const size_t slen[MAX_TESTS] =
+ { 4, 4, 4, 36, 5 };
-unsigned char salt[MAX_TESTS][40] =
+static const unsigned char salt[MAX_TESTS][40] =
{
"salt",
"salt",
"salt",
- "salt",
"saltSALTsaltSALTsaltSALTsaltSALTsalt",
"sa\0lt",
};
-uint32_t it_cnt[MAX_TESTS] =
- { 1, 2, 4096, 16777216, 4096, 4096 };
-
-uint32_t key_len[MAX_TESTS] =
- { 20, 20, 20, 20, 25, 16 };
+static const uint32_t it_cnt[MAX_TESTS] =
+ { 1, 2, 4096, 4096, 4096 };
+static const uint32_t key_len[MAX_TESTS] =
+ { 20, 20, 20, 25, 16 };
-unsigned char result_key[MAX_TESTS][32] =
+static const unsigned char result_key[MAX_TESTS][32] =
{
{ 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
{ 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
0x65, 0xa4, 0x29, 0xc1 },
- { 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4,
- 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c,
- 0x26, 0x34, 0xe9, 0x84 },
{ 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
goto exit;
}
- if( verbose != 0 )
- polarssl_printf( " PBKDF2 note: test #3 may be slow!\n" );
-
for( i = 0; i < MAX_TESTS; i++ )
{
if( verbose != 0 )
/*
* Public Key layer for parsing key files and structures
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1.h"
#include "polarssl/oid.h"
+#include <string.h>
+
#if defined(POLARSSL_RSA_C)
#include "polarssl/rsa.h"
#endif
/*
* Load all data from a file into a given buffer.
*/
-static int load_file( const char *path, unsigned char **buf, size_t *n )
+int pk_load_file( const char *path, unsigned char **buf, size_t *n )
{
FILE *f;
long size;
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
+ ( *buf = polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( POLARSSL_ERR_PK_MALLOC_FAILED );
size_t n;
unsigned char *buf;
- if( ( ret = load_file( path, &buf, &n ) ) != 0 )
+ if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
if( pwd == NULL )
size_t n;
unsigned char *buf;
- if( ( ret = load_file( path, &buf, &n ) ) != 0 )
+ if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = pk_parse_public_key( ctx, buf, n );
/*
* order INTEGER
*/
- if( ( ret = asn1_get_mpi( &p, end, &grp->N ) ) )
+ if( ( ret = asn1_get_mpi( &p, end, &grp->N ) ) != 0 )
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
grp->nbits = mpi_msb( &grp->N );
p += len;
- /*
- * Is 'parameters' present?
- */
- if( ( ret = asn1_get_tag( &p, end, &len,
- ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 0 ) ) == 0 )
+ pubkey_done = 0;
+ if( p != end )
{
- if( ( ret = pk_get_ecparams( &p, p + len, ¶ms) ) != 0 ||
- ( ret = pk_use_ecparams( ¶ms, &eck->grp ) ) != 0 )
+ /*
+ * Is 'parameters' present?
+ */
+ if( ( ret = asn1_get_tag( &p, end, &len,
+ ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 0 ) ) == 0 )
{
- ecp_keypair_free( eck );
- return( ret );
+ if( ( ret = pk_get_ecparams( &p, p + len, ¶ms) ) != 0 ||
+ ( ret = pk_use_ecparams( ¶ms, &eck->grp ) ) != 0 )
+ {
+ ecp_keypair_free( eck );
+ return( ret );
+ }
}
- }
- else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
- {
- ecp_keypair_free( eck );
- return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
- }
-
- /*
- * Is 'publickey' present? If not, or if we can't read it (eg because it
- * is compressed), create it from the private key.
- */
- pubkey_done = 0;
- if( ( ret = asn1_get_tag( &p, end, &len,
- ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 1 ) ) == 0 )
- {
- end2 = p + len;
-
- if( ( ret = asn1_get_bitstring_null( &p, end2, &len ) ) != 0 )
+ else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
+ {
+ ecp_keypair_free( eck );
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
+ }
- if( p + len != end2 )
- return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT +
- POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
-
- if( ( ret = pk_get_ecpubkey( &p, end2, eck ) ) == 0 )
- pubkey_done = 1;
- else
+ /*
+ * Is 'publickey' present? If not, or if we can't read it (eg because it
+ * is compressed), create it from the private key.
+ */
+ if( ( ret = asn1_get_tag( &p, end, &len,
+ ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 1 ) ) == 0 )
{
- /*
- * The only acceptable failure mode of pk_get_ecpubkey() above
- * is if the point format is not recognized.
- */
- if( ret != POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE )
- return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT );
+ end2 = p + len;
+
+ if( ( ret = asn1_get_bitstring_null( &p, end2, &len ) ) != 0 )
+ return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
+
+ if( p + len != end2 )
+ return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT +
+ POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
+
+ if( ( ret = pk_get_ecpubkey( &p, end2, eck ) ) == 0 )
+ pubkey_done = 1;
+ else
+ {
+ /*
+ * The only acceptable failure mode of pk_get_ecpubkey() above
+ * is if the point format is not recognized.
+ */
+ if( ret != POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE )
+ return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT );
+ }
+ }
+ else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
+ {
+ ecp_keypair_free( eck );
+ return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
}
- }
- else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
- {
- ecp_keypair_free( eck );
- return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
}
if( ! pubkey_done &&
/*
* Parse an encrypted PKCS#8 encoded private key
*/
+#if defined(POLARSSL_PKCS12_C) || defined(POLARSSL_PKCS5_C)
static int pk_parse_key_pkcs8_encrypted_der(
pk_context *pk,
const unsigned char *key, size_t keylen,
return( pk_parse_key_pkcs8_unencrypted_der( pk, buf, len ) );
}
+#endif /* POLARSSL_PKCS12_C || POLARSSL_PKCS5_C */
/*
* Parse a private key
else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
return( ret );
+#if defined(POLARSSL_PKCS12_C) || defined(POLARSSL_PKCS5_C)
ret = pem_read_buffer( &pem,
"-----BEGIN ENCRYPTED PRIVATE KEY-----",
"-----END ENCRYPTED PRIVATE KEY-----",
}
else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
return( ret );
+#endif /* POLARSSL_PKCS12_C || POLARSSL_PKCS5_C */
#else
((void) pwd);
((void) pwdlen);
* We try the different DER format parsers to see if one passes without
* error
*/
+#if defined(POLARSSL_PKCS12_C) || defined(POLARSSL_PKCS5_C)
if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, key, keylen,
pwd, pwdlen ) ) == 0 )
{
{
return( ret );
}
+#endif /* POLARSSL_PKCS12_C || POLARSSL_PKCS5_C */
if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen ) ) == 0 )
return( 0 );
/*
* Public Key layer for writing key files and structures
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1write.h"
#include "polarssl/oid.h"
+#include <string.h>
+
#if defined(POLARSSL_RSA_C)
#include "polarssl/rsa.h"
#endif
/*
* Platform abstraction layer
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
#endif /* POLARSSL_PLATFORM_MEMORY */
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
+#if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
+/*
+ * Make dummy function to prevent NULL pointer dereferences
+ */
+static int platform_snprintf_uninit( char * s, size_t n,
+ const char * format, ... )
+{
+ ((void) s);
+ ((void) n);
+ ((void) format);
+ return( 0 );
+}
+
+#define POLARSSL_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
+#endif /* !POLARSSL_PLATFORM_STD_SNPRINTF */
+
+int (*polarssl_snprintf)( char * s, size_t n,
+ const char * format,
+ ... ) = POLARSSL_PLATFORM_STD_SNPRINTF;
+
+int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
+ const char * format,
+ ... ) )
+{
+ polarssl_snprintf = snprintf_func;
+ return( 0 );
+}
+#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
/*
}
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_EXIT_ALT)
+#if !defined(POLARSSL_PLATFORM_STD_EXIT)
+/*
+ * Make dummy function to prevent NULL pointer dereferences
+ */
+static void platform_exit_uninit( int status )
+{
+ ((void) status);
+}
+
+#define POLARSSL_PLATFORM_STD_EXIT platform_exit_uninit
+#endif /* !POLARSSL_PLATFORM_STD_EXIT */
+
+void (*polarssl_exit)( int status ) = POLARSSL_PLATFORM_STD_EXIT;
+
+int platform_set_exit( void (*exit_func)( int status ) )
+{
+ polarssl_exit = exit_func;
+ return( 0 );
+}
+#endif /* POLARSSL_PLATFORM_EXIT_ALT */
+
#endif /* POLARSSL_PLATFORM_C */
/*
* RIPE MD-160 implementation
*
- * Copyright (C) 2014-2014, Brainspark B.V.
+ * Copyright (C) 2014-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ripemd160.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
#if defined(POLARSSL_SELF_TEST)
-#include <string.h>
-#endif
-
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/*
* 32-bit integer manipulation macros (little endian)
#endif
#ifndef PUT_UINT32_LE
-#define PUT_UINT32_LE(n,b,i) \
-{ \
- (b)[(i) ] = (unsigned char) ( (n) ); \
- (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
- (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
- (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
+#define PUT_UINT32_LE(n,b,i) \
+{ \
+ (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
+ (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
+ (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
+ (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
}
#endif
/*
* The RSA public-key cryptosystem
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/rsa.h"
#include "polarssl/oid.h"
+#include <string.h>
+
#if defined(POLARSSL_PKCS1_V21)
#include "polarssl/md.h"
#endif
+#if defined(POLARSSL_PKCS1_V15) && !defined(__OpenBSD__)
#include <stdlib.h>
-#include <stdio.h>
+#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
#endif
return( 0 );
}
+/*
+ * Check if contexts holding a public and private key match
+ */
+int rsa_check_pub_priv( const rsa_context *pub, const rsa_context *prv )
+{
+ if( rsa_check_pubkey( pub ) != 0 ||
+ rsa_check_privkey( prv ) != 0 )
+ {
+ return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
+ }
+
+ if( mpi_cmp_mpi( &pub->N, &prv->N ) != 0 ||
+ mpi_cmp_mpi( &pub->E, &prv->E ) != 0 )
+ {
+ return( POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
+ }
+
+ return( 0 );
+}
+
/*
* Do an RSA public key operation
*/
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
}
+#if defined(POLARSSL_THREADING_C)
+ polarssl_mutex_lock( &ctx->mutex );
+#endif
+
olen = ctx->len;
MPI_CHK( mpi_exp_mod( &T, &T, &ctx->E, &ctx->N, &ctx->RN ) );
MPI_CHK( mpi_write_binary( &T, output, olen ) );
cleanup:
+#if defined(POLARSSL_THREADING_C)
+ polarssl_mutex_unlock( &ctx->mutex );
+#endif
mpi_free( &T );
return( 0 );
}
-#if !defined(POLARSSL_RSA_NO_CRT)
/*
* Generate or update blinding values, see section 10 of:
* KOCHER, Paul C. Timing attacks on implementations of Diffie-Hellman, RSA,
return( ret );
}
-#endif /* !POLARSSL_RSA_NO_CRT */
/*
* Do an RSA private key operation
int ret;
size_t olen;
mpi T, T1, T2;
-#if !defined(POLARSSL_RSA_NO_CRT)
mpi *Vi, *Vf;
/*
Vi = &ctx->Vi;
Vf = &ctx->Vf;
#endif
-#endif /* !POLARSSL_RSA_NO_CRT */
mpi_init( &T ); mpi_init( &T1 ); mpi_init( &T2 );
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
}
-#if defined(POLARSSL_RSA_NO_CRT)
- ((void) f_rng);
- ((void) p_rng);
- MPI_CHK( mpi_exp_mod( &T, &T, &ctx->D, &ctx->N, &ctx->RN ) );
-#else
if( f_rng != NULL )
{
/*
MPI_CHK( mpi_mod_mpi( &T, &T, &ctx->N ) );
}
+#if defined(POLARSSL_THREADING_C)
+ polarssl_mutex_lock( &ctx->mutex );
+#endif
+
+#if defined(POLARSSL_RSA_NO_CRT)
+ MPI_CHK( mpi_exp_mod( &T, &T, &ctx->D, &ctx->N, &ctx->RN ) );
+#else
/*
* faster decryption using the CRT
*
*/
MPI_CHK( mpi_mul_mpi( &T1, &T, &ctx->Q ) );
MPI_CHK( mpi_add_mpi( &T, &T2, &T1 ) );
+#endif /* POLARSSL_RSA_NO_CRT */
if( f_rng != NULL )
{
MPI_CHK( mpi_mul_mpi( &T, &T, Vf ) );
MPI_CHK( mpi_mod_mpi( &T, &T, &ctx->N ) );
}
-#endif /* POLARSSL_RSA_NO_CRT */
olen = ctx->len;
MPI_CHK( mpi_write_binary( &T, output, olen ) );
cleanup:
- mpi_free( &T ); mpi_free( &T1 ); mpi_free( &T2 );
-#if !defined(POLARSSL_RSA_NO_CRT) && defined(POLARSSL_THREADING_C)
+#if defined(POLARSSL_THREADING_C)
+ polarssl_mutex_unlock( &ctx->mutex );
mpi_free( &Vi_copy ); mpi_free( &Vf_copy );
#endif
+ mpi_free( &T ); mpi_free( &T1 ); mpi_free( &T2 );
if( ret != 0 )
return( POLARSSL_ERR_RSA_PRIVATE_FAILED + ret );
if( f_rng == NULL )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
- md_info = md_info_from_type( ctx->hash_id );
+ md_info = md_info_from_type( (md_type_t) ctx->hash_id );
if( md_info == NULL )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
if( ilen < 16 || ilen > sizeof( buf ) )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
- md_info = md_info_from_type( ctx->hash_id );
+ md_info = md_info_from_type( (md_type_t) ctx->hash_id );
if( md_info == NULL )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
for( i = 0; i < ilen - 2 * hlen - 2; i++ )
{
pad_done |= p[i];
- pad_len += ( pad_done == 0 );
+ pad_len += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1;
}
p += pad_len;
* (minus one, for the 00 byte) */
for( i = 0; i < ilen - 3; i++ )
{
- pad_done |= ( p[i] == 0 );
- pad_count += ( pad_done == 0 );
+ pad_done |= ((p[i] | (unsigned char)-p[i]) >> 7) ^ 1;
+ pad_count += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1;
}
p += pad_count;
hashlen = md_get_size( md_info );
}
- md_info = md_info_from_type( ctx->hash_id );
+ md_info = md_info_from_type( (md_type_t) ctx->hash_id );
if( md_info == NULL )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
MPI_CHK( mpi_copy( &dst->RP, &src->RP ) );
MPI_CHK( mpi_copy( &dst->RQ, &src->RQ ) );
-#if !defined(POLARSSL_RSA_NO_CRT)
MPI_CHK( mpi_copy( &dst->Vi, &src->Vi ) );
MPI_CHK( mpi_copy( &dst->Vf, &src->Vf ) );
-#endif
dst->padding = src->padding;
dst->hash_id = src->hash_id;
*/
void rsa_free( rsa_context *ctx )
{
-#if !defined(POLARSSL_RSA_NO_CRT)
mpi_free( &ctx->Vi ); mpi_free( &ctx->Vf );
-#endif
mpi_free( &ctx->RQ ); mpi_free( &ctx->RP ); mpi_free( &ctx->RN );
mpi_free( &ctx->QP ); mpi_free( &ctx->DQ ); mpi_free( &ctx->DP );
mpi_free( &ctx->Q ); mpi_free( &ctx->P ); mpi_free( &ctx->D );
/*
* FIPS-180-1 compliant SHA-1 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/sha1.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
/*
* FIPS-180-1 test vectors
*/
-static unsigned char sha1_test_buf[3][57] =
+static const unsigned char sha1_test_buf[3][57] =
{
{ "abc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
/*
* RFC 2202 test vectors
*/
-static unsigned char sha1_hmac_test_key[7][26] =
+static const unsigned char sha1_hmac_test_key[7][26] =
{
{ "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
"\x0B\x0B\x0B\x0B" },
20, 4, 20, 25, 20, 80, 80
};
-static unsigned char sha1_hmac_test_buf[7][74] =
+static const unsigned char sha1_hmac_test_buf[7][74] =
{
{ "Hi There" },
{ "what do ya want for nothing?" },
if( i == 5 || i == 6 )
{
- memset( buf, '\xAA', buflen = 80 );
+ memset( buf, 0xAA, buflen = 80 );
sha1_hmac_starts( &ctx, buf, buflen );
}
else
/*
* FIPS-180-2 compliant SHA-256 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/sha256.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
/*
* FIPS-180-2 test vectors
*/
-static unsigned char sha256_test_buf[3][57] =
+static const unsigned char sha256_test_buf[3][57] =
{
{ "abc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
/*
* RFC 4231 test vectors
*/
-static unsigned char sha256_hmac_test_key[7][26] =
+static const unsigned char sha256_hmac_test_key[7][26] =
{
{ "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
"\x0B\x0B\x0B\x0B" },
20, 4, 20, 25, 20, 131, 131
};
-static unsigned char sha256_hmac_test_buf[7][153] =
+static const unsigned char sha256_hmac_test_buf[7][153] =
{
{ "Hi There" },
{ "what do ya want for nothing?" },
if( j == 5 || j == 6 )
{
- memset( buf, '\xAA', buflen = 131 );
+ memset( buf, 0xAA, buflen = 131 );
sha256_hmac_starts( &ctx, buf, buflen, k );
}
else
/*
* FIPS-180-2 compliant SHA-384/512 implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/sha512.h"
-#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
+#if defined(_MSC_VER) || defined(__WATCOMC__)
+ #define UL64(x) x##ui64
+#else
+ #define UL64(x) x##ULL
+#endif
+
+#include <string.h>
+
+#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#endif
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
/*
* FIPS-180-2 test vectors
*/
-static unsigned char sha512_test_buf[3][113] =
+static const unsigned char sha512_test_buf[3][113] =
{
{ "abc" },
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
/*
* RFC 4231 test vectors
*/
-static unsigned char sha512_hmac_test_key[7][26] =
+static const unsigned char sha512_hmac_test_key[7][26] =
{
{ "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
"\x0B\x0B\x0B\x0B" },
20, 4, 20, 25, 20, 131, 131
};
-static unsigned char sha512_hmac_test_buf[7][153] =
+static const unsigned char sha512_hmac_test_buf[7][153] =
{
{ "Hi There" },
{ "what do ya want for nothing?" },
if( j == 5 || j == 6 )
{
- memset( buf, '\xAA', buflen = 131 );
+ memset( buf, 0xAA, buflen = 131 );
sha512_hmac_starts( &ctx, buf, buflen, k );
}
else
/*
* SSL session cache implementation
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ssl_cache.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
void ssl_cache_init( ssl_cache_context *cache )
{
memset( cache, 0, sizeof( ssl_cache_context ) );
*/
if( entry->peer_cert.p != NULL )
{
- session->peer_cert =
- (x509_crt *) polarssl_malloc( sizeof(x509_crt) );
-
- if( session->peer_cert == NULL )
+ if( ( session->peer_cert = polarssl_malloc(
+ sizeof(x509_crt) ) ) == NULL )
{
ret = 1;
goto exit;
/*
* max_entries not reached, create new entry
*/
- cur = (ssl_cache_entry *)
- polarssl_malloc( sizeof(ssl_cache_entry) );
+ cur = polarssl_malloc( sizeof(ssl_cache_entry) );
if( cur == NULL )
{
ret = 1;
*/
if( session->peer_cert != NULL )
{
- cur->peer_cert.p = (unsigned char *)
- polarssl_malloc( session->peer_cert->raw.len );
+ cur->peer_cert.p = polarssl_malloc( session->peer_cert->raw.len );
if( cur->peer_cert.p == NULL )
{
ret = 1;
/**
* \file ssl_ciphersuites.c
*
- * \brief SSL ciphersuites for PolarSSL
+ * \brief SSL ciphersuites for mbed TLS
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/ssl_ciphersuites.h"
#include "polarssl/ssl.h"
-#include <stdlib.h>
+// #include <stdlib.h>
+#include <string.h>
#if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
!defined(EFI32)
#endif /* POLARSSL_DES_C */
#endif /* POLARSSL_ENABLE_WEAK_CIPHERSUITES */
- { 0, "", 0, 0, 0, 0, 0, 0, 0, 0 }
+ { 0, "",
+ POLARSSL_CIPHER_NONE, POLARSSL_MD_NONE, POLARSSL_KEY_EXCHANGE_NONE,
+ 0, 0, 0, 0, 0 }
};
#if defined(SSL_CIPHERSUITES)
/*
* SSLv3/TLSv1 client-side functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/debug.h"
#include "polarssl/ssl.h"
+#include <string.h>
+
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-#include <stdio.h>
-
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
typedef UINT32 uint32_t;
}
#endif /* POLARSSL_SSL_SERVER_NAME_INDICATION */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
static void ssl_write_renegotiation_ext( ssl_context *ssl,
unsigned char *buf,
size_t *olen )
*olen = 5 + ssl->verify_data_len;
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
-#if defined(POLARSSL_SSL_PROTO_TLS1_2)
+/*
+ * Only if we handle at least one key exchange that needs signatures.
+ */
+#if defined(POLARSSL_SSL_PROTO_TLS1_2) && \
+ defined(POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED)
static void ssl_write_signature_algorithms_ext( ssl_context *ssl,
unsigned char *buf,
size_t *olen )
*olen = 6 + sig_alg_len;
}
-#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 &&
+ POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED */
#if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
static void ssl_write_supported_elliptic_curves_ext( ssl_context *ssl,
}
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+static void ssl_write_encrypt_then_mac_ext( ssl_context *ssl,
+ unsigned char *buf, size_t *olen )
+{
+ unsigned char *p = buf;
+
+ if( ssl->encrypt_then_mac == SSL_ETM_DISABLED ||
+ ssl->max_minor_ver == SSL_MINOR_VERSION_0 )
+ {
+ *olen = 0;
+ return;
+ }
+
+ SSL_DEBUG_MSG( 3, ( "client hello, adding encrypt_then_mac "
+ "extension" ) );
+
+ *p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC >> 8 ) & 0xFF );
+ *p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC ) & 0xFF );
+
+ *p++ = 0x00;
+ *p++ = 0x00;
+
+ *olen = 4;
+}
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+static void ssl_write_extended_ms_ext( ssl_context *ssl,
+ unsigned char *buf, size_t *olen )
+{
+ unsigned char *p = buf;
+
+ if( ssl->extended_ms == SSL_EXTENDED_MS_DISABLED ||
+ ssl->max_minor_ver == SSL_MINOR_VERSION_0 )
+ {
+ *olen = 0;
+ return;
+ }
+
+ SSL_DEBUG_MSG( 3, ( "client hello, adding extended_master_secret "
+ "extension" ) );
+
+ *p++ = (unsigned char)( ( TLS_EXT_EXTENDED_MASTER_SECRET >> 8 ) & 0xFF );
+ *p++ = (unsigned char)( ( TLS_EXT_EXTENDED_MASTER_SECRET ) & 0xFF );
+
+ *p++ = 0x00;
+ *p++ = 0x00;
+
+ *olen = 4;
+}
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
static void ssl_write_session_ticket_ext( ssl_context *ssl,
unsigned char *buf, size_t *olen )
return( POLARSSL_ERR_SSL_NO_RNG );
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#endif
{
ssl->major_ver = ssl->min_major_ver;
ssl->minor_ver = ssl->min_minor_ver;
*/
n = ssl->session_negotiate->length;
- if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE || n < 16 || n > 32 ||
+ if( n < 16 || n > 32 ||
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ ssl->renegotiation != SSL_INITIAL_HANDSHAKE ||
+#endif
ssl->handshake->resume == 0 )
{
n = 0;
* RFC 5077 section 3.4: "When presenting a ticket, the client MAY
* generate and include a Session ID in the TLS ClientHello."
*/
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
- ssl->session_negotiate->ticket != NULL &&
- ssl->session_negotiate->ticket_len != 0 )
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#endif
{
- ret = ssl->f_rng( ssl->p_rng, ssl->session_negotiate->id, 32 );
+ if( ssl->session_negotiate->ticket != NULL &&
+ ssl->session_negotiate->ticket_len != 0 )
+ {
+ ret = ssl->f_rng( ssl->p_rng, ssl->session_negotiate->id, 32 );
- if( ret != 0 )
- return( ret );
+ if( ret != 0 )
+ return( ret );
- ssl->session_negotiate->length = n = 32;
+ ssl->session_negotiate->length = n = 32;
+ }
}
#endif /* POLARSSL_SSL_SESSION_TICKETS */
// Skip writing ciphersuite length for now
p += 2;
- /*
- * Add TLS_EMPTY_RENEGOTIATION_INFO_SCSV
- */
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
- {
- *p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO >> 8 );
- *p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO );
- n++;
- }
-
for( i = 0; ciphersuites[i] != 0; i++ )
{
ciphersuite_info = ssl_ciphersuite_from_id( ciphersuites[i] );
ciphersuite_info->max_minor_ver < ssl->min_minor_ver )
continue;
+ if( ssl->arc4_disabled == SSL_ARC4_DISABLED &&
+ ciphersuite_info->cipher == POLARSSL_CIPHER_ARC4_128 )
+ continue;
+
SSL_DEBUG_MSG( 3, ( "client hello, add ciphersuite: %2d",
ciphersuites[i] ) );
*p++ = (unsigned char)( ciphersuites[i] );
}
+ /*
+ * Add TLS_EMPTY_RENEGOTIATION_INFO_SCSV
+ */
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#endif
+ {
+ *p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO >> 8 );
+ *p++ = (unsigned char)( SSL_EMPTY_RENEGOTIATION_INFO );
+ n++;
+ }
+
+ /* Some versions of OpenSSL don't handle it correctly if not at end */
+#if defined(POLARSSL_SSL_FALLBACK_SCSV)
+ if( ssl->fallback == SSL_IS_FALLBACK )
+ {
+ SSL_DEBUG_MSG( 3, ( "adding FALLBACK_SCSV" ) );
+ *p++ = (unsigned char)( SSL_FALLBACK_SCSV >> 8 );
+ *p++ = (unsigned char)( SSL_FALLBACK_SCSV );
+ n++;
+ }
+#endif
+
*q++ = (unsigned char)( n >> 7 );
*q++ = (unsigned char)( n << 1 );
ext_len += olen;
#endif
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl_write_renegotiation_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
+#endif
-#if defined(POLARSSL_SSL_PROTO_TLS1_2)
+#if defined(POLARSSL_SSL_PROTO_TLS1_2) && \
+ defined(POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED)
ssl_write_signature_algorithms_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
#endif
ext_len += olen;
#endif
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ ssl_write_encrypt_then_mac_ext( ssl, p + 2 + ext_len, &olen );
+ ext_len += olen;
+#endif
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ ssl_write_extended_ms_ext( ssl, p + 2 + ext_len, &olen );
+ ext_len += olen;
+#endif
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
ssl_write_session_ticket_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
ext_len += olen;
#endif
+ /* olen unused if all extensions are disabled */
+ ((void) olen);
+
SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %d",
ext_len ) );
{
int ret;
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
{
- if( len != 1 || buf[0] != 0x0 )
+ /* Check verify-data in constant-time. The length OTOH is no secret */
+ if( len != 1 + ssl->verify_data_len * 2 ||
+ buf[0] != ssl->verify_data_len * 2 ||
+ safer_memcmp( buf + 1,
+ ssl->own_verify_data, ssl->verify_data_len ) != 0 ||
+ safer_memcmp( buf + 1 + ssl->verify_data_len,
+ ssl->peer_verify_data, ssl->verify_data_len ) != 0 )
{
- SSL_DEBUG_MSG( 1, ( "non-zero length renegotiated connection field" ) );
+ SSL_DEBUG_MSG( 1, ( "non-matching renegotiation info" ) );
if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
return( ret );
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
}
-
- ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
}
else
+#endif /* POLARSSL_SSL_RENEGOTIATION */
{
- /* Check verify-data in constant-time. The length OTOH is no secret */
- if( len != 1 + ssl->verify_data_len * 2 ||
- buf[0] != ssl->verify_data_len * 2 ||
- safer_memcmp( buf + 1,
- ssl->own_verify_data, ssl->verify_data_len ) != 0 ||
- safer_memcmp( buf + 1 + ssl->verify_data_len,
- ssl->peer_verify_data, ssl->verify_data_len ) != 0 )
+ if( len != 1 || buf[0] != 0x00 )
{
- SSL_DEBUG_MSG( 1, ( "non-matching renegotiated connection field" ) );
+ SSL_DEBUG_MSG( 1, ( "non-zero length renegotiation info" ) );
if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
return( ret );
return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
}
+
+ ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
}
return( 0 );
}
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+static int ssl_parse_encrypt_then_mac_ext( ssl_context *ssl,
+ const unsigned char *buf,
+ size_t len )
+{
+ if( ssl->encrypt_then_mac == SSL_ETM_DISABLED ||
+ ssl->minor_ver == SSL_MINOR_VERSION_0 ||
+ len != 0 )
+ {
+ return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
+ }
+
+ ((void) buf);
+
+ ssl->session_negotiate->encrypt_then_mac = SSL_ETM_ENABLED;
+
+ return( 0 );
+}
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+static int ssl_parse_extended_ms_ext( ssl_context *ssl,
+ const unsigned char *buf,
+ size_t len )
+{
+ if( ssl->extended_ms == SSL_EXTENDED_MS_DISABLED ||
+ ssl->minor_ver == SSL_MINOR_VERSION_0 ||
+ len != 0 )
+ {
+ return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
+ }
+
+ ((void) buf);
+
+ ssl->handshake->extended_ms = SSL_EXTENDED_MS_ENABLED;
+
+ return( 0 );
+}
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
static int ssl_parse_session_ticket_ext( ssl_context *ssl,
const unsigned char *buf,
size_t n;
size_t ext_len;
unsigned char *buf, *ext;
+#if defined(POLARSSL_SSL_RENEGOTIATION)
int renegotiation_info_seen = 0;
+#endif
int handshake_failure = 0;
+ const ssl_ciphersuite_t *suite_info;
#if defined(POLARSSL_DEBUG_C)
uint32_t t;
#endif
if( ssl->in_msgtype != SSL_MSG_HANDSHAKE )
{
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_RENEGOTIATION )
{
ssl->renego_records_seen++;
SSL_DEBUG_MSG( 1, ( "non-handshake message during renego" ) );
return( POLARSSL_ERR_SSL_WAITING_SERVER_HELLO_RENEGO );
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
return( POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE );
/*
* Check if the session can be resumed
*/
- if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE ||
- ssl->handshake->resume == 0 || n == 0 ||
+ if( ssl->handshake->resume == 0 || n == 0 ||
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ ssl->renegotiation != SSL_INITIAL_HANDSHAKE ||
+#endif
ssl->session_negotiate->ciphersuite != i ||
ssl->session_negotiate->compression != comp ||
ssl->session_negotiate->length != n ||
SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %d", i ) );
SSL_DEBUG_MSG( 3, ( "server hello, compress alg.: %d", buf[41 + n] ) );
+ suite_info = ssl_ciphersuite_from_id( ssl->session_negotiate->ciphersuite );
+ if( suite_info == NULL ||
+ ( ssl->arc4_disabled &&
+ suite_info->cipher == POLARSSL_CIPHER_ARC4_128 ) )
+ {
+ SSL_DEBUG_MSG( 1, ( "bad server hello message" ) );
+ return( POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO );
+ }
+
+
i = 0;
while( 1 )
{
{
case TLS_EXT_RENEGOTIATION_INFO:
SSL_DEBUG_MSG( 3, ( "found renegotiation extension" ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
renegotiation_info_seen = 1;
+#endif
if( ( ret = ssl_parse_renegotiation_info( ssl, ext + 4,
ext_size ) ) != 0 )
break;
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ case TLS_EXT_ENCRYPT_THEN_MAC:
+ SSL_DEBUG_MSG( 3, ( "found encrypt_then_mac extension" ) );
+
+ if( ( ret = ssl_parse_encrypt_then_mac_ext( ssl,
+ ext + 4, ext_size ) ) != 0 )
+ {
+ return( ret );
+ }
+
+ break;
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ case TLS_EXT_EXTENDED_MASTER_SECRET:
+ SSL_DEBUG_MSG( 3, ( "found extended_master_secret extension" ) );
+
+ if( ( ret = ssl_parse_extended_ms_ext( ssl,
+ ext + 4, ext_size ) ) != 0 )
+ {
+ return( ret );
+ }
+
+ break;
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
case TLS_EXT_SESSION_TICKET:
SSL_DEBUG_MSG( 3, ( "found session_ticket extension" ) );
SSL_DEBUG_MSG( 1, ( "legacy renegotiation, breaking off handshake" ) );
handshake_failure = 1;
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
else if( ssl->renegotiation == SSL_RENEGOTIATION &&
ssl->secure_renegotiation == SSL_SECURE_RENEGOTIATION &&
renegotiation_info_seen == 0 )
SSL_DEBUG_MSG( 1, ( "renegotiation_info extension present (legacy)" ) );
handshake_failure = 1;
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
if( handshake_failure == 1 )
{
return( ret );
}
- if( ssl->handshake->dhm_ctx.len < 64 ||
+ if( ssl->handshake->dhm_ctx.len < SSL_MIN_DHM_BYTES ||
ssl->handshake->dhm_ctx.len > 512 )
{
SSL_DEBUG_MSG( 1, ( "bad server key exchange message (DHM length)" ) );
SSL_DEBUG_MSG( 2, ( "ECDH curve: %s", curve_info->name ) );
-#if defined(POLARSSL_SSL_ECP_SET_CURVES)
+#if defined(POLARSSL_SSL_SET_CURVES)
if( ! ssl_curve_is_acceptable( ssl, ssl->handshake->ecdh_ctx.grp.id ) )
#else
if( ssl->handshake->ecdh_ctx.grp.nbits < 163 ||
return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
- if( ( ret = ssl_derive_keys( ssl ) ) != 0 )
- {
- SSL_DEBUG_RET( 1, "ssl_derive_keys", ret );
- return( ret );
- }
-
ssl->out_msglen = i + n;
ssl->out_msgtype = SSL_MSG_HANDSHAKE;
ssl->out_msg[0] = SSL_HS_CLIENT_KEY_EXCHANGE;
static int ssl_write_certificate_verify( ssl_context *ssl )
{
const ssl_ciphersuite_t *ciphersuite_info = ssl->transform_negotiate->ciphersuite_info;
+ int ret;
SSL_DEBUG_MSG( 2, ( "=> write certificate verify" ) );
+ if( ( ret = ssl_derive_keys( ssl ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_derive_keys", ret );
+ return( ret );
+ }
+
if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_PSK ||
ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_RSA_PSK ||
ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_ECDHE_PSK ||
SSL_DEBUG_MSG( 2, ( "=> write certificate verify" ) );
+ if( ( ret = ssl_derive_keys( ssl ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_derive_keys", ret );
+ return( ret );
+ }
+
if( ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_PSK ||
ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_RSA_PSK ||
ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_ECDHE_PSK ||
/*
* SSLv3/TLSv1 server-side functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/debug.h"
#include "polarssl/ssl.h"
+
+#include <string.h>
+
#if defined(POLARSSL_ECP_C)
#include "polarssl/ecp.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-#include <stdio.h>
-
#if defined(POLARSSL_HAVE_TIME)
#include <time.h>
#endif
{
int ret;
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
{
- if( len != 1 || buf[0] != 0x0 )
+ /* Check verify-data in constant-time. The length OTOH is no secret */
+ if( len != 1 + ssl->verify_data_len ||
+ buf[0] != ssl->verify_data_len ||
+ safer_memcmp( buf + 1, ssl->peer_verify_data,
+ ssl->verify_data_len ) != 0 )
{
- SSL_DEBUG_MSG( 1, ( "non-zero length renegotiated connection field" ) );
+ SSL_DEBUG_MSG( 1, ( "non-matching renegotiation info" ) );
if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
return( ret );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
-
- ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
}
else
+#endif /* POLARSSL_SSL_RENEGOTIATION */
{
- /* Check verify-data in constant-time. The length OTOH is no secret */
- if( len != 1 + ssl->verify_data_len ||
- buf[0] != ssl->verify_data_len ||
- safer_memcmp( buf + 1, ssl->peer_verify_data,
- ssl->verify_data_len ) != 0 )
+ if( len != 1 || buf[0] != 0x0 )
{
- SSL_DEBUG_MSG( 1, ( "non-matching renegotiated connection field" ) );
+ SSL_DEBUG_MSG( 1, ( "non-zero length renegotiation info" ) );
if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
return( ret );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
+
+ ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
}
return( 0 );
}
-#if defined(POLARSSL_SSL_PROTO_TLS1_2)
+#if defined(POLARSSL_SSL_PROTO_TLS1_2) && \
+ defined(POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED)
static int ssl_parse_signature_algorithms_ext( ssl_context *ssl,
const unsigned char *buf,
size_t len )
return( 0 );
}
-#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 &&
+ POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED */
#if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
static int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
((void) buf);
- ssl->session_negotiate->trunc_hmac = SSL_TRUNC_HMAC_ENABLED;
+ if( ssl->trunc_hmac == SSL_TRUNC_HMAC_ENABLED )
+ ssl->session_negotiate->trunc_hmac = SSL_TRUNC_HMAC_ENABLED;
return( 0 );
}
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+static int ssl_parse_encrypt_then_mac_ext( ssl_context *ssl,
+ const unsigned char *buf,
+ size_t len )
+{
+ if( len != 0 )
+ {
+ SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
+ return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
+ }
+
+ ((void) buf);
+
+ if( ssl->encrypt_then_mac == SSL_ETM_ENABLED &&
+ ssl->minor_ver != SSL_MINOR_VERSION_0 )
+ {
+ ssl->session_negotiate->encrypt_then_mac = SSL_ETM_ENABLED;
+ }
+
+ return( 0 );
+}
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+static int ssl_parse_extended_ms_ext( ssl_context *ssl,
+ const unsigned char *buf,
+ size_t len )
+{
+ if( len != 0 )
+ {
+ SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
+ return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
+ }
+
+ ((void) buf);
+
+ if( ssl->extended_ms == SSL_EXTENDED_MS_ENABLED &&
+ ssl->minor_ver != SSL_MINOR_VERSION_0 )
+ {
+ ssl->handshake->extended_ms = SSL_EXTENDED_MS_ENABLED;
+ }
+
+ return( 0 );
+}
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
static int ssl_parse_session_ticket_ext( ssl_context *ssl,
unsigned char *buf,
if( len == 0 )
return( 0 );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
{
SSL_DEBUG_MSG( 3, ( "ticket rejected: renegotiating" ) );
return( 0 );
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
/*
* Failures are ok: just ignore the ticket and proceed.
#if defined(POLARSSL_X509_CRT_PARSE_C)
/*
- * Return 1 if the given EC key uses the given curve, 0 otherwise
+ * Return 0 if the given key uses one of the acceptable curves, -1 otherwise
*/
#if defined(POLARSSL_ECDSA_C)
-static int ssl_key_matches_curves( pk_context *pk,
- const ecp_curve_info **curves )
+static int ssl_check_key_curve( pk_context *pk,
+ const ecp_curve_info **curves )
{
const ecp_curve_info **crv = curves;
ecp_group_id grp_id = pk_ec( *pk )->grp.id;
while( *crv != NULL )
{
if( (*crv)->grp_id == grp_id )
- return( 1 );
+ return( 0 );
crv++;
}
- return( 0 );
+ return( -1 );
}
#endif /* POLARSSL_ECDSA_C */
static int ssl_pick_cert( ssl_context *ssl,
const ssl_ciphersuite_t * ciphersuite_info )
{
- ssl_key_cert *cur, *list;
+ ssl_key_cert *cur, *list, *fallback = NULL;
pk_type_t pk_alg = ssl_get_ciphersuite_sig_pk_alg( ciphersuite_info );
+ int flags;
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
if( ssl->handshake->sni_key_cert != NULL )
if( pk_alg == POLARSSL_PK_NONE )
return( 0 );
+ SSL_DEBUG_MSG( 3, ( "ciphersuite requires certificate" ) );
+
for( cur = list; cur != NULL; cur = cur->next )
{
+ SSL_DEBUG_CRT( 3, "candidate certificate chain, certificate",
+ cur->cert );
+
if( ! pk_can_do( cur->key, pk_alg ) )
+ {
+ SSL_DEBUG_MSG( 3, ( "certificate mismatch: key type" ) );
continue;
+ }
/*
* This avoids sending the client a cert it'll reject based on
* and decrypting with the same RSA key.
*/
if( ssl_check_cert_usage( cur->cert, ciphersuite_info,
- SSL_IS_SERVER ) != 0 )
+ SSL_IS_SERVER, &flags ) != 0 )
{
+ SSL_DEBUG_MSG( 3, ( "certificate mismatch: "
+ "(extended) key usage extension" ) );
continue;
}
#if defined(POLARSSL_ECDSA_C)
- if( pk_alg == POLARSSL_PK_ECDSA )
+ if( pk_alg == POLARSSL_PK_ECDSA &&
+ ssl_check_key_curve( cur->key, ssl->handshake->curves ) != 0 )
{
- if( ssl_key_matches_curves( cur->key, ssl->handshake->curves ) )
- break;
+ SSL_DEBUG_MSG( 3, ( "certificate mismatch: elliptic curve" ) );
+ continue;
}
- else
#endif
- break;
+
+ /*
+ * Try to select a SHA-1 certificate for pre-1.2 clients, but still
+ * present them a SHA-higher cert rather than failing if it's the only
+ * one we got that satisfies the other conditions.
+ */
+ if( ssl->minor_ver < SSL_MINOR_VERSION_3 &&
+ cur->cert->sig_md != POLARSSL_MD_SHA1 )
+ {
+ if( fallback == NULL )
+ fallback = cur;
+ {
+ SSL_DEBUG_MSG( 3, ( "certificate not preferred: "
+ "sha-2 with pre-TLS 1.2 client" ) );
+ continue;
+ }
+ }
+
+ /* If we get there, we got a winner */
+ break;
}
if( cur == NULL )
- return( -1 );
+ cur = fallback;
- ssl->handshake->key_cert = cur;
- return( 0 );
+
+ /* Do not update ssl->handshake->key_cert unless the is a match */
+ if( cur != NULL )
+ {
+ ssl->handshake->key_cert = cur;
+ SSL_DEBUG_CRT( 3, "selected certificate chain, certificate",
+ ssl->handshake->key_cert->cert );
+ return( 0 );
+ }
+
+ return( -1 );
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
suite_info = ssl_ciphersuite_from_id( suite_id );
if( suite_info == NULL )
{
- SSL_DEBUG_MSG( 1, ( "ciphersuite info for %04x not found", suite_id ) );
- return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
+ SSL_DEBUG_MSG( 3, ( "trying ciphersuite: %s", suite_info->name ) );
+
if( suite_info->min_minor_ver > ssl->minor_ver ||
suite_info->max_minor_ver < ssl->minor_ver )
+ {
+ SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: version" ) );
+ return( 0 );
+ }
+
+ if( ssl->arc4_disabled == SSL_ARC4_DISABLED &&
+ suite_info->cipher == POLARSSL_CIPHER_ARC4_128 )
+ {
+ SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: rc4" ) );
return( 0 );
+ }
#if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
if( ssl_ciphersuite_uses_ec( suite_info ) &&
( ssl->handshake->curves == NULL ||
ssl->handshake->curves[0] == NULL ) )
+ {
+ SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: "
+ "no common elliptic curve" ) );
return( 0 );
+ }
#endif
#if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
ssl->f_psk == NULL &&
( ssl->psk == NULL || ssl->psk_identity == NULL ||
ssl->psk_identity_len == 0 || ssl->psk_len == 0 ) )
+ {
+ SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: no pre-shared key" ) );
return( 0 );
+ }
#endif
#if defined(POLARSSL_X509_CRT_PARSE_C)
* This must be done last since we modify the key_cert list.
*/
if( ssl_pick_cert( ssl, suite_info ) != 0 )
+ {
+ SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: "
+ "no suitable certificate" ) );
return( 0 );
+ }
#endif
*ciphersuite_info = suite_info;
#if defined(POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
static int ssl_parse_client_hello_v2( ssl_context *ssl )
{
- int ret;
+ int ret, got_common_suite;
unsigned int i, j;
size_t n;
unsigned int ciph_len, sess_len, chal_len;
SSL_DEBUG_MSG( 2, ( "=> parse client hello v2" ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
{
SSL_DEBUG_MSG( 1, ( "client hello v2 illegal for renegotiation" ) );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
buf = ssl->in_hdr;
if( p[0] == 0 && p[1] == 0 && p[2] == SSL_EMPTY_RENEGOTIATION_INFO )
{
SSL_DEBUG_MSG( 3, ( "received TLS_EMPTY_RENEGOTIATION_INFO " ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_RENEGOTIATION )
{
- SSL_DEBUG_MSG( 1, ( "received RENEGOTIATION SCSV during renegotiation" ) );
+ SSL_DEBUG_MSG( 1, ( "received RENEGOTIATION SCSV "
+ "during renegotiation" ) );
if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
return( ret );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
break;
}
}
+#if defined(POLARSSL_SSL_FALLBACK_SCSV)
+ for( i = 0, p = buf + 6; i < ciph_len; i += 3, p += 3 )
+ {
+ if( p[0] == 0 &&
+ p[1] == (unsigned char)( ( SSL_FALLBACK_SCSV >> 8 ) & 0xff ) &&
+ p[2] == (unsigned char)( ( SSL_FALLBACK_SCSV ) & 0xff ) )
+ {
+ SSL_DEBUG_MSG( 3, ( "received FALLBACK_SCSV" ) );
+
+ if( ssl->minor_ver < ssl->max_minor_ver )
+ {
+ SSL_DEBUG_MSG( 1, ( "inapropriate fallback" ) );
+
+ ssl_send_alert_message( ssl, SSL_ALERT_LEVEL_FATAL,
+ SSL_ALERT_MSG_INAPROPRIATE_FALLBACK );
+
+ return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
+ }
+
+ break;
+ }
+ }
+#endif /* POLARSSL_SSL_FALLBACK_SCSV */
+
+ got_common_suite = 0;
ciphersuites = ssl->ciphersuite_list[ssl->minor_ver];
ciphersuite_info = NULL;
#if defined(POLARSSL_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
p[2] != ( ( ciphersuites[i] ) & 0xFF ) )
continue;
+ got_common_suite = 1;
+
if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i],
&ciphersuite_info ) ) != 0 )
return( ret );
}
}
- SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) );
-
- return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
+ if( got_common_suite )
+ {
+ SSL_DEBUG_MSG( 1, ( "got ciphersuites in common, "
+ "but none of them usable" ) );
+ return( POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE );
+ }
+ else
+ {
+ SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) );
+ return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
+ }
have_ciphersuite_v2:
+ SSL_DEBUG_MSG( 2, ( "selected ciphersuite: %s", ciphersuite_info->name ) );
+
ssl->session_negotiate->ciphersuite = ciphersuites[i];
ssl->transform_negotiate->ciphersuite_info = ciphersuite_info;
ssl_optimize_checksum( ssl, ssl->transform_negotiate->ciphersuite_info );
static int ssl_parse_client_hello( ssl_context *ssl )
{
- int ret;
+ int ret, got_common_suite;
unsigned int i, j;
size_t n;
unsigned int ciph_len, sess_len;
unsigned int comp_len;
unsigned int ext_len = 0;
unsigned char *buf, *p, *ext;
+#if defined(POLARSSL_SSL_RENEGOTIATION)
int renegotiation_info_seen = 0;
+#endif
int handshake_failure = 0;
const int *ciphersuites;
const ssl_ciphersuite_t *ciphersuite_info;
SSL_DEBUG_MSG( 2, ( "=> parse client hello" ) );
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
- ( ret = ssl_fetch_input( ssl, 5 ) ) != 0 )
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#endif
{
- SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
- return( ret );
+ if( ( ret = ssl_fetch_input( ssl, 5 ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
+ return( ret );
+ }
}
buf = ssl->in_hdr;
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
- if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
- ( ret = ssl_fetch_input( ssl, 5 + n ) ) != 0 )
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation == SSL_INITIAL_HANDSHAKE )
+#endif
{
- SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
- return( ret );
+ if( ( ret = ssl_fetch_input( ssl, 5 + n ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_fetch_input", ret );
+ return( ret );
+ }
}
buf = ssl->in_msg;
- if( !ssl->renegotiation )
- n = ssl->in_left - 5;
- else
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
n = ssl->in_msglen;
+ else
+#endif
+ n = ssl->in_left - 5;
ssl->handshake->update_checksum( ssl, buf, n );
if( p[0] == 0 && p[1] == SSL_EMPTY_RENEGOTIATION_INFO )
{
SSL_DEBUG_MSG( 3, ( "received TLS_EMPTY_RENEGOTIATION_INFO " ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_RENEGOTIATION )
{
SSL_DEBUG_MSG( 1, ( "received RENEGOTIATION SCSV during renegotiation" ) );
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
}
+ renegotiation_info_seen = 1;
+#endif /* POLARSSL_SSL_RENEGOTIATION */
ssl->secure_renegotiation = SSL_SECURE_RENEGOTIATION;
break;
}
}
+#if defined(POLARSSL_SSL_FALLBACK_SCSV)
+ for( i = 0, p = buf + 41 + sess_len; i < ciph_len; i += 2, p += 2 )
+ {
+ if( p[0] == (unsigned char)( ( SSL_FALLBACK_SCSV >> 8 ) & 0xff ) &&
+ p[1] == (unsigned char)( ( SSL_FALLBACK_SCSV ) & 0xff ) )
+ {
+ SSL_DEBUG_MSG( 0, ( "received FALLBACK_SCSV" ) );
+
+ if( ssl->minor_ver < ssl->max_minor_ver )
+ {
+ SSL_DEBUG_MSG( 0, ( "inapropriate fallback" ) );
+
+ ssl_send_alert_message( ssl, SSL_ALERT_LEVEL_FATAL,
+ SSL_ALERT_MSG_INAPROPRIATE_FALLBACK );
+
+ return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO );
+ }
+
+ break;
+ }
+ }
+#endif /* POLARSSL_SSL_FALLBACK_SCSV */
+
ext = buf + 44 + sess_len + ciph_len + comp_len;
while( ext_len )
case TLS_EXT_RENEGOTIATION_INFO:
SSL_DEBUG_MSG( 3, ( "found renegotiation extension" ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
renegotiation_info_seen = 1;
+#endif
ret = ssl_parse_renegotiation_info( ssl, ext + 4, ext_size );
if( ret != 0 )
return( ret );
break;
-#if defined(POLARSSL_SSL_PROTO_TLS1_2)
+#if defined(POLARSSL_SSL_PROTO_TLS1_2) && \
+ defined(POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED)
case TLS_EXT_SIG_ALG:
SSL_DEBUG_MSG( 3, ( "found signature_algorithms extension" ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_RENEGOTIATION )
break;
+#endif
ret = ssl_parse_signature_algorithms_ext( ssl, ext + 4, ext_size );
if( ret != 0 )
return( ret );
break;
-#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 &&
+ POLARSSL_KEY_EXCHANGE__WITH_CERT__ENABLED */
#if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
case TLS_EXT_SUPPORTED_ELLIPTIC_CURVES:
break;
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ case TLS_EXT_ENCRYPT_THEN_MAC:
+ SSL_DEBUG_MSG( 3, ( "found encrypt then mac extension" ) );
+
+ ret = ssl_parse_encrypt_then_mac_ext( ssl, ext + 4, ext_size );
+ if( ret != 0 )
+ return( ret );
+ break;
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ case TLS_EXT_EXTENDED_MASTER_SECRET:
+ SSL_DEBUG_MSG( 3, ( "found extended master secret extension" ) );
+
+ ret = ssl_parse_extended_ms_ext( ssl, ext + 4, ext_size );
+ if( ret != 0 )
+ return( ret );
+ break;
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
case TLS_EXT_SESSION_TICKET:
SSL_DEBUG_MSG( 3, ( "found session ticket extension" ) );
/*
* Renegotiation security checks
*/
- if( ssl->secure_renegotiation == SSL_LEGACY_RENEGOTIATION &&
+ if( ssl->secure_renegotiation != SSL_SECURE_RENEGOTIATION &&
ssl->allow_legacy_renegotiation == SSL_LEGACY_BREAK_HANDSHAKE )
{
SSL_DEBUG_MSG( 1, ( "legacy renegotiation, breaking off handshake" ) );
handshake_failure = 1;
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
else if( ssl->renegotiation == SSL_RENEGOTIATION &&
ssl->secure_renegotiation == SSL_SECURE_RENEGOTIATION &&
renegotiation_info_seen == 0 )
SSL_DEBUG_MSG( 1, ( "renegotiation_info extension present (legacy)" ) );
handshake_failure = 1;
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
if( handshake_failure == 1 )
{
* (At the end because we need information from the EC-based extensions
* and certificate from the SNI callback triggered by the SNI extension.)
*/
+ got_common_suite = 0;
ciphersuites = ssl->ciphersuite_list[ssl->minor_ver];
ciphersuite_info = NULL;
#if defined(POLARSSL_SSL_SRV_RESPECT_CLIENT_PREFERENCE)
p[1] != ( ( ciphersuites[i] ) & 0xFF ) )
continue;
+ got_common_suite = 1;
+
if( ( ret = ssl_ciphersuite_match( ssl, ciphersuites[i],
&ciphersuite_info ) ) != 0 )
return( ret );
}
}
- SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) );
-
- if( ( ret = ssl_send_fatal_handshake_failure( ssl ) ) != 0 )
- return( ret );
-
- return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
+ if( got_common_suite )
+ {
+ SSL_DEBUG_MSG( 1, ( "got ciphersuites in common, "
+ "but none of them usable" ) );
+ ssl_send_fatal_handshake_failure( ssl );
+ return( POLARSSL_ERR_SSL_NO_USABLE_CIPHERSUITE );
+ }
+ else
+ {
+ SSL_DEBUG_MSG( 1, ( "got no ciphersuites in common" ) );
+ ssl_send_fatal_handshake_failure( ssl );
+ return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
+ }
have_ciphersuite:
+ SSL_DEBUG_MSG( 2, ( "selected ciphersuite: %s", ciphersuite_info->name ) );
+
ssl->session_negotiate->ciphersuite = ciphersuites[i];
ssl->transform_negotiate->ciphersuite_info = ciphersuite_info;
ssl_optimize_checksum( ssl, ssl->transform_negotiate->ciphersuite_info );
}
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+static void ssl_write_encrypt_then_mac_ext( ssl_context *ssl,
+ unsigned char *buf,
+ size_t *olen )
+{
+ unsigned char *p = buf;
+ const ssl_ciphersuite_t *suite = NULL;
+ const cipher_info_t *cipher = NULL;
+
+ if( ssl->session_negotiate->encrypt_then_mac == SSL_EXTENDED_MS_DISABLED ||
+ ssl->minor_ver == SSL_MINOR_VERSION_0 )
+ {
+ *olen = 0;
+ return;
+ }
+
+ /*
+ * RFC 7366: "If a server receives an encrypt-then-MAC request extension
+ * from a client and then selects a stream or Authenticated Encryption
+ * with Associated Data (AEAD) ciphersuite, it MUST NOT send an
+ * encrypt-then-MAC response extension back to the client."
+ */
+ if( ( suite = ssl_ciphersuite_from_id(
+ ssl->session_negotiate->ciphersuite ) ) == NULL ||
+ ( cipher = cipher_info_from_type( suite->cipher ) ) == NULL ||
+ cipher->mode != POLARSSL_MODE_CBC )
+ {
+ *olen = 0;
+ return;
+ }
+
+ SSL_DEBUG_MSG( 3, ( "server hello, adding encrypt then mac extension" ) );
+
+ *p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC >> 8 ) & 0xFF );
+ *p++ = (unsigned char)( ( TLS_EXT_ENCRYPT_THEN_MAC ) & 0xFF );
+
+ *p++ = 0x00;
+ *p++ = 0x00;
+
+ *olen = 4;
+}
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+static void ssl_write_extended_ms_ext( ssl_context *ssl,
+ unsigned char *buf,
+ size_t *olen )
+{
+ unsigned char *p = buf;
+
+ if( ssl->handshake->extended_ms == SSL_EXTENDED_MS_DISABLED ||
+ ssl->minor_ver == SSL_MINOR_VERSION_0 )
+ {
+ *olen = 0;
+ return;
+ }
+
+ SSL_DEBUG_MSG( 3, ( "server hello, adding extended master secret "
+ "extension" ) );
+
+ *p++ = (unsigned char)( ( TLS_EXT_EXTENDED_MASTER_SECRET >> 8 ) & 0xFF );
+ *p++ = (unsigned char)( ( TLS_EXT_EXTENDED_MASTER_SECRET ) & 0xFF );
+
+ *p++ = 0x00;
+ *p++ = 0x00;
+
+ *olen = 4;
+}
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
static void ssl_write_session_ticket_ext( ssl_context *ssl,
unsigned char *buf,
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO >> 8 ) & 0xFF );
*p++ = (unsigned char)( ( TLS_EXT_RENEGOTIATION_INFO ) & 0xFF );
- *p++ = 0x00;
- *p++ = ( ssl->verify_data_len * 2 + 1 ) & 0xFF;
- *p++ = ssl->verify_data_len * 2 & 0xFF;
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ssl->renegotiation != SSL_INITIAL_HANDSHAKE )
+ {
+ *p++ = 0x00;
+ *p++ = ( ssl->verify_data_len * 2 + 1 ) & 0xFF;
+ *p++ = ssl->verify_data_len * 2 & 0xFF;
+
+ memcpy( p, ssl->peer_verify_data, ssl->verify_data_len );
+ p += ssl->verify_data_len;
+ memcpy( p, ssl->own_verify_data, ssl->verify_data_len );
+ p += ssl->verify_data_len;
- memcpy( p, ssl->peer_verify_data, ssl->verify_data_len );
- p += ssl->verify_data_len;
- memcpy( p, ssl->own_verify_data, ssl->verify_data_len );
- p += ssl->verify_data_len;
+ *olen = 5 + ssl->verify_data_len * 2;
+ }
+ else
+#endif /* POLARSSL_SSL_RENEGOTIATION */
+ {
+ *p++ = 0x00;
+ *p++ = 0x01;
+ *p++ = 0x00;
- *olen = 5 + ssl->verify_data_len * 2;
+ *olen = 5;
+ }
}
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
* If not, try looking up session ID in our cache.
*/
if( ssl->handshake->resume == 0 &&
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl->renegotiation == SSL_INITIAL_HANDSHAKE &&
+#endif
ssl->session_negotiate->length != 0 &&
ssl->f_get_cache != NULL &&
ssl->f_get_cache( ssl->p_get_cache, ssl->session_negotiate ) == 0 )
ext_len += olen;
#endif
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ ssl_write_encrypt_then_mac_ext( ssl, p + 2 + ext_len, &olen );
+ ext_len += olen;
+#endif
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ ssl_write_extended_ms_ext( ssl, p + 2 + ext_len, &olen );
+ ext_len += olen;
+#endif
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
ssl_write_session_ticket_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
curve = ssl->handshake->curves;
#endif
- if( *curve == NULL )
+ if( curve == NULL || *curve == NULL )
{
SSL_DEBUG_MSG( 1, ( "no matching curve for ECDHE" ) );
return( POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN );
int ret;
size_t len = pk_get_len( ssl_own_key( ssl ) );
unsigned char *pms = ssl->handshake->premaster + pms_offset;
+ unsigned char fake_pms[48], peer_pms[48];
+ unsigned char mask;
+ size_t i, peer_pmslen;
+ unsigned int diff;
if( ! pk_can_do( ssl_own_key( ssl ), POLARSSL_PK_RSA ) )
{
return( POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
}
+ /*
+ * Protection against Bleichenbacher's attack: invalid PKCS#1 v1.5 padding
+ * must not cause the connection to end immediately; instead, send a
+ * bad_record_mac later in the handshake.
+ * Also, avoid data-dependant branches here to protect against
+ * timing-based variants.
+ */
+ ret = ssl->f_rng( ssl->p_rng, fake_pms, sizeof( fake_pms ) );
+ if( ret != 0 )
+ return( ret );
+
ret = pk_decrypt( ssl_own_key( ssl ), p, len,
- pms, &ssl->handshake->pmslen,
- sizeof( ssl->handshake->premaster ) - pms_offset,
+ peer_pms, &peer_pmslen,
+ sizeof( peer_pms ),
ssl->f_rng, ssl->p_rng );
- if( ret != 0 || ssl->handshake->pmslen != 48 ||
- pms[0] != ssl->handshake->max_major_ver ||
- pms[1] != ssl->handshake->max_minor_ver )
- {
- SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
+ diff = (unsigned int) ret;
+ diff |= peer_pmslen ^ 48;
+ diff |= peer_pms[0] ^ ssl->handshake->max_major_ver;
+ diff |= peer_pms[1] ^ ssl->handshake->max_minor_ver;
- /*
- * Protection against Bleichenbacher's attack:
- * invalid PKCS#1 v1.5 padding must not cause
- * the connection to end immediately; instead,
- * send a bad_record_mac later in the handshake.
- */
- ssl->handshake->pmslen = 48;
+#if defined(POLARSSL_SSL_DEBUG_ALL)
+ if( diff != 0 )
+ SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
+#endif
- ret = ssl->f_rng( ssl->p_rng, pms, ssl->handshake->pmslen );
- if( ret != 0 )
- return( ret );
+ if( sizeof( ssl->handshake->premaster ) < pms_offset ||
+ sizeof( ssl->handshake->premaster ) - pms_offset < 48 )
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
+ ssl->handshake->pmslen = 48;
- return( ret );
+ /* mask = diff ? 0xff : 0x00 */
+ mask = - ( diff | - diff ) >> ( sizeof( unsigned int ) * 8 - 1 );
+ for( i = 0; i < ssl->handshake->pmslen; i++ )
+ pms[i] = ( mask & fake_pms[i] ) | ( (~mask) & peer_pms[i] );
+
+ return( 0 );
}
#endif /* POLARSSL_KEY_EXCHANGE_RSA_ENABLED ||
POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED */
/*
* SSLv3/TLSv1 shared functions
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/debug.h"
#include "polarssl/ssl.h"
+#include <string.h>
+
#if defined(POLARSSL_X509_CRT_PARSE_C) && \
defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
#include "polarssl/oid.h"
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
#if defined(_MSC_VER) && !defined strcasecmp && !defined(EFIX64) && \
!defined(EFI32)
#define strcasecmp _stricmp
{
int ret;
- dst->peer_cert = (x509_crt *) polarssl_malloc( sizeof(x509_crt) );
+ dst->peer_cert = polarssl_malloc( sizeof(x509_crt) );
if( dst->peer_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
#if defined(POLARSSL_SSL_SESSION_TICKETS)
if( src->ticket != NULL )
{
- dst->ticket = (unsigned char *) polarssl_malloc( src->ticket_len );
+ dst->ticket = polarssl_malloc( src->ticket_len );
if( dst->ticket == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
SSL_DEBUG_BUF( 3, "premaster secret", handshake->premaster,
handshake->pmslen );
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ if( ssl->handshake->extended_ms == SSL_EXTENDED_MS_ENABLED )
+ {
+ unsigned char session_hash[48];
+ size_t hash_len;
+
+ SSL_DEBUG_MSG( 3, ( "using extended master secret" ) );
+
+ ssl->handshake->calc_verify( ssl, session_hash );
+
+#if defined(POLARSSL_SSL_PROTO_TLS1_2)
+ if( ssl->minor_ver == SSL_MINOR_VERSION_3 )
+ {
+#if defined(POLARSSL_SHA512_C)
+ if( ssl->transform_negotiate->ciphersuite_info->mac ==
+ POLARSSL_MD_SHA384 )
+ {
+ hash_len = 48;
+ }
+ else
+#endif
+ hash_len = 32;
+ }
+ else
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
+ hash_len = 36;
+
+ SSL_DEBUG_BUF( 3, "session hash", session_hash, hash_len );
+
+ handshake->tls_prf( handshake->premaster, handshake->pmslen,
+ "extended master secret",
+ session_hash, hash_len, session->master, 48 );
+
+ }
+ else
+#endif
handshake->tls_prf( handshake->premaster, handshake->pmslen,
"master secret",
handshake->randbytes, 64, session->master, 48 );
+
polarssl_zeroize( handshake->premaster, sizeof(handshake->premaster) );
}
else
{
/*
* GenericBlockCipher:
- * first multiple of blocklen greater than maclen
- * + IV except for SSL3 and TLS 1.0
+ * 1. if EtM is in use: one block plus MAC
+ * otherwise: * first multiple of blocklen greater than maclen
+ * 2. IV except for SSL3 and TLS 1.0
*/
- transform->minlen = transform->maclen
- + cipher_info->block_size
- - transform->maclen % cipher_info->block_size;
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ if( session->encrypt_then_mac == SSL_ETM_ENABLED )
+ {
+ transform->minlen = transform->maclen
+ + cipher_info->block_size;
+ }
+ else
+#endif
+ {
+ transform->minlen = transform->maclen
+ + cipher_info->block_size
+ - transform->maclen % cipher_info->block_size;
+ }
#if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1)
if( ssl->minor_ver == SSL_MINOR_VERSION_0 ||
/*
* Finally setup the cipher contexts, IVs and MAC secrets.
*/
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT )
{
key1 = keyblk + transform->maclen * 2;
iv_copy_len );
}
else
+#endif /* POLARSSL_SSL_CLI_C */
+#if defined(POLARSSL_SSL_SRV_C)
+ if( ssl->endpoint == SSL_IS_SERVER )
{
key1 = keyblk + transform->maclen * 2 + transform->keylen;
key2 = keyblk + transform->maclen * 2;
memcpy( transform->iv_enc, key1 + transform->keylen + iv_copy_len,
iv_copy_len );
}
+ else
+#endif /* POLARSSL_SSL_SRV_C */
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
#if defined(POLARSSL_SSL_PROTO_SSL3)
if( ssl->minor_ver == SSL_MINOR_VERSION_0 )
}
#endif /* POLARSSL_SSL_PROTO_SSL3 */
+#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER) || \
+ ( defined(POLARSSL_CIPHER_MODE_CBC) && \
+ ( defined(POLARSSL_AES_C) || defined(POLARSSL_CAMELLIA_C) ) )
+#define POLARSSL_SOME_MODES_USE_MAC
+#endif
+
/*
* Encryption/decryption functions
*/
static int ssl_encrypt_buf( ssl_context *ssl )
{
size_t i;
- const cipher_mode_t mode = cipher_get_cipher_mode(
- &ssl->transform_out->cipher_ctx_enc );
+ cipher_mode_t mode;
+ int auth_done = 0;
SSL_DEBUG_MSG( 2, ( "=> encrypt buf" ) );
+ if( ssl->session_out == NULL || ssl->transform_out == NULL )
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
+
+ mode = cipher_get_cipher_mode( &ssl->transform_out->cipher_ctx_enc );
+
+ SSL_DEBUG_BUF( 4, "before encrypt: output payload",
+ ssl->out_msg, ssl->out_msglen );
+
/*
- * Add MAC before encrypt, except for AEAD modes
+ * Add MAC before if needed
*/
-#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER) || \
- ( defined(POLARSSL_CIPHER_MODE_CBC) && \
- ( defined(POLARSSL_AES_C) || defined(POLARSSL_CAMELLIA_C) ) )
- if( mode != POLARSSL_MODE_GCM &&
- mode != POLARSSL_MODE_CCM )
+#if defined(POLARSSL_SOME_MODES_USE_MAC)
+ if( mode == POLARSSL_MODE_STREAM ||
+ ( mode == POLARSSL_MODE_CBC
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ && ssl->session_out->encrypt_then_mac == SSL_ETM_DISABLED
+#endif
+ ) )
{
#if defined(POLARSSL_SSL_PROTO_SSL3)
if( ssl->minor_ver == SSL_MINOR_VERSION_0 )
ssl->transform_out->maclen );
ssl->out_msglen += ssl->transform_out->maclen;
+ auth_done++;
}
#endif /* AEAD not the only option */
"including %d bytes of padding",
ssl->out_msglen, 0 ) );
- SSL_DEBUG_BUF( 4, "before encrypt: output payload",
- ssl->out_msg, ssl->out_msglen );
-
if( ( ret = cipher_crypt( &ssl->transform_out->cipher_ctx_enc,
ssl->transform_out->iv_enc,
ssl->transform_out->ivlen,
/*
* Generate IV
*/
+#if defined(POLARSSL_SSL_AEAD_RANDOM_IV)
ret = ssl->f_rng( ssl->p_rng,
ssl->transform_out->iv_enc + ssl->transform_out->fixed_ivlen,
ssl->transform_out->ivlen - ssl->transform_out->fixed_ivlen );
memcpy( ssl->out_iv,
ssl->transform_out->iv_enc + ssl->transform_out->fixed_ivlen,
ssl->transform_out->ivlen - ssl->transform_out->fixed_ivlen );
+#else
+ if( ssl->transform_out->ivlen - ssl->transform_out->fixed_ivlen != 8 )
+ {
+ /* Reminder if we ever add an AEAD mode with a different size */
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
+
+ memcpy( ssl->transform_out->iv_enc + ssl->transform_out->fixed_ivlen,
+ ssl->out_ctr, 8 );
+ memcpy( ssl->out_iv, ssl->out_ctr, 8 );
+#endif
SSL_DEBUG_BUF( 4, "IV used", ssl->out_iv,
ssl->transform_out->ivlen - ssl->transform_out->fixed_ivlen );
"including %d bytes of padding",
ssl->out_msglen, 0 ) );
- SSL_DEBUG_BUF( 4, "before encrypt: output payload",
- ssl->out_msg, ssl->out_msglen );
-
/*
* Encrypt and authenticate
*/
}
ssl->out_msglen += taglen;
+ auth_done++;
SSL_DEBUG_BUF( 4, "after encrypt: tag", enc_msg + enc_msglen, taglen );
}
ssl->out_msglen, ssl->transform_out->ivlen,
padlen + 1 ) );
- SSL_DEBUG_BUF( 4, "before encrypt: output payload",
- ssl->out_iv, ssl->out_msglen );
-
if( ( ret = cipher_crypt( &ssl->transform_out->cipher_ctx_enc,
ssl->transform_out->iv_enc,
ssl->transform_out->ivlen,
ssl->transform_out->ivlen );
}
#endif
+
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ if( auth_done == 0 )
+ {
+ /*
+ * MAC(MAC_write_key, seq_num +
+ * TLSCipherText.type +
+ * TLSCipherText.version +
+ * length_of( (IV +) ENC(...) ) +
+ * IV + // except for TLS 1.0
+ * ENC(content + padding + padding_length));
+ */
+ unsigned char pseudo_hdr[13];
+
+ SSL_DEBUG_MSG( 3, ( "using encrypt then mac" ) );
+
+ memcpy( pseudo_hdr + 0, ssl->out_ctr, 8 );
+ memcpy( pseudo_hdr + 8, ssl->out_hdr, 3 );
+ pseudo_hdr[11] = (unsigned char)( ( ssl->out_msglen >> 8 ) & 0xFF );
+ pseudo_hdr[12] = (unsigned char)( ( ssl->out_msglen ) & 0xFF );
+
+ SSL_DEBUG_BUF( 4, "MAC'd meta-data", pseudo_hdr, 13 );
+
+ md_hmac_update( &ssl->transform_out->md_ctx_enc, pseudo_hdr, 13 );
+ md_hmac_update( &ssl->transform_out->md_ctx_enc,
+ ssl->out_iv, ssl->out_msglen );
+ md_hmac_finish( &ssl->transform_out->md_ctx_enc,
+ ssl->out_iv + ssl->out_msglen );
+ md_hmac_reset( &ssl->transform_out->md_ctx_enc );
+
+ ssl->out_msglen += ssl->transform_out->maclen;
+ auth_done++;
+ }
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
}
else
#endif /* POLARSSL_CIPHER_MODE_CBC &&
return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
+ /* Make extra sure authentication was performed, exactly once */
+ if( auth_done != 1 )
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
+
for( i = 8; i > 0; i-- )
if( ++ssl->out_ctr[i - 1] != 0 )
break;
static int ssl_decrypt_buf( ssl_context *ssl )
{
size_t i;
- const cipher_mode_t mode = cipher_get_cipher_mode(
- &ssl->transform_in->cipher_ctx_dec );
-#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER) || \
- ( defined(POLARSSL_CIPHER_MODE_CBC) && \
- ( defined(POLARSSL_AES_C) || defined(POLARSSL_CAMELLIA_C) ) )
+ cipher_mode_t mode;
+ int auth_done = 0;
+#if defined(POLARSSL_SOME_MODES_USE_MAC)
size_t padlen = 0, correct = 1;
#endif
SSL_DEBUG_MSG( 2, ( "=> decrypt buf" ) );
+ if( ssl->session_in == NULL || ssl->transform_in == NULL )
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
+
+ mode = cipher_get_cipher_mode( &ssl->transform_in->cipher_ctx_dec );
+
if( ssl->in_msglen < ssl->transform_in->minlen )
{
SSL_DEBUG_MSG( 1, ( "in_msglen (%d) < minlen (%d)",
unsigned char explicit_iv_len = ssl->transform_in->ivlen -
ssl->transform_in->fixed_ivlen;
- if( ssl->in_msglen < explicit_iv_len + taglen )
+ if( ssl->in_msglen < (size_t) explicit_iv_len + taglen )
{
SSL_DEBUG_MSG( 1, ( "msglen (%d) < explicit_iv_len (%d) "
"+ taglen (%d)", ssl->in_msglen,
return( ret );
}
+ auth_done++;
if( olen != dec_msglen )
{
/*
* Check immediate ciphertext sanity
*/
- if( ssl->in_msglen % ssl->transform_in->ivlen != 0 )
- {
- SSL_DEBUG_MSG( 1, ( "msglen (%d) %% ivlen (%d) != 0",
- ssl->in_msglen, ssl->transform_in->ivlen ) );
- return( POLARSSL_ERR_SSL_INVALID_MAC );
- }
-
#if defined(POLARSSL_SSL_PROTO_TLS1_1) || defined(POLARSSL_SSL_PROTO_TLS1_2)
if( ssl->minor_ver >= SSL_MINOR_VERSION_2 )
minlen += ssl->transform_in->ivlen;
dec_msg = ssl->in_msg;
dec_msg_result = ssl->in_msg;
+ /*
+ * Authenticate before decrypt if enabled
+ */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ if( ssl->session_in->encrypt_then_mac == SSL_ETM_ENABLED )
+ {
+ unsigned char computed_mac[POLARSSL_SSL_MAX_MAC_SIZE];
+ unsigned char pseudo_hdr[13];
+
+ SSL_DEBUG_MSG( 3, ( "using encrypt then mac" ) );
+
+ dec_msglen -= ssl->transform_in->maclen;
+ ssl->in_msglen -= ssl->transform_in->maclen;
+
+ memcpy( pseudo_hdr + 0, ssl->in_ctr, 8 );
+ memcpy( pseudo_hdr + 8, ssl->in_hdr, 3 );
+ pseudo_hdr[11] = (unsigned char)( ( ssl->in_msglen >> 8 ) & 0xFF );
+ pseudo_hdr[12] = (unsigned char)( ( ssl->in_msglen ) & 0xFF );
+
+ SSL_DEBUG_BUF( 4, "MAC'd meta-data", pseudo_hdr, 13 );
+
+ md_hmac_update( &ssl->transform_in->md_ctx_dec, pseudo_hdr, 13 );
+ md_hmac_update( &ssl->transform_in->md_ctx_dec,
+ ssl->in_iv, ssl->in_msglen );
+ md_hmac_finish( &ssl->transform_in->md_ctx_dec, computed_mac );
+ md_hmac_reset( &ssl->transform_in->md_ctx_dec );
+
+ SSL_DEBUG_BUF( 4, "message mac", ssl->in_iv + ssl->in_msglen,
+ ssl->transform_in->maclen );
+ SSL_DEBUG_BUF( 4, "computed mac", computed_mac,
+ ssl->transform_in->maclen );
+
+ if( safer_memcmp( ssl->in_iv + ssl->in_msglen, computed_mac,
+ ssl->transform_in->maclen ) != 0 )
+ {
+ SSL_DEBUG_MSG( 1, ( "message mac does not match" ) );
+
+ return( POLARSSL_ERR_SSL_INVALID_MAC );
+ }
+ auth_done++;
+ }
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+
+ /*
+ * Check length sanity
+ */
+ if( ssl->in_msglen % ssl->transform_in->ivlen != 0 )
+ {
+ SSL_DEBUG_MSG( 1, ( "msglen (%d) %% ivlen (%d) != 0",
+ ssl->in_msglen, ssl->transform_in->ivlen ) );
+ return( POLARSSL_ERR_SSL_INVALID_MAC );
+ }
+
#if defined(POLARSSL_SSL_PROTO_TLS1_1) || defined(POLARSSL_SSL_PROTO_TLS1_2)
/*
* Initialize for prepended IV for block cipher in TLS v1.1 and up
padlen = 1 + ssl->in_msg[ssl->in_msglen - 1];
- if( ssl->in_msglen < ssl->transform_in->maclen + padlen )
+ if( ssl->in_msglen < ssl->transform_in->maclen + padlen &&
+ auth_done == 0 )
{
#if defined(POLARSSL_SSL_DEBUG_ALL)
SSL_DEBUG_MSG( 1, ( "msglen (%d) < maclen (%d) + padlen (%d)",
SSL_DEBUG_MSG( 1, ( "should never happen" ) );
return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
}
+
+ ssl->in_msglen -= padlen;
}
else
#endif /* POLARSSL_CIPHER_MODE_CBC &&
ssl->in_msg, ssl->in_msglen );
/*
- * Always compute the MAC (RFC4346, CBCTIME), except for AEAD of course
+ * Authenticate if not done yet.
+ * Compute the MAC regardless of the padding result (RFC4346, CBCTIME).
*/
-#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER) || \
- ( defined(POLARSSL_CIPHER_MODE_CBC) && \
- ( defined(POLARSSL_AES_C) || defined(POLARSSL_CAMELLIA_C) ) )
- if( mode != POLARSSL_MODE_GCM &&
- mode != POLARSSL_MODE_CCM )
+#if defined(POLARSSL_SOME_MODES_USE_MAC)
+ if( auth_done == 0 )
{
unsigned char tmp[POLARSSL_SSL_MAX_MAC_SIZE];
- ssl->in_msglen -= ( ssl->transform_in->maclen + padlen );
+ ssl->in_msglen -= ssl->transform_in->maclen;
ssl->in_hdr[3] = (unsigned char)( ssl->in_msglen >> 8 );
ssl->in_hdr[4] = (unsigned char)( ssl->in_msglen );
ssl->in_msglen );
md_hmac_finish( &ssl->transform_in->md_ctx_dec,
ssl->in_msg + ssl->in_msglen );
- for( j = 0; j < extra_run; j++ )
+ /* Call md_process at least once due to cache attacks */
+ for( j = 0; j < extra_run + 1; j++ )
md_process( &ssl->transform_in->md_ctx_dec, ssl->in_msg );
md_hmac_reset( &ssl->transform_in->md_ctx_dec );
#endif
correct = 0;
}
+ auth_done++;
/*
* Finally check the correct flag
if( correct == 0 )
return( POLARSSL_ERR_SSL_INVALID_MAC );
}
-#endif /* AEAD not the only option */
+#endif /* POLARSSL_SOME_MODES_USE_MAC */
+
+ /* Make extra sure authentication was performed, exactly once */
+ if( auth_done != 1 )
+ {
+ SSL_DEBUG_MSG( 1, ( "should never happen" ) );
+ return( POLARSSL_ERR_SSL_INTERNAL_ERROR );
+ }
if( ssl->in_msglen == 0 )
{
return( 0 );
}
+#undef MAC_NONE
+#undef MAC_PLAINTEXT
+#undef MAC_CIPHERTEXT
+
#if defined(POLARSSL_ZLIB_SUPPORT)
/*
* Compression/decompression functions
return( 0 );
}
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT )
{
if( ssl->client_auth == 0 )
}
#endif /* POLARSSL_SSL_PROTO_SSL3 */
}
- else /* SSL_IS_SERVER */
+#endif /* POLARSSL_SSL_CLI_C */
+#if defined(POLARSSL_SSL_SRV_C)
+ if( ssl->endpoint == SSL_IS_SERVER )
{
if( ssl_own_cert( ssl ) == NULL )
{
return( POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED );
}
}
+#endif
SSL_DEBUG_CRT( 3, "own certificate", ssl_own_cert( ssl ) );
return( 0 );
}
+#if defined(POLARSSL_SSL_SRV_C)
if( ssl->endpoint == SSL_IS_SERVER &&
( ssl->authmode == SSL_VERIFY_NONE ||
ciphersuite_info->key_exchange == POLARSSL_KEY_EXCHANGE_RSA_PSK ) )
ssl->state++;
return( 0 );
}
+#endif
if( ( ret = ssl_read_record( ssl ) ) != 0 )
{
ssl->state++;
+#if defined(POLARSSL_SSL_SRV_C)
#if defined(POLARSSL_SSL_PROTO_SSL3)
/*
* Check if the client sent an empty certificate
}
#endif /* POLARSSL_SSL_PROTO_TLS1 || POLARSSL_SSL_PROTO_TLS1_1 || \
POLARSSL_SSL_PROTO_TLS1_2 */
+#endif /* POLARSSL_SSL_SRV_C */
if( ssl->in_msgtype != SSL_MSG_HANDSHAKE )
{
polarssl_free( ssl->session_negotiate->peer_cert );
}
- if( ( ssl->session_negotiate->peer_cert = (x509_crt *) polarssl_malloc(
+ if( ( ssl->session_negotiate->peer_cert = polarssl_malloc(
sizeof( x509_crt ) ) ) == NULL )
{
SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed",
* On client, make sure the server cert doesn't change during renego to
* avoid "triple handshake" attack: https://secure-resumption.com/
*/
+#if defined(POLARSSL_SSL_RENEGOTIATION) && defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT &&
ssl->renegotiation == SSL_RENEGOTIATION )
{
return( POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE );
}
}
+#endif /* POLARSSL_SSL_RENEGOTIATION && POLARSSL_SSL_CLI_C */
if( ssl->authmode != SSL_VERIFY_NONE )
{
if( ssl_check_cert_usage( ssl->session_negotiate->peer_cert,
ciphersuite_info,
- ! ssl->endpoint ) != 0 )
+ ! ssl->endpoint,
+ &ssl->session_negotiate->verify_result ) != 0 )
{
SSL_DEBUG_MSG( 1, ( "bad certificate (usage extensions)" ) );
if( ret == 0 )
polarssl_free( ssl->handshake );
ssl->handshake = NULL;
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->renegotiation == SSL_RENEGOTIATION )
{
ssl->renegotiation = SSL_RENEGOTIATION_DONE;
ssl->renego_records_seen = 0;
}
+#endif
/*
* Switch in our now active transform context
if( ssl->session )
{
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ /* RFC 7366 3.1: keep the EtM state */
+ ssl->session_negotiate->encrypt_then_mac =
+ ssl->session->encrypt_then_mac;
+#endif
+
ssl_session_free( ssl->session );
polarssl_free( ssl->session );
}
// TODO TLS/1.2 Hash length is determined by cipher suite (Page 63)
hash_len = ( ssl->minor_ver == SSL_MINOR_VERSION_0 ) ? 36 : 12;
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl->verify_data_len = hash_len;
memcpy( ssl->own_verify_data, ssl->out_msg + 4, hash_len );
+#endif
ssl->out_msglen = 4 + hash_len;
ssl->out_msgtype = SSL_MSG_HANDSHAKE;
*/
if( ssl->handshake->resume != 0 )
{
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT )
ssl->state = SSL_HANDSHAKE_WRAPUP;
- else
+#endif
+#if defined(POLARSSL_SSL_SRV_C)
+ if( ssl->endpoint == SSL_IS_SERVER )
ssl->state = SSL_CLIENT_CHANGE_CIPHER_SPEC;
+#endif
}
else
ssl->state++;
return( POLARSSL_ERR_SSL_BAD_HS_FINISHED );
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl->verify_data_len = hash_len;
memcpy( ssl->peer_verify_data, buf, hash_len );
+#endif
if( ssl->handshake->resume != 0 )
{
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT )
ssl->state = SSL_CLIENT_CHANGE_CIPHER_SPEC;
-
+#endif
+#if defined(POLARSSL_SSL_SRV_C)
if( ssl->endpoint == SSL_IS_SERVER )
ssl->state = SSL_HANDSHAKE_WRAPUP;
+#endif
}
else
ssl->state++;
*/
if( ssl->transform_negotiate == NULL )
{
- ssl->transform_negotiate =
- (ssl_transform *) polarssl_malloc( sizeof(ssl_transform) );
+ ssl->transform_negotiate = polarssl_malloc( sizeof(ssl_transform) );
}
if( ssl->session_negotiate == NULL )
{
- ssl->session_negotiate =
- (ssl_session *) polarssl_malloc( sizeof(ssl_session) );
+ ssl->session_negotiate = polarssl_malloc( sizeof(ssl_session) );
}
if( ssl->handshake == NULL )
{
- ssl->handshake = (ssl_handshake_params *)
- polarssl_malloc( sizeof(ssl_handshake_params) );
+ ssl->handshake = polarssl_malloc( sizeof(ssl_handshake_params) );
}
/* All pointers should exist and can be directly freed without issue */
ssl_set_ciphersuites( ssl, ssl_list_ciphersuites() );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl->renego_max_records = SSL_RENEGO_MAX_RECORDS_DEFAULT;
+ memset( ssl->renego_period, 0xFF, 7 );
+ ssl->renego_period[7] = 0x00;
+#endif
#if defined(POLARSSL_DHM_C)
if( ( ret = mpi_read_string( &ssl->dhm_P, 16,
- POLARSSL_DHM_RFC5114_MODP_1024_P) ) != 0 ||
+ POLARSSL_DHM_RFC5114_MODP_2048_P) ) != 0 ||
( ret = mpi_read_string( &ssl->dhm_G, 16,
- POLARSSL_DHM_RFC5114_MODP_1024_G) ) != 0 )
+ POLARSSL_DHM_RFC5114_MODP_2048_G) ) != 0 )
{
SSL_DEBUG_RET( 1, "mpi_read_string", ret );
return( ret );
/*
* Prepare base structures
*/
- ssl->in_ctr = (unsigned char *) polarssl_malloc( len );
- ssl->in_hdr = ssl->in_ctr + 8;
- ssl->in_iv = ssl->in_ctr + 13;
- ssl->in_msg = ssl->in_ctr + 13;
-
- if( ssl->in_ctr == NULL )
+ if( ( ssl->in_ctr = polarssl_malloc( len ) ) == NULL ||
+ ( ssl->out_ctr = polarssl_malloc( len ) ) == NULL )
{
SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed", len ) );
+ polarssl_free( ssl->in_ctr );
+ ssl->in_ctr = NULL;
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
}
- ssl->out_ctr = (unsigned char *) polarssl_malloc( len );
+ memset( ssl-> in_ctr, 0, SSL_BUFFER_LEN );
+ memset( ssl->out_ctr, 0, SSL_BUFFER_LEN );
+
+ ssl->in_hdr = ssl->in_ctr + 8;
+ ssl->in_iv = ssl->in_ctr + 13;
+ ssl->in_msg = ssl->in_ctr + 13;
+
ssl->out_hdr = ssl->out_ctr + 8;
ssl->out_iv = ssl->out_ctr + 13;
ssl->out_msg = ssl->out_ctr + 13;
- if( ssl->out_ctr == NULL )
- {
- SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed", len ) );
- polarssl_free( ssl->in_ctr );
- ssl->in_ctr = NULL;
- return( POLARSSL_ERR_SSL_MALLOC_FAILED );
- }
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ ssl->encrypt_then_mac = SSL_ETM_ENABLED;
+#endif
- memset( ssl-> in_ctr, 0, SSL_BUFFER_LEN );
- memset( ssl->out_ctr, 0, SSL_BUFFER_LEN );
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ ssl->extended_ms = SSL_EXTENDED_MS_ENABLED;
+#endif
#if defined(POLARSSL_SSL_SESSION_TICKETS)
ssl->ticket_lifetime = SSL_DEFAULT_TICKET_LIFETIME;
int ret;
ssl->state = SSL_HELLO_REQUEST;
+
+#if defined(POLARSSL_SSL_RENEGOTIATION)
ssl->renegotiation = SSL_INITIAL_HANDSHAKE;
- ssl->secure_renegotiation = SSL_LEGACY_RENEGOTIATION;
+ ssl->renego_records_seen = 0;
ssl->verify_data_len = 0;
- memset( ssl->own_verify_data, 0, 36 );
- memset( ssl->peer_verify_data, 0, 36 );
+ memset( ssl->own_verify_data, 0, SSL_VERIFY_DATA_MAX_LEN );
+ memset( ssl->peer_verify_data, 0, SSL_VERIFY_DATA_MAX_LEN );
+#endif
+ ssl->secure_renegotiation = SSL_LEGACY_RENEGOTIATION;
ssl->in_offt = NULL;
ssl->out_msgtype = 0;
ssl->out_msglen = 0;
ssl->out_left = 0;
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+ if( ssl->split_done != SSL_CBC_RECORD_SPLITTING_DISABLED )
+ ssl->split_done = 0;
+#endif
ssl->transform_in = NULL;
ssl->transform_out = NULL;
- ssl->renego_records_seen = 0;
-
memset( ssl->out_ctr, 0, SSL_BUFFER_LEN );
memset( ssl->in_ctr, 0, SSL_BUFFER_LEN );
if( ssl->ticket_keys != NULL )
return( 0 );
- tkeys = (ssl_ticket_keys *) polarssl_malloc( sizeof(ssl_ticket_keys) );
+ tkeys = polarssl_malloc( sizeof(ssl_ticket_keys) );
if( tkeys == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
{
ssl->endpoint = endpoint;
-#if defined(POLARSSL_SSL_SESSION_TICKETS)
+#if defined(POLARSSL_SSL_SESSION_TICKETS) && \
+ defined(POLARSSL_SSL_CLI_C)
if( endpoint == SSL_IS_CLIENT )
ssl->session_tickets = SSL_SESSION_TICKETS_ENABLED;
#endif
+
+#if defined(POLARSSL_SSL_TRUNCATED_HMAC)
+ if( endpoint == SSL_IS_SERVER )
+ ssl->trunc_hmac = SSL_TRUNC_HMAC_ENABLED;
+#endif
}
void ssl_set_authmode( ssl_context *ssl, int authmode )
ssl->p_send = p_send;
}
+#if defined(POLARSSL_SSL_SRV_C)
void ssl_set_session_cache( ssl_context *ssl,
int (*f_get_cache)(void *, ssl_session *), void *p_get_cache,
int (*f_set_cache)(void *, const ssl_session *), void *p_set_cache )
ssl->f_set_cache = f_set_cache;
ssl->p_set_cache = p_set_cache;
}
+#endif /* POLARSSL_SSL_SRV_C */
+#if defined(POLARSSL_SSL_CLI_C)
int ssl_set_session( ssl_context *ssl, const ssl_session *session )
{
int ret;
return( 0 );
}
+#endif /* POLARSSL_SSL_CLI_C */
void ssl_set_ciphersuites( ssl_context *ssl, const int *ciphersuites )
{
{
ssl_key_cert *key_cert, *last;
- key_cert = (ssl_key_cert *) polarssl_malloc( sizeof(ssl_key_cert) );
+ key_cert = polarssl_malloc( sizeof(ssl_key_cert) );
if( key_cert == NULL )
return( NULL );
return( 0 );
}
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
#if defined(POLARSSL_RSA_C)
int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
rsa_context *rsa_key )
if( key_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
- key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
+ key_cert->key = polarssl_malloc( sizeof(pk_context) );
if( key_cert->key == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
if( key_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
- key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
+ key_cert->key = polarssl_malloc( sizeof(pk_context) );
if( key_cert->key == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
return( 0 );
}
+#endif /* POLARSSL_DEPRECATED_REMOVED */
#endif /* POLARSSL_X509_CRT_PARSE_C */
#if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
if( psk_len > POLARSSL_PSK_MAX_LEN )
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
- if( ssl->psk != NULL )
+ if( ssl->psk != NULL || ssl->psk_identity != NULL )
{
polarssl_free( ssl->psk );
polarssl_free( ssl->psk_identity );
}
+ if( ( ssl->psk = polarssl_malloc( psk_len ) ) == NULL ||
+ ( ssl->psk_identity = polarssl_malloc( psk_identity_len ) ) == NULL )
+ {
+ polarssl_free( ssl->psk );
+ ssl->psk = NULL;
+ return( POLARSSL_ERR_SSL_MALLOC_FAILED );
+ }
+
ssl->psk_len = psk_len;
ssl->psk_identity_len = psk_identity_len;
- ssl->psk = (unsigned char *) polarssl_malloc( ssl->psk_len );
- ssl->psk_identity = (unsigned char *)
- polarssl_malloc( ssl->psk_identity_len );
-
- if( ssl->psk == NULL || ssl->psk_identity == NULL )
- return( POLARSSL_ERR_SSL_MALLOC_FAILED );
-
memcpy( ssl->psk, psk, ssl->psk_len );
memcpy( ssl->psk_identity, psk_identity, ssl->psk_identity_len );
if( ssl->hostname_len + 1 == 0 )
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
- ssl->hostname = (unsigned char *) polarssl_malloc( ssl->hostname_len + 1 );
+ ssl->hostname = polarssl_malloc( ssl->hostname_len + 1 );
if( ssl->hostname == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
}
}
+#if defined(POLARSSL_SSL_FALLBACK_SCSV) && defined(POLARSSL_SSL_CLI_C)
+void ssl_set_fallback( ssl_context *ssl, char fallback )
+{
+ ssl->fallback = fallback;
+}
+#endif
+
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+void ssl_set_encrypt_then_mac( ssl_context *ssl, char etm )
+{
+ ssl->encrypt_then_mac = etm;
+}
+#endif
+
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+void ssl_set_extended_master_secret( ssl_context *ssl, char ems )
+{
+ ssl->extended_ms = ems;
+}
+#endif
+
+void ssl_set_arc4_support( ssl_context *ssl, char arc4 )
+{
+ ssl->arc4_disabled = arc4;
+}
+
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
int ssl_set_max_frag_len( ssl_context *ssl, unsigned char mfl_code )
{
#if defined(POLARSSL_SSL_TRUNCATED_HMAC)
int ssl_set_truncated_hmac( ssl_context *ssl, int truncate )
{
- if( ssl->endpoint != SSL_IS_CLIENT )
- return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
-
ssl->trunc_hmac = truncate;
return( 0 );
}
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */
-void ssl_set_renegotiation( ssl_context *ssl, int renegotiation )
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+void ssl_set_cbc_record_splitting( ssl_context *ssl, char split )
{
- ssl->disable_renegotiation = renegotiation;
+ ssl->split_done = split;
}
+#endif
void ssl_legacy_renegotiation( ssl_context *ssl, int allow_legacy )
{
ssl->allow_legacy_renegotiation = allow_legacy;
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+void ssl_set_renegotiation( ssl_context *ssl, int renegotiation )
+{
+ ssl->disable_renegotiation = renegotiation;
+}
+
void ssl_set_renegotiation_enforced( ssl_context *ssl, int max_records )
{
ssl->renego_max_records = max_records;
}
+void ssl_set_renegotiation_period( ssl_context *ssl,
+ const unsigned char period[8] )
+{
+ memcpy( ssl->renego_period, period, 8 );
+}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
+
#if defined(POLARSSL_SSL_SESSION_TICKETS)
int ssl_set_session_tickets( ssl_context *ssl, int use_tickets )
{
ssl->session_tickets = use_tickets;
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT )
return( 0 );
+#endif
+
+ if( use_tickets == SSL_SESSION_TICKETS_DISABLED )
+ return( 0 );
if( ssl->f_rng == NULL )
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
int ssl_get_verify_result( const ssl_context *ssl )
{
- return( ssl->session->verify_result );
+ if( ssl->session != NULL )
+ return( ssl->session->verify_result );
+
+ if( ssl->session_negotiate != NULL )
+ return( ssl->session_negotiate->verify_result );
+
+ return( -1 );
}
const char *ssl_get_ciphersuite( const ssl_context *ssl )
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
+#if defined(POLARSSL_SSL_CLI_C)
int ssl_get_session( const ssl_context *ssl, ssl_session *dst )
{
if( ssl == NULL ||
return( ssl_session_copy( dst, ssl->session ) );
}
+#endif /* POLARSSL_SSL_CLI_C */
/*
* Perform a single step of the SSL handshake
if( ssl->endpoint == SSL_IS_CLIENT )
ret = ssl_handshake_client_step( ssl );
#endif
-
#if defined(POLARSSL_SSL_SRV_C)
if( ssl->endpoint == SSL_IS_SERVER )
ret = ssl_handshake_server_step( ssl );
return( ret );
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
#if defined(POLARSSL_SSL_SRV_C)
/*
* Write HelloRequest to request renegotiation on server
return( ret );
}
+/*
+ * Check record counters and renegotiate if they're above the limit.
+ */
+static int ssl_check_ctr_renegotiate( ssl_context *ssl )
+{
+ if( ssl->state != SSL_HANDSHAKE_OVER ||
+ ssl->renegotiation == SSL_RENEGOTIATION_PENDING ||
+ ssl->disable_renegotiation == SSL_RENEGOTIATION_DISABLED )
+ {
+ return( 0 );
+ }
+
+ // TODO: adapt for DTLS
+ if( memcmp( ssl->in_ctr, ssl->renego_period, 8 ) <= 0 &&
+ memcmp( ssl->out_ctr, ssl->renego_period, 8 ) <= 0 )
+ {
+ return( 0 );
+ }
+
+ SSL_DEBUG_MSG( 0, ( "record counter limit reached: renegotiate" ) );
+ return( ssl_renegotiate( ssl ) );
+}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
+
/*
* Receive application data decrypted from the SSL layer
*/
SSL_DEBUG_MSG( 2, ( "=> read" ) );
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ( ret = ssl_check_ctr_renegotiate( ssl ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_check_ctr_renegotiate", ret );
+ return( ret );
+ }
+#endif
+
if( ssl->state != SSL_HANDSHAKE_OVER )
{
ret = ssl_handshake( ssl );
}
}
+#if defined(POLARSSL_SSL_RENEGOTIATION)
if( ssl->in_msgtype == SSL_MSG_HANDSHAKE )
{
SSL_DEBUG_MSG( 1, ( "received handshake message" ) );
+#if defined(POLARSSL_SSL_CLI_C)
if( ssl->endpoint == SSL_IS_CLIENT &&
( ssl->in_msg[0] != SSL_HS_HELLO_REQUEST ||
ssl->in_hslen != 4 ) )
SSL_DEBUG_MSG( 1, ( "handshake received (not HelloRequest)" ) );
return( POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE );
}
+#endif
if( ssl->disable_renegotiation == SSL_RENEGOTIATION_DISABLED ||
( ssl->secure_renegotiation == SSL_LEGACY_RENEGOTIATION &&
return( POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE );
}
}
+#endif /* POLARSSL_SSL_RENEGOTIATION */
/* Fatal and closure alerts handled by ssl_read_record() */
if( ssl->in_msgtype == SSL_MSG_ALERT )
}
/*
- * Send application data to be encrypted by the SSL layer
+ * Send application data to be encrypted by the SSL layer,
+ * taking care of max fragment length and buffer size
*/
-int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len )
+static int ssl_write_real( ssl_context *ssl,
+ const unsigned char *buf, size_t len )
{
int ret;
size_t n;
unsigned int max_len = SSL_MAX_CONTENT_LEN;
- SSL_DEBUG_MSG( 2, ( "=> write" ) );
-
- if( ssl->state != SSL_HANDSHAKE_OVER )
- {
- if( ( ret = ssl_handshake( ssl ) ) != 0 )
- {
- SSL_DEBUG_RET( 1, "ssl_handshake", ret );
- return( ret );
- }
- }
-
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
/*
* Assume mfl_code is correct since it was checked when set
}
}
+ return( (int) n );
+}
+
+/*
+ * Write application data, doing 1/n-1 splitting if necessary.
+ *
+ * With non-blocking I/O, ssl_write_real() may return WANT_WRITE,
+ * then the caller will call us again with the same arguments, so
+ * remember wether we already did the split or not.
+ */
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+static int ssl_write_split( ssl_context *ssl,
+ const unsigned char *buf, size_t len )
+{
+ int ret;
+
+ if( ssl->split_done == SSL_CBC_RECORD_SPLITTING_DISABLED ||
+ len <= 1 ||
+ ssl->minor_ver > SSL_MINOR_VERSION_1 ||
+ cipher_get_cipher_mode( &ssl->transform_out->cipher_ctx_enc )
+ != POLARSSL_MODE_CBC )
+ {
+ return( ssl_write_real( ssl, buf, len ) );
+ }
+
+ if( ssl->split_done == 0 )
+ {
+ if( ( ret = ssl_write_real( ssl, buf, 1 ) ) <= 0 )
+ return( ret );
+ ssl->split_done = 1;
+ }
+
+ if( ( ret = ssl_write_real( ssl, buf + 1, len - 1 ) ) <= 0 )
+ return( ret );
+ ssl->split_done = 0;
+
+ return( ret + 1 );
+}
+#endif /* POLARSSL_SSL_CBC_RECORD_SPLITTING */
+
+/*
+ * Write application data (public-facing wrapper)
+ */
+int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len )
+{
+ int ret;
+
+ SSL_DEBUG_MSG( 2, ( "=> write" ) );
+
+#if defined(POLARSSL_SSL_RENEGOTIATION)
+ if( ( ret = ssl_check_ctr_renegotiate( ssl ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_check_ctr_renegotiate", ret );
+ return( ret );
+ }
+#endif
+
+ if( ssl->state != SSL_HANDSHAKE_OVER )
+ {
+ if( ( ret = ssl_handshake( ssl ) ) != 0 )
+ {
+ SSL_DEBUG_RET( 1, "ssl_handshake", ret );
+ return( ret );
+ }
+ }
+
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+ ret = ssl_write_split( ssl, buf, len );
+#else
+ ret = ssl_write_real( ssl, buf, len );
+#endif
+
SSL_DEBUG_MSG( 2, ( "<= write" ) );
- return( (int) n );
+ return( ret );
}
/*
#if defined(POLARSSL_X509_CRT_PARSE_C)
int ssl_check_cert_usage( const x509_crt *cert,
const ssl_ciphersuite_t *ciphersuite,
- int cert_endpoint )
+ int cert_endpoint,
+ int *flags )
{
+ int ret = 0;
#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
int usage = 0;
#endif
!defined(POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE)
((void) cert);
((void) cert_endpoint);
+ ((void) flags);
#endif
#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
}
if( x509_crt_check_key_usage( cert, usage ) != 0 )
- return( -1 );
+ {
+ *flags |= BADCERT_KEY_USAGE;
+ ret = -1;
+ }
#else
((void) ciphersuite);
#endif /* POLARSSL_X509_CHECK_KEY_USAGE */
}
if( x509_crt_check_extended_key_usage( cert, ext_oid, ext_len ) != 0 )
- return( -1 );
+ {
+ *flags |= BADCERT_EXT_KEY_USAGE;
+ ret = -1;
+ }
#endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */
- return( 0 );
+ return( ret );
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
/*
* Threading abstraction layer
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
* Portable interface to the CPU cycle counter
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
( _MSC_VER && _M_IX86 ) || __WATCOMC__ */
+/* some versions of mingw-64 have 32-bit longs even on x84_64 */
#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) && \
- defined(__GNUC__) && defined(__i386__)
+ defined(__GNUC__) && ( defined(__i386__) || ( \
+ ( defined(__amd64__) || defined( __x86_64__) ) && __SIZEOF_LONG__ == 4 ) )
#define POLARSSL_HAVE_HARDCLOCK
return( delta );
}
-DWORD WINAPI TimerProc( LPVOID uElapse )
+/* It's OK to use a global because alarm() is supposed to be global anyway */
+static DWORD alarmMs;
+
+static DWORD WINAPI TimerProc( LPVOID TimerContext )
{
- Sleep( (DWORD) uElapse );
+ ((void) TimerContext);
+ Sleep( alarmMs );
alarmed = 1;
return( TRUE );
}
DWORD ThreadId;
alarmed = 0;
- CloseHandle( CreateThread( NULL, 0, TimerProc,
- (LPVOID) ( seconds * 1000 ), 0, &ThreadId ) );
+ alarmMs = seconds * 1000;
+ CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) );
}
void m_sleep( int milliseconds )
if( hardfail > 1 )
{
if( verbose != 0 )
- polarssl_printf( "failed\n" );
+ polarssl_printf( "failed (ignored)\n" );
- return( 1 );
+ goto hard_test_done;
}
/* Get a reference ratio cycles/ms */
if( verbose != 0 )
polarssl_printf( "passed\n" );
+hard_test_done:
+
#if defined(POLARSSL_NET_C) && defined(POLARSSL_HAVE_TIME)
if( verbose != 0 )
polarssl_printf( " TIMING test #4 (net_usleep/ get_timer): " );
/*
* Version information
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/version.h"
#include <string.h>
-const char version[] = POLARSSL_VERSION_STRING;
-
unsigned int version_get_number()
{
return( POLARSSL_VERSION_NUMBER );
/*
* Version feature information
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define strcasecmp _stricmp
#endif
-const char *features[] = {
+static const char *features[] = {
#if defined(POLARSSL_VERSION_FEATURES)
#if defined(POLARSSL_HAVE_INT8)
"POLARSSL_HAVE_INT8",
#if defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
"POLARSSL_PLATFORM_NO_STD_FUNCTIONS",
#endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
-#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
- "POLARSSL_PLATFORM_PRINTF_ALT",
-#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_EXIT_ALT)
+ "POLARSSL_PLATFORM_EXIT_ALT",
+#endif /* POLARSSL_PLATFORM_EXIT_ALT */
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
"POLARSSL_PLATFORM_FPRINTF_ALT",
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
+ "POLARSSL_PLATFORM_PRINTF_ALT",
+#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
+ "POLARSSL_PLATFORM_SNPRINTF_ALT",
+#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+#if defined(POLARSSL_DEPRECATED_WARNING)
+ "POLARSSL_DEPRECATED_WARNING",
+#endif /* POLARSSL_DEPRECATED_WARNING */
+#if defined(POLARSSL_DEPRECATED_REMOVED)
+ "POLARSSL_DEPRECATED_REMOVED",
+#endif /* POLARSSL_DEPRECATED_REMOVED */
#if defined(POLARSSL_TIMING_ALT)
"POLARSSL_TIMING_ALT",
#endif /* POLARSSL_TIMING_ALT */
#if defined(POLARSSL_AES_ROM_TABLES)
"POLARSSL_AES_ROM_TABLES",
#endif /* POLARSSL_AES_ROM_TABLES */
+#if defined(POLARSSL_CAMELLIA_SMALL_MEMORY)
+ "POLARSSL_CAMELLIA_SMALL_MEMORY",
+#endif /* POLARSSL_CAMELLIA_SMALL_MEMORY */
#if defined(POLARSSL_CIPHER_MODE_CBC)
"POLARSSL_CIPHER_MODE_CBC",
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_SELF_TEST)
"POLARSSL_SELF_TEST",
#endif /* POLARSSL_SELF_TEST */
+#if defined(POLARSSL_SSL_AEAD_RANDOM_IV)
+ "POLARSSL_SSL_AEAD_RANDOM_IV",
+#endif /* POLARSSL_SSL_AEAD_RANDOM_IV */
#if defined(POLARSSL_SSL_ALERT_MESSAGES)
"POLARSSL_SSL_ALERT_MESSAGES",
#endif /* POLARSSL_SSL_ALERT_MESSAGES */
#if defined(POLARSSL_SSL_DEBUG_ALL)
"POLARSSL_SSL_DEBUG_ALL",
#endif /* POLARSSL_SSL_DEBUG_ALL */
+#if defined(POLARSSL_SSL_ENCRYPT_THEN_MAC)
+ "POLARSSL_SSL_ENCRYPT_THEN_MAC",
+#endif /* POLARSSL_SSL_ENCRYPT_THEN_MAC */
+#if defined(POLARSSL_SSL_EXTENDED_MASTER_SECRET)
+ "POLARSSL_SSL_EXTENDED_MASTER_SECRET",
+#endif /* POLARSSL_SSL_EXTENDED_MASTER_SECRET */
+#if defined(POLARSSL_SSL_FALLBACK_SCSV)
+ "POLARSSL_SSL_FALLBACK_SCSV",
+#endif /* POLARSSL_SSL_FALLBACK_SCSV */
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
"POLARSSL_SSL_HW_RECORD_ACCEL",
#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
+#if defined(POLARSSL_SSL_CBC_RECORD_SPLITTING)
+ "POLARSSL_SSL_CBC_RECORD_SPLITTING",
+#endif /* POLARSSL_SSL_CBC_RECORD_SPLITTING */
+#if defined(POLARSSL_SSL_DISABLE_RENEGOTIATION)
+ "POLARSSL_SSL_DISABLE_RENEGOTIATION",
+#endif /* POLARSSL_SSL_DISABLE_RENEGOTIATION */
#if defined(POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO)
"POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO",
#endif /* POLARSSL_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO */
/*
* X.509 common functions for parsing and verification
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/x509.h"
#include "polarssl/asn1.h"
#include "polarssl/oid.h"
+
+#include <stdio.h>
+#include <string.h>
+
#if defined(POLARSSL_PEM_PARSE_C)
#include "polarssl/pem.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
-#define polarssl_printf printf
-#define polarssl_malloc malloc
+#include <stdio.h>
+#include <stdlib.h>
#define polarssl_free free
+#define polarssl_malloc malloc
+#define polarssl_printf printf
+#define polarssl_snprintf snprintf
#endif
-#include <string.h>
-#include <stdlib.h>
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include <windows.h>
#else
#include <time.h>
#endif
-#if defined(EFIX64) || defined(EFI32)
-#include <stdio.h>
-#endif
-
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#if !defined(_WIN32)
#endif
#endif
+#define CHECK(code) if( ( ret = code ) != 0 ){ return( ret ); }
+
/*
* CertificateSerialNumber ::= INTEGER
*/
if( **p != ASN1_BMP_STRING && **p != ASN1_UTF8_STRING &&
**p != ASN1_T61_STRING && **p != ASN1_PRINTABLE_STRING &&
- **p != ASN1_IA5_STRING && **p != ASN1_UNIVERSAL_STRING )
+ **p != ASN1_IA5_STRING && **p != ASN1_UNIVERSAL_STRING &&
+ **p != ASN1_BIT_STRING )
return( POLARSSL_ERR_X509_INVALID_NAME +
POLARSSL_ERR_ASN1_UNEXPECTED_TAG );
}
/*
+ * Name ::= CHOICE { -- only one possibility for now --
+ * rdnSequence RDNSequence }
+ *
+ * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
+ *
* RelativeDistinguishedName ::=
* SET OF AttributeTypeAndValue
*
*
* AttributeValue ::= ANY DEFINED BY AttributeType
*
- * We restrict RelativeDistinguishedName to be a set of 1 element. This is
- * the most common case, and our x509_name structure currently can't handle
- * more than that.
+ * The data structure is optimized for the common case where each RDN has only
+ * one element, which is represented as a list of AttributeTypeAndValue.
+ * For the general case we still use a flat list, but we mark elements of the
+ * same set so that they are "merged" together in the functions that consume
+ * this list, eg x509_dn_gets().
*/
int x509_get_name( unsigned char **p, const unsigned char *end,
x509_name *cur )
size_t set_len;
const unsigned char *end_set;
- /*
- * parse first SET, restricted to 1 element
- */
- if( ( ret = asn1_get_tag( p, end, &set_len,
- ASN1_CONSTRUCTED | ASN1_SET ) ) != 0 )
- return( POLARSSL_ERR_X509_INVALID_NAME + ret );
+ /* don't use recursion, we'd risk stack overflow if not optimized */
+ while( 1 )
+ {
+ /*
+ * parse SET
+ */
+ if( ( ret = asn1_get_tag( p, end, &set_len,
+ ASN1_CONSTRUCTED | ASN1_SET ) ) != 0 )
+ return( POLARSSL_ERR_X509_INVALID_NAME + ret );
- end_set = *p + set_len;
+ end_set = *p + set_len;
- if( ( ret = x509_get_attr_type_value( p, end_set, cur ) ) != 0 )
- return( ret );
+ while( 1 )
+ {
+ if( ( ret = x509_get_attr_type_value( p, end_set, cur ) ) != 0 )
+ return( ret );
- if( *p != end_set )
- return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
+ if( *p == end_set )
+ break;
- /*
- * recurse until end of SEQUENCE is reached
- */
- if( *p == end )
- return( 0 );
+ /* Mark this item as being not the only one in a set */
+ cur->next_merged = 1;
+
+ cur->next = polarssl_malloc( sizeof( x509_name ) );
- cur->next = (x509_name *) polarssl_malloc( sizeof( x509_name ) );
+ if( cur->next == NULL )
+ return( POLARSSL_ERR_X509_MALLOC_FAILED );
- if( cur->next == NULL )
- return( POLARSSL_ERR_X509_MALLOC_FAILED );
+ memset( cur->next, 0, sizeof( x509_name ) );
- memset( cur->next, 0, sizeof( x509_name ) );
+ cur = cur->next;
+ }
+
+ /*
+ * continue until end of SEQUENCE is reached
+ */
+ if( *p == end )
+ return( 0 );
- return( x509_get_name( p, end, cur->next ) );
+ cur->next = polarssl_malloc( sizeof( x509_name ) );
+
+ if( cur->next == NULL )
+ return( POLARSSL_ERR_X509_MALLOC_FAILED );
+
+ memset( cur->next, 0, sizeof( x509_name ) );
+
+ cur = cur->next;
+ }
+}
+
+static int x509_parse_int(unsigned char **p, unsigned n, int *res){
+ *res = 0;
+ for( ; n > 0; --n ){
+ if( ( **p < '0') || ( **p > '9' ) ) return POLARSSL_ERR_X509_INVALID_DATE;
+ *res *= 10;
+ *res += (*(*p)++ - '0');
+ }
+ return 0;
}
/*
{
int ret;
size_t len;
- char date[64];
unsigned char tag;
if( ( end - *p ) < 1 )
if( ret != 0 )
return( POLARSSL_ERR_X509_INVALID_DATE + ret );
- memset( date, 0, sizeof( date ) );
- memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
- len : sizeof( date ) - 1 );
-
- if( sscanf( date, "%2d%2d%2d%2d%2d%2dZ",
- &time->year, &time->mon, &time->day,
- &time->hour, &time->min, &time->sec ) < 5 )
+ CHECK( x509_parse_int( p, 2, &time->year ) );
+ CHECK( x509_parse_int( p, 2, &time->mon ) );
+ CHECK( x509_parse_int( p, 2, &time->day ) );
+ CHECK( x509_parse_int( p, 2, &time->hour ) );
+ CHECK( x509_parse_int( p, 2, &time->min ) );
+ if( len > 10 )
+ CHECK( x509_parse_int( p, 2, &time->sec ) );
+ if( len > 12 && *(*p)++ != 'Z' )
return( POLARSSL_ERR_X509_INVALID_DATE );
time->year += 100 * ( time->year < 50 );
time->year += 1900;
- *p += len;
-
return( 0 );
}
else if( tag == ASN1_GENERALIZED_TIME )
if( ret != 0 )
return( POLARSSL_ERR_X509_INVALID_DATE + ret );
- memset( date, 0, sizeof( date ) );
- memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
- len : sizeof( date ) - 1 );
-
- if( sscanf( date, "%4d%2d%2d%2d%2d%2dZ",
- &time->year, &time->mon, &time->day,
- &time->hour, &time->min, &time->sec ) < 5 )
+ CHECK( x509_parse_int( p, 4, &time->year ) );
+ CHECK( x509_parse_int( p, 2, &time->mon ) );
+ CHECK( x509_parse_int( p, 2, &time->day ) );
+ CHECK( x509_parse_int( p, 2, &time->hour ) );
+ CHECK( x509_parse_int( p, 2, &time->min ) );
+ if( len > 12 )
+ CHECK( x509_parse_int( p, 2, &time->sec ) );
+ if( len > 14 && *(*p)++ != 'Z' )
return( POLARSSL_ERR_X509_INVALID_DATE );
- *p += len;
-
return( 0 );
}
else
return( 0 );
}
-#if defined(POLARSSL_FS_IO)
-/*
- * Load all data from a file into a given buffer.
- */
-int x509_load_file( const char *path, unsigned char **buf, size_t *n )
-{
- FILE *f;
- long size;
-
- if( ( f = fopen( path, "rb" ) ) == NULL )
- return( POLARSSL_ERR_X509_FILE_IO_ERROR );
-
- fseek( f, 0, SEEK_END );
- if( ( size = ftell( f ) ) == -1 )
- {
- fclose( f );
- return( POLARSSL_ERR_X509_FILE_IO_ERROR );
- }
- fseek( f, 0, SEEK_SET );
-
- *n = (size_t) size;
-
- if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
- {
- fclose( f );
- return( POLARSSL_ERR_X509_MALLOC_FAILED );
- }
-
- if( fread( *buf, 1, *n, f ) != *n )
- {
- fclose( f );
- polarssl_free( *buf );
- return( POLARSSL_ERR_X509_FILE_IO_ERROR );
- }
-
- fclose( f );
-
- (*buf)[*n] = '\0';
-
- return( 0 );
-}
-#endif /* POLARSSL_FS_IO */
-
#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
!defined(EFI32)
#include <stdarg.h>
{
int ret;
size_t i, n;
- unsigned char c;
+ unsigned char c, merge = 0;
const x509_name *name;
const char *short_name = NULL;
char s[X509_MAX_DN_NAME_SIZE], *p;
if( name != dn )
{
- ret = snprintf( p, n, ", " );
+ ret = polarssl_snprintf( p, n, merge ? " + " : ", " );
SAFE_SNPRINTF();
}
ret = oid_get_attr_short_name( &name->oid, &short_name );
if( ret == 0 )
- ret = snprintf( p, n, "%s=", short_name );
+ ret = polarssl_snprintf( p, n, "%s=", short_name );
else
- ret = snprintf( p, n, "\?\?=" );
+ ret = polarssl_snprintf( p, n, "\?\?=" );
SAFE_SNPRINTF();
for( i = 0; i < name->val.len; i++ )
else s[i] = c;
}
s[i] = '\0';
- ret = snprintf( p, n, "%s", s );
+ ret = polarssl_snprintf( p, n, "%s", s );
SAFE_SNPRINTF();
+
+ merge = name->next_merged;
name = name->next;
}
if( i == 0 && nr > 1 && serial->p[i] == 0x0 )
continue;
- ret = snprintf( p, n, "%02X%s",
+ ret = polarssl_snprintf( p, n, "%02X%s",
serial->p[i], ( i < nr - 1 ) ? ":" : "" );
SAFE_SNPRINTF();
}
if( nr != serial->len )
{
- ret = snprintf( p, n, "...." );
+ ret = polarssl_snprintf( p, n, "...." );
SAFE_SNPRINTF();
}
ret = oid_get_sig_alg_desc( sig_oid, &desc );
if( ret != 0 )
- ret = snprintf( p, n, "???" );
+ ret = polarssl_snprintf( p, n, "???" );
else
- ret = snprintf( p, n, "%s", desc );
+ ret = polarssl_snprintf( p, n, "%s", desc );
SAFE_SNPRINTF();
#if defined(POLARSSL_X509_RSASSA_PSS_SUPPORT)
md_info = md_info_from_type( md_alg );
mgf_md_info = md_info_from_type( pss_opts->mgf1_hash_id );
- ret = snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
+ ret = polarssl_snprintf( p, n, " (%s, MGF1-%s, 0x%02X)",
md_info ? md_info->name : "???",
mgf_md_info ? mgf_md_info->name : "???",
pss_opts->expected_salt_len );
if( strlen( name ) + sizeof( " key size" ) > size )
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL );
- ret = snprintf( p, n, "%s key size", name );
+ ret = polarssl_snprintf( p, n, "%s key size", name );
SAFE_SNPRINTF();
return( 0 );
/*
* Return an informational string describing the given OID
*/
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
const char *x509_oid_get_description( x509_buf *oid )
{
const char *desc = NULL;
return( desc );
}
+#endif
/* Return the x.y.z.... style numeric string for the given OID */
+#if ! defined(POLARSSL_DEPRECATED_REMOVED)
int x509_oid_get_numeric_string( char *buf, size_t size, x509_buf *oid )
{
return oid_get_numeric_string( buf, size, oid );
}
+#endif
/*
* Return 0 if the x509_time is still valid, or 1 otherwise.
/*
* X.509 base functions for creating certificates / CSRs
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1write.h"
#include "polarssl/oid.h"
+#include <string.h>
+
#if defined(_MSC_VER) && !defined strncasecmp && !defined(EFIX64) && \
!defined(EFI32)
#define strncasecmp _strnicmp
/*
* X.509 Certidicate Revocation List (CRL) parsing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/x509_crl.h"
#include "polarssl/oid.h"
+
+#include <string.h>
+
#if defined(POLARSSL_PEM_PARSE_C)
#include "polarssl/pem.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
-#define polarssl_malloc malloc
+#include <stdlib.h>
+#include <stdio.h>
#define polarssl_free free
+#define polarssl_malloc malloc
+#define polarssl_snprintf snprintf
#endif
-#include <string.h>
-#include <stdlib.h>
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
-
#include <windows.h>
#else
#include <time.h>
if( cur_entry->next == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
+ memset( cur_entry->next, 0, sizeof( x509_crl_entry ) );
cur_entry = cur_entry->next;
- memset( cur_entry, 0, sizeof( x509_crl_entry ) );
}
}
}
/*
- * Parse one or more CRLs and add them to the chained list
+ * Parse one CRLs in DER format and append it to the chained list
*/
-int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
+int x509_crl_parse_der( x509_crl *chain,
+ const unsigned char *buf, size_t buflen )
{
int ret;
size_t len;
unsigned char *p, *end;
- x509_crl *crl;
x509_buf sig_params1, sig_params2;
-
-#if defined(POLARSSL_PEM_PARSE_C)
- size_t use_len;
- pem_context pem;
-#endif
-
- memset( &sig_params1, 0, sizeof( x509_buf ) );
- memset( &sig_params2, 0, sizeof( x509_buf ) );
-
- crl = chain;
+ x509_crl *crl = chain;
/*
* Check for valid input
if( crl == NULL || buf == NULL )
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
- while( crl->version != 0 && crl->next != NULL )
- crl = crl->next;
+ memset( &sig_params1, 0, sizeof( x509_buf ) );
+ memset( &sig_params2, 0, sizeof( x509_buf ) );
/*
* Add new CRL on the end of the chain if needed.
*/
+ while( crl->version != 0 && crl->next != NULL )
+ crl = crl->next;
+
if( crl->version != 0 && crl->next == NULL )
{
- crl->next = (x509_crl *) polarssl_malloc( sizeof( x509_crl ) );
+ crl->next = polarssl_malloc( sizeof( x509_crl ) );
if( crl->next == NULL )
{
return( POLARSSL_ERR_X509_MALLOC_FAILED );
}
+ x509_crl_init( crl->next );
crl = crl->next;
- x509_crl_init( crl );
}
-#if defined(POLARSSL_PEM_PARSE_C)
- pem_init( &pem );
- ret = pem_read_buffer( &pem,
- "-----BEGIN X509 CRL-----",
- "-----END X509 CRL-----",
- buf, NULL, 0, &use_len );
-
- if( ret == 0 )
- {
- /*
- * Was PEM encoded
- */
- buflen -= use_len;
- buf += use_len;
-
- /*
- * Steal PEM buffer
- */
- p = pem.buf;
- pem.buf = NULL;
- len = pem.buflen;
- pem_free( &pem );
- }
- else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
- {
- pem_free( &pem );
- return( ret );
- }
- else
-#endif /* POLARSSL_PEM_PARSE_C */
- {
- /*
- * nope, copy the raw DER data
- */
- p = (unsigned char *) polarssl_malloc( len = buflen );
-
- if( p == NULL )
- return( POLARSSL_ERR_X509_MALLOC_FAILED );
-
- memcpy( p, buf, buflen );
+ /*
+ * Copy raw DER-encoded CRL
+ */
+ if( ( p = polarssl_malloc( buflen ) ) == NULL )
+ return( POLARSSL_ERR_X509_MALLOC_FAILED );
- buflen = 0;
- }
+ memcpy( p, buf, buflen );
crl->raw.p = p;
- crl->raw.len = len;
- end = p + len;
+ crl->raw.len = buflen;
+
+ end = p + buflen;
/*
* CertificateList ::= SEQUENCE {
if( crl->sig_oid1.len != crl->sig_oid2.len ||
memcmp( crl->sig_oid1.p, crl->sig_oid2.p, crl->sig_oid1.len ) != 0 ||
sig_params1.len != sig_params2.len ||
- memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 )
+ ( sig_params1.len != 0 &&
+ memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) )
{
x509_crl_free( crl );
return( POLARSSL_ERR_X509_SIG_MISMATCH );
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
}
- if( buflen > 0 )
+ return( 0 );
+}
+
+/*
+ * Parse one or more CRLs and add them to the chained list
+ */
+int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
+{
+#if defined(POLARSSL_PEM_PARSE_C)
+ int ret;
+ size_t use_len;
+ pem_context pem;
+ int is_pem = 0;
+
+ if( chain == NULL || buf == NULL )
+ return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
+
+ do
{
- crl->next = (x509_crl *) polarssl_malloc( sizeof( x509_crl ) );
+ pem_init( &pem );
+ ret = pem_read_buffer( &pem,
+ "-----BEGIN X509 CRL-----",
+ "-----END X509 CRL-----",
+ buf, NULL, 0, &use_len );
- if( crl->next == NULL )
+ if( ret == 0 )
{
- x509_crl_free( crl );
- return( POLARSSL_ERR_X509_MALLOC_FAILED );
- }
+ /*
+ * Was PEM encoded
+ */
+ is_pem = 1;
- crl = crl->next;
- x509_crl_init( crl );
+ buflen -= use_len;
+ buf += use_len;
- return( x509_crl_parse( crl, buf, buflen ) );
+ if( ( ret = x509_crl_parse_der( chain,
+ pem.buf, pem.buflen ) ) != 0 )
+ {
+ return( ret );
+ }
+
+ pem_free( &pem );
+ }
+ else if( ret != POLARSSL_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
+ {
+ pem_free( &pem );
+ return( ret );
+ }
}
+ while( is_pem && buflen > 0 );
- return( 0 );
+ if( is_pem )
+ return( 0 );
+ else
+#endif /* POLARSSL_PEM_PARSE_C */
+ return( x509_crl_parse_der( chain, buf, buflen ) );
}
#if defined(POLARSSL_FS_IO)
size_t n;
unsigned char *buf;
- if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+ if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_crl_parse( chain, buf, n );
p = buf;
n = size;
- ret = snprintf( p, n, "%sCRL version : %d",
+ ret = polarssl_snprintf( p, n, "%sCRL version : %d",
prefix, crl->version );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%sissuer name : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%sissuer name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crl->issuer );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%sthis update : " \
+ ret = polarssl_snprintf( p, n, "\n%sthis update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->this_update.year, crl->this_update.mon,
crl->this_update.day, crl->this_update.hour,
crl->this_update.min, crl->this_update.sec );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%snext update : " \
+ ret = polarssl_snprintf( p, n, "\n%snext update : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crl->next_update.year, crl->next_update.mon,
crl->next_update.day, crl->next_update.hour,
entry = &crl->entry;
- ret = snprintf( p, n, "\n%sRevoked certificates:",
+ ret = polarssl_snprintf( p, n, "\n%sRevoked certificates:",
prefix );
SAFE_SNPRINTF();
while( entry != NULL && entry->raw.len != 0 )
{
- ret = snprintf( p, n, "\n%sserial number: ",
+ ret = polarssl_snprintf( p, n, "\n%sserial number: ",
prefix );
SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &entry->serial );
SAFE_SNPRINTF();
- ret = snprintf( p, n, " revocation date: " \
+ ret = polarssl_snprintf( p, n, " revocation date: " \
"%04d-%02d-%02d %02d:%02d:%02d",
entry->revocation_date.year, entry->revocation_date.mon,
entry->revocation_date.day, entry->revocation_date.hour,
entry = entry->next;
}
- ret = snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &crl->sig_oid1, crl->sig_pk, crl->sig_md,
crl->sig_opts );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n" );
+ ret = polarssl_snprintf( p, n, "\n" );
SAFE_SNPRINTF();
return( (int) ( size - n ) );
/*
* X.509 certificate parsing and verification
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/x509_crt.h"
#include "polarssl/oid.h"
+
+#include <stdio.h>
+#include <string.h>
+
#if defined(POLARSSL_PEM_PARSE_C)
#include "polarssl/pem.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
-#define polarssl_malloc malloc
+#include <stdlib.h>
#define polarssl_free free
+#define polarssl_malloc malloc
+#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_THREADING_C)
#include "polarssl/threading.h"
#endif
-#include <string.h>
-#include <stdlib.h>
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
#include <windows.h>
#else
#include <time.h>
#endif
-#if defined(EFIX64) || defined(EFI32)
-#include <stdio.h>
-#endif
-
#if defined(POLARSSL_FS_IO)
#include <stdio.h>
#if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
-#endif
+#endif /* !_WIN32 || EFIX64 || EFI32 */
#endif
/* Implementation that should never be optimized out by the compiler */
* nameAssigner [0] DirectoryString OPTIONAL,
* partyName [1] DirectoryString }
*
- * NOTE: PolarSSL only parses and uses dNSName at this point.
+ * NOTE: we only parse and use dNSName at this point.
*/
static int x509_get_subject_alt_name( unsigned char **p,
const unsigned char *end,
/* Allocate and assign next pointer */
if( cur->buf.p != NULL )
{
- cur->next = (asn1_sequence *) polarssl_malloc(
- sizeof( asn1_sequence ) );
+ if( cur->next != NULL )
+ return( POLARSSL_ERR_X509_INVALID_EXTENSIONS );
+
+ cur->next = polarssl_malloc( sizeof( asn1_sequence ) );
if( cur->next == NULL )
return( POLARSSL_ERR_X509_INVALID_EXTENSIONS +
continue;
}
+ /* Forbid repeated extensions */
+ if( ( crt->ext_types & ext_type ) != 0 )
+ return( POLARSSL_ERR_X509_INVALID_EXTENSIONS );
+
crt->ext_types |= ext_type;
switch( ext_type )
if( crt == NULL || buf == NULL )
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
- p = (unsigned char *) polarssl_malloc( len = buflen );
+ p = polarssl_malloc( len = buflen );
if( p == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
if( crt->sig_oid1.len != crt->sig_oid2.len ||
memcmp( crt->sig_oid1.p, crt->sig_oid2.p, crt->sig_oid1.len ) != 0 ||
sig_params1.len != sig_params2.len ||
- memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 )
+ ( sig_params1.len != 0 &&
+ memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 ) )
{
x509_crt_free( crt );
return( POLARSSL_ERR_X509_SIG_MISMATCH );
*/
if( crt->version != 0 && crt->next == NULL )
{
- crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) );
+ crt->next = polarssl_malloc( sizeof( x509_crt ) );
if( crt->next == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
prev = crt;
+ x509_crt_init( crt->next );
crt = crt->next;
- x509_crt_init( crt );
}
if( ( ret = x509_crt_parse_der_core( crt, buf, buflen ) ) != 0 )
size_t n;
unsigned char *buf;
- if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+ if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_crt_parse( chain, buf, n );
w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir,
MAX_PATH - 3 );
+ if( w_ret == 0 )
+ return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
hFind = FindFirstFileW( szDir, &file_data );
if( hFind == INVALID_HANDLE_VALUE )
lstrlenW( file_data.cFileName ),
p, len - 1,
NULL, NULL );
+ if( w_ret == 0 )
+ return( POLARSSL_ERR_X509_FILE_IO_ERROR );
w_ret = x509_crt_parse_file( chain, filename );
if( w_ret < 0 )
while( ( entry = readdir( dir ) ) != NULL )
{
- snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
+ polarssl_snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
if( stat( entry_name, &sb ) == -1 )
{
#define PRINT_ITEM(i) \
{ \
- ret = snprintf( p, n, "%s" i, sep ); \
+ ret = polarssl_snprintf( p, n, "%s" i, sep ); \
SAFE_SNPRINTF(); \
sep = ", "; \
}
if( oid_get_extended_key_usage( &cur->buf, &desc ) != 0 )
desc = "???";
- ret = snprintf( p, n, "%s%s", sep, desc );
+ ret = polarssl_snprintf( p, n, "%s%s", sep, desc );
SAFE_SNPRINTF();
sep = ", ";
p = buf;
n = size;
- ret = snprintf( p, n, "%scert. version : %d\n",
+ ret = polarssl_snprintf( p, n, "%scert. version : %d\n",
prefix, crt->version );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "%sserial number : ",
+ ret = polarssl_snprintf( p, n, "%sserial number : ",
prefix );
SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &crt->serial );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%sissuer name : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%sissuer name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crt->issuer );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%ssubject name : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssubject name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &crt->subject );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%sissued on : " \
+ ret = polarssl_snprintf( p, n, "\n%sissued on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_from.year, crt->valid_from.mon,
crt->valid_from.day, crt->valid_from.hour,
crt->valid_from.min, crt->valid_from.sec );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%sexpires on : " \
+ ret = polarssl_snprintf( p, n, "\n%sexpires on : " \
"%04d-%02d-%02d %02d:%02d:%02d", prefix,
crt->valid_to.year, crt->valid_to.mon,
crt->valid_to.day, crt->valid_to.hour,
crt->valid_to.min, crt->valid_to.sec );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &crt->sig_oid1, crt->sig_pk,
return( ret );
}
- ret = snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
+ ret = polarssl_snprintf( p, n, "\n%s%-" BC "s: %d bits", prefix, key_size_str,
(int) pk_get_size( &crt->pk ) );
SAFE_SNPRINTF();
if( crt->ext_types & EXT_BASIC_CONSTRAINTS )
{
- ret = snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
+ ret = polarssl_snprintf( p, n, "\n%sbasic constraints : CA=%s", prefix,
crt->ca_istrue ? "true" : "false" );
SAFE_SNPRINTF();
if( crt->max_pathlen > 0 )
{
- ret = snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
+ ret = polarssl_snprintf( p, n, ", max_pathlen=%d", crt->max_pathlen - 1 );
SAFE_SNPRINTF();
}
}
if( crt->ext_types & EXT_SUBJECT_ALT_NAME )
{
- ret = snprintf( p, n, "\n%ssubject alt name : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssubject alt name : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_subject_alt_name( &p, &n,
if( crt->ext_types & EXT_NS_CERT_TYPE )
{
- ret = snprintf( p, n, "\n%scert. type : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%scert. type : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_cert_type( &p, &n, crt->ns_cert_type ) ) != 0 )
if( crt->ext_types & EXT_KEY_USAGE )
{
- ret = snprintf( p, n, "\n%skey usage : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%skey usage : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_key_usage( &p, &n, crt->key_usage ) ) != 0 )
if( crt->ext_types & EXT_EXTENDED_KEY_USAGE )
{
- ret = snprintf( p, n, "\n%sext key usage : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%sext key usage : ", prefix );
SAFE_SNPRINTF();
if( ( ret = x509_info_ext_key_usage( &p, &n,
return( ret );
}
- ret = snprintf( p, n, "\n" );
+ ret = polarssl_snprintf( p, n, "\n" );
SAFE_SNPRINTF();
return( (int) ( size - n ) );
}
+struct x509_crt_verify_string {
+ int code;
+ const char *string;
+};
+
+static const struct x509_crt_verify_string x509_crt_verify_strings[] = {
+ { BADCERT_EXPIRED, "The certificate validity has expired" },
+ { BADCERT_REVOKED, "The certificate has been revoked (is on a CRL)" },
+ { BADCERT_CN_MISMATCH, "The certificate Common Name (CN) does not match with the expected CN" },
+ { BADCERT_NOT_TRUSTED, "The certificate is not correctly signed by the trusted CA" },
+ { BADCRL_NOT_TRUSTED, "The CRL is not correctly signed by the trusted CA" },
+ { BADCRL_EXPIRED, "The CRL is expired" },
+ { BADCERT_MISSING, "Certificate was missing" },
+ { BADCERT_SKIP_VERIFY, "Certificate verification was skipped" },
+ { BADCERT_OTHER, "Other reason (can be used by verify callback)" },
+ { BADCERT_FUTURE, "The certificate validity starts in the future" },
+ { BADCRL_FUTURE, "The CRL is from the future" },
+ { BADCERT_KEY_USAGE, "Usage does not match the keyUsage extension" },
+ { BADCERT_EXT_KEY_USAGE, "Usage does not match the extendedKeyUsage extension" },
+ { BADCERT_NS_CERT_TYPE, "Usage does not match the nsCertType extension" },
+ { 0, NULL }
+};
+
+int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
+ int flags )
+{
+ int ret;
+ const struct x509_crt_verify_string *cur;
+ char *p = buf;
+ size_t n = size;
+
+ for( cur = x509_crt_verify_strings; cur->string != NULL ; cur++ )
+ {
+ if( ( flags & cur->code ) == 0 )
+ continue;
+
+ ret = polarssl_snprintf( p, n, "%s%s\n", prefix, cur->string );
+ SAFE_SNPRINTF();
+ flags ^= cur->code;
+ }
+
+ if( flags != 0 )
+ {
+ ret = polarssl_snprintf( p, n, "%sUnknown reason "
+ "(this should not happen)\n", prefix );
+ SAFE_SNPRINTF();
+ }
+
+ return( (int) ( size - n ) );
+}
+
#if defined(POLARSSL_X509_CHECK_KEY_USAGE)
int x509_crt_check_key_usage( const x509_crt *crt, int usage )
{
*/
static int x509_name_cmp( const x509_name *a, const x509_name *b )
{
- if( a == NULL && b == NULL )
- return( 0 );
+ /* Avoid recursion, it might not be optimised by the compiler */
+ while( a != NULL || b != NULL )
+ {
+ if( a == NULL || b == NULL )
+ return( -1 );
- if( a == NULL || b == NULL )
- return( -1 );
+ /* type */
+ if( a->oid.tag != b->oid.tag ||
+ a->oid.len != b->oid.len ||
+ memcmp( a->oid.p, b->oid.p, b->oid.len ) != 0 )
+ {
+ return( -1 );
+ }
- /* type */
- if( a->oid.tag != b->oid.tag ||
- a->oid.len != b->oid.len ||
- memcmp( a->oid.p, b->oid.p, b->oid.len ) != 0 )
- {
- return( -1 );
- }
+ /* value */
+ if( x509_string_cmp( &a->val, &b->val ) != 0 )
+ return( -1 );
- /* value */
- if( x509_string_cmp( &a->val, &b->val ) != 0 )
- return( -1 );
+ /* structure of the list of sets */
+ if( a->next_merged != b->next_merged )
+ return( -1 );
- return( x509_name_cmp( a->next, b->next ) );
+ a = a->next;
+ b = b->next;
+ }
+
+ /* a == NULL == b */
+ return( 0 );
}
/*
void *p_vrfy )
{
int ret;
- int ca_flags = 0, check_path_cnt = path_cnt + 1;
+ int ca_flags = 0, check_path_cnt;
unsigned char hash[POLARSSL_MD_MAX_SIZE];
const md_info_t *md_info;
if( x509_crt_check_parent( child, trust_ca, 1, path_cnt == 0 ) != 0 )
continue;
+ check_path_cnt = path_cnt + 1;
+
/*
- * Reduce path_len to check against if top of the chain is
+ * Reduce check_path_cnt to check against if top of the chain is
* the same as the trusted CA
*/
if( child->subject_raw.len == trust_ca->subject_raw.len &&
x509_crt *grandparent;
const md_info_t *md_info;
+ /* path_cnt is 0 for the first intermediate CA */
+ if( 1 + path_cnt > POLARSSL_X509_MAX_INTERMEDIATE_CA )
+ {
+ *flags |= BADCERT_NOT_TRUSTED;
+ return( POLARSSL_ERR_X509_CERT_VERIFY_FAILED );
+ }
+
if( x509_time_expired( &child->valid_to ) )
*flags |= BADCERT_EXPIRED;
/*
* X.509 Certificate Signing Request (CSR) parsing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/x509_csr.h"
#include "polarssl/oid.h"
+
+#include <string.h>
+
#if defined(POLARSSL_PEM_PARSE_C)
#include "polarssl/pem.h"
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
-#define polarssl_malloc malloc
+#include <stdlib.h>
+#include <stdio.h>
#define polarssl_free free
+#define polarssl_malloc malloc
+#define polarssl_snprintf snprintf
#endif
-#include <string.h>
-#include <stdlib.h>
-
#if defined(POLARSSL_FS_IO) || defined(EFIX64) || defined(EFI32)
#include <stdio.h>
#endif
/*
* first copy the raw DER data
*/
- p = (unsigned char *) polarssl_malloc( len = buflen );
+ p = polarssl_malloc( len = buflen );
if( p == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
size_t n;
unsigned char *buf;
- if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+ if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_csr_parse( csr, buf, n );
p = buf;
n = size;
- ret = snprintf( p, n, "%sCSR version : %d",
+ ret = polarssl_snprintf( p, n, "%sCSR version : %d",
prefix, csr->version );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%ssubject name : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssubject name : ", prefix );
SAFE_SNPRINTF();
ret = x509_dn_gets( p, n, &csr->subject );
SAFE_SNPRINTF();
- ret = snprintf( p, n, "\n%ssigned using : ", prefix );
+ ret = polarssl_snprintf( p, n, "\n%ssigned using : ", prefix );
SAFE_SNPRINTF();
ret = x509_sig_alg_gets( p, n, &csr->sig_oid, csr->sig_pk, csr->sig_md,
return( ret );
}
- ret = snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
+ ret = polarssl_snprintf( p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str,
(int) pk_get_size( &csr->pk ) );
SAFE_SNPRINTF();
/*
* X.509 certificate writing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/asn1write.h"
#include "polarssl/sha1.h"
+#include <string.h>
+
#if defined(POLARSSL_PEM_WRITE_C)
#include "polarssl/pem.h"
#endif /* POLARSSL_PEM_WRITE_C */
/*
* X.509 Certificate Signing Request writing
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/oid.h"
#include "polarssl/asn1write.h"
+#include <string.h>
+#include <stdlib.h>
+
#if defined(POLARSSL_PEM_WRITE_C)
#include "polarssl/pem.h"
#endif
-#include <string.h>
-#include <stdlib.h>
-
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
/*
* An 32-bit implementation of the XTEA algorithm
*
- * Copyright (C) 2006-2014, Brainspark B.V.
+ * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
*
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
+ * This file is part of mbed TLS (https://tls.mbed.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "polarssl/xtea.h"
+#include <string.h>
+
+#if defined(POLARSSL_SELF_TEST)
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
+#include <stdio.h>
#define polarssl_printf printf
-#endif
+#endif /* POLARSSL_PLATFORM_C */
+#endif /* POLARSSL_SELF_TEST */
#if !defined(POLARSSL_XTEA_ALT)
#if defined(POLARSSL_SELF_TEST)
-#include <string.h>
-#include <stdio.h>
-
/*
* XTEA tests vectors (non-official)
*/
+++ /dev/null
-cmake_minimum_required(VERSION 2.6)
-project(POLARSSL C)
-
-string(REGEX MATCH "Clang" CMAKE_COMPILER_IS_CLANG "${CMAKE_C_COMPILER_ID}")
-
-if(CMAKE_COMPILER_IS_GNUCC)
- set(CMAKE_C_FLAGS "-Wall -Wextra -W -Wdeclaration-after-statement -Wlogical-op -Wwrite-strings")
- set(CMAKE_C_FLAGS_RELEASE "-O2")
- set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
- set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
- set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1 -Werror")
- set(CMAKE_C_FLAGS_CHECK "-O1 -Werror")
- set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
-endif(CMAKE_COMPILER_IS_GNUCC)
-
-if(CMAKE_COMPILER_IS_CLANG)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wdocumentation -Wunreachable-code")
- set(CMAKE_C_FLAGS_RELEASE "-O2")
- set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
- set(CMAKE_C_FLAGS_COVERAGE "-g3 -O0 --coverage")
- set(CMAKE_C_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer -g3 -O1 -Werror")
- set(CMAKE_C_FLAGS_CHECK "-O1 -Werror")
-endif(CMAKE_COMPILER_IS_CLANG)
-
-set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
- CACHE STRING "Choose the type of build: None Debug Release Coverage ASan Check CheckFull"
- FORCE)
-
-if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
- if(CMAKE_COMPILER_IS_GNUCC)
- set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
- endif(CMAKE_COMPILER_IS_GNUCC)
- if(CMAKE_COMPILER_IS_CLANG)
- set(CMAKE_SHARED_LINKER_FLAGS "--coverage")
- endif(CMAKE_COMPILER_IS_CLANG)
-endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
-
-option(USE_PKCS11_HELPER_LIBRARY "Build PolarSSL with the pkcs11-helper library." OFF)
-
-option(ENABLE_ZLIB_SUPPORT "Build PolarSSL with zlib library." OFF)
-option(ENABLE_PROGRAMS "Build PolarSSL programs." ON)
-option(ENABLE_TESTING "Build PolarSSL tests." ON)
-
-if(ENABLE_TESTING)
- enable_testing()
-endif()
-
-if(LIB_INSTALL_DIR)
-else()
-set(LIB_INSTALL_DIR lib)
-endif()
-
-include_directories(include/)
-
-if(ENABLE_ZLIB_SUPPORT)
- find_package(ZLIB)
-
- if(ZLIB_FOUND)
- include_directories(${ZLIB_INCLUDE_DIR})
- endif(ZLIB_FOUND)
-endif(ENABLE_ZLIB_SUPPORT)
-
-add_subdirectory(library)
-add_subdirectory(include)
-
-if(ENABLE_TESTING)
- if(CMAKE_COMPILER_IS_GNUCC)
- add_subdirectory(tests)
- endif(CMAKE_COMPILER_IS_GNUCC)
- if(CMAKE_COMPILER_IS_CLANG)
- add_subdirectory(tests)
- endif(CMAKE_COMPILER_IS_CLANG)
-endif()
-
-if(ENABLE_PROGRAMS)
- add_subdirectory(programs)
-endif()
-
-ADD_CUSTOM_TARGET(apidoc
- COMMAND doxygen doxygen/polarssl.doxyfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-
-if(ENABLE_TESTING)
- ADD_CUSTOM_TARGET(test-ref-config
- COMMAND tests/scripts/test-ref-configs.pl
- )
-
- ADD_CUSTOM_TARGET(covtest
- COMMAND make test
- COMMAND programs/test/selftest
- COMMAND cd tests && ./compat.sh
- COMMAND cd tests && ./ssl-opt.sh
- )
-
- ADD_CUSTOM_TARGET(lcov
- COMMAND rm -rf Coverage
- COMMAND lcov --capture --initial --directory library/CMakeFiles/polarssl.dir -o files.info
- COMMAND lcov --capture --directory library/CMakeFiles/polarssl.dir -o tests.info
- COMMAND lcov --add-tracefile files.info --add-tracefile tests.info -o all.info
- COMMAND lcov --remove all.info -o final.info '*.h'
- COMMAND gendesc tests/Descriptions.txt -o descriptions
- COMMAND genhtml --title PolarSSL --description-file descriptions --keep-descriptions --legend --no-branch-coverage -o Coverage final.info
- COMMAND rm -f files.info tests.info all.info final.info descriptions
- )
-
- ADD_CUSTOM_TARGET(memcheck
- COMMAND ctest -O memcheck.log -D ExperimentalMemCheck
- COMMAND tail -n1 memcheck.log | grep 'Memory checking results:' > /dev/null
- COMMAND rm -f memcheck.log
- )
-endif()
+++ /dev/null
-*.o
-libpolarssl*
+++ /dev/null
-option(USE_STATIC_POLARSSL_LIBRARY "Build PolarSSL static library." ON)
-option(USE_SHARED_POLARSSL_LIBRARY "Build PolarSSL shared library." OFF)
-option(LINK_WITH_PTHREAD "Explicitly link PolarSSL library to pthread." OFF)
-
-set(src
- aes.c
- aesni.c
- arc4.c
- asn1parse.c
- asn1write.c
- base64.c
- bignum.c
- blowfish.c
- camellia.c
- ccm.c
- certs.c
- cipher.c
- cipher_wrap.c
- ctr_drbg.c
- debug.c
- des.c
- dhm.c
- ecp.c
- ecp_curves.c
- ecdh.c
- ecdsa.c
- entropy.c
- entropy_poll.c
- error.c
- gcm.c
- havege.c
- hmac_drbg.c
- md.c
- md_wrap.c
- md2.c
- md4.c
- md5.c
- memory_buffer_alloc.c
- net.c
- oid.c
- padlock.c
- pbkdf2.c
- pem.c
- pkcs5.c
- pkcs11.c
- pkcs12.c
- pk.c
- pk_wrap.c
- pkparse.c
- pkwrite.c
- platform.c
- ripemd160.c
- rsa.c
- sha1.c
- sha256.c
- sha512.c
- ssl_cache.c
- ssl_ciphersuites.c
- ssl_cli.c
- ssl_srv.c
- ssl_tls.c
- threading.c
- timing.c
- version.c
- version_features.c
- x509.c
- x509_crt.c
- x509_crl.c
- x509_csr.c
- x509_create.c
- x509write_crt.c
- x509write_csr.c
- xtea.c
-)
-
-if(WIN32)
-set(libs ws2_32)
-endif(WIN32)
-
-if(CMAKE_COMPILER_IS_GNUCC)
- set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS_CHECK} -Wmissing-declarations -Wmissing-prototypes")
- set(CMAKE_C_FLAGS_CHECKFULL "${CMAKE_C_FLAGS_CHECK} -Wcast-qual")
-endif(CMAKE_COMPILER_IS_GNUCC)
-
-if(CMAKE_COMPILER_IS_CLANG)
- set(CMAKE_C_FLAGS_CHECK "${CMAKE_C_FLAGS_CHECK} -Wmissing-declarations -Wmissing-prototypes")
-endif(CMAKE_COMPILER_IS_CLANG)
-
-if (NOT USE_STATIC_POLARSSL_LIBRARY AND NOT USE_SHARED_POLARSSL_LIBRARY)
- message(FATAL_ERROR "Need to choose static or shared polarssl build!")
-endif(NOT USE_STATIC_POLARSSL_LIBRARY AND NOT USE_SHARED_POLARSSL_LIBRARY)
-
-if(USE_STATIC_POLARSSL_LIBRARY AND USE_SHARED_POLARSSL_LIBRARY)
- # if we build both static an shared, then let
- # tests and programs link to the shared lib target
- set(polarssl_static_target "polarssl_static")
-elseif(USE_STATIC_POLARSSL_LIBRARY)
- set(polarssl_static_target "polarssl")
-endif()
-
-if(USE_STATIC_POLARSSL_LIBRARY)
- add_library(${polarssl_static_target} STATIC ${src})
- set_target_properties(${polarssl_static_target} PROPERTIES OUTPUT_NAME polarssl)
- target_link_libraries(${polarssl_static_target} ${libs})
-
- if(ZLIB_FOUND)
- target_link_libraries(${polarssl_static_target} ${ZLIB_LIBRARIES})
- endif(ZLIB_FOUND)
-
- if(LINK_WITH_PTHREAD)
- target_link_libraries(${polarssl_static_target} pthread)
- endif()
-
- install(TARGETS ${polarssl_static_target}
- DESTINATION ${LIB_INSTALL_DIR}
- PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
-endif()
-
-if(USE_SHARED_POLARSSL_LIBRARY)
- add_library(polarssl SHARED ${src})
- set_target_properties(polarssl PROPERTIES VERSION 1.3.9 SOVERSION 7)
-
- target_link_libraries(polarssl ${libs})
-
- if(ZLIB_FOUND)
- target_link_libraries(polarssl ${ZLIB_LIBRARIES})
- endif(ZLIB_FOUND)
-
- if(LINK_WITH_PTHREAD)
- target_link_libraries(polarssl pthread)
- endif()
-
- install(TARGETS polarssl
- DESTINATION ${LIB_INSTALL_DIR}
- PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
-endif(USE_SHARED_POLARSSL_LIBRARY)
[with_system_polarssl=no],
)
- POLARSSL_SUBDIR=polarssl
+ POLARSSL_SUBDIR=mbedtls
POLARSSL_CFLAGS=-I\$\(top_srcdir\)/ext/$POLARSSL_SUBDIR/include/
POLARSSL_LIBS="-L\$(top_builddir)/ext/$POLARSSL_SUBDIR/library/ -lpolarssl"
SYSCONFDIR=/etc/powerdns/
LOCALSTATEDIR=/var/run/
OPTFLAGS?=-O3
-CXXFLAGS:= $(CXXFLAGS) -Iext/rapidjson/include -I$(CURDIR)/ext/polarssl/include -Wall @CF_PIE@ @CF_FORTIFY@ @CF_STACK@ $(OPTFLAGS) $(PROFILEFLAGS) $(ARCHFLAGS) -pthread -Iext/yahttp -DHAVE_CONFIG_H
-CFLAGS:=$(CFLAGS) -Wall $(OPTFLAGS) @CF_PIE@ @CF_FORTIFY@ @CF_STACK@ $(PROFILEFLAGS) $(ARCHFLAGS) -I$(CURDIR)/ext/polarssl/include -pthread -DHAVE_CONFIG_H
+CXXFLAGS:= $(CXXFLAGS) -Iext/rapidjson/include -I$(CURDIR)/ext/mbedtls/include -Wall @CF_PIE@ @CF_FORTIFY@ @CF_STACK@ $(OPTFLAGS) $(PROFILEFLAGS) $(ARCHFLAGS) -pthread -Iext/yahttp -DHAVE_CONFIG_H
+CFLAGS:=$(CFLAGS) -Wall $(OPTFLAGS) @CF_PIE@ @CF_FORTIFY@ @CF_STACK@ $(PROFILEFLAGS) $(ARCHFLAGS) -I$(CURDIR)/ext/mbedtls/include -pthread -DHAVE_CONFIG_H
LDFLAGS:=$(LDFLAGS) $(ARCHFLAGS) -pthread @LD_RELRO@ @CF_STACK@ @LD_PIE@
STRIP_BINARIES?=1
arguments.o lwres.o pdns_recursor.o recursor_cache.o dnsparser.o \
dnswriter.o dnsrecords.o rcpgenerator.o base64.o zoneparser-tng.o \
rec_channel.o rec_channel_rec.o selectmplexer.o sillyrecords.o \
-dns_random.o pubsuffix.o ext/polarssl/library/aes.o ext/polarssl/library/base64.o dnslabeltext.o \
+dns_random.o pubsuffix.o ext/mbedtls/library/aes.o ext/mbedtls/library/base64.o dnslabeltext.o \
lua-pdns.o lua-recursor.o randomhelper.o recpacketcache.o dns.o \
reczones.o base32.o nsecrecords.o json.o ws-recursor.o ws-api.o \
version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o ext/yahttp/yahttp/router.o \