📄 filters_8cpp-source.html
字号:
00642 {00643 {00644 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size, digestSize = m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>();00645 m_space = HelpCreatePutSpace(*<a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>(), NULL_CHANNEL, digestSize, digestSize, size = digestSize);00646 m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea13">Final</a>(m_space);00647 }00648 FILTER_OUTPUT(2, m_space, m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>(), messageEnd);00649 }00650 FILTER_END_NO_MESSAGE_END;00651 }00652 00653 <span class="comment">// *************************************************************</span>00654 00655 HashVerificationFilter::HashVerificationFilter(<a class="code" href="class_hash_transformation.html">HashTransformation</a> &hm, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, word32 flags)00656 : <a class="code" href="class_filter_with_buffered_input.html">FilterWithBufferedInput</a>(attachment)00657 , m_hashModule(hm)00658 {00659 IsolatedInitialize(MakeParameters(Name::HashVerificationFilterFlags(), flags));00660 }00661 00662 <span class="keywordtype">void</span> HashVerificationFilter::InitializeDerivedAndReturnNewSizes(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &parameters, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &firstSize, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &blockSize, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &lastSize)00663 {00664 m_flags = parameters.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha40">GetValueWithDefault</a>(Name::HashVerificationFilterFlags(), (word32)DEFAULT_FLAGS);00665 m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00666 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>();00667 m_verified = <span class="keyword">false</span>;00668 firstSize = m_flags & HASH_AT_BEGIN ? size : 0;00669 blockSize = 1;00670 lastSize = m_flags & HASH_AT_BEGIN ? 0 : size;00671 }00672 00673 <span class="keywordtype">void</span> HashVerificationFilter::FirstPut(<span class="keyword">const</span> byte *inString)00674 {00675 <span class="keywordflow">if</span> (m_flags & HASH_AT_BEGIN)00676 {00677 m_expectedHash.<a class="code" href="class_sec_block.html#_sec_block_with_hinta19">New</a>(m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>());00678 memcpy(m_expectedHash, inString, m_expectedHash.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00679 <span class="keywordflow">if</span> (m_flags & PUT_HASH)00680 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, m_expectedHash.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00681 }00682 }00683 00684 <span class="keywordtype">void</span> HashVerificationFilter::NextPutMultiple(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00685 {00686 m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca5">Update</a>(inString, length);00687 <span class="keywordflow">if</span> (m_flags & PUT_MESSAGE)00688 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00689 }00690 00691 <span class="keywordtype">void</span> HashVerificationFilter::LastPut(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00692 {00693 <span class="keywordflow">if</span> (m_flags & HASH_AT_BEGIN)00694 {00695 assert(length == 0);00696 m_verified = m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea15">Verify</a>(m_expectedHash);00697 }00698 <span class="keywordflow">else</span>00699 {00700 m_verified = (length==m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>() && m_hashModule.<a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea15">Verify</a>(inString));00701 <span class="keywordflow">if</span> (m_flags & PUT_HASH)00702 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00703 }00704 00705 <span class="keywordflow">if</span> (m_flags & PUT_RESULT)00706 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(m_verified);00707 00708 <span class="keywordflow">if</span> ((m_flags & THROW_EXCEPTION) && !m_verified)00709 <span class="keywordflow">throw</span> HashVerificationFailed();00710 }00711 00712 <span class="comment">// *************************************************************</span>00713 00714 <span class="keywordtype">void</span> SignerFilter::IsolatedInitialize(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &parameters)00715 {00716 m_putMessage = parameters.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha40">GetValueWithDefault</a>(Name::PutMessage(), <span class="keyword">false</span>);00717 m_messageAccumulator.reset(m_signer.<a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea12">NewSignatureAccumulator</a>());00718 }00719 <a name="l00720"></a><a class="code" href="class_signer_filter.html#_signer_filtera2">00720</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_signer_filter.html#_signer_filtera2">SignerFilter::Put2</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking)00721 {00722 FILTER_BEGIN;00723 m_messageAccumulator->Update(inString, length);00724 <span class="keywordflow">if</span> (m_putMessage)00725 FILTER_OUTPUT(1, inString, length, 0);00726 <span class="keywordflow">if</span> (messageEnd)00727 {00728 m_buf.<a class="code" href="class_sec_block.html#_sec_block_with_hinta19">New</a>(m_signer.<a class="code" href="class_p_k___signature_scheme.html#_p_k___verifier_with_recoverya6">SignatureLength</a>());00729 m_signer.<a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea10">Sign</a>(m_rng, m_messageAccumulator.release(), m_buf);00730 FILTER_OUTPUT(2, m_buf, m_buf.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>(), messageEnd);00731 m_messageAccumulator.reset(m_signer.<a class="code" href="class_p_k___signer.html#_signer_with_recovery_templatea12">NewSignatureAccumulator</a>());00732 }00733 FILTER_END_NO_MESSAGE_END;00734 }00735 00736 SignatureVerificationFilter::SignatureVerificationFilter(<span class="keyword">const</span> <a class="code" href="class_p_k___verifier.html">PK_Verifier</a> &verifier, <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment, word32 flags)00737 : <a class="code" href="class_filter_with_buffered_input.html">FilterWithBufferedInput</a>(attachment)00738 , m_verifier(verifier)00739 {00740 IsolatedInitialize(MakeParameters(Name::SignatureVerificationFilterFlags(), flags));00741 }00742 00743 <span class="keywordtype">void</span> SignatureVerificationFilter::InitializeDerivedAndReturnNewSizes(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &parameters, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &firstSize, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &blockSize, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &lastSize)00744 {00745 m_flags = parameters.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha40">GetValueWithDefault</a>(Name::SignatureVerificationFilterFlags(), (word32)DEFAULT_FLAGS);00746 m_messageAccumulator.reset(m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea15">NewVerificationAccumulator</a>());00747 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = m_verifier.<a class="code" href="class_p_k___signature_scheme.html#_p_k___verifier_with_recoverya6">SignatureLength</a>();00748 m_verified = <span class="keyword">false</span>;00749 firstSize = m_flags & SIGNATURE_AT_BEGIN ? size : 0;00750 blockSize = 1;00751 lastSize = m_flags & SIGNATURE_AT_BEGIN ? 0 : size;00752 }00753 00754 <span class="keywordtype">void</span> SignatureVerificationFilter::FirstPut(<span class="keyword">const</span> byte *inString)00755 {00756 <span class="keywordflow">if</span> (m_flags & SIGNATURE_AT_BEGIN)00757 {00758 <span class="keywordflow">if</span> (m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea14">SignatureUpfrontForVerification</a>())00759 m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea17">InitializeVerificationAccumulator</a>(*m_messageAccumulator, inString);00760 <span class="keywordflow">else</span>00761 {00762 m_signature.<a class="code" href="class_sec_block.html#_sec_block_with_hinta19">New</a>(m_verifier.<a class="code" href="class_p_k___signature_scheme.html#_p_k___verifier_with_recoverya6">SignatureLength</a>());00763 memcpy(m_signature, inString, m_signature.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00764 }00765 00766 <span class="keywordflow">if</span> (m_flags & PUT_SIGNATURE)00767 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, m_signature.<a class="code" href="class_sec_block.html#_sec_block_with_hinta13">size</a>());00768 }00769 <span class="keywordflow">else</span>00770 {00771 assert(!m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea14">SignatureUpfrontForVerification</a>());00772 }00773 }00774 00775 <span class="keywordtype">void</span> SignatureVerificationFilter::NextPutMultiple(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00776 {00777 m_messageAccumulator->Update(inString, length);00778 <span class="keywordflow">if</span> (m_flags & PUT_MESSAGE)00779 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00780 }00781 00782 <span class="keywordtype">void</span> SignatureVerificationFilter::LastPut(<span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00783 {00784 <span class="keywordflow">if</span> (m_flags & SIGNATURE_AT_BEGIN)00785 {00786 assert(length == 0);00787 m_verified = m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea16">Verify</a>(m_messageAccumulator.release(), m_signature);00788 }00789 <span class="keywordflow">else</span>00790 {00791 m_verified = (length==m_verifier.<a class="code" href="class_p_k___signature_scheme.html#_p_k___verifier_with_recoverya6">SignatureLength</a>() && m_verifier.<a class="code" href="class_p_k___verifier.html#_verifier_with_recovery_templatea16">Verify</a>(m_messageAccumulator.release(), inString));00792 <span class="keywordflow">if</span> (m_flags & PUT_SIGNATURE)00793 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(inString, length);00794 }00795 00796 <span class="keywordflow">if</span> (m_flags & PUT_RESULT)00797 <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_zlib_decompressorz1_0">Put</a>(m_verified);00798 00799 <span class="keywordflow">if</span> ((m_flags & THROW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -