diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-10 17:06:52 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-10 17:06:52 +0000 |
commit | 26cd5393c9308fabe73c41870f06f73a5b001cd7 (patch) | |
tree | f9cfd6afe3b35ea81add40d4bb5246a66a536f16 /src/modules/m_sha256.cpp | |
parent | 892b3fde2fa974e339f049283d8d3e5f75a49107 (diff) |
Update m_cloaking to use free-form keys instead of weakening the hash IV
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11820 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_sha256.cpp')
-rw-r--r-- | src/modules/m_sha256.cpp | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/modules/m_sha256.cpp b/src/modules/m_sha256.cpp index 07c9ea04b..f1b649f30 100644 --- a/src/modules/m_sha256.cpp +++ b/src/modules/m_sha256.cpp @@ -132,8 +132,6 @@ uint32_t sha256_k[64] = 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; -const char* const hxc("0123456789abcdef"); - class ModuleSHA256 : public Module { void SHA256Init(SHA256Context *ctx, const unsigned int* ikey) @@ -238,22 +236,12 @@ class ModuleSHA256 : public Module UNPACK32(ctx->h[i], &digest[i << 2]); } - void SHA256(const char *src, char *dest, unsigned int len) + void SHA256(const char *src, unsigned char *dest, unsigned int len) { - // Generate the hash - unsigned char bytehash[SHA256_DIGEST_SIZE]; SHA256Context ctx; SHA256Init(&ctx, NULL); SHA256Update(&ctx, (unsigned char *)src, len); - SHA256Final(&ctx, bytehash); - // Convert it to hex - int j=0; - for (int i = 0; i < SHA256_DIGEST_SIZE; i++) - { - dest[j++] = hxc[bytehash[i] / 16]; - dest[j++] = hxc[bytehash[i] % 16]; - } - dest[j] = '\0'; + SHA256Final(&ctx, dest); } public: @@ -272,10 +260,10 @@ class ModuleSHA256 : public Module { if (strcmp("HASH", request.id) == 0) { - char res[65]; + unsigned char bytes[SHA256_DIGEST_SIZE]; HashRequest& req = static_cast<HashRequest&>(request); - SHA256(req.data.data(), res, req.data.length()); - req.result = res; + SHA256(req.data.data(), bytes, req.data.length()); + req.binresult.assign((char*)bytes, SHA256_DIGEST_SIZE); } else if (strcmp("NAME", request.id) == 0) { |