128021Sjoerg/* crypto/dsa/dsagen.c */
228021Sjoerg/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
328021Sjoerg * All rights reserved.
428021Sjoerg *
528021Sjoerg * This package is an SSL implementation written
628021Sjoerg * by Eric Young (eay@cryptsoft.com).
728021Sjoerg * The implementation was written so as to conform with Netscapes SSL.
828021Sjoerg *
928021Sjoerg * This library is free for commercial and non-commercial use as long as
1028021Sjoerg * the following conditions are aheared to.  The following conditions
1128021Sjoerg * apply to all code found in this distribution, be it the RC4, RSA,
1228021Sjoerg * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1328021Sjoerg * included with this distribution is covered by the same copyright terms
1428021Sjoerg * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1528021Sjoerg *
1628021Sjoerg * Copyright remains Eric Young's, and as such any Copyright notices in
1728021Sjoerg * the code are not to be removed.
1828021Sjoerg * If this package is used in a product, Eric Young should be given attribution
1928021Sjoerg * as the author of the parts of the library used.
2028021Sjoerg * This can be in the form of a textual message at program startup or
2128021Sjoerg * in documentation (online or textual) provided with the package.
2228021Sjoerg *
2328021Sjoerg * Redistribution and use in source and binary forms, with or without
2428021Sjoerg * modification, are permitted provided that the following conditions
2528021Sjoerg * are met:
2650476Speter * 1. Redistributions of source code must retain the copyright
2728021Sjoerg *    notice, this list of conditions and the following disclaimer.
2828021Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
2971579Sdeischen *    notice, this list of conditions and the following disclaimer in the
3028021Sjoerg *    documentation and/or other materials provided with the distribution.
3128021Sjoerg * 3. All advertising materials mentioning features or use of this software
3228021Sjoerg *    must display the following acknowledgement:
3328021Sjoerg *    "This product includes cryptographic software written by
3428021Sjoerg *     Eric Young (eay@cryptsoft.com)"
3551186Sdt *    The word 'cryptographic' can be left out if the rouines from the library
3628021Sjoerg *    being used are not cryptographic related :-).
3728021Sjoerg * 4. If you include any Windows specific code (or a derivative thereof) from
3871579Sdeischen *    the apps directory (application code) you must include an acknowledgement:
3971579Sdeischen *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4071579Sdeischen *
4128021Sjoerg * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4228021Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4328021Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4451186Sdt * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4551186Sdt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4651186Sdt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4772167Sphantom * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4872167Sphantom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4928021Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5051186Sdt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5151186Sdt * SUCH DAMAGE.
5251186Sdt *
5353940Sache * The licence and distribution terms for any publically available version or
5453960Sache * derivative of this code cannot be changed.  i.e. this code cannot simply be
5551186Sdt * copied and put under another distribution licence
5672167Sphantom * [including the GNU Public Licence.]
5728021Sjoerg */
5828021Sjoerg
5928021Sjoerg#include <stdio.h>
6028021Sjoerg#include <openssl/dsa.h>
6128021Sjoerg
6228021Sjoerg#define TEST
6328021Sjoerg#define GENUINE_DSA
6428021Sjoerg
6528021Sjoerg#ifdef GENUINE_DSA
6628021Sjoerg# define LAST_VALUE 0xbd
6728021Sjoerg#else
6828021Sjoerg# define LAST_VALUE 0xd3
6928021Sjoerg#endif
7028021Sjoerg
7128021Sjoerg#ifdef TEST
7228021Sjoergunsigned char seed[20] = {
7328021Sjoerg    0xd5, 0x01, 0x4e, 0x4b,
7428021Sjoerg    0x60, 0xef, 0x2b, 0xa8,
7528021Sjoerg    0xb6, 0x21, 0x1b, 0x40,
7628021Sjoerg    0x62, 0xba, 0x32, 0x24,
7728021Sjoerg    0xe0, 0x42, 0x7d, LAST_VALUE
7828021Sjoerg};
7928021Sjoerg#endif
8028021Sjoerg
8128021Sjoergint cb(int p, int n)
8228021Sjoerg{
8328021Sjoerg    char c = '*';
8428021Sjoerg
8567634Sache    if (p == 0)
8628021Sjoerg        c = '.';
8767634Sache    if (p == 1)
8828021Sjoerg        c = '+';
8928021Sjoerg    if (p == 2)
9028021Sjoerg        c = '*';
9128021Sjoerg    if (p == 3)
9228021Sjoerg        c = '\n';
9328021Sjoerg    printf("%c", c);
9428021Sjoerg    fflush(stdout);
9528021Sjoerg}
9653960Sache
9751186Sdtmain()
9851186Sdt{
9951186Sdt    int i;
10051186Sdt    BIGNUM *n;
10153940Sache    BN_CTX *ctx;
10253940Sache    unsigned char seed_buf[20];
10353960Sache    DSA *dsa;
10453960Sache    int counter, h;
10553940Sache    BIO *bio_err = NULL;
10653960Sache
10753960Sache    if (bio_err == NULL)
10853960Sache        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
10953960Sache
11053960Sache    memcpy(seed_buf, seed, 20);
11153960Sache    dsa = DSA_generate_parameters(1024, seed, 20, &counter, &h, cb, bio_err);
11228021Sjoerg
11328021Sjoerg    if (dsa == NULL)
11472167Sphantom        DSA_print(bio_err, dsa, 0);
11572167Sphantom}
11672167Sphantom