Commit d865d577 authored by filatov's avatar filatov
Browse files

openssl.1.1.0 fixes for generators

parent 518d6724
......@@ -11,6 +11,7 @@ PROJECT = asn1certgen
DEBUG = yes
bins = asn1certgen
sources := asn1certgen.c ecc_openssl.c
cflags += -Wno-pointer-sign -Wno-enum-compare
sources-WIN32 := applink.c
packages += cshared openssl
predirs := asncodec
......
......@@ -41,7 +41,7 @@ char _tbsHash[512]; // has space for issuer hash + signer hash
int _tbsHashLength = 0;
char _signerHashBuf[256]; // has space for issuer hash
char* _signerHash = &_signerHashBuf[0];
const char* _signerHash = &_signerHashBuf[0];
int _signerHashLength = 0;
static const char * const _key_formats[] = {
......@@ -76,8 +76,7 @@ static copt_t _options [] = {
{ NULL, NULL, COPT_END, NULL, NULL }
};
static int is_P384CurvePoint_empty(EccP384CurvePoint_t* point);
static int is_P256CurvePoint_empty(EccP256CurvePoint_t* point);
static int is_CurvePoint_empty(EccP256CurvePoint_t* point);
static void fill_curve_point_eccP256(EccP256CurvePoint_t* point, ecc_curve_id curveType, char * keyPath);
static void fill_curve_point_eccP384(EccP384CurvePoint_t* point, ecc_curve_id curveType, char * keyPath);
......@@ -152,7 +151,7 @@ static asn_enc_rval_t Signature_oer_encoder(const asn_TYPE_descriptor_t *td,
asn_app_consume_bytes_f *cb, void *app_key)
{
Signature_t * s = (Signature_t *)sptr;
if (is_P256CurvePoint_empty(&s->choice.ecdsaNistP256Signature.rSig)){
if (is_CurvePoint_empty(&s->choice.ecdsaNistP256Signature.rSig)){
// look for signer private key
ecc_curve_id alg = _pk_type_to_curveid[s->present];
ecc_hash_id hashId = _pk_type_to_hashid[s->present];
......@@ -257,7 +256,7 @@ int main(int argc, char ** argv)
rc_d = asn_decode(NULL, ATS_BASIC_XER, &asn_DEF_EtsiTs103097Certificate, (void**)&cert, buf, ebuf - buf);
if (rc_d.code != RC_OK){
fprintf(stderr, "%s: failed to load at position %d\n %.30s\n", _profileName, rc_d.consumed, buf + rc_d.consumed);
fprintf(stderr, "%s: failed to load at position %d\n %.30s\n", _profileName, (int)rc_d.consumed, buf + rc_d.consumed);
return -1;
}
......@@ -278,7 +277,7 @@ int main(int argc, char ** argv)
EtsiTs103097Certificate_t * signer = NULL;
rc_d = asn_decode(NULL, ATS_BASIC_OER, &asn_DEF_EtsiTs103097Certificate, (void**)&signer, buf, ebuf - buf);
if (rc_d.code != RC_OK){
fprintf(stderr, "%s: failed to load signer certificate at position %d\n %.30s\n", _signerName, rc_d.consumed, buf + rc_d.consumed);
fprintf(stderr, "%s: failed to load signer certificate at position %d\n %.30s\n", _signerName, (int)rc_d.consumed, buf + rc_d.consumed);
return -1;
}
switch (signer->toBeSigned.verifyKeyIndicator.present){
......@@ -288,6 +287,9 @@ int main(int argc, char ** argv)
case VerificationKeyIndicator_PR_reconstructionValue:
hashType = PublicVerificationKey_PR_ecdsaNistP256;
break;
case VerificationKeyIndicator_PR_NOTHING:
fprintf(stderr, "%s: signer verification indicator type is unknown\n", _signerName);
return -1;
}
switch (hashType){
......@@ -295,17 +297,22 @@ int main(int argc, char ** argv)
case PublicVerificationKey_PR_ecdsaNistP256:
if (cert->issuer.present == IssuerIdentifier_PR_NOTHING)
cert->issuer.present = IssuerIdentifier_PR_sha256AndDigest;
sha256_calculate(_signerHash, buf, ebuf - buf);
sha256_calculate(_signerHashBuf, buf, ebuf - buf);
_signerHash = &_signerHashBuf[0];
_signerHashLength = sha256_hash_size;
OCTET_STRING_fromBuf(&cert->issuer.choice.sha256AndDigest, &_signerHash[sha256_hash_size-8], 8);
break;
case PublicVerificationKey_PR_ecdsaBrainpoolP384r1:
if (cert->issuer.present == IssuerIdentifier_PR_NOTHING)
cert->issuer.present = IssuerIdentifier_PR_sha384AndDigest;
sha384_calculate(_signerHash, buf, ebuf - buf);
sha384_calculate(_signerHashBuf, buf, ebuf - buf);
_signerHash = &_signerHashBuf[0];
_signerHashLength = sha384_hash_size;
OCTET_STRING_fromBuf(&cert->issuer.choice.sha384AndDigest, &_signerHash[sha384_hash_size - 8], 8);
break;
case PublicVerificationKey_PR_NOTHING:
fprintf(stderr, "%s: signer verification key type curve is unknown\n", _signerName);
return -1;
}
if (signer){
ASN_STRUCT_FREE(asn_DEF_EtsiTs103097Certificate, signer);
......@@ -320,6 +327,9 @@ int main(int argc, char ** argv)
case VerificationKeyIndicator_PR_reconstructionValue:
hashType = PublicVerificationKey_PR_ecdsaNistP256;
break;
case VerificationKeyIndicator_PR_NOTHING:
fprintf(stderr, "%s: signer verification indicator type is unknown\n", _signerName);
return -1;
}
switch (hashType) {
case PublicVerificationKey_PR_ecdsaBrainpoolP256r1:
......@@ -361,10 +371,12 @@ int main(int argc, char ** argv)
}
break;
case VerificationKeyIndicator_PR_reconstructionValue:
fprintf(stderr, "TODO: reconstruction value generation is unsupported\n");
fprintf(stderr, "TODO: reconstruction value generation is unsupported yet\n");
return -1;
case VerificationKeyIndicator_PR_NOTHING:
default:
break;
fprintf(stderr, "Unknown verification key indicator type\n");
return -1;
}
if (cert->toBeSigned.encryptionKey){
cvstrncpy(buf, CERT_MAX_SIZE, _keyPath, "/", _profileName, EXT_EKEY, NULL);
......@@ -409,7 +421,7 @@ int main(int argc, char ** argv)
return 0;
}
static int is_P256CurvePoint_empty(EccP256CurvePoint_t* point)
static int is_CurvePoint_empty(EccP256CurvePoint_t* point)
{
switch (point->present){
case EccP256CurvePoint_PR_x_only:
......@@ -445,7 +457,7 @@ static void fill_curve_point_eccP256(EccP256CurvePoint_t* point, ecc_curve_id cu
}
ecc_key_free(key);
}
/*
static int is_P384CurvePoint_empty(EccP384CurvePoint_t* point){
switch (point->present){
case EccP256CurvePoint_PR_x_only:
......@@ -459,7 +471,7 @@ static int is_P384CurvePoint_empty(EccP384CurvePoint_t* point){
}
return 1;
}
*/
static void fill_curve_point_eccP384(EccP384CurvePoint_t* point, ecc_curve_id curveType, char * keyPath)
{
void * key;
......
......@@ -501,8 +501,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -511,8 +511,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -542,8 +542,8 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC\static</AdditionalLibraryDirectories>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -582,8 +582,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC\static</AdditionalLibraryDirectories>
<AdditionalDependencies> ws2_32.lib;libcrypto64MD.lib;libssl64MD.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -137,7 +137,7 @@ int ecc_key_public(void* key, char * px, char * py, int * psign)
const EC_GROUP * ecgroup;
const EC_POINT * ecpoint;
const EC_KEY * eckey = (EC_KEY*)key;
BIGNUM x, y;
BIGNUM *x, *y;
int fsize, bcount = -1;
if( key && px && py ) {
......@@ -146,20 +146,21 @@ int ecc_key_public(void* key, char * px, char * py, int * psign)
fsize = (EC_GROUP_get_degree(ecgroup) + 7) / 8;
//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);
x = BN_new();
y = BN_new();
if (EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, x, y, NULL)){
bcount = BN_num_bytes(x);
for(; bcount < fsize; bcount++)
*(px++) = 0; // add padding with zeros
BN_bn2bin(&x, (unsigned char*)px);
BN_bn2bin(x, (unsigned char*)px);
bcount = BN_num_bytes(&y);
bcount = BN_num_bytes(y);
for(; bcount < fsize; bcount++)
*(py++) = 0; // add padding with zeros
BN_bn2bin(&y, (unsigned char*)py);
if (psign) * psign = BN_is_odd(&y);
BN_bn2bin(y, (unsigned char*)py);
if (psign) * psign = BN_is_odd(y);
}
BN_clear_free(&x); BN_clear_free(&y);
BN_clear_free(x); BN_clear_free(y);
}
return bcount;
}
......@@ -424,14 +425,22 @@ int ecc_sign(void * key, const char * hash, int hlength, char *r, char *s)
EC_KEY_free(eckey);
if (ecdsa){
int i, bcount;
bcount = BN_num_bytes(ecdsa->r);
const BIGNUM* sr;
const BIGNUM* ss;
# if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
ECDSA_SIG_get0(ecdsa, &sr, &ss);
#else
sr = ecdsa->r;
ss = ecdsa->s;
#endif
bcount = BN_num_bytes(sr);
for(i=bcount; i < fsize; i++)
*(r++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->r, r);
bcount = BN_num_bytes(ecdsa->s);
BN_bn2bin(sr, r);
bcount = BN_num_bytes(ss);
for(i=bcount; i < fsize; i++)
*(s++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->s, s);
BN_bn2bin(ss, s);
ECDSA_SIG_free(ecdsa);
return 0;
}
......
......@@ -282,7 +282,7 @@ int main(int argc, char ** argv)
p += length;
}
else {
fprintf(stderr, "Unsupported signer type: %d\n", ENUMSTRING(*p, _signer_types));
fprintf(stderr, "Unsupported signer type: %s\n", ENUMSTRING(*p, _signer_types));
return -1;
}
fprintf(stdout, "\t</signer>\n");
......@@ -368,11 +368,22 @@ int main(int argc, char ** argv)
ecdsa = ECDSA_SIG_new();
const char * r = cert + certlen - 64;
const char * s = cert + certlen - 32;
if (ecdsa->r == BN_bin2bn((const unsigned char *)r, 32, ecdsa->r) &&
ecdsa->s == BN_bin2bn((const unsigned char *)s, 32, ecdsa->s)){
BIGNUM *bnr=NULL, *bns=NULL;
BN_bin2bn((const unsigned char *)r, 32, bnr);
BN_bin2bn((const unsigned char *)s, 32, bns);
if (bnr && bns) {
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
ECDSA_SIG_set0(ecdsa, bnr,bns);
#else
ecdsa->r = bnr;
ecdsa->s = bns;
#endif
rc = ECDSA_do_verify(hash, 32, ecdsa, key);
}
else{
BN_clear_free(bnr);
BN_clear_free(bns);
}
if (rc < 0){
printf("ERROR");
ERR_print_errors_fp(stderr);
......
......@@ -89,8 +89,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -99,8 +99,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -125,13 +125,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\OpenSSL\Win32\include;..</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\OpenSSL\Win64\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>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -162,14 +162,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\OpenSSL\Win32\include;..</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\OpenSSL\Win64\include;..</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>libcrypto64MD.lib;libssl64MD.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -26,7 +26,7 @@ else
CFG += POSIX
endif
cflags += -Wall -fPIC
cflags := -Wall -fPIC $(cflags)
ifeq ($(DEBUG),)
DEBUG=no
......@@ -62,10 +62,18 @@ ifneq ($(filter profile, $(packages)),)
endif
ifneq ($(filter openssl, $(packages)),)
ifneq ($(filter x64, $(ARCH)),)
OPENSSL_ARCH:=Win64
else
OPENSSL_ARCH:=Win32
endif
ifneq ($(findstring mingw32,$(ARCH)),)
includes += C:/OpenSSL-Win32/include
libs += C:/OpenSSL-Win32/lib/MinGW/libeay32.a C:/OpenSSL-Win32/lib/MinGW/ssleay32.a
includes += C:/OpenSSL/$(OPENSSL_ARCH)/include
libs += C:/OpenSSL/$(OPENSSL_ARCH)/lib/MinGW/libeay32.a C:/OpenSSL-Win32/lib/MinGW/ssleay32.a
else
ifneq ($(findstring cygwin,$(ARCH)),)
includes += C:/OpenSSL/$(OPENSSL_ARCH)/include
endif
libs += -lssl -lcrypto
endif
endif
......
......@@ -91,7 +91,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
......@@ -99,7 +99,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......
......@@ -82,16 +82,16 @@
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......
......@@ -92,8 +92,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -102,8 +102,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -128,13 +128,13 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\OpenSSL\Win32\include;..</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\OpenSSL\Win64\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>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -166,15 +166,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>C:\OpenSSL\Win32\include;..</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\OpenSSL\Win64\include;..</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win32\lib\VC\static</AdditionalLibraryDirectories>
<AdditionalDependencies>libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -171,7 +171,7 @@ int ecc_api_key_public(void* key, char * px, char * py)
const EC_GROUP * ecgroup;
const EC_POINT * ecpoint;
const EC_KEY * eckey = (EC_KEY*)key;
BIGNUM x, y;
BIGNUM *x, *y;
int bcount = -1;
if( key && px && py ) {
......@@ -179,19 +179,19 @@ int ecc_api_key_public(void* key, char * px, char * py)
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);
x = BN_new(); y = BN_new();
if (EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, x, y, NULL)){
bcount = BN_num_bytes(x);
for(; bcount < FIELD_SIZE; bcount++)
*(px++) = 0; // add padding with zeros
BN_bn2bin(&x, (unsigned char*)px);
BN_bn2bin(x, (unsigned char*)px);
bcount = BN_num_bytes(&y);
bcount = BN_num_bytes(y);
for(; bcount < FIELD_SIZE; bcount++)
*(py++) = 0; // add padding with zeros
BN_bn2bin(&y, (unsigned char*)py);
BN_bn2bin(y, (unsigned char*)py);
}
BN_clear_free(&x); BN_clear_free(&y);
BN_clear_free(x); BN_clear_free(y);
}
return bcount;
}
......@@ -451,16 +451,18 @@ int ecc_sign(void * key, const char * data, int length, char ** psig, int max
EC_KEY_free(eckey);
if (ecdsa){
int i, bcount;
BIGNUM *sr, *ss;
ECDSA_SIG_get0(ecdsa, &sr, &ss);
*(sig++) = 0; // ECC_POINT type (x_coordinate_only)
bcount = BN_num_bytes(ecdsa->r);
bcount = BN_num_bytes(sr);
for(i=bcount; i < FIELD_SIZE; i++)
*(sig++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->r, sig);
BN_bn2bin(sr, sig);
sig += bcount;
bcount = BN_num_bytes(ecdsa->s);
bcount = BN_num_bytes(ss);
for(i=bcount; i < FIELD_SIZE; i++)
*(sig++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->s, sig);
BN_bn2bin(ss, sig);
sig += bcount;
ECDSA_SIG_free(ecdsa);
*psig = (char *)sig;
......
......@@ -94,8 +94,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -104,8 +104,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -136,7 +136,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libcrypto64MDd.lib;libssl64MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -175,7 +175,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libeay32MDd.lib;ssleay32MDd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libcrypto64MD.lib;libssl64MD.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL\Win64\lib\VC</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
......
......@@ -268,11 +268,12 @@ int main(int argc, char ** argv)
ecdsa = ECDSA_SIG_new();
const char * r = e - 64;
const char * s = e - 32;
if (ecdsa->r == BN_bin2bn((const unsigned char *)r, 32, ecdsa->r) &&
ecdsa->s == BN_bin2bn((const unsigned char *)s, 32, ecdsa->s)){
printf("%s: SIG.R: %s\n", argv[i], BN_bn2hex(ecdsa->r));
printf("%s: SIG.S: %s\n", argv[i], BN_bn2hex(ecdsa->s));
BIGNUM *sr = BN_new(), *ss = BN_new();
if (sr == BN_bin2bn((const unsigned char *)r, 32, sr) &&
ss == BN_bin2bn((const unsigned char *)s, 32, ss)){
ECDSA_SIG_set0(ecdsa, sr, ss);
printf("%s: SIG.R: %s\n", argv[i], BN_bn2hex(sr));
printf("%s: SIG.S: %s\n", argv[i], BN_bn2hex(ss));
int rc = ECDSA_do_verify(hash, 32, ecdsa, key);
if (rc < 0){
printf("%s: ERROR\n", argv[i]);
......
......@@ -81,8 +81,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)</IntDir>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -91,8 +91,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(ProjectDir)..\build\msvc\$(Platform)\$(Configuration)</OutDir>