📄 modarith_8h-source.html
字号:
<!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++: modarith.h 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 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 List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div><h1>modarith.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef CRYPTOPP_MODARITH_H</span><a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_MODARITH_H</span><a name="l00003"></a>00003 <span class="preprocessor"></span><a name="l00004"></a>00004 <span class="comment">// implementations are in integer.cpp</span><a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "misc.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="integer_8h.html">integer.h</a>"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "algebra.h"</span><a name="l00010"></a>00010 <a name="l00011"></a>00011 NAMESPACE_BEGIN(CryptoPP)<a name="l00012"></a>00012 <a name="l00013"></a>00013 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_abstract_group.html" title="Abstract Group.">AbstractGroup</a><<a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>>;<a name="l00014"></a>00014 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_abstract_ring.html" title="Abstract Ring.">AbstractRing</a><Integer>;<a name="l00015"></a>00015 CRYPTOPP_DLL_TEMPLATE_CLASS <a class="code" href="class_abstract_euclidean_domain.html" title="Abstract Euclidean Domain.">AbstractEuclideanDomain</a><Integer>;<a name="l00016"></a>00016 <span class="comment"></span><a name="l00017"></a>00017 <span class="comment">//! ring of congruence classes modulo n</span><a name="l00018"></a>00018 <span class="comment"></span><span class="comment">/*! \note this implementation represents each congruence class as the smallest non-negative integer in that class */</span><a name="l00019"></a><a class="code" href="class_modular_arithmetic.html">00019</a> class CRYPTOPP_DLL <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> : public <a class="code" href="class_abstract_ring.html" title="Abstract Ring.">AbstractRing</a><Integer><a name="l00020"></a>00020 {<a name="l00021"></a>00021 <span class="keyword">public</span>:<a name="l00022"></a>00022 <a name="l00023"></a><a class="code" href="class_modular_arithmetic.html#872afa5efebf43e4744156dcdfac3ca3">00023</a> <span class="keyword">typedef</span> <span class="keywordtype">int</span> RandomizationParameter;<a name="l00024"></a><a class="code" href="class_modular_arithmetic.html#17f2266382639dde45d028e630e07296">00024</a> <span class="keyword">typedef</span> Integer <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Element</a>;<a name="l00025"></a>00025 <a name="l00026"></a><a class="code" href="class_modular_arithmetic.html#1cdfc924e8d11f9620bd826535aabb62">00026</a> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a>(<span class="keyword">const</span> Integer &modulus = <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>())<a name="l00027"></a>00027 : m_modulus(modulus), m_result((word)0, modulus.reg.size()) {}<a name="l00028"></a>00028 <a name="l00029"></a><a class="code" href="class_modular_arithmetic.html#7a7bf808b07baa755ed9ce9f300ce743">00029</a> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a>(<span class="keyword">const</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> &ma)<a name="l00030"></a>00030 : m_modulus(ma.m_modulus), m_result((word)0, m_modulus.reg.size()) {}<a name="l00031"></a>00031 <a name="l00032"></a>00032 <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt); <span class="comment">// construct from BER encoded parameters</span><a name="l00033"></a>00033 <a name="l00034"></a><a class="code" href="class_modular_arithmetic.html#2ea01ae9e84d5392a8781b99d5cba83f">00034</a> <span class="keyword">virtual</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a> * Clone()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_modular_arithmetic.html" title="ring of congruence classes modulo n">ModularArithmetic</a>(*<span class="keyword">this</span>);}<a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt) <span class="keyword">const</span>;<a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="keywordtype">void</span> DEREncodeElement(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &out, <span class="keyword">const</span> Element &a) <span class="keyword">const</span>;<a name="l00039"></a>00039 <span class="keywordtype">void</span> BERDecodeElement(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &in, Element &a) <span class="keyword">const</span>;<a name="l00040"></a>00040 <a name="l00041"></a><a class="code" href="class_modular_arithmetic.html#71a51e5b665bf7fb89af2ccba19f0043">00041</a> <span class="keyword">const</span> Integer& GetModulus()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_modulus;}<a name="l00042"></a><a class="code" href="class_modular_arithmetic.html#2d7a07fd3831386eb9315c4e1f5fcf25">00042</a> <span class="keywordtype">void</span> SetModulus(<span class="keyword">const</span> Integer &newModulus) {m_modulus = newModulus; m_result.<a class="code" href="class_integer.html#c73621945e65a188ca645d6bf350c26c">reg</a>.<a class="code" href="class_sec_block.html#f9e98d3f4a7af1156fcf3e6e68f4ae5a" title="change size and preserve contents">resize</a>(m_modulus.reg.size());}<a name="l00043"></a>00043 <a name="l00044"></a><a class="code" href="class_modular_arithmetic.html#7a93adfe41f5545dcfaf3ee9f2b49bc3">00044</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsMontgomeryRepresentation()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">false</span>;}<a name="l00045"></a>00045 <a name="l00046"></a><a class="code" href="class_modular_arithmetic.html#6d504c7166a5eab47a74b86ce8cc782b">00046</a> <span class="keyword">virtual</span> Integer ConvertIn(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00047"></a>00047 <span class="keyword"> </span>{<span class="keywordflow">return</span> a%m_modulus;}<a name="l00048"></a>00048 <a name="l00049"></a><a class="code" href="class_modular_arithmetic.html#bbd97fd2abfb869063f51cfdeb769c71">00049</a> <span class="keyword">virtual</span> Integer ConvertOut(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00050"></a>00050 <span class="keyword"> </span>{<span class="keywordflow">return</span> a;}<a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keyword">const</span> Integer& Half(<span class="keyword">const</span> Integer &a) <span class="keyword">const</span>;<a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="class_modular_arithmetic.html#89c5edea6e87341761c35ab03a46bcc0">00054</a> <span class="keywordtype">bool</span> Equal(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b)<span class="keyword"> const</span><a name="l00055"></a>00055 <span class="keyword"> </span>{<span class="keywordflow">return</span> a==b;}<a name="l00056"></a>00056 <a name="l00057"></a><a class="code" href="class_modular_arithmetic.html#bd2425e1caf5af1a290b424cadb1517c">00057</a> <span class="keyword">const</span> Integer& Identity()<span class="keyword"> const</span><a name="l00058"></a>00058 <span class="keyword"> </span>{<span class="keywordflow">return</span> <a class="code" href="class_integer.html#19b7e6d48b1b57bd4846160ea2928175" title="avoid calling constructors for these frequently used integers">Integer::Zero</a>();}<a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="keyword">const</span> Integer& Add(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b) <span class="keyword">const</span>;<a name="l00061"></a>00061 <a name="l00062"></a>00062 Integer& Accumulate(Integer &a, <span class="keyword">const</span> Integer &b) <span class="keyword">const</span>;<a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="keyword">const</span> Integer& Inverse(<span class="keyword">const</span> Integer &a) <span class="keyword">const</span>;<a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="keyword">const</span> Integer& Subtract(<span class="keyword">const</span> Integer &a, <span class="keyword">const</span> Integer &b) <span class="keyword">const</span>;<a name="l00067"></a>00067 <a name="l00068"></a>00068 Integer& Reduce(Integer &a, <span class="keyword">const</span> Integer &b) <span class="keyword">const</span>;<a name="l00069"></a>00069 <a name="l00070"></a><a class="code" href="class_modular_arithmetic.html#2704ef13b1d9109569613196de4a4915">00070</a> <span class="keyword">const</span> Integer& Double(<span class="keyword">const</span> Integer &a)<span class="keyword"> const</span><a name="l00071"></a>00071 <span class="keyword"> </span>{<span class="keywordflow">return</span> Add(a, a);}<a name="l00072"></a>00072
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -