]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_hash.h
Add Base64 encode/decode functions to the core
[user/henk/code/inspircd.git] / src / modules / m_hash.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 class HashProvider : public DataProvider
23 {
24  public:
25         HashProvider(Module* mod, const std::string& Name) : DataProvider(mod, Name) {}
26         virtual std::string sum(const std::string& data) = 0;
27         inline std::string hexsum(const std::string& data)
28         {
29                 return BinToHex(sum(data));
30         }
31
32         inline std::string b64sum(const std::string& data)
33         {
34                 return BinToBase64(sum(data), NULL, 0);
35         }
36
37         /** Allows the IVs for the hash to be specified. As the choice of initial IV is
38          * important for the security of a hash, this should not be used except to
39          * maintain backwards compatability. This also allows you to change the hex
40          * sequence from its default of "0123456789abcdef", which does not improve the
41          * strength of the output, but helps confuse those attempting to implement it.
42          *
43          * Example:
44          * \code
45          * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC };
46          * std::string result = Hash.sumIV(iv, "fedcba9876543210", "data");
47          * \endcode
48          */
49         virtual std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata) = 0;
50 };
51
52 #endif
53