Import mbedtls-2.27.0

Imports Mbed TLS 2.27.0 from https://github.com/ARMmbed/mbedtls.git
commit f71e28780841 ("Merge pull request #843 from
paul-elliott-arm/mbedtls-2.27.0rc0-pr") (tag mbedtls-2.27.0, v2.27.0).

Files that are not needed are removed.

 cd lib/libmbedtls
 rm -rf mbedtls
 cp -R path/to/mbedtls-2.27.0/mbedtls .
 cd mbedtls
 rm CMakeLists.txt DartConfiguration.tcl Makefile
 rm .gitignore .travis.yml .pylintrc .globalrc .mypy.ini BRANCHES.md
 rm include/.gitignore include/CMakeLists.txt library/.gitignore
 rm library/CMakeLists.txt library/Makefile
 rm -rf .git .github doxygen configs programs scripts tests visualc yotta
 rm -rf 3rdparty ChangeLog.d docs
 rm -rf include/mbedtls/config_psa.h include/psa
 rm library/psa_* library/mps_*
 cd ..
 git add mbedtls

This is a complete overwrite of previous code so earlier changes in the
previous branch import/mbedtls-2.22.0 will be added on top of this commit.

Signed-off-by: Jerome Forissier <jerome@forissier.org>
diff --git a/lib/libmbedtls/mbedtls/library/cipher_wrap.c b/lib/libmbedtls/mbedtls/library/cipher_wrap.c
index f0c3614..57eb3cb 100644
--- a/lib/libmbedtls/mbedtls/library/cipher_wrap.c
+++ b/lib/libmbedtls/mbedtls/library/cipher_wrap.c
@@ -1,4 +1,3 @@
-// SPDX-License-Identifier: Apache-2.0
 /**
  * \file cipher_wrap.c
  *
@@ -6,7 +5,8 @@
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
  *
- *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ *  Copyright The Mbed TLS Contributors
+ *  SPDX-License-Identifier: Apache-2.0
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
  *  not use this file except in compliance with the License.
@@ -19,17 +19,9 @@
  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
- *
- *  This file is part of mbed TLS (https://tls.mbed.org)
  */
 
-#if !defined(MBEDTLS_CONFIG_FILE)
-#include "mbedtls/config.h"
-#else
-#include MBEDTLS_CONFIG_FILE
-#endif
-
-#include <string.h>
+#include "common.h"
 
 #if defined(MBEDTLS_CIPHER_C)
 
@@ -104,11 +96,6 @@
     return( ctx );
 }
 
-static void gcm_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_gcm_context ) );
-}
-
 static void gcm_ctx_free( void *ctx )
 {
     mbedtls_gcm_free( ctx );
@@ -128,11 +115,6 @@
     return( ctx );
 }
 
-static void ccm_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_ccm_context ) );
-}
-
 static void ccm_ctx_free( void *ctx )
 {
     mbedtls_ccm_free( ctx );
@@ -237,11 +219,6 @@
     return( aes );
 }
 
-static void aes_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_aes_context ) );
-}
-
 static void aes_ctx_free( void *ctx )
 {
     mbedtls_aes_free( (mbedtls_aes_context *) ctx );
@@ -272,7 +249,6 @@
     aes_setkey_enc_wrap,
     aes_setkey_dec_wrap,
     aes_ctx_alloc,
-    aes_ctx_clone,
     aes_ctx_free
 };
 
@@ -567,7 +543,6 @@
     gcm_aes_setkey_wrap,
     gcm_aes_setkey_wrap,
     gcm_ctx_alloc,
-    gcm_ctx_clone,
     gcm_ctx_free,
 };
 
@@ -637,7 +612,6 @@
     ccm_aes_setkey_wrap,
     ccm_aes_setkey_wrap,
     ccm_ctx_alloc,
-    ccm_ctx_clone,
     ccm_ctx_free,
 };
 
@@ -741,11 +715,6 @@
     return( ctx );
 }
 
-static void camellia_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_camellia_context ) );
-}
-
 static void camellia_ctx_free( void *ctx )
 {
     mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
@@ -776,7 +745,6 @@
     camellia_setkey_enc_wrap,
     camellia_setkey_dec_wrap,
     camellia_ctx_alloc,
-    camellia_ctx_clone,
     camellia_ctx_free
 };
 
@@ -785,7 +753,7 @@
     MBEDTLS_MODE_ECB,
     128,
     "CAMELLIA-128-ECB",
-    16,
+    0,
     0,
     16,
     &camellia_info
@@ -796,7 +764,7 @@
     MBEDTLS_MODE_ECB,
     192,
     "CAMELLIA-192-ECB",
-    16,
+    0,
     0,
     16,
     &camellia_info
@@ -807,7 +775,7 @@
     MBEDTLS_MODE_ECB,
     256,
     "CAMELLIA-256-ECB",
-    16,
+    0,
     0,
     16,
     &camellia_info
@@ -950,7 +918,6 @@
     gcm_camellia_setkey_wrap,
     gcm_camellia_setkey_wrap,
     gcm_ctx_alloc,
-    gcm_ctx_clone,
     gcm_ctx_free,
 };
 
@@ -1020,7 +987,6 @@
     ccm_camellia_setkey_wrap,
     ccm_camellia_setkey_wrap,
     ccm_ctx_alloc,
-    ccm_ctx_clone,
     ccm_ctx_free,
 };
 
@@ -1163,7 +1129,7 @@
     MBEDTLS_MODE_ECB,
     128,
     "ARIA-128-ECB",
-    16,
+    0,
     0,
     16,
     &aria_info
@@ -1174,7 +1140,7 @@
     MBEDTLS_MODE_ECB,
     192,
     "ARIA-192-ECB",
-    16,
+    0,
     0,
     16,
     &aria_info
@@ -1185,7 +1151,7 @@
     MBEDTLS_MODE_ECB,
     256,
     "ARIA-256-ECB",
-    16,
+    0,
     0,
     16,
     &aria_info
@@ -1530,11 +1496,6 @@
     return( des );
 }
 
-static void des_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_des_context ) );
-}
-
 static void des_ctx_free( void *ctx )
 {
     mbedtls_des_free( (mbedtls_des_context *) ctx );
@@ -1554,11 +1515,6 @@
     return( des3 );
 }
 
-static void des3_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_des3_context ) );
-}
-
 static void des3_ctx_free( void *ctx )
 {
     mbedtls_des3_free( (mbedtls_des3_context *) ctx );
@@ -1589,7 +1545,6 @@
     des_setkey_enc_wrap,
     des_setkey_dec_wrap,
     des_ctx_alloc,
-    des_ctx_clone,
     des_ctx_free
 };
 
@@ -1598,7 +1553,7 @@
     MBEDTLS_MODE_ECB,
     MBEDTLS_KEY_LENGTH_DES,
     "DES-ECB",
-    8,
+    0,
     0,
     8,
     &des_info
@@ -1641,7 +1596,6 @@
     des3_set2key_enc_wrap,
     des3_set2key_dec_wrap,
     des3_ctx_alloc,
-    des3_ctx_clone,
     des3_ctx_free
 };
 
@@ -1650,7 +1604,7 @@
     MBEDTLS_MODE_ECB,
     MBEDTLS_KEY_LENGTH_DES_EDE,
     "DES-EDE-ECB",
-    8,
+    0,
     0,
     8,
     &des_ede_info
@@ -1693,7 +1647,6 @@
     des3_set3key_enc_wrap,
     des3_set3key_dec_wrap,
     des3_ctx_alloc,
-    des3_ctx_clone,
     des3_ctx_free
 };
 
@@ -1702,7 +1655,7 @@
     MBEDTLS_MODE_ECB,
     MBEDTLS_KEY_LENGTH_DES_EDE3,
     "DES-EDE3-ECB",
-    8,
+    0,
     0,
     8,
     &des_ede3_info
@@ -1779,11 +1732,6 @@
     return( ctx );
 }
 
-static void blowfish_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_blowfish_context ) );
-}
-
 static void blowfish_ctx_free( void *ctx )
 {
     mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
@@ -1814,7 +1762,6 @@
     blowfish_setkey_wrap,
     blowfish_setkey_wrap,
     blowfish_ctx_alloc,
-    blowfish_ctx_clone,
     blowfish_ctx_free
 };
 
@@ -1823,7 +1770,7 @@
     MBEDTLS_MODE_ECB,
     128,
     "BLOWFISH-ECB",
-    8,
+    0,
     MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
     8,
     &blowfish_info
@@ -1901,11 +1848,6 @@
     return( ctx );
 }
 
-static void arc4_ctx_clone( void *dst, const void *src )
-{
-    memcpy( dst, src, sizeof( mbedtls_arc4_context ) );
-}
-
 static void arc4_ctx_free( void *ctx )
 {
     mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
@@ -1936,7 +1878,6 @@
     arc4_setkey_wrap,
     arc4_setkey_wrap,
     arc4_ctx_alloc,
-    arc4_ctx_clone,
     arc4_ctx_free
 };
 
@@ -2133,12 +2074,6 @@
     return( (void *) 1 );
 }
 
-static void null_ctx_clone( void *dst, const void *src )
-{
-    ((void) dst);
-    ((void) src);
-}
-
 static void null_ctx_free( void *ctx )
 {
     ((void) ctx);
@@ -2168,7 +2103,6 @@
     null_setkey,
     null_setkey,
     null_ctx_alloc,
-    null_ctx_clone,
     null_ctx_free
 };