Lines Matching refs:key

120      * Or, for a public key, the same structure with only
163 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
169 PSA_ASSERT(psa_import_key(&attributes, key_bytes, key_length, &key));
171 *status = psa_mac_sign_setup(operation, key, alg);
177 TEST_EQUAL(psa_mac_sign_setup(operation, key, alg), *status);
180 psa_destroy_key(key);
184 psa_destroy_key(key);
195 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
201 PSA_ASSERT(psa_import_key(&attributes, key_bytes, key_length, &key));
203 *status = psa_cipher_encrypt_setup(operation, key, alg);
209 TEST_EQUAL(psa_cipher_encrypt_setup(operation, key, alg),
213 psa_destroy_key(key);
217 psa_destroy_key(key);
221 static int test_operations_on_invalid_key(mbedtls_svc_key_id_t key)
233 TEST_EQUAL(psa_get_key_attributes(key, &attributes),
245 TEST_EQUAL(psa_export_key(key, buffer, sizeof(buffer), &length),
247 TEST_EQUAL(psa_export_public_key(key,
263 /* Assert that a key isn't reported as having a slot number. */
282 /* An overapproximation of the amount of storage needed for a key of the
309 * \param key_type_arg Type of key passed in
310 * \param key_data The encryption / decryption key data
343 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
382 &key));
384 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
417 status = psa_aead_encrypt_setup(&operation, key, alg);
419 status = psa_aead_decrypt_setup(&operation, key, alg);
565 psa_destroy_key(key);
577 * \param key_type_arg Type of key passed in
578 * \param key_data The encryption / decryption key data
598 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
625 &key));
628 status = psa_mac_verify_setup(&operation, key, alg);
630 status = psa_mac_sign_setup(&operation, key, alg);
674 psa_destroy_key(key);
1240 static int rsa_test_e(mbedtls_svc_key_id_t key,
1251 PSA_ASSERT(psa_export_public_key(key,
1322 mbedtls_svc_key_id_t key;
1327 * threads attempt to load/destroy the key, exactly one thread succeeds. */
1333 /* Attempt to import the key in ctx. This handles any valid error codes
1335 * that once imported by some thread, all threads can use the key. */
1342 /* Import the key, exactly one thread must succeed. */
1351 TEST_FAIL("The same key has been loaded into the key store multiple times.");
1358 /* If all of the key slots are reserved when a thread
1363 * free key slots. Each thread reserves an empty key slot,
1364 * unlocks the mutex, then relocks it to finalize key creation.
1365 * It is at that point where the thread sees that the key
1368 * There is no guarantee that the key is loaded upon this return
1369 * code, so we can't test the key information. Just stop this
1374 /* The key has been loaded by a different thread. */
1379 /* At this point the key must exist, test the key information. */
1380 status = psa_get_key_attributes(skc->key, &got_attributes);
1384 * 1: This thread successfuly imports a persistent key skc->key.
1385 * 2: N threads reserve an empty key slot in psa_import_key,
1386 * where N is equal to the number of free key slots.
1387 * 3: A final thread attempts to reserve an empty key slot, kicking
1388 * skc->key (which has no registered readers) out of its slot.
1389 * 4: This thread calls psa_get_key_attributes(skc->key,...):
1390 * it sees that skc->key is not in a slot, attempts to load it and
1395 * of allowing persistent keys to be kicked out of the key store while
1414 /* Do something with the key according
1416 TEST_ASSERT(mbedtls_test_psa_exercise_key(skc->key,
1420 psa_status_t status = psa_destroy_key(skc->key);
1426 TEST_FAIL("The same key has been destroyed multiple times.");
1453 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1461 /* Generate a key */
1462 psa_status_t status = psa_generate_key(gkc->attributes, &key);
1470 PSA_ASSERT(psa_destroy_key(key));
1474 /* Test the key information */
1475 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
1479 /* Do something with the key according
1481 if (!mbedtls_test_psa_exercise_key(key, gkc->usage, gkc->alg, 0)) {
1482 psa_destroy_key(key);
1487 PSA_ASSERT(psa_destroy_key(key));
1538 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1554 &key);
1560 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
1567 PSA_ASSERT(psa_destroy_key(key));
1568 test_operations_on_invalid_key(key);
1577 psa_destroy_key(key);
1589 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1600 status = psa_import_key(&attributes, data->x, data->len, &key);
1605 * "well perhaps this is a key size I don't support" so it returns
1620 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
1627 PSA_ASSERT(psa_destroy_key(key));
1628 test_operations_on_invalid_key(key);
1637 psa_destroy_key(key);
1643 /* Construct and attempt to import a large unstructured key. */
1651 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1664 /* Try importing the key */
1667 status = psa_import_key(&attributes, buffer, byte_size, &key);
1672 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
1678 PSA_ASSERT(psa_export_key(key, buffer, byte_size, &n));
1694 psa_destroy_key(key);
1701 /* Import an RSA key with a valid structure (but not valid numbers
1706 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1727 /* Try importing the key */
1729 status = psa_import_key(&attributes, p, length, &key);
1733 PSA_ASSERT(psa_destroy_key(key));
1753 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1785 /* Import the key */
1786 TEST_EQUAL(psa_import_key(&attributes, data->x, data->len, &key),
1789 /* Test the key information */
1790 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
1795 /* Export the key */
1796 status = psa_export_key(key, exported, export_size, &exported_length);
1812 /* Run sanity checks on the exported key. For non-canonical inputs,
1817 if (!mbedtls_test_psa_exercise_key(key, usage_arg, 0, 0)) {
1846 /* Destroy the key */
1847 PSA_ASSERT(psa_destroy_key(key));
1848 test_operations_on_invalid_key(key);
1856 psa_destroy_key(key);
1865 int type_arg, // key pair or public key
1872 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
1890 /* Import the key */
1891 PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
1893 /* Export the public key */
1895 status = psa_export_public_key(key,
1902 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
1921 psa_destroy_key(key);
1940 skc.key = key_id;
1960 /* Test that when multiple threads import the same key,
1962 * Also test that all threads can use the key as soon as it has been
1975 /* Test that when multiple threads use and destroy a key no corruption
1976 * occurs, and exactly one thread succeeds when destroying the key. */
1987 /* Ensure that one thread succeeded in destroying the key. */
2004 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2018 /* Import the key */
2019 PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
2021 /* Test the key information */
2022 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
2026 /* Do something with the key according to its type and permitted usage. */
2027 if (!mbedtls_test_psa_exercise_key(key, usage, alg, 0)) {
2031 PSA_ASSERT(psa_destroy_key(key));
2032 test_operations_on_invalid_key(key);
2042 psa_destroy_key(key);
2053 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2071 PSA_ASSERT(psa_generate_key(&attributes, &key));
2074 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
2087 psa_destroy_key(key);
2148 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2167 &key));
2172 status = psa_mac_sign_setup(&operation, key, exercise_alg);
2178 TEST_EQUAL(psa_mac_compute(key, exercise_alg,
2185 status = psa_mac_sign_setup(&operation, key, exercise_alg);
2201 status = psa_mac_verify(key, exercise_alg, input, 128,
2211 status = psa_mac_verify_setup(&operation, key, exercise_alg);
2231 status = psa_mac_verify_setup(&operation, key, exercise_alg);
2236 psa_destroy_key(key);
2248 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2273 &key));
2275 /* Check if no key usage flag implication is done */
2280 status = psa_cipher_encrypt(key, exercise_alg, input, input_buffer_size,
2291 status = psa_cipher_encrypt_setup(&operation, key, exercise_alg);
2301 status = psa_cipher_decrypt(key, exercise_alg, output, output_buffer_size,
2312 status = psa_cipher_decrypt_setup(&operation, key, exercise_alg);
2324 psa_destroy_key(key);
2339 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2361 &key));
2363 /* Check if no key usage implication is done */
2368 status = psa_aead_encrypt(key, exercise_alg,
2381 status = psa_aead_encrypt_setup(&operation, key, exercise_alg);
2390 status = psa_aead_decrypt(key, exercise_alg,
2406 status = psa_aead_decrypt_setup(&operation, key, exercise_alg);
2415 psa_destroy_key(key);
2428 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2449 &key));
2451 /* Check if no key usage implication is done */
2455 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
2461 status = psa_asymmetric_encrypt(key, exercise_alg,
2476 status = psa_asymmetric_decrypt(key, exercise_alg,
2495 psa_destroy_key(key);
2510 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2537 &key));
2541 status = psa_sign_hash(key, exercise_alg,
2552 status = psa_verify_hash(key, exercise_alg,
2563 status = psa_sign_message(key, exercise_alg,
2574 status = psa_verify_message(key, exercise_alg,
2585 psa_destroy_key(key);
2597 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2609 &key));
2623 key);
2634 psa_destroy_key(key);
2647 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2661 &key));
2664 status = mbedtls_test_psa_key_agreement_with_self(&operation, key, 0);
2670 psa_destroy_key(key);
2679 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2694 &key));
2698 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
2703 if (!mbedtls_test_psa_exercise_key(key, usage, alg, 0)) {
2706 if (!mbedtls_test_psa_exercise_key(key, usage, alg2, 0)) {
2717 psa_destroy_key(key);
2730 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
2744 &key));
2746 status = mbedtls_test_psa_raw_key_agreement_with_self(exercise_alg, key, 0);
2752 psa_destroy_key(key);
2782 /* Prepare the source key. */
2810 /* Copy the key. */
2849 * Source and target key attributes may have been returned by
2879 /* Prepare the source key. */
2898 /* Try to copy the key. */
3466 data_t *key,
3481 if (!exercise_mac_setup(key_type, key->x, key->len, alg,
3507 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
3532 &key));
3552 PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
3554 TEST_EQUAL(psa_mac_sign_setup(&operation, key, alg),
3561 PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
3571 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3580 PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
3592 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3602 PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
3613 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3624 PSA_ASSERT(psa_destroy_key(key));
3678 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
3706 &key));
3718 TEST_EQUAL(psa_mac_compute(key, alg,
3732 PSA_ASSERT(psa_mac_sign_setup(&operation, key, alg));
3751 psa_destroy_key(key);
3764 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
3780 &key));
3783 PSA_ASSERT(psa_mac_verify(key, alg, input->x, input->len,
3787 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3795 TEST_EQUAL(psa_mac_verify(key, alg,
3802 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3813 TEST_EQUAL(psa_mac_verify(key, alg,
3819 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3832 TEST_EQUAL(psa_mac_verify(key, alg,
3837 PSA_ASSERT(psa_mac_verify_setup(&operation, key, alg));
3849 psa_destroy_key(key);
3897 data_t *key,
3912 if (!exercise_cipher_setup(key_type, key->x, key->len, alg,
3939 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
3961 &key));
3964 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
3966 TEST_EQUAL(psa_cipher_encrypt_setup(&operation, key, alg),
3973 PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
3975 TEST_EQUAL(psa_cipher_decrypt_setup(&operation, key, alg),
3989 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4003 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4019 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4031 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4049 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4061 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4080 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4092 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4102 PSA_ASSERT(psa_destroy_key(key));
4117 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4144 &key));
4148 status = psa_cipher_encrypt(key, alg, input->x, input->len, output,
4154 status = psa_cipher_encrypt_setup(&operation, key, alg);
4183 psa_destroy_key(key);
4193 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4209 &key));
4210 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4217 psa_destroy_key(key);
4226 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4249 /* Set up key and output buffer */
4255 &key));
4261 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4264 PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
4269 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4273 PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
4279 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4297 PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
4316 PSA_ASSERT(psa_cipher_encrypt(key, alg, plaintext->x, plaintext->len,
4324 PSA_ASSERT(psa_cipher_decrypt(key, alg, ciphertext->x, ciphertext->len,
4334 psa_destroy_key(key);
4342 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4356 * with incorrect key types previously. Input length should be irrelevant
4364 &key));
4366 /* Should fail due to invalid alg type (to support invalid key type).
4368 status = psa_cipher_encrypt_setup(&operation, key, alg);
4374 psa_destroy_key(key);
4385 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4412 &key));
4416 PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len, output1,
4423 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4454 psa_destroy_key(key);
4468 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4490 &key));
4492 PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
4553 psa_destroy_key(key);
4567 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4589 &key));
4591 PSA_ASSERT(psa_cipher_decrypt_setup(&operation, key, alg));
4653 psa_destroy_key(key);
4666 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4689 &key));
4704 status = psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
4709 status = psa_cipher_decrypt_setup(&operation, key, alg);
4753 psa_destroy_key(key);
4766 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4794 &key));
4796 PSA_ASSERT(psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
4808 psa_destroy_key(key);
4819 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4837 &key));
4841 PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len,
4852 PSA_ASSERT(psa_cipher_decrypt(key, alg, output1, output1_length,
4865 psa_destroy_key(key);
4877 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
4902 &key));
4904 PSA_ASSERT(psa_cipher_encrypt_setup(&operation1, key, alg));
4905 PSA_ASSERT(psa_cipher_decrypt_setup(&operation2, key, alg));
5009 psa_destroy_key(key);
5022 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5042 &key));
5043 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5059 status = psa_aead_encrypt(key, alg,
5088 TEST_EQUAL(psa_aead_decrypt(key, alg,
5102 psa_destroy_key(key);
5117 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5134 &key));
5135 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5148 status = psa_aead_encrypt(key, alg,
5168 psa_destroy_key(key);
5183 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5201 &key));
5202 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5218 status = psa_aead_decrypt(key, alg,
5242 psa_destroy_key(key);
5444 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5471 &key));
5473 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5485 status = psa_aead_encrypt_setup(&operation, key, alg);
5530 psa_destroy_key(key);
5548 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5574 &key));
5576 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5588 status = psa_aead_encrypt_setup(&operation, key, alg);
5652 psa_destroy_key(key);
5671 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5693 &key));
5695 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5703 status = psa_aead_encrypt_setup(&operation, key, alg);
5736 psa_destroy_key(key);
5755 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5778 &key));
5780 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5790 status = psa_aead_encrypt_setup(&operation, key, alg);
5822 psa_destroy_key(key);
5842 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5866 &key));
5868 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
5879 status = psa_aead_decrypt_setup(&operation, key, alg);
5923 psa_destroy_key(key);
5935 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
5951 &key));
5953 status = psa_aead_encrypt_setup(&operation, key, alg);
5959 status = psa_aead_decrypt_setup(&operation, key, alg);
5964 psa_destroy_key(key);
5977 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
6003 &key));
6005 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
6085 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6087 TEST_EQUAL(psa_aead_encrypt_setup(&operation, key, alg),
6094 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6096 TEST_EQUAL(psa_aead_decrypt_setup(&operation, key, alg),
6103 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6105 TEST_EQUAL(psa_aead_decrypt_setup(&operation, key, alg),
6112 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6114 TEST_EQUAL(psa_aead_encrypt_setup(&operation, key, alg),
6121 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6131 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6142 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6155 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6168 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6179 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6195 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6208 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6221 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6243 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6266 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6286 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6297 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6315 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6334 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6351 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6370 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6388 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6401 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6412 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6427 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6448 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6471 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6496 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6518 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6542 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6569 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6588 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6607 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6623 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6644 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6659 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6677 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6692 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6715 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6732 PSA_ASSERT(psa_aead_decrypt_setup(&operation, key, alg));
6747 PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
6762 psa_destroy_key(key);
6792 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
6808 &key));
6809 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
6821 PSA_ASSERT(psa_sign_hash(key, alg,
6836 psa_destroy_key(key);
6865 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
6891 &key));
6892 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
6912 PSA_ASSERT(psa_sign_hash_start(&operation, key, alg,
6965 psa_destroy_key(key);
6976 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
6995 &key));
6997 actual_status = psa_sign_hash(key, alg,
7010 psa_destroy_key(key);
7046 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7075 &key));
7088 actual_status = psa_sign_hash_start(&operation, key, alg,
7103 actual_status = psa_sign_hash_start(&operation, key, alg,
7158 psa_destroy_key(key);
7168 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7184 &key));
7185 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
7197 PSA_ASSERT(psa_sign_hash(key, alg,
7206 PSA_ASSERT(psa_verify_hash(key, alg,
7215 TEST_EQUAL(psa_verify_hash(key, alg,
7228 psa_destroy_key(key);
7258 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7287 &key));
7288 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
7308 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7352 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7379 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7400 psa_destroy_key(key);
7411 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7425 &key));
7427 PSA_ASSERT(psa_verify_hash(key, alg,
7433 psa_destroy_key(key);
7465 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7489 &key));
7501 PSA_ASSERT(psa_verify_hash_start(&operation, key, alg,
7551 PSA_ASSERT(psa_verify_hash_start(&operation, key, alg,
7565 psa_destroy_key(key);
7576 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7590 &key));
7592 actual_status = psa_verify_hash(key, alg,
7599 psa_destroy_key(key);
7634 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7657 &key));
7670 actual_status = psa_verify_hash_start(&operation, key, alg,
7685 actual_status = psa_verify_hash_start(&operation, key, alg,
7731 psa_destroy_key(key);
7748 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7769 &key));
7770 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
7799 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7806 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7818 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7829 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7837 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7848 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7858 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7861 TEST_EQUAL(psa_sign_hash_start(&sign_operation, key, alg,
7867 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
7871 TEST_EQUAL(psa_verify_hash_start(&verify_operation, key, alg,
7885 psa_destroy_key(key);
7903 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
7925 &key));
7926 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
7942 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7971 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
7988 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
8007 psa_destroy_key(key);
8032 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8055 PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len, &key));
8056 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8068 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
8076 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
8095 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
8113 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
8131 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
8148 PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
8164 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
8180 PSA_ASSERT(psa_verify_hash_start(&verify_operation, key, alg,
8203 psa_destroy_key(key);
8216 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8232 &key));
8233 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8241 PSA_ASSERT(psa_sign_message(key, alg,
8252 psa_destroy_key(key);
8267 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8286 &key));
8288 actual_status = psa_sign_message(key, alg,
8301 psa_destroy_key(key);
8313 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8330 &key));
8331 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8339 PSA_ASSERT(psa_sign_message(key, alg,
8346 PSA_ASSERT(psa_verify_message(key, alg,
8355 TEST_EQUAL(psa_verify_message(key, alg,
8364 psa_destroy_key(key);
8377 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8391 &key));
8393 PSA_ASSERT(psa_verify_message(key, alg,
8399 psa_destroy_key(key);
8412 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8426 &key));
8428 actual_status = psa_verify_message(key, alg,
8436 psa_destroy_key(key);
8450 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8464 /* Import the key */
8469 &key));
8472 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8480 actual_status = psa_asymmetric_encrypt(key, alg,
8499 actual_status = psa_asymmetric_encrypt(key, alg,
8519 psa_destroy_key(key);
8532 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8551 &key));
8554 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8570 PSA_ASSERT(psa_asymmetric_encrypt(key, alg,
8579 PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
8594 psa_destroy_key(key);
8609 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8625 &key));
8627 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
8635 PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
8651 PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
8663 psa_destroy_key(key);
8678 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8697 &key));
8699 actual_status = psa_asymmetric_decrypt(key, alg,
8714 actual_status = psa_asymmetric_decrypt(key, alg,
8725 psa_destroy_key(key);
8856 // When taking a private key as secret input, use key agreement
8930 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
8952 &key));
8954 /* valid key derivation */
8955 if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, key, alg,
8973 psa_destroy_key(key);
9089 case 1: // input key
9127 case 1: // input key, type DERIVE
9128 case 11: // input key, type RAW
9147 case 2: // key agreement
9189 if (derive_type == 1) { // output key
9192 /* For output key derivation secret must be provided using
9193 input key, otherwise operation is not permitted. */
9256 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
9272 &key));
9274 if (!mbedtls_test_psa_setup_key_derivation_wrap(&operation, key, alg,
9308 psa_destroy_key(key);
9390 /* Derive a key. */
9405 /* Test the key information */
9410 /* Exercise the derived key. */
9473 /* Derive the same output again, but this time store it in key objects. */
10130 /* Split threads to generate key then destroy key. */
10157 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10173 /* Generate a key */
10174 psa_status_t status = psa_generate_key(&attributes, &key);
10184 /* Test the key information */
10185 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
10189 /* Do something with the key according to its type and permitted usage. */
10190 if (!mbedtls_test_psa_exercise_key(key, usage, alg, 0)) {
10201 psa_destroy_key(key);
10215 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10233 /* Generate a key */
10237 &key);
10244 /* Test the key information */
10245 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
10251 TEST_ASSERT(rsa_test_e(key, bits, custom_data));
10255 /* Do something with the key according to its type and permitted usage. */
10256 if (!mbedtls_test_psa_exercise_key(key, usage, alg, 0)) {
10266 psa_destroy_key(key);
10280 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10303 /* Generate a key */
10306 &key);
10313 /* Test the key information */
10314 PSA_ASSERT(psa_get_key_attributes(key, &got_attributes));
10320 TEST_ASSERT(rsa_test_e(key, bits, params_data));
10324 /* Do something with the key according to its type and permitted usage. */
10325 if (!mbedtls_test_psa_exercise_key(key, usage, alg, 0)) {
10336 psa_destroy_key(key);
10361 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10389 /* Import the key */
10391 &key));
10395 /* Generate a key */
10396 PSA_ASSERT(psa_generate_key(&attributes, &key));
10402 /* Create base key */
10412 /* Derive a key. */
10422 &key));
10438 /* Export the key if permitted by the key policy. */
10440 PSA_ASSERT(psa_export_key(key,
10450 PSA_ASSERT(psa_purge_key(key));
10454 /* Check key slot still contains key data */
10455 PSA_ASSERT(psa_get_key_attributes(key, &attributes));
10466 /* Export the key again if permitted by the key policy. */
10468 PSA_ASSERT(psa_export_key(key,
10475 /* Do something with the key according to its type and permitted usage. */
10476 if (!mbedtls_test_psa_exercise_key(key, usage_flags, alg, 0)) {
10491 psa_destroy_key(key);
10511 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10530 &key));
10546 TEST_EQUAL(psa_pake_set_password_key(&operation, key),
10581 status = psa_pake_set_password_key(&operation, key);
10715 PSA_ASSERT(psa_destroy_key(key));
10732 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10741 &key));
10754 PSA_ASSERT(psa_pake_set_password_key(&server, key));
10755 PSA_ASSERT(psa_pake_set_password_key(&client, key));
10768 psa_destroy_key(key);
10786 mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
10800 &key));
10806 /* Get shared key */
10826 PSA_ASSERT(psa_pake_set_password_key(&server, key));
10827 PSA_ASSERT(psa_pake_set_password_key(&client, key));
10859 psa_destroy_key(key);
10877 /* The output for KEY_SHARE and ZK_PUBLIC is the same as a public key */