]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Curve TLS ID is being stored in algorithms/ecc.c.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 May 2011 17:08:55 +0000 (19:08 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 May 2011 17:08:55 +0000 (19:08 +0200)
lib/algorithms.h
lib/algorithms/ciphersuites.c
lib/algorithms/ecc.c
lib/auth/ecdh_common.c
lib/ext/ecc.c
lib/ext/ecc.h

index 48770762843a267c04360776a9389202eed969cb..5d7d7fa24885736adc942025a9da3faa318e9253 100644 (file)
@@ -130,6 +130,7 @@ struct gnutls_ecc_curve_entry_st
 {
   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) */
@@ -151,5 +152,7 @@ const char * _gnutls_ecc_curve_get_name (ecc_curve_t curve);
 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
index 050d9646bb35d9f9df04afb2e20a2d8d76e9974a..6b7f4eb4b1e672580757b11e29d4500db643077d 100644 (file)
@@ -615,10 +615,13 @@ gnutls_cipher_suite_get_name (gnutls_kx_algorithm_t kx_algorithm,
   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;
 }
index 66174e6b75b5e3b2c68dab5887c16bbddb20d239..4bd2a130ba2b5ffdcdb047ba7bbe914181b1ddec 100644 (file)
@@ -35,6 +35,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = {
   {
     .name = "SECP224R1", 
     .id = GNUTLS_ECC_CURVE_SECP224R1,
+    .tls_id = 21,
     .size = 28,
     .prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
     .A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
@@ -46,6 +47,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = {
   {
     .name = "SECP256R1", 
     .id = GNUTLS_ECC_CURVE_SECP256R1,
+    .tls_id = 23,
     .size = 32,
     .prime = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
     .A = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC",
@@ -57,6 +59,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = {
   {
     .name = "SECP384R1",
     .id = GNUTLS_ECC_CURVE_SECP384R1,
+    .tls_id = 24,
     .size = 48,
     .prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF",
     .A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC",
@@ -68,6 +71,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = {
   {
     .name = "SECP521R1",
     .id = GNUTLS_ECC_CURVE_SECP521R1,
+    .tls_id = 25,
     .size = 66,
     .prime = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
     .A = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
@@ -82,6 +86,46 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = {
 #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
index eb879d98c40f2c17264c9b6e0e8a488cad0996ca..556f34a253ab257bf21bc4a85d688b14fadded77 100644 (file)
@@ -148,7 +148,7 @@ _gnutls_proc_ecdh_common_server_kx (gnutls_session_t session,
     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);
@@ -190,7 +190,7 @@ int _gnutls_ecdh_common_print_server_kx (gnutls_session_t session, gnutls_buffer
   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);
 
index 11c00716e4d76a1847f1c746371bb0cf04777004..b417a2bcfd1322b9d61318f15fb62200f0de35bf 100644 (file)
@@ -33,6 +33,7 @@
 #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.
@@ -110,7 +111,7 @@ _gnutls_supported_ecc_recv_params (gnutls_session_t session,
 
       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;
 
@@ -177,7 +178,7 @@ _gnutls_supported_ecc_send_params (gnutls_session_t session, gnutls_buffer_st* e
           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)
@@ -246,40 +247,6 @@ _gnutls_supported_ecc_pf_send_params (gnutls_session_t session, gnutls_buffer_st
   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.
index 745a000815c7fb918180dadfa91f48aa1644294c..b2c22a478f8b56c78305d27cd32ac2749a886ad2 100644 (file)
@@ -29,8 +29,6 @@
 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);