]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hash.h
Update Event and Request APIs
[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 result;
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 };
61
62 /** Allows the IVs for the hash to be specified. As the choice of initial IV is
63  * important for the security of a hash, this should not be used except to
64  * maintain backwards compatability. This also allows you to change the hex
65  * sequence from its default of "0123456789abcdef", which does not improve the
66  * strength of the output, but helps confuse those attempting to implement it.
67  *
68  * Only m_md5 implements this request; only m_cloaking should use it.
69  *
70  * Example:
71  * \code
72  * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };
73  * std::string result = HashRequestIV(this, HashModule, iv, "0123456789abcdef", "data").result;
74  * \endcode
75  */
76 struct HashRequestIV : public Request
77 {
78         unsigned int* iv;
79         const char* map;
80         std::string result;
81         const std::string data;
82         HashRequestIV(Module* Me, Module* Target, unsigned int* IV, const char* HexMap, const std::string &sdata)
83                 : Request(Me, Target, "HASH-IV"), iv(IV), map(HexMap), data(sdata)
84         {
85                 Send();
86         }
87 };
88
89 #endif
90