I am trying to use OpenSSL to calculate the sha1 hash from a c program. I am compiling with clang on Mac OS X Yosemite with Intel i7 (so 64 bit).
The corresponding code snippet is something like this:
#include <openssl/evp.h>
...
unsigned char outHash[20];
hash("SHA1","abcd", 20, outHash);
The fact is that when using the hash function from openssl/evp.hcompiling with clang, the following error occurs:
Undefined symbols for architecture x86_64:
"_hash", referenced from:
_getRandomSHA1 in main-68ccd6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, it looks like OpenSSL was not found by the linker (the hash function is not installed). Any ideas how to fix this?
EDIT:
Turns out I was trying to use a function that doesn't exist ("hash") - sorry for fooling you about this.
However, I still have the same problem: including openssl/evp.h, it does not seem to work.
-, , evp sha1:
unsigned int hash(const char *mode, const char* dataToHash, size_t dataSize, unsigned char* outHashed) {
unsigned int md_len = -1;
const EVP_MD *md = EVP_get_digestbyname(mode);
if(NULL != md) {
EVP_MD_CTX mdctx;
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
EVP_DigestUpdate(&mdctx, dataToHash, dataSize);
EVP_DigestFinal_ex(&mdctx, outHashed, &md_len);
EVP_MD_CTX_cleanup(&mdctx);
}
return md_len;
}
:
hash("SHA1","abcd", 20, outHash);
, , ( ):
clang main.c
:
Undefined symbols for architecture x86_64:
"_EVP_DigestFinal_ex", referenced from:
_hash in main-935849.o
"_EVP_DigestInit_ex", referenced from:
_hash in main-935849.o
"_EVP_DigestUpdate", referenced from:
_hash in main-935849.o
"_EVP_MD_CTX_cleanup", referenced from:
_hash in main-935849.o
"_EVP_MD_CTX_init", referenced from:
_hash in main-935849.o
"_EVP_get_digestbyname", referenced from:
_hash in main-935849.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)