Skip to content

Commit

Permalink
fixes #110 - fix compilation warnings for deprecated openssl SHA256_ …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
d99kris committed Aug 14, 2022
1 parent 8140402 commit 5994451
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
32 changes: 25 additions & 7 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// crypto.cpp
//
// Copyright (c) 2019-2021 Kristofer Berggren
// Copyright (c) 2019-2022 Kristofer Berggren
// All rights reserved.
//
// nmail is distributed under the MIT license, see LICENSE for details.
Expand Down Expand Up @@ -138,12 +138,30 @@ std::string Crypto::AESDecrypt(const std::string& p_Ciphertext, const std::strin

std::string Crypto::SHA256(const std::string& p_Str)
{
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, p_Str.c_str(), p_Str.size());
SHA256_Final(hash, &sha256);
return Util::ToHex(std::string((char*)hash, SHA256_DIGEST_LENGTH));
std::string hexDigest;
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
if (mdctx != nullptr)
{
if (EVP_DigestInit_ex(mdctx, EVP_sha256(), nullptr) == 1)
{
if (EVP_DigestUpdate(mdctx, p_Str.c_str(), p_Str.size()) == 1)
{
unsigned int resultLen = 0;
unsigned int digestLen = EVP_MD_size(EVP_sha256());
std::vector<char> digest(digestLen);

if ((EVP_DigestFinal_ex(mdctx, (unsigned char*)digest.data(), &resultLen) == 1) &&
(resultLen == digestLen))
{
hexDigest = Util::ToHex(std::string(digest.begin(), digest.end()));
}
}
}

EVP_MD_CTX_free(mdctx);
}

return hexDigest;
}

bool Crypto::AESEncryptFile(const std::string& p_InPath, const std::string& p_OutPath, const std::string& p_Pass)
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "August 2022" "nmail v3.88" "User Commands"
.TH NMAIL "1" "August 2022" "nmail v3.89" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "3.88"
#define NMAIL_VERSION "3.89"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit 5994451

Please sign in to comment.