modexppc_8cpp-source.html

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

HTML
94
字号
<!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++: modexppc.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>modexppc.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// modexppc.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span>00006 <span class="preprocessor"></span>00007 <span class="preprocessor">#include "modexppc.h"</span>00008 <span class="preprocessor">#include "asn.h"</span>00009 00010 NAMESPACE_BEGIN(CryptoPP)00011 00012 <span class="comment">/*</span>00013 <span class="comment">ModExpPrecomputation&amp; ModExpPrecomputation::operator=(const ModExpPrecomputation &amp;rhs)</span>00014 <span class="comment">{</span>00015 <span class="comment">        m_base = rhs.m_base;</span>00016 <span class="comment">        m_mr = rhs.m_mr;</span>00017 <span class="comment">        m_ep = rhs.m_ep;</span>00018 <span class="comment">        if (m_mr.get() != NULL)</span>00019 <span class="comment">                m_ep.m_group = &amp;m_mr-&gt;MultiplicativeGroup();</span>00020 <span class="comment">        return *this;</span>00021 <span class="comment">}</span>00022 <span class="comment"></span>00023 <span class="comment">void ModExpPrecomputation::SetModulusAndBase(const Integer &amp;modulus, const Integer &amp;base)</span>00024 <span class="comment">{</span>00025 <span class="comment">        m_base = base;</span>00026 <span class="comment">        if (m_mr.get() == NULL || modulus != m_mr-&gt;GetModulus())</span>00027 <span class="comment">                m_mr.reset(new MontgomeryRepresentation(modulus));</span>00028 <span class="comment">        m_ep.SetGroupAndBase(m_mr-&gt;MultiplicativeGroup(), m_mr-&gt;ConvertIn(base));</span>00029 <span class="comment">}</span>00030 <span class="comment"></span>00031 <span class="comment">void ModExpPrecomputation::SetBase(const Integer &amp;base)</span>00032 <span class="comment">{</span>00033 <span class="comment">        m_base = base;</span>00034 <span class="comment">        m_ep.SetGroupAndBase(m_mr-&gt;MultiplicativeGroup(), m_mr-&gt;ConvertIn(base));</span>00035 <span class="comment">}</span>00036 <span class="comment"></span>00037 <span class="comment">void ModExpPrecomputation::Precompute(unsigned int maxExpBits, unsigned int storage)</span>00038 <span class="comment">{</span>00039 <span class="comment">        m_ep.Precompute(maxExpBits, storage);</span>00040 <span class="comment">}</span>00041 <span class="comment"></span>00042 <span class="comment">void ModExpPrecomputation::Load(BufferedTransformation &amp;bt)</span>00043 <span class="comment">{</span>00044 <span class="comment">        BERSequenceDecoder seq(bt);</span>00045 <span class="comment">        word32 version;</span>00046 <span class="comment">        BERDecodeUnsigned&lt;word32&gt;(seq, version, INTEGER, 1, 1);</span>00047 <span class="comment">        m_ep.m_exponentBase.BERDecode(seq);</span>00048 <span class="comment">        m_ep.m_windowSize = m_ep.m_exponentBase.BitCount() - 1;</span>00049 <span class="comment">        m_ep.m_bases.clear();</span>00050 <span class="comment">        while (!seq.EndReached())</span>00051 <span class="comment">                m_ep.m_bases.push_back(Integer(seq));</span>00052 <span class="comment">        if (!m_ep.m_bases.empty())</span>00053 <span class="comment">                m_base = m_mr-&gt;ConvertOut(m_ep.m_bases[0]);</span>00054 <span class="comment">        seq.MessageEnd();</span>00055 <span class="comment">}</span>00056 <span class="comment"></span>00057 <span class="comment">void ModExpPrecomputation::Save(BufferedTransformation &amp;bt) const</span>00058 <span class="comment">{</span>00059 <span class="comment">        DERSequenceEncoder seq(bt);</span>00060 <span class="comment">        DEREncodeUnsigned&lt;word32&gt;(seq, 1);      // version</span>00061 <span class="comment">        m_ep.m_exponentBase.DEREncode(seq);</span>00062 <span class="comment">        for (unsigned i=0; i&lt;m_ep.m_bases.size(); i++)</span>00063 <span class="comment">                m_ep.m_bases[i].DEREncode(seq);</span>00064 <span class="comment">        seq.MessageEnd();</span>00065 <span class="comment">}</span>00066 <span class="comment"></span>00067 <span class="comment">Integer ModExpPrecomputation::Exponentiate(const Integer &amp;exponent) const</span>00068 <span class="comment">{</span>00069 <span class="comment">        return m_mr-&gt;ConvertOut(m_ep.Exponentiate(exponent));</span>00070 <span class="comment">}</span>00071 <span class="comment"></span>00072 <span class="comment">Integer ModExpPrecomputation::CascadeExponentiate(const Integer &amp;exponent, const DL_FixedBasePrecomputation&lt;Integer&gt; &amp;pc2, const Integer &amp;exponent2) const</span>00073 <span class="comment">{</span>00074 <span class="comment">        return m_mr-&gt;ConvertOut(m_ep.CascadeExponentiate(exponent, static_cast&lt;const ModExpPrecomputation &amp;&gt;(pc2).m_ep, exponent2));</span>00075 <span class="comment">}</span>00076 <span class="comment">*/</span>00077 00078 NAMESPACE_END00079 00080 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:20 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 + -
显示快捷键?