1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcrypto/test/tasymmetric/script_gen/gen_random.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,70 @@
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 +* Generates C code that initialises a variable to hold some random data.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +
1.25 +/**
1.26 + @file
1.27 +*/
1.28 +
1.29 +#include <openssl/rand.h>
1.30 +
1.31 +static void gen_random(int len)
1.32 + {
1.33 + unsigned char data[len];
1.34 + int i, j;
1.35 +
1.36 + RAND_bytes(data, len);
1.37 +
1.38 + printf("unsigned char random[] =");
1.39 + for (i = 0 ; i < sizeof(data) ; i += 16)
1.40 + {
1.41 + printf("\n\t\"");
1.42 + for (j = i ; j < sizeof(data) && j < (i + 16) ; ++j)
1.43 + {
1.44 + printf("\\x%02x", data[j]);
1.45 + }
1.46 + printf("\"");
1.47 + }
1.48 +
1.49 + printf(";\n");
1.50 + }
1.51 +
1.52 +static void badUsage()
1.53 + {
1.54 + printf("gen_random [BYTES]\n");
1.55 + exit(1);
1.56 + }
1.57 +
1.58 +int main(int argc, char* argv[])
1.59 + {
1.60 + int bytes = 256;
1.61 +
1.62 + if (argc > 2)
1.63 + badUsage();
1.64 + else if (argc == 2)
1.65 + {
1.66 + bytes = atoi(argv[1]);
1.67 + if (bytes < 1)
1.68 + badUsage();
1.69 + }
1.70 +
1.71 + gen_random(bytes);
1.72 + return 0;
1.73 + }