On Mon, Mar 20, 2006, Friedline, Harold wrote: > I am attempting to write code to utilize the crypto(3) library that > comes with openssl. Specifically, I am using these functions > OpenSSL_add_all_digests(); > md = EVP_get_digestbyname(dgst); > EVP_DigestInit_ex(&mdctx, md, NULL); > EVP_DigestInit(&mdctx, md); > EVP_DigestUpdate(&mdctx, input_string, strlen(input_string)); > EVP_DigestFinal_ex(&mdctx, md_value, &md_len); > EVP_DigestFinal(&mdctx, md_value, &md_len); > EVP_MD_CTX_cleanup(&mdctx) > The code compiles and links. Using it, however, produces different > results than using > echo "some string" | openssl dgst -md5 > Why are the results different and, am I utilizing the shared lib > functions in a way that is causing bad results? > >
Well other than the EOL which "echo" sends which has already been mentioned... If you use the _ex() variants you have to initialize the context structure first. That is you need an EVP_MD_CTX_init(&mdctx); better still is to use a context pointer and create it with EVM_MD_CTX_create() and free it with EVP_MD_CTX_destroy(). That is better because it maintains binary compatibility. Steve. -- Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage OpenSSL project core developer and freelance consultant. Funding needed! Details on homepage. Homepage: http://www.drh-consultancy.demon.co.uk ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [email protected] Automated List Manager [EMAIL PROTECTED]
