X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_md5.cpp;h=c902ee3cb753c8f9c527a0bfd3e381656261c766;hb=9f69e159adcc0892f0bdef16ac4617630737b156;hp=aea9f2806f5f9ee761bf588cf16e9ab84d06457d;hpb=43847ec9c7e1a195163eb4c529f1c92fd1ace0a4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index aea9f2806..c902ee3cb 100644 --- a/src/modules/m_md5.cpp +++ b/src/modules/m_md5.cpp @@ -1,24 +1,33 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2008 Pippijn van Steenhoven + * Copyright (C) 2007-2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006 Craig Edwards * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + /* $ModDesc: Allows for MD5 encrypted oper passwords */ -/* $ModDep: m_hash.h */ #include "inspircd.h" #ifdef HAS_STDINT #include #endif -#include "m_hash.h" +#include "hash.h" /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -39,7 +48,7 @@ typedef unsigned char byte; /** An MD5 context, used by m_opermd5 */ -class MD5Context : public classbase +class MD5Context { public: word32 buf[4]; @@ -47,7 +56,7 @@ class MD5Context : public classbase word32 in[16]; }; -class ModuleMD5 : public Module +class MD5Provider : public HashProvider { void byteSwap(word32 *buf, unsigned words) { @@ -149,12 +158,12 @@ class ModuleMD5 : public Module byteSwap(ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); + memset(ctx, 0, sizeof(*ctx)); } void MD5Transform(word32 buf[4], word32 const in[16]) { - register word32 a, b, c, d; + word32 a, b, c, d; a = buf[0]; b = buf[1]; @@ -258,59 +267,36 @@ class ModuleMD5 : public Module } *dest++ = 0; } - - unsigned int *key; - char* chars; - public: - - ModuleMD5(InspIRCd* Me) - : Module(Me), key(NULL), chars(NULL) + std::string sum(const std::string& data) { - ServerInstance->Modules->PublishInterface("HashRequest", this); - Implementation eventlist[] = { I_OnRequest }; - ServerInstance->Modules->Attach(eventlist, this, 1); + char res[16]; + MyMD5(res, (void*)data.data(), data.length(), NULL); + return std::string(res, 16); } - virtual ~ModuleMD5() + std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata) { - ServerInstance->Modules->UnpublishInterface("HashRequest", this); + char res[33]; + GenHash(sdata.data(), res, HexMap, IV, sdata.length()); + return res; } + MD5Provider(Module* parent) : HashProvider(parent, "hash/md5", 16, 64) {} +}; - virtual const char* OnRequest(Request* request) +class ModuleMD5 : public Module +{ + MD5Provider md5; + public: + ModuleMD5() : md5(this) { - HashRequest* MD5 = (HashRequest*)request; - - if (strcmp("KEY", request->GetId()) == 0) - { - this->key = (unsigned int*)MD5->GetKeyData(); - } - else if (strcmp("HEX", request->GetId()) == 0) - { - this->chars = (char*)MD5->GetOutputs(); - } - else if (strcmp("SUM", request->GetId()) == 0) - { - static char data[MAXBUF]; - GenHash(MD5->GetHashData().data(), data, chars ? chars : "0123456789abcdef", key, MD5->GetHashData().length()); - return data; - } - else if (strcmp("NAME", request->GetId()) == 0) - { - return "md5"; - } - else if (strcmp("RESET", request->GetId()) == 0) - { - this->chars = NULL; - this->key = NULL; - } - return NULL; + ServerInstance->Modules->AddService(md5); } - virtual Version GetVersion() + Version GetVersion() { - return Version("$Id$",VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION); + return Version("Implements MD5 hashing",VF_VENDOR); } };