Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 1909 → Rev 1910

/branches/Security/tools/itscertgen/certgen.c
170,7 → 170,7
{
while (*v && isspace(*v))v++;
if (*v){
int i;
size_t i;
for (i = 0; i<size; i++){
if (values[i] && 0 == strcmp(values[i], v)) {
return i;
215,7 → 215,7
return -1;
}
 
static copt_t options [] = {
static const copt_t options [] = {
{ "h?", "help", COPT_HELP, NULL, "Print this help page" },
{ "i", "in", COPT_STR, &_searchPath, "Certificates search path [Output path by default]" },
{ "o", "out", COPT_STR, &_outPath, "Output path [current dir by default]" },
820,7 → 820,7
//next try to convert ISO text representation
memset(&tm, 0, sizeof(tm));
if (3 == sscanf(v, "%d-%d-%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday)){
ret = mktaitime(&tm);
ret = (unsigned int)mktaitime(&tm);
if (ret == (time_t)-1){
fprintf(stderr, "%s: Date format specification error. Use YYY-MM-DD\n", v);
ret = 0;
/branches/Security/tools/itscertgen/cshared/copts.c
29,6 → 29,12
 
#include "copts.h"
 
#ifdef _MSC_VER
#define inline __inline
#define strcasecmp stricmp
#define strdup _strdup
#endif
 
#define COPT_AFLAG_ERROR 0x10000
#define COPT_AFLAG_PRESCAN 0x08000
#define COPT_AFLAG_LOPT 0x04000
384,7 → 390,7
if(value.v_long>SHRT_MAX || value.v_long<SHRT_MIN){
return -1;
}
value.v_short = value.v_long;
value.v_short = (short) value.v_long;
break;
case COPT_USHORT:
if(!val || !opt->vptr) return -1;
393,7 → 399,7
if(value.v_ulong>USHRT_MAX){
return -1;
}
value.v_ushort = value.v_ulong;
value.v_ushort = (unsigned short) value.v_ulong;
break;
 
case COPT_CHAR:
406,7 → 412,7
if(value.v_ulong>UCHAR_MAX){
return -1;
}
value.v_char = value.v_long;
value.v_char = (unsigned char)value.v_long;
}
break;
case COPT_STRENUM:
467,7 → 473,7
}
break;
case COPT_STRENUM:
opt->vptr = ((const char**)opt->vptr) + value.v_long;
opt->vptr = (void*)(((const char**)opt->vptr) + value.v_long);
break;
case COPT_SHORT:
case COPT_USHORT:
744,7 → 750,7
if( t == COPT_STR
|| t == COPT_STRLIST
){
if(0==strcmp("NULL", val) || 0==strcmp("null", val)) val = NULL;
if(0==strcmp("NULL", val) || 0==strcmp("null", val)) val = NULL;
else val = strdup(val);
}
 
/branches/Security/tools/itscertgen/cshared/cserialize.c
157,9 → 157,6
uint64_t overflow = 0;
while(value >= overflow){
num_bytes++;
if(num_bytes > maxsize){
return -1;
}
overflow = one64 << (7*num_bytes);
}
#endif
/branches/Security/tools/itscertgen/cshared/cserialize.h
6,10 → 6,16
extern "C" {
#endif
 
#ifdef __GNUC__
#if defined(__GNUC__)
# define cint64_swap(X) __builtin_bswap64(X)
# define cint32_swap(X) __builtin_bswap32(X)
# define cint16_swap(X) __builtin_bswap16(X)
#elif defined (_MSC_VER)
# define cint64_swap(X) _byteswap_uint64(X)
# define cint32_swap(X) _byteswap_ulong (X)
# define cint16_swap(X) _byteswap_ushort(X)
#define __ORDER_LITTLE_ENDIAN__ 1
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#else
uint64_t cint64_swap(const uint64_t);
uint32_t cint32_swap(const uint32_t);
/branches/Security/tools/itscertgen/cshared/cshared.vcxproj
0,0 → 1,89
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="copts.c" />
<ClCompile Include="cserialize.c" />
<ClCompile Include="cstr.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="copts.h" />
<ClInclude Include="cserialize.h" />
<ClInclude Include="cstr.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cshared</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)msvc\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)msvc\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
/branches/Security/tools/itscertgen/cxml/cxml.c
3,6 → 3,11
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
 
#ifdef _MSC_VER
#define inline __inline
#endif
 
#ifdef DEBUG
//#define DEBUG_XML_STRUCTURE
#include <signal.h>
219,7 → 224,7
return ret;
}
 
typedef int (cxml_tag_f) (cxml_handler_t* const h, cxml_tag_t * const tag);
//typedef int (*cxml_tag_f) (cxml_handler_t* const h, cxml_tag_t * const tag);
 
static int cxml_call_handler(cxml_tag_f * handler, cxml_handler_t * const h, cxml_tag_t * const tag)
{
/branches/Security/tools/itscertgen/cxml/cxml.h
1,153 → 1,165
#ifndef cxml_h
#define cxml_h
 
typedef struct cxml_attr_t cxml_attr_t;
typedef struct cxml_tag_t cxml_tag_t;
struct cxml_attr_t
{
cxml_attr_t * next;
const char * name;
const char * value;
};
#ifdef __cplusplus
extern "C" {
#endif
 
typedef enum {
CXML_TAG_SYSTEM = 0,
CXML_TAG_OPEN,
CXML_TAG_CLOSE,
CXML_TAG_AUTOCLOSE,
CXML_TAG_COMMENT,
/* internal tag types */
CXML_TAG_CDATA=8,
CXML_TAG_ENTITY=12,
}cxml_tag_type;
#if defined(_DEBUG) && !defined(DEBUG)
#define DEBUG _DEBUG
#endif
 
typedef struct cxml_attr_t cxml_attr_t;
typedef struct cxml_tag_t cxml_tag_t;
struct cxml_attr_t
{
cxml_attr_t * next;
const char * name;
const char * value;
};
 
typedef enum {
CXML_TAG_SYSTEM = 0,
CXML_TAG_OPEN,
CXML_TAG_CLOSE,
CXML_TAG_AUTOCLOSE,
CXML_TAG_COMMENT,
/* internal tag types */
CXML_TAG_CDATA = 8,
CXML_TAG_ENTITY = 12,
}cxml_tag_type;
 
#define cxml_tag_is_open(tag) (tag->type & CXML_TAG_OPEN)
#define cxml_tag_is_close(tag) (tag->type & CXML_TAG_CLOSE)
 
struct cxml_tag_t
{
int ucount;
cxml_tag_type type;
const char * nspace;
const char * name;
cxml_attr_t * attributes;
};
struct cxml_tag_t
{
int ucount;
cxml_tag_type type;
const char * nspace;
const char * name;
cxml_attr_t * attributes;
};
 
typedef struct cxml_handler_t cxml_handler_t;
typedef struct cxml_handler_class cxml_handler_class;
typedef struct cxml_entity_t cxml_entity_t;
typedef struct cxml_handler_t cxml_handler_t;
typedef struct cxml_handler_class cxml_handler_class;
typedef struct cxml_entity_t cxml_entity_t;
 
typedef int (cxml_doc_f) (cxml_handler_t* const h, int rc);
typedef int (cxml_tag_f) (cxml_handler_t* const h, cxml_tag_t * const tag);
typedef int (cxml_text_f) (cxml_handler_t* const h, char * const text);
typedef int (cxml_doc_f)(cxml_handler_t* const h, int rc);
typedef int (cxml_tag_f)(cxml_handler_t* const h, cxml_tag_t * const tag);
typedef int (cxml_text_f)(cxml_handler_t* const h, char * const text);
 
typedef void * (cxml_alloc_f)(unsigned int);
typedef void (cxml_free_f) (void *);
typedef void * (cxml_alloc_f)(unsigned int);
typedef void (cxml_free_f)(void *);
 
struct cxml_handler_t
{
const cxml_handler_class * Class;
const char * File;
const char * Version;
const char * Encoding;
const char * WaitTag;
cxml_entity_t * Entities;
};
struct cxml_handler_t
{
const cxml_handler_class * Class;
const char * File;
const char * Version;
const char * Encoding;
const char * WaitTag;
cxml_entity_t * Entities;
};
 
struct cxml_handler_class
{
unsigned int size;
cxml_doc_f * doc_begin;
cxml_doc_f * doc_end;
cxml_tag_f * tag_begin;
cxml_tag_f * tag_end;
cxml_text_f * text;
struct cxml_handler_class
{
unsigned int size;
cxml_doc_f * doc_begin;
cxml_doc_f * doc_end;
cxml_tag_f * tag_begin;
cxml_tag_f * tag_end;
cxml_text_f * text;
 
/* Allocation halpers.
* Can be NULL to use default ones */
cxml_alloc_f * tag_alloc;
cxml_free_f * tag_free;
cxml_alloc_f * alloc;
cxml_free_f * free;
};
/* Allocation halpers.
* Can be NULL to use default ones */
cxml_alloc_f * tag_alloc;
cxml_free_f * tag_free;
cxml_alloc_f * alloc;
cxml_free_f * free;
};
 
struct cxml_entity_t
{
cxml_entity_t * next;
int nlen;
const char * name;
int vlen;
char value[];
};
struct cxml_entity_t
{
cxml_entity_t * next;
int nlen;
const char * name;
int vlen;
char value[];
};
 
void cxml_handler_init(void * const h, const cxml_handler_class * const Class);
void * cxml_handler_new(const cxml_handler_class * const Class);
void cxml_handler_delete(void * const h);
void cxml_handler_close(void * const h);
void cxml_handler_init(void * const h, const cxml_handler_class * const Class);
void * cxml_handler_new(const cxml_handler_class * const Class);
void cxml_handler_delete(void * const h);
void cxml_handler_close(void * const h);
 
int cxml_handler_parse(void * const h, char* const text);
int cxml_handler_parse_file(void * const h, const char * file);
int cxml_handler_parse(void * const h, char* const text);
int cxml_handler_parse_file(void * const h, const char * file);
#if defined(SEEK_SET) || defined (_FILE_DEFINED)
#define _CXML_HANDLER_PARSE_STREAM_DEFINED
int cxml_handler_parse_stream(void * const h, FILE * f);
int cxml_handler_parse_stream(void * const h, FILE * f);
#endif
 
/* Internal functions for tags manipulations */
cxml_tag_t * cxml_tag_new(void * const h, const cxml_tag_type type, const char * const name);
cxml_tag_t * cxml_tag_use(cxml_tag_t * const tag);
void cxml_tag_free(void * const h, cxml_tag_t * const tag);
void cxml_wait_for_close(void * const p, cxml_tag_t * const tag);
/* Internal functions for tags manipulations */
cxml_tag_t * cxml_tag_new(void * const h, const cxml_tag_type type, const char * const name);
cxml_tag_t * cxml_tag_use(cxml_tag_t * const tag);
void cxml_tag_free(void * const h, cxml_tag_t * const tag);
void cxml_wait_for_close(void * const p, cxml_tag_t * const tag);
 
cxml_attr_t * cxml_attr_new(void * const h, const char * const name);
void cxml_attr_free(void * const h, cxml_attr_t * const a);
cxml_attr_t * cxml_attr_new(void * const h, const char * const name);
void cxml_attr_free(void * const h, cxml_attr_t * const a);
 
int cxml_tag_is(const cxml_tag_t * const tag, const char * const tagname);
int cxml_tag_has_attr(cxml_tag_t * const tag, const char * const key);
const char * cxml_tag_attr_value(cxml_tag_t * const tag, const char * const key);
int cxml_tag_attr_int(cxml_tag_t * const tag, const char * const key);
unsigned int cxml_tag_attr_uint(cxml_tag_t * const tag, const char * const key);
int cxml_tag_attr_boolean(cxml_tag_t * const tag, const char * const key);
int cxml_tag_is(const cxml_tag_t * const tag, const char * const tagname);
int cxml_tag_has_attr(cxml_tag_t * const tag, const char * const key);
const char * cxml_tag_attr_value(cxml_tag_t * const tag, const char * const key);
int cxml_tag_attr_int(cxml_tag_t * const tag, const char * const key);
unsigned int cxml_tag_attr_uint(cxml_tag_t * const tag, const char * const key);
int cxml_tag_attr_boolean(cxml_tag_t * const tag, const char * const key);
 
int cxml_handler_add_entity(void * const h, const char * const name, char * const value, const int value_len);
int cxml_handler_add_entity_from_tag(void * const h, cxml_tag_t * const tag);
int cxml_handler_add_entity(void * const h, const char * const name, char * const value, const int value_len);
int cxml_handler_add_entity_from_tag(void * const h, cxml_tag_t * const tag);
 
int cxml_text_decode(void * const handler, char * const src, int const srclen);
int cxml_text_encode(void * const handler, char * * const p_dst,
const char * const src, int const srclen);
int cxml_text_decode(void * const handler, char * const src, int const srclen);
int cxml_text_encode(void * const handler, char * * const p_dst,
const char * const src, int const srclen);
 
/** Utility function to process basic DCMI encoding */
int cxml_to_dcmi (char ** const pdst, const char * const src, int const len);
/** Utility function to process basic DCMI encoding */
int cxml_to_dcmi(char ** const pdst, const char * const src, int const len);
 
/** XML states and tag handlers support */
typedef struct cxml_taghandler_t cxml_taghandler_t;
/** XML states and tag handlers support */
typedef struct cxml_taghandler_t cxml_taghandler_t;
 
struct cxml_taghandler_t
{
const char * tagname;
cxml_tag_f * on_tag;
cxml_text_f * on_text;
const cxml_taghandler_t * childs;
};
struct cxml_taghandler_t
{
const char * tagname;
cxml_tag_f * on_tag;
cxml_text_f * on_text;
const cxml_taghandler_t * childs;
};
#define CXML_HDEFAULT ((const char *)1)
#define CXML_HCOMMENT ((const char *)2)
#define CXML_HSYSTEM ((const char *)3)
 
void * cxml_st_handler_new (const cxml_handler_class * const Class,
const cxml_taghandler_t * const Handlers);
void cxml_st_handler_delete(void * const h);
void * cxml_st_handler_new(const cxml_handler_class * const Class,
const cxml_taghandler_t * const Handlers);
void cxml_st_handler_delete(void * const h);
 
const cxml_tag_t * cxml_st_current_tag (void * const h);
const cxml_tag_t * cxml_st_current_tag(void * const h);
 
void * cxml_alloc(void * const h, unsigned int size);
void cxml_free(void * const h, void const * ptr);
void * cxml_alloc(void * const h, unsigned int size);
void cxml_free(void * const h, void const * ptr);
 
#ifdef DEBUG
#define ASSERT_RETURN(RC) do {return cxml_checkassert(RC);}while(0)
#define ASSERT_GOTO(LABEL) do {cxml_assert(); goto LABEL; }while(0)
void cxml_assert(void);
int cxml_checkassert(int rc);
void cxml_assert(void);
int cxml_checkassert(int rc);
#else
#define ASSERT_RETURN(RC) return RC
#define ASSERT_GOTO(LABEL) goto LABEL
#endif
#endif
 
#ifdef __cplusplus
}
#endif
/branches/Security/tools/itscertgen/cxml/cxml.vcxproj
0,0 → 1,90
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="cxml.c" />
<ClCompile Include="cxmlst.c" />
<ClCompile Include="cxml_dcmi.c" />
<ClCompile Include="cxml_decode.c" />
<ClCompile Include="cxml_encode.c" />
<ClCompile Include="cxml_entity.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cxml.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>cxml</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)msvc\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)msvc\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
/branches/Security/tools/itscertgen/cxml/cxml_dcmi.c
120,7 → 120,7
return -1;
}
if(val > 0xFF){
*p++ = (val>>8);
*p++ = (char)(val>>8);
}
*p++ = val&0xFF;
e++;
/branches/Security/tools/itscertgen/ecc_openssl.c
1,205 → 1,205
#include "ecc_api.h"
 
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
#include <openssl/sha.h>
#include <openssl/ecdsa.h>
 
static const int _NIDS[] = {
NID_secp256k1,
NID_secp256k1
};
static EVP_PKEY_CTX *pctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY_CTX *kctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY *params[sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
 
int ecc_api_init()
{
int i;
int rc = -1;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
/* Create the context for generating the parameters */
pctx[i] = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if(pctx[i]){
if(EVP_PKEY_paramgen_init(pctx[i])){
/* Set the paramgen parameters according to the type */
if(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx[i], _NIDS[i])){
/* Generate parameters */
if (EVP_PKEY_paramgen(pctx[i], &params[i])) {
/* Create context for the key generation */
kctx[i] = EVP_PKEY_CTX_new(params[i], NULL);
if(kctx[i]){
if(EVP_PKEY_keygen_init(kctx[i])){
rc = 0;
continue;
}
}
}
}
}
}
ERR_print_errors_fp(stderr);
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
}
return rc;
}
 
int ecc_api_done()
{
int i;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
}
return 0;
}
 
void * ecc_api_key_gen (ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg)
{
EVP_PKEY * key = NULL;
if(!EVP_PKEY_keygen(kctx[pk_alg], &key)){
ERR_print_errors_fp(stderr);
}
return (void*)key;
}
void ecc_api_key_free(void* key)
{
EVP_PKEY_free((EVP_PKEY*)key);
}
 
int ecc_api_key_private(void* key, char* buf)
{
int len = -1;
const EC_KEY * eckey;
eckey = EVP_PKEY_get1_EC_KEY((EVP_PKEY*)key);
if(eckey){
const BIGNUM * ecbn;
ecbn = EC_KEY_get0_private_key(eckey);
if(ecbn){
len = BN_num_bytes(ecbn);
if(buf){
BN_bn2bin(ecbn, (unsigned char*)buf);
}
}
}
return len;
}
int ecc_api_key_public(void* key, char * px, char * py)
{
const EC_KEY * eckey;
const EC_GROUP * ecgroup;
const EC_POINT * ecpoint;
BIGNUM x, y;
int bcount = -1;
eckey = EVP_PKEY_get1_EC_KEY(key);
ecgroup = EC_KEY_get0_group(eckey);
ecpoint = EC_KEY_get0_public_key(eckey);
 
//fill public key data
BN_init(&x); BN_init(&y);
if(EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, &x, &y, NULL)){
bcount = BN_num_bytes(&x);
if(px){
BN_bn2bin(&x, (unsigned char*)px);
}
 
bcount = BN_num_bytes(&y);
if(py){
BN_bn2bin(&x, (unsigned char*)py);
}
}
BN_clear_free(&x); BN_clear_free(&y);
return bcount;
}
#include "ecc_api.h"
 
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
#include <openssl/sha.h>
#include <openssl/ecdsa.h>
 
static const int _NIDS[] = {
NID_secp256k1,
NID_secp256k1
};
static EVP_PKEY_CTX *pctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY_CTX *kctx [sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
static EVP_PKEY *params[sizeof(_NIDS)/sizeof(_NIDS[0])] = {NULL};
 
int ecc_api_init()
{
int i;
int rc = -1;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
/* Create the context for generating the parameters */
pctx[i] = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if(pctx[i]){
if(EVP_PKEY_paramgen_init(pctx[i])){
/* Set the paramgen parameters according to the type */
if(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx[i], _NIDS[i])){
/* Generate parameters */
if (EVP_PKEY_paramgen(pctx[i], &params[i])) {
/* Create context for the key generation */
kctx[i] = EVP_PKEY_CTX_new(params[i], NULL);
if(kctx[i]){
if(EVP_PKEY_keygen_init(kctx[i])){
rc = 0;
continue;
}
}
}
}
}
}
ERR_print_errors_fp(stderr);
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
}
return rc;
}
 
int ecc_api_done()
{
int i;
for(i=0; i<sizeof(_NIDS)/sizeof(_NIDS[0]); i++){
if(kctx[i])EVP_PKEY_CTX_free(kctx[i]);kctx[i] = NULL;
if(params[i])EVP_PKEY_free(params[i]);params[i] = NULL;
if(pctx[i])EVP_PKEY_CTX_free(pctx[i]);pctx[i] = NULL;
}
return 0;
}
 
void * ecc_api_key_gen (ecc_pk_algorithm pk_alg, ecc_sym_algorithm sym_alg)
{
EVP_PKEY * key = NULL;
if(!EVP_PKEY_keygen(kctx[pk_alg], &key)){
ERR_print_errors_fp(stderr);
}
return (void*)key;
}
void ecc_api_key_free(void* key)
{
EVP_PKEY_free((EVP_PKEY*)key);
}
 
int ecc_api_key_private(void* key, char* buf)
{
int len = -1;
const EC_KEY * eckey;
eckey = EVP_PKEY_get1_EC_KEY((EVP_PKEY*)key);
if(eckey){
const BIGNUM * ecbn;
ecbn = EC_KEY_get0_private_key(eckey);
if(ecbn){
len = BN_num_bytes(ecbn);
if(buf){
BN_bn2bin(ecbn, (unsigned char*)buf);
}
}
}
return len;
}
int ecc_api_key_public(void* key, char * px, char * py)
{
const EC_KEY * eckey;
const EC_GROUP * ecgroup;
const EC_POINT * ecpoint;
BIGNUM x, y;
int bcount = -1;
eckey = EVP_PKEY_get1_EC_KEY(key);
ecgroup = EC_KEY_get0_group(eckey);
ecpoint = EC_KEY_get0_public_key(eckey);
 
//fill public key data
BN_init(&x); BN_init(&y);
if(EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, &x, &y, NULL)){
bcount = BN_num_bytes(&x);
if(px){
BN_bn2bin(&x, (unsigned char*)px);
}
 
bcount = BN_num_bytes(&y);
if(py){
BN_bn2bin(&x, (unsigned char*)py);
}
}
BN_clear_free(&x); BN_clear_free(&y);
return bcount;
}
 
static int _pass_cb(char *buf, int size, int rwflag, void *u)
{
fprintf(stderr, "Ask for a pass phrase");
return 0;
}
int ecc_api_key_private_save(void* key, const char* path)
{
int rc = -1;
FILE * f = fopen(path, "wb");
if(f){
}
int ecc_api_key_private_save(void* key, const char* path)
{
int rc = -1;
FILE * f = fopen(path, "wb");
if(f){
rc = PEM_write_PKCS8PrivateKey(f, key, NULL, NULL, 0, _pass_cb, NULL);
fclose(f);
if(!rc){
ERR_print_errors_fp(stderr);
remove(path);
rc = -1;
}
}else{
perror(path);
}
return rc;
}
 
void * ecc_api_key_private_load(const char* path)
{
EVP_PKEY * key = NULL;
FILE * f = fopen(path, "rb");
if(f){
key = PEM_read_PrivateKey(f, NULL, NULL, NULL);
fclose(f);
}
return key;
}
 
int sha256_calculate(char* hash, const char * ptr, int len)
{
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, ptr, len);
SHA256_Final((unsigned char*)hash, &ctx);
return 0;
}
 
int ecc_sign(void * key, const char * data, int length, char ** psig, int maxsize)
{
EC_KEY * eckey;
unsigned char *sig = (unsigned char *)*psig;
 
if (65 <= maxsize){
eckey = EC_KEY_dup(EVP_PKEY_get1_EC_KEY(key));
if(eckey){
unsigned char hash[32];
ECDSA_SIG * ecdsa;
SHA256_CTX ctx;
BIGNUM *kinv = NULL;
BIGNUM *rp = NULL;
 
SHA256_Init(&ctx);
SHA256_Update(&ctx, data, length);
SHA256_Final(hash, &ctx);
 
fclose(f);
if(!rc){
ERR_print_errors_fp(stderr);
remove(path);
rc = -1;
}
}else{
perror(path);
}
return rc;
}
 
void * ecc_api_key_private_load(const char* path)
{
EVP_PKEY * key = NULL;
FILE * f = fopen(path, "rb");
if(f){
key = PEM_read_PrivateKey(f, NULL, NULL, NULL);
fclose(f);
}
return key;
}
 
int sha256_calculate(char* hash, const char * ptr, int len)
{
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, ptr, len);
SHA256_Final((unsigned char*)hash, &ctx);
return 0;
}
 
int ecc_sign(void * key, const char * data, int length, char ** psig, int maxsize)
{
EC_KEY * eckey;
unsigned char *sig = (unsigned char *)*psig;
 
if (65 <= maxsize){
eckey = EC_KEY_dup(EVP_PKEY_get1_EC_KEY(key));
if(eckey){
unsigned char hash[32];
ECDSA_SIG * ecdsa;
SHA256_CTX ctx;
BIGNUM *kinv = NULL;
BIGNUM *rp = NULL;
 
SHA256_Init(&ctx);
SHA256_Update(&ctx, data, length);
SHA256_Final(hash, &ctx);
 
if (ECDSA_sign_setup(eckey, NULL, &kinv, &rp)){
ecdsa = ECDSA_do_sign_ex(hash, 32, kinv, rp, eckey);
EC_KEY_free(eckey);
BN_clear_free(kinv);
BN_clear_free(rp);
BN_clear_free(kinv);
BN_clear_free(rp);
if (ecdsa){
int bcount;
*(sig++) = 0; // x_coordinate_only
*(sig++) = 0; // x_coordinate_only
bcount = BN_num_bytes(ecdsa->r);
BN_bn2bin(ecdsa->r, sig);
sig += bcount;
BN_bn2bin(ecdsa->r, sig);
sig += bcount;
bcount = BN_num_bytes(ecdsa->s);
BN_bn2bin(ecdsa->s, sig);
sig += bcount;
BN_bn2bin(ecdsa->s, sig);
sig += bcount;
ECDSA_SIG_free(ecdsa);
*psig = (char*)sig;
return 0;
}
}
}
}
return -1;
}
*psig = (char*)sig;
return 0;
}
}
}
}
return -1;
}
/branches/Security/tools/itscertgen/itscertgen.sln
0,0 → 1,38

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "itscertgen", "itscertgen.vcxproj", "{17B446F1-6962-4B49-8A59-9584807F9024}"
ProjectSection(ProjectDependencies) = postProject
{D5918B85-FA45-4F75-9B50-C2D3E34ABA17} = {D5918B85-FA45-4F75-9B50-C2D3E34ABA17}
{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07} = {CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cxml", "cxml\cxml.vcxproj", "{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cshared", "cshared\cshared.vcxproj", "{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{17B446F1-6962-4B49-8A59-9584807F9024}.Debug|Win32.ActiveCfg = Debug|Win32
{17B446F1-6962-4B49-8A59-9584807F9024}.Debug|Win32.Build.0 = Debug|Win32
{17B446F1-6962-4B49-8A59-9584807F9024}.Release|Win32.ActiveCfg = Release|Win32
{17B446F1-6962-4B49-8A59-9584807F9024}.Release|Win32.Build.0 = Release|Win32
{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}.Debug|Win32.ActiveCfg = Debug|Win32
{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}.Debug|Win32.Build.0 = Debug|Win32
{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}.Release|Win32.ActiveCfg = Release|Win32
{CBFC4BFA-FE7E-45FB-AE2F-2608B7C0AD07}.Release|Win32.Build.0 = Release|Win32
{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}.Debug|Win32.ActiveCfg = Debug|Win32
{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}.Debug|Win32.Build.0 = Debug|Win32
{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}.Release|Win32.ActiveCfg = Release|Win32
{D5918B85-FA45-4F75-9B50-C2D3E34ABA17}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
/branches/Security/tools/itscertgen/itscertgen.vcxproj
0,0 → 1,104
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="applink.c" />
<ClCompile Include="certgen.c" />
<ClCompile Include="ecc_openssl.c" />
<ClCompile Include="mkgmtime.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ecc_api.h" />
<ClInclude Include="mkgmtime.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="cshared\cshared.vcxproj">
<Project>{d5918b85-fa45-4f75-9b50-c2d3e34aba17}</Project>
</ProjectReference>
<ProjectReference Include="cxml\cxml.vcxproj">
<Project>{cbfc4bfa-fe7e-45fb-ae2f-2608b7c0ad07}</Project>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{17B446F1-6962-4B49-8A59-9584807F9024}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>itscertgen</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\msvc\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\msvc\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\OpenSSL-Win32\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\OpenSSL-Win32\lib\VC\static</AdditionalLibraryDirectories>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>