From bc162e5d2be64ea3f552a61155211c2d6a1beb76 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 9 Feb 2019 17:41:21 +0100 Subject: for mbedtls --- test/monniaux/mbedtls/download_and_patch.sh | 4 ++ test/monniaux/mbedtls/make.sh | 3 + test/monniaux/mbedtls/mbedtls_Kalray.patch | 107 ++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100755 test/monniaux/mbedtls/download_and_patch.sh create mode 100755 test/monniaux/mbedtls/make.sh create mode 100644 test/monniaux/mbedtls/mbedtls_Kalray.patch (limited to 'test/monniaux/mbedtls') diff --git a/test/monniaux/mbedtls/download_and_patch.sh b/test/monniaux/mbedtls/download_and_patch.sh new file mode 100755 index 00000000..32f660fa --- /dev/null +++ b/test/monniaux/mbedtls/download_and_patch.sh @@ -0,0 +1,4 @@ +git clone https://github.com/ARMmbed/mbedtls.git +cd mbedtls +git checkout f352f75f6bd5734c8f671323dd6ab32472d5da34 +patch -p1 < ../mbedtls_Kalray.patch diff --git a/test/monniaux/mbedtls/make.sh b/test/monniaux/mbedtls/make.sh new file mode 100755 index 00000000..5d40988e --- /dev/null +++ b/test/monniaux/mbedtls/make.sh @@ -0,0 +1,3 @@ +CCOMP=`pwd`/../../../ccomp +cd mbedtls +make CC=$CCOMP CFLAGS="-fstruct-passing -fbitfields -Dvolatile= -U__STRICT_ANSI__" WARNING_CFLAGS="-Wall -fno-unprototyped" "$@" diff --git a/test/monniaux/mbedtls/mbedtls_Kalray.patch b/test/monniaux/mbedtls/mbedtls_Kalray.patch new file mode 100644 index 00000000..8b271130 --- /dev/null +++ b/test/monniaux/mbedtls/mbedtls_Kalray.patch @@ -0,0 +1,107 @@ +diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h +index f89bf9604..9f8a4faeb 100644 +--- a/include/mbedtls/config.h ++++ b/include/mbedtls/config.h +@@ -1076,7 +1076,7 @@ + * + * Enable functions that use the filesystem. + */ +-#define MBEDTLS_FS_IO ++// DMonniaux #define MBEDTLS_FS_IO + + /** + * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES +@@ -1100,7 +1100,8 @@ + * + * Uncomment this macro to disable the built-in platform entropy functions. + */ +-//#define MBEDTLS_NO_PLATFORM_ENTROPY ++//DMonniaux ++#define MBEDTLS_NO_PLATFORM_ENTROPY + + /** + * \def MBEDTLS_ENTROPY_FORCE_SHA256 +@@ -2441,7 +2442,7 @@ + * + * This module provides networking routines. + */ +-#define MBEDTLS_NET_C ++// DMonniaux #define MBEDTLS_NET_C + + /** + * \def MBEDTLS_OID_C +@@ -2838,7 +2839,7 @@ + * + * This module is used by the HAVEGE random number generator. + */ +-#define MBEDTLS_TIMING_C ++// DMonniaux #define MBEDTLS_TIMING_C + + /** + * \def MBEDTLS_VERSION_C +diff --git a/library/bignum.c b/library/bignum.c +index 87015af0c..a2bad7b84 100644 +--- a/library/bignum.c ++++ b/library/bignum.c +@@ -1696,6 +1696,8 @@ cleanup: + return( ret ); + } + ++#define INT_DIV(x,y) (((long)(x)) / (y)) ++ + /* + * Modulo: r = A mod b + */ +@@ -1734,12 +1736,12 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_ + { + x = A->p[i - 1]; + y = ( y << biH ) | ( x >> biH ); +- z = y / b; ++ z = INT_DIV(y, b); + y -= z * b; + + x <<= biH; + y = ( y << biH ) | ( x >> biH ); +- z = y / b; ++ z = INT_DIV(y, b); + y -= z * b; + } + +diff --git a/library/ssl_tls.c b/library/ssl_tls.c +index 8710a5076..e47c859fe 100644 +--- a/library/ssl_tls.c ++++ b/library/ssl_tls.c +@@ -2482,6 +2482,8 @@ static int ssl_decompress_buf( mbedtls_ssl_context *ssl ) + } + #endif /* MBEDTLS_ZLIB_SUPPORT */ + ++#define INT_DIV(x, y) (((long)(x))/(y)) ++ + #if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_RENEGOTIATION) + static int ssl_write_hello_request( mbedtls_ssl_context *ssl ); + +@@ -2492,7 +2494,7 @@ static int ssl_resend_hello_request( mbedtls_ssl_context *ssl ) + * timeout if we were using the usual handshake doubling scheme */ + if( ssl->conf->renego_max_records < 0 ) + { +- uint32_t ratio = ssl->conf->hs_timeout_max / ssl->conf->hs_timeout_min + 1; ++ uint32_t ratio = INT_DIV(ssl->conf->hs_timeout_max, ssl->conf->hs_timeout_min + 1); + unsigned char doublings = 1; + + while( ratio != 0 ) +diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function +index 1255ff4be..103abe9a8 100644 +--- a/tests/suites/helpers.function ++++ b/tests/suites/helpers.function +@@ -40,10 +40,10 @@ typedef UINT32 uint32_t; + #endif + + #include ++#include + + #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) + #include +-#include + #endif + + /* Type for Hex parameters */ -- cgit