From 62be98048805c09ae7c06b3359de77cd8d36e8f6 Mon Sep 17 00:00:00 2001 From: alessandro ferro <49845537+xfarrow@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:30:23 +0200 Subject: [PATCH] OpenSSL 3.0 by default Legacy code still present but not used --- dircomp.c | 13 ++++++++----- dircomp.h | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dircomp.c b/dircomp.c index 1e1d3c3..eb9f20f 100644 --- a/dircomp.c +++ b/dircomp.c @@ -310,8 +310,8 @@ int byte_by_byte_file_comparison(char* filename1, char* filename2) /// @return Returns 1 if the files are the same, 0 otherwise, -1 if an error occurred int hash_by_hash_file_comparison(char* filename1, char* filename2) { - char* hash1 = sha1(filename1); - char* hash2 = sha1(filename2); + unsigned char* hash1 = sha1(filename1); + unsigned char* hash2 = sha1(filename2); if(hash1 == NULL || hash2 == NULL) { return -1; @@ -322,10 +322,10 @@ int hash_by_hash_file_comparison(char* filename1, char* filename2) return ret; } -/// @brief Generates the SHA-1 hash of a file +/// @brief Generates the SHA-1 hash of a file. Deprecated since OpenSSL >= 3.0 /// @param filename Name of the file /// @return Pointer to the digest -unsigned char* sha1(char *filename) +unsigned char* sha1_legacy(char *filename) { FILE *f = fopen(filename, "rb"); if (f == NULL) @@ -355,7 +355,10 @@ unsigned char* sha1(char *filename) return hash; } -unsigned char* sha1_openssl3(char *filename){ +/// @brief Generates the SHA-1 hash of a file. +/// @param filename Name of the file +/// @return Pointer to the digest +unsigned char* sha1(char *filename){ EVP_MD_CTX *mdctx; // envelope context const EVP_MD *md; // envelope mode (SHA1) unsigned char *hash = malloc(EVP_MAX_MD_SIZE * sizeof(unsigned char)); // result will be here diff --git a/dircomp.h b/dircomp.h index 2b0425f..3e369fa 100644 --- a/dircomp.h +++ b/dircomp.h @@ -41,7 +41,9 @@ int byte_by_byte_file_comparison(char*, char*); int hash_by_hash_file_comparison(char*, char*); -unsigned char* sha1(char*); +unsigned char* sha1(char *filename) + +unsigned char* sha1_legacy(char*); char* combine_path(char*, char*);