[package] opkg: fallback to dest->root_dir if specified overlay_root does not exist...
[openwrt.git] / package / ead / src / tinysrp / tconf.c
1 /*
2 * Copyright (c) 1997-2000 The Stanford SRP Authentication Project
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
21 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
22 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
23 * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
24 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 *
26 * In addition, the following conditions apply:
27 *
28 * 1. Any software that incorporates the SRP authentication technology
29 * must display the following acknowlegment:
30 * "This product uses the 'Secure Remote Password' cryptographic
31 * authentication system developed by Tom Wu (tjw@CS.Stanford.EDU)."
32 *
33 * 2. Any software that incorporates all or part of the SRP distribution
34 * itself must also display the following acknowledgment:
35 * "This product includes software developed by Tom Wu and Eugene
36 * Jhong for the SRP Distribution (http://srp.stanford.edu/srp/)."
37 *
38 * 3. Redistributions in source or binary form must retain an intact copy
39 * of this copyright notice and list of conditions.
40 */
41
42 #include <unistd.h> /* close getlogin */
43 #include <stdlib.h> /* atexit exit */
44 #include <stdio.h>
45 #include <string.h>
46
47 #include "t_pwd.h"
48
49 #define MIN_BASIS_BITS 512
50 #define BASIS_BITS 2048
51
52 extern int optind;
53 extern char *optarg;
54
55 extern int errno;
56
57 char *progName;
58
59 int debug = 0;
60 int verbose = 0;
61 int composite = 0;
62
63 int main(argc, argv)
64 int argc;
65 char *argv[];
66 {
67 char *chp;
68 char *configFile = NULL;
69 char cbuf[256];
70 char b64buf[MAXB64PARAMLEN];
71 int c, ch, i, lastidx, keylen, yesno, fsize, status, nparams;
72 FILE *efp;
73
74 struct t_preconf * tpc;
75 struct t_conf tcs;
76 struct t_conf * tc = &tcs;
77 struct t_confent * tcent;
78
79 progName = *argv;
80 if ((chp = strrchr(progName, '/')) != (char *) 0) progName = chp + 1;
81
82 while ((ch = getopt(argc, argv, "dv2c:")) != EOF)
83 switch(ch) {
84 case 'c':
85 configFile = optarg;
86 break;
87 case 'v':
88 verbose++;
89 break;
90 case 'd':
91 debug++;
92 break;
93 case '2':
94 composite++;
95 break;
96 default:
97 fprintf(stderr, "usage: %s [-dv2] [-c configfile]\n", progName);
98 exit(1);
99 }
100
101 argc -= optind;
102 argv += optind;
103
104 lastidx = 0;
105 keylen = 0;
106
107 tcent = t_newconfent(tc);
108
109 printf("\nThis program will generate a set of parameters for the EPS\n");
110 printf("password file. The size of these parameters, measured in bits,\n");
111 printf("determines the level of security offered by SRP, and is related\n");
112 printf("to the security of similarly-sized RSA or Diffie-Hellman keys.\n");
113 printf("Choosing a predefined field is generally preferable to generating\n");
114 printf("a new field because clients can avoid costly parameter verification.\n");
115 printf("Either way, the values generated by this program are public and\n");
116 printf("can even shared between systems.\n");
117
118 printf("\nEnter the new field size, in bits. Suggested sizes:\n\n");
119 printf(" 512 (fast, minimally secure)\n");
120 printf(" 768 (moderate security)\n");
121 printf("1024 (most popular default)\n");
122 printf("1536 (additional security, possibly slow)\n");
123 printf("2048 (maximum supported security level)\n");
124 printf("\nField size (%d to %d): ", MIN_BASIS_BITS, BASIS_BITS);
125
126 fgets(cbuf, sizeof(cbuf), stdin);
127 fsize = atoi(cbuf);
128 if(fsize < MIN_BASIS_BITS || fsize > BASIS_BITS) {
129 fprintf(stderr, "%s: field size must be between %d and %d\n",
130 progName, MIN_BASIS_BITS, BASIS_BITS);
131 exit(1);
132 }
133
134 if(fsize <= keylen)
135 fprintf(stderr, "Warning: new field size is not larger than old field size\n");
136
137 printf("\nInitializing random number generator...");
138 fflush(stdout);
139 t_initrand();
140
141 if(composite)
142 printf("done.\n\nGenerating a %d-bit composite with safe prime factors. This may take a while.\n", fsize);
143 else
144 printf("done.\n\nGenerating a %d-bit safe prime. This may take a while.\n", fsize);
145
146 while((tcent = (composite ? t_makeconfent_c(tc, fsize) :
147 t_makeconfent(tc, fsize))) == NULL)
148 printf("Parameter generation failed, retrying...\n");
149 tcent->index = lastidx + 1;
150
151 printf("\nParameters successfully generated.\n");
152 printf("N = [%s]\n", t_tob64(b64buf,
153 tcent->modulus.data, tcent->modulus.len));
154 printf("g = [%s]\n", t_tob64(b64buf,
155 tcent->generator.data, tcent->generator.len));
156 printf("\nYou must update the pre_params array in t_getconf.c\n");
157 }
This page took 0.054036 seconds and 5 git commands to generate.