X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_ripemd160.cpp;h=8d3131bc02a9639083538284a88d43766ec28243;hb=f9fd78c01623514a060c607534fc52cb73140200;hp=0768f523c9f80a527c55f49adab3835f78a37468;hpb=37f22f28a36270e8268652858ab6df1b4e0b0f7b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_ripemd160.cpp b/src/modules/m_ripemd160.cpp index 0768f523c..8d3131bc0 100644 --- a/src/modules/m_ripemd160.cpp +++ b/src/modules/m_ripemd160.cpp @@ -1,16 +1,25 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2008 Pippijn van Steenhoven + * Copyright (C) 2008 Craig Edwards + * Copyright (C) 2008 Robin Burchell * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * 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 free but copyrighted software; see - * the file COPYING for details. + * 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 . */ + /* * * AUTHOR: Antoon Bosselaers, ESAT-COSIC @@ -25,7 +34,7 @@ * The RIPEMD-160 software is freely available for use under the terms and * conditions described hereunder, which shall be deemed to be accepted by * any user of the software and applicable on any use of the software: - * + * * 1. K.U.Leuven Department of Electrical Engineering-ESAT/COSIC shall for * all purposes be considered the owner of the RIPEMD-160 software and of * all copyright, trade secret, patent or other intellectual property @@ -39,34 +48,23 @@ * circumstances K.U.Leuven R&D will be held liable for any deficiency, * fault or other mishappening with regard to the use or performance of * the software. - * 3. User agrees to give due credit to K.U.Leuven in scientific publications - * or communications in relation with the use of the RIPEMD-160 software - * as follows: RIPEMD-160 software written by Antoon Bosselaers, + * 3. User agrees to give due credit to K.U.Leuven in scientific publications + * or communications in relation with the use of the RIPEMD-160 software + * as follows: RIPEMD-160 software written by Antoon Bosselaers, * available at http://www.esat.kuleuven.be/~cosicart/ps/AB-9601/. * */ -/* $ModDesc: Allows for RIPEMD-160 encrypted oper passwords */ -/* $ModDep: m_hash.h */ - /* macro definitions */ #include "inspircd.h" -#ifdef HAS_STDINT -#include -#endif -#include "m_hash.h" +#include "modules/hash.h" #define RMDsize 160 -#ifndef HAS_STDINT -typedef unsigned char byte; -typedef unsigned int dword; -#else -typedef uint8_t byte; -typedef uint32_t dword; -#endif +typedef uint8_t byte; +typedef uint32_t dword; /* collect four bytes into one word: */ #define BYTES_TO_DWORD(strptr) \ @@ -80,12 +78,12 @@ typedef uint32_t dword; #define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* the five basic functions F(), G() and H() */ -#define F(x, y, z) ((x) ^ (y) ^ (z)) -#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define F(x, y, z) ((x) ^ (y) ^ (z)) +#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) #define H(x, y, z) (((x) | ~(y)) ^ (z)) -#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define J(x, y, z) ((x) ^ ((y) | ~(z))) - + /* the ten basic operations FF() through III() */ #define FF(a, b, c, d, e, x, s) {\ @@ -149,8 +147,11 @@ typedef uint32_t dword; } -class ModuleRIPEMD160 : public Module +class RIProv : public HashProvider { + /** Final hash value + */ + byte hashcode[RMDsize/8]; void MDinit(dword *MDbuf, unsigned int* key) { @@ -198,7 +199,7 @@ class ModuleRIPEMD160 : public Module FF(cc, dd, ee, aa, bb, X[13], 7); FF(bb, cc, dd, ee, aa, X[14], 9); FF(aa, bb, cc, dd, ee, X[15], 8); - + /* round 2 */ GG(ee, aa, bb, cc, dd, X[ 7], 7); GG(dd, ee, aa, bb, cc, X[ 4], 6); @@ -216,7 +217,7 @@ class ModuleRIPEMD160 : public Module GG(bb, cc, dd, ee, aa, X[14], 7); GG(aa, bb, cc, dd, ee, X[11], 13); GG(ee, aa, bb, cc, dd, X[ 8], 12); - + /* round 3 */ HH(dd, ee, aa, bb, cc, X[ 3], 11); HH(cc, dd, ee, aa, bb, X[10], 13); @@ -234,7 +235,7 @@ class ModuleRIPEMD160 : public Module HH(aa, bb, cc, dd, ee, X[11], 12); HH(ee, aa, bb, cc, dd, X[ 5], 7); HH(dd, ee, aa, bb, cc, X[12], 5); - + /* round 4 */ II(cc, dd, ee, aa, bb, X[ 1], 11); II(bb, cc, dd, ee, aa, X[ 9], 12); @@ -290,7 +291,7 @@ class ModuleRIPEMD160 : public Module JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6); /* parallel round 2 */ - III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); + III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); III(ddd, eee, aaa, bbb, ccc, X[11], 13); III(ccc, ddd, eee, aaa, bbb, X[ 3], 15); III(bbb, ccc, ddd, eee, aaa, X[ 7], 7); @@ -325,7 +326,7 @@ class ModuleRIPEMD160 : public Module HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7); HHH(ddd, eee, aaa, bbb, ccc, X[13], 5); - /* parallel round 4 */ + /* parallel round 4 */ GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15); GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5); GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8); @@ -377,7 +378,7 @@ class ModuleRIPEMD160 : public Module unsigned int i; /* counter */ dword X[16]; /* message words */ - memset(X, 0, 16*sizeof(dword)); + memset(X, 0, sizeof(X)); /* put bytes from strptr into X */ for (i=0; i<(lswlen&63); i++) { @@ -391,7 +392,7 @@ class ModuleRIPEMD160 : public Module if ((lswlen & 63) > 55) { /* length goes to next block */ compress(MDbuf, X); - memset(X, 0, 16*sizeof(dword)); + memset(X, 0, sizeof(X)); } /* append length in bits*/ @@ -404,8 +405,7 @@ class ModuleRIPEMD160 : public Module byte *RMD(byte *message, dword length, unsigned int* key) { - dword MDbuf[RMDsize/32]; /* contains (A, B, C, D(, E)) */ - static byte hashcode[RMDsize/8]; /* for final hash-value */ + dword MDbuf[RMDsize/32]; /* contains (A, B, C, D(E)) */ dword X[16]; /* current 16-word chunk */ unsigned int i; /* counter */ dword nbytes; /* # of bytes not yet processed */ @@ -433,64 +433,28 @@ class ModuleRIPEMD160 : public Module return (byte *)hashcode; } - - unsigned int* key; - char* chars; - - public: - - ModuleRIPEMD160(InspIRCd* Me) : Module(Me), key(NULL), chars("0123456789abcdef") +public: + std::string GenerateRaw(const std::string& data) { - ServerInstance->Modules->PublishInterface("HashRequest", this); - Implementation eventlist[] = { I_OnRequest }; - ServerInstance->Modules->Attach(eventlist, this, 1); + char* rv = (char*)RMD((byte*)data.data(), data.length(), NULL); + return std::string(rv, RMDsize / 8); } - virtual ~ModuleRIPEMD160() - { - ServerInstance->Modules->UnpublishInterface("HashRequest", this); - } + RIProv(Module* m) : HashProvider(m, "ripemd160", 20, 64) {} +}; - - virtual const char* OnRequest(Request* request) +class ModuleRIPEMD160 : public Module +{ + public: + RIProv mr; + ModuleRIPEMD160() : mr(this) { - HashRequest* SHA = (HashRequest*)request; - if (strcmp("KEY", request->GetId()) == 0) - { - this->key = (unsigned int*)SHA->GetKeyData(); - } - else if (strcmp("HEX", request->GetId()) == 0) - { - this->chars = (char*)SHA->GetOutputs(); - } - else if (strcmp("SUM", request->GetId()) == 0) - { - int j = 0; - static char* data; - data = (char*)RMD((byte *)SHA->GetHashData().data(),SHA->GetHashData().length(), key); - for (int i = 0, j = 0; i < RMDsize / 8; i++) - { - data[j++] = chars[data[i] / 16]; - data[j++] = chars[data[i] % 16]; - data[j] = '\0'; - } - return data; - } - else if (strcmp("NAME", request->GetId()) == 0) - { - return "ripemd160"; - } - else if (strcmp("RESET", request->GetId()) == 0) - { - this->chars = "0123456789abcdef"; - this->key = NULL; - } - return NULL; } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version(1, 2, 0, 1, VF_VENDOR|VF_SERVICEPROVIDER, API_VERSION); + return Version("Provides RIPEMD-160 hashing", VF_VENDOR); } +}; -}; \ No newline at end of file +MODULE_INIT(ModuleRIPEMD160)