MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
md5.hpp
1#ifndef MSTL_CORE_ENCRYPT_MD5_HPP__
2#define MSTL_CORE_ENCRYPT_MD5_HPP__
3#include "../string/string.hpp"
5
6class MSTL_API MD5 {
7private:
8 static constexpr uint32_t S[64] = {
9 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
10 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
11 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
12 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
13 };
14
15 static constexpr uint32_t K[64] = {
16 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
17 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
18 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
19 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
20 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
21 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
22 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
23 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
24 };
25
26 static constexpr uint32_t rotleft(const uint32_t x, const uint32_t c) { return (x << c) | (x >> (32 - c)); }
27
28 static constexpr uint32_t F(const uint32_t x, const uint32_t y, const uint32_t z) { return (x & y) | (~x & z); }
29 static constexpr uint32_t G(const uint32_t x, const uint32_t y, const uint32_t z) { return (x & z) | (y & ~z); }
30 static constexpr uint32_t H(const uint32_t x, const uint32_t y, const uint32_t z) { return x ^ y ^ z; }
31 static constexpr uint32_t I(const uint32_t x, const uint32_t y, const uint32_t z) { return y ^ (x | ~z); }
32
33public:
34 static bstring hash(bstring_view data);
35 static string hash_hex(bstring_view data);
36};
37
38
39MSTL_ALWAYS_INLINE_INLINE string md5(const bstring& data) {
40 return MD5::hash_hex(data.view());
41}
42MSTL_ALWAYS_INLINE_INLINE string md5(const string& data) {
43 return md5(to_bstring(data));
44}
45
46MSTL_ALWAYS_INLINE_INLINE string md5(const bstring_view data) {
47 return MD5::hash_hex(data);
48}
49MSTL_ALWAYS_INLINE_INLINE string md5(const string_view data) {
50 return md5(to_bstring(data));
51}
52
53MSTL_ALWAYS_INLINE_INLINE string md5(const char* data) {
54 return md5(string_view{data});
55}
56
58#endif // MSTL_CORE_ENCRYPT_MD5_HPP__
unsigned int uint32_t
32位无符号整数类型
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针