added sha256 calculation functions, and non backward compatible SSL Id computation code to active later (0.7)

This commit is contained in:
csoler 2017-11-15 23:24:43 +01:00
parent ba7cf4995b
commit 7472f78223
5 changed files with 63 additions and 6 deletions

View file

@ -610,6 +610,27 @@ Sha1CheckSum RsDirUtil::sha1sum(const unsigned char *data, uint32_t size)
return Sha1CheckSum(sha_buf) ;
}
Sha256CheckSum RsDirUtil::sha256sum(const unsigned char *data, uint32_t size)
{
SHA256_CTX sha_ctx ;
if(SHA256_DIGEST_LENGTH != 32)
throw std::runtime_error("Warning: can't compute Sha2561Sum with sum size != 32") ;
SHA256_Init(&sha_ctx);
while(size > 512)
{
SHA256_Update(&sha_ctx, data, 512);
data = &data[512] ;
size -= 512 ;
}
SHA256_Update(&sha_ctx, data, size);
unsigned char sha_buf[SHA256_DIGEST_LENGTH];
SHA256_Final(&sha_buf[0], &sha_ctx);
return Sha256CheckSum(sha_buf) ;
}
bool RsDirUtil::saveStringToFile(const std::string &file, const std::string &str)
{
std::ofstream out(file.c_str(), std::ios_base::out | std::ios_base::binary);

View file

@ -101,7 +101,8 @@ bool cleanupDirectoryFaster(const std::string& dir, const std::set<std::stri
bool hashFile(const std::string& filepath, std::string &name, RsFileHash &hash, uint64_t &size);
bool getFileHash(const std::string& filepath,RsFileHash &hash, uint64_t &size, RsThread *thread = NULL);
Sha1CheckSum sha1sum(const uint8_t *data,uint32_t size) ;
Sha1CheckSum sha1sum(const uint8_t *data,uint32_t size) ;
Sha256CheckSum sha256sum(const uint8_t *data,uint32_t size) ;
bool saveStringToFile(const std::string& file, const std::string& str);
bool loadStringFromFile(const std::string& file, std::string& str);