Skip to content

Commit dfe6582

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 08bbd13 commit dfe6582

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

include/psa/crypto.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,21 @@ psa_status_t psa_get_key_information(psa_key_handle_t handle,
387387
* g INTEGER
388388
* }
389389
* ```
390+
* - For Diffie-Hellman key exchange keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY), the
391+
* `DomainParameters` format as defined by RFC 3279 §2.3.3.
392+
* ```
393+
* DomainParameters ::= SEQUENCE {
394+
* p INTEGER, -- odd prime, p=jq +1
395+
* g INTEGER, -- generator, g
396+
* q INTEGER, -- factor of p-1
397+
* j INTEGER OPTIONAL, -- subgroup factor
398+
* validationParms ValidationParms OPTIONAL
399+
* }
400+
* ValidationParms ::= SEQUENCE {
401+
* seed BIT STRING,
402+
* pgenCounter INTEGER
403+
* }
404+
* ```
390405
*
391406
* \param handle Handle to the key to set domain parameters for.
392407
* \param[in] data Buffer containing the key domain parameters. The content
@@ -494,6 +509,10 @@ psa_status_t psa_get_key_domain_parameters(psa_key_handle_t handle,
494509
* and `PSA_ECC_CURVE_BRAINPOOL_PXXX`).
495510
* This is the content of the `privateKey` field of the `ECPrivateKey`
496511
* format defined by RFC 5915.
512+
* - For Diffie-Hellman key exchange key pairs (#PSA_KEY_TYPE_DH_KEYPAIR), the
513+
* format is the representation of the private key `x` as a big-endian byte
514+
* string. The length of the byte string is the private key size in bytes
515+
* (leading zeroes are not stripped).
497516
* - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is
498517
* true), the format is the same as for psa_export_public_key().
499518
*
@@ -565,6 +584,10 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
565584
* representation of the public key `y = g^x mod p` as a big-endian byte
566585
* string. The length of the byte string is the length of the base prime `p`
567586
* in bytes.
587+
* - For Diffie-Hellman key exchange public keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY),
588+
* the format is the representation of the public key `y = g^x mod p` as a
589+
* big-endian byte string. The length of the byte string is the length of the
590+
* base prime `p` in bytes.
568591
*
569592
* \param handle Handle to the key to export.
570593
* \param[out] data Buffer where the key data is to be written.
@@ -2302,6 +2325,12 @@ typedef struct {
23022325
* parameters. The key domain parameters can also be
23032326
* provided by psa_set_key_domain_parameters(),
23042327
* which documents the format of the structure.
2328+
* - For a DH key (\p type is
2329+
* #PSA_KEY_TYPE_DH_KEYPAIR), the \p extra is an
2330+
* optional structure specifying the key domain
2331+
* parameters. The key domain parameters can also be
2332+
* provided by psa_set_key_domain_parameters(),
2333+
* which documents the format of the structure.
23052334
* \param extra_size Size of the buffer that \p extra
23062335
* points to, in bytes. Note that if \p extra is
23072336
* \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)