Group interruptible_export_public_key

group Interruptible public-key export

Typedefs

typedef struct psa_export_public_key_iop_s psa_export_public_key_iop_t

The type of the state data structure for interruptible public-key export operations.

Before calling any function on an interruptible export public-key object, the application must initialize it by any of the following means:

  • Set the structure to all-bits-zero, for example:

    psa_export_public_key_iop_t operation;
    memset(&operation, 0, sizeof(operation));
    

  • Initialize the structure to logical zero values, for example:

    psa_export_public_key_iop_t operation = {0};
    

  • Initialize the structure to the initializer PSA_EXPORT_PUBLIC_KEY_IOP_INIT, for example:

    psa_export_public_key_iop_t operation = PSA_EXPORT_PUBLIC_KEY_IOP_INIT;
    

  • Assign the result of the function psa_export_public_key_iop_init() to the structure, for example:

    psa_export_public_key_iop_t operation;
    operation = psa_export_public_key_iop_init();
    

This is an implementation-defined struct. Applications should not make any assumptions about the content of this structure. Implementation details can change in future versions without notice.

Functions

uint32_t psa_export_public_key_iop_get_num_ops(psa_export_public_key_iop_t *operation)

Get the number of ops that an export public-key operation has taken so far. If the operation has completed, then this will represent the number of ops required for the entire operation. After initialization or calling psa_export_public_key_iop_abort() on the operation, a value of 0 will be returned.

Warning

This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises. This is a helper provided to help you tune the value passed to psa_interruptible_set_max_ops().

Parameters:

operation – The psa_export_public_key_iop_t to use. This must be initialized first.

Returns:

Number of ops that the operation has taken so far.

psa_status_t psa_export_public_key_iop_setup(psa_export_public_key_iop_t *operation, mbedtls_svc_key_id_t key)

Start an interruptible operation to export a public key or the public part of a key pair in binary format.

Note

This function combined with psa_export_public_key_iop_complete() is equivalent to psa_export_public_key() but psa_export_public_key_iop_complete() can return early and resume according to the limit set with psa_interruptible_set_max_ops() to reduce the maximum time spent in a function.

Note

Users should call psa_export_public_key_iop_complete() repeatedly on the same operation object after a successful call to this function until psa_export_public_key_iop_complete() either returns PSA_SUCCESS or an error. psa_export_public_key_iop_complete() will return PSA_OPERATION_INCOMPLETE if there is more work to do. Alternatively users can call psa_export_public_key_iop_abort() at any point if they no longer want the result.

Note

This function clears the number of ops completed as part of the operation. Please ensure you copy this value via psa_export_public_key_iop_get_num_ops() if required before calling.

Note

If this function returns an error status, the operation enters an error state and must be aborted by calling psa_export_public_key_iop_abort().

Warning

This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.

Parameters:
Return values:
  • PSA_SUCCESS – The operation started successfully. Call psa_export_public_key_iop_complete() with the same context to complete the operation.

  • PSA_ERROR_INVALID_HANDLEkey is not a valid key identifier.

  • PSA_ERROR_INVALID_ARGUMENT – The key is neither a public key nor a key pair.

  • PSA_ERROR_NOT_SUPPORTED – The following conditions can result in this error:

    • The key’s storage location does not support export of the key.

    • The implementation does not support export of keys with this key type.

  • PSA_ERROR_BAD_STATE – The following conditions can result in this error:

    • The library has not been previously initialized by psa_crypto_init().

    • The operation state is not valid: it must be inactive.

  • PSA_ERROR_COMMUNICATION_FAILURE – \emptydescription

  • PSA_ERROR_CORRUPTION_DETECTED – \emptydescription

  • PSA_ERROR_STORAGE_FAILURE – \emptydescription

  • PSA_ERROR_DATA_CORRUPT – \emptydescription

  • PSA_ERROR_DATA_INVALID – \emptydescription

  • PSA_ERROR_INSUFFICIENT_MEMORY – \emptydescription

psa_status_t psa_export_public_key_iop_complete(psa_export_public_key_iop_t *operation, uint8_t *data, size_t data_size, size_t *data_length)

Continue and eventually complete the action of exporting a public key, in an interruptible manner.

Note

This function combined with psa_export_public_key_iop_setup() is equivalent to psa_export_public_key() but this function can return early and resume according to the limit set with psa_interruptible_set_max_ops() to reduce the maximum time spent in a function call.

Note

Users should call this function on the same operation object repeatedly whilst it returns PSA_OPERATION_INCOMPLETE, stopping when it returns either PSA_SUCCESS or an error. Alternatively users can call psa_export_public_key_iop_abort() at any point if they no longer want the result.

Note

When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_export_public_key_iop_abort().

Warning

This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.

Parameters:
  • operation[inout] The psa_export_public_key_iop_t to use. This must be initialized first, and have had psa_export_public_key_iop_setup() called with it first.

  • data[out] Buffer where the key data is to be written.

  • data_size[in] Size of the data buffer in bytes. This must be appropriate for the key:

    • The required output size is PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(type, bits) where type is the key type and bits is the key size in bits.

    • PSA_EXPORT_PUBLIC_KEY_MAX_SIZE evaluates to the maximum output size of any supported public key or public part of a key pair.

  • data_length[out] On success, the number of bytes that make up the key data.

Return values:
  • PSA_SUCCESS – Success. The first (*data_length) bytes of data contain the exported public key.

  • PSA_ERROR_BAD_STATE – The following conditions can result in this error:

    • The library has not been previously initialized by psa_crypto_init().

    • The operation state is not valid: it must be active.

  • PSA_ERROR_BUFFER_TOO_SMALL – The size of the data buffer is too small. PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(), PSA_EXPORT_PUBLIC_KEY_MAX_SIZE.

  • PSA_ERROR_INSUFFICIENT_MEMORY – \emptydescription

  • PSA_ERROR_COMMUNICATION_FAILURE – \emptydescription

  • PSA_ERROR_CORRUPTION_DETECTED – \emptydescription

  • PSA_ERROR_STORAGE_FAILURE – \emptydescription

  • PSA_ERROR_DATA_CORRUPT – \emptydescription

  • PSA_ERROR_DATA_INVALID – \emptydescription

  • PSA_OPERATION_INCOMPLETE – Operation was interrupted due to the setting of psa_interruptible_set_max_ops(). There is still work to be done. Call this function again with the same operation object.

psa_status_t psa_export_public_key_iop_abort(psa_export_public_key_iop_t *operation)

Abort an interruptible public-key export operation.

Note

This function clears the number of ops completed as part of the operation. Please ensure you copy this value via psa_export_public_key_iop_get_num_ops() if required before calling.

Note

Aborting an operation frees all associated resources except for the operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_export_public_key_iop_setup() again.

Note

You may call this function any time after the operation object has been initialized. In particular, calling psa_export_public_key_iop_abort() after the operation has already been terminated by a call to psa_export_public_key_iop_abort() or psa_export_public_key_iop_complete() is safe.

Warning

This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.

Parameters:

operation[inout] The psa_export_public_key_iop_t to use

Return values:
  • PSA_SUCCESS – The operation was aborted successfully.

  • PSA_ERROR_BAD_STATE – The library has not been previously initialized by psa_crypto_init().

  • PSA_ERROR_CORRUPTION_DETECTED – \emptydescription