]> andersk Git - moira.git/blame - util/gdss/lib/crypto/crypto_util.c
Switch from Imake-based build system to autoconf-based.
[moira.git] / util / gdss / lib / crypto / crypto_util.c
CommitLineData
0095f096 1/*
2 * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
3 * ALL RIGHTS RESERVED
4 *
5 * "Digital Equipment Corporation authorizes the reproduction,
6 * distribution and modification of this software subject to the following
7 * restrictions:
8 *
9 * 1. Any partial or whole copy of this software, or any modification
10 * thereof, must include this copyright notice in its entirety.
11 *
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.
17 *
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.
20 *
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.
26 *
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"
31 *
32 */
33
34#include <stdio.h>
0095f096 35#include <sys/time.h>
0095f096 36#include <sys/types.h>
37#include "random.h"
38#include "BigNum.h"
39#include "BigRSA.h"
40#include "bigkeygen.h"
41
42/*
43 * InitDelegationKey. Generate a new rsa key of desired bit length.
44 * If random number generator is not yet seeded,
45 * initialize with uncertainty from the principal
46 * prime.
47 */
48int InitDelegationKey(principal, delegation, bitlen)
49RSAKeyStorage *principal, *delegation;
50int bitlen;
51{
52 RNGState rng;
53 read_rng_state (&rng);
54 if ((rng.count)==0) initialize_rng_state (principal->p,32);
55 return(newRSAKey (delegation, bitlen));
56}
57
58/*
59 * Private2Public. Remove private key stuff in a key storage block.
60 */
61int Private2Public (key)
62RSAKeyStorage *key;
63{
64 memset(key->p,0,PRIVATE_KEY_SIZE-PUBLIC_KEY_SIZE);
65 key->pl=key->ql=key->dpl=key->dql=0;
66}
67
68
69/*
70 * initrandom - interactive random number initializer
71 *
72 * The following routine attempts to initialize the random number generator
73 * with a reasonable amount of uncertainty. This is provided mostly by
74 * the user, with some additional time inputs from the system.
75 */
76int initrandom()
77{
78unsigned char bar[16];
79int seed ;
80char buffer[256], sphinx_ans[80];
81char *ptr=buffer, *env=NULL;
82int i;
83long tick = clock();
84struct timeval tv ;
85struct timezone tz ;
86int thischar , lastchar ;
87
88 memset(ptr,0,256);
89
90 gettimeofday(&tv, &tz);
91 memcpy(ptr,&tv,sizeof(struct timeval));
92 ptr += sizeof(struct timeval);
93/*
94 printf("\nRiddle of the Sphinx :\n\n");
95 printf("What creature is it, that in the morning goes on four feet,\n");
96 printf("at noon on two, and at night on three?\n\n");
97 fflush(stdout);
98 scanf("%s", sphinx_ans); gets(ptr);
99 if ((strcasecmp(sphinx_ans, "man") == 0) || (strcasecmp(sphinx_ans, "woman") == 0)) {
100 printf("\nCorrect!\n\n");
101 } else {
102 printf("\nWrong! Please brush up on your Egyptian mythology.\n\n");
103 }
104*/
105 tick = clock();
106 memcpy(ptr,&tick,sizeof(long));
107 ptr += sizeof(long);
108 memcpy(ptr,&ptr,sizeof(char *));
109 ptr+=sizeof(char *);
110 gettimeofday(&tv, &tz);
111 memcpy(ptr,&tv,sizeof(struct timeval));
112 ptr += sizeof(struct timeval);
113
114 seed = sizeof(buffer) - (ptr - buffer) - sizeof(struct timeval);
115
116 printf("\nSome 'uncertainty' is needed to initialize the random");
117 printf("\nnumber generator to generate your long term key. Please");
118 printf("\nenter up to %d characters of text. The quality of your key", seed);
119 printf("\ndepends upon how 'uncertain' this input is. When you");
120 printf("\nthink you have entered enough text, enter two successive");
121 printf("\ncarriage returns.");
122 printf("\n\n");
123 fflush(stdout);
124
125 for( i = thischar = lastchar = 0;
126 (thischar=getchar())!= EOF,((thischar != '\n')||(lastchar != '\n')); i++) {
127 lastchar = thischar;
128 ptr[ i % seed ] += (unsigned char) thischar ;
129 }
130
131 printf("\nThank you very much.\n");
132
133 gettimeofday(&tv, &tz);
134 memcpy(ptr,&tv,sizeof(struct timeval));
135
136 initialize_rng_state (buffer, sizeof(buffer));
137
138}
139
This page took 0.065484 seconds and 5 git commands to generate.