diff --git a/tools/itscertgen/generator/ecc_keygen.c b/tools/itscertgen/generator/ecc_keygen.c new file mode 100644 index 0000000000000000000000000000000000000000..33bcfb1a47a5179921f527ec47a967d25c759a24 --- /dev/null +++ b/tools/itscertgen/generator/ecc_keygen.c @@ -0,0 +1,66 @@ +/********************************************************************* +###################################################################### +## +## Created by: Denis Filatov +## +## Copyleft (c) 2015 +## This code is provided under the CeCill-C license agreement. +###################################################################### +*********************************************************************/ +#include "ecc_api.h" +#include +#include "../cshared/copts.h" +#include "../cshared/cstr.h" + +static const char *_outPath = "."; +static int _outFormat = 0; +static int _certCount = 1; +static int _compressed = 0; + +static const char * _o_formats[] = { + "bin", "hex", "pem", NULL +}; + +static copt_t options [] = { + { "h?", "help", COPT_HELP, NULL, "Print this help page" }, + { "o", "out", COPT_STR, (void*)&_outPath, "Output path [current dir by default]" }, + { "O", "format", COPT_STRENUM, (void*)_o_formats, "Output format (bin|hex|pem)[binary by default]" }, + { "n", "count", COPT_INT, (void*)&_certCount, "Key pair count (1 by default)" }, + { NULL, NULL, COPT_END, NULL, NULL } +}; + +int main(int argc, char** argv) +{ + argc = coptions(argc, argv, COPT_HELP_NOVALUES , options); + + if(argc < 1){ + if(argc<0 && (0-argc)<((sizeof(options)/sizeof(options[0]))-1)){ + printf("Unknown option %s\n", argv[0-argc]); + } + const char * a = strrchr(argv[0], '/'); + if (a == NULL) a = argv[0]; + coptions_help(stdout, a, COPT_HELP_NOVALUES, options, " [signer]"); + return -1; + } + _outFormat = copts_enum_value(options, 2, _o_formats); + + if(0 == ecc_api_init()){ + char s[1024], *path; + int len; + path = cvstrncpy(s, sizeof(s), _outPath, "/", NULL); + len = s+sizeof(s)-path; + for(int count = 0; count < _certCount; count++){ + void * key = ecc_api_key_gen(ecdsa_nistp256_with_sha256, aes_128_ccm); + if(key){ + int nlen = sprintf(path, "key_%03d", count+1); + cstrncpy(path + nlen, len - nlen, ".prv"); + ecc_api_key_private_save(key, s, _outFormat); + cstrncpy(path + nlen, len - nlen, ".pub"); + ecc_api_key_public_save(key, s, _outFormat); + ecc_api_key_free(key); + } + } + } + ecc_api_done(); + return 0; +} diff --git a/tools/itscertgen/generator/ecc_keygen.vcxproj b/tools/itscertgen/generator/ecc_keygen.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..d7731476356905c915567e8db5f64d9bededb71f --- /dev/null +++ b/tools/itscertgen/generator/ecc_keygen.vcxproj @@ -0,0 +1,109 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + false + + + + + + + + {d5918b85-fa45-4f75-9b50-c2d3e34aba17} + + + {cbfc4bfa-fe7e-45fb-ae2f-2608b7c0ad07} + + + + {38CBB245-1E96-4010-8E21-4C58EAA7122A} + Win32Proj + itscertgen + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + true + $(SolutionDir)build\msvc\$(Configuration)\ + $(SolutionDir)build\msvc\$(Configuration)\$(ProjectName)\ + + + false + $(SolutionDir)build\msvc\$(Configuration)\ + $(SolutionDir)build\msvc\$(Configuration)\$(ProjectName)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + C:\OpenSSL\Win32\include;.. + + + Console + true + C:\OpenSSL\Win32\lib\VC\static + libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + C:\OpenSSL\Win32\include;.. + + + Console + true + true + true + libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies) + C:\OpenSSL\Win32\lib\VC\static + + + + + + \ No newline at end of file diff --git a/tools/itscertgen/itscertgen.sln b/tools/itscertgen/itscertgen.sln index 22da1cfef273dac7666307924b1f8ebacf8bb8b3..9271276695926c4d9562a22c7fe4bb21ca69158b 100644 --- a/tools/itscertgen/itscertgen.sln +++ b/tools/itscertgen/itscertgen.sln @@ -17,6 +17,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "itscertinfo", "checker\itsc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msgcheck", "msgcheck\msgcheck.vcxproj", "{D6D77DDB-032E-4E26-AEC3-7BA9D955D476}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ecc_keygen", "generator\ecc_keygen.vcxproj", "{38CBB245-1E96-4010-8E21-4C58EAA7122A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -43,6 +45,10 @@ Global {D6D77DDB-032E-4E26-AEC3-7BA9D955D476}.Debug|Win32.Build.0 = Debug|Win32 {D6D77DDB-032E-4E26-AEC3-7BA9D955D476}.Release|Win32.ActiveCfg = Release|Win32 {D6D77DDB-032E-4E26-AEC3-7BA9D955D476}.Release|Win32.Build.0 = Release|Win32 + {38CBB245-1E96-4010-8E21-4C58EAA7122A}.Debug|Win32.ActiveCfg = Debug|Win32 + {38CBB245-1E96-4010-8E21-4C58EAA7122A}.Debug|Win32.Build.0 = Debug|Win32 + {38CBB245-1E96-4010-8E21-4C58EAA7122A}.Release|Win32.ActiveCfg = Release|Win32 + {38CBB245-1E96-4010-8E21-4C58EAA7122A}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE