aappleby / smhasher

Automatically exported from code.google.com/p/smhasher
2.63k stars 467 forks source link

Cannot compile and add hash, linker errors #67

Open MatthewCushing opened 5 years ago

MatthewCushing commented 5 years ago

Hi, I've been trying for quite a while now to get our blake2s hash added however I've been running into issues when trying to compile. I'm not sure if these issues I'm having are staring me right in the face but unfortunately I can't figure it out. Essentially, I added 3 header files and a C file. I assumed all I needed to do was add the blake2s.c into the cmakelists.txt add_library() function but that doesn't seem to help. Can anyone give me a hand here? I'd really appreciate it.

Let me go through what all I've added to make sure you have all the info you may need to help. I have: blake2.h blake2-impl.h blake2s.h blake2s.c

I have included blake2s.c in the add_library() function in CMakeLists.txt

# CMakeLists.txt
add_library(
    SMHasherSupport
    # ......others
    blake2s.c
)

I have included blake2s.h in Hashes.h as well as given the following method definition:

// Hashes.h
#include "blake2s.h"
// ....other includes

void blake2s (const void *key, int len, uint32_t seed, void *out);
// ...….other has functions follow

In Hashes.cpp I have implemented the method.

// Hashes.cpp
void
blake2s(const void *key, int len, uint32_t seed, void *out)
{
    my_blake2s((char *)key, len, seed, (char *)out;
}

Lastly, in main.cpp I have put blake2s into g_hashes[]

// main.cpp
HashInfo g_hashes[] =
{
    { blake2s, 32, 0x0, "blake2s", "blake2s 32-bit cryptographic hash function"},
    // DoNothingHash and so on goes here

Note: I'm still having trouble understanding what values are coming through key, len, seed, and out but I'm assuming your definition of "key" is the string that you are trying to hash, len is the length of that string, seed is a random number to give an extra level of protection on the hash? Similar to a salt? And out is the final hash string? It seems everyone has a different term for things when it comes to hashing as the blake2s that my work is using says the key is the salt.
Anyways......this is what I got so far and everytime I try to compile, I receive this in terminal:

...
...
[98%] Building CXX object CMakeFiles/SMHasher.dir/main.cpp.o
[100%] Linking CXX executable SMHasher
./usr/bint/ld: libSMHasherSupport.a(Hashes.cpp.o): in function `blake2s(void const*, int, unsigned int, void*)':
Hashes.cpp:(.text+0x1): undefined reference to `my_blake2s(void const*, int, unsigned int, void*)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/SMHasher.dir/build.make:85: SMHasher] Error 1
make[1]: *** [CMakeFiles/Makefile2:110: CMakeFiles/SMHasher.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

So it seems everything goes fine until it's time to read from one my of files that aren't in the original repo (the my_blake2s file being in blake2s.c). I have added much smaller hash functions (like Djb2) directly to Hashes.cpp and after building first time I'm used to getting a verification hex code to slot in however I have not been able to get all of blake2s directly into Hashes.cpp without the multiple files (I'm an intern so don't have too much experience working with larger projects until recently - 4months ago).

Thanks! Matt