]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hash.h
Fix infinite loop on alias expansion, found by Adam
[user/henk/code/inspircd.git] / src / modules / m_hash.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __HASH_H__
15 #define __HASH_H__
16
17 #include "modules.h"
18
19 #define SHA256_DIGEST_SIZE (256 / 8)
20 #define SHA256_BLOCK_SIZE  (512 / 8)
21
22 /** Query a hash algorithm's name
23  *
24  * Example:
25  * \code
26  * cout << "Using hash algorithm: " << HashNameRequest(this, HashModule).response;
27  * \endcode
28  */
29 struct HashNameRequest : public Request
30 {
31         std::string response;
32         HashNameRequest(Module* Me, Module* Target) : Request(Me, Target, "NAME")
33         {
34                 Send();
35         }
36 };
37
38 /** Send this class to the hashing module to HashSUM a std::string.
39  *
40  * Example:
41  * \code
42  * // Get the Hash sum of the string 'doodads'.
43  * std::string result = HashRequest(this, HashModule, "doodads").result;
44  * \endcode
45  */
46 struct HashRequest : public Request
47 {
48         const std::string data;
49         std::string binresult;
50         /** Initialize HashSumRequest for sending.
51          * @param Me A pointer to the sending module
52          * @param Target A pointer to the hashing module
53          * @param data The data to be hashed
54          */
55         HashRequest(Module* Me, Module* Target, const std::string &sdata)
56                 : Request(Me, Target, "HASH"), data(sdata)
57         {
58                 Send();
59         }
60         inline std::string hex()
61         {
62                 return BinToHex(binresult);
63         }
64 };
65
66 /** Allows the IVs for the hash to be specified. As the choice of initial IV is
67  * important for the security of a hash, this should not be used except to
68  * maintain backwards compatability. This also allows you to change the hex
69  * sequence from its default of "0123456789abcdef", which does not improve the
70  * strength of the output, but helps confuse those attempting to implement it.
71  *
72  * Only m_md5 implements this request; only m_cloaking should use it.
73  *
74  * Example:
75  * \code
76  * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };
77  * std::string result = HashRequestIV(this, HashModule, iv, "0123456789abcdef", "data").result;
78  * \endcode
79  */
80 struct HashRequestIV : public Request
81 {
82         unsigned int* iv;
83         const char* map;
84         std::string result;
85         const std::string data;
86         HashRequestIV(Module* Me, Module* Target, unsigned int* IV, const char* HexMap, const std::string &sdata)
87                 : Request(Me, Target, "HASH-IV"), iv(IV), map(HexMap), data(sdata)
88         {
89                 Send();
90         }
91 };
92
93 #endif
94