From 26cd5393c9308fabe73c41870f06f73a5b001cd7 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 10 Oct 2009 17:06:52 +0000 Subject: 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 --- src/modules/m_sha256.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'src/modules/m_sha256.cpp') 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(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) { -- cgit v1.2.3