Commit | Line | Data |
---|---|---|
69d568dd TC |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
20 | /** | |
21 | Hashing functions based upon openssl. | |
22 | ||
23 | @copyright Intra2net AG | |
24 | */ | |
25 | ||
26 | #ifndef CRYPTO_HXX | |
27 | #define CRYPTO_HXX | |
28 | ||
29 | ||
30 | #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) | |
31 | using namespace std; | |
32 | #endif | |
33 | ||
34 | #include <openssl/evp.h> | |
35 | #include <boost/shared_array.hpp> | |
36 | #include <boost/shared_ptr.hpp> | |
37 | ||
38 | namespace I2n { | |
39 | ||
40 | enum algorithm { NONE=0, MD5=1, SHA1=2, SHA256=8, SHA384=9, SHA512=10 }; | |
41 | ||
42 | // output: hex encoded hash | |
2bf8e5a0 | 43 | string hash_data(string data, algorithm algo); |
69d568dd TC |
44 | |
45 | // output: raw binary hash | |
2bf8e5a0 | 46 | string hash_data_raw(string data, algorithm algo); |
69d568dd TC |
47 | |
48 | // hash data in 64kB blocks | |
2bf8e5a0 | 49 | string hash_file(string filename, algorithm algo); |
69d568dd TC |
50 | |
51 | string encode_hex(string data); | |
52 | ||
53 | string encode_hex(char *data, unsigned int size); | |
54 | ||
55 | typedef boost::shared_array<char> char_arr; | |
56 | ||
57 | typedef boost::shared_array<unsigned char> uchar_arr; | |
58 | ||
59 | typedef boost::shared_ptr<EVP_MD_CTX> EVP_MD_CTX_Ptr; | |
60 | }; // eo I2n namespace | |
61 | ||
62 | #endif /* [CRYPTO_HXX] */ |