summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-05-07 21:53:47 -0400
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-09-17 16:33:07 -0400
commitd6bb88cd7a84874da10fa493841244aad6eae863 (patch)
treef20999859d212bb1fe9a0b54a173eb28270dabf5
parentc605e559e890ce77ec033a6c1cad819f266401a8 (diff)
downloadgnutls-d6bb88cd7a84874da10fa493841244aad6eae863.tar.gz
x509: handle X25519 and X448 in read_pubkey
_gnutls_x509_read_ecdh_pubkey is basically a clone of _gnutls_x509_read_eddsa_pubkey. Another form of implementation would be to collapse these two static functions into a common function for all "CFRG" curves. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
-rw-r--r--lib/x509/key_decode.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/x509/key_decode.c b/lib/x509/key_decode.c
index ea241163b9..44e4297db0 100644
--- a/lib/x509/key_decode.c
+++ b/lib/x509/key_decode.c
@@ -41,6 +41,9 @@ static int _gnutls_x509_read_ecc_pubkey(uint8_t * der, int dersize,
static int _gnutls_x509_read_eddsa_pubkey(gnutls_ecc_curve_t curve,
uint8_t * der, int dersize,
gnutls_pk_params_st * params);
+static int _gnutls_x509_read_ecdh_pubkey(gnutls_ecc_curve_t curve,
+ uint8_t * der, int dersize,
+ gnutls_pk_params_st * params);
static int _gnutls_x509_read_gost_pubkey(uint8_t * der, int dersize,
gnutls_pk_params_st * params);
@@ -125,6 +128,17 @@ int _gnutls_x509_read_eddsa_pubkey(gnutls_ecc_curve_t curve,
return _gnutls_set_datum(&params->raw_pub, der, dersize);
}
+int _gnutls_x509_read_ecdh_pubkey(gnutls_ecc_curve_t curve,
+ uint8_t * der, int dersize,
+ gnutls_pk_params_st * params)
+{
+ int size = gnutls_ecc_curve_get_size(curve);
+ if (dersize != size)
+ return gnutls_assert_val(GNUTLS_E_ILLEGAL_PARAMETER);
+
+ return _gnutls_set_datum(&params->raw_pub, der, dersize);
+}
+
/* Pubkey is a concatenation of X (in little endian) and Y (also LE)
* encoded into OCTET STRING. */
static int
@@ -564,6 +578,12 @@ int _gnutls_x509_read_pubkey(gnutls_pk_algorithm_t algo, uint8_t * der,
case GNUTLS_PK_EDDSA_ED448:
ret = _gnutls_x509_read_eddsa_pubkey(GNUTLS_ECC_CURVE_ED448, der, dersize, params);
break;
+ case GNUTLS_PK_ECDH_X25519:
+ ret = _gnutls_x509_read_ecdh_pubkey(GNUTLS_ECC_CURVE_X25519, der, dersize, params);
+ break;
+ case GNUTLS_PK_ECDH_X448:
+ ret = _gnutls_x509_read_ecdh_pubkey(GNUTLS_ECC_CURVE_X448, der, dersize, params);
+ break;
case GNUTLS_PK_GOST_01:
case GNUTLS_PK_GOST_12_256:
case GNUTLS_PK_GOST_12_512: