2 * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
5 * "Digital Equipment Corporation authorizes the reproduction,
6 * distribution and modification of this software subject to the following
9 * 1. Any partial or whole copy of this software, or any modification
10 * thereof, must include this copyright notice in its entirety.
12 * 2. This software is supplied "as is" with no warranty of any kind,
13 * expressed or implied, for any purpose, including any warranty of fitness
14 * or merchantibility. DIGITAL assumes no responsibility for the use or
15 * reliability of this software, nor promises to provide any form of
16 * support for it on any basis.
18 * 3. Distribution of this software is authorized only if no profit or
19 * remuneration of any kind is received in exchange for such distribution.
21 * 4. This software produces public key authentication certificates
22 * bearing an expiration date established by DIGITAL and RSA Data
23 * Security, Inc. It may cease to generate certificates after the expiration
24 * date. Any modification of this software that changes or defeats
25 * the expiration date or its effect is unauthorized.
27 * 5. Software that will renew or extend the expiration date of
28 * authentication certificates produced by this software may be obtained
29 * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
30 * 94065, (415)595-8782, or from DIGITAL"
40 #include <sys/types.h>
44 #include "bigkeygen.h"
47 * InitDelegationKey. Generate a new rsa key of desired bit length.
48 * If random number generator is not yet seeded,
49 * initialize with uncertainty from the principal
52 int InitDelegationKey(principal, delegation, bitlen)
53 RSAKeyStorage *principal, *delegation;
57 read_rng_state (&rng);
58 if ((rng.count)==0) initialize_rng_state (principal->p,32);
59 return(newRSAKey (delegation, bitlen));
63 * Private2Public. Remove private key stuff in a key storage block.
65 int Private2Public (key)
68 memset(key->p,0,PRIVATE_KEY_SIZE-PUBLIC_KEY_SIZE);
69 key->pl=key->ql=key->dpl=key->dql=0;
74 * initrandom - interactive random number initializer
76 * The following routine attempts to initialize the random number generator
77 * with a reasonable amount of uncertainty. This is provided mostly by
78 * the user, with some additional time inputs from the system.
82 unsigned char bar[16];
84 char buffer[256], sphinx_ans[80];
85 char *ptr=buffer, *env=NULL;
90 int thischar , lastchar ;
94 gettimeofday(&tv, &tz);
95 memcpy(ptr,&tv,sizeof(struct timeval));
96 ptr += sizeof(struct timeval);
98 printf("\nRiddle of the Sphinx :\n\n");
99 printf("What creature is it, that in the morning goes on four feet,\n");
100 printf("at noon on two, and at night on three?\n\n");
102 scanf("%s", sphinx_ans); gets(ptr);
103 if ((strcasecmp(sphinx_ans, "man") == 0) || (strcasecmp(sphinx_ans, "woman") == 0)) {
104 printf("\nCorrect!\n\n");
106 printf("\nWrong! Please brush up on your Egyptian mythology.\n\n");
110 memcpy(ptr,&tick,sizeof(long));
112 memcpy(ptr,&ptr,sizeof(char *));
114 gettimeofday(&tv, &tz);
115 memcpy(ptr,&tv,sizeof(struct timeval));
116 ptr += sizeof(struct timeval);
118 seed = sizeof(buffer) - (ptr - buffer) - sizeof(struct timeval);
120 printf("\nSome 'uncertainty' is needed to initialize the random");
121 printf("\nnumber generator to generate your long term key. Please");
122 printf("\nenter up to %d characters of text. The quality of your key", seed);
123 printf("\ndepends upon how 'uncertain' this input is. When you");
124 printf("\nthink you have entered enough text, enter two successive");
125 printf("\ncarriage returns.");
129 for( i = thischar = lastchar = 0;
130 (thischar=getchar())!= EOF,((thischar != '\n')||(lastchar != '\n')); i++) {
132 ptr[ i % seed ] += (unsigned char) thischar ;
135 printf("\nThank you very much.\n");
137 gettimeofday(&tv, &tz);
138 memcpy(ptr,&tv,sizeof(struct timeval));
140 initialize_rng_state (buffer, sizeof(buffer));