📄 eccrypto_8cpp-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++: eccrypto.cpp 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>eccrypto.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// eccrypto.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span><a name="l00004"></a>00004 <a name="l00005"></a>00005 <span class="comment">// prevent Sun's CC compiler from including this file automatically</span><a name="l00006"></a>00006 <span class="preprocessor">#if !defined(__SUNPRO_CC) || defined(CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES)</span><a name="l00007"></a>00007 <span class="preprocessor"></span><a name="l00008"></a>00008 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span><a name="l00009"></a>00009 <span class="preprocessor"></span><a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="eccrypto_8h.html">eccrypto.h</a>"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "nbtheory.h"</span><a name="l00012"></a>00012 <span class="preprocessor">#include "oids.h"</span><a name="l00013"></a>00013 <span class="preprocessor">#include "hex.h"</span><a name="l00014"></a>00014 <span class="preprocessor">#include "argnames.h"</span><a name="l00015"></a>00015 <span class="preprocessor">#include "ec2n.h"</span><a name="l00016"></a>00016 <a name="l00017"></a>00017 NAMESPACE_BEGIN(CryptoPP)<a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#if 0</span><a name="l00020"></a>00020 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> ECDSA_TestInstantiations()<a name="l00021"></a>00021 {<a name="l00022"></a>00022 <a class="code" href="struct_e_c_d_s_a.html" title="ECDSA">ECDSA<EC2N>::Signer</a> t1;<a name="l00023"></a>00023 <a class="code" href="struct_e_c_d_s_a.html" title="ECDSA">ECDSA<EC2N>::Verifier</a> t2(t1);<a name="l00024"></a>00024 <a class="code" href="struct_e_c_n_r.html" title="ECNR.">ECNR<ECP>::Signer</a> t3;<a name="l00025"></a>00025 <a class="code" href="struct_e_c_n_r.html" title="ECNR.">ECNR<ECP>::Verifier</a> t4(t3);<a name="l00026"></a>00026 <a class="code" href="struct_e_c_i_e_s.html" title="Elliptic Curve Integrated Encryption Scheme, AKA ECIES.">ECIES<ECP>::Encryptor</a> t5;<a name="l00027"></a>00027 <a class="code" href="struct_e_c_i_e_s.html" title="Elliptic Curve Integrated Encryption Scheme, AKA ECIES.">ECIES<EC2N>::Decryptor</a> t6;<a name="l00028"></a>00028 <a class="code" href="struct_e_c_d_h.html" title="Elliptic Curve Diffie-Hellman, AKA ECDH.">ECDH<ECP>::Domain</a> t7;<a name="l00029"></a>00029 <a class="code" href="struct_e_c_m_q_v.html" title="Elliptic Curve Menezes-Qu-Vanstone, AKA ECMQV.">ECMQV<ECP>::Domain</a> t8;<a name="l00030"></a>00030 }<a name="l00031"></a>00031 <span class="preprocessor">#endif</span><a name="l00032"></a>00032 <span class="preprocessor"></span><a name="l00033"></a>00033 <span class="comment">// VC60 workaround: complains when these functions are put into an anonymous namespace</span><a name="l00034"></a>00034 <span class="keyword">static</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> ConvertToInteger(<span class="keyword">const</span> <a class="code" href="class_polynomial_mod2.html" title="Polynomial with Coefficients in GF(2).">PolynomialMod2</a> &x)<a name="l00035"></a>00035 {<a name="l00036"></a>00036 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> l = x.<a class="code" href="class_polynomial_mod2.html#d22cb6a5fcb0a78646059cf0005d2f6b" title="number of significant bytes = ceiling(BitCount()/8)">ByteCount</a>();<a name="l00037"></a>00037 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> temp(l);<a name="l00038"></a>00038 x.<a class="code" href="class_polynomial_mod2.html#1f444d22084163c2b69b5ade313aef14" title="encode in big-endian format">Encode</a>(temp, l);<a name="l00039"></a>00039 <span class="keywordflow">return</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>(temp, l);<a name="l00040"></a>00040 }<a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> ConvertToInteger(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<a name="l00043"></a>00043 {<a name="l00044"></a>00044 <span class="keywordflow">return</span> x;<a name="l00045"></a>00045 }<a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keyword">static</span> <span class="keywordtype">bool</span> CheckMOVCondition(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &r)<a name="l00048"></a>00048 {<a name="l00049"></a>00049 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> t=1;<a name="l00050"></a>00050 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n=q.<a class="code" href="class_integer.html#867356d88074424328d0ebb9bea63254" title="number of significant bits = floor(log2(abs(*this))) + 1">BitCount</a>(), m=r.<a class="code" href="class_integer.html#867356d88074424328d0ebb9bea63254" title="number of significant bits = floor(log2(abs(*this))) + 1">BitCount</a>();<a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=n; DiscreteLogWorkFactor(i)<m/2; i+=n)<a name="l00053"></a>00053 {<a name="l00054"></a>00054 t = (t*q)%r;<a name="l00055"></a>00055 <span class="keywordflow">if</span> (t == 1)<a name="l00056"></a>00056 <span class="keywordflow">return</span> <span class="keyword">false</span>;<a name="l00057"></a>00057 }<a name="l00058"></a>00058 <span class="keywordflow">return</span> <span class="keyword">true</span>;<a name="l00059"></a>00059 }<a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="comment">// ******************************************************************</span><a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">struct </span>EcRecommendedParameters;<a name="l00064"></a>00064 <a name="l00065"></a><a class="code" href="struct_ec_recommended_parameters_3_01_e_c2_n_01_4.html">00065</a> <span class="keyword">template</span><> <span class="keyword">struct </span>EcRecommendedParameters<EC2N><a name="l00066"></a>00066 {<a name="l00067"></a><a class="code" href="struct_ec_recommended_parameters_3_01_e_c2_n_01_4.html#de4044e2537acf8795cedaaed9bc22cc">00067</a> EcRecommendedParameters(<span class="keyword">const</span> <a class="code" href="class_o_i_d.html" title="Object Identifier.">OID</a> &oid, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t2, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t3, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t4, <span class="keyword">const</span> <span class="keywordtype">char</span> *a, <span class="keyword">const</span> <span class="keywordtype">char</span> *b, <span class="keyword">const</span> <span class="keywordtype">char</span> *g, <span class="keyword">const</span> <span class="keywordtype">char</span> *n, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> h)<a name="l00068"></a>00068 : oid(oid), t0(0), t1(0), t2(t2), t3(t3), t4(t4), a(a), b(b), g(g), n(n), h(h) {}<a name="l00069"></a><a class="code" href="struct_ec_recommended_parameters_3_01_e_c2_n_01_4.html#5033f33731b0bdb6d093fa4bb2d38eab">00069</a> EcRecommendedParameters(<span class="keyword">const</span> <a class="code" href="class_o_i_d.html" title="Object Identifier.">OID</a> &oid, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t0, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t2, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t3, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t4, <span class="keyword">const</span> <span class="keywordtype">char</span> *a, <span class="keyword">const</span> <span class="keywordtype">char</span> *b, <span class="keyword">const</span> <span class="keywordtype">char</span> *g, <span class="keyword">const</span> <span class="keywordtype">char</span> *n, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> h)<a name="l00070"></a>00070 : oid(oid), t0(t0), t1(t1), t2(t2), t3(t3), t4(t4), a(a), b(b), g(g), n(n), h(h) {}<a name="l00071"></a><a class="code" href="struct_ec_recommended_parameters_3_01_e_c2_n_01_4.html#ff7b8f826bb05b4885cf08e59530c1ce">00071</a> EC2N *NewEC()<span class="keyword"> const</span><a name="l00072"></a>00072 <span class="keyword"> </span>{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -