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

📄 cryptlib_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: cryptlib.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="namespaces.html"><span>Namespaces</span></a></li>    <li><a href="classes.html"><span>Classes</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>  </ul></div><h1>cryptlib.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// cryptlib.cpp - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span><a name="l00004"></a>00004 <a name="l00005"></a>00005 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span><a name="l00006"></a>00006 <span class="preprocessor"></span><a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span><a name="l00008"></a>00008 <span class="preprocessor">#include "misc.h"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "filters.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "algparam.h"</span><a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="fips140_8h.html">fips140.h</a>"</span><a name="l00012"></a>00012 <span class="preprocessor">#include "argnames.h"</span><a name="l00013"></a>00013 <span class="preprocessor">#include "fltrimpl.h"</span><a name="l00014"></a>00014 <span class="preprocessor">#include "trdlocal.h"</span><a name="l00015"></a>00015 <span class="preprocessor">#include "osrng.h"</span><a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include &lt;memory&gt;</span><a name="l00018"></a>00018 <a name="l00019"></a>00019 NAMESPACE_BEGIN(CryptoPP)<a name="l00020"></a>00020 <a name="l00021"></a>00021 CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);<a name="l00022"></a>00022 CRYPTOPP_COMPILE_ASSERT(sizeof(word16) == 2);<a name="l00023"></a>00023 CRYPTOPP_COMPILE_ASSERT(sizeof(word32) == 4);<a name="l00024"></a>00024 <span class="preprocessor">#ifdef WORD64_AVAILABLE</span><a name="l00025"></a>00025 <span class="preprocessor"></span>CRYPTOPP_COMPILE_ASSERT(<span class="keyword">sizeof</span>(word64) == 8);<a name="l00026"></a>00026 <span class="preprocessor">#endif</span><a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#ifdef CRYPTOPP_NATIVE_DWORD_AVAILABLE</span><a name="l00028"></a>00028 <span class="preprocessor"></span>CRYPTOPP_COMPILE_ASSERT(<span class="keyword">sizeof</span>(dword) == 2*<span class="keyword">sizeof</span>(word));<a name="l00029"></a>00029 <span class="preprocessor">#endif</span><a name="l00030"></a>00030 <span class="preprocessor"></span><a name="l00031"></a>00031 <span class="keyword">const</span> std::string <a class="code" href="class_buffered_transformation.html#5e938c68f2a5e32a03440b1dc2bdc74a">BufferedTransformation::NULL_CHANNEL</a>;<a name="l00032"></a><a class="code" href="cryptlib_8h.html#d3205973dd1afa14090a683154c1109c">00032</a> <span class="keyword">const</span> <a class="code" href="class_null_name_value_pairs.html" title="empty set of name-value pairs">NullNameValuePairs</a> g_nullNameValuePairs;<a name="l00033"></a>00033 <a name="l00034"></a><a class="code" href="cryptlib_8h.html#e42d0f5e86285a0fd540be52caabbfeb">00034</a> <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &amp; TheBitBucket()<a name="l00035"></a>00035 {<a name="l00036"></a>00036         <span class="keyword">static</span> <a class="code" href="class_bit_bucket.html">BitBucket</a> bitBucket;<a name="l00037"></a>00037         <span class="keywordflow">return</span> bitBucket;<a name="l00038"></a>00038 }<a name="l00039"></a>00039 <a name="l00040"></a><a class="code" href="class_algorithm.html#1c77f5117ca2cd881baf26a364cfc606">00040</a> <a class="code" href="class_algorithm.html#1c77f5117ca2cd881baf26a364cfc606">Algorithm::Algorithm</a>(<span class="keywordtype">bool</span> checkSelfTestStatus)<a name="l00041"></a>00041 {<a name="l00042"></a>00042         <span class="keywordflow">if</span> (checkSelfTestStatus &amp;&amp; FIPS_140_2_ComplianceEnabled())<a name="l00043"></a>00043         {<a name="l00044"></a>00044                 <span class="keywordflow">if</span> (GetPowerUpSelfTestStatus() == <a class="code" href="fips140_8h.html#8ccac50ac3bfc5abaa6cb457f0ded35d50805cb51444d59eb747962fa279ad27">POWER_UP_SELF_TEST_NOT_DONE</a> &amp;&amp; !PowerUpSelfTestInProgressOnThisThread())<a name="l00045"></a>00045                         <span class="keywordflow">throw</span> <a class="code" href="class_self_test_failure.html" title="exception thrown when a crypto algorithm is used after a self test fails">SelfTestFailure</a>(<span class="stringliteral">"Cryptographic algorithms are disabled before the power-up self tests are performed."</span>);<a name="l00046"></a>00046 <a name="l00047"></a>00047                 <span class="keywordflow">if</span> (GetPowerUpSelfTestStatus() == <a class="code" href="fips140_8h.html#8ccac50ac3bfc5abaa6cb457f0ded35d7fdf030b911a428fda600038ef914c95">POWER_UP_SELF_TEST_FAILED</a>)<a name="l00048"></a>00048                         <span class="keywordflow">throw</span> <a class="code" href="class_self_test_failure.html" title="exception thrown when a crypto algorithm is used after a self test fails">SelfTestFailure</a>(<span class="stringliteral">"Cryptographic algorithms are disabled after a power-up self test failed."</span>);<a name="l00049"></a>00049         }<a name="l00050"></a>00050 }<a name="l00051"></a>00051 <a name="l00052"></a><a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7">00052</a> <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SimpleKeyingInterface::SetKey</a>(<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)<a name="l00053"></a>00053 {<a name="l00054"></a>00054         this-&gt;<a class="code" href="class_simple_keying_interface.html#32b2095542b18025814118734bf34da2">ThrowIfInvalidKeyLength</a>(length);<a name="l00055"></a>00055         this-&gt;UncheckedSetKey(key, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)length, params);<a name="l00056"></a>00056 }<a name="l00057"></a>00057 <a name="l00058"></a><a class="code" href="class_simple_keying_interface.html#0401f9c67930805180964bc02ae0ac1c">00058</a> <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#0401f9c67930805180964bc02ae0ac1c" title="calls SetKey() with an NameValuePairs object that just specifies "Rounds"">SimpleKeyingInterface::SetKeyWithRounds</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> rounds)<a name="l00059"></a>00059 {<a name="l00060"></a>00060         <a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length, MakeParameters(<a class="code" href="namespace_name.html#ef07deb188a711a240d95f3ccddc9e8e" title="int">Name::Rounds</a>(), rounds));<a name="l00061"></a>00061 }<a name="l00062"></a>00062 <a name="l00063"></a><a class="code" href="class_simple_keying_interface.html#c25e27eaeae2e909741c07de93caef49">00063</a> <span class="keywordtype">void</span> <a class="code" href="class_simple_keying_interface.html#c25e27eaeae2e909741c07de93caef49" title="calls SetKey() with an NameValuePairs object that just specifies "IV"">SimpleKeyingInterface::SetKeyWithIV</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length, <span class="keyword">const</span> byte *iv)<a name="l00064"></a>00064 {<a name="l00065"></a>00065         <a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length, MakeParameters(<a class="code" href="namespace_name.html#9b6839240a8bdf1f5bcbebf1866f4733" title="const byte *">Name::IV</a>(), iv));

⌨️ 快捷键说明

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