mirror of
https://github.com/znc/znc.git
synced 2026-05-05 04:52:31 +02:00
Add sha256 support
This imports the sha256 code from http://www.ouah.org/ogay/sha2/ (The other hashes from sha-2 were removed). sha256 is a much stronger hashing algorithm than md5 is (There were successful birthday attacks against md5). All the code now defaults to creating sha256 salted hashes (The salting used is the same as before). Old znc.conf files can still be read. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1618 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -8,8 +8,9 @@
|
||||
|
||||
#include "ZNCString.h"
|
||||
#include "FileUtils.h"
|
||||
#include "MD5.h"
|
||||
#include "Utils.h"
|
||||
#include "MD5.h"
|
||||
#include "SHA256.h"
|
||||
#include <sstream>
|
||||
|
||||
using std::stringstream;
|
||||
@@ -867,6 +868,26 @@ CString CString::MD5() const {
|
||||
return (const char*) CMD5(*this);
|
||||
}
|
||||
|
||||
CString CString::SHA256() const {
|
||||
unsigned char digest[SHA256_DIGEST_SIZE];
|
||||
char digest_hex[SHA256_DIGEST_SIZE * 2 + 1];
|
||||
const unsigned char *message = (const unsigned char *) c_str();
|
||||
|
||||
sha256(message, length(), digest);
|
||||
|
||||
sprintf(digest_hex,
|
||||
"%02x%02x%02x%02x%02x%02x%02x%02x"
|
||||
"%02x%02x%02x%02x%02x%02x%02x%02x"
|
||||
"%02x%02x%02x%02x%02x%02x%02x%02x"
|
||||
"%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
digest[ 0], digest[ 1], digest[ 2], digest[ 3], digest[ 4], digest[ 5], digest[ 6], digest[ 7],
|
||||
digest[ 8], digest[ 9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15],
|
||||
digest[16], digest[17], digest[18], digest[19], digest[20], digest[21], digest[22], digest[23],
|
||||
digest[24], digest[25], digest[26], digest[27], digest[28], digest[29], digest[30], digest[31]);
|
||||
|
||||
return digest_hex;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
CString CString::Encrypt_n(const CString& sPass, const CString& sIvec) {
|
||||
CString sRet;
|
||||
|
||||
Reference in New Issue
Block a user