📄 esign_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++: esign.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>esign.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// esign.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 <span class="preprocessor">#include "<a class="code" href="esign_8h.html" title="This file contains classes that implement the ESIGN signature schemes as defined...">esign.h</a>"</span><a name="l00005"></a>00005 <span class="preprocessor">#include "asn.h"</span><a name="l00006"></a>00006 <span class="preprocessor">#include "modarith.h"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "nbtheory.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "sha.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "algparam.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 void ESIGN_TestInstantiations()<a name="l00014"></a>00014 {<a name="l00015"></a>00015 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Verifier</a> x1(1, 1);<a name="l00016"></a>00016 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Signer</a> x2(NullRNG(), 1);<a name="l00017"></a>00017 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Verifier</a> x3(x2);<a name="l00018"></a>00018 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Verifier</a> x4(x2.GetKey());<a name="l00019"></a>00019 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Verifier</a> x5(x3);<a name="l00020"></a>00020 <a class="code" href="struct_e_s_i_g_n.html" title="ESIGN, as defined in IEEE P1363a.">ESIGN<SHA>::Signer</a> x6 = x2;<a name="l00021"></a>00021 <a name="l00022"></a>00022 x6 = x2;<a name="l00023"></a>00023 x3 = <a class="code" href="class_t_f___s_s.html#65546b9070fbf3960015932defd8b333" title="implements PK_Verifier interface">ESIGN<SHA>::Verifier</a>(x2);<a name="l00024"></a>00024 x4 = x2.GetKey();<a name="l00025"></a>00025 }<a name="l00026"></a>00026 <a name="l00027"></a><a class="code" href="class_e_s_i_g_n_function.html#6517cb00d59eb584c9ecf86d3dce6742">00027</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#6517cb00d59eb584c9ecf86d3dce6742" title="decode this object from a BufferedTransformation, using BER (Basic Encoding Rules)...">ESIGNFunction::BERDecode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt)<a name="l00028"></a>00028 {<a name="l00029"></a>00029 <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);<a name="l00030"></a>00030 <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00031"></a>00031 <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00032"></a>00032 seq.<a class="code" href="class_b_e_r_general_decoder.html#40b14625c98ac7febb8ca218d02358ad">MessageEnd</a>();<a name="l00033"></a>00033 }<a name="l00034"></a>00034 <a name="l00035"></a><a class="code" href="class_e_s_i_g_n_function.html#524f9708759975ed9a9481ee94b9eb08">00035</a> <span class="keywordtype">void</span> <a class="code" href="class_e_s_i_g_n_function.html#524f9708759975ed9a9481ee94b9eb08" title="encode this object into a BufferedTransformation, using DER (Distinguished Encoding...">ESIGNFunction::DEREncode</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt)<span class="keyword"> const</span><a name="l00036"></a>00036 <span class="keyword"></span>{<a name="l00037"></a>00037 <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);<a name="l00038"></a>00038 <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00039"></a>00039 <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>.<a class="code" href="class_integer.html#6ab51a05bee88cfa690179611e8a084e" title="encode using Distinguished Encoding Rules, put result into a BufferedTransformation...">DEREncode</a>(seq);<a name="l00040"></a>00040 seq.<a class="code" href="class_d_e_r_general_encoder.html#cb5f1a94ba97027c603b019bd5228510">MessageEnd</a>();<a name="l00041"></a>00041 }<a name="l00042"></a>00042 <a name="l00043"></a><a class="code" href="class_e_s_i_g_n_function.html#4f97965d2ec6ac022f4d801d1a049905">00043</a> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> <a class="code" href="class_e_s_i_g_n_function.html#4f97965d2ec6ac022f4d801d1a049905">ESIGNFunction::ApplyFunction</a>(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x)<span class="keyword"> const</span><a name="l00044"></a>00044 <span class="keyword"></span>{<a name="l00045"></a>00045 <a class="code" href="class_crypto_material.html#a1da44802c5cf00946043922cb9e7e6e">DoQuickSanityCheck</a>();<a name="l00046"></a>00046 <span class="keywordflow">return</span> STDMIN(a_exp_b_mod_c(x, <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a>, <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>) >> (2*<a class="code" href="class_e_s_i_g_n_function.html#5a6e6a26b2bfb547685852483909f5a5">GetK</a>()+2), <a class="code" href="class_trapdoor_function_bounds.html#9b505cf1a3494645998e7e0872b76a72">MaxImage</a>());<a name="l00047"></a>00047 }<a name="l00048"></a>00048 <a name="l00049"></a><a class="code" href="class_e_s_i_g_n_function.html#cc185d24c97a74543a6e5820219282bd">00049</a> <span class="keywordtype">bool</span> <a class="code" href="class_e_s_i_g_n_function.html#cc185d24c97a74543a6e5820219282bd" title="check this object for errors">ESIGNFunction::Validate</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level)<span class="keyword"> const</span><a name="l00050"></a>00050 <span class="keyword"></span>{<a name="l00051"></a>00051 <span class="keywordtype">bool</span> pass = <span class="keyword">true</span>;<a name="l00052"></a>00052 pass = pass && <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a> > <a class="code" href="class_integer.html#8c070592581bf6c2f928c72bfa1c1638" title="avoid calling constructors for these frequently used integers">Integer::One</a>() && <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>.<a class="code" href="class_integer.html#ed4bb7208a18b986ef3e1a7d92e06d1d">IsOdd</a>();<a name="l00053"></a>00053 pass = pass && <a class="code" href="class_e_s_i_g_n_function.html#086e17e8047753768b22c6b59faebf60">m_e</a> >= 8 && m_e < <a class="code" href="class_e_s_i_g_n_function.html#74695389e40c412ff0a1e34ebb797678">m_n</a>;<a name="l00054"></a>00054 <span class="keywordflow">return</span> pass;<a name="l00055"></a>00055 }<a name="l00056"></a>00056 <a name="l00057"></a><a class="code" href="class_e_s_i_g_n_function.html#53def4f94e81acd0e02a3e50fb9b15ee">00057</a> <span class="keywordtype">bool</span> <a class="code" href="class_e_s_i_g_n_function.html#53def4f94e81acd0e02a3e50fb9b15ee" title="to be implemented by derived classes, users should use one of the above functions...">ESIGNFunction::GetVoidValue</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> std::type_info &valueType, <span class="keywordtype">void</span> *pValue)<span class="keyword"> const</span><a name="l00058"></a>00058 <span class="keyword"></span>{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -