0

This code below creates a hash of a file that is created, however I wondered where I should begin to convert this into a program that will scan a folder for files and automatically hash them? Tips, hints, and pointers on where to look to understand how to do this would be much appreciated!

#include <stdio.h>
#include <openssl/sha.h>

int main()
{
    unsigned char c[SHA512_DIGEST_LENGTH];
    char *filename="sha512.c";
    int i;
    FILE *inFile = fopen (filename, "rb");
    SHA512_CTX mdContext;
    int bytes;
    unsigned char data[1024];

    SHA512_Init (&mdContext);
    while ((bytes = fread (data, 1, 1024, inFile)) != 0)
        SHA512_Update (&mdContext, data, bytes);
    SHA512_Final (c,&mdContext);
    for(i = 0; i < SHA512_DIGEST_LENGTH; i++) printf("%02x", c[i]);
    printf (" %s\n", filename);
    fclose (inFile);
    return 0;
}

Understandably a loop is required, however I am unsure how to go about calculate each file only once (as opposed to continuously calculating files that have already been hashed). This code is utilising openssl.

Thank you in advance.

0 Answers0