adler32_8cpp-source.html

来自「Crypto++是一个非常强大的密码学库,主要是功能全」· HTML 代码 · 共 91 行

HTML
91
字号
<!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++: adler32.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>adler32.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// adler32.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 "adler32.h"</span>00005 00006 NAMESPACE_BEGIN(CryptoPP)00007 <a name="l00008"></a><a class="code" href="class_adler32.html#_adler32a1">00008</a> <span class="keywordtype">void</span> <a class="code" href="class_adler32.html#_adler32a1">Adler32::Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00009 {00010         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> BASE = 65521;00011 00012         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> s1 = m_s1;00013         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> s2 = m_s2;00014 00015         <span class="keywordflow">if</span> (length % 8 != 0)00016         {00017                 <span class="keywordflow">do</span>00018                 {00019                         s1 += *input++;00020                         s2 += s1;00021                         length--;00022                 } <span class="keywordflow">while</span> (length % 8 != 0);00023 00024                 <span class="keywordflow">if</span> (s1 &gt;= BASE)00025                         s1 -= BASE;00026                 s2 %= BASE;00027         }00028 00029         <span class="keywordflow">while</span> (length &gt; 0)00030         {00031                 s1 += input[0]; s2 += s1;00032                 s1 += input[1]; s2 += s1;00033                 s1 += input[2]; s2 += s1;00034                 s1 += input[3]; s2 += s1;00035                 s1 += input[4]; s2 += s1;00036                 s1 += input[5]; s2 += s1;00037                 s1 += input[6]; s2 += s1;00038                 s1 += input[7]; s2 += s1;00039 00040                 length -= 8;00041                 input += 8;00042 00043                 <span class="keywordflow">if</span> (s1 &gt;= BASE)00044                         s1 -= BASE;00045                 <span class="keywordflow">if</span> (length % 0x8000 == 0)00046                         s2 %= BASE;00047         }00048 00049         assert(s1 &lt; BASE);00050         assert(s2 &lt; BASE);00051 00052         m_s1 = (word16)s1;00053         m_s2 = (word16)s2;00054 }00055 <a name="l00056"></a><a class="code" href="class_adler32.html#_adler32a2">00056</a> <span class="keywordtype">void</span> <a class="code" href="class_adler32.html#_adler32a2">Adler32::TruncatedFinal</a>(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size)00057 {00058         ThrowIfInvalidTruncatedSize(size);00059 00060         <span class="keywordflow">switch</span> (size)00061         {00062         <span class="keywordflow">default</span>:00063                 hash[3] = byte(m_s1);00064         <span class="keywordflow">case</span> 3:00065                 hash[2] = byte(m_s1 &gt;&gt; 8);00066         <span class="keywordflow">case</span> 2:00067                 hash[1] = byte(m_s2);00068         <span class="keywordflow">case</span> 1:00069                 hash[0] = byte(m_s2 &gt;&gt; 8);00070         <span class="keywordflow">case</span> 0:00071                 ;00072         }00073 00074         Reset();00075 }00076 00077 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:07 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 + -
显示快捷键?