[git] GnuPG - branch, STABLE-BRANCH-2-2, updated. gnupg-2.2.5-33-ge610d51

by NIIBE Yutaka cvs at cvs.gnupg.org
Wed Mar 28 11:59:35 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, STABLE-BRANCH-2-2 has been updated
       via  e610d51f0de11154050915b951bcc5c53c940f5e (commit)
      from  96918346beeca7a46de9f03f19502373994c21bc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e610d51f0de11154050915b951bcc5c53c940f5e
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Wed Mar 28 18:44:45 2018 +0900

    g10: Change ask_curve so that it can be used outside.
    
    * g10/call-agent.h (struct key_attr): New.
    * g10/keygen.c (ask_curve): Return const char *.  No allocation.
    (quick_generate_keypair): Follow the change.
    (generate_keypair, generate_subkeypair): Likewise.
    (parse_algo_usage_expire): Return const char *.
    
    --
    
    This change is intended for using ask_curve from card-util.c.
    
    Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>

diff --git a/g10/call-agent.h b/g10/call-agent.h
index 8de0d13..7314ae8 100644
--- a/g10/call-agent.h
+++ b/g10/call-agent.h
@@ -19,6 +19,13 @@
 #ifndef GNUPG_G10_CALL_AGENT_H
 #define GNUPG_G10_CALL_AGENT_H
 
+struct key_attr {
+  int algo;              /* Algorithm identifier.  */
+  union {
+    unsigned int nbits;  /* Supported keysize.  */
+    const char *curve;   /* Name of curve.  */
+  };
+};
 
 struct agent_card_info_s
 {
@@ -57,13 +64,7 @@ struct agent_card_info_s
   int is_v2;         /* True if this is a v2 card.  */
   int chvmaxlen[3];  /* Maximum allowed length of a CHV. */
   int chvretry[3];   /* Allowed retries for the CHV; 0 = blocked. */
-  struct {           /* Array with key attributes.  */
-    int algo;              /* Algorithm identifier.  */
-    union {
-      unsigned int nbits;  /* Supported keysize.  */
-      const char *curve;   /* Name of curve.  */
-    };
-  } key_attr[3];
+  struct key_attr key_attr[3];
   struct {
     unsigned int ki:1;     /* Key import available.  */
     unsigned int aac:1;    /* Algorithm attributes are changeable.  */
diff --git a/g10/keygen.c b/g10/keygen.c
index 8de6538..1098798 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -141,8 +141,8 @@ static gpg_error_t parse_algo_usage_expire (ctrl_t ctrl, int for_subkey,
                                      const char *algostr, const char *usagestr,
                                      const char *expirestr,
                                      int *r_algo, unsigned int *r_usage,
-                                     u32 *r_expire,
-                                     unsigned int *r_nbits, char **r_curve);
+                                     u32 *r_expire, unsigned int *r_nbits,
+                                     const char **r_curve);
 static void do_generate_keypair (ctrl_t ctrl, struct para_data_s *para,
                                  struct output_control_s *outctrl, int card );
 static int write_keyblock (iobuf_t out, kbnode_t node);
@@ -2233,9 +2233,9 @@ ask_keysize (int algo, unsigned int primary_keysize)
 
 
 /* Ask for the curve.  ALGO is the selected algorithm which this
-   function may adjust.  Returns a malloced string with the name of
-   the curve.  BOTH tells that gpg creates a primary and subkey. */
-static char *
+   function may adjust.  Returns a const string of the name of the
+   curve.  */
+static const char *
 ask_curve (int *algo, int *subkey_algo)
 {
   /* NB: We always use a complete algo list so that we have stable
@@ -2267,7 +2267,7 @@ ask_curve (int *algo, int *subkey_algo)
 #undef MY_USE_ECDSADH
   int idx;
   char *answer;
-  char *result = NULL;
+  const char *result = NULL;
   gcry_sexp_t keyparms;
 
   tty_printf (_("Please select which elliptic curve you want:\n"));
@@ -2358,16 +2358,16 @@ ask_curve (int *algo, int *subkey_algo)
               if (subkey_algo && *subkey_algo == PUBKEY_ALGO_ECDSA)
                 *subkey_algo = PUBKEY_ALGO_EDDSA;
               *algo = PUBKEY_ALGO_EDDSA;
-              result = xstrdup (curves[idx].eddsa_curve);
+              result = curves[idx].eddsa_curve;
             }
           else
-            result = xstrdup (curves[idx].name);
+            result = curves[idx].name;
           break;
         }
     }
 
   if (!result)
-    result = xstrdup (curves[0].name);
+    result = curves[0].name;
 
   return result;
 }
@@ -4058,7 +4058,7 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr,
       unsigned int use;
       u32 expire;
       unsigned int nbits;
-      char *curve;
+      const char *curve;
 
       err = parse_algo_usage_expire (ctrl, 0, algostr, usagestr, expirestr,
                                      &algo, &use, &expire, &nbits, &curve);
@@ -4253,7 +4253,7 @@ generate_keypair (ctrl_t ctrl, int full, const char *fname,
         }
       else
         {
-          char *curve = NULL;
+          const char *curve = NULL;
 
           if (subkey_algo)
             {
@@ -4316,8 +4316,7 @@ generate_keypair (ctrl_t ctrl, int full, const char *fname,
                     {
                       /* Need to switch to a different curve for the
                          encryption key.  */
-                      xfree (curve);
-                      curve = xstrdup ("Curve25519");
+                      curve = "Curve25519";
                     }
                   r = xmalloc_clear (sizeof *r + strlen (curve));
                   r->key = pSUBKEYCURVE;
@@ -4377,8 +4376,6 @@ generate_keypair (ctrl_t ctrl, int full, const char *fname,
               r->next = para;
               para = r;
             }
-
-          xfree (curve);
         }
     }
   else /* Default key generation.  */
@@ -4921,7 +4918,7 @@ parse_algo_usage_expire (ctrl_t ctrl, int for_subkey,
                          const char *algostr, const char *usagestr,
                          const char *expirestr,
                          int *r_algo, unsigned int *r_usage, u32 *r_expire,
-                         unsigned int *r_nbits, char **r_curve)
+                         unsigned int *r_nbits, const char **r_curve)
 {
   gpg_error_t err;
   int algo;
@@ -4979,11 +4976,7 @@ parse_algo_usage_expire (ctrl_t ctrl, int for_subkey,
     return gpg_error (GPG_ERR_INV_VALUE);
 
   if (curve)
-    {
-      *r_curve = xtrystrdup (curve);
-      if (!*r_curve)
-        return gpg_error_from_syserror ();
-    }
+    *r_curve = curve;
   *r_algo = algo;
   *r_usage = use;
   *r_expire = expire;
@@ -5008,7 +5001,7 @@ generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock, const char *algostr,
   unsigned int use;
   u32 expire;
   unsigned int nbits = 0;
-  char *curve = NULL;
+  const char *curve = NULL;
   u32 cur_time;
   char *key_from_hexgrip = NULL;
   char *hexgrip = NULL;
@@ -5160,7 +5153,6 @@ generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock, const char *algostr,
 
  leave:
   xfree (key_from_hexgrip);
-  xfree (curve);
   xfree (hexgrip);
   xfree (serialno);
   xfree (cache_nonce);

-----------------------------------------------------------------------

Summary of changes:
 g10/call-agent.h | 15 ++++++++-------
 g10/keygen.c     | 38 +++++++++++++++-----------------------
 2 files changed, 23 insertions(+), 30 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list