Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / 3rdparty / md5 / md5.h
blob29c7167944c2294a5fef72468c2b8f6a28d0d7b7
1 /** @file md5.h Functions to create MD5 checksums. */
3 /*
4 Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
22 L. Peter Deutsch
23 ghost@aladdin.com
28 Independent implementation of MD5 (RFC 1321).
30 This code implements the MD5 Algorithm defined in RFC 1321, whose
31 text is available at
32 http://www.ietf.org/rfc/rfc1321.txt
33 The code is derived from the text of the RFC, including the test suite
34 (section A.5) but excluding the rest of Appendix A. It does not include
35 any code or documentation that is identified in the RFC as being
36 copyrighted.
38 The original and principal author of md5.h is L. Peter Deutsch
39 <ghost@aladdin.com>. Other authors are noted in the change history
40 that follows (in reverse chronological order):
42 2007-12-24 Changed to C++ and adapted to OpenTTD source
43 2002-04-13 lpd Removed support for non-ANSI compilers; removed
44 references to Ghostscript; clarified derivation from RFC 1321;
45 now handles byte order either statically or dynamically.
46 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
47 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
48 added conditionalization for C++ compilation from Martin
49 Purschke <purschke@bnl.gov>.
50 1999-05-03 lpd Original version.
53 #ifndef MD5_INCLUDED
54 #define MD5_INCLUDED
56 /** The number of bytes in a MD5 hash. */
57 static const size_t MD5_HASH_BYTES = 16;
59 /** Container for storing a MD5 hash/checksum/digest. */
60 struct MD5Hash : std::array<byte, MD5_HASH_BYTES> {
61 MD5Hash() : std::array<byte, MD5_HASH_BYTES>{} {}
63 /**
64 * Exclusively-or the given hash into this hash.
65 * @param other The other hash.
66 * @return Reference to this hash.
68 MD5Hash &operator^=(const MD5Hash &other)
70 for (size_t i = 0; i < size(); i++) this->operator[](i) ^= other[i];
71 return *this;
75 struct Md5 {
76 private:
77 uint32_t count[2]; ///< message length in bits, lsw first
78 uint32_t abcd[4]; ///< digest buffer
79 uint8_t buf[64]; ///< accumulate block
81 void Process(const uint8_t *data);
83 public:
84 Md5();
85 void Append(const void *data, const size_t nbytes);
86 void Finish(MD5Hash &digest);
89 #endif /* MD5_INCLUDED */