OpenSSL 3.0 by default

Legacy code still present but not used
This commit is contained in:
alessandro ferro 2023-04-27 17:30:23 +02:00
parent 3080990f83
commit 62be980488
2 changed files with 11 additions and 6 deletions

View File

@ -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 /// @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) int hash_by_hash_file_comparison(char* filename1, char* filename2)
{ {
char* hash1 = sha1(filename1); unsigned char* hash1 = sha1(filename1);
char* hash2 = sha1(filename2); unsigned char* hash2 = sha1(filename2);
if(hash1 == NULL || hash2 == NULL) if(hash1 == NULL || hash2 == NULL)
{ {
return -1; return -1;
@ -322,10 +322,10 @@ int hash_by_hash_file_comparison(char* filename1, char* filename2)
return ret; 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 /// @param filename Name of the file
/// @return Pointer to the digest /// @return Pointer to the digest
unsigned char* sha1(char *filename) unsigned char* sha1_legacy(char *filename)
{ {
FILE *f = fopen(filename, "rb"); FILE *f = fopen(filename, "rb");
if (f == NULL) if (f == NULL)
@ -355,7 +355,10 @@ unsigned char* sha1(char *filename)
return hash; 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 EVP_MD_CTX *mdctx; // envelope context
const EVP_MD *md; // envelope mode (SHA1) const EVP_MD *md; // envelope mode (SHA1)
unsigned char *hash = malloc(EVP_MAX_MD_SIZE * sizeof(unsigned char)); // result will be here unsigned char *hash = malloc(EVP_MAX_MD_SIZE * sizeof(unsigned char)); // result will be here

View File

@ -41,7 +41,9 @@ int byte_by_byte_file_comparison(char*, char*);
int hash_by_hash_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*); char* combine_path(char*, char*);