Hi,
I try to write a program to verify a signature, all results of openssl(0.9.8.h) 
function calls are fine except the last one       result = 
EVP_VerifyFinal(md_ctx, sig, sig_size, evp_pkey);the result is -1, which means 
it's an error. Any idea what did I do wrong? see the codes below.
Thanks,--Don 
#define PUBLIC_KEY_LENGTH               128
unsigned char   public_key[PUBLIC_KEY_LENGTH] =
{   0x73, 0xeb, 0x34, ...}
int verify_s signature (char *buf, int buf_size, char *sig, int sig_size){    
int result = -1;    EVP_PKEY *evp_pkey = NULL;    DSA *dsa_key = NULL;    
EVP_MD_CTX *md_ctx = NULL; 
        /* Create the evp pkey object */        if ((evp_pkey = EVP_PKEY_new()) 
== NULL)            goto cleanup;       /* Allocate a DSA key object */
        if ((dsa_key = DSA_new()) == NULL)          goto cleanup;         
if((dsa_key->pub_key = BN_bin2bn(public_key, PUBLIC_KEY_LENGTH, 0)) == NULL)
            goto cleanup;       /* Set the EVP key type to DSA  */        
result = EVP_PKEY_set1_DSA(evp_pkey, dsa_key);        if (result != 1)
           goto cleanup;         /* Signature Verification start */     if 
((md_ctx = EVP_MD_CTX_create()) == NULL)        goto cleanup;                if 
(!EVP_VerifyInit_ex(md_ctx, EVP_dss1(), NULL))       if (result != 1) 
            goto cleanup;         result = EVP_VerifyUpdate(md_ctx, buf, 
buf_size);     if ( result !=1)
            goto cleanup;         result = EVP_VerifyFinal(md_ctx, sig, 
sig_size, evp_pkey);
cleanup:
...
       return result;}

Reply via email to