@@ -792,12 +792,12 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
792
792
* \retval #PSA_SUCCESS
793
793
* \retval #PSA_ERROR_INVALID_HANDLE
794
794
* \retval #PSA_ERROR_OCCUPIED_SLOT
795
- * \p target already contains key material.
795
+ * \p target_handle already contains key material.
796
796
* \retval #PSA_ERROR_EMPTY_SLOT
797
- * \p source does not contain key material.
797
+ * \p source_handle does not contain key material.
798
798
* \retval #PSA_ERROR_INVALID_ARGUMENT
799
799
* The policy constraints on the source, on the target and
800
- * \p constraints are incompatible.
800
+ * \p constraint are incompatible.
801
801
* \retval #PSA_ERROR_NOT_PERMITTED
802
802
* The source key is not exportable and its lifetime does not
803
803
* allow copying it to the target's lifetime.
@@ -1152,7 +1152,7 @@ psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation,
1152
1152
* \retval #PSA_ERROR_EMPTY_SLOT
1153
1153
* \retval #PSA_ERROR_NOT_PERMITTED
1154
1154
* \retval #PSA_ERROR_INVALID_ARGUMENT
1155
- * \p key is not compatible with \p alg.
1155
+ * \p handle is not compatible with \p alg.
1156
1156
* \retval #PSA_ERROR_NOT_SUPPORTED
1157
1157
* \p alg is not supported or is not a MAC algorithm.
1158
1158
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1191,7 +1191,7 @@ psa_status_t psa_mac_compute(psa_key_handle_t handle,
1191
1191
* \retval #PSA_ERROR_EMPTY_SLOT
1192
1192
* \retval #PSA_ERROR_NOT_PERMITTED
1193
1193
* \retval #PSA_ERROR_INVALID_ARGUMENT
1194
- * \p key is not compatible with \p alg.
1194
+ * \p handle is not compatible with \p alg.
1195
1195
* \retval #PSA_ERROR_NOT_SUPPORTED
1196
1196
* \p alg is not supported or is not a MAC algorithm.
1197
1197
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1294,7 +1294,7 @@ static psa_mac_operation_t psa_mac_operation_init(void);
1294
1294
* \retval #PSA_ERROR_EMPTY_SLOT
1295
1295
* \retval #PSA_ERROR_NOT_PERMITTED
1296
1296
* \retval #PSA_ERROR_INVALID_ARGUMENT
1297
- * \p key is not compatible with \p alg.
1297
+ * \p handle is not compatible with \p alg.
1298
1298
* \retval #PSA_ERROR_NOT_SUPPORTED
1299
1299
* \p alg is not supported or is not a MAC algorithm.
1300
1300
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1532,7 +1532,7 @@ psa_status_t psa_mac_abort(psa_mac_operation_t *operation);
1532
1532
* \retval #PSA_ERROR_EMPTY_SLOT
1533
1533
* \retval #PSA_ERROR_NOT_PERMITTED
1534
1534
* \retval #PSA_ERROR_INVALID_ARGUMENT
1535
- * \p key is not compatible with \p alg.
1535
+ * \p handle is not compatible with \p alg.
1536
1536
* \retval #PSA_ERROR_NOT_SUPPORTED
1537
1537
* \p alg is not supported or is not a cipher algorithm.
1538
1538
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
@@ -1574,7 +1574,7 @@ psa_status_t psa_cipher_encrypt(psa_key_handle_t handle,
1574
1574
* \retval #PSA_ERROR_EMPTY_SLOT
1575
1575
* \retval #PSA_ERROR_NOT_PERMITTED
1576
1576
* \retval #PSA_ERROR_INVALID_ARGUMENT
1577
- * \p key is not compatible with \p alg.
1577
+ * \p handle is not compatible with \p alg.
1578
1578
* \retval #PSA_ERROR_NOT_SUPPORTED
1579
1579
* \p alg is not supported or is not a cipher algorithm.
1580
1580
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
@@ -1680,7 +1680,7 @@ static psa_cipher_operation_t psa_cipher_operation_init(void);
1680
1680
* \retval #PSA_ERROR_EMPTY_SLOT
1681
1681
* \retval #PSA_ERROR_NOT_PERMITTED
1682
1682
* \retval #PSA_ERROR_INVALID_ARGUMENT
1683
- * \p key is not compatible with \p alg.
1683
+ * \p handle is not compatible with \p alg.
1684
1684
* \retval #PSA_ERROR_NOT_SUPPORTED
1685
1685
* \p alg is not supported or is not a cipher algorithm.
1686
1686
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1739,7 +1739,7 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
1739
1739
* \retval #PSA_ERROR_EMPTY_SLOT
1740
1740
* \retval #PSA_ERROR_NOT_PERMITTED
1741
1741
* \retval #PSA_ERROR_INVALID_ARGUMENT
1742
- * \p key is not compatible with \p alg.
1742
+ * \p handle is not compatible with \p alg.
1743
1743
* \retval #PSA_ERROR_NOT_SUPPORTED
1744
1744
* \p alg is not supported or is not a cipher algorithm.
1745
1745
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -1967,7 +1967,7 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
1967
1967
* \retval #PSA_ERROR_EMPTY_SLOT
1968
1968
* \retval #PSA_ERROR_NOT_PERMITTED
1969
1969
* \retval #PSA_ERROR_INVALID_ARGUMENT
1970
- * \p key is not compatible with \p alg.
1970
+ * \p handle is not compatible with \p alg.
1971
1971
* \retval #PSA_ERROR_NOT_SUPPORTED
1972
1972
* \p alg is not supported or is not an AEAD algorithm.
1973
1973
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2025,7 +2025,7 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle,
2025
2025
* The ciphertext is not authentic.
2026
2026
* \retval #PSA_ERROR_NOT_PERMITTED
2027
2027
* \retval #PSA_ERROR_INVALID_ARGUMENT
2028
- * \p key is not compatible with \p alg.
2028
+ * \p handle is not compatible with \p alg.
2029
2029
* \retval #PSA_ERROR_NOT_SUPPORTED
2030
2030
* \p alg is not supported or is not an AEAD algorithm.
2031
2031
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2144,7 +2144,7 @@ static psa_aead_operation_t psa_aead_operation_init(void);
2144
2144
* \retval #PSA_ERROR_EMPTY_SLOT
2145
2145
* \retval #PSA_ERROR_NOT_PERMITTED
2146
2146
* \retval #PSA_ERROR_INVALID_ARGUMENT
2147
- * \p key is not compatible with \p alg.
2147
+ * \p handle is not compatible with \p alg.
2148
2148
* \retval #PSA_ERROR_NOT_SUPPORTED
2149
2149
* \p alg is not supported or is not an AEAD algorithm.
2150
2150
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2206,7 +2206,7 @@ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation,
2206
2206
* \retval #PSA_ERROR_EMPTY_SLOT
2207
2207
* \retval #PSA_ERROR_NOT_PERMITTED
2208
2208
* \retval #PSA_ERROR_INVALID_ARGUMENT
2209
- * \p key is not compatible with \p alg.
2209
+ * \p handle is not compatible with \p alg.
2210
2210
* \retval #PSA_ERROR_NOT_SUPPORTED
2211
2211
* \p alg is not supported or is not an AEAD algorithm.
2212
2212
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2444,7 +2444,7 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
2444
2444
* psa_aead_update() does not buffer any output and therefore \p ciphertext
2445
2445
* will not contain any output and can be a 0-sized buffer.
2446
2446
* - \p tag contains the authentication tag. Its length is always
2447
- * #PSA_AEAD_TAG_LENGTH(\p alg) where \p alg is the AEAD algorithm
2447
+ * #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is the AEAD algorithm
2448
2448
* that the operation performs.
2449
2449
*
2450
2450
* When this function returns, the operation becomes inactive.
@@ -2467,7 +2467,7 @@ psa_status_t psa_aead_update(psa_aead_operation_t *operation,
2467
2467
* The operation state is not valid (not set up, nonce not set,
2468
2468
* decryption, or already completed).
2469
2469
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
2470
- * The size of the \p output buffer is too small.
2470
+ * The size of the \p ciphertext or \p tag buffer is too small.
2471
2471
* \retval #PSA_ERROR_INVALID_ARGUMENT
2472
2472
* The total length of input to psa_aead_update_ad() so far is
2473
2473
* less than the additional data length that was previously
@@ -2509,8 +2509,6 @@ psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
2509
2509
* \retval #PSA_ERROR_BAD_STATE
2510
2510
* The operation state is not valid (not set up, nonce not set,
2511
2511
* encryption, or already completed).
2512
- * \retval #PSA_ERROR_BUFFER_TOO_SMALL
2513
- * The size of the \p output buffer is too small.
2514
2512
* \retval #PSA_ERROR_INVALID_ARGUMENT
2515
2513
* The total length of input to psa_aead_update_ad() so far is
2516
2514
* less than the additional data length that was previously
@@ -2576,7 +2574,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
2576
2574
* \param handle Handle to the key to use for the operation.
2577
2575
* It must be an asymmetric key pair.
2578
2576
* \param alg A signature algorithm that is compatible with
2579
- * the type of \p key .
2577
+ * the type of \p handle .
2580
2578
* \param[in] hash The hash or message to sign.
2581
2579
* \param hash_length Size of the \p hash buffer in bytes.
2582
2580
* \param[out] signature Buffer where the signature is to be written.
@@ -2590,7 +2588,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
2590
2588
* determine a sufficient buffer size by calling
2591
2589
* #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
2592
2590
* where \c key_type and \c key_bits are the type and bit-size
2593
- * respectively of \p key .
2591
+ * respectively of \p handle .
2594
2592
* \retval #PSA_ERROR_NOT_SUPPORTED
2595
2593
* \retval #PSA_ERROR_INVALID_ARGUMENT
2596
2594
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2623,7 +2621,7 @@ psa_status_t psa_asymmetric_sign(psa_key_handle_t handle,
2623
2621
* \param handle Handle to the key to use for the operation.
2624
2622
* It must be a public key or an asymmetric key pair.
2625
2623
* \param alg A signature algorithm that is compatible with
2626
- * the type of \p key .
2624
+ * the type of \p handle .
2627
2625
* \param[in] hash The hash or message whose signature is to be
2628
2626
* verified.
2629
2627
* \param hash_length Size of the \p hash buffer in bytes.
@@ -2660,7 +2658,7 @@ psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
2660
2658
* It must be a public key or an asymmetric
2661
2659
* key pair.
2662
2660
* \param alg An asymmetric encryption algorithm that is
2663
- * compatible with the type of \p key .
2661
+ * compatible with the type of \p handle .
2664
2662
* \param[in] input The message to encrypt.
2665
2663
* \param input_length Size of the \p input buffer in bytes.
2666
2664
* \param[in] salt A salt or label, if supported by the
@@ -2687,7 +2685,7 @@ psa_status_t psa_asymmetric_verify(psa_key_handle_t handle,
2687
2685
* determine a sufficient buffer size by calling
2688
2686
* #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
2689
2687
* where \c key_type and \c key_bits are the type and bit-size
2690
- * respectively of \p key .
2688
+ * respectively of \p handle .
2691
2689
* \retval #PSA_ERROR_NOT_SUPPORTED
2692
2690
* \retval #PSA_ERROR_INVALID_ARGUMENT
2693
2691
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2716,7 +2714,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle,
2716
2714
* \param handle Handle to the key to use for the operation.
2717
2715
* It must be an asymmetric key pair.
2718
2716
* \param alg An asymmetric encryption algorithm that is
2719
- * compatible with the type of \p key .
2717
+ * compatible with the type of \p handle .
2720
2718
* \param[in] input The message to decrypt.
2721
2719
* \param input_length Size of the \p input buffer in bytes.
2722
2720
* \param[in] salt A salt or label, if supported by the
@@ -2743,7 +2741,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle,
2743
2741
* determine a sufficient buffer size by calling
2744
2742
* #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
2745
2743
* where \c key_type and \c key_bits are the type and bit-size
2746
- * respectively of \p key .
2744
+ * respectively of \p handle .
2747
2745
* \retval #PSA_ERROR_NOT_SUPPORTED
2748
2746
* \retval #PSA_ERROR_INVALID_ARGUMENT
2749
2747
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
@@ -2880,24 +2878,89 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator,
2880
2878
uint8_t * output ,
2881
2879
size_t output_length );
2882
2880
2883
- /** Create a symmetric key from data read from a generator.
2884
- *
2885
- * This function reads a sequence of bytes from a generator and imports
2886
- * these bytes as a key.
2887
- * The data that is read is discarded from the generator. The generator's
2888
- * capacity is decreased by the number of bytes read.
2889
- *
2890
- * This function is equivalent to calling #psa_generator_read and
2891
- * passing the resulting output to #psa_import_key, but
2892
- * if the implementation provides an isolation boundary then
2893
- * the key material is not exposed outside the isolation boundary.
2881
+ /** Generate a key deterministically from data read from a generator.
2882
+ *
2883
+ * This function uses the output of a generator to derive a key.
2884
+ * How much output it consumes and how the key is derived depends on the
2885
+ * key type.
2886
+ *
2887
+ * - For key types for which the key is an arbitrary sequence of bytes
2888
+ * of a given size,
2889
+ * this function is functionally equivalent to calling #psa_generator_read
2890
+ * and passing the resulting output to #psa_import_key.
2891
+ * However, this function has a security benefit:
2892
+ * if the implementation provides an isolation boundary then
2893
+ * the key material is not exposed outside the isolation boundary.
2894
+ * As a consequence, for these key types, this function always consumes
2895
+ * exactly (\p bits / 8) bytes from the generator.
2896
+ * The following key types defined in this specification follow this scheme:
2897
+ *
2898
+ * - #PSA_KEY_TYPE_AES;
2899
+ * - #PSA_KEY_TYPE_ARC4;
2900
+ * - #PSA_KEY_TYPE_CAMELLIA;
2901
+ * - #PSA_KEY_TYPE_DERIVE;
2902
+ * - #PSA_KEY_TYPE_HMAC.
2903
+ *
2904
+ * - For ECC keys on a Montgomery elliptic curve
2905
+ * (#PSA_KEY_TYPE_ECC_KEYPAIR(\c curve) where \c curve designates a
2906
+ * Montgomery curve), this function always draws a byte string whose
2907
+ * length is determined by the curve, and sets the mandatory bits
2908
+ * accordingly. That is:
2909
+ *
2910
+ * - #PSA_ECC_CURVE_CURVE25519: draw a 32-byte string
2911
+ * and process it as specified in RFC 7748 §5.
2912
+ * - #PSA_ECC_CURVE_CURVE448: draw a 56-byte string
2913
+ * and process it as specified in RFC 7748 §5.
2914
+ *
2915
+ * - For key types for which the key is represented by a single sequence of
2916
+ * \p bits bits with constraints as to which bit sequences are acceptable,
2917
+ * this function draws a byte string of length (\p bits / 8) bytes rounded
2918
+ * up to the nearest whole number of bytes. If the resulting byte string
2919
+ * is acceptable, it becomes the key, otherwise the drawn bytes are discarded.
2920
+ * This process is repeated until an acceptable byte string is drawn.
2921
+ * The byte string drawn from the generator is interpreted as specified
2922
+ * for the output produced by psa_export_key().
2923
+ * The following key types defined in this specification follow this scheme:
2924
+ *
2925
+ * - #PSA_KEY_TYPE_DES.
2926
+ * Force-set the parity bits, but discard forbidden weak keys.
2927
+ * For 2-key and 3-key triple-DES, the three keys are generated
2928
+ * successively (for example, for 3-key triple-DES,
2929
+ * if the first 8 bytes specify a weak key and the next 8 bytes do not,
2930
+ * discard the first 8 bytes, use the next 8 bytes as the first key,
2931
+ * and continue reading output from the generator to derive the other
2932
+ * two keys).
2933
+ * - Finite-field Diffie-Hellman keys (#PSA_KEY_TYPE_DH_KEYPAIR),
2934
+ * DSA keys (#PSA_KEY_TYPE_DSA_KEYPAIR), and
2935
+ * ECC keys on a Weierstrass elliptic curve
2936
+ * (#PSA_KEY_TYPE_ECC_KEYPAIR(\c curve) where \c curve designates a
2937
+ * Weierstrass curve).
2938
+ * For these key types, interpret the byte string as integer
2939
+ * in big-endian order. Discard it if it is not in the range
2940
+ * [0, *N* - 2] where *N* is the boundary of the private key domain
2941
+ * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA,
2942
+ * or the order of the curve's base point for ECC).
2943
+ * Add 1 to the resulting integer and use this as the private key *x*.
2944
+ * This method allows compliance to NIST standards, specifically
2945
+ * the methods titled "key-pair generation by testing candidates"
2946
+ * in NIST SP 800-56A §5.6.1.1.4 for Diffie-Hellman,
2947
+ * in FIPS 186-4 §B.1.2 for DSA, and
2948
+ * in NIST SP 800-56A §5.6.1.2.2 or
2949
+ * FIPS 186-4 §B.4.2 for elliptic curve keys.
2950
+ *
2951
+ * - For other key types, including #PSA_KEY_TYPE_RSA_KEYPAIR,
2952
+ * the way in which the generator output is consumed is
2953
+ * implementation-defined.
2954
+ *
2955
+ * In all cases, the data that is read is discarded from the generator.
2956
+ * The generator's capacity is decreased by the number of bytes read.
2894
2957
*
2895
2958
* \param handle Handle to the slot where the key will be stored.
2896
2959
* It must have been obtained by calling
2897
2960
* psa_allocate_key() or psa_create_key() and must
2898
2961
* not contain key material yet.
2899
2962
* \param type Key type (a \c PSA_KEY_TYPE_XXX value).
2900
- * This must be a symmetric key type.
2963
+ * This must be a secret key type or a key pair type.
2901
2964
* \param bits Key size in bits.
2902
2965
* \param[in,out] generator The generator object to read from.
2903
2966
*
@@ -2906,12 +2969,10 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator,
2906
2969
* If the key is persistent, the key material and the key's metadata
2907
2970
* have been saved to persistent storage.
2908
2971
* \retval #PSA_ERROR_INSUFFICIENT_CAPACITY
2909
- * There were fewer than \p output_length bytes
2910
- * in the generator. Note that in this case, no
2911
- * output is written to the output buffer.
2912
- * The generator's capacity is set to 0, thus
2913
- * subsequent calls to this function will not
2914
- * succeed, even with a smaller output buffer.
2972
+ * There was not enough data to create the desired key.
2973
+ * Note that in this case, no output is written to the output buffer.
2974
+ * The generator's capacity is set to 0, thus subsequent calls to
2975
+ * this function will not succeed, even with a smaller output buffer.
2915
2976
* \retval #PSA_ERROR_NOT_SUPPORTED
2916
2977
* The key type or key size is not supported, either by the
2917
2978
* implementation in general or in this particular slot.
@@ -3114,8 +3175,8 @@ psa_status_t psa_key_derivation_input_key(psa_crypto_generator_t *generator,
3114
3175
* psa_key_derivation_setup() with a
3115
3176
* key agreement and derivation algorithm
3116
3177
* \c alg (\c PSA_ALG_XXX value such that
3117
- * #PSA_ALG_IS_KEY_AGREEMENT(\p alg) is true
3118
- * and #PSA_ALG_IS_RAW_KEY_AGREEMENT(\p alg)
3178
+ * #PSA_ALG_IS_KEY_AGREEMENT(\c alg) is true
3179
+ * and #PSA_ALG_IS_RAW_KEY_AGREEMENT(\c alg)
3119
3180
* is false).
3120
3181
* The generator must be ready for an
3121
3182
* input of the type given by \p step.
0 commit comments