📄 modes_8h-source.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++: modes.h 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 Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>modes.h</h1><a href="modes_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef CRYPTOPP_MODES_H</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_MODES_H</span>00003 <span class="preprocessor"></span><span class="comment"></span>00004 <span class="comment">/*! \file</span>00005 <span class="comment">*/</span>00006 00007 <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span>00008 <span class="preprocessor">#include "secblock.h"</span>00009 <span class="preprocessor">#include "misc.h"</span>00010 <span class="preprocessor">#include "<a class="code" href="strciphr_8h.html">strciphr.h</a>"</span>00011 <span class="preprocessor">#include "argnames.h"</span>00012 00013 NAMESPACE_BEGIN(CryptoPP)00014 00015 <span class="comment">//! Cipher mode documentation. See NIST SP 800-38A for definitions of these modes.</span>00016 <span class="comment"></span><span class="comment"></span>00017 <span class="comment">/*! Each class derived from this one defines two types, Encryption and Decryption, </span>00018 <span class="comment"> both of which implement the SymmetricCipher interface.</span>00019 <span class="comment"> For each mode there are two classes, one of which is a template class,</span>00020 <span class="comment"> and the other one has a name that ends in "_ExternalCipher".</span>00021 <span class="comment"> The "external cipher" mode objects hold a reference to the underlying block cipher,</span>00022 <span class="comment"> instead of holding an instance of it. The reference must be passed in to the constructor.</span>00023 <span class="comment"> For the "cipher holder" classes, the CIPHER template parameter should be a class</span>00024 <span class="comment"> derived from BlockCipherDocumentation, for example DES or AES.</span>00025 <span class="comment">*/</span><a name="l00026"></a><a class="code" href="struct_cipher_mode_documentation.html">00026</a> <span class="keyword">struct </span><a class="code" href="struct_cipher_mode_documentation.html">CipherModeDocumentation</a> : <span class="keyword">public</span> <a class="code" href="struct_symmetric_cipher_documentation.html">SymmetricCipherDocumentation</a>00027 {00028 };00029 00030 <span class="keyword">class </span>CRYPTOPP_DLL CipherModeBase : <span class="keyword">public</span> <a class="code" href="class_symmetric_cipher.html">SymmetricCipher</a>00031 {00032 <span class="keyword">public</span>:00033 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea21">MinKeyLength</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->MinKeyLength();}00034 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea22">MaxKeyLength</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->MaxKeyLength();}00035 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea23">DefaultKeyLength</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->DefaultKeyLength();}00036 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea24">GetValidKeyLength</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->GetValidKeyLength(n);}00037 <span class="keywordtype">bool</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea25">IsValidKeyLength</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->IsValidKeyLength(n);}00038 00039 <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea26">SetKey</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params = g_nullNameValuePairs);00040 00041 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_stream_transformation.html#_symmetric_ciphera4">OptimalDataAlignment</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="namespace_name.html#a9">BlockSize</a>();}00042 00043 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_ca32">IVSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="namespace_name.html#a9">BlockSize</a>();}00044 <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#_x_m_a_c_ca34">GetNextIV</a>(byte *IV);00045 00046 <span class="keyword">protected</span>:00047 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespace_name.html#a9">BlockSize</a>()<span class="keyword"> const </span>{assert(m_register.size() > 0); <span class="keywordflow">return</span> m_register.size();}00048 <span class="keywordtype">void</span> SetIV(<span class="keyword">const</span> byte *iv);00049 <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetFeedbackSize(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> feedbackSize)00050 {00051 <span class="keywordflow">if</span> (!(feedbackSize == 0 || feedbackSize == <a class="code" href="namespace_name.html#a9">BlockSize</a>()))00052 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_argument.html">InvalidArgument</a>(<span class="stringliteral">"CipherModeBase: feedback size cannot be specified for this cipher mode"</span>);00053 }00054 <span class="keyword">virtual</span> <span class="keywordtype">void</span> ResizeBuffers()00055 {00056 m_register.New(m_cipher->BlockSize());00057 }00058 <span class="keyword">virtual</span> <span class="keywordtype">void</span> UncheckedSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) =0;00059 00060 <a class="code" href="class_block_cipher.html">BlockCipher</a> *m_cipher;00061 <a class="code" href="class_sec_block.html">SecByteBlock</a> m_register;00062 };00063 00064 <span class="keyword">template</span> <<span class="keyword">class</span> POLICY_INTERFACE>00065 <span class="keyword">class </span>ModePolicyCommonTemplate : <span class="keyword">public</span> CipherModeBase, <span class="keyword">public</span> POLICY_INTERFACE00066 {00067 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetAlignment()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_cipher->BlockAlignment();}00068 <span class="keywordtype">void</span> CipherSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00069 };00070 00071 <span class="keyword">template</span> <<span class="keyword">class</span> POLICY_INTERFACE>00072 <span class="keywordtype">void</span> ModePolicyCommonTemplate<POLICY_INTERFACE>::CipherSetKey(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html">NameValuePairs</a> &params, <span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00073 {00074 m_cipher->SetKey(key, length, params);00075 ResizeBuffers();00076 <span class="keywordtype">int</span> feedbackSize = params.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha43">GetIntValueWithDefault</a>(Name::FeedbackSize(), 0);00077 SetFeedbackSize(feedbackSize);00078 <span class="keyword">const</span> byte *iv = params.<a class="code" href="class_name_value_pairs.html#_x_t_r___d_ha40">GetValueWithDefault</a>(Name::IV(), (<span class="keyword">const</span> byte *)NULL);00079 SetIV(iv);00080 }00081 00082 CRYPTOPP_DLL_TEMPLATE_CLASS ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>;00083 CRYPTOPP_DLL_TEMPLATE_CLASS ModePolicyCommonTemplate<AdditiveCipherAbstractPolicy>;00084 00085 <span class="keyword">class </span>CRYPTOPP_DLL CFB_ModePolicy : <span class="keyword">public</span> ModePolicyCommonTemplate<CFB_CipherAbstractPolicy>00086 {00087 <span class="keyword">public</span>:00088 IV_Requirement IVRequirement()<span class="keyword"> const </span>{<span class="keywordflow">return</span> RANDOM_IV;}00089 00090 <span class="keyword">protected</span>:00091 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetBytesPerIteration()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_feedbackSize;}00092 byte * GetRegisterBegin() {<span class="keywordflow">return</span> m_register + <a class="code" href="namespace_name.html#a9">BlockSize</a>() - m_feedbackSize;}00093 <span class="keywordtype">void</span> TransformRegister()00094 {00095 m_cipher->ProcessBlock(m_register, m_temp);00096 memmove(m_register, m_register+m_feedbackSize, <a class="code" href="namespace_name.html#a9">BlockSize</a>()-m_feedbackSize);00097 memcpy(m_register+<a class="code" href="namespace_name.html#a9">BlockSize</a>()-m_feedbackSize, m_temp, m_feedbackSize);00098 }00099 <span class="keywordtype">void</span> CipherResynchronize(<span class="keyword">const</span> byte *iv)00100 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -