Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
MD5Util.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
21#pragma once
22
23#include "sese/io/Stream.h"
24
25namespace sese {
26
30class MD5Util {
31public:
36
42 static void encode(const InputStream::Ptr &input, const OutputStream::Ptr &output) noexcept;
48 static void encode(InputStream *input, OutputStream *output) noexcept;
49
56 static std::unique_ptr<char[]> encode(const InputStream::Ptr &input, bool is_cap = true) noexcept;
63 static std::unique_ptr<char[]> encode(InputStream *input, bool is_cap = true) noexcept;
64
65private:
67 static void transform(uint32_t *res, uint8_t *buffer) noexcept;
68
69 static const uint32_t A = 0x67452301;
70 static const uint32_t B = 0xefcdab89;
71 static const uint32_t C = 0x98badcfe;
72 static const uint32_t D = 0x10325476;
73
74 static const uint32_t S11 = 7;
75 static const uint32_t S12 = 12;
76 static const uint32_t S13 = 17;
77 static const uint32_t S14 = 22;
78
79 static const uint32_t S21 = 5;
80 static const uint32_t S22 = 9;
81 static const uint32_t S23 = 14;
82 static const uint32_t S24 = 20;
83
84 static const uint32_t S31 = 4;
85 static const uint32_t S32 = 11;
86 static const uint32_t S33 = 16;
87 static const uint32_t S34 = 23;
88
89 static const uint32_t S41 = 6;
90 static const uint32_t S42 = 10;
91 static const uint32_t S43 = 15;
92 static const uint32_t S44 = 21;
93
94 constexpr static const unsigned char PADDING[64] = {0x80};
95
96 static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z) noexcept;
97 static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z) noexcept;
98 static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z) noexcept;
99 static inline uint32_t I(uint32_t x, uint32_t y, uint32_t z) noexcept;
100
101 static inline uint32_t FF(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t t) noexcept;
102 static inline uint32_t GG(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t t) noexcept;
103 static inline uint32_t HH(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t t) noexcept;
104 static inline uint32_t II(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t t) noexcept;
105};
106} // namespace sese