@ -85,7 +85,7 @@ using namespace epee;
# include <boost/algorithm/string.hpp>
# include <boost/algorithm/string.hpp>
# include <boost/asio.hpp>
# include <boost/asio.hpp>
# include <boost/format.hpp>
# include <boost/format.hpp>
# include <openssl/ sha .h>
# include <openssl/ evp .h>
# undef MONERO_DEFAULT_LOG_CATEGORY
# undef MONERO_DEFAULT_LOG_CATEGORY
# define MONERO_DEFAULT_LOG_CATEGORY "util"
# define MONERO_DEFAULT_LOG_CATEGORY "util"
@ -941,14 +941,7 @@ std::string get_nix_version_display_string()
bool sha256sum ( const uint8_t * data , size_t len , crypto : : hash & hash )
bool sha256sum ( const uint8_t * data , size_t len , crypto : : hash & hash )
{
{
SHA256_CTX ctx ;
return EVP_Digest ( data , len , ( unsigned char * ) hash . data , NULL , EVP_sha256 ( ) , NULL ) ! = 0 ;
if ( ! SHA256_Init ( & ctx ) )
return false ;
if ( ! SHA256_Update ( & ctx , data , len ) )
return false ;
if ( ! SHA256_Final ( ( unsigned char * ) hash . data , & ctx ) )
return false ;
return true ;
}
}
bool sha256sum ( const std : : string & filename , crypto : : hash & hash )
bool sha256sum ( const std : : string & filename , crypto : : hash & hash )
@ -961,8 +954,8 @@ std::string get_nix_version_display_string()
if ( ! f )
if ( ! f )
return false ;
return false ;
std : : ifstream : : pos_type file_size = f . tellg ( ) ;
std : : ifstream : : pos_type file_size = f . tellg ( ) ;
SHA256_CTX ctx ;
std: : unique_ptr < EVP_MD_CTX , decltype ( & EVP_MD_CTX_free ) > ctx ( EVP_MD_CTX_new ( ) , & EVP_MD_CTX_free ) ;
if ( ! SHA256_Init( & ctx ) )
if ( ! EVP_DigestInit_ex( ctx . get ( ) , EVP_sha256 ( ) , nullptr ) )
return false ;
return false ;
size_t size_left = file_size ;
size_t size_left = file_size ;
f . seekg ( 0 , std : : ios : : beg ) ;
f . seekg ( 0 , std : : ios : : beg ) ;
@ -973,12 +966,12 @@ std::string get_nix_version_display_string()
f . read ( buf , read_size ) ;
f . read ( buf , read_size ) ;
if ( ! f | | ! f . good ( ) )
if ( ! f | | ! f . good ( ) )
return false ;
return false ;
if ( ! SHA256_Update( & ctx , buf , read_size ) )
if ( ! EVP_DigestUpdate( ctx . get ( ) , buf , read_size ) )
return false ;
return false ;
size_left - = read_size ;
size_left - = read_size ;
}
}
f . close ( ) ;
f . close ( ) ;
if ( ! SHA256_Final( ( unsigned char * ) hash . data , & ctx ) )
if ( ! EVP_DigestFinal_ex( ctx . get ( ) , ( unsigned char * ) hash . data , nullptr ) )
return false ;
return false ;
return true ;
return true ;
}
}