diff options
| author | NIIBE Yutaka <[email protected]> | 2025-05-21 05:44:16 +0000 |
|---|---|---|
| committer | NIIBE Yutaka <[email protected]> | 2025-05-21 05:49:56 +0000 |
| commit | 57a3d2392539167767578dbb1414ad1cfb2a84ab (patch) | |
| tree | ea5874238421a1bdc3c411e3f68c469fcb1bcb96 /common/kem.c | |
| parent | doc: Add a note to READ on how to disable the systemd activation. (diff) | |
| download | gnupg-57a3d2392539167767578dbb1414ad1cfb2a84ab.tar.gz gnupg-57a3d2392539167767578dbb1414ad1cfb2a84ab.zip | |
agent: Support ECC KEM by PKDECRYPT --kem.
* common/kem.c (gnupg_ecc_kem_kdf): Support traditional KDF of RFC
6637.
* common/util.h (gnupg_ecc_kem_kdf): Add FIXED_INFO argument.
* g10/pkglue.c (do_encrypt_kem): Follow the change.
* agent/pkdecrypt.c (ecc_pgp_kem_decap): Return ECC parameters.
(composite_pgp_kem_decrypt): Follow the changes.
(ecc_kem_decrypt): New.
(agent_kem_decrypt): Support ECC KEM.
--
GnuPG-bug-id: 7649
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'common/kem.c')
| -rw-r--r-- | common/kem.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/common/kem.c b/common/kem.c index bbb450e1b..fc5575f4f 100644 --- a/common/kem.c +++ b/common/kem.c @@ -150,24 +150,50 @@ gpg_error_t gnupg_ecc_kem_kdf (void *kek, size_t kek_len, int hashalgo, const void *ecdh, size_t ecdh_len, const void *ecc_ct, size_t ecc_ct_len, - const void *ecc_pk, size_t ecc_pk_len) + const void *ecc_pk, size_t ecc_pk_len, + gcry_buffer_t *fixed_info) { - gcry_buffer_t iov[3]; - unsigned int dlen; + if (fixed_info) + { + /* Traditional ECC */ + gpg_error_t err; + gcry_kdf_hd_t hd; + unsigned long param[1]; - dlen = gcry_md_get_algo_dlen (hashalgo); - if (kek_len != dlen) - return gpg_error (GPG_ERR_INV_LENGTH); + param[0] = kek_len; + err = gcry_kdf_open (&hd, GCRY_KDF_ONESTEP_KDF, hashalgo, param, 1, + ecdh, ecdh_len, NULL, 0, NULL, 0, + (char *)fixed_info->data+fixed_info->off, + fixed_info->len); + if (!err) + { + gcry_kdf_compute (hd, NULL); + gcry_kdf_final (hd, kek_len, kek); + gcry_kdf_close (hd); + } - memset (iov, 0, sizeof (iov)); + return err; + } + else + { + /* ECC in composite KEM */ + gcry_buffer_t iov[3]; + unsigned int dlen; + + dlen = gcry_md_get_algo_dlen (hashalgo); + if (kek_len != dlen) + return gpg_error (GPG_ERR_INV_LENGTH); - iov[0].data = (unsigned char *)ecdh; - iov[0].len = ecdh_len; - iov[1].data = (unsigned char *)ecc_ct; - iov[1].len = ecc_ct_len; - iov[2].data = (unsigned char *)ecc_pk; - iov[2].len = ecc_pk_len; - gcry_md_hash_buffers (hashalgo, 0, kek, iov, 3); + memset (iov, 0, sizeof (iov)); + + iov[0].data = (unsigned char *)ecdh; + iov[0].len = ecdh_len; + iov[1].data = (unsigned char *)ecc_ct; + iov[1].len = ecc_ct_len; + iov[2].data = (unsigned char *)ecc_pk; + iov[2].len = ecc_pk_len; + gcry_md_hash_buffers (hashalgo, 0, kek, iov, 3); + } return 0; } |
