diff --git a/doc/crypto/api.db/psa/crypto.h b/doc/crypto/api.db/psa/crypto.h index db80b884..0d635279 100644 --- a/doc/crypto/api.db/psa/crypto.h +++ b/doc/crypto/api.db/psa/crypto.h @@ -17,6 +17,8 @@ typedef uint8_t psa_key_persistence_t; typedef uint16_t psa_key_type_t; typedef uint32_t psa_key_usage_t; typedef /* implementation-defined type */ psa_mac_operation_t; +typedef /* implementation-defined type */ psa_sign_interruptible_operation_t; +typedef /* implementation-defined type */ psa_verify_interruptible_operation_t; #define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \ /* implementation-defined value */ #define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \ @@ -207,6 +209,7 @@ typedef /* implementation-defined type */ psa_mac_operation_t; /* specification-defined value */ #define PSA_HASH_SUSPEND_OUTPUT_MAX_SIZE /* implementation-defined value */ #define PSA_HASH_SUSPEND_OUTPUT_SIZE(alg) /* specification-defined value */ +#define PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED UINT32_MAX #define PSA_KEY_ATTRIBUTES_INIT /* implementation-defined value */ #define PSA_KEY_DERIVATION_INPUT_CONTEXT /* implementation-defined value */ #define PSA_KEY_DERIVATION_INPUT_COST /* implementation-defined value */ @@ -298,9 +301,13 @@ typedef /* implementation-defined type */ psa_mac_operation_t; #define PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(key_type, key_bits) \ /* implementation-defined value */ #define PSA_SIGNATURE_MAX_SIZE /* implementation-defined value */ +#define PSA_SIGN_INTERRUPTIBLE_OPERATION_INIT \ + /* implementation-defined value */ #define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \ /* implementation-defined value */ #define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE /* implementation-defined value */ +#define PSA_VERIFY_INTERRUPTIBLE_OPERATION_INIT \ + /* implementation-defined value */ psa_status_t psa_aead_abort(psa_aead_operation_t * operation); psa_status_t psa_aead_decrypt(psa_key_id_t key, psa_algorithm_t alg, @@ -483,6 +490,8 @@ psa_status_t psa_import_key(const psa_key_attributes_t * attributes, const uint8_t * data, size_t data_length, psa_key_id_t * key); +uint32_t psa_interruptible_get_max_ops(void); +void psa_interruptible_set_max_ops(uint32_t max_ops); psa_key_attributes_t psa_key_attributes_init(void); psa_status_t psa_key_derivation_abort(psa_key_derivation_operation_t * operation); psa_status_t psa_key_derivation_get_capacity(const psa_key_derivation_operation_t * operation, @@ -577,6 +586,23 @@ psa_status_t psa_sign_hash(psa_key_id_t key, uint8_t * signature, size_t signature_size, size_t * signature_length); +psa_status_t psa_sign_interruptible_abort(psa_sign_interruptible_operation_t * operation); +psa_status_t psa_sign_interruptible_complete(psa_sign_interruptible_operation_t * operation, + uint8_t * signature, + size_t signature_size, + size_t * signature_length); +uint32_t psa_sign_interruptible_get_num_ops(psa_sign_interruptible_operation_t * operation); +psa_status_t psa_sign_interruptible_hash(psa_sign_interruptible_operation_t * operation, + const uint8_t * hash, + size_t hash_length); +psa_sign_interruptible_operation_t psa_sign_interruptible_operation_init(void); +psa_status_t psa_sign_interruptible_setup(psa_sign_interruptible_operation_t * operation, + psa_key_id_t key, + psa_algorithm_t alg); +psa_status_t psa_sign_interruptible_setup_complete(psa_sign_interruptible_operation_t * operation); +psa_status_t psa_sign_interruptible_update(psa_sign_interruptible_operation_t * operation, + const uint8_t * input, + size_t input_length); psa_status_t psa_sign_message(psa_key_id_t key, psa_algorithm_t alg, const uint8_t * input, @@ -590,6 +616,22 @@ psa_status_t psa_verify_hash(psa_key_id_t key, size_t hash_length, const uint8_t * signature, size_t signature_length); +psa_status_t psa_verify_interruptible_abort(psa_verify_interruptible_operation_t * operation); +psa_status_t psa_verify_interruptible_complete(psa_verify_interruptible_operation_t * operation); +uint32_t psa_verify_interruptible_get_num_ops(psa_verify_interruptible_operation_t * operation); +psa_status_t psa_verify_interruptible_hash(psa_verify_interruptible_operation_t * operation, + const uint8_t * hash, + size_t hash_length); +psa_verify_interruptible_operation_t psa_verify_interruptible_operation_init(void); +psa_status_t psa_verify_interruptible_setup(psa_verify_interruptible_operation_t * operation, + psa_key_id_t key, + psa_algorithm_t alg, + const uint8_t * signature, + size_t signature_length); +psa_status_t psa_verify_interruptible_setup_complete(psa_verify_interruptible_operation_t * operation); +psa_status_t psa_verify_interruptible_update(psa_verify_interruptible_operation_t * operation, + const uint8_t * input, + size_t input_length); psa_status_t psa_verify_message(psa_key_id_t key, psa_algorithm_t alg, const uint8_t * input, diff --git a/doc/crypto/api/library/library.rst b/doc/crypto/api/library/library.rst index 4692bf86..e5085467 100644 --- a/doc/crypto/api/library/library.rst +++ b/doc/crypto/api/library/library.rst @@ -14,7 +14,7 @@ :include: psa/error.h /* This file is a reference template for implementation of the - * PSA Certified Crypto API v1.1 + * PSA Certified Crypto API v1.2 */ @@ -73,3 +73,55 @@ Library initialization .. warning:: The set of functions that depend on successful initialization of the library is :scterm:`IMPLEMENTATION DEFINED`. Applications that rely on calling functions before initializing the library might not be portable to other implementations. + + +Interruptible operation limit +----------------------------- + +.. todo:: Provide simple intro to these support functions + +See :secref:`interruptible-operations` + +.. function:: psa_interruptible_set_max_ops + + .. summary:: + Set the maximum number of *ops* allowed to be executed by an interruptible function in a single call. + + .. param:: uint32_t max_ops + The maximum number of ops to be executed in a single call, this can be a number from ``0`` to `PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED`, where ``0`` is obviously the least amount of work done per call. + + .. return:: void + + Interruptible functions use this value to limit the computation that is done in any single call to the function. If this limit is reached, the function will return :code:`PSA_OPERATION_INCOMPLETE`, and the caller must repeat the function call until a different status code is returned, or abort the operation. + + After initialization of the implementation, the maximum *ops* defaults to `PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED`. This means that the whole operation will complete in a single call, regardless of the number of *ops* required. An application must call `psa_interruptible_set_max_ops()` to set a different limit. + + .. note:: + + The time taken to execute a single *op* is implementation specific and depends on software, hardware, the algorithm, key type and curve chosen. Even within a single operation, successive ops can take differing amounts of time. The only guarantee is that lower values for ``max_ops`` means functions will block for a lesser maximum amount of time and conversely larger values will mean blocking for a larger maximum amount of time. The functions `psa_sign_interruptible_get_num_ops()` and `psa_verify_interruptible_get_num_ops()` are provided to help with tuning this value. + + .. admonition:: Implementation note + + The interpretation of this maximum number is obviously also implementation defined. On a hard real-time system, this can indicate a hard deadline, which is good, as a real-time system needs a guarantee of not spending more than X time, however care must be taken to avoid the situation whereby calls just return, not being able to do any actual work within the allotted time. On a non-real-time system, the implementation can be more relaxed, but again whether this number should be interpreted as as hard or soft limit or even whether a less than or equals as regards to ops executed in a single call is implementation defined. + + .. warning:: + With implementations that interpret this number as a hard limit, setting this number too small can result in an infinite loop, whereby each call results in immediate return with no computation done. + +.. function:: psa_interruptible_get_max_ops + + .. summary:: + Get the maximum number of *ops* allowed to be executed by an interruptible function in a single call. + + .. return:: uint32_t + Maximum number of *ops* allowed to be executed by an interruptible function in a single call. + + This returns the value last set in a call to `psa_interruptible_set_max_ops()`. + +.. macro:: PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED + :definition: UINT32_MAX + + .. summary:: + + Maximum value for use with `psa_interruptible_set_max_ops()`. + + Using this value in a call to `psa_interruptible_set_max_ops()` will cause interruptible functions to complete their calculation before returning. diff --git a/doc/crypto/api/ops/sign.rst b/doc/crypto/api/ops/sign.rst index 456c6da8..d9d774b3 100644 --- a/doc/crypto/api/ops/sign.rst +++ b/doc/crypto/api/ops/sign.rst @@ -9,13 +9,64 @@ Asymmetric signature ==================== -There are two pairs of single-part functions for asymmetric signature: +An asymmetric signature algorithm provides two functions: -* The signature and verification functions `psa_sign_message()` and `psa_verify_message()` take a message as one of their inputs and perform a hash-and-sign algorithm. +* **Sign**: Calculate a message signature using a private, or secret, key. +* **Verify**: Check that a signature matches a message using a public key. -* The functions `psa_sign_hash()` and `psa_verify_hash()` take a message hash as one of their inputs. This is useful for signing pre-computed hashes, or for implementing hash-and-sign using a :ref:`multi-part hash operation ` before signing the resulting hash. To determine which hash algorithm to use, call the macro `PSA_ALG_GET_HASH()` on the corresponding signature algorithm. +Successful verification indicates that the message signature was calculated using the private key that is associated with the public key. - Some hash-and-sign algorithms add padding to the message hash before completing the signing operation. The format of the padding that is used depends on the algorithm used to construct the signature, see the description of the specific algorithm for details. +In the |API|, an asymmetric-sign function requires an asymmetric key-pair; and an asymmetric-verify function requires an asymmetric public-key or key-pair. + +There are three categories of asymmetric signature algorithm in the |API|: + +* Hash-and-sign algorithms, that have two distinct phases: + + - Calculate a hash of the message + - Calculate a signature over the hash + + For these algorithms, the asymmetric signature API allows applications to either calculate the full message signature, or calculate the signature of a pre-computed hash. For example, this enables the application to use a multi-part hash operation to calculate the hash of a large message, prior to calculating or verifying a signature on the calculated hash. + + The following algorithms are in this category: + + | `PSA_ALG_RSA_PKCS1V15_SIGN` + | `PSA_ALG_RSA_PSS` + | `PSA_ALG_RSA_PSS_ANY_SALT` + | `PSA_ALG_ECDSA` + | `PSA_ALG_DETERMINISTIC_ECDSA` + | `PSA_ALG_ED25519PH` + | `PSA_ALG_ED448PH` + +* Message signature algorithms that do not separate the message processing from the signature calculations. This approach can provide better security against certain types of attack. + + For these algorithms, it is not possible to inject a pre-computed hash into the middle of the algorithm. An application can choose to calculate a message hash, and sign that instead of the message --- but this is not functionally equivalent to signing the message, and eliminates the security benefits of signing the message directly. + + Some of these algorithms still permit the signature of a large message to be calculated, or verified, by providing the message data in fragments. This is possible when the algorithm only processes the message data once. See the individual algorithm descriptions for details. + + The following algorithms are in this category: + + | `PSA_ALG_PURE_EDDSA` + +* Specialized signature algorithms, that use part of a standard signature algorithm within a specific protocol. It is recommended that these algorithms are only used for that purpose, with inputs as specified by the higher-level protocol. See the individual algorithm descriptions for details on their usage. + + The following algorithms are in this category: + + | `PSA_ALG_RSA_PKCS1V15_SIGN_RAW` + | `PSA_ALG_ECDSA_ANY` + +The |API| provides several functions for calculating and verifying signatures: + +* The single-part signature and verification functions, `psa_sign_message()` and `psa_verify_message()`, take a message as one of their inputs, and perform the sign or verify algorithm. + + These functions can be used on any hash-and-sign, or message signature, algorithms. See also `PSA_ALG_IS_SIGN_MESSAGE()`. + +* The single-part functions, `psa_sign_hash()` and `psa_verify_hash()`, typically take a message hash as one of their inputs, and perform the sign or verify algorithm. + + These functions can be used on any hash-and-sign signature algorithm. It is recommended that the input to these functions is a hash, computed using the corresponding hash algorithm. To determine which hash algorithm to use, the macro `PSA_ALG_GET_HASH()` can be called on the signature algorithm identifier. + + These functions can also be used on the specialized signature algorithms, with a hash or encoded-hash as input. See also `PSA_ALG_IS_SIGN_HASH()`. + +* The pair of `interruptible operations `, `psa_sign_interruptible_operation_t` and `psa_verify_interruptible_operation_t`, enable the signature of a message, or pre-computed hash, to be calculated and verified in an interruptible manner. See :secref:`interruptible_sign` and :secref:`interruptible_verify` for details on how to use these operations. .. _sign-algorithms: @@ -36,7 +87,7 @@ Asymmetric signature algorithms Unspecified if ``hash_alg`` is not a supported hash algorithm. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. This signature scheme is defined by :RFC-title:`8017#8.2` under the name RSASSA-PKCS1-v1_5. @@ -53,7 +104,7 @@ Asymmetric signature algorithms .. summary:: The raw RSA PKCS#1 v1.5 signature algorithm, without hashing. - This algorithm can be only used with the `psa_sign_hash()` and `psa_verify_hash()` functions. + This specialized signature algorithm can be only used with the `psa_sign_hash()` and `psa_verify_hash()` functions, or with the interruptible asymmetric signature and verification operations. This signature scheme is defined by :RFC-title:`8017#8.2` under the name RSASSA-PKCS1-v1_5. @@ -87,7 +138,7 @@ Asymmetric signature algorithms Unspecified if ``hash_alg`` is not a supported hash algorithm. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. This algorithm is randomized: each invocation returns a different, equally valid signature. @@ -124,7 +175,7 @@ Asymmetric signature algorithms Unspecified if ``hash_alg`` is not a supported hash algorithm. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. This algorithm is randomized: each invocation returns a different, equally valid signature. @@ -160,7 +211,7 @@ Asymmetric signature algorithms Unspecified if ``hash_alg`` is not a supported hash algorithm. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. When used with `psa_sign_hash()` or `psa_verify_hash()`, the provided ``hash`` parameter is the message digest, computed using the ``hash_alg`` hash algorithm. @@ -194,13 +245,15 @@ Asymmetric signature algorithms .. summary:: The randomized ECDSA signature scheme, without hashing. - This algorithm can be only used with the `psa_sign_hash()` and `psa_verify_hash()` functions. + This specialized signature algorithm can be only used with the `psa_sign_hash()` and `psa_verify_hash()` functions, or with the interruptible asymmetric signature and verification operations. This algorithm is randomized: each invocation returns a different, equally valid signature. This is the same signature scheme as `PSA_ALG_ECDSA()`, but without specifying a hash algorithm, and skipping the message hashing operation. - This algorithm is only recommended to sign or verify a sequence of bytes that are an already-calculated hash. Note that the input is padded with zeros on the left or truncated on the right as required to fit the curve size. + .. warning:: + + This algorithm is only recommended to sign or verify a sequence of bytes that are a pre-computed hash. Note that the input is padded with zeros on the left or truncated on the right as required to fit the curve size. This algorithm cannot be used with the wildcard key policy :code:`PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)`. It is only permitted when `PSA_ALG_ECDSA_ANY` is the key's permitted-algorithm policy. @@ -230,7 +283,7 @@ Asymmetric signature algorithms Unspecified if ``hash_alg`` is not a supported hash algorithm. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. When used with `psa_sign_hash()` or `psa_verify_hash()`, the provided ``hash`` parameter is the message digest, computed using the ``hash_alg`` hash algorithm. @@ -260,9 +313,9 @@ Asymmetric signature algorithms :definition: ((psa_algorithm_t) 0x06000800) .. summary:: - Edwards-curve digital signature algorithm without prehashing (PureEdDSA), using standard parameters. + Edwards-curve digital signature algorithm without pre-hashing (PureEdDSA), using standard parameters. - This algorithm can be only used with the `psa_sign_message()` and `psa_verify_message()` functions. + This message signature algorithm can be only used with the `psa_sign_message()` and `psa_verify_message()` functions, or with the interruptible asymmetric signature and verification operations. This is the PureEdDSA digital signature algorithm defined by :RFC-title:`8032`, using standard parameters. @@ -273,13 +326,18 @@ Asymmetric signature algorithms * Edwards448: the Ed448 algorithm is computed with an empty string as the context. The output signature is a 114-byte string: the concatenation of *R* and *S* as defined by :RFC:`8032#5.2.6`. .. note:: - Contexts are not supported in the current version of this specification because there is no suitable signature interface that can take the context as a parameter. A future version of this specification may add suitable functions and extend this algorithm to support contexts. + When using an interruptible asymmetric signature operation with this algorithm, it is not possible to fragment the message data when calculating the signature. The message must be passed in a single call to `psa_sign_interruptible_update()`. + + However, it is possible to fragment the message data when verifying a signature using an interruptible asymmetric verification operation. .. note:: - To sign or verify the pre-computed hash of a message using EdDSA, the HashEdDSA algorithms (`PSA_ALG_ED25519PH` and `PSA_ALG_ED448PH`) can be used with `psa_sign_hash()` and `psa_verify_hash()`. + To sign or verify the pre-computed hash of a message using EdDSA, the HashEdDSA algorithms (`PSA_ALG_ED25519PH` and `PSA_ALG_ED448PH`) can be used. The signature produced by HashEdDSA is distinct from that produced by PureEdDSA. + .. note:: + Contexts are not supported in the current version of this specification because there is no suitable signature interface that can take the context as a parameter. A future version of this specification may add suitable functions and extend this algorithm to support contexts. + .. subsection:: Compatible key types | :code:`PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_TWISTED_EDWARDS)` @@ -289,11 +347,11 @@ Asymmetric signature algorithms :definition: ((psa_algorithm_t) 0x0600090B) .. summary:: - Edwards-curve digital signature algorithm with prehashing (HashEdDSA), using the Edwards25519 curve. + Edwards-curve digital signature algorithm with pre-hashing (HashEdDSA), using the Edwards25519 curve. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. - This computes the Ed25519ph algorithm as specified in :RFC-title:`8032#5.1`, and requires an Edwards25519 curve key. An empty string is used as the context. The prehash function is SHA-512. + This calculates the Ed25519ph algorithm as specified in :RFC-title:`8032#5.1`, and requires an Edwards25519 curve key. An empty string is used as the context. The pre-hash function is SHA-512. When used with `psa_sign_hash()` or `psa_verify_hash()`, the provided ``hash`` parameter is the SHA-512 message digest. @@ -320,11 +378,11 @@ Asymmetric signature algorithms :definition: ((psa_algorithm_t) 0x06000915) .. summary:: - Edwards-curve digital signature algorithm with prehashing (HashEdDSA), using the Edwards448 curve. + Edwards-curve digital signature algorithm with pre-hashing (HashEdDSA), using the Edwards448 curve. - This algorithm can be used with both the message and hash signature functions. + This hash-and-sign signature algorithm can be used with both the message and hash signature functions. - This computes the Ed448ph algorithm as specified in :RFC-title:`8032#5.2`, and requires an Edwards448 curve key. An empty string is used as the context. The prehash function is the first 64 bytes of the output from SHAKE256. + This calculates the Ed448ph algorithm as specified in :RFC-title:`8032#5.2`, and requires an Edwards448 curve key. An empty string is used as the context. The pre-hash function is the first 64 bytes of the output from SHAKE256. When used with `psa_sign_hash()` or `psa_verify_hash()`, the provided ``hash`` parameter is the truncated SHAKE256 message digest. @@ -348,8 +406,8 @@ Asymmetric signature algorithms When used with `psa_sign_hash()` or `psa_verify_hash()`, the ``hash`` parameter to the call should be used as ``PH(M)`` in the algorithms defined in :RFC:`8032#5.2`. -Asymmetric signature functions ------------------------------- +Single-part asymmetric signature functions +------------------------------------------ .. function:: psa_sign_message @@ -390,13 +448,13 @@ Asymmetric signature functions .. retval:: PSA_ERROR_NOT_SUPPORTED The following conditions can result in this error: - * ``alg`` is not supported or is not an asymmetric signature algorithm. + * ``alg`` is not supported, or is not an asymmetric signature algorithm that permits signing a message. * ``key`` is not supported for use with ``alg``. * ``input_length`` is too large for the implementation. .. retval:: PSA_ERROR_INVALID_ARGUMENT The following conditions can result in this error: - * ``alg`` is not an asymmetric signature algorithm. + * ``alg`` is not an asymmetric signature algorithm that permits signing a message. * ``key`` is not an asymmetric key pair, that is compatible with ``alg``. * ``input_length`` is too large for the algorithm and key type. .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY @@ -443,13 +501,13 @@ Asymmetric signature functions .. retval:: PSA_ERROR_NOT_SUPPORTED The following conditions can result in this error: - * ``alg`` is not supported or is not an asymmetric signature algorithm. + * ``alg`` is not supported, or is not an asymmetric signature algorithm that permits verifying a message. * ``key`` is not supported for use with ``alg``. * ``input_length`` is too large for the implementation. .. retval:: PSA_ERROR_INVALID_ARGUMENT The following conditions can result in this error: - * ``alg`` is not an asymmetric signature algorithm. + * ``alg`` is not an asymmetric signature algorithm that permits verifying a message. * ``key`` is not a public key or an asymmetric key pair, that is compatible with ``alg``. * ``input_length`` is too large for the algorithm and key type. .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY @@ -467,7 +525,7 @@ Asymmetric signature functions .. function:: psa_sign_hash .. summary:: - Sign an already-calculated hash with a private key. + Sign a pre-computed hash with a private key. .. param:: psa_key_id_t key Identifier of the key to use for the operation. It must be an asymmetric key pair. The key must permit the usage `PSA_KEY_USAGE_SIGN_HASH`. @@ -505,12 +563,12 @@ Asymmetric signature functions .. retval:: PSA_ERROR_NOT_SUPPORTED The following conditions can result in this error: - * ``alg`` is not supported or is not an asymmetric signature algorithm. + * ``alg`` is not supported, or is not an asymmetric signature algorithm that permits signing a pre-computed hash. * ``key`` is not supported for use with ``alg``. .. retval:: PSA_ERROR_INVALID_ARGUMENT The following conditions can result in this error: - * ``alg`` is not an asymmetric signature algorithm. + * ``alg`` is not an asymmetric signature algorithm that permits signing a pre-computed hash. * ``key`` is not an asymmetric key pair, that is compatible with ``alg``. * ``hash_length`` is not valid for the algorithm and key type. * ``hash`` is not a valid input value for the algorithm and key type. @@ -524,20 +582,9 @@ Asymmetric signature functions .. retval:: PSA_ERROR_BAD_STATE The library requires initializing by a call to `psa_crypto_init()`. - With most signature algorithms that follow the hash-and-sign paradigm, the ``hash`` input to this function is the hash of the message to sign. The algorithm used to compute this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output, and the following condition is true: - - .. code-block:: xref - - hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg)) + For hash-and-sign signature algorithms, the ``hash`` input to this function is the hash of the message to sign. The algorithm used to calculate this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output: :code:`hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg))`. - The current version of this specification defines the following signature algorithms with this property: `PSA_ALG_RSA_PKCS1V15_SIGN`, `PSA_ALG_RSA_PSS`, `PSA_ALG_ECDSA`, `PSA_ALG_DETERMINISTIC_ECDSA`, `PSA_ALG_ED25519PH`, and `PSA_ALG_ED448PH`. - - Some hash-and-sign mechanisms apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. The current version of this specification defines one such signature algorithm: `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. - - .. note:: - To perform a hash-and-sign signature algorithm, the hash must be calculated before passing it to this function. This can be done by calling `psa_hash_compute()` or with a multi-part hash operation. The correct hash algorithm to use can be determined using `PSA_ALG_GET_HASH()`. - - Alternatively, to hash and sign a message in a single call, use `psa_sign_message()`. + Specialized signature algorithms can apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. For example, see `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. .. function:: psa_verify_hash @@ -572,38 +619,730 @@ Asymmetric signature functions .. retval:: PSA_ERROR_NOT_SUPPORTED The following conditions can result in this error: + * ``alg`` is not supported, or is not an asymmetric signature algorithm that permits verifying a pre-computed hash. + * ``key`` is not supported for use with ``alg``. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * ``alg`` is not an asymmetric signature algorithm that permits verifying a pre-computed hash. + * ``key`` is not a public key or an asymmetric key pair, that is compatible with ``alg``. + * ``hash_length`` is not valid for the algorithm and key type. + * ``hash`` is not a valid input value for the algorithm and key type. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_BAD_STATE + The library requires initializing by a call to `psa_crypto_init()`. + + For hash-and-sign signature algorithms, the ``hash`` input to this function is the hash of the message to verify. The algorithm used to calculate this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output: :code:`hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg))`. + + Specialized signature algorithms can apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. For example, see `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. + + +.. _interruptible_sign: + +Interruptible asymmetric signature operations +--------------------------------------------- + +.. todo:: + + Decide how to calculate the signature of the zero-length message using the interruptible API. Either: + + * Implicitly, if neither `psa_sign_interruptible_hash()`, nor `psa_sign_interruptible_update()`, is called; OR + * Require that `psa_sign_interruptible_update()` is called with a zero-length input. + + In the latter case, we can required that at least one those APIs must be called after finishing setup, before calling `psa_sign_interruptible_complete()`. + + :issue:`Current preference for the latter` + +The interruptible asymmetric signature operation calculates the signature of a message, or pre-computed hash, in an interruptible manner. For example, this can enable an application to remain responsive in an execution environment that does not provide multi-tasking. + +An interruptible asymmetric signature operation is used as follows: + +1. Allocate an interruptible asymmetric signature operation object, of type `psa_sign_interruptible_operation_t`, which will be passed to all the functions listed here. +#. Initialize the operation object with one of the methods described in the documentation for `psa_sign_interruptible_operation_t`, for example, `PSA_SIGN_INTERRUPTIBLE_OPERATION_INIT`. +#. Call `psa_sign_interruptible_setup()` to specify the algorithm and key. +#. Call `psa_sign_interruptible_setup_complete()` to complete the setup, until this function does not return :code:`PSA_OPERATION_INCOMPLETE`. +#. Either: + + 1. Call `psa_sign_interruptible_hash()` with a pre-computed hash of the message to sign; or + 2. Call `psa_sign_interruptible_update()` one or more times, passing a fragment of the message each time. The signature that is calculated will that be of the concatenation of these fragments, in order. +#. Call `psa_sign_interruptible_complete()` to finish calculating the signature value, until this function does not return :code:`PSA_OPERATION_INCOMPLETE`. +#. If an error occurs at any stage, or to terminate the operation early, call `psa_sign_interruptible_abort()`. + + +.. typedef:: /* implementation-defined type */ psa_sign_interruptible_operation_t + + .. summary:: + The type of the state data structure for an interruptible asymmetric signature operation. + + Before calling any function on an interruptible asymmetric signature operation object, the application must initialize it by any of the following means: + + * Set the object to all-bits-zero, for example: + + .. code-block:: xref + + psa_sign_interruptible_operation_t operation; + memset(&operation, 0, sizeof(operation)); + + * Initialize the object to logical zero values by declaring the object as static or global without an explicit initializer, for example: + + .. code-block:: xref + + static psa_sign_interruptible_operation_t operation; + + * Initialize the object to the initializer `PSA_SIGN_INTERRUPTIBLE_OPERATION_INIT`, for example: + + .. code-block:: xref + + psa_sign_interruptible_operation_t operation = PSA_SIGN_INTERRUPTIBLE_OPERATION_INIT; + + * Assign the result of the function `psa_sign_interruptible_operation_init()` to the object, for example: + + .. code-block:: xref + + psa_sign_interruptible_operation_t operation; + operation = psa_sign_interruptible_operation_init(); + + This is an implementation-defined type. Applications that make assumptions about the content of this object will result in implementation-specific behavior, and are non-portable. + +.. macro:: PSA_SIGN_INTERRUPTIBLE_OPERATION_INIT + :definition: /* implementation-defined value */ + + .. summary:: + This macro evaluates to an initializer for an interruptible asymmetric signature operation object of type `psa_sign_interruptible_operation_t`. + +.. function:: psa_sign_interruptible_operation_init + + .. summary:: + Return an initial value for an interruptible asymmetric signature operation object. + + .. return:: psa_sign_interruptible_operation_t + +.. function:: psa_sign_interruptible_get_num_ops + + .. summary:: + Get the number of *ops* that an interruptible asymmetric signature operation has taken so far. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to inspect. + + .. return:: uint32_t + Number of *ops* that the operation has taken so far. + + After the interruptible operation has completed, the returned value is the number of *ops* required for the entire operation. The value is reset to zero by a call to either `psa_sign_interruptible_setup()` or `psa_sign_interruptible_abort()`. + + This function can be used to tune the value passed to `psa_interruptible_set_max_ops()`. + + The value is undefined if the operation object has not been initialized. + +.. function:: psa_sign_interruptible_setup + + .. summary:: + Begin the setup of an interruptible asymmetric signature operation. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to set up. It must have been initialized as per the documentation for `psa_sign_interruptible_operation_t` and not yet in use. + .. param:: psa_key_id_t key + Identifier of the key to use for the operation. It must be an asymmetric key pair. The key must either permit the usage `PSA_KEY_USAGE_SIGN_HASH` or `PSA_KEY_USAGE_SIGN_MESSAGE`. + .. param:: psa_algorithm_t alg + An asymmetric signature algorithm: a value of type `psa_algorithm_t` such that :code:`PSA_ALG_IS_SIGN(alg)` is true. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation setup must now be completed by calling `psa_sign_interruptible_setup_complete()`. + .. retval:: PSA_ERROR_INVALID_HANDLE + ``key`` is not a valid key identifier. + .. retval:: PSA_ERROR_NOT_PERMITTED + The following conditions can result in this error: + + * The key has neither the `PSA_KEY_USAGE_SIGN_HASH` nor the `PSA_KEY_USAGE_SIGN_MESSAGE` usage flag. + * The key does not permit the requested algorithm. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The following conditions can result in this error: + * ``alg`` is not supported or is not an asymmetric signature algorithm. * ``key`` is not supported for use with ``alg``. .. retval:: PSA_ERROR_INVALID_ARGUMENT The following conditions can result in this error: * ``alg`` is not an asymmetric signature algorithm. - * ``key`` is not a public key or an asymmetric key pair, that is compatible with ``alg``. + * ``key`` is not an asymmetric key pair, that is compatible with ``alg``. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_INSUFFICIENT_ENTROPY + + This function sets up the calculation of an asymmetric signature of a message or pre-computed hash. To verify an asymmetric signature against an expected value, use an interruptible asymmetric verification operation, see :secref:`interruptible_verify`. + + After a successful call to `psa_sign_interruptible_setup()`, the operation is in setup state. Setup can be completed by calling `psa_sign_interruptible_setup_complete()` repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. Once setup has begun, the application must eventually terminate the operation. The following events terminate an operation: + + * A successful call to `psa_sign_interruptible_complete()`. + * A call to `psa_sign_interruptible_abort()`. + + If `psa_sign_interruptible_setup()` returns an error, the operation object is unchanged. + +.. function:: psa_sign_interruptible_setup_complete + + .. summary:: + Finish setting up an interruptible asymmetric signature operation. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to use. The operation must be in the process of being set up. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation is now ready for input of data to sign. + .. retval:: PSA_OPERATION_INCOMPLETE + The function was interrupted after exhausting the maximum *ops*. The computation is incomplete, and this function must be called again with the same operation object to continue. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation setup must have started, but not yet finished. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_INSUFFICIENT_ENTROPY + + .. note:: + This is an interruptible function, and must be called repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + When this function returns successfully, the operation is ready for data input using a call to `psa_sign_interruptible_hash()` or `psa_sign_interruptible_update()`. + If this function returns :code:`PSA_OPERATION_INCOMPLETE`, setup is not complete, and this function must be called again to continue the operation. + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_sign_interruptible_abort()`. + + The amount of calculation performed in a single call to this function is determined by the maximum *ops* setting. See `psa_interruptible_set_max_ops()`. + +.. function:: psa_sign_interruptible_hash + + .. summary:: + Input a pre-computed hash to an interruptible asymmetric signature operation. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to use. The operation must have been set up, with no data input. + .. param:: const uint8_t * hash + The input to sign. This is usually the hash of a message. + + See the description of this function, or the description of individual signature algorithms, for details of the acceptable inputs. + .. param:: size_t hash_length + Size of the ``hash`` buffer in bytes. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation is now ready for completion. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation must be set up, with no data input. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_NOT_PERMITTED + The key does not have the `PSA_KEY_USAGE_SIGN_HASH` flag. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * The algorithm does not allow signing of a pre-computed hash. * ``hash_length`` is not valid for the algorithm and key type. * ``hash`` is not a valid input value for the algorithm and key type. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The implementation does not support signing of a pre-computed hash. .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY .. retval:: PSA_ERROR_COMMUNICATION_FAILURE .. retval:: PSA_ERROR_CORRUPTION_DETECTED .. retval:: PSA_ERROR_STORAGE_FAILURE .. retval:: PSA_ERROR_DATA_CORRUPT .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_INSUFFICIENT_ENTROPY + :issue:`I don't think is necessary in this phase of the operation?` + + The application must complete the setup of the operation before calling this function. + + For hash-and-sign signature algorithms, the ``hash`` input to this function is the hash of the message to sign. The algorithm used to calculate this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output: :code:`hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg))`. + + Specialized signature algorithms can apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. For example, see `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. + + After input of the hash, the signature operation can be completed by calling `psa_sign_interruptible_complete()` until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_sign_interruptible_abort()`. + +.. function:: psa_sign_interruptible_update + + .. summary:: + Add a message fragment to an interruptible asymmetric signature operation. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to use. The operation must have been set up, with no hash value input. + .. param:: const uint8_t * input + Buffer containing the message fragment to add to the signature calculation. + .. param:: size_t input_length + Size of the ``input`` buffer in bytes. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation must be set up, with no hash value input. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_NOT_PERMITTED + The key does not have the `PSA_KEY_USAGE_SIGN_MESSAGE` flag. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * The algorithm does not allow signing of a message. + * The total input for the operation is too large for the signature algorithm. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The following conditions can result in this error: + + * The implementation does not support signing of a message. + * The total input for the operation is too large for the implementation. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_INSUFFICIENT_ENTROPY + :issue:`I don't think is necessary in this phase of the operation?` + + The application must complete the setup of the operation before calling this function. + + For message-signature algorithms that process the message data multiple times when computing a signature, `psa_sign_interruptible_update()` must be called exactly once with the entire message content. For signature algorithms that only process the message data once, the message content can be passed in a series of calls to `psa_sign_interruptible_update()`. + + After input of the message, the signature operation can be completed by calling `psa_sign_interruptible_complete()` until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_sign_interruptible_abort()`. + +.. function:: psa_sign_interruptible_complete + + .. summary:: + Attempt to finish the interruptible calculation of an asymmetric signature. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible asymmetric signature operation to use. The operation must have hash or message data input, or be in the process of finishing. + .. param:: uint8_t * signature + Buffer where the signature is to be written. + .. param:: size_t signature_size + Size of the ``signature`` buffer in bytes. This must be appropriate for the selected algorithm and key: + + * The required signature size is :code:`PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)` where ``key_type`` and ``key_bits`` are attributes of the key, and ``alg`` is the algorithm used to calculate the signature. + * `PSA_SIGNATURE_MAX_SIZE` evaluates to the maximum signature size of any supported signature algorithm. + .. param:: size_t * signature_length + On success, the number of bytes that make up the returned signature value. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The first ``(*signature_length)`` bytes of ``signature`` contain the signature value. + .. retval:: PSA_OPERATION_INCOMPLETE + The function was interrupted after exhausting the maximum *ops*. The computation is incomplete, and this function must be called again with the same operation object to continue. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation setup must be complete, or a previous call to `psa_sign_interruptible_complete()` returned :code:`PSA_OPERATION_INCOMPLETE`. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_BUFFER_TOO_SMALL + The size of the ``signature`` buffer is too small. + `PSA_SIGN_OUTPUT_SIZE()` or `PSA_SIGNATURE_MAX_SIZE` can be used to determine a sufficient buffer size. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + .. retval:: PSA_ERROR_INSUFFICIENT_ENTROPY + + .. note:: + This is an interruptible function, and must be called repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + When this function returns successfully, the signature is returned in ``signature``, and the operation becomes inactive. + If this function returns :code:`PSA_OPERATION_INCOMPLETE`, no signature is returned, and this function must be called again to continue the operation. + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_sign_interruptible_abort()`. + + The amount of calculation performed in a single call to this function is determined by the maximum *ops* setting. See `psa_interruptible_set_max_ops()`. + +.. function:: psa_sign_interruptible_abort + + .. summary:: + Abort an interruptible asymmetric signature operation. + + .. param:: psa_sign_interruptible_operation_t * operation + The interruptible signature operation to abort. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation object can now be discarded or reused. + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED .. retval:: PSA_ERROR_BAD_STATE The library requires initializing by a call to `psa_crypto_init()`. - With most signature algorithms that follow the hash-and-sign paradigm, the ``hash`` input to this function is the hash of the message to verify. The algorithm used to compute this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output, and the following condition is true: + 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_sign_interruptible_setup()` again. - .. code-block:: xref + This function can be called at any time after the operation object has been initialized as described in `psa_sign_interruptible_operation_t`. + + In particular, it is valid to call `psa_sign_interruptible_abort()` twice, or to call `psa_sign_interruptible_abort()` on an operation that has not been set up. + + +.. _interruptible_verify: + +Interruptible asymmetric verification operations +------------------------------------------------ + +The interruptible asymmetric verification operation verifies the signature of a message, or pre-computed hash, in an interruptible manner. For example, this can enable an application to remain responsive in an execution environment that does not provide multi-tasking. + +An interruptible asymmetric verification operation is used as follows: + +1. Allocate an interruptible asymmetric verification operation object, of type `psa_verify_interruptible_operation_t`, which will be passed to all the functions listed here. +#. Initialize the operation object with one of the methods described in the documentation for `psa_verify_interruptible_operation_t`, for example, `PSA_VERIFY_INTERRUPTIBLE_OPERATION_INIT`. +#. Call `psa_verify_interruptible_setup()` to specify the algorithm, key, and the signature to verify. +#. Call `psa_verify_interruptible_setup_complete()` to complete the setup, until this function does not return :code:`PSA_OPERATION_INCOMPLETE`. +#. Either: + + 1. Call `psa_verify_interruptible_hash()` with a pre-computed hash of the message to verify; or + 2. Call `psa_verify_interruptible_update()` one or more times, passing a fragment of the message each time. The signature is verified against the concatenation of these fragments, in order. +#. Call `psa_verify_interruptible_complete()` to finish verifying the signature value, until this function does not return :code:`PSA_OPERATION_INCOMPLETE`. +#. If an error occurs at any stage, or to terminate the operation early, call `psa_verify_interruptible_abort()`. + + +.. typedef:: /* implementation-defined type */ psa_verify_interruptible_operation_t + + .. summary:: + The type of the state data structure for an interruptible asymmetric verification operation. + + Before calling any function on an interruptible asymmetric verification operation object, the application must initialize it by any of the following means: + + * Set the object to all-bits-zero, for example: + + .. code-block:: xref + + psa_verify_interruptible_operation_t operation; + memset(&operation, 0, sizeof(operation)); + + * Initialize the object to logical zero values by declaring the object as static or global without an explicit initializer, for example: + + .. code-block:: xref + + static psa_verify_interruptible_operation_t operation; + + * Initialize the object to the initializer `PSA_VERIFY_INTERRUPTIBLE_OPERATION_INIT`, for example: + + .. code-block:: xref + + psa_verify_interruptible_operation_t operation = PSA_VERIFY_INTERRUPTIBLE_OPERATION_INIT; + + * Assign the result of the function `psa_verify_interruptible_operation_init()` to the object, for example: + + .. code-block:: xref + + psa_verify_interruptible_operation_t operation; + operation = psa_verify_interruptible_operation_init(); + + This is an implementation-defined type. Applications that make assumptions about the content of this object will result in implementation-specific behavior, and are non-portable. + +.. macro:: PSA_VERIFY_INTERRUPTIBLE_OPERATION_INIT + :definition: /* implementation-defined value */ + + .. summary:: + This macro evaluates to an initializer for an interruptible asymmetric verification operation object of type `psa_verify_interruptible_operation_t`. + +.. function:: psa_verify_interruptible_operation_init + + .. summary:: + Return an initial value for an interruptible asymmetric verification operation object. + + .. return:: psa_verify_interruptible_operation_t + +.. function:: psa_verify_interruptible_get_num_ops + + .. summary:: + Get the number of *ops* that an interruptible asymmetric verification operation has taken so far. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible asymmetric verification operation to inspect. + + .. return:: uint32_t + Number of *ops* that the operation has taken so far. + + After the interruptible operation has completed, the returned value is the number of *ops* required for the entire operation. The value is reset to zero by a call to either `psa_verify_interruptible_setup()` or `psa_verify_interruptible_abort()`. + + This function can be used to tune the value passed to `psa_interruptible_set_max_ops()`. + + The value is undefined if the operation object has not been initialized. + +.. function:: psa_verify_interruptible_setup + + .. summary:: + Begin the setup of an interruptible asymmetric verification operation. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to set up. It must have been initialized as per the documentation for `psa_verify_interruptible_operation_t` and not yet in use. + .. param:: psa_key_id_t key + Identifier of the key to use for the operation. It must be an asymmetric key pair or asymmetric public key. The key must either permit the usage `PSA_KEY_USAGE_VERIFY_HASH` or `PSA_KEY_USAGE_VERIFY_MESSAGE`. + .. param:: psa_algorithm_t alg + An asymmetric signature algorithm: a value of type `psa_algorithm_t` such that :code:`PSA_ALG_IS_SIGN(alg)` is true. + .. param:: const uint8_t * signature + Buffer containing the signature to verify. + .. param:: size_t signature_length + Size of the ``signature`` buffer in bytes. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation setup must now be completed by calling `psa_verify_interruptible_setup_complete()`. + .. retval:: PSA_ERROR_INVALID_HANDLE + ``key`` is not a valid key identifier. + .. retval:: PSA_ERROR_NOT_PERMITTED + The following conditions can result in this error: + + * The key has neither the `PSA_KEY_USAGE_VERIFY_HASH` nor the `PSA_KEY_USAGE_VERIFY_MESSAGE` usage flag. + * The key does not permit the requested algorithm. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The following conditions can result in this error: + + * ``alg`` is not supported or is not an asymmetric signature algorithm. + * ``key`` is not supported for use with ``alg``. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * ``alg`` is not an asymmetric signature algorithm. + * ``key`` is not an asymmetric key pair, or asymmetric public key, that is compatible with ``alg``. + * ``signature`` is not a valid signature for the algorithm and key. + + .. todo:: Decision required on handling invalid signatures. + + If the signature is clearly invalid (for the algorithm/key combination), an implementation could: + + 1. report ``PSA_ERROR_INVALID_ARGUMENT`` now, + 2. ``PSA_ERROR_INVALID_SIGNATURE`` now, or + 3. defer ``PSA_ERROR_INVALID_SIGNATURE`` until the operation is completed. + + Although (3) might appear to reduce information leakage (early return), it will still short cut all the calculations (as would happen in the single-part function). + + My preference is permitting an implementation to do (1)-or-(3), but we could instead permit (2)-or-(3) + + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + + This function sets up the verification of an asymmetric signature of a message or pre-computed hash. To calculate an asymmetric signature, use an interruptible asymmetric signature operation, see :secref:`interruptible_sign`. + + After a successful call to `psa_verify_interruptible_setup()`, the operation is in setup state. Setup can be completed by calling `psa_verify_interruptible_setup_complete()` repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. Once setup has begun, the application must eventually terminate the operation. The following events terminate an operation: + + * A successful call to `psa_verify_interruptible_complete()`. + * A call to `psa_verify_interruptible_abort()`. + + If `psa_verify_interruptible_setup()` returns an error, the operation object is unchanged. + +.. function:: psa_verify_interruptible_setup_complete + + .. summary:: + Finish setting up an interruptible asymmetric verification operation. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to use. The operation must be in the process of being set up. - hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg)) + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation is now ready for input of data to verify. + .. retval:: PSA_OPERATION_INCOMPLETE + The function was interrupted after exhausting the maximum *ops*. The computation is incomplete, and this function must be called again with the same operation object to continue. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation setup must have started, but not yet finished. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + + .. note:: + This is an interruptible function, and must be called repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + When this function returns successfully, the operation is ready for data input using a call to `psa_verify_interruptible_hash()` or `psa_verify_interruptible_update()`. + If this function returns :code:`PSA_OPERATION_INCOMPLETE`, setup is not complete, and this function must be called again to continue the operation. + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_verify_interruptible_abort()`. + + The amount of calculation performed in a single call to this function is determined by the maximum *ops* setting. See `psa_interruptible_set_max_ops()`. + +.. function:: psa_verify_interruptible_hash + + .. summary:: + Input a pre-computed hash to an interruptible asymmetric verification operation. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to use. The operation must have been set up, with no data input. + .. param:: const uint8_t * hash + The input whose signature is to be verified. This is usually the hash of a message. + + See the description of this function, or the description of individual signature algorithms, for details of the acceptable inputs. + .. param:: size_t hash_length + Size of the ``hash`` buffer in bytes. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation is now ready for completion. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation must be set up, with no data input. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_NOT_PERMITTED + The key does not have the `PSA_KEY_USAGE_VERIFY_HASH` flag. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * The algorithm does not allow verification of a pre-computed hash. + * ``hash_length`` is not valid for the algorithm and key type. + * ``hash`` is not a valid input value for the algorithm and key type. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The implementation does not support verification of a pre-computed hash. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + + The application must complete the setup of the operation before calling this function. + + For hash-and-sign signature algorithms, the ``hash`` input to this function is the hash of the message to verify. The algorithm used to calculate this hash is encoded in the signature algorithm. For such algorithms, ``hash_length`` must equal the length of the hash output: :code:`hash_length == PSA_HASH_LENGTH(PSA_ALG_GET_HASH(alg))`. + + Specialized signature algorithms can apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. For example, see `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. - The current version of this specification defines the following signature algorithms with this property: `PSA_ALG_RSA_PKCS1V15_SIGN`, `PSA_ALG_RSA_PSS`, `PSA_ALG_ECDSA`, `PSA_ALG_DETERMINISTIC_ECDSA`, `PSA_ALG_ED25519PH`, and `PSA_ALG_ED448PH`. + After input of the hash, the verification operation can be completed by calling `psa_verify_interruptible_complete()` until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. - Some hash-and-sign mechanisms apply a padding or encoding to the hash. In such cases, the encoded hash must be passed to this function. The current version of this specification defines one such signature algorithm: `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_verify_interruptible_abort()`. + + +.. function:: psa_verify_interruptible_update + + .. summary:: + Add a message fragment to an interruptible asymmetric verification operation. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to use. The operation must have been set up, with no hash value input. + .. param:: const uint8_t * input + Buffer containing the message fragment to add to the verification. + .. param:: size_t input_length + Size of the ``input`` buffer in bytes. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation must be set up, with no hash value input. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_NOT_PERMITTED + The key does not have the `PSA_KEY_USAGE_VERIFY_MESSAGE` flag. + .. retval:: PSA_ERROR_INVALID_ARGUMENT + The following conditions can result in this error: + + * The algorithm does not allow verification of a message. + * The total input for the operation is too large for the signature algorithm. + .. retval:: PSA_ERROR_NOT_SUPPORTED + The following conditions can result in this error: + + * The implementation does not support signing of a message. + * The total input for the operation is too large for the implementation. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID + + The application must complete the setup of the operation before calling this function. + + For message-signature algorithms that process the message data multiple times when verifying a signature, `psa_verify_interruptible_update()` must be called exactly once with the entire message content. For signature algorithms that only process the message data once, the message content can be passed in a series of calls to `psa_verify_interruptible_update()`. + + After input of the message, the verification operation can be completed by calling `psa_verify_interruptible_complete()` until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_verify_interruptible_abort()`. + +.. function:: psa_verify_interruptible_complete + + .. summary:: + Attempt to finish the interruptible verification of an asymmetric signature. + + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to use. The operation must have hash or message data input, or be in the process of finishing. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The signature is valid. + .. retval:: PSA_OPERATION_INCOMPLETE + The function was interrupted after exhausting the maximum *ops*. The computation is incomplete, and this function must be called again with the same operation object to continue. + .. retval:: PSA_ERROR_BAD_STATE + The following conditions can result in this error: + + * The operation state is not valid: the operation setup must be complete, or a previous call to `psa_verify_interruptible_complete()` returned :code:`PSA_OPERATION_INCOMPLETE`. + * The library requires initializing by a call to `psa_crypto_init()`. + .. retval:: PSA_ERROR_INVALID_SIGNATURE + The signature is not the result of signing the input message, or hash value, with the requested algorithm, using the private key corresponding to the key provided to the operation. + .. retval:: PSA_ERROR_INSUFFICIENT_MEMORY + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_STORAGE_FAILURE + .. retval:: PSA_ERROR_DATA_CORRUPT + .. retval:: PSA_ERROR_DATA_INVALID .. note:: - To perform a hash-and-sign verification algorithm, the hash must be calculated before passing it to this function. This can be done by calling `psa_hash_compute()` or with a multi-part hash operation. The correct hash algorithm to use can be determined using `PSA_ALG_GET_HASH()`. + This is an interruptible function, and must be called repeatedly, until it returns a status code that is not :code:`PSA_OPERATION_INCOMPLETE`. + + When this function returns successfully, the operation becomes inactive. + If this function returns :code:`PSA_OPERATION_INCOMPLETE`, this function must be called again to continue the operation. + If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_verify_interruptible_abort()`. + + The amount of calculation performed in a single call to this function is determined by the maximum *ops* setting. See `psa_interruptible_set_max_ops()`. + +.. function:: psa_verify_interruptible_abort + + .. summary:: + Abort an interruptible asymmetric verification operation. - Alternatively, to hash and verify a message in a single call, use `psa_verify_message()`. + .. param:: psa_verify_interruptible_operation_t * operation + The interruptible verification operation to abort. + + .. return:: psa_status_t + .. retval:: PSA_SUCCESS + Success. + The operation object can now be discarded or reused. + .. retval:: PSA_ERROR_COMMUNICATION_FAILURE + .. retval:: PSA_ERROR_CORRUPTION_DETECTED + .. retval:: PSA_ERROR_BAD_STATE + The library requires initializing by a call to `psa_crypto_init()`. + + 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_verify_interruptible_setup()` again. + + This function can be called at any time after the operation object has been initialized as described in `psa_verify_interruptible_operation_t`. + + In particular, it is valid to call `psa_verify_interruptible_abort()` twice, or to call `psa_verify_interruptible_abort()` on an operation that has not been set up. Support macros -------------- @@ -618,7 +1357,9 @@ Support macros An algorithm identifier: a value of type `psa_algorithm_t`. .. return:: - ``1`` if ``alg`` is a signature algorithm that can be used to sign a message. ``0`` if ``alg`` is a signature algorithm that can only be used to sign an already-calculated hash. ``0`` if ``alg`` is not a signature algorithm. This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier. + ``1`` if ``alg`` is a signature algorithm that can be used to sign a message. ``0`` if ``alg`` is a signature algorithm that can only be used to sign a pre-computed hash. ``0`` if ``alg`` is not a signature algorithm. This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier. + + This macro evaluates to ``1`` for hash-and-sign and message-signature algorithms. .. macro:: PSA_ALG_IS_SIGN_HASH :definition: /* specification-defined value */ @@ -632,8 +1373,7 @@ Support macros .. return:: ``1`` if ``alg`` is a signature algorithm that can be used to sign a hash. ``0`` if ``alg`` is a signature algorithm that can only be used to sign a message. ``0`` if ``alg`` is not a signature algorithm. This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier. - - This includes all algorithms such that `PSA_ALG_IS_HASH_AND_SIGN()` is true, as well as signature algorithms for which the input to `psa_sign_hash()` or `psa_verify_hash()` is not directly a hash, such as `PSA_ALG_IS_RSA_PKCS1V15_SIGN`. + This macro evaluates to ``1`` for hash-and-sign and specialized signature algorithms. .. macro:: PSA_ALG_IS_RSA_PKCS1V15_SIGN :definition: /* specification-defined value */ @@ -773,22 +1513,18 @@ Support macros .. return:: ``1`` if ``alg`` is a hash-and-sign algorithm that signs exactly the hash value, ``0`` otherwise. This macro can return either ``0`` or ``1`` if ``alg`` is not a supported algorithm identifier. - A wildcard signature algorithm policy, using `PSA_ALG_ANY_HASH`, returns the same value as the signature algorithm parameterised with a valid hash algorithm. + A wildcard signature algorithm policy, using `PSA_ALG_ANY_HASH`, returns the same value as the signature algorithm parameterized with a valid hash algorithm. This macro identifies algorithms that can be used with `psa_sign_hash()` that use the exact message hash value as an input the signature operation. For example, if :code:`PSA_ALG_IS_HASH_AND_SIGN(alg)` is true, the following call sequence is equivalent to :code:`psa_sign_message(key, alg, msg, msg_len, ...)`: .. code-block:: xref - psa_hash_operation_t op = {0}; uint8_t hash[PSA_HASH_MAX_SIZE]; size_t hash_len; - psa_hash_setup(&op, PSA_ALG_GET_HASH(alg)); - psa_hash_update(&op, msg, msg_len); - psa_hash_finish(&op, hash, sizeof(hash), &hash_len); + psa_hash_compute(PSA_ALG_GET_HASH(alg), msg, msg_len, + hash, sizeof(hash), &hash_len); psa_sign_hash(key, alg, hash, hash_len, ...); - This excludes hash-and-sign algorithms that require a encoded or modified hash for the signature step in the algorithm, such as `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`. For such algorithms, `PSA_ALG_IS_SIGN_HASH()` is true but `PSA_ALG_IS_HASH_AND_SIGN()` is false. - .. macro:: PSA_ALG_ANY_HASH :definition: ((psa_algorithm_t)0x020000ff) diff --git a/doc/crypto/appendix/history.rst b/doc/crypto/appendix/history.rst index dd735e85..acd176e4 100644 --- a/doc/crypto/appendix/history.rst +++ b/doc/crypto/appendix/history.rst @@ -17,6 +17,8 @@ Changes between *1.1.2* and *1.2.0* Changes to the API ~~~~~~~~~~~~~~~~~~ +* Added interruptible operations for asymmetric sign and verify. See :secref:`sign` and :secref:`interruptible-operations`. + Clarifications and fixes ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/crypto/figure/interruptible_operation.pdf b/doc/crypto/figure/interruptible_operation.pdf index 81472000..c5c9b415 100644 Binary files a/doc/crypto/figure/interruptible_operation.pdf and b/doc/crypto/figure/interruptible_operation.pdf differ diff --git a/doc/crypto/figure/interruptible_operation.puml b/doc/crypto/figure/interruptible_operation.puml index 51a83365..31bf24c4 100644 --- a/doc/crypto/figure/interruptible_operation.puml +++ b/doc/crypto/figure/interruptible_operation.puml @@ -13,9 +13,9 @@ legend bottom end legend state inactive as "//inactive//" -state starting as "//starting//" -state active as "//active//" -state finishing as "//finishing//" +state setup as "//setup//" +state input as "//input//" +state completing as "//completing//" state error as "//error//" ##darkred [*] --> inactive: **Initialize** @@ -23,22 +23,22 @@ note as N1 Operation object starts as uninitialised memory end note -inactive --> starting: **Setup** -starting --> starting: **Setup-complete**\n//incomplete// -starting --> active: **Setup-complete** -active --> active: **Update** -active --> finishing: **Finish**\n//incomplete// -active --> inactive: **Finish** -finishing --> finishing: **Finish**\n//incomplete// -finishing --> inactive: **Finish** +inactive --> setup: **Setup** +setup --> setup: **Setup-complete**\n//incomplete// +setup --> input: **Setup-complete** +input --> input: **Update** +input --> completing: **Complete**\n//incomplete// +input --> inactive: **Complete** +completing --> completing: **Complete**\n//incomplete// +completing --> inactive: **Complete** error -[#darkred,dashed]-> inactive: **Abort** inactive -[#darkred,dashed]-> inactive: **Setup**\n//fails// -starting -[#darkred,dashed]-> error: **Setup-complete**\n//fails// -active -[#darkred,dashed]-> error: **Update**\n//fails// -active -[#darkred,dashed]-> error: **Finish**\n//fails// -finishing -[#darkred,dashed]-> error: **Finish**\n//fails// -starting -[#blue,dotted]-> inactive: **Abort** -active -[#blue,dotted]-> inactive: **Abort** -finishing -[#blue,dotted]-> inactive: **Abort** +setup -[#darkred,dashed]-> error: **Setup-complete**\n//fails// +input -[#darkred,dashed]-> error: **Update**\n//fails// +input -[#darkred,dashed]-> error: **Complete**\n//fails// +completing -[#darkred,dashed]-> error: **Complete**\n//fails// +setup -[#blue,dotted]-> inactive: **Abort** +input -[#blue,dotted]-> inactive: **Abort** +completing -[#blue,dotted]-> inactive: **Abort** @enduml diff --git a/doc/crypto/figure/interruptible_operation.svg b/doc/crypto/figure/interruptible_operation.svg index 575421bc..ce2ed7c2 100644 --- a/doc/crypto/figure/interruptible_operation.svg +++ b/doc/crypto/figure/interruptible_operation.svg @@ -1,19 +1,19 @@ -inactivestartingactivefinishingerrorOperation object starts asuninitialised memoryInitializeSetupAbortSetup-completeincompleteSetup-completeUpdateFinishincompleteFinishAbortFinishincompleteFinishAbortAbortSetupfailsSetup-completefailsUpdatefailsFinishfailsFinishfails———Solid lines show successful operation---Dashed lines show error flows………Dotted lines show operation cancellation \ No newline at end of file +inactivesetupinputcompletingerrorOperation object starts asuninitialised memoryInitializeSetupAbortSetup-completeincompleteSetup-completeUpdateCompleteincompleteCompleteAbortCompleteincompleteCompleteAbortAbortSetupfailsSetup-completefailsUpdatefailsCompletefailsCompletefails———Solid lines show successful operation---Dashed lines show error flows………Dotted lines show operation cancellation \ No newline at end of file diff --git a/doc/crypto/overview/functionality.rst b/doc/crypto/overview/functionality.rst index 30011622..fb8b3b3b 100644 --- a/doc/crypto/overview/functionality.rst +++ b/doc/crypto/overview/functionality.rst @@ -274,7 +274,7 @@ There are three components in an interruptible operation: * A non-error status code, :code:`PSA_OPERATION_INCOMPLETE`, that is returned by some interruptible operation functions to indicate that the computation is incomplete. The same function must be called repeatedly until it returns either a success or an error status. * The concept of a unit of work --- called *ops* --- that can be carried out by an interruptible operation function. The amount of computation done, or time duration, for one *op* is implementation- and function- specific, and can depend on the algorithm inputs, for example, the key size. - An application can set an overall *max ops* value, that limits the *ops* performed within any interruptible function called by that application. The current *max ops* value can also be queried. + An application can set an overall *maximum ops* value, that limits the *ops* performed within any interruptible function called by that application. The current *maximum ops* value can also be queried. If the *maximum ops* is not set by an application, interruptible functions will not return until the operation is complete. Each interruptible operation also provides a function to report the cumulative number of *ops* used by the operation. This value is only reset when the operation object is set up for a new operation, which permits the value to be queried after an operation has finished. @@ -305,25 +305,25 @@ The typical sequence of actions with a interruptible operation is as follows: #. **Complete-setup:** Complete the operation setup on an interruptible operation object that is *starting*. - If the setup computation is interrupted, a the operation remains in *starting* state. If setup completes successfully, the operation enters an *active* state. On failure, the operation object will enter an *error* state. + If the setup computation is interrupted, a the operation remains in *setup* state. If setup completes successfully, the operation enters an *input* state. On failure, the operation object will enter an *error* state. An application needs to repeat this step until the setup completes with success or an error status. -#. **Update:** Update an *active* interruptible operation object. The update function can provide additional parameters, supply data for processing or generate outputs. +#. **Update:** Update an interruptible operation object in *input* state. The update function can provide additional parameters, supply data for processing or generate outputs. - On success, the operation object remains *active*. On failure, the operation object will enter an *error* state. + On success, the operation object remains in *input* state. On failure, the operation object will enter an *error* state. -#. **Finish:** To end an interruptible operation, call the applicable finishing function. This will take any final inputs, produce any final outputs, and then release any resources associated with the operation. +#. **Complete:** To end an interruptible operation, call the applicable completion function. This will perform the final computation, produce any final outputs, and then release any resources associated with the operation. - If the finishing computation is interrupted, a the operation is left in *finishing* state. If finishing completes successfully, the operation enters an *inactive* state. On failure, the operation object will enter an *error* state. + If the finishing computation is interrupted, a the operation is left in *completing* state. If the operation completes successfully, the operation enters an *inactive* state. On failure, the operation object will enter an *error* state. - An application needs to repeat this step until the finishing function completes with success or an error status. + An application needs to repeat this step until the completion function completes with success or an error status. -#. **Abort:** An interruptible operation can be aborted at any stage during its use by calling the associated ``psa_xxx_abort()`` function. This will release any resources associated with the operation and return the operation object to the *inactive* state. +#. **Abort:** An interruptible operation can be aborted at any stage during its use by calling the associated ``psa_xxx_interruptible_abort()`` function. This will release any resources associated with the operation and return the operation object to the *inactive* state. - Any error that occurs to an operation while it is in an *active* state will result in the operation entering an *error* state. The application must call the associated ``psa_xxx_abort()`` function to release the operation resources and return the object to the *inactive* state. + Any error that occurs to an operation while it is not in an *inactive* state will result in the operation entering an *error* state. The application must call the associated ``psa_xxx_interruptible_abort()`` function to release the operation resources and return the object to the *inactive* state. - ``psa_xxx_abort()`` can be called on an *inactive* operation, and this has no effect. + ``psa_xxx_interruptible_abort()`` can be called on an *inactive* operation, and this has no effect. Once an interruptible operation object is returned to the *inactive* state, it can be reused by calling one of the applicable setup functions again. @@ -338,9 +338,9 @@ It is safe to move an interruptible operation object to a different memory locat * Moving the object while a function is being called on the object. See also :secref:`concurrency`. * Working with both the original and the copied operation objects. -Each type of interruptible operation can have multiple *starting*, *active*, and *finishing* states. Documentation for the specific operation describes the setup, update and finishing functions, and any requirements about their usage and ordering. +Each type of interruptible operation can have multiple *setup*, *input*, and *completing* states. Documentation for the specific operation describes the setup, update and completion functions, and any requirements about their usage and ordering. -See :secref:`interruptible_example` for an example of using an interruptible operation. +See :secref:`interruptible_sign` for an example of using an interruptible operation. Randomness and key generation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~