bing han
bing han

Reputation: 17

what's the parameters' usage in detail of SHA1() function in c language

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

Answers (1)

Non-maskable Interrupt
Non-maskable Interrupt

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

Related Questions