Crypto: Disable SHA-1 by default
SHA-1 is considered to a weak message digest, so this patch changes it
to disabled by default. Makes corresponding updates to the tests.
Change-Id: Idfb7f1b33d46b9ba553a327e4ed83320e728870b
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
diff --git a/platform/ext/common/tfm_mbedcrypto_config.h b/platform/ext/common/tfm_mbedcrypto_config.h
index a7e5ddf..674430b 100644
--- a/platform/ext/common/tfm_mbedcrypto_config.h
+++ b/platform/ext/common/tfm_mbedcrypto_config.h
@@ -1776,7 +1776,7 @@
* on it, and considering stronger message digests instead.
*
*/
-#define MBEDTLS_SHA1_C
+//#define MBEDTLS_SHA1_C
/**
* \def MBEDTLS_SHA256_C
diff --git a/test/suites/crypto/crypto_tests_common.c b/test/suites/crypto/crypto_tests_common.c
index 9cfbef1..c07b137 100644
--- a/test/suites/crypto/crypto_tests_common.c
+++ b/test/suites/crypto/crypto_tests_common.c
@@ -358,6 +358,22 @@
ret->val = TEST_PASSED;
}
+void psa_unsupported_hash_test(const psa_algorithm_t alg,
+ struct test_result_t *ret)
+{
+ psa_status_t status;
+ psa_hash_operation_t handle = PSA_HASH_OPERATION_INIT;
+
+ /* Setup the hash object for the unsupported hash algorithm */
+ status = psa_hash_setup(&handle, alg);
+ if (status != PSA_ERROR_NOT_SUPPORTED) {
+ TEST_FAIL("Should not successfully setup an unsupported hash alg");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+}
+
/*
* \brief This is the list of algorithms supported by the current
* configuration of the crypto engine used by the crypto
@@ -365,7 +381,6 @@
* is changed, this list needs to be updated accordingly
*/
static const psa_algorithm_t hash_alg[] = {
- PSA_ALG_SHA_1,
PSA_ALG_SHA_224,
PSA_ALG_SHA_256,
PSA_ALG_SHA_384,
@@ -373,9 +388,6 @@
};
static const uint8_t hash_val[][PSA_HASH_SIZE(PSA_ALG_SHA_512)] = {
- {0x56, 0x4A, 0x0E, 0x35, 0xF1, 0xC7, 0xBC, 0xD0, /*!< SHA-1 */
- 0x7D, 0xCF, 0xB1, 0xBC, 0xC9, 0x16, 0xFA, 0x2E,
- 0xF5, 0xBE, 0x96, 0xB2},
{0x00, 0xD2, 0x90, 0xE2, 0x0E, 0x4E, 0xC1, 0x7E, /*!< SHA-224 */
0x7A, 0x95, 0xF5, 0x10, 0x5C, 0x76, 0x74, 0x04,
0x6E, 0xB5, 0x56, 0x5E, 0xE5, 0xE7, 0xBA, 0x15,
@@ -449,10 +461,45 @@
ret->val = TEST_PASSED;
}
+void psa_unsupported_mac_test(const psa_key_type_t key_type,
+ const psa_algorithm_t alg,
+ struct test_result_t *ret)
+{
+ psa_status_t status;
+ psa_key_handle_t key_handle;
+ psa_mac_operation_t handle = PSA_MAC_OPERATION_INIT;
+ psa_key_attributes_t key_attributes = PSA_KEY_ATTRIBUTES_INIT;
+ const uint8_t data[] = "THIS IS MY KEY1";
+
+ ret->val = TEST_PASSED;
+
+ /* Setup the key policy */
+ psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_VERIFY);
+ psa_set_key_algorithm(&key_attributes, alg);
+ psa_set_key_type(&key_attributes, key_type);
+
+ /* Import key */
+ status = psa_import_key(&key_attributes, data, sizeof(data), &key_handle);
+ if (status != PSA_SUCCESS) {
+ TEST_FAIL("Error importing a key");
+ return;
+ }
+
+ /* Setup the mac object for the unsupported mac algorithm */
+ status = psa_mac_verify_setup(&handle, key_handle, alg);
+ if (status != PSA_ERROR_NOT_SUPPORTED) {
+ TEST_FAIL("Should not successfully setup an unsupported MAC alg");
+ /* Do not return, to ensure key is destroyed */
+ }
+
+ /* Destroy the key */
+ status = psa_destroy_key(key_handle);
+ if (status != PSA_SUCCESS) {
+ TEST_FAIL("Error destroying the key");
+ }
+}
+
static const uint8_t hmac_val[][PSA_HASH_SIZE(PSA_ALG_SHA_512)] = {
- {0x0d, 0xa6, 0x9d, 0x02, 0x43, 0x17, 0x3e, 0x7e, /*!< SHA-1 */
- 0xe7, 0x3b, 0xc6, 0xa9, 0x51, 0x06, 0x8a, 0xea,
- 0x12, 0xb0, 0xa7, 0x1d},
{0xc1, 0x9f, 0x19, 0xac, 0x05, 0x65, 0x5f, 0x02, /*!< SHA-224 */
0x1b, 0x64, 0x32, 0xd9, 0xb1, 0x49, 0xba, 0x75,
0x05, 0x60, 0x52, 0x4e, 0x78, 0xfa, 0x61, 0xc9,
@@ -477,10 +524,11 @@
0xa9, 0x6a, 0x5d, 0xb2, 0x81, 0xe1, 0x6f, 0x1f},
};
-static const uint8_t long_key_hmac_val[PSA_HASH_SIZE(PSA_ALG_SHA_1)] = {
- 0xb5, 0x06, 0x7b, 0x9a, 0xb9, 0xe7, 0x47, 0x3c, /*!< SHA-1 */
- 0x2d, 0x44, 0x46, 0x1f, 0x4a, 0xbd, 0x22, 0x53,
- 0x9c, 0x05, 0x34, 0x34
+static const uint8_t long_key_hmac_val[PSA_HASH_SIZE(PSA_ALG_SHA_224)] = {
+ 0x47, 0xa3, 0x42, 0xb1, 0x2f, 0x52, 0xd3, 0x8f, /*!< SHA-224 */
+ 0x1e, 0x02, 0x4a, 0x46, 0x73, 0x0b, 0x77, 0xc1,
+ 0x5e, 0x93, 0x31, 0xa9, 0x3e, 0xc2, 0x81, 0xb5,
+ 0x3d, 0x07, 0x6f, 0x31
};
void psa_mac_test(const psa_algorithm_t alg,
diff --git a/test/suites/crypto/crypto_tests_common.h b/test/suites/crypto/crypto_tests_common.h
index 3a0f56e..908828c 100644
--- a/test/suites/crypto/crypto_tests_common.h
+++ b/test/suites/crypto/crypto_tests_common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -92,6 +92,15 @@
const size_t key_size,
struct test_result_t *ret);
/**
+ * \brief Tests setup of an unsupported hash algorithm
+ *
+ * \param[in] alg PSA algorithm
+ * \param[out] ret Test result
+ *
+ */
+void psa_unsupported_hash_test(const psa_algorithm_t alg,
+ struct test_result_t *ret);
+/**
* \brief Tests different hashing algorithms
*
* \param[in] alg PSA algorithm
@@ -101,6 +110,17 @@
void psa_hash_test(const psa_algorithm_t alg,
struct test_result_t *ret);
/**
+ * \brief Tests setup of an unsupported MAC algorithm
+ *
+ * \param[in] key_type PSA key type
+ * \param[in] alg PSA algorithm
+ * \param[out] ret Test result
+ *
+ */
+void psa_unsupported_mac_test(const psa_key_type_t key_type,
+ const psa_algorithm_t alg,
+ struct test_result_t *ret);
+/**
* \brief Tests different MAC algorithms
*
* \param[in] alg PSA algorithm
diff --git a/test/suites/crypto/non_secure/crypto_ns_interface_testsuite.c b/test/suites/crypto/non_secure/crypto_ns_interface_testsuite.c
index 38cbbf1..dfc634d 100644
--- a/test/suites/crypto/non_secure/crypto_ns_interface_testsuite.c
+++ b/test/suites/crypto/non_secure/crypto_ns_interface_testsuite.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -48,7 +48,7 @@
{&tfm_crypto_test_6009, "TFM_CRYPTO_TEST_6009",
"Non Secure Symmetric encryption invalid cipher (HMAC-128-CFB)", {0} },
{&tfm_crypto_test_6010, "TFM_CRYPTO_TEST_6010",
- "Non Secure Hash (SHA-1) interface", {0} },
+ "Non Secure Unsupported Hash (SHA-1) interface", {0} },
{&tfm_crypto_test_6011, "TFM_CRYPTO_TEST_6011",
"Non Secure Hash (SHA-224) interface", {0} },
{&tfm_crypto_test_6012, "TFM_CRYPTO_TEST_6012",
@@ -58,7 +58,7 @@
{&tfm_crypto_test_6014, "TFM_CRYPTO_TEST_6014",
"Non Secure Hash (SHA-512) interface", {0} },
{&tfm_crypto_test_6019, "TFM_CRYPTO_TEST_6019",
- "Non Secure HMAC (SHA-1) interface", {0} },
+ "Non Secure Unsupported HMAC (SHA-1) interface", {0} },
{&tfm_crypto_test_6020, "TFM_CRYPTO_TEST_6020",
"Non Secure HMAC (SHA-256) interface", {0} },
{&tfm_crypto_test_6021, "TFM_CRYPTO_TEST_6021",
@@ -66,7 +66,7 @@
{&tfm_crypto_test_6022, "TFM_CRYPTO_TEST_6022",
"Non Secure HMAC (SHA-512) interface", {0} },
{&tfm_crypto_test_6024, "TFM_CRYPTO_TEST_6024",
- "Non Secure HMAC with long key (SHA-1) interface", {0} },
+ "Non Secure HMAC with long key (SHA-224) interface", {0} },
{&tfm_crypto_test_6030, "TFM_CRYPTO_TEST_6030",
"Non Secure AEAD (AES-128-CCM) interface", {0} },
{&tfm_crypto_test_6031, "TFM_CRYPTO_TEST_6031",
@@ -133,7 +133,7 @@
static void tfm_crypto_test_6010(struct test_result_t *ret)
{
- psa_hash_test(PSA_ALG_SHA_1, ret);
+ psa_unsupported_hash_test(PSA_ALG_SHA_1, ret);
}
static void tfm_crypto_test_6011(struct test_result_t *ret)
@@ -158,7 +158,8 @@
static void tfm_crypto_test_6019(struct test_result_t *ret)
{
- psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_1), 0, ret);
+ psa_unsupported_mac_test(PSA_KEY_TYPE_HMAC, PSA_ALG_HMAC(PSA_ALG_SHA_1),
+ ret);
}
static void tfm_crypto_test_6020(struct test_result_t *ret)
@@ -177,7 +178,7 @@
}
static void tfm_crypto_test_6024(struct test_result_t *ret)
{
- psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_1), 1, ret);
+ psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_224), 1, ret);
}
static void tfm_crypto_test_6030(struct test_result_t *ret)
diff --git a/test/suites/crypto/secure/crypto_sec_interface_testsuite.c b/test/suites/crypto/secure/crypto_sec_interface_testsuite.c
index c80ee10..ca54b9c 100644
--- a/test/suites/crypto/secure/crypto_sec_interface_testsuite.c
+++ b/test/suites/crypto/secure/crypto_sec_interface_testsuite.c
@@ -50,7 +50,7 @@
{&tfm_crypto_test_5009, "TFM_CRYPTO_TEST_5009",
"Secure Symmetric encryption invalid cipher (HMAC-128-CFB)", {0} },
{&tfm_crypto_test_5010, "TFM_CRYPTO_TEST_5010",
- "Secure Hash (SHA-1) interface", {0} },
+ "Secure Unsupported Hash (SHA-1) interface", {0} },
{&tfm_crypto_test_5011, "TFM_CRYPTO_TEST_5011",
"Secure Hash (SHA-224) interface", {0} },
{&tfm_crypto_test_5012, "TFM_CRYPTO_TEST_5012",
@@ -60,7 +60,7 @@
{&tfm_crypto_test_5014, "TFM_CRYPTO_TEST_5014",
"Secure Hash (SHA-512) interface", {0} },
{&tfm_crypto_test_5019, "TFM_CRYPTO_TEST_5019",
- "Secure HMAC (SHA-1) interface", {0} },
+ "Secure Unsupported HMAC (SHA-1) interface", {0} },
{&tfm_crypto_test_5020, "TFM_CRYPTO_TEST_5020",
"Secure HMAC (SHA-256) interface", {0} },
{&tfm_crypto_test_5021, "TFM_CRYPTO_TEST_5021",
@@ -68,7 +68,7 @@
{&tfm_crypto_test_5022, "TFM_CRYPTO_TEST_5022",
"Secure HMAC (SHA-512) interface", {0} },
{&tfm_crypto_test_5024, "TFM_CRYPTO_TEST_5024",
- "Secure HMAC with long key (SHA-1) interface", {0} },
+ "Secure HMAC with long key (SHA-224) interface", {0} },
{&tfm_crypto_test_5030, "TFM_CRYPTO_TEST_5030",
"Secure AEAD (AES-128-CCM) interface", {0} },
{&tfm_crypto_test_5031, "TFM_CRYPTO_TEST_5031",
@@ -137,7 +137,7 @@
static void tfm_crypto_test_5010(struct test_result_t *ret)
{
- psa_hash_test(PSA_ALG_SHA_1, ret);
+ psa_unsupported_hash_test(PSA_ALG_SHA_1, ret);
}
static void tfm_crypto_test_5011(struct test_result_t *ret)
@@ -162,7 +162,8 @@
static void tfm_crypto_test_5019(struct test_result_t *ret)
{
- psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_1), 0, ret);
+ psa_unsupported_mac_test(PSA_KEY_TYPE_HMAC, PSA_ALG_HMAC(PSA_ALG_SHA_1),
+ ret);
}
static void tfm_crypto_test_5020(struct test_result_t *ret)
@@ -182,7 +183,7 @@
static void tfm_crypto_test_5024(struct test_result_t *ret)
{
- psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_1), 1, ret);
+ psa_mac_test(PSA_ALG_HMAC(PSA_ALG_SHA_224), 1, ret);
}
static void tfm_crypto_test_5030(struct test_result_t *ret)