nbtheory_8h-source.html

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

HTML
157
字号
<!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++: nbtheory.h 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>nbtheory.h</h1><div class="fragment"><pre>00001 <span class="comment">// nbtheory.h - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#ifndef CRYPTOPP_NBTHEORY_H</span>00004 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_NBTHEORY_H</span>00005 <span class="preprocessor"></span>00006 <span class="preprocessor">#include "<a class="code" href="integer_8h.html">integer.h</a>"</span>00007 <span class="preprocessor">#include "algparam.h"</span>00008 00009 NAMESPACE_BEGIN(CryptoPP)00010 00011 <span class="comment">// export a table of small primes</span>00012 <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxPrimeTableSize;00013 <span class="keyword">extern</span> <span class="keyword">const</span> word lastSmallPrime;00014 <span class="keyword">extern</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> primeTableSize;00015 <span class="keyword">extern</span> word primeTable[];00016 00017 <span class="comment">// build up the table to maxPrimeTableSize</span>00018 CRYPTOPP_DLL <span class="keywordtype">void</span> BuildPrimeTable();00019 00020 <span class="comment">// ************ primality testing ****************</span>00021 00022 <span class="comment">// generate a provable prime</span>00023 CRYPTOPP_DLL <a class="code" href="class_integer.html">Integer</a> MaurerProvablePrime(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bits);00024 CRYPTOPP_DLL <a class="code" href="class_integer.html">Integer</a> MihailescuProvablePrime(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bits);00025 00026 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsSmallPrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;p);00027 00028 <span class="comment">// returns true if p is divisible by some prime less than bound</span>00029 <span class="comment">// bound not be greater than the largest entry in the prime table</span>00030 CRYPTOPP_DLL <span class="keywordtype">bool</span> TrialDivision(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;p, <span class="keywordtype">unsigned</span> bound);00031 00032 <span class="comment">// returns true if p is NOT divisible by small primes</span>00033 CRYPTOPP_DLL <span class="keywordtype">bool</span> SmallDivisorsTest(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;p);00034 00035 <span class="comment">// These is no reason to use these two, use the ones below instead</span>00036 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsFermatProbablePrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;n, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;b);00037 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsLucasProbablePrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;n);00038 00039 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsStrongProbablePrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;n, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;b);00040 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsStrongLucasProbablePrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;n);00041 00042 <span class="comment">// Rabin-Miller primality test, i.e. repeating the strong probable prime test </span>00043 <span class="comment">// for several rounds with random bases</span>00044 CRYPTOPP_DLL <span class="keywordtype">bool</span> RabinMillerTest(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;w, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> rounds);00045 00046 <span class="comment">// primality test, used to generate primes</span>00047 CRYPTOPP_DLL <span class="keywordtype">bool</span> IsPrime(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;p);00048 00049 <span class="comment">// more reliable than IsPrime(), used to verify primes generated by others</span>00050 CRYPTOPP_DLL <span class="keywordtype">bool</span> VerifyPrime(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;p, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level = 1);00051 00052 <span class="keyword">class </span>PrimeSelector00053 {00054 <span class="keyword">public</span>:00055         <span class="keyword">const</span> PrimeSelector *GetSelectorPointer()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">this</span>;}00056         <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsAcceptable(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;candidate) <span class="keyword">const</span> =0;00057 };00058 00059 <span class="comment">// use a fast sieve to find the first probable prime in {x | p&lt;=x&lt;=max and x%mod==equiv}</span>00060 <span class="comment">// returns true iff successful, value of p is undefined if no such prime exists</span>00061 CRYPTOPP_DLL <span class="keywordtype">bool</span> FirstPrime(<a class="code" href="class_integer.html">Integer</a> &amp;p, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;max, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;equiv, <span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;mod, <span class="keyword">const</span> PrimeSelector *pSelector);00062 00063 CRYPTOPP_DLL <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> PrimeSearchInterval(<span class="keyword">const</span> <a class="code" href="class_integer.html">Integer</a> &amp;max);00064 00065 CRYPTOPP_DLL AlgorithmParameters&lt;AlgorithmParameters&lt;AlgorithmParameters&lt;NullNameValuePairs, Integer::RandomNumberType&gt;, <a class="code" href="class_integer.html">Integer</a>&gt;, Integer&gt;00066         MakeParametersForTwoPrimesOfEqualSize(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> productBitLength);00067 00068 <span class="comment">// ********** other number theoretic functions ************</span>00069 00070 <span class="keyword">inline</span> Integer GCD(<span class="keyword">const</span> Integer &amp;a, <span class="keyword">const</span> Integer &amp;b)00071         {<span class="keywordflow">return</span> <a class="code" href="class_integer.html#_integerz49_12">Integer::Gcd</a>(a,b);}00072 <span class="keyword">inline</span> <span class="keywordtype">bool</span> RelativelyPrime(<span class="keyword">const</span> Integer &amp;a, <span class="keyword">const</span> Integer &amp;b)

⌨️ 快捷键说明

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