Skip to content

Commit a301f66

Browse files
authored
Merge pull request #398 from shrutig-arm/main
Updating key agreement and PAKE tests
2 parents 36b8787 + 232fb58 commit a301f66

File tree

7 files changed

+106
-75
lines changed

7 files changed

+106
-75
lines changed

api-tests/dev_apis/crypto/test_c024/test_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static const test_data check1[] = {
507507
.usage_flags = PSA_KEY_USAGE_ENCRYPT,
508508
.key_alg = PSA_ALG_XCHACHA20_POLY1305,
509509
.aead_alg = PSA_ALG_XCHACHA20_POLY1305,
510-
.nonce = aead_Xchacha20_poly1305_nonce,
510+
.nonce = aead_xchacha20_poly1305_nonce,
511511
.nonce_length = 24,
512512
.additional_data = aead_add_data,
513513
.additional_data_length = 12,

api-tests/dev_apis/crypto/test_c042/test_data.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ static const test_data check1[] = {
274274
.alg = PSA_ALG_ED25519PH,
275275
.hash = sha_512_hash_eddsa519,
276276
.hash_length = 64,
277-
.signature = expected_output,
278277
.signature = eddsa_25519ph_signature,
279278
.signature_length = 64,
280279
.expected_status = PSA_SUCCESS,

api-tests/dev_apis/crypto/test_c050/test_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ AES_16B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CCM_STAR_NO_TAG,
193193
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(15),
194194
{0xdf, 0x2a, 0x1b, 0xaf, 0x8a, 0xcc, 0x1f, 0xf9, 0x25, 0x6d, 0x6b, 0x86, 0xb7, 0x5d, 0xd7}, 27,
195195
PSA_SUCCESS
196-
}
196+
},
197197
#endif
198198

199199
#ifdef ARCH_TEST_XCHACHA20
@@ -205,7 +205,7 @@ PSA_SUCCESS
205205
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(15),
206206
{0x9c, 0xd4, 0xb4, 0x42, 0xb0, 0xd7, 0x1e, 0xe5, 0x00, 0x91, 0x02, 0x6b, 0xe5, 0x74, 0x09}, 39,
207207
PSA_SUCCESS
208-
}
208+
},
209209
#endif
210210
};
211211
#endif

api-tests/dev_apis/crypto/test_c061/test_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ BUFFER_SIZE, {0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf,
166166
PSA_KEY_TYPE_XCHACHA20, {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b,
167167
0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
168168
0x9c, 0x9d, 0x9e, 0x9f}, 32, PSA_KEY_USAGE_ENCRYPT,
169-
PSA_ALG_XCHACHA20_POLY1305, PSA_ALG_CHACHA20_POLY1305,
169+
PSA_ALG_XCHACHA20_POLY1305, PSA_ALG_XCHACHA20_POLY1305,
170170
{0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
171171
0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
172172
0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,

api-tests/dev_apis/crypto/test_c078/test_c078.c

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @file
2-
* Copyright (c) 2024, Arm Limited or its affiliates. All rights reserved.
2+
* Copyright (c) 2024-2025, Arm Limited or its affiliates. All rights reserved.
33
* SPDX-License-Identifier : Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,27 +80,26 @@ int32_t psa_pake_jpake_setup(psa_pake_operation_t *op, const uint8_t *user, cons
8080
sizeof(peer));
8181
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
8282

83-
return VAL_STATUS_SUCCESS;
83+
return status;
8484
}
8585

8686
int32_t send_message_jpake(psa_pake_operation_t *from, psa_pake_operation_t *to,
87-
psa_pake_step_t step, uint8_t n)
87+
psa_pake_step_t step)
8888
{
8989
int32_t status;
9090
uint8_t data[1024];
9191
size_t op_len;
9292

9393
status = val->crypto_function(VAL_CRYPTO_PAKE_OUTPUT, from, step, data, sizeof(data), &op_len);
94-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(n));
9594

9695
status = val->crypto_function(VAL_CRYPTO_PAKE_INPUT, to, step, data, op_len);
97-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(n + 1));
9896

99-
return VAL_STATUS_SUCCESS;
97+
return status;
10098
}
10199

102100
int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
103101
{
102+
#if defined(ARCH_TEST_JPAKE)
104103
uint8_t i = 0;
105104
int32_t status;
106105
psa_pake_operation_t user = PSA_PAKE_OPERATION_INIT;
@@ -151,43 +150,56 @@ int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
151150
/* Round 1 key exchange */
152151
val->print(PRINT_DEBUG, "[check 3] : Starting Round1 Key Exchange from user to peer\n", 0);
153152
// Get and set g1
154-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE, 9);
153+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE);
154+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
155155

156156
// Get and set V1, ZKP public key for x1
157-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC, 11);
157+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC);
158+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
158159

159160
// Get and set r1, ZKP proof for x1
160-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF, 13);
161+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF);
162+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
161163

162164
// Get and set g2
163-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE, 15);
165+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE);
166+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
164167

165168
// Get V2, ZKP public key for x2
166-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC, 17);
169+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC);
170+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
167171

168172
// Get r2, ZKP proof for x2
169-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF, 19);
173+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF);
174+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
170175

171176
val->print(PRINT_DEBUG, " Round1 Key Exchange from user to peer done\n", 0);
172177

173178
val->print(PRINT_DEBUG, "[check 4] : Starting Round1 Key Exchange from peer to user\n", 0);
179+
174180
//Get and set g3
175-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE, 21);
181+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE);
182+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
176183

177184
// Get and set V3, ZKP public key for x3
178-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC, 23);
185+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC);
186+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
179187

180188
// get and set r3, ZKP proof for x3
181-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF, 25);
189+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF);
190+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(12));
182191

183192
// get and set g4
184-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE, 27);
193+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE);
194+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(13));
185195

186196
// Get and set V4, ZKP public key for x4
187-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC, 29);
197+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC);
198+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(14));
188199

189200
// Get and set r4, ZKP proof for x4
190-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF, 31);
201+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF);
202+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(15));
191203

192204
val->print(PRINT_DEBUG, " Round1 Key Exchange from peer to user done\n", 0);
193205

@@ -196,26 +208,32 @@ int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
196208
val->print(PRINT_DEBUG, "[check 5] : Starting Round2 Key Exchange from user to peer\n", 0);
197209

198210
// Get and set A
199-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE, 33);
211+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_KEY_SHARE);
212+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(16));
200213

201214
//Get and set V5, ZKP public key for x2*s
202-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC, 35);
215+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PUBLIC);
216+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(17));
203217

204218
// Get and set r5, ZKP proof for x2*s
205-
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF, 37);
219+
status = send_message_jpake(&user, &peer, PSA_PAKE_STEP_ZK_PROOF);
220+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(18));
206221

207222
val->print(PRINT_DEBUG, " Round2 Key Exchange from user to peer done\n", 0);
208223

209224
val->print(PRINT_DEBUG, "[check 6] : Starting Round2 Key Exchange from peer to user\n", 0);
210225

211226
// Get and Set B
212-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE, 39);
227+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_KEY_SHARE);
228+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(19));
213229

214230
// Get and Set V6, ZKP public key for x4*s
215-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC, 41);
231+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PUBLIC);
232+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(20));
216233

217234
// Get and set r6, ZKP proof for x4*s
218-
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF, 43);
235+
status = send_message_jpake(&peer, &user, PSA_PAKE_STEP_ZK_PROOF);
236+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(21));
219237

220238
val->print(PRINT_DEBUG, " Round2 Key Exchange from peer to user done\n", 0);
221239

@@ -234,26 +252,26 @@ int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
234252

235253
/* Setup Key Derivation for User */
236254
status = val->crypto_function(VAL_CRYPTO_PAKE_GET_SHARED_KEY, &user, &attributes, &key);
237-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(45));
255+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(22));
238256

239257
status = val->crypto_function(VAL_CRYPTO_PAKE_ABORT, &user);
240-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(46));
258+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(23));
241259

242260
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP,
243261
&kdf, PSA_ALG_TLS12_ECJPAKE_TO_PMS);
244-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(47));
262+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(24));
245263

246264
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY,
247265
&kdf, PSA_KEY_DERIVATION_INPUT_SECRET,
248266
key);
249-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(48));
267+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(25));
250268

251269
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES,
252270
&kdf, secret1, sizeof(secret1));
253-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(49));
271+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(26));
254272

255273
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &kdf);
256-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(50));
274+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(27));
257275

258276
val->print(PRINT_DEBUG, "[secret1] : ", 0);
259277
for (i = 0; i < 32; i++)
@@ -262,29 +280,29 @@ int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
262280
}
263281

264282
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key);
265-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(51));
283+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(28));
266284

267285
val->print(PRINT_DEBUG, "\n[check 8] : Derive shared secret from peer \n", 0);
268286

269287
/* Setup Key Derivation for Peer */
270288
status = val->crypto_function(VAL_CRYPTO_PAKE_GET_SHARED_KEY, &peer, &attributes, &key);
271-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(52));
289+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(29));
272290

273291
status = val->crypto_function(VAL_CRYPTO_PAKE_ABORT, &peer);
274-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(53));
292+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(30));
275293

276294
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_SETUP,
277295
&kdf, PSA_ALG_TLS12_ECJPAKE_TO_PMS);
278-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(54));
296+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(31));
279297

280298
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_INPUT_KEY,
281299
&kdf, PSA_KEY_DERIVATION_INPUT_SECRET,
282300
key);
283-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(55));
301+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(32));
284302

285303
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES,
286304
&kdf, secret2, sizeof(secret2));
287-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(56));
305+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(33));
288306

289307
val->print(PRINT_DEBUG, "[secret2] : ", 0);
290308

@@ -296,15 +314,20 @@ int32_t psa_pake_jpake_test(caller_security_t caller __UNUSED)
296314
val->print(PRINT_DEBUG, "\n", 0);
297315

298316
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION_ABORT, &kdf);
299-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(57));
317+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(34));
300318

301319
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, key);
302-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(58));
320+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(35));
303321

304-
TEST_ASSERT_MEMCMP(secret1, secret2, sizeof(secret1), TEST_CHECKPOINT_NUM(59));
322+
TEST_ASSERT_MEMCMP(secret1, secret2, sizeof(secret1), TEST_CHECKPOINT_NUM(36));
305323

306324
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, pw_key);
307-
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(60));
325+
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(37));
308326

309327
return VAL_STATUS_SUCCESS;
328+
329+
#else
330+
val->print(PRINT_TEST, "No test available for the selected crypto configuration\n", 0);
331+
return RESULT_SKIP(VAL_STATUS_NO_TESTS);
332+
#endif
310333
}

0 commit comments

Comments
 (0)