cryptlib_8cpp-source.html

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

HTML
649
字号
00514 00515                 EncryptionFilter(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> <a class="code" href="class_p_k___encryptor.html">PK_Encryptor</a> &amp;encryptor, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00516                         : Unflushable&lt;FilterWithInputQueue&gt;(attachment), m_rng(rng), m_encryptor(encryptor)00517                 {00518                 }00519 00520                 <span class="keywordtype">bool</span> IsolatedMessageEnd(<span class="keywordtype">bool</span> blocking)00521                 {00522                         <span class="keywordflow">switch</span> (m_continueAt)00523                         {00524                         <span class="keywordflow">case</span> 0:00525                                 {00526                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> plaintextLength = m_inQueue.CurrentSize();00527                                 m_ciphertextLength = m_encryptor.CiphertextLength(plaintextLength);00528 00529                                 <a class="code" href="class_sec_block.html">SecByteBlock</a> plaintext(plaintextLength);00530                                 m_inQueue.Get(plaintext, plaintextLength);00531                                 m_ciphertext.resize(m_ciphertextLength);00532                                 m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext);00533                                 }00534 00535                         <span class="keywordflow">case</span> 1:00536                                 <span class="keywordflow">if</span> (!Output(1, m_ciphertext, m_ciphertextLength, 0, blocking))00537                                         <span class="keywordflow">return</span> <span class="keyword">false</span>;00538                         };00539                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00540                 }00541 00542                 <a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;m_rng;00543                 <span class="keyword">const</span> <a class="code" href="class_p_k___encryptor.html">PK_Encryptor</a> &amp;m_encryptor;00544                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_ciphertextLength;00545                 <a class="code" href="class_sec_block.html">SecByteBlock</a> m_ciphertext;00546         };00547 00548         <span class="keywordflow">return</span> <span class="keyword">new</span> EncryptionFilter(rng, *<span class="keyword">this</span>, attachment);00549 }00550 <a name="l00551"></a><a class="code" href="class_p_k___decryptor.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_4a14">00551</a> <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> * <a class="code" href="class_p_k___decryptor.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_4a14">PK_Decryptor::CreateDecryptionFilter</a>(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)<span class="keyword"> const</span>00552 <span class="keyword"></span>{00553         <span class="keyword">struct </span>DecryptionFilter : <span class="keyword">public</span> Unflushable&lt;FilterWithInputQueue&gt;00554         {00555                 <span class="comment">// VC60 complains if this function is missing</span>00556                 DecryptionFilter(<span class="keyword">const</span> DecryptionFilter &amp;x) : Unflushable&lt;FilterWithInputQueue&gt;(NULL), m_decryptor(x.m_decryptor) {}00557 00558                 DecryptionFilter(<span class="keyword">const</span> <a class="code" href="class_p_k___decryptor.html">PK_Decryptor</a> &amp;decryptor, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00559                         : Unflushable&lt;FilterWithInputQueue&gt;(attachment), m_decryptor(decryptor)00560                 {00561                 }00562 00563                 <span class="keywordtype">bool</span> IsolatedMessageEnd(<span class="keywordtype">bool</span> blocking)00564                 {00565                         <span class="keywordflow">switch</span> (m_continueAt)00566                         {00567                         <span class="keywordflow">case</span> 0:00568                                 {00569                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ciphertextLength = m_inQueue.CurrentSize();00570                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);00571 00572                                 <a class="code" href="class_sec_block.html">SecByteBlock</a> ciphertext(ciphertextLength);00573                                 m_inQueue.Get(ciphertext, ciphertextLength);00574                                 m_plaintext.resize(maxPlaintextLength);00575                                 m_result = m_decryptor.Decrypt(ciphertext, ciphertextLength, m_plaintext);00576                                 <span class="keywordflow">if</span> (!m_result.isValidCoding)00577                                         <span class="keywordflow">throw</span> <a class="code" href="class_invalid_ciphertext.html">InvalidCiphertext</a>(m_decryptor.AlgorithmName() + <span class="stringliteral">": invalid ciphertext"</span>);00578                                 }00579 00580                         <span class="keywordflow">case</span> 1:00581                                 <span class="keywordflow">if</span> (!Output(1, m_plaintext, m_result.messageLength, 0, blocking))00582                                         <span class="keywordflow">return</span> <span class="keyword">false</span>;00583                         }00584                         <span class="keywordflow">return</span> <span class="keyword">true</span>;00585                 }00586 00587                 <span class="keyword">const</span> <a class="code" href="class_p_k___decryptor.html">PK_Decryptor</a> &amp;m_decryptor;00588                 <a class="code" href="class_sec_block.html">SecByteBlock</a> m_plaintext;00589                 <a class="code" href="struct_decoding_result.html">DecodingResult</a> m_result;00590         };00591 00592         <span class="keywordflow">return</span> <span class="keyword">new</span> DecryptionFilter(*<span class="keyword">this</span>, attachment);00593 }00594 <a name="l00595"></a><a class="code" href="class_p_k___fixed_length_crypto_system.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_4a14">00595</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_p_k___fixed_length_crypto_system.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_4a14">PK_FixedLengthCryptoSystem::MaxPlaintextLength</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cipherTextLength)<span class="keyword"> const</span>00596 <span class="keyword"></span>{00597         <span class="keywordflow">if</span> (cipherTextLength == FixedCiphertextLength())00598                 <span class="keywordflow">return</span> FixedMaxPlaintextLength();00599         <span class="keywordflow">else</span>00600                 <span class="keywordflow">return</span> 0;00601 }00602 <a name="l00603"></a><a class="code" href="class_p_k___fixed_length_crypto_system.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_4a16">00603</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_p_k___fixed_length_crypto_system.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_4a16">PK_FixedLengthCryptoSystem::CiphertextLength</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> plainTextLength)<span class="keyword"> const</span>00604 <span class="keyword"></span>{00605         <span class="keywordflow">if</span> (plainTextLength &lt;= FixedMaxPlaintextLength())00606                 <span class="keywordflow">return</span> FixedCiphertextLength();00607         <span class="keywordflow">else</span>00608                 <span class="keywordflow">return</span> 0;00609 }00610 <a name="l00611"></a><a class="code" href="class_p_k___fixed_length_decryptor.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_4a13">00611</a> <a class="code" href="struct_decoding_result.html">DecodingResult</a> <a class="code" href="class_p_k___fixed_length_decryptor.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_4a13">PK_FixedLengthDecryptor::Decrypt</a>(<span class="keyword">const</span> byte *cipherText, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cipherTextLength, byte *plainText)<span class="keyword"> const</span>00612 <span class="keyword"></span>{00613         <span class="keywordflow">if</span> (cipherTextLength != FixedCiphertextLength())00614                 <span class="keywordflow">return</span> <a class="code" href="struct_decoding_result.html">DecodingResult</a>();00615 00616         <span class="keywordflow">return</span> <a class="code" href="class_p_k___fixed_length_decryptor.html#_t_f___crypto_system_base_3_01_p_k___fixed_length_decryptor_00_01_t_f___base_3_01_trapdoor_function_inverse_01_4_01_4a2">FixedLengthDecrypt</a>(cipherText, plainText);00617 }00618 <a name="l00619"></a><a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea10">00619</a> <span class="keywordtype">void</span> <a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea10">PK_Signer::Sign</a>(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <a class="code" href="class_hash_transformation.html">HashTransformation</a> *messageAccumulator, byte *signature)<span class="keyword"> const</span>00620 <span class="keyword"></span>{00621         std::auto_ptr&lt;HashTransformation&gt; m(messageAccumulator);00622         <a class="code" href="class_p_k___signer.html#_p_k___signer_with_recoverya5">SignAndRestart</a>(rng, *m, signature);00623 }00624 <a name="l00625"></a><a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea11">00625</a> <span class="keywordtype">void</span> <a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea11">PK_Signer::SignMessage</a>(<a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a> &amp;rng, <span class="keyword">const</span> byte *message, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> messageLen, byte *signature)<span class="keyword"> const</span>00626 <span class="keyword"></span>{00627         std::auto_ptr&lt;HashTransformation&gt; accumulator(<a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea12">NewSignatureAccumulator</a>());00628         accumulator-&gt;Update(message, messageLen);00629         <a class="code" href="class_p_k___signer.html#_p_k___signer_with_recoverya5">SignAndRestart</a>(rng, *accumulator, signature);00630 }00631 <a name="l00632"></a><a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea16">00632</a> <span class="keywordtype">bool</span> <a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea16">PK_Verifier::Verify</a>(<a class="code" href="class_hash_transformation.html">HashTransformation</a> *messageAccumulator, <span class="keyword">const</span> byte *signature)<span class="keyword"> const</span>00633 <span class="keyword"></span>{00634         std::auto_ptr&lt;HashTransformation&gt; m(messageAccumulator);00635         <span class="keywordflow">return</span> <a class="code" href="class_p_k___verifier.html#_p_k___verifier_with_recoverya11">VerifyAndRestart</a>(*m, signature);00636 }00637 <a name="l00638"></a><a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea18">00638</a> <span class="keywordtype">bool</span> <a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea18">PK_Verifier::VerifyMessage</a>(<span class="keyword">const</span> byte *message, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> messageLen, <span class="keyword">const</span> byte *sig)<span class="keyword"> const</span>00639 <span class="keyword"></span>{00640         std::auto_ptr&lt;HashTransformation&gt; accumulator(<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea15">NewVerificationAccumulator</a>());00641         accumulator-&gt;Update(message, messageLen);00642         <span cla

⌨️ 快捷键说明

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