mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
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@fsij.org>
This commit is contained in:
parent
96918346be
commit
e610d51f0d
@ -19,6 +19,13 @@
|
|||||||
#ifndef GNUPG_G10_CALL_AGENT_H
|
#ifndef GNUPG_G10_CALL_AGENT_H
|
||||||
#define 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
|
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 is_v2; /* True if this is a v2 card. */
|
||||||
int chvmaxlen[3]; /* Maximum allowed length of a CHV. */
|
int chvmaxlen[3]; /* Maximum allowed length of a CHV. */
|
||||||
int chvretry[3]; /* Allowed retries for the CHV; 0 = blocked. */
|
int chvretry[3]; /* Allowed retries for the CHV; 0 = blocked. */
|
||||||
struct { /* Array with key attributes. */
|
struct key_attr key_attr[3];
|
||||||
int algo; /* Algorithm identifier. */
|
|
||||||
union {
|
|
||||||
unsigned int nbits; /* Supported keysize. */
|
|
||||||
const char *curve; /* Name of curve. */
|
|
||||||
};
|
|
||||||
} key_attr[3];
|
|
||||||
struct {
|
struct {
|
||||||
unsigned int ki:1; /* Key import available. */
|
unsigned int ki:1; /* Key import available. */
|
||||||
unsigned int aac:1; /* Algorithm attributes are changeable. */
|
unsigned int aac:1; /* Algorithm attributes are changeable. */
|
||||||
|
38
g10/keygen.c
38
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 *algostr, const char *usagestr,
|
||||||
const char *expirestr,
|
const char *expirestr,
|
||||||
int *r_algo, unsigned int *r_usage,
|
int *r_algo, unsigned int *r_usage,
|
||||||
u32 *r_expire,
|
u32 *r_expire, unsigned int *r_nbits,
|
||||||
unsigned int *r_nbits, char **r_curve);
|
const char **r_curve);
|
||||||
static void do_generate_keypair (ctrl_t ctrl, struct para_data_s *para,
|
static void do_generate_keypair (ctrl_t ctrl, struct para_data_s *para,
|
||||||
struct output_control_s *outctrl, int card );
|
struct output_control_s *outctrl, int card );
|
||||||
static int write_keyblock (iobuf_t out, kbnode_t node);
|
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
|
/* Ask for the curve. ALGO is the selected algorithm which this
|
||||||
function may adjust. Returns a malloced string with the name of
|
function may adjust. Returns a const string of the name of the
|
||||||
the curve. BOTH tells that gpg creates a primary and subkey. */
|
curve. */
|
||||||
static char *
|
static const char *
|
||||||
ask_curve (int *algo, int *subkey_algo)
|
ask_curve (int *algo, int *subkey_algo)
|
||||||
{
|
{
|
||||||
/* NB: We always use a complete algo list so that we have stable
|
/* 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
|
#undef MY_USE_ECDSADH
|
||||||
int idx;
|
int idx;
|
||||||
char *answer;
|
char *answer;
|
||||||
char *result = NULL;
|
const char *result = NULL;
|
||||||
gcry_sexp_t keyparms;
|
gcry_sexp_t keyparms;
|
||||||
|
|
||||||
tty_printf (_("Please select which elliptic curve you want:\n"));
|
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)
|
if (subkey_algo && *subkey_algo == PUBKEY_ALGO_ECDSA)
|
||||||
*subkey_algo = PUBKEY_ALGO_EDDSA;
|
*subkey_algo = PUBKEY_ALGO_EDDSA;
|
||||||
*algo = PUBKEY_ALGO_EDDSA;
|
*algo = PUBKEY_ALGO_EDDSA;
|
||||||
result = xstrdup (curves[idx].eddsa_curve);
|
result = curves[idx].eddsa_curve;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = xstrdup (curves[idx].name);
|
result = curves[idx].name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
result = xstrdup (curves[0].name);
|
result = curves[0].name;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -4058,7 +4058,7 @@ quick_generate_keypair (ctrl_t ctrl, const char *uid, const char *algostr,
|
|||||||
unsigned int use;
|
unsigned int use;
|
||||||
u32 expire;
|
u32 expire;
|
||||||
unsigned int nbits;
|
unsigned int nbits;
|
||||||
char *curve;
|
const char *curve;
|
||||||
|
|
||||||
err = parse_algo_usage_expire (ctrl, 0, algostr, usagestr, expirestr,
|
err = parse_algo_usage_expire (ctrl, 0, algostr, usagestr, expirestr,
|
||||||
&algo, &use, &expire, &nbits, &curve);
|
&algo, &use, &expire, &nbits, &curve);
|
||||||
@ -4253,7 +4253,7 @@ generate_keypair (ctrl_t ctrl, int full, const char *fname,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *curve = NULL;
|
const char *curve = NULL;
|
||||||
|
|
||||||
if (subkey_algo)
|
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
|
/* Need to switch to a different curve for the
|
||||||
encryption key. */
|
encryption key. */
|
||||||
xfree (curve);
|
curve = "Curve25519";
|
||||||
curve = xstrdup ("Curve25519");
|
|
||||||
}
|
}
|
||||||
r = xmalloc_clear (sizeof *r + strlen (curve));
|
r = xmalloc_clear (sizeof *r + strlen (curve));
|
||||||
r->key = pSUBKEYCURVE;
|
r->key = pSUBKEYCURVE;
|
||||||
@ -4377,8 +4376,6 @@ generate_keypair (ctrl_t ctrl, int full, const char *fname,
|
|||||||
r->next = para;
|
r->next = para;
|
||||||
para = r;
|
para = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree (curve);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* Default key generation. */
|
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 *algostr, const char *usagestr,
|
||||||
const char *expirestr,
|
const char *expirestr,
|
||||||
int *r_algo, unsigned int *r_usage, u32 *r_expire,
|
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;
|
gpg_error_t err;
|
||||||
int algo;
|
int algo;
|
||||||
@ -4979,11 +4976,7 @@ parse_algo_usage_expire (ctrl_t ctrl, int for_subkey,
|
|||||||
return gpg_error (GPG_ERR_INV_VALUE);
|
return gpg_error (GPG_ERR_INV_VALUE);
|
||||||
|
|
||||||
if (curve)
|
if (curve)
|
||||||
{
|
*r_curve = curve;
|
||||||
*r_curve = xtrystrdup (curve);
|
|
||||||
if (!*r_curve)
|
|
||||||
return gpg_error_from_syserror ();
|
|
||||||
}
|
|
||||||
*r_algo = algo;
|
*r_algo = algo;
|
||||||
*r_usage = use;
|
*r_usage = use;
|
||||||
*r_expire = expire;
|
*r_expire = expire;
|
||||||
@ -5008,7 +5001,7 @@ generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock, const char *algostr,
|
|||||||
unsigned int use;
|
unsigned int use;
|
||||||
u32 expire;
|
u32 expire;
|
||||||
unsigned int nbits = 0;
|
unsigned int nbits = 0;
|
||||||
char *curve = NULL;
|
const char *curve = NULL;
|
||||||
u32 cur_time;
|
u32 cur_time;
|
||||||
char *key_from_hexgrip = NULL;
|
char *key_from_hexgrip = NULL;
|
||||||
char *hexgrip = NULL;
|
char *hexgrip = NULL;
|
||||||
@ -5160,7 +5153,6 @@ generate_subkeypair (ctrl_t ctrl, kbnode_t keyblock, const char *algostr,
|
|||||||
|
|
||||||
leave:
|
leave:
|
||||||
xfree (key_from_hexgrip);
|
xfree (key_from_hexgrip);
|
||||||
xfree (curve);
|
|
||||||
xfree (hexgrip);
|
xfree (hexgrip);
|
||||||
xfree (serialno);
|
xfree (serialno);
|
||||||
xfree (cache_nonce);
|
xfree (cache_nonce);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user