{
const char *name;
ecc_curve_t id;
+ int tls_id; /* The RFC4492 namedCurve ID */
int size; /* the size in bytes */
/** The prime that defines the field the curve is in (encoded in hex) */
const gnutls_ecc_curve_entry_st * _gnutls_ecc_curve_get_params (ecc_curve_t curve);
int _gnutls_ecc_curve_get_size (ecc_curve_t curve);
ecc_curve_t _gnutls_ecc_curve_get_id (const char *name);
+int _gnutls_tls_id_to_ecc_curve (int num);
+int _gnutls_ecc_curve_get_tls_id (ecc_curve_t supported_ecc);
#endif
const char *ret = NULL;
/* avoid prefix */
- GNUTLS_CIPHER_SUITE_LOOP (if (kx_algorithm == p->kx_algorithm &&
- cipher_algorithm == p->block_algorithm &&
- mac_algorithm == p->mac_algorithm)
- ret = p->name + sizeof ("GNUTLS_") - 1);
+ GNUTLS_CIPHER_SUITE_LOOP (
+ if (kx_algorithm == p->kx_algorithm &&
+ cipher_algorithm == p->block_algorithm && mac_algorithm == p->mac_algorithm)
+ {
+ ret = p->name + sizeof ("GNUTLS_") - 1);
+ break;
+ }
return ret;
}
{
.name = "SECP224R1",
.id = GNUTLS_ECC_CURVE_SECP224R1,
+ .tls_id = 21,
.size = 28,
.prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
.A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
{
.name = "SECP256R1",
.id = GNUTLS_ECC_CURVE_SECP256R1,
+ .tls_id = 23,
.size = 32,
.prime = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
.A = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC",
{
.name = "SECP384R1",
.id = GNUTLS_ECC_CURVE_SECP384R1,
+ .tls_id = 24,
.size = 48,
.prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF",
.A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC",
{
.name = "SECP521R1",
.id = GNUTLS_ECC_CURVE_SECP521R1,
+ .tls_id = 25,
.size = 66,
.prime = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
.A = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
#define GNUTLS_ECC_CURVE_LOOP(b) \
{ const gnutls_ecc_curve_entry_st *p; \
for(p = ecc_curves; p->name != NULL; p++) { b ; } }
+
+
+/* Returns the TLS id of the given curve
+ */
+int
+_gnutls_tls_id_to_ecc_curve (int num)
+{
+ ecc_curve_t ret = GNUTLS_ECC_CURVE_INVALID;
+
+ GNUTLS_ECC_CURVE_LOOP (
+ if (p->tls_id == num)
+ {
+ ret = p->id;
+ break;
+ }
+ );
+
+ return ret;
+}
+
+/* Maps numbers to TLS NamedCurve IDs (RFC4492).
+ * Returns a negative number on error.
+ */
+int
+_gnutls_ecc_curve_get_tls_id (ecc_curve_t supported_ecc)
+{
+ int ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
+
+ GNUTLS_ECC_CURVE_LOOP (
+ if (p->id == supported_ecc)
+ {
+ ret = p->tls_id;
+ break;
+ }
+ );
+
+ return ret;
+}
+
+
/*-
* _gnutls_ecc_curve_get_id:
* @name: is a MAC algorithm name
return gnutls_assert_val(GNUTLS_E_ECC_NO_SUPPORTED_CURVES);
DECR_LEN (data_size, 2);
- curve = _gnutls_num_to_ecc(_gnutls_read_uint16 (&data[i]));
+ curve = _gnutls_tls_id_to_ecc_curve(_gnutls_read_uint16 (&data[i]));
i += 2;
ret = _gnutls_session_supports_ecc_curve(session, curve);
if (ret < 0)
return gnutls_assert_val(ret);
- ret = _gnutls_buffer_append_prefix(data, 16, _gnutls_ecc_to_num(curve));
+ ret = _gnutls_buffer_append_prefix(data, 16, _gnutls_ecc_curve_get_tls_id(curve));
if (ret < 0)
return gnutls_assert_val(ret);
#include <ext/ecc.h>
#include <gnutls_state.h>
#include <gnutls_num.h>
+#include <algorithms.h>
/* Maps record size to numbers according to the
* extensions draft.
for (i = 0; i < len; i+=2)
{
- new_type = _gnutls_num_to_ecc (_gnutls_read_uint16(&p[i]));
+ new_type = _gnutls_tls_id_to_ecc_curve (_gnutls_read_uint16(&p[i]));
if (new_type < 0)
continue;
for (i = 0; i < len; i++)
{
p =
- _gnutls_ecc_to_num (session->internals.priorities.
+ _gnutls_ecc_curve_get_tls_id (session->internals.priorities.
supported_ecc.priority[i]);
ret = _gnutls_buffer_append_prefix(extdata, 16, p);
if (ret < 0)
return 2;
}
-/* Maps numbers to record sizes according to the
- * extensions draft.
- */
-int
-_gnutls_num_to_ecc (int num)
-{
- switch (num)
- {
- case 23:
- /* sec256r1 */
- return GNUTLS_ECC_CURVE_SECP256R1;
- case 24:
- return GNUTLS_ECC_CURVE_SECP384R1;
- default:
- return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
- }
-}
-
-/* Maps record size to numbers according to the
- * extensions draft.
- */
-int
-_gnutls_ecc_to_num (ecc_curve_t supported_ecc)
-{
- switch (supported_ecc)
- {
- case GNUTLS_ECC_CURVE_SECP256R1:
- return 23;
- case GNUTLS_ECC_CURVE_SECP384R1:
- return 24;
- default:
- return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
- }
-}
/* Returns 0 if the given ECC curve is allowed in the current
* session. A negative error value is returned otherwise.
extern extension_entry_st ext_mod_supported_ecc;
extern extension_entry_st ext_mod_supported_ecc_pf;
-int _gnutls_num_to_ecc (int num);
-int _gnutls_ecc_to_num (ecc_curve_t);
int
_gnutls_session_supports_ecc_curve (gnutls_session_t session, int ecc_type);