md5.hpp
Go to the documentation of this file.
00001 /* 00002 Copyright 2005-2007 Adobe Systems Incorporated and others 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://stlab.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef ADOBE_MD5_HPP 00010 #define ADOBE_MD5_HPP 00011 00012 #include <adobe/config.hpp> 00013 00014 #include <boost/cstdint.hpp> 00015 #include <boost/array.hpp> 00016 00017 #include <cstddef> 00018 00019 /*************************************************************************************************/ 00020 00021 /* 00022 Relevant copyright information is provided below and may not be removed from this file. 00023 00024 Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm. 00025 */ 00026 00027 /*************************************************************************************************/ 00028 00029 /* 00030 MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm 00031 00032 Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights 00033 reserved. 00034 00035 License to copy and use this software is granted provided that it is 00036 identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in 00037 all material mentioning or referencing this software or this function. 00038 00039 License is also granted to make and use derivative works provided that such 00040 works are identified as "derived from the RSA Data Security, Inc. MD5 00041 Message-Digest Algorithm" in all material mentioning or referencing the 00042 derived work. 00043 00044 RSA Data Security, Inc. makes no representations concerning either the 00045 merchantability of this software or the suitability of this software for 00046 any particular purpose. It is provided "as is" without express or implied 00047 warranty of any kind. 00048 00049 These notices must be retained in any copies of any part of this 00050 documentation and/or software. 00051 */ 00052 00053 /*************************************************************************************************/ 00054 00055 namespace adobe { 00056 00093 /*************************************************************************************************/ 00094 00095 class md5_t 00096 { 00097 public: 00098 typedef boost::array<boost::uint8_t, 16> digest_t; 00099 00100 md5_t(); 00101 00102 void update(void* input_block, std::size_t input_length); 00103 00104 digest_t final(); 00105 00106 private: 00107 void reset(); 00108 00109 boost::uint32_t state_m[4]; /* state (ABCD) */ 00110 boost::uint32_t count_m[2]; /* number of bits, modulo 2^64 (lsb first) */ 00111 boost::uint8_t buffer_m[64]; /* input buffer */ 00112 }; 00113 00114 /*************************************************************************************************/ 00115 00126 inline md5_t::digest_t md5(void* input_block, std::size_t input_length) 00127 { 00128 md5_t m; 00129 00130 m.update(input_block, input_length); 00131 00132 return m.final(); 00133 } 00134 00135 /*************************************************************************************************/ 00136 00137 } // namespace adobe 00138 00139 /*************************************************************************************************/ 00140 00141 #endif 00142 00143 /*************************************************************************************************/ |