Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
MD5Util.h
Go to the documentation of this file.
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
22#pragma once
23
24#include "sese/io/Stream.h"
25
26namespace sese {
27
31class MD5Util {
32public:
35
41 static void encode(const InputStream::Ptr &input, const OutputStream::Ptr &output) noexcept;
47 static void encode(InputStream *input, OutputStream *output) noexcept;
48
55 static std::unique_ptr<char[]> encode(const InputStream::Ptr &input, bool is_cap = true) noexcept;
62 static std::unique_ptr<char[]> encode(InputStream *input, bool is_cap = true) noexcept;
63
64private:
65 static void transform(uint32_t *res, uint8_t *buffer) noexcept;
66
67 static const uint32_t A = 0x67452301;
68 static const uint32_t B = 0xefcdab89;
69 static const uint32_t C = 0x98badcfe;
70 static const uint32_t D = 0x10325476;
71
72 static const uint32_t S11 = 7;
73 static const uint32_t S12 = 12;
74 static const uint32_t S13 = 17;
75 static const uint32_t S14 = 22;
76
77 static const uint32_t S21 = 5;
78 static const uint32_t S22 = 9;
79 static const uint32_t S23 = 14;
80 static const uint32_t S24 = 20;
81
82 static const uint32_t S31 = 4;
83 static const uint32_t S32 = 11;
84 static const uint32_t S33 = 16;
85 static const uint32_t S34 = 23;
86
87 static const uint32_t S41 = 6;
88 static const uint32_t S42 = 10;
89 static const uint32_t S43 = 15;
90 static const uint32_t S44 = 21;
91
92 constexpr static const unsigned char PADDING[64] = {0x80};
93
94 static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z) noexcept;
95 static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z) noexcept;
96 static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z) noexcept;
97 static inline uint32_t I(uint32_t x, uint32_t y, uint32_t z) noexcept;
98
99 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;
100 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;
101 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;
102 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;
103};
104} // namespace sese