diff options
author | Werner Koch <wk@gnupg.org> | 2021-08-18 11:23:23 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2021-08-18 11:24:53 +0200 |
commit | 8ed79103474c17d8dce20c740fc9813ada5f79ac (patch) | |
tree | 41abeaa6b1fb6767fc6a6f9730a43e67b4e9087b /agent | |
parent | agent: Fix for zero length help string in pinentry hints. (diff) | |
download | gnupg2-8ed79103474c17d8dce20c740fc9813ada5f79ac.tar.xz gnupg2-8ed79103474c17d8dce20c740fc9813ada5f79ac.zip |
agent: Improve the GENPIN callback.
* agent/call-pinentry.c (DEFAULT_GENPIN_BYTES): Replace by ...
(DEFAULT_GENPIN_BITS): this and increase to 150.
(generate_pin): Make sure that we use at least 128 bits.
Diffstat (limited to 'agent')
-rw-r--r-- | agent/call-pinentry.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 3aeb15048..d0e4f3d08 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -55,8 +55,12 @@ /* Define the maximum tries to generate a pin for the GENPIN inquire */ #define MAX_GENPIN_TRIES 10 -/* Define the number of characters to use for a generated pin */ -#define DEFAULT_GENPIN_BYTES (128 / 8) +/* Define the number of bits to use for a generated pin. The + * passphrase will be rendered as zbase32 which results for 150 bits + * in a string of 30 characters. That fits nicely into the 5 + * character blocking which pinentry can do. 128 bits would actually + * be sufficient but can't be formatted nicely. */ +#define DEFAULT_GENPIN_BITS 150 /* The assuan context of the current pinentry. */ static assuan_context_t entry_ctx; @@ -846,18 +850,19 @@ estimate_passphrase_quality (const char *pw) /* Generate a random passphrase in zBase32 encoding (RFC-6189) to be - * used by pinetry to suggest a passphrase. */ + * used by Pinentry to suggest a passphrase. */ static char * generate_pin (void) { - size_t nbytes = opt.min_passphrase_len; + unsigned int nbits = opt.min_passphrase_len * 8; + size_t nbytes; void *rand; char *generated; - if (nbytes < 8) - { - nbytes = DEFAULT_GENPIN_BYTES; - } + if (nbits < 128) + nbits = DEFAULT_GENPIN_BITS; + + nbytes = (nbits + 7) / 8; rand = gcry_random_bytes_secure (nbytes, GCRY_STRONG_RANDOM); if (!rand) @@ -866,7 +871,7 @@ generate_pin (void) return NULL; } - generated = zb32_encode (rand, nbytes * 8); + generated = zb32_encode (rand, nbits); gcry_free (rand); return generated; } |