]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
x509: handle X25519 and X448 in read_pubkey
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Sat, 8 May 2021 01:53:47 +0000 (21:53 -0400)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 17 Sep 2021 20:33:07 +0000 (16:33 -0400)
_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>
lib/x509/key_decode.c

index ea241163b99d26a73f3cc1bdb75c9a9ad9fa4e77..44e4297db0e067a2c5f4197cae1088d7eeb5e3cf 100644 (file)
@@ -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: