1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

common:kem: Factor out a function to retrieve ECC parameters.

* common/util.h (struct gnupg_ecc_params, gnupg_get_ecc_params): New.
(ECC_SCALAR_LEN_MAX, ECC_POINT_LEN_MAX, ECC_HASH_LEN_MAX): New.
* agent/pkdecrypt.c (ecc_extract_pk_from_key, ecc_extract_sk_from_key):
Follow the change of gnupg_get_ecc_params.
(ecc_raw_kem, ecc_pgp_kem_decap, composite_pgp_kem_decrypt): Likewise.
(ecc_kem_decrypt): Likewise.
(get_ecc_params): Move to...
* common/kem.c (gnupg_get_ecc_params): ... here
* g10/pkglue.c (ECC_POINT_LEN_MAX, ECC_HASH_LEN_MAX): Remove duplicates.

--

GnuPG-bug-id: 7649
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2025-07-03 15:45:52 +09:00
parent a354018bf3
commit 5e623b71d5
No known key found for this signature in database
GPG key ID: 640114AF89DE6054
4 changed files with 104 additions and 112 deletions

View file

@ -35,7 +35,7 @@
#include <gpg-error.h>
#include <gcrypt.h>
#include "mischelp.h"
#include "util.h"
/* domSeperation as per *PGP specs. */
#define KMAC_KEY "OpenPGPCompositeKeyDerivationFunction"
@ -248,3 +248,72 @@ gnupg_kem_combiner (void *kek, size_t kek_len,
KMAC_CUSTOM, strlen (KMAC_CUSTOM), iov, 6);
return err;
}
#define ECC_CURVE25519_INDEX 0
static const struct gnupg_ecc_params ecc_table[] =
{
{
"Curve25519",
33, 32, 32,
GCRY_MD_SHA3_256, GCRY_KEM_RAW_X25519,
1, 1
},
{
"X448",
56, 56, 56,
GCRY_MD_SHA3_512, GCRY_KEM_RAW_X448,
0, 0
},
{
"NIST P-256",
65, 32, 65,
GCRY_MD_SHA3_256, GCRY_KEM_RAW_P256R1,
0, 0
},
{
"NIST P-384",
97, 48, 97,
GCRY_MD_SHA3_512, GCRY_KEM_RAW_P384R1,
0, 0
},
{
"NIST P-521",
133, 66, 133,
GCRY_MD_SHA3_512, GCRY_KEM_RAW_P521R1,
0, 0
},
{
"brainpoolP256r1",
65, 32, 65,
GCRY_MD_SHA3_256, GCRY_KEM_RAW_BP256,
0, 0
},
{
"brainpoolP384r1",
97, 48, 97,
GCRY_MD_SHA3_512, GCRY_KEM_RAW_BP384,
0, 0
},
{
"brainpoolP512r1",
129, 64, 129,
GCRY_MD_SHA3_512, GCRY_KEM_RAW_BP512,
0, 0
},
{ NULL, 0, 0, 0, 0, 0, 0, 0 }
};
/* Return the ECC parameters for CURVE. CURVE is expected to be the
* canonical name. */
const struct gnupg_ecc_params *
gnupg_get_ecc_params (const char *curve)
{
int i;
for (i = 0; ecc_table[i].curve; i++)
if (!strcmp (ecc_table[i].curve, curve))
return &ecc_table[i];
return NULL;
}