Compare Revisions

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

Ignore whitespace Rev 2843 → Rev 2844

/trunk/tools/itscertgen/generator/ecc_openssl.c
19,6 → 19,8
#include <openssl/ecdsa.h>
#include <string.h>
 
#define FIELD_SIZE 32
 
#define ARRAYSIZE(A) (sizeof(A)/sizeof(A[0]))
 
static char * _bin2hex(char * hex, int hlen, const char * bin, int blen);
172,23 → 174,25
BIGNUM x, y;
int bcount = -1;
 
ecgroup = EC_KEY_get0_group(eckey);
ecpoint = EC_KEY_get0_public_key(eckey);
if( key && px && py ) {
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){
//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);
for(; bcount < FIELD_SIZE; bcount++)
*(px++) = 0; // add padding with zeros
BN_bn2bin(&x, (unsigned char*)px);
}
 
bcount = BN_num_bytes(&y);
if (py){
bcount = BN_num_bytes(&y);
for(; bcount < FIELD_SIZE; bcount++)
*(py++) = 0; // add padding with zeros
BN_bn2bin(&y, (unsigned char*)py);
}
BN_clear_free(&x); BN_clear_free(&y);
}
BN_clear_free(&x); BN_clear_free(&y);
return bcount;
}
 
446,12 → 450,16
ecdsa = ECDSA_do_sign(hash, 32, eckey);
EC_KEY_free(eckey);
if (ecdsa){
int bcount;
int i, bcount;
*(sig++) = 0; // ECC_POINT type (x_coordinate_only)
bcount = BN_num_bytes(ecdsa->r);
for(i=bcount; i < FIELD_SIZE; i++)
*(sig++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->r, sig);
sig += bcount;
bcount = BN_num_bytes(ecdsa->s);
for(i=bcount; i < FIELD_SIZE; i++)
*(sig++) = 0; // add padding with zeros
BN_bn2bin(ecdsa->s, sig);
sig += bcount;
ECDSA_SIG_free(ecdsa);