📄 modes_8h-source.html
字号:
<a name="l00053"></a>00053 {<a name="l00054"></a>00054 m_register.New(m_cipher->BlockSize());<a name="l00055"></a>00055 }<a name="l00056"></a>00056 <a name="l00057"></a><a class="code" href="class_cipher_mode_base.html#b6c63ae5b5521b462912b1bb2d766989">00057</a> <a class="code" href="class_block_cipher.html" title="interface for one direction (encryption or decryption) of a block cipher">BlockCipher</a> *m_cipher;<a name="l00058"></a><a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">00058</a> <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> m_register;<a name="l00059"></a>00059 };<a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="keyword">template</span> <<span class="keyword">class</span> POLICY_INTERFACE><a name="l00062"></a><a class="code" href="class_mode_policy_common_template.html">00062</a> <span class="keyword">class </span>CRYPTOPP_NO_VTABLE <a class="code" href="class_mode_policy_common_template.html">ModePolicyCommonTemplate</a> : <span class="keyword">public</span> <a class="code" href="class_cipher_mode_base.html">CipherModeBase</a>, <span class="keyword">public</span> POLICY_INTERFACE<a name="l00063"></a>00063 {<a name="l00064"></a>00064 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetAlignment()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->BlockAlignment();}<a name="l00065"></a>00065 <span class="keywordtype">void</span> CipherSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length);<a name="l00066"></a>00066 };<a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="keyword">template</span> <<span class="keyword">class</span> POLICY_INTERFACE><a name="l00069"></a>00069 <span class="keywordtype">void</span> <a class="code" href="class_mode_policy_common_template.html">ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length)<a name="l00070"></a>00070 {<a name="l00071"></a>00071 <a class="code" href="class_cipher_mode_base.html#b6c63ae5b5521b462912b1bb2d766989">m_cipher</a>-><a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length, params);<a name="l00072"></a>00072 <a class="code" href="class_cipher_mode_base.html#8c864c16ce0eb014699c0a61adcc6836">ResizeBuffers</a>();<a name="l00073"></a>00073 <span class="keywordtype">int</span> feedbackSize = params.<a class="code" href="class_name_value_pairs.html#7ddb654b7afcd1a04422a7b4b01366d9" title="get a named value with type int, with default">GetIntValueWithDefault</a>(<a class="code" href="namespace_name.html#62c578a9a83ca83029cd1ce38431989d" title="int">Name::FeedbackSize</a>(), 0);<a name="l00074"></a>00074 <a class="code" href="class_cipher_mode_base.html#687cdab140bc5c733bc43299a97c2a17">SetFeedbackSize</a>(feedbackSize);<a name="l00075"></a>00075 }<a name="l00076"></a>00076 <a name="l00077"></a><a class="code" href="class_c_f_b___mode_policy.html">00077</a> <span class="keyword">class </span>CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CFB_ModePolicy : <span class="keyword">public</span> <a class="code" href="class_mode_policy_common_template.html">ModePolicyCommonTemplate</a><CFB_CipherAbstractPolicy><a name="l00078"></a>00078 {<a name="l00079"></a>00079 <span class="keyword">public</span>:<a name="l00080"></a><a class="code" href="class_c_f_b___mode_policy.html#cf2976914f792c5d4b092cf47985d285">00080</a> <a class="code" href="class_simple_keying_interface.html#88201c180fbfaa9fef2715252546ad6e">IV_Requirement</a> <a class="code" href="class_cipher_mode_base.html#a46eb377a83a479ee66ea044f845bf50" title="returns the minimal requirement for secure IVs">IVRequirement</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="class_simple_keying_interface.html#88201c180fbfaa9fef2715252546ad6e4520c4379ee3a1aed95a36e2235ba338">RANDOM_IV</a>;}<a name="l00081"></a><a class="code" href="class_c_f_b___mode_policy.html#680d77ca6c3ea9ced0567e39c755b3a6">00081</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * CRYPTOPP_API StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">"CFB"</span>;}<a name="l00082"></a>00082 <a name="l00083"></a>00083 <span class="keyword">protected</span>:<a name="l00084"></a><a class="code" href="class_c_f_b___mode_policy.html#fdf9b0c44c6d16ed8555e1713719030f">00084</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetBytesPerIteration()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_feedbackSize;}<a name="l00085"></a><a class="code" href="class_c_f_b___mode_policy.html#d33d9b4fab007750dac748a0d25cb49f">00085</a> byte * GetRegisterBegin() {<span class="keywordflow">return</span> <a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a> + <a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>() - m_feedbackSize;}<a name="l00086"></a><a class="code" href="class_c_f_b___mode_policy.html#dbefecab5cb048bfce9cdea106ef3ac0">00086</a> <span class="keywordtype">void</span> TransformRegister()<a name="l00087"></a>00087 {<a name="l00088"></a>00088 assert(<a class="code" href="class_cipher_mode_base.html#b6c63ae5b5521b462912b1bb2d766989">m_cipher</a>-><a class="code" href="class_block_transformation.html#924da616b7ba966704fb67e2b852fd2e" title="returns true if this is an encryption object">IsForwardTransformation</a>()); <span class="comment">// CFB mode needs the "encrypt" direction of the underlying block cipher, even to decrypt</span><a name="l00089"></a>00089 <a class="code" href="class_cipher_mode_base.html#b6c63ae5b5521b462912b1bb2d766989">m_cipher</a>-><a class="code" href="class_block_transformation.html#2fefb3f4c6c6297c0c91fcbba9e4f4f3" title="encrypt or decrypt one block">ProcessBlock</a>(<a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>, m_temp);<a name="l00090"></a>00090 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> updateSize = <a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>()-m_feedbackSize;<a name="l00091"></a>00091 memmove_s(<a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>, <a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>(), <a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>+m_feedbackSize, updateSize);<a name="l00092"></a>00092 memcpy_s(<a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>+updateSize, <a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-updateSize, m_temp, m_feedbackSize);<a name="l00093"></a>00093 }<a name="l00094"></a><a class="code" href="class_c_f_b___mode_policy.html#78490e0b7794ca4cd7758d47343b0d47">00094</a> <span class="keywordtype">void</span> CipherResynchronize(<span class="keyword">const</span> byte *iv)<a name="l00095"></a>00095 {<a name="l00096"></a>00096 memcpy_s(<a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>, <a class="code" href="class_cipher_mode_base.html#5d4cdcf2a0a4f5c52115fa622eebc10a">m_register</a>.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>(), iv, <a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>());<a name="l00097"></a>00097 TransformRegister();<a name="l00098"></a>00098 }<a name="l00099"></a><a class="code" href="class_c_f_b___mode_policy.html#94b4e3f06db50fd888ec24026323646d">00099</a> <span class="keywordtype">void</span> <a class="code" href="class_cipher_mode_base.html#687cdab140bc5c733bc43299a97c2a17">SetFeedbackSize</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> feedbackSize)<a name="l00100"></a>00100 {<a name="l00101"></a>00101 <span class="keywordflow">if</span> (feedbackSize > <a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>())<a name="l00102"></a>00102 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html" title="exception thrown when an invalid argument is detected">InvalidArgument</a>(<span class="stringliteral">"CFB_Mode: invalid feedback size"</span>);<a name="l00103"></a>00103 m_feedbackSize = feedbackSize ? feedbackSize : <a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>();<a name="l00104"></a>00104 }<a name="l00105"></a><a class="code" href="class_c_f_b___mode_policy.html#17ae07ee0ef40f778bd94a52202ed2be">00105</a> <span class="keywordtype">void</span> <a class="code" href="class_cipher_mode_base.html#8c864c16ce0eb014699c0a61adcc6836">ResizeBuffers</a>()<a name="l00106"></a>00106 {<a name="l00107"></a>00107 <a class="code" href="class_cipher_mode_base.html#8c864c16ce0eb014699c0a61adcc6836">CipherModeBase::ResizeBuffers</a>();<a name="l00108"></a>00108 m_temp.New(<a class="code" href="class_cipher_mode_base.html#6d0a5b8deef965aa690441541c5a7aa7">BlockSize</a>());<a name="l00109"></a>00109 }<a name="l00110"></a>00110 <a name="l00111"></a><a class="code" href="class_c_f_b___mode_policy.html#3f54e6a630ed22a9fc40457a5926f18b">00111</a> <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> m_temp;<a name="l00112"></a><a class="code" href="class_c_f_b___mode_policy.html#39e0c7dda96bfbf8cfe7abe3709b0138">00112</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_feedbackSize;<a name="l00113"></a>00113 };<a name="l00114"></a>00114 <a name="l00115"></a><a class="code" href="modes_8h.html#0c35d7771f5bc9ace517ebdf23338b92">00115</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="modes_8h.html#0c35d7771f5bc9ace517ebdf23338b92">CopyOrZero</a>(<span class="keywordtype">void</span> *dest, <span class="keyword">const</span> <span class="keywordtype">void</span> *src, <span class="keywordtype">size_t</span> s)<a name="l00116"></a>00116 {<a name="l00117"></a>00117 <span class="keywordflow">if</span> (src)<a name="l00118"></a>00118 memcpy_s(dest, s, src, s);<a name="l00119"></a>00119 <span class="keywordflow">else</span><a name="l00120"></a>00120 memset(dest, 0, s);<a name="l00121"></a>00121 }<a name="l00122"></a>00122 <a name="l00123"></a><a class="code" href="class_o_f_b___mode_policy.html">00123</a> <span class="keyword">class </span>CRYPTOPP_DLL CRYPTOPP_NO_VTABLE OFB_ModePolicy : <span class="keyword">public</span> <a class="code" href="class_mode_policy_common_template.html">ModePolicyCommonTemplate</a><AdditiveCipherAbstractPolicy><a name="l00124"></a>00124 {<a name="l00125"></a>00125 <span class="keyword">public</span>:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -