Skip to content

Commit 693b4c4

Browse files
committed
psa: Add DH key exchange keys
Add the ability to specify Diffie-Hellman key exchange keys. Specify the import/export format as well, even though importing and exporting isn't implemented yet.
1 parent 42b366a commit 693b4c4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/psa/crypto.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,21 @@ psa_status_t psa_get_key_information(psa_key_handle_t handle,
381381
* g INTEGER
382382
* }
383383
* ```
384+
* - For Diffie-Hellman key exchange keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY), the
385+
* `DomainParameters` format as defined by RFC 3279 §2.3.3.
386+
* ```
387+
* DomainParameters ::= SEQUENCE {
388+
* p INTEGER, -- odd prime, p=jq +1
389+
* g INTEGER, -- generator, g
390+
* q INTEGER, -- factor of p-1
391+
* j INTEGER OPTIONAL, -- subgroup factor
392+
* validationParms ValidationParms OPTIONAL
393+
* }
394+
* ValidationParms ::= SEQUENCE {
395+
* seed BIT STRING,
396+
* pgenCounter INTEGER
397+
* }
398+
* ```
384399
* Must call before import key. If you want, you can call before generate key
385400
* or use extra to pass the domain parameters.
386401
*
@@ -446,6 +461,9 @@ psa_status_t psa_get_key_domain_parameters(uint8_t *data,
446461
* and `PSA_ECC_CURVE_BRAINPOOL_PXXX`).
447462
* This is the content of the `privateKey` field of the `ECPrivateKey`
448463
* format defined by RFC 5915.
464+
* - For Diffie-Hellman key exchange key pairs (#PSA_KEY_TYPE_DH_KEYPAIR), the
465+
* format is a representation of the private key `x` as a big-endian byte
466+
* string.
449467
* - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is
450468
* true), the format is the same as for psa_export_public_key().
451469
*
@@ -519,6 +537,9 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
519537
* -- where `m` is the bit size associated with the curve,
520538
* -- i.e. the bit size of `q` for a curve over `F_q`.
521539
* ```
540+
* - For Diffie-Hellman key exchange public keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY),
541+
* the format is a representation of the public key `y` (`g^x mod p`) as a
542+
* big-endian byte string.
522543
*
523544
* \param handle Handle to the key to export.
524545
* \param[out] data Buffer where the key data is to be written.
@@ -2256,6 +2277,12 @@ typedef struct {
22562277
* parameters. The key domain parameters can also be
22572278
* provided by psa_set_key_domain_parameters(),
22582279
* which documents the format of the structure.
2280+
* - For a DH key (\p type is
2281+
* #PSA_KEY_TYPE_DH_KEYPAIR), the \p extra is an
2282+
* optional structure specifying the key domain
2283+
* parameters. The key domain parameters can also be
2284+
* provided by psa_set_key_domain_parameters(),
2285+
* which documents the format of the structure.
22592286
* \param extra_size Size of the buffer that \p extra
22602287
* points to, in bytes. Note that if \p extra is
22612288
* \c NULL then \p extra_size must be zero.

include/psa/crypto_values.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@
497497
#define PSA_ECC_CURVE_CURVE25519 ((psa_ecc_curve_t) 0x001d)
498498
#define PSA_ECC_CURVE_CURVE448 ((psa_ecc_curve_t) 0x001e)
499499

500+
/** Diffie-Hellman key exchange public key. */
501+
#define PSA_KEY_TYPE_DH_PUBLIC_KEY ((psa_key_type_t)0x60040000)
502+
/** Diffie-Hellman key exchange key pair (private and public key). */
503+
#define PSA_KEY_TYPE_DH_KEYPAIR ((psa_key_type_t)0x70040000)
504+
/** Whether a key type is a Diffie-Hellman key exchange key (pair or
505+
* public-only). */
506+
#define PSA_KEY_TYPE_IS_DH(type) \
507+
(PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_DH_PUBLIC_KEY)
508+
500509
/** The block size of a block cipher.
501510
*
502511
* \param type A cipher key type (value of type #psa_key_type_t).

0 commit comments

Comments
 (0)