tron@2186: /* $Id$ */ tron@2186: rubidium@10429: /** @file md5.h Functions to create MD5 checksums. */ belugas@6527: truelight@602: /* truelight@602: Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. truelight@602: truelight@602: This software is provided 'as-is', without any express or implied truelight@602: warranty. In no event will the authors be held liable for any damages truelight@602: arising from the use of this software. truelight@602: truelight@602: Permission is granted to anyone to use this software for any purpose, truelight@602: including commercial applications, and to alter it and redistribute it truelight@602: freely, subject to the following restrictions: truelight@602: truelight@602: 1. The origin of this software must not be misrepresented; you must not truelight@602: claim that you wrote the original software. If you use this software truelight@602: in a product, an acknowledgment in the product documentation would be truelight@602: appreciated but is not required. truelight@602: 2. Altered source versions must be plainly marked as such, and must not be truelight@602: misrepresented as being the original software. truelight@602: 3. This notice may not be removed or altered from any source distribution. truelight@602: truelight@602: L. Peter Deutsch truelight@602: ghost@aladdin.com truelight@602: truelight@602: */ belugas@6527: truelight@602: /* truelight@602: Independent implementation of MD5 (RFC 1321). truelight@602: truelight@602: This code implements the MD5 Algorithm defined in RFC 1321, whose truelight@602: text is available at skidd13@8629: http://www.ietf.org/rfc/rfc1321.txt truelight@602: The code is derived from the text of the RFC, including the test suite truelight@602: (section A.5) but excluding the rest of Appendix A. It does not include truelight@602: any code or documentation that is identified in the RFC as being truelight@602: copyrighted. truelight@602: truelight@602: The original and principal author of md5.h is L. Peter Deutsch truelight@602: . Other authors are noted in the change history truelight@602: that follows (in reverse chronological order): truelight@602: skidd13@8629: 2007-12-24 Changed to C++ and adapted to OpenTTD source truelight@602: 2002-04-13 lpd Removed support for non-ANSI compilers; removed skidd13@8629: references to Ghostscript; clarified derivation from RFC 1321; skidd13@8629: now handles byte order either statically or dynamically. truelight@602: 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. truelight@602: 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); skidd13@8629: added conditionalization for C++ compilation from Martin skidd13@8629: Purschke . truelight@602: 1999-05-03 lpd Original version. truelight@602: */ truelight@602: Darkvater@2436: #ifndef MD5_INCLUDED Darkvater@2436: #define MD5_INCLUDED truelight@602: truelight@602: /* truelight@602: * This package supports both compile-time and run-time determination of CPU truelight@602: * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be truelight@602: * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is truelight@602: * defined as non-zero, the code will be compiled to run only on big-endian truelight@602: * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to truelight@602: * run on either big- or little-endian CPUs, but will run slightly less truelight@602: * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. truelight@602: */ truelight@602: skidd13@8629: struct Md5 { skidd13@8629: private: skidd13@8629: uint32 count[2]; ///< message length in bits, lsw first skidd13@8629: uint32 abcd[4]; ///< digest buffer skidd13@8629: uint8 buf[64]; ///< accumulate block truelight@602: skidd13@8629: void Process(const uint8 *data); skidd13@8629: skidd13@8629: public: skidd13@8629: Md5(); skidd13@8629: void Append(const void *data, const size_t nbytes); skidd13@8629: void Finish(uint8 digest[16]); rubidium@6574: }; truelight@602: Darkvater@2436: #endif /* MD5_INCLUDED */