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

📄 cryptlib_8h-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00356"></a><a class="code" href="class_simple_keying_interface.html#6e0fc6e456477b293902fae10497ba69">00356</a>         <span class="keyword">virtual</span> ~SimpleKeyingInterface() {}<a name="l00357"></a>00357 <span class="comment"></span><a name="l00358"></a>00358 <span class="comment">        //! returns smallest valid key length in bytes */</span><a name="l00359"></a>00359 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> MinKeyLength() <span class="keyword">const</span> =0;<span class="comment"></span><a name="l00360"></a>00360 <span class="comment">        //! returns largest valid key length in bytes */</span><a name="l00361"></a>00361 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> MaxKeyLength() <span class="keyword">const</span> =0;<span class="comment"></span><a name="l00362"></a>00362 <span class="comment">        //! returns default (recommended) key length in bytes */</span><a name="l00363"></a>00363 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> DefaultKeyLength() <span class="keyword">const</span> =0;<a name="l00364"></a>00364 <span class="comment"></span><a name="l00365"></a>00365 <span class="comment">        //! returns the smallest valid key length in bytes that is &gt;= min(n, GetMaxKeyLength())</span><a name="l00366"></a>00366 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> GetValidKeyLength(<span class="keywordtype">size_t</span> n) <span class="keyword">const</span> =0;<a name="l00367"></a>00367 <span class="comment"></span><a name="l00368"></a>00368 <span class="comment">        //! returns whether n is a valid key length</span><a name="l00369"></a><a class="code" href="class_simple_keying_interface.html#2229cdb9d7ac7e2cf3b02b39ae59ad77">00369</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsValidKeyLength(<span class="keywordtype">size_t</span> n)<span class="keyword"> const</span><a name="l00370"></a>00370 <span class="keyword">                </span>{<span class="keywordflow">return</span> n == GetValidKeyLength(n);}<a name="l00371"></a>00371 <span class="comment"></span><a name="l00372"></a>00372 <span class="comment">        //! set or reset the key of this object</span><a name="l00373"></a>00373 <span class="comment"></span><span class="comment">        /*! \param params is used to specify Rounds, BlockSize, etc */</span><a name="l00374"></a>00374         <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetKey(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &amp;params = g_nullNameValuePairs);<a name="l00375"></a>00375 <span class="comment"></span><a name="l00376"></a>00376 <span class="comment">        //! calls SetKey() with an NameValuePairs object that just specifies "Rounds"</span><a name="l00377"></a>00377 <span class="comment"></span>        <span class="keywordtype">void</span> SetKeyWithRounds(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> rounds);<a name="l00378"></a>00378 <span class="comment"></span><a name="l00379"></a>00379 <span class="comment">        //! calls SetKey() with an NameValuePairs object that just specifies "IV"</span><a name="l00380"></a>00380 <span class="comment"></span>        <span class="keywordtype">void</span> SetKeyWithIV(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length, <span class="keyword">const</span> byte *iv);<a name="l00381"></a>00381 <a name="l00382"></a><a class="code" href="class_simple_keying_interface.html#88201c180fbfaa9fef2715252546ad6eceff3ad4b12bcb6d7b61a5bd543a815c">00382</a>         <span class="keyword">enum</span> <a class="code" href="class_simple_keying_interface.html#88201c180fbfaa9fef2715252546ad6e">IV_Requirement</a> {UNIQUE_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE};<span class="comment"></span><a name="l00383"></a>00383 <span class="comment">        //! returns the minimal requirement for secure IVs</span><a name="l00384"></a>00384 <span class="comment"></span>        <span class="keyword">virtual</span> IV_Requirement IVRequirement() <span class="keyword">const</span> =0;<a name="l00385"></a>00385 <span class="comment"></span><a name="l00386"></a>00386 <span class="comment">        //! returns whether this object can be resynchronized (i.e. supports initialization vectors)</span><a name="l00387"></a>00387 <span class="comment"></span><span class="comment">        /*! If this function returns true, and no IV is passed to SetKey() and CanUseStructuredIVs()==true, an IV of all 0's will be assumed. */</span><a name="l00388"></a><a class="code" href="class_simple_keying_interface.html#71039112353cc70e9859ebd95037cc1a">00388</a>         <span class="keywordtype">bool</span> IsResynchronizable()<span class="keyword"> const </span>{<span class="keywordflow">return</span> IVRequirement() &lt; NOT_RESYNCHRONIZABLE;}<span class="comment"></span><a name="l00389"></a>00389 <span class="comment">        //! returns whether this object can use random IVs (in addition to ones returned by GetNextIV)</span><a name="l00390"></a><a class="code" href="class_simple_keying_interface.html#a09fd0893ac8c6068e07ce30bb55c1d9">00390</a> <span class="comment"></span>        <span class="keywordtype">bool</span> CanUseRandomIVs()<span class="keyword"> const </span>{<span class="keywordflow">return</span> IVRequirement() &lt;= UNPREDICTABLE_RANDOM_IV;}<span class="comment"></span><a name="l00391"></a>00391 <span class="comment">        //! returns whether this object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV)</span><a name="l00392"></a><a class="code" href="class_simple_keying_interface.html#b98803e8744b73663e7e9c872eef822b">00392</a> <span class="comment"></span>        <span class="keywordtype">bool</span> CanUsePredictableIVs()<span class="keyword"> const </span>{<span class="keywordflow">return</span> IVRequirement() &lt;= RANDOM_IV;}<span class="comment"></span><a name="l00393"></a>00393 <span class="comment">        //! returns whether this object can use structured IVs, for example a counter (in addition to ones returned by GetNextIV)</span><a name="l00394"></a><a class="code" href="class_simple_keying_interface.html#fbf7065f7db5439d471d1bcc260d3bd5">00394</a> <span class="comment"></span>        <span class="keywordtype">bool</span> CanUseStructuredIVs()<span class="keyword"> const </span>{<span class="keywordflow">return</span> IVRequirement() &lt;= UNIQUE_IV;}<a name="l00395"></a>00395 <span class="comment"></span><a name="l00396"></a>00396 <span class="comment">        //! returns size of IVs used by this object</span><a name="l00397"></a><a class="code" href="class_simple_keying_interface.html#c6da9a8d3c783014ab54a2a3ee9e676a">00397</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> IVSize()<span class="keyword"> const </span>{<span class="keywordflow">throw</span> NotImplemented(<span class="stringliteral">"SimpleKeyingInterface: this object doesn't support resynchronization"</span>);}<span class="comment"></span><a name="l00398"></a>00398 <span class="comment">        //! resynchronize with an IV</span><a name="l00399"></a><a class="code" href="class_simple_keying_interface.html#8ee3f5f9c00d193bf9d8fd8aa46ccbb2">00399</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">void</span> Resynchronize(<span class="keyword">const</span> byte *IV) {<span class="keywordflow">throw</span> NotImplemented(<span class="stringliteral">"SimpleKeyingInterface: this object doesn't support resynchronization"</span>);}<span class="comment"></span><a name="l00400"></a>00400 <span class="comment">        //! get a secure IV for the next message</span><a name="l00401"></a>00401 <span class="comment"></span><span class="comment">        /*! This method should be called after you finish encrypting one message and are ready to start the next one.</span><a name="l00402"></a>00402 <span class="comment">                After calling it, you must call SetKey() or Resynchronize() before using this object again. </span><a name="l00403"></a>00403 <span class="comment">                This method is not implemented on decryption objects. */</span><a name="l00404"></a>00404         <span class="keyword">virtual</span> <span class="keywordtype">void</span> GetNextIV(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &amp;rng, byte *IV);<a name="l00405"></a>00405 <a name="l00406"></a>00406 <span class="keyword">protected</span>:<a name="l00407"></a>00407         <span class="keyword">virtual</span> <span class="keyword">const</span> Algorithm &amp; GetAlgorithm() <span class="keyword">const</span> =0;<a name="l00408"></a>00408         <span class="keyword">virtual</span> <span class="keywordtype">void</span> UncheckedSetKey(<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" title="interface for retrieving values given their names">NameValuePairs</a> &amp;params) =0;<a name="l00409"></a>00409 <a name="l00410"></a>00410         <span class="keywordtype">void</span> ThrowIfInvalidKeyLength(<span class="keywordtype">size_t</span> length);<a name="l00411"></a>00411         <span class="keywordtype">void</span> ThrowIfResynchronizable();                 <span class="comment">// to be called when no IV is passed</span><a name="l00412"></a>00412         <span class="keywordtype">void</span> ThrowIfInvalidIV(<span class="keyword">const</span> byte *iv);  <span class="comment">// check for NULL IV if it can't be used</span><a name="l00413"></a>00413         <span class="keyword">const</span> byte * GetIVAndThrowIfInvalid(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &amp;params);<a name="l00414"></a><a class="code" href="class_simple_keying_interface.html#719efcf12f0de461b951830b8131b36a">00414</a>         <span class="keyword">inline</span> <span class="keywordtype">void</span> AssertValidKeyLength(<span class="keywordtype">size_t</span> length)<span class="keyword"> const</span><a name="l00415"></a>00415 <span class="keyword">                </span>{assert(IsValidKeyLength(length));}<a name="l00416"></a>00416 };<a name="l00417"></a>00417 <span class="comment"></span><a name="l00418"></a>00418 <span class="comment">//! interface for the data processing part of block ciphers</span><a name="l00419"></a>00419 <span class="comment"></span><span class="comment"></span><a name="l00420"></a>00420 <span class="comment">/*! Classes derived from BlockTransformation are block ciphers</span><a name="l00421"></a>00421 <span class="comment">        in ECB mode (for example the DES::Encryption class), which are stateless,</span><a name="l00422"></a>00422 <span class="comment">        and they can make assumptions about the memory alignment of their inputs and outputs.</span><a name="l00423"></a>00423 <span class="comment">        These classes should not be used directly, but only in combination with</span><a name="l00424"></a>00424 <span class="comment">        a mode class (see CipherModeDocumentation in modes.h).</span><a name="l00425"></a>00425 <span class="comment">*/</span><a name="l00426"></a><a class="code" href="class_block_transformation.html">00426</a> <span class="keyword">class </span>CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : <span class="keyword">public</span> Algorithm<a name="l00427"></a>00427 {<a name="l00428"></a>00428 <span class="keyword">public</span>:<span class="comment"></span><a name="l00429"></a>00429 <span class="comment">        //! encrypt or decrypt inBlock, xor with xorBlock, and write to outBlock</span><a name="l00430"></a>00430 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">void</span> ProcessAndXorBlock(<span class="keyword">const</span> byte *inBlock, <span class="keyword">const</span> byte *xorBlock, byte *outBlock) <span class="keyword">const</span> =0;<a name="l00431"></a>00431 <span class="comment"></span><a name="l00432"></a>00432 <span class="comment">        //! encrypt or decrypt one block</span><a name="l00433"></a>00433 <span class="comment"></span><span class="comment">        /*! \pre size of inBlock and outBlock == BlockSize() */</span><a name="l00434"></a><a class="code" href="class_block_transformation.html#2fefb3f4c6c6297c0c91fcbba9e4f4f3">00434</a>         <span class="keywordtype">void</span> ProcessBlock(<span class="keyword">const</span> byte *inBlock, byte *outBlock)<span class="keyword"> const</span><a name="l00435"></a>00435 <span class="keyword">                </span>{ProcessAndXorBlock(inBlock, NULL, outBlock);}<a name="l00436"></a>00436 <span class="comment"></span><a name="l00437"></a>00437 <span class="comment">        //! encrypt or decrypt one block in place</span><a name="l00438"></a><a class="code" href="class_block_transformation.html#12cc1846de571557be0f82471e8904bf">00438</a> <span class="comment"></span>        <span class="keywordtype">void</span> ProcessBlock(byte *inoutBlock)<span class="keyword"> const</span><a name="l00439"></a>00439 <span class="keyword">                </span>{ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}<a name="l00440"></a>00440 <span class="comment"></span><a name="l00441"></a>00441 <span class="comment">        //! block size of the cipher in bytes</span><a name="l00442"></a>00442 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> BlockSize() <span class="keyword">const</span> =0;<a name="l00443"></a>00443 <span class="comment"></span><a name="l00444"></a>00444 <span class="comment">        //! block pointers must be divisible by this</span><a name="l00445"></a>00445 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> BlockAlignment() <span class="keyword">const</span>;    <span class="comment">// returns alignment of word32 by default</span><a name="l00446"></a>00446 <span class="comment"></span><a name="l00447"></a>00447 <span class="comment">        //! returns true if this is a permutation (i.e. there is an inverse transformation)</span><a name="l00448"></a><a class="code" href="class_block_transformation.html#a4118be8bfaf6772a9a8e03dd450614b">00448</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsPermutation()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">true</span>;}<a

⌨️ 快捷键说明

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