Your problem is with signlen. You’re accessing a null pointer in EVP_DigestSignFinal().
Declare signlen as size_t, not a size_t*, and pass the *ADDRESS* of signlen. E.g.: EVP_DigestSignFinal(mdctx, NULL, &signlen); From: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] On Behalf Of Amir Reda Sent: Monday, November 24, 2014 10:10 AM To: openssl-users@openssl.org Subject: sign problem dear all i have a problem with c++ code for sign some data here is the code BIO *sgerr = NULL; const char szPath[MAX_FILE_NAME_SIZE] = "sgerr.pem"; sgerr = BIO_new_file(szPath,"wb"); cout<<"i'm in sign digest"<<endl; //create private key EVP_PKEY *priv_key = NULL; priv_key = EVP_PKEY_new(); if (1 == EVP_PKEY_set1_RSA(priv_key,m_caKeyPairs)) { cout<<"Successful key private created"<<endl; } else { cout<<"private key is bad"<<endl; } EVP_MD_CTX *mdctx = NULL; mdctx = EVP_MD_CTX_create(); size_t *signlen = NULL; //Initialize the DigestSign operation if (1 == EVP_DigestSignInit(mdctx, NULL, EVP_sha1(), NULL, priv_key)) { cout<<"initialize correct"<<endl; } else { cout<<"something wrong"<<endl; } //update with the message if (1 == EVP_DigestSignUpdate(mdctx, m_digestData,(DATA_SIZE + RSA_KEY_SIZE))) { cout<<"digest created successfully"<<endl; cout<<"digest is "<<endl; for (int i = 0; i < DIGEST_SIZE; i++) { printf("0x%.2x ", m_digest[i]); } cout<<endl; } else { cout<<"something wrong"<<endl; } //Finalise the DigestSign operation determine the sign length if (1 == EVP_DigestSignFinal(mdctx, NULL, signlen)) { cout<<"sign length is "<<(*signlen)<<endl; } else { cout<<"something wrong"<<endl; } if (1 == EVP_DigestSignFinal(mdctx, m_signedDigest, signlen)) { cout<<"sign successfully created"<<endl; } else { cout<<"something wrong"<<endl; } the output of this code in terminal during debugging i'm in sign digest Successful key private created initialize correct digest created successfully digest is 0x99 0x2d 0x5c 0x5b 0x2f 0x7a 0x85 0x98 0x7c 0x69 0xca 0x33 0x17 0xab 0x87 0x7c 0x79 0x73 0xd7 0x4a until i arrive to this point if (1 == EVP_DigestSignFinal(mdctx, NULL, signlen)) i got this error No source available for "EVP_PKEY_sign() at 0xb7ede098" even this function just return the length of the sign note i'm using eclipse kepler and i don't know what i did wrong -- Warmest regards and best wishes for a good health,urs sincerely mero