Skip to content

Commit d05d143

Browse files
Valerii Chubarsa-kib
authored andcommitted
Add ED25519 test cases
Add test cases to generate ED25519 key, sign/verify for ED25519, ED25519ctx and ED25519ph. The test vectors originate from RFC 8032 sections 7.1, 7.2, 7.3 Signed-off-by: Valerii Chubar <valerii_chubar@epam.com> Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
1 parent eb3d01f commit d05d143

File tree

2 files changed

+311
-0
lines changed

2 files changed

+311
-0
lines changed

host/xtest/regression_4000.c

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,15 @@ struct xtest_ac_case {
27222722
const uint8_t *public_y;
27232723
size_t public_y_len;
27242724
} ecc;
2725+
struct {
2726+
const uint8_t *private;
2727+
size_t private_len;
2728+
const uint8_t *public;
2729+
size_t public_len;
2730+
const uint8_t flag;
2731+
const uint8_t *context;
2732+
size_t context_len;
2733+
} eddsa;
27252734
} params;
27262735

27272736
const uint8_t *ptx;
@@ -2779,6 +2788,27 @@ struct xtest_ac_case {
27792788
#define XTEST_AC_ECC_CASE(level, algo, mode, vect) \
27802789
XTEST_AC_CASE(level, algo, mode, vect, XTEST_AC_ECDSA_UNION(vect))
27812790

2791+
#define XTEST_AC_EDDSA_UNION(vect, flag) \
2792+
{ .eddsa = { \
2793+
ARRAY(vect ## _private), \
2794+
ARRAY(vect ## _public), \
2795+
flag, \
2796+
} }
2797+
2798+
#define XTEST_AC_EDDSA_CTX_UNION(vect, flag) \
2799+
{ .eddsa = { \
2800+
ARRAY(vect ## _private), \
2801+
ARRAY(vect ## _public), \
2802+
flag, \
2803+
ARRAY(vect ## _context), \
2804+
} }
2805+
2806+
#define XTEST_AC_EDDSA_CASE(level, algo, mode, vect, flag) \
2807+
XTEST_AC_CASE(level, algo, mode, vect, XTEST_AC_EDDSA_UNION(vect, flag))
2808+
2809+
#define XTEST_AC_EDDSA_CTX_CASE(level, algo, mode, vect, flag) \
2810+
XTEST_AC_CASE(level, algo, mode, vect, XTEST_AC_EDDSA_CTX_UNION(vect, flag))
2811+
27822812
static const struct xtest_ac_case xtest_ac_cases[] = {
27832813
/* RSA test without crt parameters */
27842814
XTEST_AC_RSA_CASE(0, TEE_ALG_RSA_NOPAD, TEE_MODE_ENCRYPT,
@@ -3555,6 +3585,24 @@ static const struct xtest_ac_case xtest_ac_cases[] = {
35553585
gmt_003_part5_a2),
35563586
};
35573587

3588+
static const struct xtest_ac_case xtest_ac_eddsa_cases[] = {
3589+
3590+
XTEST_AC_EDDSA_CASE(0, TEE_ALG_ED25519, TEE_MODE_SIGN,
3591+
ed25519_rfc_8032_7_1, 0),
3592+
XTEST_AC_EDDSA_CASE(0, TEE_ALG_ED25519, TEE_MODE_VERIFY,
3593+
ed25519_rfc_8032_7_1, 0),
3594+
3595+
XTEST_AC_EDDSA_CTX_CASE(0, TEE_ALG_ED25519, TEE_MODE_SIGN,
3596+
ed25519ctx_rfc_8032_7_2, 0),
3597+
XTEST_AC_EDDSA_CTX_CASE(0, TEE_ALG_ED25519, TEE_MODE_VERIFY,
3598+
ed25519ctx_rfc_8032_7_2, 0),
3599+
3600+
XTEST_AC_EDDSA_CASE(0, TEE_ALG_ED25519, TEE_MODE_SIGN,
3601+
ed25519ph_rfc_8032_7_3, 1),
3602+
XTEST_AC_EDDSA_CASE(0, TEE_ALG_ED25519, TEE_MODE_VERIFY,
3603+
ed25519ph_rfc_8032_7_3, 1),
3604+
};
3605+
35583606
static bool create_key(ADBG_Case_t *c, TEEC_Session *s,
35593607
uint32_t max_key_size, uint32_t key_type,
35603608
TEE_Attribute *attrs, size_t num_attrs,
@@ -4273,6 +4321,19 @@ static bool test_x25519_key_pair(ADBG_Case_t *c, TEEC_Session *s,
42734321
ARRAY_SIZE(attrs));
42744322
}
42754323

4324+
static bool test_ed25519_key_pair(ADBG_Case_t *c, TEEC_Session *s,
4325+
TEE_ObjectHandle key, uint32_t key_size)
4326+
{
4327+
const struct key_attrs attrs[] = {
4328+
KEY_ATTR(TEE_ATTR_ED25519_PRIVATE_VALUE, false),
4329+
KEY_ATTR(TEE_ATTR_ED25519_PUBLIC_VALUE, false),
4330+
};
4331+
4332+
return test_keygen_attributes(c, s, key, key_size,
4333+
(struct key_attrs *)&attrs,
4334+
ARRAY_SIZE(attrs));
4335+
}
4336+
42764337
static bool generate_and_test_key(ADBG_Case_t *c, TEEC_Session *s,
42774338
uint32_t key_type, uint32_t check_keysize,
42784339
uint32_t key_size,
@@ -4336,6 +4397,11 @@ static bool generate_and_test_key(ADBG_Case_t *c, TEEC_Session *s,
43364397
test_x25519_key_pair(c, s, key, key_size));
43374398
break;
43384399

4400+
case TEE_TYPE_ED25519_KEYPAIR:
4401+
ret_val = ADBG_EXPECT_TRUE(c,
4402+
test_ed25519_key_pair(c, s, key, key_size));
4403+
break;
4404+
43394405
default:
43404406
ret_val = false;
43414407
break;
@@ -4747,6 +4813,36 @@ static void xtest_tee_test_4007_x25519(ADBG_Case_t *c)
47474813
ADBG_CASE_DEFINE(regression, 4007_x25519, xtest_tee_test_4007_x25519,
47484814
"Test TEE Internal API Generate X25519 key");
47494815

4816+
4817+
static void xtest_tee_test_4007_ed25519(ADBG_Case_t *c)
4818+
{
4819+
TEEC_Session session = { };
4820+
uint32_t ret_orig = 0;
4821+
4822+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
4823+
xtest_teec_open_session(&session, &crypt_user_ta_uuid,
4824+
NULL, &ret_orig)))
4825+
return;
4826+
4827+
if (!ta_crypt_cmd_is_algo_supported(c, &session, TEE_ALG_ED25519,
4828+
TEE_ECC_CURVE_25519)) {
4829+
Do_ADBG_Log("ED25519 not supported: skip subcase");
4830+
goto out;
4831+
}
4832+
4833+
Do_ADBG_BeginSubCase(c, "Generate Ed25519 key");
4834+
4835+
ADBG_EXPECT_TRUE(c, generate_and_test_key(c, &session,
4836+
TEE_TYPE_ED25519_KEYPAIR,
4837+
0, 256, NULL, 0));
4838+
4839+
Do_ADBG_EndSubCase(c, "Generate Ed25519 key");
4840+
out:
4841+
TEEC_CloseSession(&session);
4842+
}
4843+
ADBG_CASE_DEFINE(regression, 4007_ed25519, xtest_tee_test_4007_ed25519,
4844+
"Test TEE Internal API Generate ed25519 key");
4845+
47504846
static void xtest_tee_test_4008(ADBG_Case_t *c)
47514847
{
47524848
TEEC_Session session = { };
@@ -5766,4 +5862,127 @@ static void xtest_tee_test_4015(ADBG_Case_t *c)
57665862
}
57675863
ADBG_CASE_DEFINE(regression, 4015, xtest_tee_test_4015,
57685864
"Test TEE Internal API Derive key X25519");
5865+
5866+
static void xtest_tee_test_4016_ed25519(ADBG_Case_t *c)
5867+
{
5868+
TEEC_Session session = { };
5869+
TEE_OperationHandle op = TEE_HANDLE_NULL;
5870+
TEE_ObjectHandle key_handle = TEE_HANDLE_NULL;
5871+
TEE_Attribute key_attrs[2] = { };
5872+
size_t num_key_attrs = 0;
5873+
TEE_Attribute attrs[2] = { };
5874+
size_t num_attrs = 0;
5875+
uint8_t out[64] = { };
5876+
size_t out_size = sizeof(out);
5877+
size_t n = 0;
5878+
uint32_t ret_orig = 0;
5879+
size_t max_key_size = 0;
5880+
5881+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5882+
xtest_teec_open_session(&session, &crypt_user_ta_uuid,
5883+
NULL, &ret_orig)))
5884+
return;
5885+
5886+
if (!ta_crypt_cmd_is_algo_supported(c, &session, TEE_ALG_ED25519,
5887+
TEE_ECC_CURVE_25519)) {
5888+
Do_ADBG_Log("ED25519 not supported: skip subcase");
5889+
goto out;
5890+
}
5891+
5892+
for (n = 0; n < ARRAY_SIZE(xtest_ac_eddsa_cases); n++) {
5893+
const struct xtest_ac_case *tv = xtest_ac_eddsa_cases + n;
5894+
5895+
if (tv->algo != TEE_ALG_ED25519)
5896+
continue;
5897+
5898+
num_attrs = 0;
5899+
num_key_attrs = 0;
5900+
max_key_size = tv->params.eddsa.private_len * 8;
5901+
5902+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5903+
ta_crypt_cmd_allocate_operation(c, &session, &op,
5904+
TEE_ALG_ED25519, tv->mode, max_key_size)))
5905+
goto out;
5906+
5907+
xtest_add_attr(&num_key_attrs, key_attrs,
5908+
TEE_ATTR_ED25519_PUBLIC_VALUE,
5909+
tv->params.eddsa.public,
5910+
tv->params.eddsa.public_len);
5911+
5912+
if (tv->params.eddsa.flag == 1)
5913+
xtest_add_attr(&num_attrs, attrs,
5914+
TEE_ATTR_EDDSA_PREHASH, NULL, 0);
5915+
5916+
if (tv->params.eddsa.context_len > 0)
5917+
xtest_add_attr(&num_attrs, attrs, TEE_ATTR_EDDSA_CTX,
5918+
tv->params.eddsa.context,
5919+
tv->params.eddsa.context_len);
5920+
5921+
switch (tv->mode) {
5922+
case TEE_MODE_SIGN:
5923+
xtest_add_attr(&num_key_attrs, key_attrs,
5924+
TEE_ATTR_ED25519_PRIVATE_VALUE,
5925+
tv->params.eddsa.private,
5926+
tv->params.eddsa.private_len);
5927+
5928+
if (!ADBG_EXPECT_TRUE(c,
5929+
create_key(c, &session, max_key_size,
5930+
TEE_TYPE_ED25519_KEYPAIR,
5931+
key_attrs, num_key_attrs,
5932+
&key_handle)))
5933+
goto out;
5934+
5935+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5936+
ta_crypt_cmd_set_operation_key(c,
5937+
&session, op, key_handle)))
5938+
goto out;
5939+
5940+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5941+
ta_crypt_cmd_asymmetric_sign(c,
5942+
&session, op,
5943+
attrs, num_attrs, tv->ptx,
5944+
tv->ptx_len, out, &out_size)))
5945+
goto out;
5946+
5947+
ADBG_EXPECT_BUFFER(c, tv->ctx, tv->ctx_len, out, out_size);
5948+
5949+
break;
5950+
5951+
case TEE_MODE_VERIFY:
5952+
if (!ADBG_EXPECT_TRUE(c,
5953+
create_key(c, &session, max_key_size,
5954+
TEE_TYPE_ED25519_PUBLIC_KEY,
5955+
key_attrs, num_key_attrs,
5956+
&key_handle)))
5957+
goto out;
5958+
5959+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5960+
ta_crypt_cmd_set_operation_key(c,
5961+
&session, op, key_handle)))
5962+
goto out;
5963+
5964+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5965+
ta_crypt_cmd_asymmetric_verify(c, &session, op,
5966+
attrs, num_attrs,
5967+
tv->ptx,
5968+
tv->ptx_len,
5969+
tv->ctx,
5970+
tv->ctx_len)))
5971+
goto out;
5972+
break;
5973+
5974+
default:
5975+
break;
5976+
}
5977+
5978+
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
5979+
ta_crypt_cmd_free_operation(c, &session, op)))
5980+
goto out;
5981+
}
5982+
out:
5983+
TEEC_CloseSession(&session);
5984+
}
5985+
ADBG_CASE_DEFINE(regression, 4016_ed25519, xtest_tee_test_4016_ed25519,
5986+
"Test TEE Internal API ED25519 sign/verify");
5987+
57695988
#endif /*CFG_SYSTEM_PTA*/

host/xtest/regression_4000_data.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,4 +8650,96 @@ static const uint8_t x25519_shared_secret[] = {
86508650
0x76, 0xf0, 0x9b, 0x3c, 0x1e, 0x16, 0x17, 0x42
86518651
};
86528652

8653+
/* Ed25519 test vectors (RFC 8032 - 7.1) */
8654+
static const uint8_t ed25519_rfc_8032_7_1_private[] = {
8655+
0x83, 0x3f, 0xe6, 0x24, 0x9, 0x23, 0x7b, 0x9d,
8656+
0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
8657+
0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
8658+
0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42
8659+
};
8660+
static const uint8_t ed25519_rfc_8032_7_1_public[] = {
8661+
0xec, 0x17, 0x2b, 0x93, 0xad, 0x5e, 0x56, 0x3b,
8662+
0xf4, 0x93, 0x2c, 0x70, 0xe1, 0x24, 0x50, 0x34,
8663+
0xc3, 0x54, 0x67, 0xef, 0x2e, 0xfd, 0x4d, 0x64,
8664+
0xeb, 0xf8, 0x19, 0x68, 0x34, 0x67, 0xe2, 0xbf
8665+
};
8666+
static const uint8_t ed25519_rfc_8032_7_1_ptx[] = {
8667+
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
8668+
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
8669+
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
8670+
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
8671+
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
8672+
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
8673+
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0xe,
8674+
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
8675+
};
8676+
static const uint8_t ed25519_rfc_8032_7_1_out[] = {
8677+
0xdc, 0x2a, 0x44, 0x59, 0xe7, 0x36, 0x96, 0x33,
8678+
0xa5, 0x2b, 0x1b, 0xf2, 0x77, 0x83, 0x9a, 0x0,
8679+
0x20, 0x10, 0x09, 0xa3, 0xef, 0xbf, 0x3e, 0xcb,
8680+
0x69, 0xbe, 0xa2, 0x18, 0x6c, 0x26, 0xb5, 0x89,
8681+
0x09, 0x35, 0x1f, 0xc9, 0xac, 0x90, 0xb3, 0xec,
8682+
0xfd, 0xfb, 0xc7, 0xc6, 0x64, 0x31, 0xe0, 0x30,
8683+
0x3d, 0xca, 0x17, 0x9c, 0x13, 0x8a, 0xc1, 0x7a,
8684+
0xd9, 0xbe, 0xf1, 0x17, 0x73, 0x31, 0xa7, 0x4
8685+
};
8686+
8687+
/* Ed25519 test vectors (RFC 8032 - 7.2) */
8688+
static const uint8_t ed25519ctx_rfc_8032_7_2_private[] = {
8689+
0x03, 0x05, 0x33, 0x4e, 0x38, 0x1a, 0xf7, 0x8f,
8690+
0x14, 0x1c, 0xb6, 0x66, 0xf6, 0x19, 0x9f, 0x57,
8691+
0xbc, 0x34, 0x95, 0x33, 0x5a, 0x25, 0x6a, 0x95,
8692+
0xbd, 0x2a, 0x55, 0xbf, 0x54, 0x66, 0x63, 0xf6
8693+
};
8694+
static const uint8_t ed25519ctx_rfc_8032_7_2_public[] = {
8695+
0xdf, 0xc9, 0x42, 0x5e, 0x4f, 0x96, 0x8f, 0x7f,
8696+
0x0c, 0x29, 0xf0, 0x25, 0x9c, 0xf5, 0xf9, 0xae,
8697+
0xd6, 0x85, 0x1c, 0x2b, 0xb4, 0xad, 0x8b, 0xfb,
8698+
0x86, 0x0c, 0xfe, 0xe0, 0xab, 0x24, 0x82, 0x92
8699+
};
8700+
static const uint8_t ed25519ctx_rfc_8032_7_2_ptx[] = {
8701+
0xf7, 0x26, 0x93, 0x6d, 0x19, 0xc8, 0x00, 0x49,
8702+
0x4e, 0x3f, 0xda, 0xff, 0x20, 0xb2, 0x76, 0xa8
8703+
};
8704+
static const uint8_t ed25519ctx_rfc_8032_7_2_out[] = {
8705+
0x55, 0xa4, 0xcc, 0x2f, 0x70, 0xa5, 0x4e, 0x4,
8706+
0x28, 0x8c, 0x5f, 0x4c, 0xd1, 0xe4, 0x5a, 0x7b,
8707+
0xb5, 0x20, 0xb3, 0x62, 0x92, 0x91, 0x18, 0x76,
8708+
0xca, 0xda, 0x73, 0x23, 0x19, 0x8d, 0xd8, 0x7a,
8709+
0x8b, 0x36, 0x95, 0x0b, 0x95, 0x13, 0x00, 0x22,
8710+
0x90, 0x7a, 0x7f, 0xb7, 0xc4, 0xe9, 0xb2, 0xd5,
8711+
0xf6, 0xcc, 0xa6, 0x85, 0xa5, 0x87, 0xb4, 0xb2,
8712+
0x1f, 0x4b, 0x88, 0x8e, 0x4e, 0x7e, 0xdb, 0xd
8713+
};
8714+
static const uint8_t ed25519ctx_rfc_8032_7_2_context[] = {
8715+
0x66, 0x6f, 0x6f
8716+
};
8717+
8718+
/* Ed25519 test vectors (RFC 8032 - 7.3) */
8719+
static const uint8_t ed25519ph_rfc_8032_7_3_private[] = {
8720+
0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
8721+
0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
8722+
0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
8723+
0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42
8724+
};
8725+
static const uint8_t ed25519ph_rfc_8032_7_3_public[] = {
8726+
0xec, 0x17, 0x2b, 0x93, 0xad, 0x5e, 0x56, 0x3b,
8727+
0xf4, 0x93, 0x2c, 0x70, 0xe1, 0x24, 0x50, 0x34,
8728+
0xc3, 0x54, 0x67, 0xef, 0x2e, 0xfd, 0x4d, 0x64,
8729+
0xeb, 0xf8, 0x19, 0x68, 0x34, 0x67, 0xe2, 0xbf
8730+
};
8731+
static const uint8_t ed25519ph_rfc_8032_7_3_ptx[] = {
8732+
0x61, 0x62, 0x63
8733+
};
8734+
static const uint8_t ed25519ph_rfc_8032_7_3_out[] = {
8735+
0x98, 0xa7, 0x02, 0x22, 0xf0, 0xb8, 0x12, 0x1a,
8736+
0xa9, 0xd3, 0x0f, 0x81, 0x3d, 0x68, 0x3f, 0x80,
8737+
0x9e, 0x46, 0x2b, 0x46, 0x9c, 0x7f, 0xf8, 0x76,
8738+
0x39, 0x49, 0x9b, 0xb9, 0x4e, 0x6d, 0xae, 0x41,
8739+
0x31, 0xf8, 0x50, 0x42, 0x46, 0x3c, 0x2a, 0x35,
8740+
0x5a, 0x20, 0x03, 0xd0, 0x62, 0xad, 0xf5, 0xaa,
8741+
0xa1, 0x0b, 0x8c, 0x61, 0xe6, 0x36, 0x06, 0x2a,
8742+
0xaa, 0xd1, 0x1c, 0x2a, 0x26, 0x08, 0x34, 0x06
8743+
};
8744+
86538745
#endif /*XTEST_4000_DATA_H*/

0 commit comments

Comments
 (0)