Skip to content

Commit 1028873

Browse files
committed
Provide context to a multi-part sign operation in a separate function
Likewise for the multi-part verify operation.
1 parent 3e9b936 commit 1028873

2 files changed

Lines changed: 100 additions & 28 deletions

File tree

doc/crypto/api.db/psa/crypto.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,12 @@ psa_status_t psa_sign_message_with_context(psa_key_id_t key,
861861
size_t signature_size,
862862
size_t * signature_length);
863863
psa_sign_operation_t psa_sign_operation_init(void);
864+
psa_status_t psa_sign_set_context(psa_sign_operation_t * operation,
865+
const uint8_t * context,
866+
size_t context_length);
864867
psa_status_t psa_sign_setup(psa_sign_operation_t * operation,
865868
psa_key_id_t key,
866-
psa_algorithm_t alg,
867-
const uint8_t * context,
868-
size_t context_length);
869+
psa_algorithm_t alg);
869870
psa_status_t psa_sign_update(psa_sign_operation_t * operation,
870871
const uint8_t * input,
871872
size_t input_length);
@@ -906,11 +907,12 @@ psa_status_t psa_verify_message_with_context(psa_key_id_t key,
906907
const uint8_t * signature,
907908
size_t signature_length);
908909
psa_verify_operation_t psa_verify_operation_init(void);
910+
psa_status_t psa_verify_set_context(psa_verify_operation_t * operation,
911+
const uint8_t * context,
912+
size_t context_length);
909913
psa_status_t psa_verify_setup(psa_verify_operation_t * operation,
910914
psa_key_id_t key,
911915
psa_algorithm_t alg,
912-
const uint8_t * context,
913-
size_t context_length,
914916
const uint8_t * signature,
915917
size_t signature_length);
916918
psa_status_t psa_verify_update(psa_verify_operation_t * operation,

doc/crypto/api/ops/signature.rst

Lines changed: 93 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,10 +2273,6 @@ Multi-part asymmetric signature operations
22732273
The key must permit the usage `PSA_KEY_USAGE_SIGN_MESSAGE`.
22742274
.. param:: psa_algorithm_t alg
22752275
An asymmetric signature algorithm: a value of type `psa_algorithm_t` such that :code:`PSA_ALG_IS_SIGN_MESSAGE(alg)` is true.
2276-
.. param:: const uint8_t * context
2277-
The context to use for this signature.
2278-
.. param:: size_t context_length
2279-
Size of the ``context`` buffer in bytes.
22802276

22812277
.. return:: psa_status_t
22822278
.. retval:: PSA_SUCCESS
@@ -2291,14 +2287,11 @@ Multi-part asymmetric signature operations
22912287

22922288
* ``alg`` is not supported, or is not an asymmetric signature algorithm that permits signing a message.
22932289
* ``key`` is not supported for use with ``alg``.
2294-
* The implementation does not support this value of ``context_length`` for ``alg``.
22952290
.. retval:: PSA_ERROR_INVALID_ARGUMENT
22962291
The following conditions can result in this error:
22972292

22982293
* ``alg`` is not an asymmetric signature algorithm that permits signing a message with a non-zero-length context.
22992294
* ``key`` is not an asymmetric key pair, that is compatible with ``alg``.
2300-
* ``context_length`` is not valid for the algorithm and key type.
2301-
* ``context`` is not a valid input value for the algorithm and key type.
23022295
.. retval:: PSA_ERROR_INSUFFICIENT_MEMORY
23032296
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
23042297
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
@@ -2312,13 +2305,12 @@ Multi-part asymmetric signature operations
23122305
* The operation state is not valid: it must be inactive.
23132306
* The library requires initializing by a call to `psa_crypto_init()`.
23142307

2315-
If a context parameter is not required or not supported by the algorithm, a zero-length context must be provided.
2316-
2317-
The sequence of operations to sign a message is as follows:
2308+
The sequence of operations to sign a message using a multi-part sign operation is as follows:
23182309

23192310
1. Allocate a sign operation object which will be passed to all the functions listed here.
23202311
#. Initialize the operation object with one of the methods described in the documentation for `psa_sign_operation_t`, for example `PSA_SIGN_OPERATION_INIT`.
2321-
#. Call `psa_sign_setup()` to specify the key-pair, algorithm, and optional context value.
2312+
#. Call `psa_sign_setup()` to specify the key pair and algorithm.
2313+
#. Optionally, call `psa_sign_set_context()` to provide a context.
23222314
#. Call `psa_sign_update()` zero, one or more times, passing a fragment of the message each time.
23232315
The signature that is calculated is the signature of the concatenation of these messages in order.
23242316
#. To extract the signature the hash, call `psa_sign_finish()`.
@@ -2336,6 +2328,49 @@ Multi-part asymmetric signature operations
23362328

23372329
See :secref:`multi-part-operations`.
23382330

2331+
.. function:: psa_sign_set_context
2332+
2333+
.. summary::
2334+
Provide a context for a multi-part sign operation.
2335+
2336+
.. versionadded:: 1.5
2337+
2338+
.. param:: psa_sign_operation_t * operation
2339+
Active sign operation.
2340+
.. param:: const uint8_t * context
2341+
Buffer containing the context value.
2342+
.. param:: size_t context_length
2343+
Size of the ``context`` buffer in bytes.
2344+
2345+
.. return:: psa_status_t
2346+
.. retval:: PSA_SUCCESS
2347+
Success.
2348+
.. retval:: PSA_ERROR_BAD_STATE
2349+
The following conditions can result in this error:
2350+
2351+
* The operation state is not valid: it must be active, and no call to `psa_sign_set_context()` or `psa_sign_update()` has been made.
2352+
* The library requires initializing by a call to `psa_crypto_init()`.
2353+
.. retval:: PSA_ERROR_INVALID_ARGUMENT
2354+
The following conditions can result in this error:
2355+
2356+
* ``context_length`` is not valid for the algorithm and key type.
2357+
* ``context`` is not a valid input value for the algorithm and key type.
2358+
.. retval:: PSA_ERROR_NOT_SUPPORTED
2359+
The context value is not supported by this implementation.
2360+
.. retval:: PSA_ERROR_INSUFFICIENT_MEMORY
2361+
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
2362+
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
2363+
2364+
This function sets the context value in a multi-part sign operation.
2365+
2366+
The application must call `psa_sign_setup()` before calling this function.
2367+
For a signature algorithm with a context parameter, this function is called immediately after `psa_sign_setup()`, before calling any other function on the sign operation.
2368+
2369+
If a context parameter is not required or not supported by the algorithm, either call `psa_sign_set_context()` with a zero-length context, or do not call this function.
2370+
The macro `PSA_ALG_SIGN_SUPPORTS_CONTEXT()` can be used to determine if a signature algorithm supports non-zero-length context values.
2371+
2372+
If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_sign_abort()`.
2373+
23392374
.. function:: psa_sign_update
23402375

23412376
.. summary::
@@ -2511,10 +2546,6 @@ Multi-part asymmetric signature operations
25112546
The key must permit the usage `PSA_KEY_USAGE_VERIFY_MESSAGE`.
25122547
.. param:: psa_algorithm_t alg
25132548
An asymmetric signature algorithm: a value of type `psa_algorithm_t` such that :code:`PSA_ALG_IS_SIGN_MESSAGE(alg)` is true.
2514-
.. param:: const uint8_t * context
2515-
The context to use for this signature.
2516-
.. param:: size_t context_length
2517-
Size of the ``context`` buffer in bytes.
25182549
.. param:: const uint8_t * signature
25192550
Buffer containing the signature to verify.
25202551
.. param:: size_t signature_length
@@ -2533,14 +2564,11 @@ Multi-part asymmetric signature operations
25332564

25342565
* ``alg`` is not supported, or is not an asymmetric signature algorithm that permits verifying a message.
25352566
* ``key`` is not supported for use with ``alg``.
2536-
* The implementation does not support this value of ``context_length`` for ``alg``.
25372567
.. retval:: PSA_ERROR_INVALID_ARGUMENT
25382568
The following conditions can result in this error:
25392569

25402570
* ``alg`` is not an asymmetric signature algorithm that permits verifying a message with a non-zero-length context.
25412571
* ``key`` is not a public key or an asymmetric key pair, that is compatible with ``alg``.
2542-
* ``context_length`` is not valid for the algorithm and key type.
2543-
* ``context`` is not a valid input value for the algorithm and key type.
25442572
.. retval:: PSA_ERROR_INSUFFICIENT_MEMORY
25452573
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
25462574
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
@@ -2554,15 +2582,14 @@ Multi-part asymmetric signature operations
25542582
* The operation state is not valid: it must be inactive.
25552583
* The library requires initializing by a call to `psa_crypto_init()`.
25562584

2557-
If a context parameter is not required or not supported by the algorithm, a zero-length context must be provided.
2558-
2559-
The sequence of operations to verify a message signature is as follows:
2585+
The sequence of operations to verify a message signature using a multi-part sign operation is as follows:
25602586

25612587
1. Allocate a verify operation object which will be passed to all the functions listed here.
25622588
#. Initialize the operation object with one of the methods described in the documentation for `psa_verify_operation_t`, for example `PSA_VERIFY_OPERATION_INIT`.
2563-
#. Call `psa_verify_setup()` to specify the key-pair, algorithm, context value, and signature to verify.
2589+
#. Call `psa_verify_setup()` to specify the key, algorithm, and signature to verify.
2590+
#. Optionally, call `psa_verify_set_context()` to provide a context.
25642591
#. Call `psa_verify_update()` zero, one or more times, passing a fragment of the message each time.
2565-
The signature tis verified against the concatenation of these messages in order.
2592+
The signature is verified against the concatenation of these messages in order.
25662593
#. To determine the validity of the signature, call `psa_verify_finish()`.
25672594

25682595
After a successful call to `psa_verify_setup()`, the operation is active, and the application must eventually terminate the operation.
@@ -2578,6 +2605,49 @@ Multi-part asymmetric signature operations
25782605

25792606
See :secref:`multi-part-operations`.
25802607

2608+
.. function:: psa_verify_set_context
2609+
2610+
.. summary::
2611+
Provide a context for a multi-part verify operation.
2612+
2613+
.. versionadded:: 1.5
2614+
2615+
.. param:: psa_verify_operation_t * operation
2616+
Active verify operation.
2617+
.. param:: const uint8_t * context
2618+
Buffer containing the context value.
2619+
.. param:: size_t context_length
2620+
Size of the ``context`` buffer in bytes.
2621+
2622+
.. return:: psa_status_t
2623+
.. retval:: PSA_SUCCESS
2624+
Success.
2625+
.. retval:: PSA_ERROR_BAD_STATE
2626+
The following conditions can result in this error:
2627+
2628+
* The operation state is not valid: it must be active, and no call to `psa_verify_set_context()` or `psa_verify_update()` has been made.
2629+
* The library requires initializing by a call to `psa_crypto_init()`.
2630+
.. retval:: PSA_ERROR_INVALID_ARGUMENT
2631+
The following conditions can result in this error:
2632+
2633+
* ``context_length`` is not valid for the algorithm and key type.
2634+
* ``context`` is not a valid input value for the algorithm and key type.
2635+
.. retval:: PSA_ERROR_NOT_SUPPORTED
2636+
The context value is not supported by this implementation.
2637+
.. retval:: PSA_ERROR_INSUFFICIENT_MEMORY
2638+
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
2639+
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
2640+
2641+
This function sets the context value in a multi-part verify operation.
2642+
2643+
The application must call `psa_verify_setup()` before calling this function.
2644+
For a signature algorithm with a context parameter, this function is called immediately after `psa_verify_setup()`, before calling any other function on the verify operation.
2645+
2646+
If a context parameter is not required or not supported by the algorithm, either call `psa_verify_set_context()` with a zero-length context, or do not call this function.
2647+
The macro `PSA_ALG_SIGN_SUPPORTS_CONTEXT()` can be used to determine if a signature algorithm supports non-zero-length context values.
2648+
2649+
If this function returns an error status, the operation enters an error state and must be aborted by calling `psa_verify_abort()`.
2650+
25812651
.. function:: psa_verify_update
25822652

25832653
.. summary::

0 commit comments

Comments
 (0)