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

📄 cryptlib_8h-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00336"></a><a class="code" href="class_algorithm.html">00336</a> <span class="keyword">class </span>CRYPTOPP_DLL Algorithm : <span class="keyword">public</span> Clonable00337 {00338 <span class="keyword">public</span>:<span class="comment"></span>00339 <span class="comment">        /*! When FIPS-140-2 compliance is enabled and checkSelfTestStatus == true,</span>00340 <span class="comment">                this constructor throws SelfTestFailure if the self test hasn't been run or fails. */</span>00341         Algorithm(<span class="keywordtype">bool</span> checkSelfTestStatus = <span class="keyword">true</span>);<span class="comment"></span>00342 <span class="comment">        //! returns name of this algorithm, not universally implemented yet</span><a name="l00343"></a><a class="code" href="class_algorithm.html#_zlib_decompressora17">00343</a> <span class="comment"></span>        <span class="keyword">virtual</span> std::string AlgorithmName()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="stringliteral">"unknown"</span>;}00344 };00345 <span class="comment"></span>00346 <span class="comment">//! keying interface for crypto algorithms that take byte strings as keys</span>00347 <span class="comment"></span><a name="l00348"></a><a class="code" href="class_simple_keying_interface.html">00348</a> <span class="keyword">class </span>CRYPTOPP_DLL SimpleKeyingInterface00349 {00350 <span class="keyword">public</span>:<span class="comment"></span>00351 <span class="comment">        //! returns smallest valid key length in bytes */</span>00352 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MinKeyLength() <span class="keyword">const</span> =0;<span class="comment"></span>00353 <span class="comment">        //! returns largest valid key length in bytes */</span>00354 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MaxKeyLength() <span class="keyword">const</span> =0;<span class="comment"></span>00355 <span class="comment">        //! returns default (recommended) key length in bytes */</span>00356 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DefaultKeyLength() <span class="keyword">const</span> =0;00357 <span class="comment"></span>00358 <span class="comment">        //! returns the smallest valid key length in bytes that is &gt;= min(n, GetMaxKeyLength())</span>00359 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetValidKeyLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n) <span class="keyword">const</span> =0;00360 <span class="comment"></span>00361 <span class="comment">        //! returns whether n is a valid key length</span><a name="l00362"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea25">00362</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsValidKeyLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n)<span class="keyword"> const</span>00363 <span class="keyword">                </span>{<span class="keywordflow">return</span> n == GetValidKeyLength(n);}00364 <span class="comment"></span>00365 <span class="comment">        //! set or reset the key of this object</span>00366 <span class="comment"></span><span class="comment">        /*! \param params is used to specify Rounds, BlockSize, etc */</span>00367         <span class="keyword">virtual</span> <span class="keywordtype">void</span> SetKey(<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> &amp;params = g_nullNameValuePairs) =0;00368 <span class="comment"></span>00369 <span class="comment">        //! calls SetKey() with an NameValuePairs object that just specifies "Rounds"</span>00370 <span class="comment"></span>        <span class="keywordtype">void</span> SetKeyWithRounds(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keywordtype">int</span> rounds);00371 <span class="comment"></span>00372 <span class="comment">        //! calls SetKey() with an NameValuePairs object that just specifies "IV"</span>00373 <span class="comment"></span>        <span class="keywordtype">void</span> SetKeyWithIV(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length, <span class="keyword">const</span> byte *iv);00374 00375         <span class="keyword">enum</span> IV_Requirement {STRUCTURED_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE};<span class="comment"></span>00376 <span class="comment">        //! returns the minimal requirement for secure IVs</span>00377 <span class="comment"></span>        <span class="keyword">virtual</span> IV_Requirement IVRequirement() <span class="keyword">const</span> =0;00378 <span class="comment"></span>00379 <span class="comment">        //! returns whether this object can be resynchronized (i.e. supports initialization vectors)</span>00380 <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="l00381"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea30">00381</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>00382 <span class="comment">        //! returns whether this object can use random IVs (in addition to ones returned by GetNextIV)</span><a name="l00383"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea31">00383</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>00384 <span class="comment">        //! returns whether this object can use random but possibly predictable IVs (in addition to ones returned by GetNextIV)</span><a name="l00385"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea32">00385</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>00386 <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="l00387"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_c___basea33">00387</a> <span class="comment"></span>        <span class="keywordtype">bool</span> CanUseStructuredIVs()<span class="keyword"> const </span>{<span class="keywordflow">return</span> IVRequirement() &lt;= STRUCTURED_IV;}00388 <span class="comment"></span>00389 <span class="comment">        //! returns size of IVs used by this object</span><a name="l00390"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_ca32">00390</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>00391 <span class="comment">        //! resynchronize with an IV</span><a name="l00392"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_ca33">00392</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>00393 <span class="comment">        //! get a secure IV for the next message</span>00394 <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>00395 <span class="comment">                After calling it, you must call SetKey() or Resynchronize() before using this object again. </span>00396 <span class="comment">                This method is not implemented on decryption objects. */</span><a name="l00397"></a><a class="code" href="class_simple_keying_interface.html#_x_m_a_c_ca34">00397</a>         <span class="keyword">virtual</span> <span class="keywordtype">void</span> GetNextIV(byte *IV) {<span class="keywordflow">throw</span> NotImplemented(<span class="stringliteral">"SimpleKeyingInterface: this object doesn't support GetNextIV()"</span>);}00398 00399 <span class="keyword">protected</span>:00400         <span class="keywordtype">void</span> ThrowIfInvalidKeyLength(<span class="keyword">const</span> Algorithm &amp;algorithm, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00401 00402         <span class="keyword">inline</span> <span class="keywordtype">void</span> AssertValidKeyLength(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)<span class="keyword"> const</span>00403 <span class="keyword">        </span>{00404                 assert(IsValidKeyLength(length));00405         }00406 };00407 <span class="comment"></span>00408 <span class="comment">//! interface for the data processing part of block ciphers</span>00409 <span class="comment"></span><span class="comment"></span>00410 <span class="comment">/*! Classes derived from BlockTransformation are block ciphers</span>00411 <span class="comment">        in ECB mode (for example the DES::Encryption class), which are stateless,</span>00412 <span class="comment">        and they can make assumptions about the memory alignment of their inputs and outputs.</span>00413 <span class="comment">        These classes should not be used directly, but only in combination with</span>00414 <span class="comment">        a mode class (see CipherModeDocumentation in modes.h).</span>00415 <span class="comment">*/</span><a name="l00416"></a><a class="code" href="class_block_transformation.html">00416</a> <span class="keyword">class </span>CRYPTOPP_DLL BlockTransformation : <span class="keyword">public</span> Algorithm00417 {00418 <span class="keyword">public</span>:<span class="comment"></span>00419 <span class="comment">        //! encrypt or decrypt inBlock, xor with xorBlock, and write to outBlock</span>00420 <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;00421 <span class="comment"></span>00422 <span class="comment">        //! encrypt or decrypt one block</span>00423 <span class="comment"></span><span class="comment">        /*! \pre size of inBlock and outBlock == BlockSize() */</span><a name="l00424"></a><a class="code" href="class_block_transformation.html#_twofish_1_1_enca9">00424</a>         <span class="keywordtype">void</span> ProcessBlock(<span class="keyword">const</span> byte *inBlock, byte *outBlock)<span class="keyword"> const</span>00425 <span class="keyword">                </span>{ProcessAndXorBlock(inBlock, NULL, outBlock);}00426 <span class="comment"></span>00427 <span class="comment">        //! encrypt or decrypt one block in place</span><a name="l00428"></a><a class="code" href="class_block_transformation.html#_twofish_1_1_enca10">00428</a> <span class="comment"></span>        <span class="keywordtype">void</span> ProcessBlock(byte *inoutBlock)<span class="keyword"> const</span>00429 <span class="keyword">                </span>{ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}00430 <span class="comment"></span>00431 <span class="comment">        //! block size of the cipher in bytes</span>00432 <span class="comment"></span>        <span class="keyword">virtual</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> =0;00433 <span class="comment"></span>00434 <span class="comment">        //! block pointers must be divisible by this</span><a name="l00435"></a><a class="code" href="class_block_transformation.html#_twofish_1_1_enca11">00435</a> <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="keywordflow">return</span> 4;}00436 <span class="comment"></span>00437 <span class="comment">        //! returns true if this is a permutation (i.e. there is an inverse transformation)</span><a name="l00438"></a><a class="code" href="class_block_transformation.html#_twofish_1_1_enca12">00438</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>;}00439 <span class="comment"></span>00440 <span class="comment">        //! returns true if this is an encryption object</span>00441 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsForwardTransformation() <span class="keyword">const</span> =0;00442 <span class="comment"></span>00443 <span class="comment">        //! return number of blocks that can be processed in parallel, for bit-slicing implementations</span><a name="l00444"></a><a class="code" href="class_block_transformation.html#_twofish_1_1_enca14">00444</a> <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OptimalNumberOfParallelBlocks()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1;}00445 <span class="comment"></span>00446 <span class="comment">        //! encrypt or decrypt multiple blocks, for bit-slicing implementations</span>00447 <span class="comment"></span>        <span class="keyword">virtual</span> <span class="keywordtype">void</span> ProcessAndXorMultipleBlocks(<span class="keyword">const</span> byte *inBlocks, <span class="keyword">const</span> byte *xorBlocks, byte *outBlocks, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numberOfBlocks) <span class="keyword">const</span>;00448 };00449 <span class="comment"></span>

⌨️ 快捷键说明

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