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

📄 whrlpool_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: whrlpool.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>  </ul></div><h1>whrlpool.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// whrlpool.cpp - originally modified by Kevin Springle from</span><a name="l00002"></a>00002 <span class="comment">// Paulo Barreto and Vincent Rijmen's public domain code, whirlpool.c.</span><a name="l00003"></a>00003 <span class="comment">// Updated to Whirlpool version 3.0, optimized and MMX version added by Wei Dai</span><a name="l00004"></a>00004 <span class="comment">// Any modifications are placed in the public domain</span><a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="comment">// This is the original introductory comment:</span><a name="l00007"></a>00007 <span class="comment"></span><a name="l00008"></a>00008 <span class="comment">/**</span><a name="l00009"></a>00009 <span class="comment"> * The Whirlpool hashing function.</span><a name="l00010"></a>00010 <span class="comment"> *</span><a name="l00011"></a>00011 <span class="comment"> * &lt;P&gt;</span><a name="l00012"></a>00012 <span class="comment"> * &lt;b&gt;References&lt;/b&gt;</span><a name="l00013"></a>00013 <span class="comment"> *</span><a name="l00014"></a>00014 <span class="comment"> * &lt;P&gt;</span><a name="l00015"></a>00015 <span class="comment"> * The Whirlpool algorithm was developed by</span><a name="l00016"></a>00016 <span class="comment"> * &lt;a href="mailto:pbarreto@scopus.com.br"&gt;Paulo S. L. M. Barreto&lt;/a&gt; and</span><a name="l00017"></a>00017 <span class="comment"> * &lt;a href="mailto:vincent.rijmen@cryptomathic.com"&gt;Vincent Rijmen&lt;/a&gt;.</span><a name="l00018"></a>00018 <span class="comment"> *</span><a name="l00019"></a>00019 <span class="comment"> * See</span><a name="l00020"></a>00020 <span class="comment"> *      P.S.L.M. Barreto, V. Rijmen,</span><a name="l00021"></a>00021 <span class="comment"> *      ``The Whirlpool hashing function,''</span><a name="l00022"></a>00022 <span class="comment"> *      NESSIE submission, 2000 (tweaked version, 2001),</span><a name="l00023"></a>00023 <span class="comment"> *      &lt;https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip&gt;</span><a name="l00024"></a>00024 <span class="comment"> * </span><a name="l00025"></a>00025 <span class="comment"> * @author  Paulo S.L.M. Barreto</span><a name="l00026"></a>00026 <span class="comment"> * @author  Vincent Rijmen.</span><a name="l00027"></a>00027 <span class="comment"> *</span><a name="l00028"></a>00028 <span class="comment"> * @version 3.0 (2003.03.12)</span><a name="l00029"></a>00029 <span class="comment"> *</span><a name="l00030"></a>00030 <span class="comment"> * =============================================================================</span><a name="l00031"></a>00031 <span class="comment"> *</span><a name="l00032"></a>00032 <span class="comment"> * Differences from version 2.1:</span><a name="l00033"></a>00033 <span class="comment"> *</span><a name="l00034"></a>00034 <span class="comment"> * - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2, 9).</span><a name="l00035"></a>00035 <span class="comment"> *</span><a name="l00036"></a>00036 <span class="comment"> * =============================================================================</span><a name="l00037"></a>00037 <span class="comment"> *</span><a name="l00038"></a>00038 <span class="comment"> * Differences from version 2.0:</span><a name="l00039"></a>00039 <span class="comment"> *</span><a name="l00040"></a>00040 <span class="comment"> * - Generation of ISO/IEC 10118-3 test vectors.</span><a name="l00041"></a>00041 <span class="comment"> * - Bug fix: nonzero carry was ignored when tallying the data length</span><a name="l00042"></a>00042 <span class="comment"> *      (this bug apparently only manifested itself when feeding data</span><a name="l00043"></a>00043 <span class="comment"> *      in pieces rather than in a single chunk at once).</span><a name="l00044"></a>00044 <span class="comment"> * - Support for MS Visual C++ 64-bit integer arithmetic.</span><a name="l00045"></a>00045 <span class="comment"> *</span><a name="l00046"></a>00046 <span class="comment"> * Differences from version 1.0:</span><a name="l00047"></a>00047 <span class="comment"> *</span><a name="l00048"></a>00048 <span class="comment"> * - Original S-box replaced by the tweaked, hardware-efficient version.</span><a name="l00049"></a>00049 <span class="comment"> *</span><a name="l00050"></a>00050 <span class="comment"> * =============================================================================</span><a name="l00051"></a>00051 <span class="comment"> *</span><a name="l00052"></a>00052 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS</span><a name="l00053"></a>00053 <span class="comment"> * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span><a name="l00054"></a>00054 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span><a name="l00055"></a>00055 <span class="comment"> * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE</span><a name="l00056"></a>00056 <span class="comment"> * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR</span><a name="l00057"></a>00057 <span class="comment"> * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF</span><a name="l00058"></a>00058 <span class="comment"> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR</span><a name="l00059"></a>00059 <span class="comment"> * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span><a name="l00060"></a>00060 <span class="comment"> * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE</span><a name="l00061"></a>00061 <span class="comment"> * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,</span><a name="l00062"></a>00062 <span class="comment"> * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><a name="l00063"></a>00063 <span class="comment"> *</span><a name="l00064"></a>00064 <span class="comment"> */</span><a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="preprocessor">#include "pch.h"</span><a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="preprocessor">#ifdef WORD64_AVAILABLE</span><a name="l00069"></a>00069 <span class="preprocessor"></span><a name="l00070"></a>00070 <span class="preprocessor">#include "whrlpool.h"</span><a name="l00071"></a>00071 <span class="preprocessor">#include "misc.h"</span><a name="l00072"></a>00072 <span class="preprocessor">#include "cpu.h"</span><a name="l00073"></a>00073 <a name="l00074"></a>00074 NAMESPACE_BEGIN(CryptoPP)<a name="l00075"></a>00075 <a name="l00076"></a>00076 void Whirlpool_TestInstantiations()<a name="l00077"></a>00077 {<a name="l00078"></a>00078         <a class="code" href="class_whirlpool.html" title="Whirlpool">Whirlpool</a> x;<a name="l00079"></a>00079 }<a name="l00080"></a>00080 <a name="l00081"></a><a class="code" href="class_whirlpool.html#d35ae383ad169c5f58ec3e7e563a1399">00081</a> <span class="keywordtype">void</span> <a class="code" href="class_whirlpool.html#d35ae383ad169c5f58ec3e7e563a1399">Whirlpool::InitState</a>(HashWordType *state)<a name="l00082"></a>00082 {<a name="l00083"></a>00083         memset(state, 0, 8*<span class="keyword">sizeof</span>(state[0]));<a name="l00084"></a>00084 }<a name="l00085"></a>00085 <a name="l00086"></a><a class="code" href="class_whirlpool.html#d4c14416343a26485a6fdaf02eeb2c4f">00086</a> <span class="keywordtype">void</span> <a class="code" href="class_whirlpool.html#d4c14416343a26485a6fdaf02eeb2c4f" title="truncated version of Final()">Whirlpool::TruncatedFinal</a>(byte *hash, <span class="keywordtype">size_t</span> size)<a name="l00087"></a>00087 {<a name="l00088"></a>00088         <a class="code" href="class_hash_transformation.html#64ba03d31c489dc32b50e00d377d8032">ThrowIfInvalidTruncatedSize</a>(size);<a name="l00089"></a>00089 <a name="l00090"></a>00090         <a class="code" href="class_iterated_hash_base.html#01f39339fa69510303ad401245df1037">PadLastBlock</a>(32);<a name="l00091"></a>00091         <a class="code" href="class_iterated_hash.html#394a6ed0dd2a885652cd203ad4fa5fe0">CorrectEndianess</a>(<a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>, <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>, 32);<a name="l00092"></a>00092 <a name="l00093"></a>00093         <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>[<a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-4] = 0;<a name="l00094"></a>00094         <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>[<a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-3] = 0;<a name="l00095"></a>00095         <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>[<a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-2] = <a class="code" href="class_iterated_hash_base.html#db8961e69e48b194b83815d5466f8e7d">GetBitCountHi</a>();<a name="l00096"></a>00096         <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>[<a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-1] = <a class="code" href="class_iterated_hash_base.html#a2dadd15d5ef537cf6e0286f42ab62c8">GetBitCountLo</a>();<a name="l00097"></a>00097 <a name="l00098"></a>00098         <a class="code" href="class_whirlpool.html#49ecf7d398bb027dd4f2465c05f1b77f">Transform</a>(<a class="code" href="class_iterated_hash_with_static_transform.html#90c715c25bcbb9978a083b3da3c73013">m_state</a>, <a class="code" href="class_iterated_hash.html#d1d059e2cba2115f403befa9e6c070da">m_data</a>);<a name="l00099"></a>00099         <a class="code" href="class_iterated_hash.html#394a6ed0dd2a885652cd203ad4fa5fe0">CorrectEndianess</a>(<a class="code" href="class_iterated_hash_with_static_transform.html#90c715c25bcbb9978a083b3da3c73013">m_state</a>, <a class="code" href="class_iterated_hash_with_static_transform.html#90c715c25bcbb9978a083b3da3c73013">m_state</a>, <a class="code" href="class_iterated_hash_with_static_transform.html#f308600222696a01464a8e93bc2c00c0" title="size of the hash returned by Final()">DigestSize</a>());<a name="l00100"></a>00100         memcpy(hash, <a class="code" href="class_iterated_hash_with_static_transform.html#90c715c25bcbb9978a083b3da3c73013">m_state</a>, size);<a name="l00101"></a>00101 <a name="l00102"></a>00102         <a class="code" href="class_iterated_hash_base.html#d53da712634ea213ad047b2a68b0fe70" title="discard the current state, and restart with a new message">Restart</a>();              <span class="comment">// reinit for next use</span>

⌨️ 快捷键说明

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