📄 gf2__32_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++: gf2_32.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>gf2_32.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// gf2_32.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 "misc.h"</span>00005 <span class="preprocessor">#include "gf2_32.h"</span>00006 00007 NAMESPACE_BEGIN(CryptoPP)00008 00009 GF2_32::Element GF2_32::Multiply(Element a, Element b)<span class="keyword"> const</span>00010 <span class="keyword"></span>{00011 word32 table[4];00012 table[0] = 0;00013 table[1] = m_modulus;00014 <span class="keywordflow">if</span> (a & 0x80000000)00015 {00016 table[2] = m_modulus ^ (a<<1);00017 table[3] = a<<1;00018 }00019 <span class="keywordflow">else</span>00020 {00021 table[2] = a<<1;00022 table[3] = m_modulus ^ (a<<1);00023 }00024 00025 <span class="preprocessor">#ifdef FAST_ROTATE</span>00026 <span class="preprocessor"></span> b = rotrFixed(b, 30U);00027 word32 result = table[b&2];00028 00029 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=29; i>=0; --i)00030 {00031 b = rotlFixed(b, 1U);00032 result = (result<<1) ^ table[(b&2) + (result>>31)];00033 }00034 00035 <span class="keywordflow">return</span> (b&1) ? result ^ a : result;00036 <span class="preprocessor">#else</span>00037 <span class="preprocessor"></span> word32 result = table[(b>>30) & 2];00038 00039 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=29; i>=0; --i)00040 result = (result<<1) ^ table[((b>>i)&2) + (result>>31)];00041 00042 <span class="keywordflow">return</span> (b&1) ? result ^ a : result;00043 <span class="preprocessor">#endif</span>00044 <span class="preprocessor"></span>}00045 00046 GF2_32::Element GF2_32::MultiplicativeInverse(Element a)<span class="keyword"> const</span>00047 <span class="keyword"></span>{00048 <span class="keywordflow">if</span> (a <= 1) <span class="comment">// 1 is a special case</span>00049 <span class="keywordflow">return</span> a;00050 00051 <span class="comment">// warning - don't try to adapt this algorithm for another situation</span>00052 word32 g0=m_modulus, g1=a, g2=a;00053 word32 v0=0, v1=1, v2=1;00054 00055 assert(g1);00056 00057 <span class="keywordflow">while</span> (!(g2 & 0x80000000))00058 {00059 g2 <<= 1;00060 v2 <<= 1;00061 }00062 00063 g2 <<= 1;00064 v2 <<= 1;00065 00066 g0 ^= g2;00067 v0 ^= v2;00068 00069 <span class="keywordflow">while</span> (g0 != 1)00070 {00071 <span class="keywordflow">if</span> (g1 < g0 || ((g0^g1) < g0 && (g0^g1) < g1))00072 {00073 assert(BitPrecision(g1) <= BitPrecision(g0));00074 g2 = g1;00075 v2 = v1;00076 }00077 <span class="keywordflow">else</span>00078 {00079 assert(BitPrecision(g1) > BitPrecision(g0));00080 g2 = g0; g0 = g1; g1 = g2;00081 v2 = v0; v0 = v1; v1 = v2;00082 }00083 00084 <span class="keywordflow">while</span> ((g0^g2) >= g2)00085 {00086 assert(BitPrecision(g0) > BitPrecision(g2));00087 g2 <<= 1;00088 v2 <<= 1;00089 }00090 00091 assert(BitPrecision(g0) == BitPrecision(g2));00092 g0 ^= g2;00093 v0 ^= v2;00094 }00095 00096 <span class="keywordflow">return</span> v0;00097 }00098 00099 NAMESPACE_END</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:15 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 + -