]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_hash.h
Reset the already_sent IDs during slow garbage collection
[user/henk/code/inspircd.git] / src / modules / m_hash.h
index d82104cdb97b8b1527f16e76cd2ab3228ec6643a..7deb4c68c74305a62144fa3443b6cffabf6954f1 100644 (file)
@@ -1 +1,50 @@
-/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#ifndef __HASH_H__\r#define __HASH_H__\r\r#include "modules.h"\r\r#define SHA256_DIGEST_SIZE (256 / 8)\r#define SHA256_BLOCK_SIZE  (512 / 8)\r\r/** HashRequest is the base class used to send Hash requests to hashing.so.\r * You should not instantiate classes of type HashRequest directly, instead\r * you should instantiate classes of type HashResetRequest, HashSumRequest,\r * HashKeyRequest and HashHexRequest, shown below.\r */\rclass HashRequest : public Request\r{\r   /** The keys (IV) to use */\r    unsigned int* keys;\r    /** The output characters (hex sequence) to use */\r     const char* outputs;\r   /** The string to hash */\r      std::string tohash;\r public:\r   /** Initialize HashRequest as an Hash_RESET message */\r HashRequest(const char* req, Module* Me, Module* Target) : Request(Me, Target, req)\r    {\r      }\r\r     /** Initialize HashRequest as an Hash_SUM message */\r   HashRequest(Module* Me, Module* Target, const std::string &hashable) : Request(Me, Target, "SUM"), keys(NULL), outputs(NULL), tohash(hashable)\r {\r      }\r\r     /** Initialize HashRequest as an Hash_KEY message */\r   HashRequest(Module* Me, Module* Target, unsigned int* k) : Request(Me, Target, "KEY"), keys(k), outputs(NULL), tohash("")\r      {\r      }\r\r     /** Initialize HashRequest as an Hash_HEX message */\r   HashRequest(Module* Me, Module* Target, const char* out) : Request(Me, Target, "HEX"), keys(NULL), outputs(out), tohash("")\r    {\r      }\r\r     /** Get data to be hashed */\r   const char* GetHashData()\r      {\r              return tohash.c_str();\r }\r\r     /** Get keys (IVs) to be used */\r       unsigned int* GetKeyData()\r     {\r              return keys;\r   }\r\r     /** Get output characters (hex sequence) to be used */\r const char* GetOutputs()\r       {\r              return outputs;\r        }\r};\r\r/** Send this class to the hashing module to query for its name.\r *\r * Example:\r * \code\r * cout << "Using hash algorithm: " << HashNameRequest(this, HashModule).Send();\r * \endcode\r */\rclass HashNameRequest : public HashRequest\r{\r public:\r  /** Initialize HashNameRequest for sending.\r     * @param Me A pointer to the sending module\r    * @param Target A pointer to the hashing module\r        */\r    HashNameRequest(Module* Me, Module* Target) : HashRequest("NAME", Me, Target)\r  {\r      }\r};\r\r/** Send this class to the hashing module to reset the Hash module to a known state.\r * This will reset the IV to the defaults specified by the Hash spec,\r * and reset the hex sequence to "0123456789abcdef". It should be sent before\r * ANY other Request types.\r *\r * Example:\r * \code\r * // Reset the Hash module.\r * HashResetRequest(this, HashModule).Send();\r * \endcode\r */\rclass HashResetRequest : public HashRequest\r{\r public:\r   /** Initialize HashResetRequest for sending.\r    * @param Me A pointer to the sending module\r    * @param Target A pointer to the hashing module\r        */\r    HashResetRequest(Module* Me, Module* Target) : HashRequest("RESET", Me, Target)\r        {\r      }\r};\r\r/** Send this class to the hashing module to HashSUM a std::string.\r * You should make sure you know the state of the module before you send this\r * class, e.g. by first sending an HashResetRequest class. The hash will be\r * returned when you call Send().\r *\r * Example:\r * \code\r * // ALWAYS ALWAYS reset first, or set your own IV and hex chars.\r * HashResetRequest(this, HashModule).Send();\r * // Get the Hash sum of the string 'doodads'.\r * std::string result = HashSumRequest(this, HashModule, "doodads").Send();\r * \endcode\r */\rclass HashSumRequest : public HashRequest\r{\r public:\r        /** Initialize HashSumRequest for sending.\r      * @param Me A pointer to the sending module\r    * @param Target A pointer to the hashing module\r        * @param data The data to be hashed\r    */\r    HashSumRequest(Module* Me, Module* Target, const std::string &data) : HashRequest(Me, Target, data)\r    {\r      }\r};\r\r/** Send this class to hashing module to change the IVs (keys) to use for hashing.\r * You should make sure you know the state of the module before you send this\r * class, e.g. by first sending an HashResetRequest class. The default values for\r * the IV's are those specified in the Hash specification. Only in very special\r * circumstances should you need to change the IV's (see for example m_cloaking.cpp)\r *\r * Example:\r * \code\r * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };\r * HashKeyRequest(this, HashModule, iv);\r * \endcode\r */\rclass HashKeyRequest : public HashRequest\r{\r public:\r /** Initialize HashKeyRequest for sending.\r      * @param Me A pointer to the sending module\r    * @param Target A pointer to the hashing module\r        * @param data The new IV's. This should be an array of exactly four 32 bit values.\r     * On 64-bit architectures, the upper 32 bits of the values will be discarded.\r  */\r    HashKeyRequest(Module* Me, Module* Target, unsigned int* data) : HashRequest(Me, Target, data)\r {\r      }\r};\r\r/** Send this class to the hashing module to change the hex sequence to use for generating the returned value.\r * You should make sure you know the state of the module before you send this\r * class, e.g. by first sending an HashResetRequest class. The default value for\r * the hex sequence is "0123456789abcdef". Only in very special circumstances should\r * you need to change the hex sequence (see for example m_cloaking.cpp).\r *\r * Example:\r * \code\r * static const char tab[] = "fedcba9876543210";\r * HashHexRequest(this, HashModule, tab);\r * \endcode\r */\rclass HashHexRequest : public HashRequest\r{\r public:\r      /** Initialize HashHexRequest for sending.\r      * @param Me A pointer to the sending module\r    * @param Target A pointer to the hashing module\r        * @param data The hex sequence to use. This should contain exactly 16 ASCII characters,\r        * terminated by a NULL char.\r   */\r    HashHexRequest(Module* Me, Module* Target, const char* data) : HashRequest(Me, Target, data)\r   {\r      }\r};\r\r#endif\r\r
\ No newline at end of file
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#ifndef __HASH_H__
+#define __HASH_H__
+
+#include "modules.h"
+
+#define SHA256_DIGEST_SIZE (256 / 8)
+#define SHA256_BLOCK_SIZE  (512 / 8)
+
+class HashProvider : public DataProvider
+{
+ public:
+       HashProvider(Module* mod, const std::string& Name) : DataProvider(mod, Name) {}
+       virtual std::string sum(const std::string& data) = 0;
+       inline std::string hexsum(const std::string& data)
+       {
+               return BinToHex(sum(data));
+       }
+
+       /** Allows the IVs for the hash to be specified. As the choice of initial IV is
+        * important for the security of a hash, this should not be used except to
+        * maintain backwards compatability. This also allows you to change the hex
+        * sequence from its default of "0123456789abcdef", which does not improve the
+        * strength of the output, but helps confuse those attempting to implement it.
+        *
+        * Only m_md5 implements this request; only m_cloaking should use it.
+        *
+        * Example:
+        * \code
+        * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };
+        * std::string result = Hash.sumIV(iv, "0123456789abcdef", "data");
+        * \endcode
+        */
+       virtual std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata) = 0;
+};
+
+#endif
+