⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubkey_8cpp-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
字号:
<!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++: pubkey.cpp 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>pubkey.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// pubkey.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span>00006 <span class="preprocessor"></span>00007 <span class="preprocessor">#include "<a class="code" href="pubkey_8h.html">pubkey.h</a>"</span>00008 00009 NAMESPACE_BEGIN(CryptoPP)00010 00011 <span class="keywordtype">void</span> TF_DigestSignerBase::SignDigest(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> byte *digest, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digestLen, byte *signature)<span class="keyword"> const</span>00012 <span class="keyword"></span>{00013         assert(digestLen &lt;= MaxDigestLength());00014 00015         <a class="code" href="class_sec_block.html">SecByteBlock</a> paddedBlock(PaddedBlockByteLength());00016         GetPaddingAlgorithm().<a class="code" href="class_p_k___padding_algorithm.html#_p_k___padding_algorithma2">Pad</a>(rng, digest, digestLen, paddedBlock, PaddedBlockBitLength());00017         GetTrapdoorFunctionInterface().CalculateRandomizedInverse(rng, <a class="code" href="class_integer.html">Integer</a>(paddedBlock, paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())).Encode(signature, DigestSignatureLength());00018 }00019 00020 <span class="keywordtype">bool</span> TF_DigestVerifierBase::VerifyDigest(<span class="keyword">const</span> byte *digest, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digestLen, <span class="keyword">const</span> byte *signature)<span class="keyword"> const</span>00021 <span class="keyword"></span>{00022         <a class="code" href="class_sec_block.html">SecByteBlock</a> paddedBlock(PaddedBlockByteLength());00023         <a class="code" href="class_integer.html">Integer</a> x = GetTrapdoorFunctionInterface().ApplyFunction(<a class="code" href="class_integer.html">Integer</a>(signature, DigestSignatureLength()));00024         <span class="keywordflow">if</span> (x.ByteCount() &gt; paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00025                 x = <a class="code" href="class_integer.html#_integerz37_10">Integer::Zero</a>();    <span class="comment">// don't return false here to prevent timing attack</span>00026         x.Encode(paddedBlock, paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00027         <span class="keywordflow">if</span> (GetPaddingAlgorithm().<a class="code" href="class_p_k___padding_algorithm.html#_p_k_c_s___signature_padding_schemea3">IsReversible</a>())00028         {00029                 <a class="code" href="class_sec_block.html">SecByteBlock</a> recoveredDigest(MaxDigestLength());00030                 <a class="code" href="struct_decoding_result.html">DecodingResult</a> result = GetPaddingAlgorithm().<a class="code" href="class_p_k___padding_algorithm.html#_p_k___padding_algorithma3">Unpad</a>(paddedBlock, PaddedBlockBitLength(), recoveredDigest);00031                 <span class="keywordflow">return</span> result == <a class="code" href="struct_decoding_result.html">DecodingResult</a>(digestLen) &amp;&amp; memcmp(digest, recoveredDigest, digestLen) == 0;00032         }00033         <span class="keywordflow">else</span>00034         {00035                 <a class="code" href="class_sec_block.html">SecByteBlock</a> paddedBlock2(PaddedBlockByteLength());00036                 GetPaddingAlgorithm().Pad(NullRNG(), digest, digestLen, paddedBlock2, PaddedBlockBitLength());00037                 <span class="keywordflow">return</span> paddedBlock == paddedBlock2;00038         }00039 }00040 <a name="l00041"></a><a class="code" href="class_t_f___decryptor_base.html#_t_f___private_object_impl_3_01_t_f___decryptor_base_00_01_s_c_h_e_m_e___o_p_t_i_o_n_s_01_4a10">00041</a> <a class="code" href="struct_decoding_result.html">DecodingResult</a> <a class="code" href="class_t_f___decryptor_base.html#_t_f___private_object_impl_3_01_t_f___decryptor_base_00_01_s_c_h_e_m_e___o_p_t_i_o_n_s_01_4a10">TF_DecryptorBase::FixedLengthDecrypt</a>(<span class="keyword">const</span> byte *cipherText, byte *plainText)<span class="keyword"> const</span>00042 <span class="keyword"></span>{00043         <a class="code" href="class_sec_block.html">SecByteBlock</a> paddedBlock(PaddedBlockByteLength());00044         <a class="code" href="class_integer.html">Integer</a> x = GetTrapdoorFunctionInterface().CalculateInverse(<a class="code" href="class_integer.html">Integer</a>(cipherText, FixedCiphertextLength()));00045         <span class="keywordflow">if</span> (x.ByteCount() &gt; paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())00046                 x = <a class="code" href="class_integer.html#_integerz37_10">Integer::Zero</a>();    <span class="comment">// don't return false here to prevent timing attack</span>00047         x.Encode(paddedBlock, paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00048         <span class="keywordflow">return</span> GetPaddingAlgorithm().Unpad(paddedBlock, PaddedBlockBitLength(), plainText);00049 }00050 <a name="l00051"></a><a class="code" href="class_t_f___encryptor_base.html#_t_f___public_object_impl_3_01_t_f___encryptor_base_00_01_s_c_h_e_m_e___o_p_t_i_o_n_s_01_4a9">00051</a> <span class="keywordtype">void</span> <a class="code" href="class_t_f___encryptor_base.html#_t_f___public_object_impl_3_01_t_f___encryptor_base_00_01_s_c_h_e_m_e___o_p_t_i_o_n_s_01_4a9">TF_EncryptorBase::Encrypt</a>(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> byte *plainText, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> plainTextLength, byte *cipherText)<span class="keyword"> const</span>00052 <span class="keyword"></span>{00053         <span class="keywordflow">if</span> (plainTextLength &gt; FixedMaxPlaintextLength())00054                 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html">InvalidArgument</a>(<a class="code" href="class_algorithm.html#_zlib_decompressora17">AlgorithmName</a>() + <span class="stringliteral">": message too long for this public key"</span>);00055 00056         <a class="code" href="class_sec_block.html">SecByteBlock</a> paddedBlock(PaddedBlockByteLength());00057         GetPaddingAlgorithm().Pad(rng, plainText, plainTextLength, paddedBlock, PaddedBlockBitLength());00058         GetTrapdoorFunctionInterface().ApplyRandomizedFunction(rng, <a class="code" href="class_integer.html">Integer</a>(paddedBlock, paddedBlock.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>())).<a class="code" href="class_integer.html#_integerz39_1">Encode</a>(cipherText, FixedCiphertextLength());00059 }00060 00061 NAMESPACE_END00062 00063 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:22 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>

⌨️ 快捷键说明

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