I tried your code and I had a suspicion that using the
*_ex() functions along with *() functions can cause
trouble. Which is what has happened in your case.
Here is the correct code for your reference. You are
supposed to stick to either Init_ex() , Final_ex()
functions or Init() ,Final() functions, you can't mix
the two.
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/ssl.h>
int main() {
unsigned char
input_string[1024],md_value[1024];
EVP_MD_CTX mdctx;
const EVP_MD *md;
int md_len,i;
strcpy(input_string,"God is great");
OpenSSL_add_all_digests();
md = EVP_get_digestbyname("SHA1");
EVP_DigestInit_ex(&mdctx, md, NULL);
EVP_DigestUpdate(&mdctx, input_string,
strlen(input_string));
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx) ;
for(i=0;i<md_len;i++)
printf("%02X",md_value[i]);
}
This gives the same output as
echo -n "God is great"|openssl sha1
regards,
Girish
--- "Friedline, Harold" <[EMAIL PROTECTED]>
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?
>
> Thanks in advance!!
>
> Harold Friedline
> Barclaycard US
>
> I think animal testing is a terrible idea; they get
> all nervous and give
> the wrong answers.
>
>
>
>
> Barclays www.barclaycardus.com
>
> This e-mail and any files transmitted with it may
> contain confidential and/or proprietary information.
> It is intended solely for the use of the individual
> or entity who is the intended recipient.
> Unauthorized use of this information is prohibited.
> If you have received this in error, please contact
> the sender by replying to this message and delete
> this material from any system it may be on.
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]