X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fhash.h;h=ca27cd0ac8797b2f3ff4295f25295132e80f6223;hb=b0f16081ccaef527ed4b5434a7264508cf455f39;hp=da04c45ba9d2bfd8500c33bcb489e73ca30981f0;hpb=e244cb2c63b1ac1d85bdbb4691f7b1bd940ae804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/hash.h b/include/modules/hash.h index da04c45ba..ca27cd0ac 100644 --- a/include/modules/hash.h +++ b/include/modules/hash.h @@ -1,7 +1,12 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2010 Daniel De Graaf + * Copyright (C) 2014 Daniel Vassdal + * Copyright (C) 2013 Sadie Powell + * Copyright (C) 2012 Robby + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006 Craig Edwards * * 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 @@ -26,24 +31,33 @@ class HashProvider : public DataProvider public: const unsigned int out_size; const unsigned int block_size; - HashProvider(Module* mod, const std::string& Name, int osiz, int bsiz) - : DataProvider(mod, Name), out_size(osiz), block_size(bsiz) {} - virtual std::string sum(const std::string& data) = 0; - inline std::string hexsum(const std::string& data) + HashProvider(Module* mod, const std::string& Name, unsigned int osiz = 0, unsigned int bsiz = 0) + : DataProvider(mod, "hash/" + Name), out_size(osiz), block_size(bsiz) { - return BinToHex(sum(data)); } - inline std::string b64sum(const std::string& data) + virtual std::string GenerateRaw(const std::string& data) = 0; + + virtual std::string ToPrintable(const std::string& raw) + { + return BinToHex(raw); + } + + virtual bool Compare(const std::string& input, const std::string& hash) + { + return InspIRCd::TimingSafeCompare(Generate(input), hash); + } + + std::string Generate(const std::string& data) { - return BinToBase64(sum(data), NULL, 0); + return ToPrintable(GenerateRaw(data)); } /** HMAC algorithm, RFC 2104 */ std::string hmac(const std::string& key, const std::string& msg) { std::string hmac1, hmac2; - std::string kbuf = key.length() > block_size ? sum(key) : key; + std::string kbuf = key.length() > block_size ? GenerateRaw(key) : key; kbuf.resize(block_size); for (size_t n = 0; n < block_size; n++) @@ -52,7 +66,12 @@ class HashProvider : public DataProvider hmac2.push_back(static_cast(kbuf[n] ^ 0x36)); } hmac2.append(msg); - hmac1.append(sum(hmac2)); - return sum(hmac1); + hmac1.append(GenerateRaw(hmac2)); + return GenerateRaw(hmac1); + } + + bool IsKDF() const + { + return (!block_size); } };