Merge remote-tracking branch 'origin/pr/621' into baremetal
diff --git a/include/mbedtls/platform_util.h b/include/mbedtls/platform_util.h
index 09d0965..98384ad 100644
--- a/include/mbedtls/platform_util.h
+++ b/include/mbedtls/platform_util.h
@@ -113,6 +113,12 @@
#endif /* MBEDTLS_CHECK_PARAMS */
+#if defined(__GNUC__) || defined(__arm__)
+#define MBEDTLS_ALWAYS_INLINE __attribute__((always_inline))
+#else
+#define MBEDTLS_ALWAYS_INLINE
+#endif
+
/* Internal helper macros for deprecating API constants. */
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
#if defined(MBEDTLS_DEPRECATED_WARNING)
diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h
index 40ad4b1..710c286 100644
--- a/include/mbedtls/ssl.h
+++ b/include/mbedtls/ssl.h
@@ -142,11 +142,19 @@
/*
* Various constants
*/
+#if !defined(MBEDTLS_SSL_PROTO_NO_TLS)
#define MBEDTLS_SSL_MAJOR_VERSION_3 3
#define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
#define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
#define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
+#else /* MBEDTLS_SSL_PROTO_NO_TLS */
+#define MBEDTLS_SSL_MAJOR_VERSION_3 254
+#define MBEDTLS_SSL_MINOR_VERSION_0 257 /*!< unused */
+#define MBEDTLS_SSL_MINOR_VERSION_1 256 /*!< unused */
+#define MBEDTLS_SSL_MINOR_VERSION_2 255 /*!< DTLS v1.0 */
+#define MBEDTLS_SSL_MINOR_VERSION_3 253 /*!< DTLS v1.2 */
+#endif /* MBEDTLS_SSL_PROTO_NO_TLS */
#define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
#define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
@@ -1165,18 +1173,18 @@
unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
#endif
-#if !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER)
- unsigned char max_major_ver; /*!< max. major version used */
-#endif /* !MBEDTLS_SSL_CONF_MAX_MAJOR_VER */
-#if !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER)
- unsigned char max_minor_ver; /*!< max. minor version used */
-#endif /* !MBEDTLS_SSL_CONF_MAX_MINOR_VER */
#if !defined(MBEDTLS_SSL_CONF_MIN_MAJOR_VER)
unsigned char min_major_ver; /*!< min. major version used */
#endif /* !MBEDTLS_SSL_CONF_MIN_MAJOR_VER */
+#if !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER)
+ unsigned char max_major_ver; /*!< max. major version used */
+#endif /* !MBEDTLS_SSL_CONF_MAX_MAJOR_VER */
#if !defined(MBEDTLS_SSL_CONF_MIN_MINOR_VER)
- unsigned char min_minor_ver; /*!< min. minor version used */
+ uint16_t min_minor_ver; /*!< min. minor version used */
#endif /* !MBEDTLS_SSL_CONF_MIN_MINOR_VER */
+#if !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER)
+ uint16_t max_minor_ver; /*!< max. minor version used */
+#endif /* !MBEDTLS_SSL_CONF_MAX_MINOR_VER */
/*
* Flags (bitfields)
diff --git a/include/mbedtls/ssl_internal.h b/include/mbedtls/ssl_internal.h
index d9690cb..a98a458 100644
--- a/include/mbedtls/ssl_internal.h
+++ b/include/mbedtls/ssl_internal.h
@@ -1196,6 +1196,8 @@
#endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
MBEDTLS_SSL_PROTO_TLS1_2 */
+#if defined(MBEDTLS_SSL_PROTO_TLS)
+
/*
* Convert version numbers to/from wire format
* and, for DTLS, to/from TLS equivalent.
@@ -1257,6 +1259,88 @@
#endif /* MBEDTLS_SSL_PROTO_TLS */
}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_leq( int v0, int v1 )
+{
+ return( v0 <= v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_lt( int v0, int v1 )
+{
+ return( v0 < v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_geq( int v0, int v1 )
+{
+ return( v0 >= v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_gt( int v0, int v1 )
+{
+ return( v0 > v1 );
+}
+
+#else /* MBEDTLS_SSL_PROTO_TLS */
+
+/* If only DTLS is enabled, we can match the internal encoding
+ * with the standard's encoding of versions. */
+static inline void mbedtls_ssl_write_version( int major, int minor,
+ int transport,
+ unsigned char ver[2] )
+{
+ ((void) transport);
+ ver[0] = (unsigned char) major;
+ ver[1] = (unsigned char) minor;
+}
+
+static inline void mbedtls_ssl_read_version( int *major, int *minor,
+ int transport,
+ const unsigned char ver[2] )
+{
+ ((void) transport);
+ *major = ver[0];
+ *minor = ver[1];
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_leq( int v0, int v1 )
+{
+ return( v0 >= v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_lt( int v0, int v1 )
+{
+ return( v0 > v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_geq( int v0, int v1 )
+{
+ return( v0 <= v1 );
+}
+
+MBEDTLS_ALWAYS_INLINE static inline int mbedtls_ssl_ver_gt( int v0, int v1 )
+{
+ return( v0 < v1 );
+}
+
+#endif /* MBEDTLS_SSL_PROTO_TLS */
+
+MBEDTLS_ALWAYS_INLINE static inline size_t mbedtls_ssl_minor_ver_index(
+ int ver )
+{
+ switch( ver )
+ {
+ case MBEDTLS_SSL_MINOR_VERSION_0:
+ return( 0 );
+ case MBEDTLS_SSL_MINOR_VERSION_1:
+ return( 1 );
+ case MBEDTLS_SSL_MINOR_VERSION_2:
+ return( 2 );
+ case MBEDTLS_SSL_MINOR_VERSION_3:
+ return( 3 );
+ }
+ return( 0 );
+}
+
#ifdef __cplusplus
}
#endif
@@ -1697,7 +1781,8 @@
#define MBEDTLS_SSL_BEGIN_FOR_EACH_CIPHERSUITE( ssl, ver, info ) \
{ \
int const *__id_ptr; \
- for( __id_ptr=(ssl)->conf->ciphersuite_list[ (ver) ]; \
+ for( __id_ptr=(ssl)->conf->ciphersuite_list[ \
+ mbedtls_ssl_minor_ver_index( ver ) ]; \
*__id_ptr != 0; __id_ptr++ ) \
{ \
const int __id = *__id_ptr; \
diff --git a/include/tinycrypt/ecc.h b/include/tinycrypt/ecc.h
index 37a7ef1..9c53f3e 100644
--- a/include/tinycrypt/ecc.h
+++ b/include/tinycrypt/ecc.h
@@ -1,5 +1,10 @@
/* ecc.h - TinyCrypt interface to common ECC functions */
+/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
/* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
diff --git a/include/tinycrypt/ecc_dh.h b/include/tinycrypt/ecc_dh.h
index c680a77..a2edb01 100644
--- a/include/tinycrypt/ecc_dh.h
+++ b/include/tinycrypt/ecc_dh.h
@@ -1,6 +1,11 @@
/* ecc_dh.h - TinyCrypt interface to EC-DH implementation */
/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
diff --git a/include/tinycrypt/ecc_dsa.h b/include/tinycrypt/ecc_dsa.h
index cc5eebc..e54a77e 100644
--- a/include/tinycrypt/ecc_dsa.h
+++ b/include/tinycrypt/ecc_dsa.h
@@ -1,6 +1,11 @@
/* ecc_dh.h - TinyCrypt interface to EC-DSA implementation */
/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 5c2d870..84d5bbe 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -773,8 +773,10 @@
if( suite_info == MBEDTLS_SSL_CIPHERSUITE_INVALID_HANDLE )
return( 1 );
- if( mbedtls_ssl_suite_get_min_minor_ver( suite_info ) > max_minor_ver ||
- mbedtls_ssl_suite_get_max_minor_ver( suite_info ) < min_minor_ver )
+ if( mbedtls_ssl_ver_gt( mbedtls_ssl_suite_get_min_minor_ver( suite_info ),
+ max_minor_ver ) ||
+ mbedtls_ssl_ver_lt( mbedtls_ssl_suite_get_max_minor_ver( suite_info ),
+ min_minor_ver ) )
{
return( 1 );
}
@@ -1557,10 +1559,12 @@
* Since the RFC is not clear on this point, accept DTLS 1.0 (TLS 1.1)
* even is lower than our min version.
*/
- if( major_ver < MBEDTLS_SSL_MAJOR_VERSION_3 ||
- minor_ver < MBEDTLS_SSL_MINOR_VERSION_2 ||
- major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ||
- minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt( major_ver, MBEDTLS_SSL_MAJOR_VERSION_3 ) ||
+ mbedtls_ssl_ver_lt( minor_ver, MBEDTLS_SSL_MINOR_VERSION_2 ) ||
+ mbedtls_ssl_ver_gt( major_ver,
+ mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ) ||
+ mbedtls_ssl_ver_gt( minor_ver,
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server version" ) );
@@ -1715,10 +1719,14 @@
ssl->conf->transport,
buf + 0 );
- if( major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
- minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ||
- major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ||
- minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt( major_ver,
+ mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ) ||
+ mbedtls_ssl_ver_lt( minor_ver,
+ mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ) ||
+ mbedtls_ssl_ver_gt( major_ver,
+ mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ) ||
+ mbedtls_ssl_ver_gt( minor_ver,
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "server version out of bounds - "
" min: [%d:%d], server: [%d:%d], max: [%d:%d]",
@@ -2951,7 +2959,8 @@
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_1)
- if( mbedtls_ssl_get_minor_ver( ssl ) < MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_3 ) )
{
pk_alg = mbedtls_ssl_get_ciphersuite_sig_pk_alg( ciphersuite_info );
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index fd1ece0..0fa7c0e 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -878,7 +878,8 @@
* present them a SHA-higher cert rather than failing if it's the only
* one we got that satisfies the other conditions.
*/
- if( mbedtls_ssl_get_minor_ver( ssl ) < MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_3 ) )
{
mbedtls_md_type_t sig_md;
{
@@ -945,10 +946,12 @@
MBEDTLS_SSL_DEBUG_MSG( 3, ( "trying ciphersuite: %s",
mbedtls_ssl_suite_get_name( suite_info ) ) );
- if( mbedtls_ssl_suite_get_min_minor_ver( suite_info )
- > mbedtls_ssl_get_minor_ver( ssl ) ||
- mbedtls_ssl_suite_get_max_minor_ver( suite_info )
- < mbedtls_ssl_get_minor_ver( ssl ) )
+ if( mbedtls_ssl_ver_gt(
+ mbedtls_ssl_suite_get_min_minor_ver( suite_info ),
+ mbedtls_ssl_get_minor_ver( ssl ) ) ||
+ mbedtls_ssl_ver_lt(
+ mbedtls_ssl_suite_get_max_minor_ver( suite_info ),
+ mbedtls_ssl_get_minor_ver( ssl ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: version" ) );
return( 0 );
@@ -1120,7 +1123,8 @@
? buf[4] : mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
#endif
- if( mbedtls_ssl_get_minor_ver( ssl ) < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt( mbedtls_ssl_get_minor_ver( ssl ),
+ mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "client only supports ssl smaller than minimum"
" [%d:%d] < [%d:%d]",
@@ -1246,8 +1250,9 @@
{
MBEDTLS_SSL_DEBUG_MSG( 3, ( "received FALLBACK_SCSV" ) );
- if( mbedtls_ssl_get_minor_ver( ssl ) <
- mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "inapropriate fallback" ) );
@@ -1661,8 +1666,10 @@
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED ||
MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */
- if( major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
- minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt( major_ver,
+ mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ) ||
+ mbedtls_ssl_ver_lt( minor_ver,
+ mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "client only supports ssl smaller than minimum"
" [%d:%d] < [%d:%d]",
@@ -1674,13 +1681,19 @@
return( MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION );
}
- if( major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_gt(
+ major_ver,
+ mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ) )
{
major_ver = mbedtls_ssl_conf_get_max_major_ver( ssl->conf );
minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
}
- else if( minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ else if( mbedtls_ssl_ver_gt(
+ minor_ver,
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
+ {
minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
+ }
#if !defined(MBEDTLS_SSL_CONF_FIXED_MAJOR_VER)
ssl->major_ver = major_ver;
@@ -2070,8 +2083,9 @@
{
MBEDTLS_SSL_DEBUG_MSG( 2, ( "received FALLBACK_SCSV" ) );
- if( mbedtls_ssl_get_minor_ver( ssl ) <
- mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_lt(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "inapropriate fallback" ) );
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index e47c456..5a869b7 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -861,7 +861,7 @@
else
#endif
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
- if( minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( minor_ver, MBEDTLS_SSL_MINOR_VERSION_3 ) )
return( tls1_prf( secret, slen, label, random, rlen, dstbuf, dlen ) );
else
#endif
@@ -1160,7 +1160,7 @@
else
#endif
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
- if( minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( minor_ver, MBEDTLS_SSL_MINOR_VERSION_3 ) )
ssl_calc_finished_tls( ssl, buf, from );
else
#endif
@@ -1484,7 +1484,7 @@
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 )
+ if( mbedtls_ssl_ver_geq( minor_ver, MBEDTLS_SSL_MINOR_VERSION_1 ) )
{
/* For HMAC-based ciphersuites, initialize the HMAC transforms.
For AEAD-based ciphersuites, there is nothing to do here. */
@@ -1759,7 +1759,7 @@
else
#endif
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
- if( minor_ver < MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( minor_ver, MBEDTLS_SSL_MINOR_VERSION_3 ) )
ssl_calc_verify_tls( ssl, dst, hlen );
else
#endif
@@ -2533,8 +2533,9 @@
#endif
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >=
- MBEDTLS_SSL_MINOR_VERSION_1 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_1 ) )
{
unsigned char mac[MBEDTLS_SSL_MAC_ADD];
@@ -2713,8 +2714,9 @@
* Prepend per-record IV for block cipher in TLS v1.1 and up as per
* Method 1 (6.2.3.2. in RFC4346 and RFC5246)
*/
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >=
- MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
if( f_rng == NULL )
{
@@ -2763,8 +2765,9 @@
}
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) <
- MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_lt(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
/*
* Save IV in SSL3 and TLS1
@@ -3021,8 +3024,9 @@
* Check immediate ciphertext sanity
*/
#if defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >=
- MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
/* The ciphertext is prefixed with the CBC IV. */
minlen += transform->ivlen;
@@ -3127,8 +3131,9 @@
/*
* Initialize for prepended IV for block cipher in TLS v1.1 and up
*/
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >=
- MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
/* Safe because data_len >= minlen + ivlen = 2 * ivlen. */
memcpy( transform->iv_dec, data, transform->ivlen );
@@ -3157,8 +3162,9 @@
}
#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) <
- MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_lt(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
/*
* Save IV in SSL3 and TLS1, where CBC decryption of consecutive
@@ -3221,8 +3227,9 @@
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >
- MBEDTLS_SSL_MINOR_VERSION_0 )
+ if( mbedtls_ssl_ver_gt(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_0 ) )
{
/* The padding check involves a series of up to 256
* consecutive memory reads at the end of the record
@@ -3320,8 +3327,9 @@
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_transform_get_minor_ver( transform ) >
- MBEDTLS_SSL_MINOR_VERSION_0 )
+ if( mbedtls_ssl_ver_gt(
+ mbedtls_ssl_transform_get_minor_ver( transform ),
+ MBEDTLS_SSL_MINOR_VERSION_0 ) )
{
/*
* Process MAC and always update for padlen afterwards to make
@@ -5340,7 +5348,8 @@
return( MBEDTLS_ERR_SSL_INVALID_RECORD );
}
- if( minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
+ if( mbedtls_ssl_ver_gt( minor_ver,
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) )
{
MBEDTLS_SSL_DEBUG_MSG( 1, ( "minor version mismatch" ) );
return( MBEDTLS_ERR_SSL_INVALID_RECORD );
@@ -8162,7 +8171,9 @@
/* Adjust out_msg to make space for explicit IV, if used. */
if( transform != NULL &&
- mbedtls_ssl_get_minor_ver( ssl ) >= MBEDTLS_SSL_MINOR_VERSION_2 )
+ mbedtls_ssl_ver_geq(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
{
ssl->out_msg = ssl->out_iv + transform->ivlen - transform->fixed_ivlen;
}
@@ -8651,10 +8662,10 @@
void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
const int *ciphersuites )
{
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] = ciphersuites;
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] = ciphersuites;
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] = ciphersuites;
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] = ciphersuites;
+ conf->ciphersuite_list[0] = ciphersuites;
+ conf->ciphersuite_list[1] = ciphersuites;
+ conf->ciphersuite_list[2] = ciphersuites;
+ conf->ciphersuite_list[3] = ciphersuites;
}
void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
@@ -8664,10 +8675,14 @@
if( major != MBEDTLS_SSL_MAJOR_VERSION_3 )
return;
- if( minor < MBEDTLS_SSL_MINOR_VERSION_0 || minor > MBEDTLS_SSL_MINOR_VERSION_3 )
+ if( mbedtls_ssl_ver_lt( minor, MBEDTLS_SSL_MINOR_VERSION_0 ) ||
+ mbedtls_ssl_ver_gt( minor, MBEDTLS_SSL_MINOR_VERSION_3 ) )
+ {
return;
+ }
- conf->ciphersuite_list[minor] = ciphersuites;
+ conf->ciphersuite_list[mbedtls_ssl_minor_ver_index( minor )] =
+ ciphersuites;
}
#endif /* MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE */
@@ -9421,8 +9436,12 @@
/* For TLS 1.1 or higher, an explicit IV is added
* after the record header. */
#if defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_get_minor_ver( ssl ) >= MBEDTLS_SSL_MINOR_VERSION_2 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
+ {
transform_expansion += block_size;
+ }
#endif /* MBEDTLS_SSL_PROTO_TLS1_1 || MBEDTLS_SSL_PROTO_TLS1_2 */
break;
@@ -10628,7 +10647,9 @@
#endif /* MBEDTLS_SSL_PROTO_SSL3 */
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
defined(MBEDTLS_SSL_PROTO_TLS1_2)
- if( mbedtls_ssl_get_minor_ver( ssl ) >= MBEDTLS_SSL_MINOR_VERSION_1 )
+ if( mbedtls_ssl_ver_geq(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_1 ) )
{
ret = mbedtls_ssl_send_alert_message( ssl,
MBEDTLS_SSL_ALERT_LEVEL_WARNING,
@@ -10836,7 +10857,9 @@
if( ssl->conf->cbc_record_splitting ==
MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED ||
len <= 1 ||
- mbedtls_ssl_get_minor_ver( ssl ) > MBEDTLS_SSL_MINOR_VERSION_1 ||
+ mbedtls_ssl_ver_gt(
+ mbedtls_ssl_get_minor_ver( ssl ),
+ MBEDTLS_SSL_MINOR_VERSION_1 ) ||
mbedtls_cipher_get_cipher_mode( &ssl->transform_out->cipher_ctx_enc )
!= MBEDTLS_MODE_CBC )
{
@@ -11432,14 +11455,18 @@
* least check it matches the requirements for serializing.
*/
if( MBEDTLS_SSL_TRANSPORT_IS_TLS( ssl->conf->transport ) ||
- mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) <
- MBEDTLS_SSL_MAJOR_VERSION_3 ||
- mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) >
- MBEDTLS_SSL_MAJOR_VERSION_3 ||
- mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) <
- MBEDTLS_SSL_MINOR_VERSION_3 ||
- mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) >
- MBEDTLS_SSL_MINOR_VERSION_3 ||
+ mbedtls_ssl_ver_lt(
+ mbedtls_ssl_conf_get_max_major_ver( ssl->conf ),
+ MBEDTLS_SSL_MAJOR_VERSION_3 ) ||
+ mbedtls_ssl_ver_gt(
+ mbedtls_ssl_conf_get_min_major_ver( ssl->conf ),
+ MBEDTLS_SSL_MAJOR_VERSION_3 ) ||
+ mbedtls_ssl_ver_lt(
+ mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ),
+ MBEDTLS_SSL_MINOR_VERSION_3 ) ||
+ mbedtls_ssl_ver_gt(
+ mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ),
+ MBEDTLS_SSL_MINOR_VERSION_3 ) ||
mbedtls_ssl_conf_is_renegotiation_enabled( ssl->conf ) )
{
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
@@ -11964,11 +11991,11 @@
#endif /* !MBEDTLS_SSL_CONF_MAX_MINOR_VER */
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] =
- ssl_preset_suiteb_ciphersuites;
+ conf->ciphersuite_list[0] =
+ conf->ciphersuite_list[1] =
+ conf->ciphersuite_list[2] =
+ conf->ciphersuite_list[3] =
+ ssl_preset_suiteb_ciphersuites;
#endif /* MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE */
#if defined(MBEDTLS_X509_CRT_PARSE_C)
@@ -12016,11 +12043,11 @@
#endif /* !MBEDTLS_SSL_CONF_MAX_MINOR_VER */
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_0] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_1] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_2] =
- conf->ciphersuite_list[MBEDTLS_SSL_MINOR_VERSION_3] =
- mbedtls_ssl_list_ciphersuites();
+ conf->ciphersuite_list[0] =
+ conf->ciphersuite_list[1] =
+ conf->ciphersuite_list[2] =
+ conf->ciphersuite_list[3] =
+ mbedtls_ssl_list_ciphersuites();
#endif /* MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE */
#if defined(MBEDTLS_X509_CRT_PARSE_C)
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 788793a..5c13f8a 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -69,6 +69,8 @@
#include "mbedtls/debug.h"
#include "mbedtls/timing.h"
+#include "mbedtls/ssl_internal.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1506,14 +1508,18 @@
mbedtls_ssl_ciphersuite_from_id( opt.force_ciphersuite[0] );
if( opt.max_version != -1 &&
- mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) > opt.max_version )
+ mbedtls_ssl_ver_gt(
+ mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ),
+ opt.max_version ) )
{
mbedtls_printf( "forced ciphersuite not allowed with this protocol version\n" );
ret = 2;
goto usage;
}
if( opt.min_version != -1 &&
- mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) < opt.min_version )
+ mbedtls_ssl_ver_lt(
+ mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ),
+ opt.min_version ) )
{
mbedtls_printf( "forced ciphersuite not allowed with this protocol version\n" );
ret = 2;
@@ -1523,17 +1529,24 @@
/* If the server selects a version that's not supported by
* this suite, then there will be no common ciphersuite... */
if( opt.max_version == -1 ||
- opt.max_version > mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) )
+ mbedtls_ssl_ver_gt(
+ opt.max_version,
+ mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) ) )
{
opt.max_version = mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info );
}
- if( opt.min_version < mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) )
+ if( mbedtls_ssl_ver_lt(
+ opt.min_version,
+ mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) ) )
{
opt.min_version = mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info );
/* DTLS starts with TLS 1.1 */
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
- opt.min_version < MBEDTLS_SSL_MINOR_VERSION_2 )
+ mbedtls_ssl_ver_lt( opt.min_version,
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
+ {
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
+ }
}
/* Enable RC4 if needed and not explicitly disabled */
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index b07ab4f..c0476dc 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -68,6 +68,8 @@
#include "mbedtls/debug.h"
#include "mbedtls/timing.h"
+#include "mbedtls/ssl_internal.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -2232,14 +2234,18 @@
mbedtls_ssl_ciphersuite_from_id( opt.force_ciphersuite[0] );
if( opt.max_version != -1 &&
- mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) > opt.max_version )
+ mbedtls_ssl_ver_gt(
+ mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ),
+ opt.max_version ) )
{
mbedtls_printf( "forced ciphersuite not allowed with this protocol version\n" );
ret = 2;
goto usage;
}
if( opt.min_version != -1 &&
- mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) < opt.min_version )
+ mbedtls_ssl_ver_lt(
+ mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ),
+ opt.min_version ) )
{
mbedtls_printf( "forced ciphersuite not allowed with this protocol version\n" );
ret = 2;
@@ -2249,17 +2255,24 @@
/* If we select a version that's not supported by
* this suite, then there will be no common ciphersuite... */
if( opt.max_version == -1 ||
- opt.max_version > mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) )
+ mbedtls_ssl_ver_gt(
+ opt.max_version,
+ mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info ) ) )
{
opt.max_version = mbedtls_ssl_suite_get_max_minor_ver( ciphersuite_info );
}
- if( opt.min_version < mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) )
+ if( mbedtls_ssl_ver_lt(
+ opt.min_version,
+ mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info ) ) )
{
opt.min_version = mbedtls_ssl_suite_get_min_minor_ver( ciphersuite_info );
/* DTLS starts with TLS 1.1 */
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
- opt.min_version < MBEDTLS_SSL_MINOR_VERSION_2 )
+ mbedtls_ssl_ver_lt( opt.min_version,
+ MBEDTLS_SSL_MINOR_VERSION_2 ) )
+ {
opt.min_version = MBEDTLS_SSL_MINOR_VERSION_2;
+ }
}
/* Enable RC4 if needed and not explicitly disabled */
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5938a5f..2ea77e7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -133,6 +133,7 @@
add_test_suite(shax)
add_test_suite(ssl)
add_test_suite(timing)
+add_test_suite(tinycrypt)
add_test_suite(rsa)
add_test_suite(version)
add_test_suite(xtea)
diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function
index b177779..268d56c 100644
--- a/tests/suites/test_suite_ssl.function
+++ b/tests/suites/test_suite_ssl.function
@@ -121,7 +121,7 @@
CHK( mbedtls_md_setup( &t_in->md_ctx_enc, md_info, 1 ) == 0 );
CHK( mbedtls_md_setup( &t_in->md_ctx_dec, md_info, 1 ) == 0 );
- if( ver > MBEDTLS_SSL_MINOR_VERSION_0 )
+ if( mbedtls_ssl_ver_gt( ver, MBEDTLS_SSL_MINOR_VERSION_0 ) )
{
CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_enc,
md0, maclen ) == 0 );
diff --git a/tests/suites/test_suite_tinycrypt.data b/tests/suites/test_suite_tinycrypt.data
new file mode 100644
index 0000000..ac2a8e2
--- /dev/null
+++ b/tests/suites/test_suite_tinycrypt.data
@@ -0,0 +1,11 @@
+Tinycrypt ECDH
+test_ecdh:
+
+Tinycrypt ECDSA
+test_ecdsa:
+
+ECDH primitive rfc 5903 p256
+ecdh_primitive_testvec:"C88F01F510D9AC3F70A292DAA2316DE544E9AAB8AFE84049C62A9C57862D1433":"DAD0B65394221CF9B051E1FECA5787D098DFE637FC90B9EF945D0C3772581180":"5271A0461CDB8252D61F1C456FA3E59AB1F45B33ACCF5F58389E0577B8990BB3":"C6EF9C5D78AE012A011164ACB397CE2088685D8F06BF9BE0B283AB46476BEE53":"D12DFB5289C8D4F81208B70270398C342296970A0BCCB74C736FC7554494BF63":"56FBF3CA366CC23E8157854C13C58D6AAC23F046ADA30F8353E74F33039872AB":"D6840F6B42F6EDAFD13116E0E12565202FEF8E9ECE7DCE03812464D04B9442DE"
+
+ECDSA primitive rfc 4754 p256
+ecdsa_primitive_testvec:"2442A5CC0ECD015FA3CA31DC8E2BBC70BF42D60CBCA20085E0822CB04235E970":"6FC98BD7E50211A4A27102FA3549DF79EBCB4BF246B80945CDDFE7D509BBFD7D":"BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD":"CB28E0999B9C7715FD0A80D8E47A77079716CBBF917DD72E97566EA1C066957C":"86FA3BB4E26CAD5BF90B7F81899256CE7594BB1EA0C89212748BFF3B3D5B0315":1
diff --git a/tests/suites/test_suite_tinycrypt.function b/tests/suites/test_suite_tinycrypt.function
new file mode 100644
index 0000000..24b331d
--- /dev/null
+++ b/tests/suites/test_suite_tinycrypt.function
@@ -0,0 +1,117 @@
+/* BEGIN_HEADER */
+
+#include "tinycrypt/ecc.h"
+#include "tinycrypt/ecc_dh.h"
+#include "tinycrypt/ecc_dsa.h"
+
+/* END_HEADER */
+
+/* BEGIN_DEPENDENCIES
+ * depends_on:MBEDTLS_USE_TINYCRYPT
+ * END_DEPENDENCIES
+ */
+
+/* BEGIN_CASE depends_on:MBEDTLS_USE_TINYCRYPT */
+void test_ecdh()
+{
+ uint8_t private1[NUM_ECC_BYTES] = {0};
+ uint8_t private2[NUM_ECC_BYTES] = {0};
+ uint8_t public1[2*NUM_ECC_BYTES] = {0};
+ uint8_t public2[2*NUM_ECC_BYTES] = {0};
+ uint8_t secret1[NUM_ECC_BYTES] = {0};
+ uint8_t secret2[NUM_ECC_BYTES] = {0};
+
+ const struct uECC_Curve_t * curve = uECC_secp256r1();
+
+ uECC_set_rng( &uecc_rng_wrapper );
+
+ TEST_ASSERT( uECC_make_key( public1, private1, curve ) != 0 );
+
+ TEST_ASSERT( uECC_make_key( public2, private2, curve ) != 0 );
+
+ TEST_ASSERT( uECC_shared_secret( public2, private1, secret1, curve ) != 0 );
+
+ TEST_ASSERT( uECC_shared_secret( public1, private2, secret2, curve ) != 0 );
+
+ TEST_ASSERT( memcmp( secret1, secret2, sizeof( secret1 ) ) == 0 );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_USE_TINYCRYPT */
+void test_ecdsa()
+{
+ uint8_t private[NUM_ECC_BYTES] = {0};
+ uint8_t public[2*NUM_ECC_BYTES] = {0};
+ uint8_t hash[NUM_ECC_BYTES] = {0};
+ uint8_t sig[2*NUM_ECC_BYTES] = {0};
+
+ const struct uECC_Curve_t * curve = uECC_secp256r1();
+
+ uECC_set_rng( &uecc_rng_wrapper );
+
+ TEST_ASSERT( rnd_std_rand( NULL, hash, NUM_ECC_BYTES ) == 0 );
+
+ TEST_ASSERT( uECC_make_key( public, private, curve ) != 0 );
+
+ TEST_ASSERT( uECC_sign( private, hash, sizeof( hash ), sig, curve ) != 0 );
+
+ TEST_ASSERT( uECC_verify( public, hash, sizeof( hash ), sig, curve ) != 0 );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_USE_TINYCRYPT */
+void ecdh_primitive_testvec( data_t * private1, data_t * xA_str,
+ data_t * yA_str, data_t * private2,
+ data_t * xB_str, data_t * yB_str, data_t * z_str )
+{
+ const struct uECC_Curve_t * curve = uECC_secp256r1();
+ uint8_t public1[2*NUM_ECC_BYTES] = {0};
+ uint8_t public2[2*NUM_ECC_BYTES] = {0};
+ uint8_t secret1[NUM_ECC_BYTES] = {0};
+ uint8_t secret2[NUM_ECC_BYTES] = {0};
+
+ memcpy( public1, xA_str->x, xA_str->len );
+ memcpy( public1 + NUM_ECC_BYTES, yA_str->x, yA_str->len );
+ memcpy( public2, xB_str->x, xB_str->len );
+ memcpy( public2 + NUM_ECC_BYTES, yB_str->x, yB_str->len );
+
+ // Compute shared secrets and compare to test vector secret
+ TEST_ASSERT( uECC_shared_secret( public2, private1->x, secret1, curve ) != 0 );
+
+ TEST_ASSERT( uECC_shared_secret( public1, private2->x, secret2, curve ) != 0 );
+
+ TEST_ASSERT( memcmp( secret1, secret2, sizeof( secret1 ) ) == 0 );
+ TEST_ASSERT( memcmp( secret1, z_str->x, sizeof( secret1 ) ) == 0 );
+ TEST_ASSERT( memcmp( secret2, z_str->x, sizeof( secret2 ) ) == 0 );
+}
+/* END_CASE */
+
+/* BEGIN_CASE depends_on:MBEDTLS_USE_TINYCRYPT */
+void ecdsa_primitive_testvec( data_t * xQ_str, data_t * yQ_str,
+ data_t * hash, data_t * r_str, data_t * s_str,
+ int result )
+{
+ const struct uECC_Curve_t * curve = uECC_secp256r1();
+ uint8_t pub_bytes[2*NUM_ECC_BYTES] = {0};
+ uint8_t sig_bytes[2*NUM_ECC_BYTES] = {0};
+
+ memcpy( pub_bytes, xQ_str->x, xQ_str->len );
+ memcpy( pub_bytes + NUM_ECC_BYTES, yQ_str->x, yQ_str->len );
+ memcpy( sig_bytes, r_str->x, r_str->len );
+ memcpy( sig_bytes + NUM_ECC_BYTES, s_str->x, r_str->len );
+
+ TEST_ASSERT( uECC_verify( pub_bytes, hash->x, hash->len,
+ sig_bytes, curve ) == result );
+
+ // Alter the signature and check the verification fails
+ for( int i = 0; i < 2*NUM_ECC_BYTES; i++ )
+ {
+ uint8_t temp = sig_bytes[i];
+ sig_bytes[i] = ( sig_bytes[i] + 1 ) % 256;
+ TEST_ASSERT( uECC_verify( pub_bytes, hash->x, hash->len,
+ sig_bytes, curve ) == 0 );
+ sig_bytes[i] = temp;
+ }
+
+}
+/* END_CASE */
diff --git a/tinycrypt/LICENSE b/tinycrypt/LICENSE
new file mode 100644
index 0000000..2e1db51
--- /dev/null
+++ b/tinycrypt/LICENSE
@@ -0,0 +1,61 @@
+
+================================================================================
+
+ TinyCrypt Cryptographic Library
+
+================================================================================
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ - Neither the name of the Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+================================================================================
+Copyright (c) 2014, Kenneth MacKay
+All rights reserved.
+
+https://github.com/kmackay/micro-ecc
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+================================================================================
diff --git a/tinycrypt/README b/tinycrypt/README
new file mode 100644
index 0000000..d0f49a6
--- /dev/null
+++ b/tinycrypt/README
@@ -0,0 +1,77 @@
+
+================================================================================
+
+ TinyCrypt Cryptographic Library
+ (integrated as part of Mbed TLS)
+
+================================================================================
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ - Neither the name of the Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+================================================================================
+
+Copyright (c) 2019 ARM Limited
+
+================================================================================
+Overview:
+
+The TinyCrypt Library provides an implementation for constrained devices of a
+minimal set of standard cryptography primitives.
+
+This is a modified form of the library based on version 0.2.8 included as part
+of Mbed TLS as a compilation option. It is not included in its full form and
+those wishing to use TinyCrypt should use the original unmodified project.
+
+The original project can be found here: https://github.com/intel/tinycrypt
+
+Contributions should be made upstream to that project, and full documentation
+can be found in the originating repository.
+
+================================================================================
+
+Organization:
+
+tinycrypt: C source code of the cryptographic primitives.
+include/tinycrypt: C header files of the cryptographic primitives.
+
+No documentation is provided, and instead is available with the original
+project.
+
+Tests are provided as part of Mbed TLS and the Mbed TLS test suites.
+
+================================================================================
+
+Building:
+
+To include TinyCrypt as part of Mbed TLS, enable the configuration option
+MBEDTLS_USE_TINYCRYPT in the configration file 'include/mbedtls/config.h', and
+build as Mbed TLS as normal.
+
+================================================================================
+
diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c
index ab1956a..cef1469 100644
--- a/tinycrypt/ecc.c
+++ b/tinycrypt/ecc.c
@@ -1,6 +1,11 @@
/* ecc.c - TinyCrypt implementation of common ECC functions */
/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
diff --git a/tinycrypt/ecc_dh.c b/tinycrypt/ecc_dh.c
index 8aae1a2..ec1328e 100644
--- a/tinycrypt/ecc_dh.c
+++ b/tinycrypt/ecc_dh.c
@@ -1,6 +1,11 @@
/* ec_dh.c - TinyCrypt implementation of EC-DH */
/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*
diff --git a/tinycrypt/ecc_dsa.c b/tinycrypt/ecc_dsa.c
index 3743091..a3893d3 100644
--- a/tinycrypt/ecc_dsa.c
+++ b/tinycrypt/ecc_dsa.c
@@ -1,5 +1,10 @@
/* ec_dsa.c - TinyCrypt implementation of EC-DSA */
+/*
+ * Copyright (c) 2019, Arm Limited (or its affiliates), All Rights Reserved.
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
/* Copyright (c) 2014, Kenneth MacKay
* All rights reserved.
*