]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
lib/algorithms: add modern ecdh functions comparable to curve_is_eddsa
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 7 May 2021 23:34:59 +0000 (19:34 -0400)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 17 Sep 2021 20:33:07 +0000 (16:33 -0400)
This is useful for the so-called CFRG curves used in ECDH, x25519 and x448.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
lib/algorithms.h

index 7a051b6365907f87a5ea57e62b609b5e3d6f0ee4..5172bd2784a38942fea90f24e83fd546cf54dab8 100644 (file)
@@ -475,12 +475,28 @@ inline static int _curve_is_eddsa(const gnutls_ecc_curve_entry_st * e)
        return 0;
 }
 
+inline static int _curve_is_modern_ecdh(const gnutls_ecc_curve_entry_st * e)
+{
+       if (unlikely(e == NULL))
+               return 0;
+       if (e->pk == GNUTLS_PK_ECDH_X25519 ||
+           e->pk == GNUTLS_PK_ECDH_X448)
+               return 1;
+       return 0;
+}
+
 inline static int curve_is_eddsa(gnutls_ecc_curve_t id)
 {
        const gnutls_ecc_curve_entry_st *e = _gnutls_ecc_curve_get_params(id);
        return _curve_is_eddsa(e);
 }
 
+inline static int curve_is_modern_ecdh(gnutls_ecc_curve_t id)
+{
+       const gnutls_ecc_curve_entry_st *e = _gnutls_ecc_curve_get_params(id);
+       return _curve_is_modern_ecdh(e);
+}
+
 static inline int _gnutls_kx_is_ecc(gnutls_kx_algorithm_t kx)
 {
        if (kx == GNUTLS_KX_ECDHE_RSA || kx == GNUTLS_KX_ECDHE_ECDSA ||