summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2022-06-27 18:02:03 +0200
committerWerner Koch <wk@gnupg.org>2022-06-27 18:06:40 +0200
commitae2f1f0785e429d6dbb577a1fcf9a880aaff8e49 (patch)
treebe877253450635c7b211fa1c5fcccaa19044f8a0 /g10
parentagent: Flush before calling ftruncate. (diff)
downloadgnupg2-ae2f1f0785e429d6dbb577a1fcf9a880aaff8e49.tar.xz
gnupg2-ae2f1f0785e429d6dbb577a1fcf9a880aaff8e49.zip
agent: Do not consider --min-passphrase-len for the magic wand.
* agent/call-pinentry.c (generate_pin): Lock to exactly 30 octets. * g10/gpg.c (main) <aGenRandom>: Add Level 30.
Diffstat (limited to 'g10')
-rw-r--r--g10/gpg.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/g10/gpg.c b/g10/gpg.c
index 466a48d9d..397f4cc87 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -64,6 +64,7 @@
#include "objcache.h"
#include "../common/init.h"
#include "../common/mbox-util.h"
+#include "../common/zb32.h"
#include "../common/shareddefs.h"
#include "../common/compliance.h"
#include "../common/comopt.h"
@@ -5068,8 +5069,29 @@ main (int argc, char **argv)
if (hexhack)
level = 1;
+ /* Level 30 uses the same algorithm as our magic wand in
+ * pinentry/gpg-agent. */
+ if (level == 30)
+ {
+ unsigned int nbits = 150;
+ size_t nbytes = (nbits + 7) / 8;
+ void *rand;
+ char *generated;
+
+ rand = gcry_random_bytes_secure (nbytes, GCRY_STRONG_RANDOM);
+ if (!rand)
+ log_fatal ("failed to generate random password\n");
+
+ generated = zb32_encode (rand, nbits);
+ gcry_free (rand);
+ es_fputs (generated, es_stdout);
+ es_putc ('\n', es_stdout);
+ xfree (generated);
+ break;
+ }
+
if (argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0)
- wrong_args ("--gen-random 0|1|2 [count]");
+ wrong_args ("--gen-random 0|1|2|16|30 [count]");
while (endless || count)
{