[PATCH] ECC: (flags param) is only for key generation

NIIBE Yutaka gniibe at fsij.org
Fri Apr 25 04:37:22 CEST 2014


On 2014-04-25 at 09:39 +0900, NIIBE Yutaka wrote:
> But, I think that "(flags param)" only makes sense for key generation.

This is revised patch, full version.

diff --git a/cipher/ecc.c b/cipher/ecc.c
index 6a60785..c73d9aa 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -577,15 +577,9 @@ ecc_generate (const gcry_sexp_t genparms, gcry_sexp_t *r_skey)
         goto leave;
     }
 
-  if ((flags & PUBKEY_FLAG_PARAM) || (flags & PUBKEY_FLAG_EDDSA))
-    {
-      rc = sexp_build
-        (&curve_flags, NULL,
-         ((flags & PUBKEY_FLAG_PARAM) && (flags & PUBKEY_FLAG_EDDSA))?
-         "(flags param eddsa)" :
-         ((flags & PUBKEY_FLAG_PARAM))?
-         "(flags param)" :
-         "(flags eddsa)");
+  if ((flags & PUBKEY_FLAG_EDDSA))
+    {
+      rc = sexp_build (&curve_flags, NULL, "(flags eddsa)");
       if (rc)
         goto leave;
     }
@@ -673,13 +667,9 @@ ecc_check_secret_key (gcry_sexp_t keyparms)
     }
 
   /* Extract the parameters.  */
-  if ((flags & PUBKEY_FLAG_PARAM))
-    rc = sexp_extract_param (keyparms, NULL, "-p?a?b?g?n?/q?+d",
-                             &sk.E.p, &sk.E.a, &sk.E.b, &mpi_g, &sk.E.n,
-                             &mpi_q, &sk.d, NULL);
-  else
-    rc = sexp_extract_param (keyparms, NULL, "/q?+d",
-                             &mpi_q, &sk.d, NULL);
+  rc = sexp_extract_param (keyparms, NULL, "-p?a?b?g?n?/q?+d",
+                           &sk.E.p, &sk.E.a, &sk.E.b, &mpi_g, &sk.E.n,
+                           &mpi_q, &sk.d, NULL);
   if (rc)
     goto leave;
 
@@ -810,13 +800,9 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms)
   /*
    * Extract the key.
    */
-  if ((ctx.flags & PUBKEY_FLAG_PARAM))
-    rc = sexp_extract_param (keyparms, NULL, "-p?a?b?g?n?/q?+d",
-                             &sk.E.p, &sk.E.a, &sk.E.b, &mpi_g, &sk.E.n,
-                             &mpi_q, &sk.d, NULL);
-  else
-    rc = sexp_extract_param (keyparms, NULL, "/q?+d",
-                             &mpi_q, &sk.d, NULL);
+  rc = sexp_extract_param (keyparms, NULL, "-p?a?b?g?n?/q?+d",
+                           &sk.E.p, &sk.E.a, &sk.E.b, &mpi_g, &sk.E.n,
+                           &mpi_q, &sk.d, NULL);
   if (rc)
     goto leave;
   if (mpi_g)
@@ -974,13 +960,9 @@ ecc_verify (gcry_sexp_t s_sig, gcry_sexp_t s_data, gcry_sexp_t s_keyparms)
   /*
    * Extract the key.
    */
-  if ((ctx.flags & PUBKEY_FLAG_PARAM))
-    rc = sexp_extract_param (s_keyparms, NULL, "-p?a?b?g?n?/q",
-                             &pk.E.p, &pk.E.a, &pk.E.b, &mpi_g, &pk.E.n,
-                             &mpi_q, NULL);
-  else
-    rc = sexp_extract_param (s_keyparms, NULL, "/q",
-                             &mpi_q, NULL);
+  rc = sexp_extract_param (s_keyparms, NULL, "-p?a?b?g?n?/q",
+                           &pk.E.p, &pk.E.a, &pk.E.b, &mpi_g, &pk.E.n,
+                           &mpi_q, NULL);
   if (rc)
     goto leave;
   if (mpi_g)
@@ -1550,28 +1532,16 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparms)
     }
 
   /* Extract the parameters.  */
-  if ((flags & PUBKEY_FLAG_PARAM))
-    {
-      if ((flags & PUBKEY_FLAG_EDDSA))
-        rc = sexp_extract_param (keyparms, NULL, "p?a?b?g?n?/q",
-                                 &values[0], &values[1], &values[2],
-                                 &values[3], &values[4], &values[5],
-                                 NULL);
-      else
-        rc = sexp_extract_param (keyparms, NULL, "p?a?b?g?n?q",
-                                 &values[0], &values[1], &values[2],
-                                 &values[3], &values[4], &values[5],
-                                 NULL);
-    }
+  if ((flags & PUBKEY_FLAG_EDDSA))
+    rc = sexp_extract_param (keyparms, NULL, "p?a?b?g?n?/q",
+                             &values[0], &values[1], &values[2],
+                             &values[3], &values[4], &values[5],
+                             NULL);
   else
-    {
-      if ((flags & PUBKEY_FLAG_EDDSA))
-        rc = sexp_extract_param (keyparms, NULL, "/q",
-                                 &values[5], NULL);
-      else
-        rc = sexp_extract_param (keyparms, NULL, "q",
-                                 &values[5], NULL);
-    }
+    rc = sexp_extract_param (keyparms, NULL, "p?a?b?g?n?q",
+                             &values[0], &values[1], &values[2],
+                             &values[3], &values[4], &values[5],
+                             NULL);
   if (rc)
     goto leave;
 
-- 





More information about the Gcrypt-devel mailing list