]> git.tdb.fi Git - libs/crypto.git/blob - source/md5.h
f47723c5b49ff619f1d6237620bb955c6ff7eba5
[libs/crypto.git] / source / md5.h
1 #ifndef MSP_CRYPTO_MD5_H_
2 #define MSP_CRYPTO_MD5_H_
3
4 #include <msp/core/inttypes.h>
5 #include "hash.h"
6
7 namespace Msp {
8 namespace Crypto {
9
10 class MD5: public Hash
11 {
12 private:
13         UInt32 buffer[4];
14         UInt64 processed_bytes;
15         char unprocessed[64];
16         unsigned unprocessed_bytes;
17
18         static UInt32 sin_table[64];
19         static unsigned rotate_table[16];
20
21 public:
22         MD5();
23         MD5(const char *, unsigned);
24         MD5(const std::string &);
25 private:
26         void init();
27
28 public:
29         virtual unsigned get_digest_size() const { return 16; }
30
31         using Hash::update;
32         virtual void update(const char *, unsigned);
33         virtual unsigned get_digest(char *, unsigned) const;
34
35 private:
36         void process_block(const char *);
37
38         template<unsigned, unsigned, unsigned>
39         static void perform_round(UInt32 *, const UInt32 *);
40 };
41
42 } // namespace Crypto
43 } // namespace Msp
44
45 #endif