@@ -443,6 +443,132 @@ psa_status_t psa_open_key(psa_key_id_t id,
443
443
*/
444
444
psa_status_t psa_close_key (psa_key_handle_t handle );
445
445
446
+ /** Make a copy of a key.
447
+ *
448
+ * Copy key material from one location to another.
449
+ *
450
+ * This function is primarily useful to copy a key from one location
451
+ * to another, since it populates a key using the material from
452
+ * another key which may have a different lifetime.
453
+ *
454
+ * This function may be used to share a key with a different party,
455
+ * subject to implementation-defined restrictions on key sharing.
456
+ *
457
+ * The policy on the source key must have the usage flag
458
+ * #PSA_KEY_USAGE_COPY set.
459
+ * This flag is sufficient to permit the copy if the key has the lifetime
460
+ * #PSA_KEY_LIFETIME_VOLATILE or #PSA_KEY_LIFETIME_PERSISTENT.
461
+ * Some secure elements do not provide a way to copy a key without
462
+ * making it extractable from the secure element. If a key is located
463
+ * in such a secure element, then the key must have both usage flags
464
+ * #PSA_KEY_USAGE_COPY and #PSA_KEY_USAGE_EXPORT in order to make
465
+ * a copy of the key outside the secure element.
466
+ *
467
+ * The resulting key may only be used in a way that conforms to
468
+ * both the policy of the original key and the policy specified in
469
+ * the \p attributes parameter:
470
+ * - The usage flags on the resulting key are the bitwise-and of the
471
+ * usage flags on the source policy and the usage flags in \p attributes.
472
+ * - If both allow the same algorithm or wildcard-based
473
+ * algorithm policy, the resulting key has the same algorithm policy.
474
+ * - If either of the policies allows an algorithm and the other policy
475
+ * allows a wildcard-based algorithm policy that includes this algorithm,
476
+ * the resulting key allows the same algorithm.
477
+ * - If the policies do not allow any algorithm in common, this function
478
+ * fails with the status #PSA_ERROR_INVALID_ARGUMENT.
479
+ *
480
+ * The effect of this function on implementation-defined attributes is
481
+ * implementation-defined.
482
+ *
483
+ * \param source_handle The key to copy. It must be a valid key handle.
484
+ * \param[in] attributes The attributes for the new key.
485
+ * They are used as follows:
486
+ * - The key type and size may be 0. If either is
487
+ * nonzero, it must match the corresponding
488
+ * attribute of the source key.
489
+ * - The key location (the lifetime and, for
490
+ * persistent keys, the key identifier) is
491
+ * used directly.
492
+ * - The policy constraints (usage flags and
493
+ * algorithm policy) are combined from
494
+ * the source key and \p attributes so that
495
+ * both sets of restrictions apply, as
496
+ * described in the documentation of this function.
497
+ * \param[out] target_handle On success, a handle to the newly created key.
498
+ * \c 0 on failure.
499
+ *
500
+ * \retval #PSA_SUCCESS
501
+ * \retval #PSA_ERROR_INVALID_HANDLE
502
+ * \p source_handle is invalid.
503
+ * \retval #PSA_ERROR_ALREADY_EXISTS
504
+ * This is an attempt to create a persistent key, and there is
505
+ * already a persistent key with the given identifier.
506
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
507
+ * The lifetime or identifier in \p attributes are invalid.
508
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
509
+ * The policy constraints on the source and specified in
510
+ * \p attributes are incompatible.
511
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
512
+ * \p attributes specifies a key type or key size
513
+ * which does not match the attributes of the source key.
514
+ * \retval #PSA_ERROR_NOT_PERMITTED
515
+ * The source key does not have the #PSA_KEY_USAGE_COPY usage flag.
516
+ * \retval #PSA_ERROR_NOT_PERMITTED
517
+ * The source key is not exportable and its lifetime does not
518
+ * allow copying it to the target's lifetime.
519
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
520
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
521
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
522
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
523
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
524
+ */
525
+ psa_status_t psa_copy_key (psa_key_handle_t source_handle ,
526
+ const psa_key_attributes_t * attributes ,
527
+ psa_key_handle_t * target_handle );
528
+
529
+
530
+ /**
531
+ * \brief Destroy a key.
532
+ *
533
+ * This function destroys a key from both volatile
534
+ * memory and, if applicable, non-volatile storage. Implementations shall
535
+ * make a best effort to ensure that that the key material cannot be recovered.
536
+ *
537
+ * This function also erases any metadata such as policies and frees all
538
+ * resources associated with the key.
539
+ *
540
+ * Destroying a key will invalidate all existing handles to the key.
541
+ *
542
+ * If the key is currently in use in a multipart operation, then destroying the
543
+ * key will abort the multipart operation.
544
+ *
545
+ * \param handle Handle to the key to erase.
546
+ *
547
+ * \retval #PSA_SUCCESS
548
+ * The key material has been erased.
549
+ * \retval #PSA_ERROR_NOT_PERMITTED
550
+ * The key cannot be erased because it is
551
+ * read-only, either due to a policy or due to physical restrictions.
552
+ * \retval #PSA_ERROR_INVALID_HANDLE
553
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
554
+ * There was an failure in communication with the cryptoprocessor.
555
+ * The key material may still be present in the cryptoprocessor.
556
+ * \retval #PSA_ERROR_STORAGE_FAILURE
557
+ * The storage is corrupted. Implementations shall make a best effort
558
+ * to erase key material even in this stage, however applications
559
+ * should be aware that it may be impossible to guarantee that the
560
+ * key material is not recoverable in such cases.
561
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
562
+ * An unexpected condition which is not a storage corruption or
563
+ * a communication failure occurred. The cryptoprocessor may have
564
+ * been compromised.
565
+ * \retval #PSA_ERROR_BAD_STATE
566
+ * The library has not been previously initialized by psa_crypto_init().
567
+ * It is implementation-dependent whether a failure to initialize
568
+ * results in this error code.
569
+ */
570
+ psa_status_t psa_destroy_key (psa_key_handle_t handle );
571
+
446
572
/**@}*/
447
573
448
574
/** \defgroup import_export Key import and export
0 commit comments