2 genauth.c -- generate public/private keypairs
3 Copyright (C) 1998,1999,2000 Ivo Timmermans <zarq@iname.com>
4 2000 Guus Sliepen <guus@sliepen.warande.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: genauth.c,v 1.7.4.4 2000/10/20 15:34:35 guus Exp $
28 #include <openssl/rsa.h>
29 #include <openssl/rand.h>
35 #define RSA_PUBLIC_EXPONENT 65535
37 void indicator(int a, int b, void *p)
54 fprintf(stderr, " p\n");
57 fprintf(stderr, " q\n");
68 int main(int argc, char **argv)
73 setlocale (LC_ALL, "");
74 bindtextdomain (PACKAGE, LOCALEDIR);
77 if(argc > 2 || (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))))
79 fprintf(stderr, _("Usage: %s bits\n"), argv[0]);
90 fprintf(stderr, _("Illegal number: %s\n"), argv[1]);
94 bits = ((bits - 1) | 7) + 1; /* Align to bytes for easy mallocing and reading */
96 fprintf(stderr, _("Seeding the PRNG: please press some keys or move\nthe mouse if this program seems to have halted...\n"));
98 RAND_load_file("/dev/random", 1024); /* OpenSSL PRNG state apparently uses 1024 bytes */
100 fprintf(stderr, _("Generating %d bits keys:\n"), bits);
102 key = RSA_generate_key(bits, RSA_PUBLIC_EXPONENT, indicator, NULL);
104 fprintf(stderr, _("Done.\n"));
106 printf(_("Public key: %s\n"), BN_bn2hex(key->n));
107 printf(_("Private key: %s\n"), BN_bn2hex(key->d));
108 printf(_("Public exp: %s\n"), BN_bn2hex(key->e));
110 fflush(stdin); /* Flush any input caused by random keypresses */