Proposed patch: ssh-keygen allows writing to stdout for moduli generation
Christian Pfaffel-Janser
christian.pfaffel-janser at SIEMENS.com
Fri Mar 2 00:19:32 EST 2007
Hello all,
I propose the following patch to ssh-keygen.c for openssh version 4.5.
It allows to redirect output of the moduli operations to stdout, to do
something like e.g.:
$ ssh-keygen -G - -b 2048 | ssh-keygen -T - -f - >moduli
Best regards,
Christian
--- ssh/ssh-keygen.c.old 2007-03-01 12:43:06.000000000 +0100
+++ ssh/ssh-keygen.c 2007-03-01 12:47:32.000000000 +0100
@@ -1270,13 +1270,16 @@ main(int ac, char **av)
}
if (do_gen_candidates) {
- FILE *out = fopen(out_file, "w");
-
- if (out == NULL) {
- error("Couldn't open modulus candidate file \"%s\": %s",
- out_file, strerror(errno));
- return (1);
- }
+ FILE *out;
+
+ if (strcmp(out_file, "-") != 0) {
+ if ((out = fopen(out_file, "w")) == NULL) {
+ fatal("Couldn't open modulus candidate file \"%s\": %s",
+ out_file, strerror(errno));
+ }
+ } else
+ out = stdout;
+
if (bits == 0)
bits = DEFAULT_BITS;
if (gen_candidates(out, memory, bits, start) != 0)
@@ -1287,8 +1290,16 @@ main(int ac, char **av)
if (do_screen_candidates) {
FILE *in;
- FILE *out = fopen(out_file, "w");
+ FILE *out;
+ if (strcmp(out_file, "-") != 0) {
+ if ((out = fopen(out_file, "w")) == NULL) {
+ fatal("Couldn't open moduli file \"%s\": %s",
+ out_file, strerror(errno));
+ }
+ } else
+ out = stdout;
+
if (have_identity && strcmp(identity_file, "-") != 0) {
if ((in = fopen(identity_file, "r")) == NULL) {
fatal("Couldn't open modulus candidate "
@@ -1298,10 +1309,6 @@ main(int ac, char **av)
} else
in = stdin;
- if (out == NULL) {
- fatal("Couldn't open moduli file \"%s\": %s",
- out_file, strerror(errno));
- }
if (prime_test(in, out, trials, generator_wanted) != 0)
fatal("modulus screening failed");
return (0);
More information about the openssh-unix-dev
mailing list