1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcrypto/test/tasymmetric/script_gen/gen_rsakey.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,86 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Generate an RSA key.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +
1.25 +/**
1.26 + @file
1.27 +*/
1.28 +
1.29 +#include <stdio.h>
1.30 +#include <openssl/crypto.h>
1.31 +#include <openssl/rand.h>
1.32 +#include <openssl/rsa.h>
1.33 +#include <openssl/bn.h>
1.34 +#include "utils.h"
1.35 +
1.36 +#ifndef BOOL
1.37 +#define BOOL int
1.38 +#define TRUE 1
1.39 +#define FALSE 0
1.40 +#endif
1.41 +
1.42 +static void printRSAKey(RSA* key)
1.43 + {
1.44 + printf("static RSA* createRSAKey()\n");
1.45 + printf("\t{\n");
1.46 +
1.47 + printCBN("n_data", key->n);
1.48 + printCBN("e_data", key->e);
1.49 + printCBN("d_data", key->d);
1.50 +
1.51 + printf("\tRSA* key = RSA_new();\n");
1.52 + printf("\tkey->n = BN_new();\n");
1.53 + printf("\tkey->e = BN_new();\n");
1.54 + printf("\tkey->d = BN_new();\n");
1.55 +
1.56 + printf("\tBN_bin2bn(n_data, n_data_len, key->n);\n");
1.57 + printf("\tBN_bin2bn(e_data, e_data_len, key->e);\n");
1.58 + printf("\tBN_bin2bn(d_data, d_data_len, key->d);\n");
1.59 +
1.60 + printf("\treturn key;\n");
1.61 +
1.62 + printf("\t}\n");
1.63 + }
1.64 +
1.65 +static const char rnd_seed[] = "string to make the random number generator think it has entropy";
1.66 +
1.67 +static void badUsage()
1.68 + {
1.69 + printf("usage: gen_rsakey\n");
1.70 + exit(1);
1.71 + }
1.72 +
1.73 +int main(int argc, char **argv)
1.74 + {
1.75 + RSA *rsa;
1.76 + int modulus_size = 1024;
1.77 + int exponent = 65537;
1.78 +
1.79 + if (argc > 1)
1.80 + badUsage();
1.81 +
1.82 + RAND_seed(rnd_seed, sizeof rnd_seed);
1.83 +
1.84 + rsa = RSA_generate_key(modulus_size, exponent, NULL, NULL);
1.85 +
1.86 + printRSAKey(rsa);
1.87 +
1.88 + return 0;
1.89 + }