Tuesday, August 6, 2013

How to compare SHA1 of 512KB data with the given SHA1 from meta info file?

How to compare SHA1 of 512KB data with the given SHA1 from meta info file?

My program sends a request for data with 512KB size to a server. In order
to check data integrity, It has the given SHA1 from a meta-information
file. I'm going to compare SHA1 of this received data with the given SHA1
like, but I think something goes wrong because the buffer size is too big.
int main(int argc, char** argv)
{
char given_SHA1[20]; // assume that it has some value.
char received_buffer[524288]; // Assume that this holds 512KB data
from a socket. does not make sense. it is too big.
char SHA1_received[20];
SHA1(received_buffer, SHA1_received); // SHA1_received will get SHA1
of 512KB data.
if(strcmp(SHA1_received, given_SHA1) == 0)
{
printf("received data is OK\n");
}
else
{
printf("error\n");
exit(0);
}
}
Is there any alternative way to do stuff that this code does, instead of
declaring 512KB buffer as local variable?

No comments:

Post a Comment