Fix the removal of implicit conversions in libfmt 10 by using explicit casts.
[0ad.git] / source / maths / MD5.h
blob283b9c0be49d64292ff8f8267ba695250d070bbe
1 /* Copyright (C) 2010 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_MD5
19 #define INCLUDED_MD5
21 #include <cstring>
23 /**
24 * MD5 hashing algorithm. Note that MD5 is broken and must not be used for
25 * anything that requires security.
27 class MD5
29 public:
30 static const size_t DIGESTSIZE = 16;
32 MD5();
34 void Update(const u8* data, size_t len)
36 // (Defined inline for efficiency in the common fixed-length fits-in-buffer case)
38 const size_t CHUNK_SIZE = sizeof(m_Buf);
40 m_InputLen += len;
42 // If we have enough space in m_Buf and won't flush, simply append the input
43 if (m_BufLen + len < CHUNK_SIZE)
45 memcpy(m_Buf + m_BufLen, data, len);
46 m_BufLen += len;
47 return;
50 // Fall back to non-inline function if we have to do more work
51 UpdateRest(data, len);
54 void Final(u8* digest);
56 private:
57 void InitState();
58 void UpdateRest(const u8* data, size_t len);
59 void Transform(const u32* in);
60 u32 m_Digest[4]; // internal state
61 u8 m_Buf[64]; // buffered input bytes
62 size_t m_BufLen; // bytes in m_Buf that are valid
63 u64 m_InputLen; // bytes
66 #endif // INCLUDED_MD5