#include <algorithms.h>
#include <gnutls_errors.h>
#include <x509/common.h>
-
+#include <gnutls_pk.h>
/* Supported ECC curves
*/
.id = GNUTLS_ECC_CURVE_SECP192R1,
.tls_id = 19,
.size = 24,
- },
+ },
{
.name = "SECP224R1",
.oid = "1.3.132.0.33",
.id = GNUTLS_ECC_CURVE_SECP224R1,
.tls_id = 21,
.size = 28,
- },
+ },
{
.name = "SECP256R1",
.oid = "1.2.840.10045.3.1.7",
.id = GNUTLS_ECC_CURVE_SECP256R1,
.tls_id = 23,
.size = 32,
- },
+ },
{
.name = "SECP384R1",
.oid = "1.3.132.0.34",
.id = GNUTLS_ECC_CURVE_SECP384R1,
.tls_id = 24,
.size = 48,
- },
+ },
{
.name = "SECP521R1",
.oid = "1.3.132.0.35",
.id = GNUTLS_ECC_CURVE_SECP521R1,
.tls_id = 25,
.size = 66,
- },
+ },
{0, 0, 0}
};
{
gnutls_ecc_curve_t ret = GNUTLS_ECC_CURVE_INVALID;
- GNUTLS_ECC_CURVE_LOOP(if (p->tls_id == num) {
- ret = p->id; break;}
+ GNUTLS_ECC_CURVE_LOOP(
+ if (p->tls_id == num && _gnutls_pk_curve_exists(p->id)) {
+ ret = p->id;
+ break;
+ }
);
return ret;
if (supported_curves[0] == 0) {
int i = 0;
- GNUTLS_ECC_CURVE_LOOP(supported_curves[i++] = p->id;);
+ GNUTLS_ECC_CURVE_LOOP(
+ if (_gnutls_pk_curve_exists(p->id))
+ supported_curves[i++] = p->id;
+ );
supported_curves[i++] = 0;
}
gnutls_ecc_curve_t ret = GNUTLS_ECC_CURVE_INVALID;
GNUTLS_ECC_CURVE_LOOP(
- if (strcasecmp(p->oid, oid) == 0) {
+ if (strcasecmp(p->oid, oid) == 0 && _gnutls_pk_curve_exists(p->id)) {
ret = p->id;
break;
}
gnutls_ecc_curve_t ret = GNUTLS_ECC_CURVE_INVALID;
GNUTLS_ECC_CURVE_LOOP(
- if (strcasecmp(p->name, name) == 0) {
+ if (strcasecmp(p->name, name) == 0 && _gnutls_pk_curve_exists(p->id)) {
ret = p->id;
break;
}
gnutls_ecc_curve_t ret = GNUTLS_ECC_CURVE_SECP224R1;
GNUTLS_ECC_CURVE_LOOP(
- if (8 * p->size >= bits) {
+ if (8 * p->size >= bits && _gnutls_pk_curve_exists(p->id)) {
ret = p->id;
break;
}
const gnutls_pk_params_st * priv,
const gnutls_pk_params_st * pub);
-
+ int (*curve_exists) (gnutls_ecc_curve_t); /* true/false */
} gnutls_crypto_pk_st;
/* priority: infinity for backend algorithms, 90 for kernel
#define _gnutls_pk_generate_keys( algo, bits, priv) _gnutls_pk_ops.generate_keys( algo, bits, priv)
#define _gnutls_pk_generate_params( algo, bits, priv) _gnutls_pk_ops.generate_params( algo, bits, priv)
#define _gnutls_pk_hash_algorithm( pk, sig, params, hash) _gnutls_pk_ops.hash_algorithm(pk, sig, params, hash)
+#define _gnutls_pk_curve_exists( curve) _gnutls_pk_ops.curve_exists(curve)
inline static int
_gnutls_pk_fixup(gnutls_pk_algorithm_t algo, gnutls_direction_t direction,
}
}
+static int _wrap_nettle_pk_curve_exists(gnutls_ecc_curve_t curve)
+{
+ return ((get_supported_curve(curve)!=NULL)?1:0);
+}
+
/* Generates algorithm's parameters. That is:
* For DSA: p, q, and g are generated.
* For RSA: nothing
.generate_keys = wrap_nettle_pk_generate_keys,
.pk_fixup_private_params = wrap_nettle_pk_fixup,
.derive = _wrap_nettle_pk_derive,
+ .curve_exists = _wrap_nettle_pk_curve_exists,
};