Reputation: 17
For example, I've seen a file like this:
char data[] = "Hello, world!";
size_t length = sizeof(data);
unsigned char hash[SHA_DIGEST_LENGTH];
SHA1(data, length, hash);
Then, I found a instance almost like it. However the difference is SHA1(data, length - 1, hash);
So, I am a little confused. Should I use "sizeof(data)"
or "sizeof(data)-1"
? Thanks in advance.
Upvotes: 0
Views: 595
Reputation: 3911
It depends on the actual payload you want to hash.
sizeof data
includes the zero terminator.sizeof(data) -1
or strlen(data)
exclude the zero.Upvotes: 2