dsagen.c revision 256281
1289177Speter/* crypto/dsa/dsagen.c */
2289177Speter/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3289177Speter * All rights reserved.
4289177Speter *
5289177Speter * This package is an SSL implementation written
6289177Speter * by Eric Young (eay@cryptsoft.com).
7289177Speter * The implementation was written so as to conform with Netscapes SSL.
8289177Speter *
9289177Speter * This library is free for commercial and non-commercial use as long as
10289177Speter * the following conditions are aheared to.  The following conditions
11289177Speter * apply to all code found in this distribution, be it the RC4, RSA,
12289177Speter * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13289177Speter * included with this distribution is covered by the same copyright terms
14289177Speter * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15289177Speter *
16289177Speter * Copyright remains Eric Young's, and as such any Copyright notices in
17289177Speter * the code are not to be removed.
18289177Speter * If this package is used in a product, Eric Young should be given attribution
19289177Speter * as the author of the parts of the library used.
20289177Speter * This can be in the form of a textual message at program startup or
21289177Speter * in documentation (online or textual) provided with the package.
22289177Speter *
23289177Speter * Redistribution and use in source and binary forms, with or without
24289177Speter * modification, are permitted provided that the following conditions
25289177Speter * are met:
26289177Speter * 1. Redistributions of source code must retain the copyright
27289177Speter *    notice, this list of conditions and the following disclaimer.
28289177Speter * 2. Redistributions in binary form must reproduce the above copyright
29289177Speter *    notice, this list of conditions and the following disclaimer in the
30289177Speter *    documentation and/or other materials provided with the distribution.
31289177Speter * 3. All advertising materials mentioning features or use of this software
32289177Speter *    must display the following acknowledgement:
33289177Speter *    "This product includes cryptographic software written by
34289177Speter *     Eric Young (eay@cryptsoft.com)"
35289177Speter *    The word 'cryptographic' can be left out if the rouines from the library
36289177Speter *    being used are not cryptographic related :-).
37289177Speter * 4. If you include any Windows specific code (or a derivative thereof) from
38289177Speter *    the apps directory (application code) you must include an acknowledgement:
39289177Speter *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40289177Speter *
41289177Speter * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42289177Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43289177Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44289177Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45289177Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46289177Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47289177Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48289177Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49289177Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50289177Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51289177Speter * SUCH DAMAGE.
52289177Speter *
53289177Speter * The licence and distribution terms for any publically available version or
54289177Speter * derivative of this code cannot be changed.  i.e. this code cannot simply be
55289177Speter * copied and put under another distribution licence
56289177Speter * [including the GNU Public Licence.]
57289177Speter */
58289177Speter
59289177Speter#include <stdio.h>
60289177Speter#include <openssl/dsa.h>
61289177Speter
62289177Speter#define TEST
63289177Speter#define GENUINE_DSA
64289177Speter
65289177Speter#ifdef GENUINE_DSA
66289177Speter#define LAST_VALUE 0xbd
67289177Speter#else
68289177Speter#define LAST_VALUE 0xd3
69289177Speter#endif
70289177Speter
71289177Speter#ifdef TEST
72362181Sdimunsigned char seed[20]={
73289177Speter	0xd5,0x01,0x4e,0x4b,
74289177Speter	0x60,0xef,0x2b,0xa8,
75289177Speter	0xb6,0x21,0x1b,0x40,
76362181Sdim	0x62,0xba,0x32,0x24,
77289177Speter	0xe0,0x42,0x7d,LAST_VALUE};
78289177Speter#endif
79362181Sdim
80362181Sdimint cb(int p, int n)
81289177Speter	{
82289177Speter	char c='*';
83289177Speter
84289177Speter	if (p == 0) c='.';
85289177Speter	if (p == 1) c='+';
86362181Sdim	if (p == 2) c='*';
87289177Speter	if (p == 3) c='\n';
88289177Speter	printf("%c",c);
89289177Speter	fflush(stdout);
90289177Speter	}
91289177Speter
92289177Spetermain()
93289177Speter	{
94289177Speter	int i;
95289177Speter	BIGNUM *n;
96289177Speter	BN_CTX *ctx;
97289177Speter	unsigned char seed_buf[20];
98289177Speter	DSA *dsa;
99289177Speter	int counter,h;
100289177Speter	BIO *bio_err=NULL;
101289177Speter
102289177Speter	if (bio_err == NULL)
103289177Speter		bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
104289177Speter
105289177Speter	memcpy(seed_buf,seed,20);
106289177Speter	dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb,bio_err);
107289177Speter
108289177Speter	if (dsa == NULL)
109289177Speter		DSA_print(bio_err,dsa,0);
110289177Speter	}
111289177Speter
112289177Speter