@@ -448,8 +448,32 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
448
448
* The output of this function can be passed to psa_import_key() to
449
449
* create an object that is equivalent to the public key.
450
450
*
451
- * The format is the DER representation defined by RFC 5280 as
452
- * `SubjectPublicKeyInfo`, with the `subjectPublicKey` format
451
+ * This specification supports a single format for each key type.
452
+ * Implementations may support other formats as long as the standard
453
+ * format is supported. Implementations that support other formats
454
+ * should ensure that the formats are clearly unambiguous so as to
455
+ * minimize the risk that an invalid input is accidentally interpreted
456
+ * according to a different format.
457
+ *
458
+ * For standard key types, the output format is as follows:
459
+ * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the DER encoding of
460
+ * the representation defined by RFC 3279 §2.3.1 as `RSAPublicKey`.
461
+ * ```
462
+ * RSAPublicKey ::= SEQUENCE {
463
+ * modulus INTEGER, -- n
464
+ * publicExponent INTEGER } -- e
465
+ * ```
466
+ * - For elliptic curve public keys (key types for which
467
+ * #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true), the format is the uncompressed
468
+ * representation defined by SEC1 §2.3.3 as the content of an ECPoint:
469
+ * Let `m` be the bit size associated with the curve, i.e. the bit size of
470
+ * `q` for a curve over `F_q`. The representation consists of:
471
+ * - The byte 0x04;
472
+ * - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
473
+ * - `y_P` as a `ceiling(m/8)`-byte string, big-endian.
474
+ *
475
+ * For other public key types, the format is the DER representation defined by
476
+ * RFC 5280 as `SubjectPublicKeyInfo`, with the `subjectPublicKey` format
453
477
* specified below.
454
478
* ```
455
479
* SubjectPublicKeyInfo ::= SEQUENCE {
@@ -459,21 +483,6 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
459
483
* algorithm OBJECT IDENTIFIER,
460
484
* parameters ANY DEFINED BY algorithm OPTIONAL }
461
485
* ```
462
- *
463
- * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY),
464
- * the `subjectPublicKey` format is defined by RFC 3279 §2.3.1 as
465
- * `RSAPublicKey`,
466
- * with the OID `rsaEncryption`,
467
- * and with the parameters `NULL`.
468
- * ```
469
- * pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
470
- * rsadsi(113549) pkcs(1) 1 }
471
- * rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 }
472
- *
473
- * RSAPublicKey ::= SEQUENCE {
474
- * modulus INTEGER, -- n
475
- * publicExponent INTEGER } -- e
476
- * ```
477
486
* - For DSA public keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY),
478
487
* the `subjectPublicKey` format is defined by RFC 3279 §2.3.2 as
479
488
* `DSAPublicKey`,
@@ -489,30 +498,6 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
489
498
* g INTEGER }
490
499
* DSAPublicKey ::= INTEGER -- public key, Y
491
500
* ```
492
- * - For elliptic curve public keys (key types for which
493
- * #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true),
494
- * the `subjectPublicKey` format is defined by RFC 3279 §2.3.5 as
495
- * `ECPoint`, which contains the uncompressed
496
- * representation defined by SEC1 §2.3.3.
497
- * The OID is `id-ecPublicKey`,
498
- * and the parameters must be given as a `namedCurve` OID as specified in
499
- * RFC 5480 §2.1.1.1 or other applicable standards.
500
- * ```
501
- * ansi-X9-62 OBJECT IDENTIFIER ::=
502
- * { iso(1) member-body(2) us(840) 10045 }
503
- * id-public-key-type OBJECT IDENTIFIER ::= { ansi-X9.62 2 }
504
- * id-ecPublicKey OBJECT IDENTIFIER ::= { id-publicKeyType 1 }
505
- *
506
- * ECPoint ::= ...
507
- * -- first 8 bits: 0x04;
508
- * -- then x_P as a `ceiling(m/8)`-byte string, big endian;
509
- * -- then y_P as a `ceiling(m/8)`-byte string, big endian;
510
- * -- where `m` is the bit size associated with the curve,
511
- * -- i.e. the bit size of `q` for a curve over `F_q`.
512
- *
513
- * EcpkParameters ::= CHOICE { -- other choices are not allowed
514
- * namedCurve OBJECT IDENTIFIER }
515
- * ```
516
501
*
517
502
* \param handle Handle to the key to export.
518
503
* \param[out] data Buffer where the key data is to be written.
@@ -2156,19 +2141,28 @@ psa_status_t psa_key_derivation(psa_crypto_generator_t *generator,
2156
2141
* The resulting generator always has the maximum capacity permitted by
2157
2142
* the algorithm.
2158
2143
*
2159
- * \param[in,out] generator The generator object to set up. It must have
2160
- * been initialized as per the documentation for
2161
- * #psa_crypto_generator_t and not yet in use.
2162
- * \param private_key Handle to the private key to use.
2163
- * \param[in] peer_key Public key of the peer. It must be
2164
- * in the same format that psa_import_key()
2165
- * accepts. The standard formats for public
2166
- * keys are documented in the documentation
2167
- * of psa_export_public_key().
2168
- * \param peer_key_length Size of \p peer_key in bytes.
2169
- * \param alg The key agreement algorithm to compute
2170
- * (\c PSA_ALG_XXX value such that
2171
- * #PSA_ALG_IS_KEY_AGREEMENT(\p alg) is true).
2144
+ * \param[in,out] generator The generator object to set up. It must have been
2145
+ * initialized as per the documentation for
2146
+ * #psa_crypto_generator_t and not yet in use.
2147
+ * \param private_key Handle to the private key to use.
2148
+ * \param[in] peer_key Public key of the peer. The peer key must be in the
2149
+ * same format that psa_import_key() accepts for the
2150
+ * public key type corresponding to the type of
2151
+ * \p private_key. That is, this function performs the
2152
+ * equivalent of
2153
+ * `psa_import_key(internal_public_key_handle,
2154
+ * PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(private_key_type),
2155
+ * peer_key, peer_key_length)` where
2156
+ * `private_key_type` is the type of \p private_key.
2157
+ * For example, for EC keys, this means that \p
2158
+ * peer_key is interpreted as a point on the curve
2159
+ * that the private key is associated with. The
2160
+ * standard formats for public keys are documented in
2161
+ * the documentation of psa_export_public_key().
2162
+ * \param peer_key_length Size of \p peer_key in bytes.
2163
+ * \param alg The key agreement algorithm to compute
2164
+ * (\c PSA_ALG_XXX value such that
2165
+ * #PSA_ALG_IS_KEY_AGREEMENT(\p alg) is true).
2172
2166
*
2173
2167
* \retval #PSA_SUCCESS
2174
2168
* Success.
0 commit comments