📄 ripemd_8cpp-source.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++: ripemd.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 Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>ripemd.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// ripemd.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 <span class="preprocessor">#include "ripemd.h"</span>00005 <span class="preprocessor">#include "misc.h"</span>00006 00007 NAMESPACE_BEGIN(CryptoPP)00008 00009 <span class="keywordtype">void</span> RIPEMD160::Init()00010 {00011 m_digest[0] = 0x67452301L;00012 m_digest[1] = 0xefcdab89L;00013 m_digest[2] = 0x98badcfeL;00014 m_digest[3] = 0x10325476L;00015 m_digest[4] = 0xc3d2e1f0L;00016 }00017 00018 <span class="keywordtype">void</span> RIPEMD160::Transform (word32 *digest, <span class="keyword">const</span> word32 *X)00019 {00020 <span class="preprocessor">#define Subround(f, a, b, c, d, e, x, s, k) \</span>00021 <span class="preprocessor"> a += f(b, c, d) + x + k;\</span>00022 <span class="preprocessor"> a = rotlFixed((word32)a, s) + e;\</span>00023 <span class="preprocessor"> c = rotlFixed((word32)c, 10U)</span>00024 <span class="preprocessor"></span>00025 <span class="preprocessor">#define F(x, y, z) (x ^ y ^ z) </span>00026 <span class="preprocessor"></span><span class="preprocessor">#define G(x, y, z) (z ^ (x & (y^z)))</span>00027 <span class="preprocessor"></span><span class="preprocessor">#define H(x, y, z) (z ^ (x | ~y))</span>00028 <span class="preprocessor"></span><span class="preprocessor">#define I(x, y, z) (y ^ (z & (x^y)))</span>00029 <span class="preprocessor"></span><span class="preprocessor">#define J(x, y, z) (x ^ (y | ~z))</span>00030 <span class="preprocessor"></span>00031 <span class="preprocessor">#define k0 0</span>00032 <span class="preprocessor"></span><span class="preprocessor">#define k1 0x5a827999UL</span>00033 <span class="preprocessor"></span><span class="preprocessor">#define k2 0x6ed9eba1UL</span>00034 <span class="preprocessor"></span><span class="preprocessor">#define k3 0x8f1bbcdcUL</span>00035 <span class="preprocessor"></span><span class="preprocessor">#define k4 0xa953fd4eUL</span>00036 <span class="preprocessor"></span><span class="preprocessor">#define k5 0x50a28be6UL</span>00037 <span class="preprocessor"></span><span class="preprocessor">#define k6 0x5c4dd124UL</span>00038 <span class="preprocessor"></span><span class="preprocessor">#define k7 0x6d703ef3UL</span>00039 <span class="preprocessor"></span><span class="preprocessor">#define k8 0x7a6d76e9UL</span>00040 <span class="preprocessor"></span><span class="preprocessor">#define k9 0</span>00041 <span class="preprocessor"></span>00042 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> a1, b1, c1, d1, e1, a2, b2, c2, d2, e2;00043 a1 = a2 = digest[0];00044 b1 = b2 = digest[1];00045 c1 = c2 = digest[2];00046 d1 = d2 = digest[3];00047 e1 = e2 = digest[4];00048 00049 Subround(F, a1, b1, c1, d1, e1, X[ 0], 11, k0);00050 Subround(F, e1, a1, b1, c1, d1, X[ 1], 14, k0);00051 Subround(F, d1, e1, a1, b1, c1, X[ 2], 15, k0);00052 Subround(F, c1, d1, e1, a1, b1, X[ 3], 12, k0);00053 Subround(F, b1, c1, d1, e1, a1, X[ 4], 5, k0);00054 Subround(F, a1, b1, c1, d1, e1, X[ 5], 8, k0);00055 Subround(F, e1, a1, b1, c1, d1, X[ 6], 7, k0);00056 Subround(F, d1, e1, a1, b1, c1, X[ 7], 9, k0);00057 Subround(F, c1, d1, e1, a1, b1, X[ 8], 11, k0);00058 Subround(F, b1, c1, d1, e1, a1, X[ 9], 13, k0);00059 Subround(F, a1, b1, c1, d1, e1, X[10], 14, k0);00060 Subround(F, e1, a1, b1, c1, d1, X[11], 15, k0);00061 Subround(F, d1, e1, a1, b1, c1, X[12], 6, k0);00062 Subround(F, c1, d1, e1, a1, b1, X[13], 7, k0);00063 Subround(F, b1, c1, d1, e1, a1, X[14], 9, k0);00064 Subround(F, a1, b1, c1, d1, e1, X[15], 8, k0);00065 00066 Subround(G, e1, a1, b1, c1, d1, X[ 7], 7, k1);00067 Subround(G, d1, e1, a1, b1, c1, X[ 4], 6, k1);00068 Subround(G, c1, d1, e1, a1, b1, X[13], 8, k1);00069 Subround(G, b1, c1, d1, e1, a1, X[ 1], 13, k1);00070 Subround(G, a1, b1, c1, d1, e1, X[10], 11, k1);00071 Subround(G, e1, a1, b1, c1, d1, X[ 6], 9, k1);00072 Subround(G, d1, e1, a1, b1, c1, X[15], 7, k1);00073 Subround(G, c1, d1, e1, a1, b1, X[ 3], 15, k1);00074 Subround(G, b1, c1, d1, e1, a1, X[12], 7, k1);00075 Subround(G, a1, b1, c1, d1, e1, X[ 0], 12, k1);00076 Subround(G, e1, a1, b1, c1, d1, X[ 9], 15, k1);00077 Subround(G, d1, e1, a1, b1, c1, X[ 5], 9, k1);00078 Subround(G, c1, d1, e1, a1, b1, X[ 2], 11, k1);00079 Subround(G, b1, c1, d1, e1, a1, X[14], 7, k1);00080 Subround(G, a1, b1, c1, d1, e1, X[11], 13, k1);00081 Subround(G, e1, a1, b1, c1, d1, X[ 8], 12, k1);00082 00083 Subround(H, d1, e1, a1, b1, c1, X[ 3], 11, k2);00084 Subround(H, c1, d1, e1, a1, b1, X[10], 13, k2);00085 Subround(H, b1, c1, d1, e1, a1, X[14], 6, k2);00086 Subround(H, a1, b1, c1, d1, e1, X[ 4], 7, k2);00087 Subround(H, e1, a1, b1, c1, d1, X[ 9], 14, k2);00088 Subround(H, d1, e1, a1, b1, c1, X[15], 9, k2);00089 Subround(H, c1, d1, e1, a1, b1, X[ 8], 13, k2);00090 Subround(H, b1, c1, d1, e1, a1, X[ 1], 15, k2);00091 Subround(H, a1, b1, c1, d1, e1, X[ 2], 14, k2);00092 Subround(H, e1, a1, b1, c1, d1, X[ 7], 8, k2);00093 Subround(H, d1, e1, a1, b1, c1, X[ 0], 13, k2);00094 Subround(H, c1, d1, e1, a1, b1, X[ 6], 6, k2);00095 Subround(H, b1, c1, d1, e1, a1, X[13], 5, k2);00096 Subround(H, a1, b1, c1, d1, e1, X[11], 12, k2);00097 Subround(H, e1, a1, b1, c1, d1, X[ 5], 7, k2);00098 Subround(H, d1, e1, a1, b1, c1, X[12], 5, k2);00099 00100 Subround(I, c1, d1, e1, a1, b1, X[ 1], 11, k3);00101 Subround(I, b1, c1, d1, e1, a1, X[ 9], 12, k3);00102 Subround(I, a1, b1, c1, d1, e1, X[11], 14, k3);00103 Subround(I, e1, a1, b1, c1, d1, X[10], 15, k3);00104 Subround(I, d1, e1, a1, b1, c1, X[ 0], 14, k3);00105 Subround(I, c1, d1, e1, a1, b1, X[ 8], 15, k3);00106 Subround(I, b1, c1, d1, e1, a1, X[12], 9, k3);00107 Subround(I, a1, b1, c1, d1, e1, X[ 4], 8, k3);00108 Subround(I, e1, a1, b1, c1, d1, X[13], 9, k3);00109 Subround(I, d1, e1, a1, b1, c1, X[ 3], 14, k3);00110 Subround(I, c1, d1, e1, a1, b1, X[ 7], 5, k3);00111 Subround(I, b1, c1, d1, e1, a1, X[15], 6, k3);00112 Subround(I, a1, b1, c1, d1, e1, X[14], 8, k3);00113 Subround(I, e1, a1, b1, c1, d1, X[ 5], 6, k3);00114 Subround(I, d1, e1, a1, b1, c1, X[ 6], 5, k3);00115 Subround(I, c1, d1, e1, a1, b1, X[ 2], 12, k3);00116 00117 Subround(J, b1, c1, d1, e1, a1, X[ 4], 9, k4);00118 Subround(J, a1, b1, c1, d1, e1, X[ 0], 15, k4);00119 Subround(J, e1, a1, b1, c1, d1, X[ 5], 5, k4);00120 Subround(J, d1, e1, a1, b1, c1, X[ 9], 11, k4);00121 Subround(J, c1, d1, e1, a1, b1, X[ 7], 6, k4);00122 Subround(J, b1, c1, d1, e1, a1, X[12], 8, k4);00123 Subround(J, a1, b1, c1, d1, e1, X[ 2], 13, k4);00124 Subround(J, e1, a1, b1, c1, d1, X[10], 12, k4);00125 Subround(J, d1, e1, a1, b1, c1, X[14], 5, k4);00126 Subround(J, c1, d1, e1, a1, b1, X[ 1], 12, k4);00127 Subround(J, b1, c1, d1, e1, a1, X[ 3], 13, k4);00128 Subround(J, a1, b1, c1, d1, e1, X[ 8], 14, k4);00129 Subround(J, e1, a1, b1, c1, d1, X[11], 11, k4);00130 Subround(J, d1, e1, a1, b1, c1, X[ 6], 8, k4);00131 Subround(J, c1, d1, e1, a1, b1, X[15], 5, k4);00132 Subround(J, b1, c1, d1, e1, a1, X[13], 6, k4);00133 00134 Subround(J, a2, b2, c2, d2, e2, X[ 5], 8, k5);00135 Subround(J, e2, a2, b2, c2, d2, X[14], 9, k5);00136 Subround(J, d2, e2, a2, b2, c2, X[ 7], 9, k5);00137 Subround(J, c2, d2, e2, a2, b2, X[ 0], 11, k5);00138 Subround(J, b2, c2, d2, e2, a2, X[ 9], 13, k5);00139 Subround(J, a2, b2, c2, d2, e2, X[ 2], 15, k5);00140 Subround(J, e2, a2, b2, c2, d2, X[11], 15, k5);00141 Subround(J, d2, e2, a2, b2, c2, X[ 4], 5, k5);00142 Subround(J, c2, d2, e2, a2, b2, X[13], 7, k5);00143 Subround(J, b2, c2, d2, e2, a2, X[ 6], 7, k5);00144 Subround(J, a2, b2, c2, d2, e2, X[15], 8, k5);00145 Subround(J, e2, a2, b2, c2, d2, X[ 8], 11, k5);00146 Subround(J, d2, e2, a2, b2, c2, X[ 1], 14, k5);00147 Subround(J, c2, d2, e2, a2, b2, X[10], 14, k5);00148 Subround(J, b2, c2, d2, e2, a2, X[ 3], 12, k5);00149 Subround(J, a2, b2, c2, d2, e2, X[12], 6, k5);00150 00151 Subround(I, e2, a2, b2, c2, d2, X[ 6], 9, k6); 00152 Subround(I, d2, e2, a2, b2, c2, X[11], 13, k6);00153 Subround(I, c2, d2, e2, a2, b2, X[ 3], 15, k6);00154 Subround(I, b2, c2, d2, e2, a2, X[ 7], 7, k6);00155 Subround(I, a2, b2, c2, d2, e2, X[ 0], 12, k6);00156 Subround(I, e2, a2, b2, c2, d2, X[13], 8, k6);00157 Subround(I, d2, e2, a2, b2, c2, X[ 5], 9, k6);00158 Subround(I, c2, d2, e2, a2, b2, X[10], 11, k6);00159 Subround(I, b2, c2, d2, e2, a2, X[14], 7, k6);00160 Subround(I, a2, b2, c2, d2, e2, X[15], 7, k6);00161 Subround(I, e2, a2, b2, c2, d2, X[ 8], 12, k6);00162 Subround(I, d2, e2, a2, b2, c2, X[12], 7, k6);00163 Subround(I, c2, d2, e2, a2, b2, X[ 4], 6, k6);00164 Subround(I, b2, c2, d2, e2, a2, X[ 9], 15, k6);00165 Subround(I, a2, b2, c2, d2, e2, X[ 1], 13, k6);00166 Subround(I, e2, a2, b2, c2, d2, X[ 2], 11, k6);00167 00168 Subround(H, d2, e2, a2, b2, c2, X[15], 9, k7);00169 Subround(H, c2, d2, e2, a2, b2, X[ 5], 7, k7);00170 Subround(H, b2, c2, d2, e2, a2, X[ 1], 15, k7);00171 Subround(H, a2, b2, c2, d2, e2, X[ 3], 11, k7);00172 Subround(H, e2, a2, b2, c2, d2, X[ 7], 8, k7);00173 Subround(H, d2, e2, a2, b2, c2, X[14], 6, k7);00174 Subround(H, c2, d2, e2, a2, b2, X[ 6], 6, k7);00175 Subround(H, b2, c2, d2, e2, a2, X[ 9], 14, k7);00176 Subround(H, a2, b2, c2, d2, e2, X[11], 12, k7);00177 Subround(H, e2, a2, b2, c2, d2, X[ 8], 13, k7);00178 Subround(H, d2, e2, a2, b2, c2, X[12], 5, k7);00179 Subround(H, c2, d2, e2, a2, b2, X[ 2], 14, k7);00180 Subround(H, b2, c2, d2, e2, a2, X[10], 13, k7);00181 Subround(H, a2, b2, c2, d2, e2, X[ 0], 13, k7);00182 Subround(H, e2, a2, b2, c2, d2, X[ 4], 7, k7);00183 Subround(H, d2, e2, a2, b2, c2, X[13], 5, k7);00184 00185 Subround(G, c2, d2, e2, a2, b2, X[ 8], 15, k8);00186 Subround(G, b2, c2, d2, e2, a2, X[ 6], 5, k8);00187 Subround(G, a2, b2, c2, d2, e2, X[ 4], 8, k8);00188 Subround(G, e2, a2, b2, c2, d2, X[ 1], 11, k8);00189 Subround(G, d2, e2, a2, b2, c2, X[ 3], 14, k8);00190 Subround(G, c2, d2, e2, a2, b2, X[11], 14, k8);00191 Subround(G, b2, c2, d2, e2, a2, X[15], 6, k8);00192 Subround(G, a2, b2, c2, d2, e2, X[ 0], 14, k8);00193 Subround(G, e2, a2, b2, c2, d2, X[ 5], 6, k8);00194 Subround(G, d2, e2, a2, b2, c2, X[12], 9, k8);00195 Subround(G, c2, d2, e2, a2, b2, X[ 2], 12, k8);00196 Subround(G, b2, c2, d2, e2, a2, X[13], 9, k8);00197 Subround(G, a2, b2, c2, d2, e2, X[ 9], 12, k8);00198 Subround(G, e2, a2, b2, c2, d2, X[ 7], 5, k8);00199 Subround(G, d2, e2, a2, b2, c2, X[10], 15, k8);00200 Subround(G, c2, d2, e2, a2, b2, X[14], 8, k8);00201 00202 Subround(F, b2, c2, d2, e2, a2, X[12], 8, k9);00203 Subround(F, a2, b2, c2, d2, e2, X[15], 5, k9);00204 Subround(F, e2, a2, b2, c2, d2, X[10], 12, k9);00205 Subround(F, d2, e2, a2, b2, c2, X[ 4], 9, k9);00206 Subround(F, c2, d2, e2, a2, b2, X[ 1], 12, k9);00207 Subround(F, b2, c2, d2, e2, a2, X[ 5], 5, k9);00208 Subround(F, a2, b2, c2, d2, e2, X[ 8], 14, k9);00209 Subround(F, e2, a2, b2, c2, d2, X[ 7], 6, k9);00210 Subround(F, d2, e2, a2, b2, c2, X[ 6], 8, k9);00211 Subround(F, c2, d2, e2, a2, b2, X[ 2], 13, k9);00212 Subround(F, b2, c2, d2, e2, a2, X[13], 6, k9);00213 Subround(F, a2, b2, c2, d2, e2, X[14], 5, k9);00214 Subround(F, e2, a2, b2, c2, d2, X[ 0], 15, k9);00215 Subround(F, d2, e2, a2, b2, c2, X[ 3], 13, k9);00216 Subround(F, c2, d2, e2, a2, b2, X[ 9], 11, k9);00217 Subround(F, b2, c2, d2, e2, a2, X[11], 11, k9);00218 00219 c1 = digest[1] + c1 + d2;00220 digest[1] = digest[2] + d1 + e2;00221 digest[2] = digest[3] + e1 + a2;00222 digest[3] = digest[4] + a1 + b2;00223 digest[4] = digest[0] + b1 + c2;00224 digest[0] = c1;00225 }00226 00227 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:23 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 + -