Hashed
Hashed

Reputation: 57

C++ hashing algorithm

I have the following algoritm (based on SHA-1 hash function implementation). It produces the hash of "abc". The result is the unsigned char* digest.

#define BYTES "abce"
SHA1* sha1 = new SHA1();
sha1->addBytes( BYTES, strlen( BYTES ) );
unsigned char* digest = sha1->getDigest();

I would like to rehash the result digest. I m doing this in the following way but does not work. Is char* S defined something different from #define BYTES "abce" ?

char* S = reinterpret_cast<char*>(digest);
sha1 = new SHA1();
sha1->addBytes( S, strlen( S ) );           
unsigned char* digest1 = sha1->getDigest();

Upvotes: 0

Views: 367

Answers (1)

David Schwartz
David Schwartz

Reputation: 182865

Do not ever use strlen on anything but a C-style string.

          sha1->addBytes( S, strlen( S ) );         

That makes no sense. You probably want 20, the size of a SHA digest.

Upvotes: 5

Related Questions