Some of the check functions I've used

Source: Internet
Author: User
Tags crc32 file info file size function definition function prototype hash openssl printf


OpenSSL provides a SHA1 library that can be invoked directly after OpenSSL is installed.


The function prototype is shown in the attachment, where static void Mdfile (filename) is a MD5 checksum of the file, and the static void Mdstring (instring) is a MD5 checksum of the string. Can be used directly, can also be encapsulated in the library after the call, it is worth noting that the source code in the function definition of the static removed.


The hash algorithm is shown in the attachment.


USHORT checksum(USHORT *buffer,int size)
  unsigned long cksum=0;

    size -=sizeof(USHORT);
  cksum =(cksum>>16)+(cksum & 0xffff);
  return (USHORT)(~cksum);

CRC Checksum:

int FILE_CRC32 (const char *filename,unsigned int *CRC)
unsigned char buffer[max_buffer_size];
unsigned int VCRC = 0xFFFFFFFF;
unsigned int read = 0;
unsigned int filesize = 0;
struct stat fst;

if (stat (FILENAME,&FST))
printf ("Get file info failed\n");
/* Unsigned long may denote the file size * *
if ((filesize = fst.st_size) = = 0)

/* Open File */
if (fp = fopen (filename, "r") = = NULL)
printf ("Open the File failed\n");

while (filesize)
Read = filesize > max_buffer_size? Max_buffer_size:filesize;
if ((read = Fread (BUFFER,1,READ,FP)) = = 0) break;
* CRC * *
FileSize = read;
Fclose (FP);
return 0;

void Crc32 (const unsigned char* byte,unsigned int length,unsigned int *VCRC)
unsigned int i = 0;
for (i = 0; i < length; i++)
*VCRC = ((*VCRC) >> 8) ^ Crc32table[byte[i] ^ ((*VCRC) & 0X000000FF)];

Article Source:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: