md2_8cpp-source.html
来自「Crypto++是一个非常强大的密码学库,主要是功能全」· HTML 代码 · 共 122 行
HTML
122 行
<!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++: md2.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>md2.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// md2.cpp - modified by Wei Dai from Andrew M. Kuchling's md2.c</span>00002 <span class="comment">// The original code and all modifications are in the public domain.</span>00003 00004 <span class="comment">// This is the original introductory comment:</span>00005 00006 <span class="comment">/*</span>00007 <span class="comment"> * md2.c : MD2 hash algorithm.</span>00008 <span class="comment"> *</span>00009 <span class="comment"> * Part of the Python Cryptography Toolkit, version 1.1</span>00010 <span class="comment"> *</span>00011 <span class="comment"> * Distribute and use freely; there are no restrictions on further </span>00012 <span class="comment"> * dissemination and usage except those imposed by the laws of your </span>00013 <span class="comment"> * country of residence.</span>00014 <span class="comment"> *</span>00015 <span class="comment"> */</span>00016 00017 <span class="preprocessor">#include "pch.h"</span>00018 <span class="preprocessor">#include "md2.h"</span>00019 00020 NAMESPACE_BEGIN(CryptoPP)00021 00022 MD2::MD2()00023 : m_X(48), m_C(16), m_buf(16)00024 {00025 Init();00026 }00027 00028 <span class="keywordtype">void</span> MD2::Init()00029 {00030 memset(m_X, 0, 48);00031 memset(m_C, 0, 16);00032 memset(m_buf, 0, 16);00033 m_count = 0;00034 }00035 <a name="l00036"></a><a class="code" href="class_m_d2.html#_m_d2a1">00036</a> <span class="keywordtype">void</span> <a class="code" href="class_m_d2.html#_m_d2a1">MD2::Update</a>(<span class="keyword">const</span> byte *buf, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)00037 {00038 <span class="keyword">static</span> <span class="keyword">const</span> byte S[256] = {00039 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,00040 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,00041 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,00042 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,00043 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,00044 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,00045 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,00046 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,00047 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,00048 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,00049 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,00050 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,00051 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,00052 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,00053 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,00054 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,00055 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,00056 31, 26, 219, 153, 141, 51, 159, 17, 131, 2000057 };00058 00059 <span class="keywordflow">while</span> (len) 00060 {00061 word32 L = (16-m_count) < len ? (16-m_count) : len;00062 memcpy(m_buf+m_count, buf, L);00063 m_count+=L;00064 buf+=L;00065 len-=L;00066 <span class="keywordflow">if</span> (m_count==16) 00067 {00068 byte t;00069 <span class="keywordtype">int</span> i,j;00070 00071 m_count=0;00072 memcpy(m_X+16, m_buf, 16);00073 t=m_C[15];00074 <span class="keywordflow">for</span>(i=0; i<16; i++)00075 {00076 m_X[32+i]=m_X[16+i]^m_X[i];00077 t=m_C[i]^=S[m_buf[i]^t];00078 }00079 00080 t=0;00081 <span class="keywordflow">for</span>(i=0; i<18; i++)00082 {00083 <span class="keywordflow">for</span>(j=0; j<48; j++)00084 t=m_X[j]^=S[t];00085 t=(t+i) & 0xFF;00086 }00087 }00088 }00089 }00090 <a name="l00091"></a><a class="code" href="class_m_d2.html#_m_d2a2">00091</a> <span class="keywordtype">void</span> <a class="code" href="class_m_d2.html#_m_d2a2">MD2::TruncatedFinal</a>(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size)00092 {00093 ThrowIfInvalidTruncatedSize(size);00094 00095 byte padding[16];00096 word32 padlen;00097 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;00098 00099 padlen= 16-m_count;00100 <span class="keywordflow">for</span>(i=0; i<padlen; i++) padding[i]=(byte)padlen;00101 <a class="code" href="class_m_d2.html#_m_d2a1">Update</a>(padding, padlen);00102 <a class="code" href="class_m_d2.html#_m_d2a1">Update</a>(m_C, 16);00103 memcpy(hash, m_X, size);00104 00105 Init();00106 }00107 00108 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 + =
减小字号Ctrl + -
显示快捷键?