Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
27 #include <openssl/crypto.h>
28 #include <openssl/rand.h>
29 #include <openssl/dsa.h>
30 #include <openssl/bn.h>
39 static void printDSAKey(DSA* key)
41 printf("static DSA* createDSAKey()\n");
44 printCBN("p_data", key->p);
45 printCBN("q_data", key->q);
46 printCBN("g_data", key->g);
47 printCBN("priv_key_data", key->priv_key);
48 printCBN("pub_key_data", key->pub_key);
50 printf("\tDSA* key = DSA_new();\n");
51 printf("\tkey->p = BN_new();\n");
52 printf("\tkey->q = BN_new();\n");
53 printf("\tkey->g = BN_new();\n");
54 printf("\tkey->priv_key = BN_new();\n");
55 printf("\tkey->pub_key = BN_new();\n\n");
57 printf("\tBN_bin2bn(p_data, p_data_len, key->p);\n");
58 printf("\tBN_bin2bn(q_data, q_data_len, key->q);\n");
59 printf("\tBN_bin2bn(g_data, g_data_len, key->g);\n");
60 printf("\tBN_bin2bn(pub_key_data, pub_key_data_len, key->pub_key);\n");
61 printf("\tBN_bin2bn(priv_key_data, priv_key_data_len, key->priv_key);\n\n");
63 printf("\treturn key;\n");
69 * This is the seed used in the openssl test code. Using it (by
70 * specifying the -use_seed option) makes this program generate the
71 * same key used in the openssl test code
73 * It comes from the updated Appendix 5 to FIPS PUB 186.
76 static unsigned char seed[20]={
77 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
78 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
81 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
83 static void badUsage()
85 printf("usage: gen_dsakey [ -use_seed ]\n");
89 int main(int argc, char **argv)
92 int counter,ret=0,i,j;
93 unsigned char buf[256];
95 unsigned char sig[256];
103 if (strcmp(argv[1], "-use_seed") != 0)
108 RAND_seed(rnd_seed, sizeof rnd_seed);
110 dsa=DSA_generate_parameters(512,useSeed ? seed : NULL,20,&counter,&h,NULL,NULL);
112 DSA_generate_key(dsa);