📄 rsa_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++: rsa.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>rsa.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// rsa.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="rsa_8h.html" title="This file contains classes that implement the RSA ciphers and signature schemes as...">rsa.h</a>"</span><a name="l00005"></a>00005 <span class="preprocessor">#include "asn.h"</span><a name="l00006"></a>00006 <span class="preprocessor">#include "oids.h"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "modarith.h"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "nbtheory.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "sha.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "algparam.h"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="fips140_8h.html">fips140.h</a>"</span><a name="l00012"></a>00012 <a name="l00013"></a>00013 <span class="preprocessor">#if !defined(NDEBUG) && !defined(CRYPTOPP_IS_DLL)</span><a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#include "pssr.h"</span><a name="l00015"></a>00015 NAMESPACE_BEGIN(CryptoPP)<a name="l00016"></a>00016 void RSA_TestInstantiations()<a name="l00017"></a>00017 {<a name="l00018"></a>00018 <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PKCS1v15, SHA>::Verifier</a> x1(1, 1);<a name="l00019"></a>00019 <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PKCS1v15, SHA>::Signer</a> x2(NullRNG(), 1);<a name="l00020"></a>00020 <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PKCS1v15, SHA>::Verifier</a> x3(x2);<a name="l00021"></a>00021 <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PKCS1v15, SHA>::Verifier</a> x4(x2.GetKey());<a name="l00022"></a>00022 <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PSS, SHA>::Verifier</a> x5(x3);<a name="l00023"></a>00023 <span class="preprocessor">#ifndef __MWERKS__</span><a name="l00024"></a>00024 <span class="preprocessor"></span> <a class="code" href="struct_r_s_a_s_s.html" title="RSA signature scheme with appendix">RSASS<PSSR, SHA>::Signer</a> x6 = x2;<a name="l00025"></a>00025 x3 = x2;<a name="l00026"></a>00026 x6 = x2;<a name="l00027"></a>00027 <span class="preprocessor">#endif</span><a name="l00028"></a>00028 <span class="preprocessor"></span> <a class="code" href="struct_r_s_a_e_s.html" title="RSA cryptosystem">RSAES<PKCS1v15>::Encryptor</a> x7(x2);<a name="l00029"></a>00029 <span class="preprocessor">#ifndef __GNUC__</span><a name="l00030"></a>00030 <span class="preprocessor"></span> <a class="code" href="struct_r_s_a_e_s.html" title="RSA cryptosystem">RSAES<PKCS1v15>::Encryptor</a> x8(x3);<a name="l00031"></a>00031 <span class="preprocessor">#endif</span><a name="l00032"></a>00032 <span class="preprocessor"></span> <a class="code" href="struct_r_s_a_e_s.html" title="RSA cryptosystem">RSAES<OAEP<SHA></a> >::Encryptor x9(x2);<a name="l00033"></a>00033 <a name="l00034"></a>00034 x4 = x2.GetKey();<a name="l00035"></a>00035 }<a name="l00036"></a>00036 NAMESPACE_END<a name="l00037"></a>00037 <span class="preprocessor">#endif</span><a name="l00038"></a>00038 <span class="preprocessor"></span><a name="l00039"></a>00039 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span><a name="l00040"></a>00040 <span class="preprocessor"></span><a name="l00041"></a>00041 NAMESPACE_BEGIN(CryptoPP)<a name="l00042"></a>00042 <a name="l00043"></a><a class="code" href="class_r_s_a_function.html#525ac5bbc49c2e19fe359e69470eb304">00043</a> <a class="code" href="class_o_i_d.html" title="Object Identifier.">OID</a> <a class="code" href="class_r_s_a_function.html" title="_">RSAFunction</a>::GetAlgorithmID()<span class="keyword"> const</span><a name="l00044"></a>00044 <span class="keyword"></span>{<a name="l00045"></a>00045 <span class="keywordflow">return</span> ASN1::rsaEncryption();<a name="l00046"></a>00046 }<a name="l00047"></a>00047 <a name="l00048"></a><a class="code" href="class_r_s_a_function.html#6d8871f435b3e6ae6ae1b2655fc987b2">00048</a> <span class="keywordtype">void</span> <a class="code" href="class_r_s_a_function.html#6d8871f435b3e6ae6ae1b2655fc987b2" title="decode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header...">RSAFunction::BERDecodePublicKey</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt, <span class="keywordtype">bool</span>, <span class="keywordtype">size_t</span>)<a name="l00049"></a>00049 {<a name="l00050"></a>00050 <a class="code" href="class_b_e_r_sequence_decoder.html" title="BER Sequence Decoder.">BERSequenceDecoder</a> seq(bt);<a name="l00051"></a>00051 <a class="code" href="class_r_s_a_function.html#b2e89822414861cb312d52d8c7ac3017">m_n</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00052"></a>00052 <a class="code" href="class_r_s_a_function.html#f6d15cdabeb084e9cdc7efb1bbdea783">m_e</a>.<a class="code" href="class_integer.html#810fc0382f8928893fe192ab79b1972c">BERDecode</a>(seq);<a name="l00053"></a>00053 seq.<a class="code" href="class_b_e_r_general_decoder.html#40b14625c98ac7febb8ca218d02358ad">MessageEnd</a>();<a name="l00054"></a>00054 }<a name="l00055"></a>00055 <a name="l00056"></a><a class="code" href="class_r_s_a_function.html#49bf7b8d47a5e73ac58729e280090eb2">00056</a> <span class="keywordtype">void</span> <a class="code" href="class_r_s_a_function.html#49bf7b8d47a5e73ac58729e280090eb2" title="encode subjectPublicKey part of subjectPublicKeyInfo, without the BIT STRING header...">RSAFunction::DEREncodePublicKey</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt)<span class="keyword"> const</span><a name="l00057"></a>00057 <span class="keyword"></span>{<a name="l00058"></a>00058 <a class="code" href="class_d_e_r_sequence_encoder.html" title="DER Sequence Encoder.">DERSequenceEncoder</a> seq(bt);<a name="l00059"></a>00059 <a class="code" href="class_r_s_a_function.html#b2e89822414861cb312d52d8c7ac3017">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="l00060"></a>00060 <a class="code" href="class_r_s_a_function.html#f6d15cdabeb084e9cdc7efb1bbdea783">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="l00061"></a>00061 seq.<a class="code" href="class_d_e_r_general_encoder.html#cb5f1a94ba97027c603b019bd5228510">MessageEnd</a>();<a name="l00062"></a>00062 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -