mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
gpg: Add level 16 to --gen-random
* g10/gpg.c (main): Add that hack. -- This is an yet undocumented hack to allow printing hex encoded random number with gpg. The level is forced to be 1 which is is good for almost all uses. Note that --armor is ignored. Signed-off-by: Werner Koch <wk@gnupg.org> Backported-from-master: d847f0651ab4304129145b55353501636b4e4728
This commit is contained in:
parent
67a2973bf9
commit
1d8191faee
35
g10/gpg.c
35
g10/gpg.c
@ -4905,23 +4905,34 @@ main (int argc, char **argv)
|
||||
int level = argc ? atoi(*argv):0;
|
||||
int count = argc > 1 ? atoi(argv[1]): 0;
|
||||
int endless = !count;
|
||||
int hexhack = (level == 16);
|
||||
|
||||
if( argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0 )
|
||||
wrong_args("--gen-random 0|1|2 [count]");
|
||||
if (hexhack)
|
||||
level = 1;
|
||||
|
||||
while( endless || count ) {
|
||||
if (argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0)
|
||||
wrong_args ("--gen-random 0|1|2 [count]");
|
||||
|
||||
while (endless || count)
|
||||
{
|
||||
byte *p;
|
||||
/* Wee need a multiple of 3, so that in case of
|
||||
armored output we get a correct string. No
|
||||
linefolding is done, as it is best to levae this to
|
||||
other tools */
|
||||
/* We need a multiple of 3, so that in case of armored
|
||||
* output we get a correct string. No linefolding is
|
||||
* done, as it is best to leave this to other tools */
|
||||
size_t n = !endless && count < 99? count : 99;
|
||||
size_t nn;
|
||||
|
||||
p = gcry_random_bytes (n, level);
|
||||
#ifdef HAVE_DOSISH_SYSTEM
|
||||
setmode ( fileno(stdout), O_BINARY );
|
||||
#endif
|
||||
if (opt.armor) {
|
||||
if (hexhack)
|
||||
{
|
||||
for (nn = 0; nn < n; nn++)
|
||||
es_fprintf (es_stdout, "%02x", p[nn]);
|
||||
}
|
||||
else if (opt.armor)
|
||||
{
|
||||
char *tmp = make_radix64_string (p, n);
|
||||
es_fputs (tmp, es_stdout);
|
||||
xfree (tmp);
|
||||
@ -4929,14 +4940,16 @@ main (int argc, char **argv)
|
||||
es_putc ('=', es_stdout);
|
||||
if (n%3)
|
||||
es_putc ('=', es_stdout);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
es_fwrite( p, n, 1, es_stdout );
|
||||
}
|
||||
xfree(p);
|
||||
if( !endless )
|
||||
if (!endless)
|
||||
count -= n;
|
||||
}
|
||||
if (opt.armor)
|
||||
if (opt.armor || hexhack)
|
||||
es_putc ('\n', es_stdout);
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user