X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fgenauth.c;h=78c567d0dc2fc8b9c0a5ed5497c7656d980a8d08;hp=b727eb6eb551aa6c553eb0ae4b10d43a4159861f;hb=9f64499e40a95a8c05c82924219517aa017fc411;hpb=ee96ccabbbf0180d5631d3c22838456f28ee9c15 diff --git a/src/genauth.c b/src/genauth.c index b727eb6e..78c567d0 100644 --- a/src/genauth.c +++ b/src/genauth.c @@ -1,6 +1,7 @@ /* - genauth.c -- generate a random passphrase + genauth.c -- generate public/private keypairs Copyright (C) 1998,1999,2000 Ivo Timmermans + 2000 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,6 +16,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: genauth.c,v 1.7.4.4 2000/10/20 15:34:35 guus Exp $ */ #include "config.h" @@ -22,77 +25,89 @@ #include #include #include +#include +#include #include -#include "encr.h" +#include "system.h" + +#define RSA_PUBLIC_EXPONENT 65535 -unsigned char initvec[] = { 0x22, 0x7b, 0xad, 0x55, 0x41, 0xf4, 0x3e, 0xf3 }; +void indicator(int a, int b, void *p) +{ + switch(a) + { + case 0: + fprintf(stderr, "."); + break; + case 1: + fprintf(stderr, "+"); + break; + case 2: + fprintf(stderr, "-"); + break; + case 3: + switch(b) + { + case 0: + fprintf(stderr, " p\n"); + break; + case 1: + fprintf(stderr, " q\n"); + break; + default: + fprintf(stderr, "?"); + } + break; + default: + fprintf(stderr, "?"); + } +} int main(int argc, char **argv) { - FILE *fp; - int bits, c, i, bytes; - unsigned char *p; + int bits; + RSA *key; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); if(argc > 2 || (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) { - fprintf(stderr, "Usage: %s bits\n", argv[0]); + fprintf(stderr, _("Usage: %s bits\n"), argv[0]); return 1; } if(!argv[1]) argv[1] = "1024"; - - if(!(bits = atol(argv[1]))) + + bits = atol(argv[1]); + + if(bits<32) { - fprintf(stderr, "Illegal number: %s\n", argv[1]); + fprintf(stderr, _("Illegal number: %s\n"), argv[1]); return 1; } + + bits = ((bits - 1) | 7) + 1; /* Align to bytes for easy mallocing and reading */ - bits = ((bits - 1) | 63) + 1; - fprintf(stderr, "Generating %d bits number", bits); - bytes = bits >> 3; + fprintf(stderr, _("Seeding the PRNG: please press some keys or move\nthe mouse if this program seems to have halted...\n")); - if((fp = fopen("/dev/urandom", "r")) == NULL) - { - perror("Opening /dev/urandom"); - return 1; - } + RAND_load_file("/dev/random", 1024); /* OpenSSL PRNG state apparently uses 1024 bytes */ - p = xmalloc(bytes); + fprintf(stderr, _("Generating %d bits keys:\n"), bits); - setbuf(stdout, NULL); - for(i = 0; i < bytes; i++) - { - c = fgetc(fp); - if(feof(fp)) - { - puts(""); - fprintf(stderr, "File was empty!\n"); - } - p[i] = c; - } - fclose(fp); + key = RSA_generate_key(bits, RSA_PUBLIC_EXPONENT, indicator, NULL); - if(isatty(1)) - { - fprintf(stderr, ": done.\nThe following line should be ENTIRELY copied into a passphrase file:\n"); - printf("%d ", bits); - for(i = 0; i < bytes; i++) - printf("%02x", p[i]); - puts(""); - } - else - { - printf("%d ", bits); - for(i = 0; i < bytes; i++) - printf("%02x", p[i]); - puts(""); - fprintf(stderr, ": done.\n"); - } + fprintf(stderr, _("Done.\n")); - return 0; -} + printf(_("Public key: %s\n"), BN_bn2hex(key->n)); + printf(_("Private key: %s\n"), BN_bn2hex(key->d)); + printf(_("Public exp: %s\n"), BN_bn2hex(key->e)); + fflush(stdin); /* Flush any input caused by random keypresses */ + return 0; +}