tea_8cpp-source.html

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

HTML
68
字号
<!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++: tea.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>tea.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// tea.cpp - modified by Wei Dai from code in the original paper</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 <span class="preprocessor">#include "<a class="code" href="tea_8h.html">tea.h</a>"</span>00005 <span class="preprocessor">#include "misc.h"</span>00006 00007 NAMESPACE_BEGIN(CryptoPP)00008 00009 <span class="keyword">const</span> word32 TEA::Base::DELTA = 0x9e3779b9;00010 00011 <span class="keywordtype">void</span> TEA::Base::UncheckedSetKey(CipherDir direction, <span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00012 {00013         AssertValidKeyLength(length);00014 00015         GetUserKey(BIG_ENDIAN_ORDER, k.begin(), 4, userKey, KEYLENGTH);00016 }00017 00018 <span class="keyword">typedef</span> BlockGetAndPut&lt;word32, BigEndian&gt; Block;00019 00020 <span class="keywordtype">void</span> TEA::Enc::ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00021 <span class="keyword"></span>{00022         word32 y, z;00023         Block::Get(inBlock)(y)(z);00024 00025         word32 sum = 0;00026         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;ROUNDS; i++)00027         {   00028                 sum += DELTA;00029                 y += (z &lt;&lt; 4) + k[0] ^ z + sum ^ (z &gt;&gt; 5) + k[1];00030                 z += (y &lt;&lt; 4) + k[2] ^ y + sum ^ (y &gt;&gt; 5) + k[3];00031         }00032 00033         Block::Put(xorBlock, outBlock)(y)(z);00034 }00035 00036 <span class="keyword">typedef</span> BlockGetAndPut&lt;word32, BigEndian&gt; Block;00037 00038 <span class="keywordtype">void</span> TEA::Dec::ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock)<span class="keyword"> const</span>00039 <span class="keyword"></span>{00040         word32 y, z;00041         Block::Get(inBlock)(y)(z);00042 00043         word32 sum = DELTA &lt;&lt; LOG_ROUNDS;00044         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;ROUNDS; i++)00045         {00046                 z -= (y &lt;&lt; 4) + k[2] ^ y + sum ^ (y &gt;&gt; 5) + k[3]; 00047                 y -= (z &lt;&lt; 4) + k[0] ^ z + sum ^ (z &gt;&gt; 5) + k[1];00048                 sum -= DELTA;00049         }00050 00051         Block::Put(xorBlock, outBlock)(y)(z);00052 }00053 00054 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:26 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 + -
显示快捷键?