Skip to content

Commit 8edf779

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 5851f48 commit 8edf779

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[in] data Buffer containing the key domain parameters. The content
392407
* of this buffer is interpreted according to \p type. of
@@ -492,6 +507,10 @@ psa_status_t psa_get_key_domain_parameters(psa_key_handle_t handle,
492507
* and `PSA_ECC_CURVE_BRAINPOOL_PXXX`).
493508
* This is the content of the `privateKey` field of the `ECPrivateKey`
494509
* format defined by RFC 5915.
510+
* - For Diffie-Hellman key exchange key pairs (#PSA_KEY_TYPE_DH_KEYPAIR), the
511+
* format is the representation of the private key `x` as a big-endian byte
512+
* string. The length of the byte string is the private key size in bytes
513+
* (leading zeroes are not stripped).
495514
* - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is
496515
* true), the format is the same as for psa_export_public_key().
497516
*
@@ -563,6 +582,10 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
563582
* representation of the public key `y = g^x mod p` as a big-endian byte
564583
* string. The length of the byte string is the length of the base prime `p`
565584
* in bytes.
585+
* - For Diffie-Hellman key exchange public keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY),
586+
* the format is the representation of the public key `y = g^x mod p` as a
587+
* big-endian byte string. The length of the byte string is the length of the
588+
* base prime `p` in bytes.
566589
*
567590
* \param handle Handle to the key to export.
568591
* \param[out] data Buffer where the key data is to be written.
@@ -2300,6 +2323,12 @@ typedef struct {
23002323
* parameters. The key domain parameters can also be
23012324
* provided by psa_set_key_domain_parameters(),
23022325
* which documents the format of the structure.
2326+
* - For a DH key (\p type is
2327+
* #PSA_KEY_TYPE_DH_KEYPAIR), the \p extra is an
2328+
* optional structure specifying the key domain
2329+
* parameters. The key domain parameters can also be
2330+
* provided by psa_set_key_domain_parameters(),
2331+
* which documents the format of the structure.
23032332
* \param extra_size Size of the buffer that \p extra
23042333
* points to, in bytes. Note that if \p extra is
23052334
* \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)