⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 md5mac_8cpp-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: md5mac.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>md5mac.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// md5mac.cpp - modified by Wei Dai from Colin Plumb's public domain md5.c</span>00002 <span class="comment">// any modifications are placed in the public domain</span>00003 00004 <span class="preprocessor">#include "pch.h"</span>00005 <span class="preprocessor">#include "<a class="code" href="md5mac_8h.html">md5mac.h</a>"</span>00006 <span class="preprocessor">#include "misc.h"</span>00007 00008 NAMESPACE_BEGIN(CryptoPP)00009 00010 <span class="keyword">const</span> word32 MD5MAC_Base::T[12] =00011         { 0xac45ef97,0xcd430f29,0x551b7e45,0x3411801c,00012           0x96ce77b1,0x7c8e722e,0x0aab5a5f,0x18be4336,00013           0x21b4219d,0x4db987bc,0xbd279da2,0xc3d75bc7 };00014 00015 <span class="keywordtype">void</span> MD5MAC_Base::UncheckedSetKey(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylength)00016 {00017         <span class="keyword">const</span> word32 zeros[4] = {0,0,0,0};00018 00019         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0, j; i&lt;3; i++)00020         {00021                 m_key[4*i+0] = 0x67452301L;00022                 m_key[4*i+1] = 0xefcdab89L;00023                 m_key[4*i+2] = 0x98badcfeL;00024                 m_key[4*i+3] = 0x10325476L;00025 00026                 memcpy(m_data, userKey, KEYLENGTH);00027                 CorrectEndianess(m_data, m_data, KEYLENGTH);00028                 <span class="keywordflow">for</span> (j=0; j&lt;3; j++)00029                         memcpy(m_data+4+4*j, T+((i+j)%3)*4, 16);00030                 Transform(m_key+4*i, m_data, zeros);00031 00032                 <span class="keywordflow">for</span> (j=0; j&lt;3; j++)00033                         memcpy(m_data+4*j, T+((i+j)%3)*4, 16);00034                 memcpy(m_data+12, userKey, KEYLENGTH);00035                 CorrectEndianess(m_data+12, m_data+12, KEYLENGTH);00036                 Transform(m_key+4*i, m_data, zeros);00037         }00038 00039         Init();00040 }00041 00042 <span class="keywordtype">void</span> MD5MAC_Base::Init()00043 {00044         m_digest[0] = m_key[0];00045         m_digest[1] = m_key[1];00046         m_digest[2] = m_key[2];00047         m_digest[3] = m_key[3];00048 }00049 <a name="l00050"></a><a class="code" href="class_m_d5_m_a_c___base.html#_m_d5_m_a_c___basea2">00050</a> <span class="keywordtype">void</span> <a class="code" href="class_m_d5_m_a_c___base.html#_m_d5_m_a_c___basea2">MD5MAC_Base::TruncatedFinal</a>(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size)00051 {00052         ThrowIfInvalidTruncatedSize(size);00053 00054         PadLastBlock(56);00055         CorrectEndianess(m_data, m_data, 56);00056 00057         m_data[14] = GetBitCountLo();00058         m_data[15] = GetBitCountHi();00059 00060         Transform(m_digest, m_data, m_key+4);00061 00062         <span class="keywordtype">unsigned</span> i;00063         <span class="keywordflow">for</span> (i=0; i&lt;4; i++)00064                 m_data[i] = m_key[8+i];00065         <span class="keywordflow">for</span> (i=0; i&lt;12; i++)00066                 m_data[i+4] = T[i] ^ m_key[8+i%4];00067         Transform(m_digest, m_data, m_key+4);00068 00069         CorrectEndianess(m_digest, m_digest, DIGESTSIZE);00070         memcpy(hash, m_digest, size);00071 00072         <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();              <span class="comment">// reinit for next use</span>00073 }00074 00075 <span class="keywordtype">void</span> MD5MAC_Base::Transform(word32 *digest, <span class="keyword">const</span> word32 *in, <span class="keyword">const</span> word32 *key)00076 {00077 <span class="preprocessor">#define F1(x, y, z) ((z ^ (x &amp; (y ^ z))) + key[0])</span>00078 <span class="preprocessor"></span><span class="preprocessor">#define F2(x, y, z) ((y ^ (z &amp; (x ^ y))) + key[1])</span>00079 <span class="preprocessor"></span><span class="preprocessor">#define F3(x, y, z) ((x ^ y ^ z) + key[2])</span>00080 <span class="preprocessor"></span><span class="preprocessor">#define F4(x, y, z) ((y ^ (x | ~z)) + key[3])</span>00081 <span class="preprocessor"></span>00082 <span class="preprocessor">#define MD5STEP(f, w, x, y, z, data, s) \</span>00083 <span class="preprocessor">        w = rotlFixed(w + f(x, y, z) + data, s) + x</span>00084 <span class="preprocessor"></span>00085     word32 a, b, c, d;00086 00087         a=digest[0];00088         b=digest[1];00089         c=digest[2];00090         d=digest[3];00091 00092     MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);00093     MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);00094     MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);00095     MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);00096     MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);00097     MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);00098     MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);00099     MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);00100     MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);00101     MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);00102     MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);00103     MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);00104     MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);00105     MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);00106     MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);00107     MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);00108 00109     MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);00110     MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);00111     MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);00112     MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);00113     MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);00114     MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);00115     MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);00116     MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);00117     MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);00118     MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);00119     MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);00120     MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);00121     MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);00122     MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);00123     MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);00124     MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);00125 00126     MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);00127     MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);00128     MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);00129     MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);00130     MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);00131     MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);00132     MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);00133     MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);00134     MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);00135     MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);00136     MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);00137     MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);00138     MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);00139     MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);00140     MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);00141     MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);00142 00143     MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);00144     MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);00145     MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);00146     MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);00147     MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);00148     MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);00149     MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);00150     MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);00151     MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);00152     MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);00153     MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);00154     MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);00155     MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);00156     MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);00157     MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);00158     MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);00159 00160         digest[0]+=a;00161         digest[1]+=b;00162         digest[2]+=c;00163         digest[3]+=d;00164 }00165 00166 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:19 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -