-
problem by d2i_ECDSA_SIG
------=_Part_15503_3955994.1206454665031
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi everyone,
i have problem with ECDSA_do_sign() and ECDSA_do_verify().
After sign with ECDSA_do_sign() i got signatur. I used d2i_ECDSA_SIG() to
decode this signature and verify it. is that true?
But there is a error: Segmentation fault (core dumped) when i do
d2i_ECDSA_SIG() . I have no ideal about this error. Any hints from you?
Thanks in advance.
Nguyen.
Here is my code:
unsigned int olen, sig_len;
unsigned char *digest, *sig_buf;
int ires;
EC_KEY *ecprivkey=NULL;
EVP_PKEY *pkey;
EC_KEY* hpubkey;
ECDSA_SIG *ret;
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
ERR_load_EC_strings();
/*Get public key from file to verify*/
FILE *fp = fopen("/var/www/210308eccert.pem", "r");
X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
pkey=X509_get_pubkey(cert);
hpubkey = EVP_PKEY_get1_EC_KEY(pkey);
if (!hpubkey) {printf("can't get public\n ");}
/*file to compute digest string*/
FILE *f=fopen("/var/www/test_dgst.txt","r");
process_file(f,&olen);
if (!digest)
{
fclose(f);
printf("error by compute digest\n");
}
print_hex(digest,olen);
printf("\n");
/*private key file to sign on digest string */
FILE *fpkey=fopen("/var/www/210308keyec.pem","r");
ecprivkey= PEM_read_ECPrivateKey(fpkey, NULL, NULL, NULL);
/*sign digest string and return poniter ret to ECDSA_SIG*/
ret = ECDSA_do_sign(digest, sizeof digest, ecprivkey);
if (ret=NULL){printf("sign error\n");}
/*decodes a DER encoded ECDSA signature*/
ECDSA_SIG *s = ECDSA_SIG_new();
if (s==NULL) {printf("ECDSA_SIG_new error\n");}
s=d2i_ECDSA_SIG(&ret, &sig_buf, sig_len);
if (s==NULL){ printf("convert error\n");}
/*verify signature with public key*/
ires=ECDSA_do_verify(digest, sizeof digest, s, hpubkey);
printf("vaue of ires %d\n",ires);
and here is error:
nguyen@ubuntu:~/OpenSSl$ ./test
c9c300ff35fca10408ff2500a2040800000000ff
Segmentation fault (core dumped)
------=_Part_15503_3955994.1206454665031
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi everyone,<br><br>i have problem with ECDSA_do_sign() and ECDSA_do_verify(). <br><br>After sign with ECDSA_do_sign() i got signatur. I used d2i_ECDSA_SIG() to decode this signature and verify it. is that true?<br><br>But there is a error: Segmentation fault (core dumped) when i do d2i_ECDSA_SIG() . I have no ideal about this error. Any hints from you?<br>
<br>Thanks in advance.<br>Nguyen.<br><br>Here is my code:<br><br>unsigned int olen, sig_len;<br>unsigned char *digest, *sig_buf;<br>int ires;<br><br>EC_KEY *ecprivkey=NULL;<br>EVP_PKEY *pkey;<br>EC_KEY* hpubkey;<br>ECDSA_SIG *ret;<br>
<br>OpenSSL_add_all_algorithms();<br>ERR_load_crypto_strings();<br>ERR_load_EC_strings();<br><br>/*Get public key from file to verify*/<br>FILE *fp = fopen("/var/www/210308eccert.pem", "r");<br>X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);<br>
pkey=X509_get_pubkey(cert);<br>hpubkey = EVP_PKEY_get1_EC_KEY(pkey);<br>if (!hpubkey) {printf("can't get public\n ");}<br><br>/*file to compute digest string*/<br>FILE *f=fopen("/var/www/test_dgst.txt","r");<br>
<br>process_file(f,&olen); <br>if (!digest)<br>{<br> fclose(f);<br> printf("error by compute digest\n");<br>}<br><br>print_hex(digest,olen);<br>printf("\n");<br><br>/*private key file to sign on digest string */<br>
FILE *fpkey=fopen("/var/www/210308keyec.pem","r");<br><br>ecprivkey= PEM_read_ECPrivateKey(fpkey, NULL, NULL, NULL);<br>/*sign digest string and return poniter ret to ECDSA_SIG*/<br>ret = ECDSA_do_sign(digest, sizeof digest, ecprivkey);<br>
<br>if (ret=NULL){printf("sign error\n");}<br><br>/*decodes a DER encoded ECDSA signature*/<br>ECDSA_SIG *s = ECDSA_SIG_new();<br>if (s==NULL) {printf("ECDSA_SIG_new error\n");}<br>s=d2i_ECDSA_SIG(&ret, &sig_buf, sig_len);<br>
if (s==NULL){ printf("convert error\n");}<br><br>/*verify signature with public key*/<br>ires=ECDSA_do_verify(digest, sizeof digest, s, hpubkey);<br> <br>printf("vaue of ires %d\n",ires);<br><br>
and here is error:<br>nguyen@ubuntu:~/OpenSSl$ ./test<br>c9c300ff35fca10408ff2500a2040800000000ff<br>Segmentation fault (core dumped)
------=_Part_15503_3955994.1206454665031--
______________________________________________________________________
OpenSSL Project [url]http://www.openssl.org[/url]
User Support Mailing List [email]openssl-users@openssl.org[/email]
Automated List Manager [email]majordomo@openssl.org[/email]