Add tests for DES3 CMAC
Signed-off-by: Alexander Zakharov <uglym8@gmail.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/regression_4000.c b/host/xtest/regression_4000.c
index f3924f3..4f8c713 100644
--- a/host/xtest/regression_4000.c
+++ b/host/xtest/regression_4000.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
+ * Copyright (c) 2021, SumUp Services GmbH
*/
#include <stdio.h>
@@ -1100,6 +1101,11 @@
mac_cmac_ ## vect ## _key, (in_incr), \
mac_cmac_ ## vect ## _data, mac_cmac_ ## vect ## _out)
+#define XTEST_MAC_DES3_CMAC_CASE(vect, in_incr) \
+ XTEST_MAC_CASE(TEE_ALG_DES3_CMAC, TEE_TYPE_DES3, \
+ mac_des3_cmac_ ## vect ## _key, (in_incr), \
+ mac_des3_cmac_ ## vect ## _data, mac_des3_cmac_ ## vect ## _out)
+
static const struct xtest_mac_case mac_cases[] = {
XTEST_MAC_CASE(TEE_ALG_HMAC_MD5, TEE_TYPE_HMAC_MD5,
mac_data_md5_key1,
@@ -1155,6 +1161,19 @@
XTEST_MAC_CMAC_CASE(vect11, 9),
XTEST_MAC_CMAC_CASE(vect12, 9),
+ { TEE_ALG_DES3_CMAC, TEE_TYPE_DES3, mac_des3_cmac_vect1_key,
+ ARRAY_SIZE(mac_des3_cmac_vect1_key), 0, NULL, 0, mac_des3_cmac_vect1_out,
+ ARRAY_SIZE(mac_des3_cmac_vect1_out) },
+ XTEST_MAC_DES3_CMAC_CASE(vect2, 3),
+ XTEST_MAC_DES3_CMAC_CASE(vect3, 9),
+ XTEST_MAC_DES3_CMAC_CASE(vect4, 9),
+ { TEE_ALG_DES3_CMAC, TEE_TYPE_DES3, mac_des3_cmac_vect5_key,
+ ARRAY_SIZE(mac_des3_cmac_vect5_key), 0, NULL, 0, mac_des3_cmac_vect5_out,
+ ARRAY_SIZE(mac_des3_cmac_vect5_out) },
+ XTEST_MAC_DES3_CMAC_CASE(vect6, 3),
+ XTEST_MAC_DES3_CMAC_CASE(vect7, 5),
+ XTEST_MAC_DES3_CMAC_CASE(vect8, 9),
+
XTEST_MAC_CASE(TEE_ALG_HMAC_SM3, TEE_TYPE_HMAC_SM3,
mac_data_sm3_d31_key,
13, mac_data_sm3_d31_in, mac_data_sm3_d31_out),
diff --git a/host/xtest/regression_4000_data.h b/host/xtest/regression_4000_data.h
index 951b57f..70a1e6d 100644
--- a/host/xtest/regression_4000_data.h
+++ b/host/xtest/regression_4000_data.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
+ * Copyright (c) 2021, SumUp Services GmbH
*/
#ifndef XTEST_4000_DATA_H
@@ -8486,4 +8487,135 @@
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
};
+/*
+ * DES3-CMAC
+ * Test vectors from
+ * https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/cavp-testing-block-cipher-modes
+ */
+
+/* Three Key TDEA */
+
+/* CMACGenTDES3.rsp Count = 8 */
+static const uint8_t mac_des3_cmac_vect1_key[] = {
+ 0xf8, 0x7c, 0x4c, 0x3d, 0xf7, 0x1f, 0xd9, 0x8c,
+ 0xe5, 0x32, 0xf4, 0x1f, 0xfe, 0x31, 0x58, 0x20,
+ 0x51, 0x4f, 0xad, 0x7c, 0x7a, 0xae, 0x2f, 0x46
+};
+
+static const uint8_t mac_des3_cmac_vect1_out[] = {
+ 0x19, 0xfb, 0xd3, 0xdc, 0x15, 0x4b, 0xc1, 0x39
+};
+
+/* CMACVerTDES3.rsp Count = 25 */
+static const uint8_t mac_des3_cmac_vect2_key[] = {
+ 0xa2, 0x52, 0xda, 0xad, 0x73, 0x1c, 0x10, 0x97,
+ 0x45, 0x46, 0x38, 0xab, 0xf1, 0xf8, 0x40, 0x6d,
+ 0xd0, 0xae, 0xcb, 0xc7, 0x8c, 0x01, 0x8a, 0xa8
+};
+
+static const uint8_t mac_des3_cmac_vect2_data[] = {
+ 0x1d, 0x99, 0x92, 0x0c, 0x59, 0x73, 0x99, 0x7c,
+ 0xc0, 0x59, 0xd4, 0x42, 0x46, 0x7f, 0x76, 0x59
+};
+
+static const uint8_t mac_des3_cmac_vect2_out[] = {
+ 0x7c, 0x14, 0x90, 0x12, 0xd6, 0x12, 0x0e, 0xc6
+};
+
+/* CMACVerTDES3.rsp Count = 40 */
+static const uint8_t mac_des3_cmac_vect3_key[] = {
+ 0xf2, 0x45, 0xf8, 0xd5, 0x85, 0x13, 0x3e, 0x31,
+ 0x04, 0xd3, 0xfb, 0xc2, 0xd0, 0xec, 0x80, 0xf4,
+ 0x3e, 0xce, 0x1f, 0xd9, 0xa2, 0x8f, 0x5e, 0xd5
+};
+
+static const uint8_t mac_des3_cmac_vect3_data[] = {
+ 0x99, 0x3d, 0xac, 0xbc, 0x22, 0x1e, 0xd3, 0x2a,
+ 0x6f, 0xb3, 0xd9, 0x05, 0x59, 0xc6, 0x74, 0xfb,
+ 0x68, 0x08, 0x9e, 0xea, 0x8d, 0xf9, 0xea, 0xec,
+ 0x14, 0x07, 0x19, 0x91, 0xd4, 0xfa, 0xe8, 0x6b
+};
+
+static const uint8_t mac_des3_cmac_vect3_out[] = {
+ 0x25, 0xfb, 0x96, 0x2e, 0xa9, 0x3b, 0x89, 0x7f
+};
+
+/* CMACVerTDES3.rsp Count = 57 */
+static const uint8_t mac_des3_cmac_vect4_key[] = {
+ 0xc2, 0x9e, 0xc1, 0x2c, 0xa4, 0x83, 0xc2, 0x61,
+ 0xc1, 0xfe, 0xa7, 0x34, 0xf4, 0xad, 0x08, 0x10,
+ 0x8a, 0xc2, 0x75, 0x02, 0x68, 0x2c, 0x67, 0xdc
+};
+
+static const uint8_t mac_des3_cmac_vect4_data[] = {
+ 0x19, 0x5c, 0x0b, 0x84, 0xba, 0xac, 0xc8, 0x8a, 0x33
+};
+
+static const uint8_t mac_des3_cmac_vect4_out[] = {
+ 0xe3, 0xeb, 0xff, 0x96, 0x12, 0x49, 0x42, 0x45
+};
+
+/* Two Key TDEA */
+
+/* CMACVerTDES2.rsp Count = 55 */
+static const uint8_t mac_des3_cmac_vect5_key[] = {
+ 0xb6, 0xe0, 0xe5, 0x80, 0x20, 0x92, 0x34, 0x94,
+ 0xdc, 0x76, 0x80, 0x08, 0xe9, 0x98, 0x8f, 0xc2,
+ 0xb6, 0xe0, 0xe5, 0x80, 0x20, 0x92, 0x34, 0x94
+};
+
+static const uint8_t mac_des3_cmac_vect5_out[] = {
+ 0x5c, 0x73, 0x43, 0xa4, 0x16, 0x8a, 0x37, 0x0f
+};
+
+/* CMACVerTDES2.rsp Count = 101 */
+static const uint8_t mac_des3_cmac_vect6_key[] = {
+ 0x61, 0xc4, 0xec, 0x20, 0x70, 0xe9, 0xbf, 0x2a,
+ 0xec, 0x02, 0xd0, 0xb0, 0xe9, 0x9e, 0x8f, 0x01,
+ 0x61, 0xc4, 0xec, 0x20, 0x70, 0xe9, 0xbf, 0x2a
+};
+
+static const uint8_t mac_des3_cmac_vect6_data[] = {
+ 0xff, 0xbd, 0x75, 0x61, 0x93, 0x91, 0x88, 0xbc
+};
+
+static const uint8_t mac_des3_cmac_vect6_out[] = {
+ 0x55, 0xa0, 0x4c, 0x23, 0xd5, 0xb4, 0x3e, 0x49
+};
+
+/* CMACVerTDES2.rsp Count = 223 */
+static const uint8_t mac_des3_cmac_vect7_key[] = {
+ 0xb6, 0xc8, 0x9d, 0x79, 0x85, 0x70, 0xab, 0x6e,
+ 0xcd, 0x54, 0x54, 0xc1, 0xa7, 0x29, 0xf2, 0xd9,
+ 0xb6, 0xc8, 0x9d, 0x79, 0x85, 0x70, 0xab, 0x6e
+};
+
+static const uint8_t mac_des3_cmac_vect7_data[] = {
+ 0x83, 0xd2, 0xc3, 0x86, 0xe8, 0x73, 0xad, 0xa1,
+ 0x49, 0x76, 0x71, 0x2b, 0x67, 0x27, 0x7c
+};
+
+static const uint8_t mac_des3_cmac_vect7_out[] = {
+ 0x03, 0xbf, 0x2c, 0x9f, 0x49, 0x6e, 0x4f, 0xa9
+};
+
+/* CMACVerTDES2.rsp Count = 358 */
+static const uint8_t mac_des3_cmac_vect8_key[] = {
+ 0xe0, 0x85, 0xab, 0xa8, 0x58, 0x83, 0xc7, 0x5d,
+ 0x62, 0x76, 0x75, 0x7a, 0x54, 0x31, 0xc8, 0x37,
+ 0xe0, 0x85, 0xab, 0xa8, 0x58, 0x83, 0xc7, 0x5d
+};
+
+static const uint8_t mac_des3_cmac_vect8_data[] = {
+ 0xb0, 0x53, 0x76, 0xdb, 0x71, 0xce, 0x06, 0x66,
+ 0x63, 0x81, 0x95, 0x03, 0xeb, 0x0a, 0xd5, 0xef,
+ 0x63, 0x2d, 0x0c, 0xa4, 0x6c, 0xd4, 0x0e, 0xfe,
+ 0x86, 0x54, 0x69, 0x9d, 0xde, 0xf2, 0xdf, 0x8a,
+ 0x66, 0xa6, 0x19, 0x1d, 0x2b, 0x1f, 0x99, 0x1e
+};
+
+static const uint8_t mac_des3_cmac_vect8_out[] = {
+ 0xd5, 0xe7, 0x9f, 0x0b, 0x3c, 0x67, 0xd7, 0xf3
+};
+
#endif /*XTEST_4000_DATA_H*/