EVP_sha1 is a function. Try: EVP_DigestInit_ex(&mdctx, EVP_sha1(), NULL);
Matt On 8 December 2011 16:45, Rainer Gerhards <[email protected]> wrote: > Hi all, > > I intend to use the EVP interface in order to prepare for future > changes, but currently need only SHA1 hashes. I have taken the code > sample from the EVP_DigestInit man page. It works fine. However, when > I replace > > EVP_DigestInit_ex(&mdctx, md, NULL); > > with > > EVP_DigestInit_ex(&mdctx, EVP_sha1, NULL); > > A segfault occurs at that very location. From what I have found in the > doc and on the web, EVP_sha1 should be a valid constant for this kind > of use. > > I'd appreciate if someone could tell me where my misunderstanding (and > thus the segfault ;)) is rooted (platform is recent Ubuntu Linux). > Complete segfaulting code after my sig, just to be sure... > > -- > Thanks, > Rainer > > > #include <stdio.h> > #include <openssl/evp.h> > > main(int argc, char *argv[]) > { > EVP_MD_CTX mdctx; > const EVP_MD *md; > char mess1[] = "Test Message\n"; > char mess2[] = "Hello World\n"; > unsigned char md_value[EVP_MAX_MD_SIZE]; > int md_len, i; > > OpenSSL_add_all_digests(); > > if(!argv[1]) { > printf("Usage: mdtest digestname\n"); > exit(1); > } > > md = EVP_get_digestbyname(argv[1]); > > if(!md) { > printf("Unknown message digest %s\n", argv[1]); > exit(1); > } > > EVP_MD_CTX_init(&mdctx); > EVP_DigestInit_ex(&mdctx, EVP_sha1, NULL); // <-- segfault location > //EVP_DigestInit_ex(&mdctx, md, NULL); > EVP_DigestUpdate(&mdctx, mess1, strlen(mess1)); > EVP_DigestUpdate(&mdctx, mess2, strlen(mess2)); > EVP_DigestFinal_ex(&mdctx, md_value, &md_len); > EVP_MD_CTX_cleanup(&mdctx); > > printf("Digest is: "); > for(i = 0; i < md_len; i++) printf("%02x", md_value[i]); > printf("\n"); > } > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List [email protected] > Automated List Manager [email protected] >
