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

📄 safer_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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++: safer.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>safer.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// safer.cpp - modified by by Wei Dai from Richard De Moliner's safer.c</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#include "pch.h"</span><a name="l00004"></a>00004 <span class="preprocessor">#include "<a class="code" href="safer_8h.html">safer.h</a>"</span><a name="l00005"></a>00005 <span class="preprocessor">#include "misc.h"</span><a name="l00006"></a>00006 <span class="preprocessor">#include "argnames.h"</span><a name="l00007"></a>00007 <a name="l00008"></a>00008 NAMESPACE_BEGIN(CryptoPP)<a name="l00009"></a>00009 <a name="l00010"></a>00010 const byte <a class="code" href="class_s_a_f_e_r.html" title="base class, do not use directly">SAFER</a>::Base::exp_tab[256] = <a name="l00011"></a>00011         {1, 45, 226, 147, 190, 69, 21, 174, 120, 3, 135, 164, 184, 56, 207, 63,<a name="l00012"></a>00012         8, 103, 9, 148, 235, 38, 168, 107, 189, 24, 52, 27, 187, 191, 114, 247,<a name="l00013"></a>00013         64, 53, 72, 156, 81, 47, 59, 85, 227, 192, 159, 216, 211, 243, 141, 177,<a name="l00014"></a>00014         255, 167, 62, 220, 134, 119, 215, 166, 17, 251, 244, 186, 146, 145, 100, 131,<a name="l00015"></a>00015         241, 51, 239, 218, 44, 181, 178, 43, 136, 209, 153, 203, 140, 132, 29, 20,<a name="l00016"></a>00016         129, 151, 113, 202, 95, 163, 139, 87, 60, 130, 196, 82, 92, 28, 232, 160,<a name="l00017"></a>00017         4, 180, 133, 74, 246, 19, 84, 182, 223, 12, 26, 142, 222, 224, 57, 252,<a name="l00018"></a>00018         32, 155, 36, 78, 169, 152, 158, 171, 242, 96, 208, 108, 234, 250, 199, 217,<a name="l00019"></a>00019         0, 212, 31, 110, 67, 188, 236, 83, 137, 254, 122, 93, 73, 201, 50, 194,<a name="l00020"></a>00020         249, 154, 248, 109, 22, 219, 89, 150, 68, 233, 205, 230, 70, 66, 143, 10,<a name="l00021"></a>00021         193, 204, 185, 101, 176, 210, 198, 172, 30, 65, 98, 41, 46, 14, 116, 80,<a name="l00022"></a>00022         2, 90, 195, 37, 123, 138, 42, 91, 240, 6, 13, 71, 111, 112, 157, 126,<a name="l00023"></a>00023         16, 206, 18, 39, 213, 76, 79, 214, 121, 48, 104, 54, 117, 125, 228, 237,<a name="l00024"></a>00024         128, 106, 144, 55, 162, 94, 118, 170, 197, 127, 61, 175, 165, 229, 25, 97,<a name="l00025"></a>00025         253, 77, 124, 183, 11, 238, 173, 75, 34, 245, 231, 115, 35, 33, 200, 5,<a name="l00026"></a>00026         225, 102, 221, 179, 88, 105, 99, 86, 15, 161, 49, 149, 23, 7, 58, 40};<a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="keyword">const</span> byte <a class="code" href="class_s_a_f_e_r_1_1_base.html#4d810b8ff6a4970e23aa5fc1d7bc932b">SAFER::Base::log_tab</a>[256] = <a name="l00029"></a>00029         {128, 0, 176, 9, 96, 239, 185, 253, 16, 18, 159, 228, 105, 186, 173, 248,<a name="l00030"></a>00030         192, 56, 194, 101, 79, 6, 148, 252, 25, 222, 106, 27, 93, 78, 168, 130,<a name="l00031"></a>00031         112, 237, 232, 236, 114, 179, 21, 195, 255, 171, 182, 71, 68, 1, 172, 37,<a name="l00032"></a>00032         201, 250, 142, 65, 26, 33, 203, 211, 13, 110, 254, 38, 88, 218, 50, 15,<a name="l00033"></a>00033         32, 169, 157, 132, 152, 5, 156, 187, 34, 140, 99, 231, 197, 225, 115, 198,<a name="l00034"></a>00034         175, 36, 91, 135, 102, 39, 247, 87, 244, 150, 177, 183, 92, 139, 213, 84,<a name="l00035"></a>00035         121, 223, 170, 246, 62, 163, 241, 17, 202, 245, 209, 23, 123, 147, 131, 188,<a name="l00036"></a>00036         189, 82, 30, 235, 174, 204, 214, 53, 8, 200, 138, 180, 226, 205, 191, 217,<a name="l00037"></a>00037         208, 80, 89, 63, 77, 98, 52, 10, 72, 136, 181, 86, 76, 46, 107, 158,<a name="l00038"></a>00038         210, 61, 60, 3, 19, 251, 151, 81, 117, 74, 145, 113, 35, 190, 118, 42,<a name="l00039"></a>00039         95, 249, 212, 85, 11, 220, 55, 49, 22, 116, 215, 119, 167, 230, 7, 219,<a name="l00040"></a>00040         164, 47, 70, 243, 97, 69, 103, 227, 12, 162, 59, 28, 133, 24, 4, 29,<a name="l00041"></a>00041         41, 160, 143, 178, 90, 216, 166, 126, 238, 141, 83, 75, 161, 154, 193, 14,<a name="l00042"></a>00042         122, 73, 165, 44, 129, 196, 199, 54, 43, 127, 67, 149, 51, 242, 108, 104,<a name="l00043"></a>00043         109, 240, 2, 40, 206, 221, 155, 234, 94, 153, 124, 20, 134, 207, 229, 66,<a name="l00044"></a>00044         184, 64, 120, 45, 58, 233, 100, 31, 146, 144, 125, 57, 111, 224, 137, 48};<a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#define EXP(x)       exp_tab[(x)]</span><a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define LOG(x)       log_tab[(x)]</span><a name="l00048"></a>00048 <span class="preprocessor"></span><span class="preprocessor">#define PHT(x, y)    { y += x; x += y; }</span><a name="l00049"></a>00049 <span class="preprocessor"></span><span class="preprocessor">#define IPHT(x, y)   { x -= y; y -= x; }</span><a name="l00050"></a>00050 <span class="preprocessor"></span><a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> BLOCKSIZE = 8;<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MAX_ROUNDS = 13;<a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="class_s_a_f_e_r_1_1_base.html#d403227c3c5f82315dbb3f13dd2ec868">00054</a> <span class="keywordtype">void</span> <a class="code" href="class_s_a_f_e_r_1_1_base.html#d403227c3c5f82315dbb3f13dd2ec868">SAFER::Base::UncheckedSetKey</a>(<span class="keyword">const</span> byte *userkey_1, <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)<a name="l00055"></a>00055 {<a name="l00056"></a>00056         <span class="keywordtype">bool</span> strengthened = Strengthened();<a name="l00057"></a>00057         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nof_rounds = 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#ef07deb188a711a240d95f3ccddc9e8e" title="int">Name::Rounds</a>(), length == 8 ? (strengthened ? 8 : 6) : 10);<a name="l00058"></a>00058 <a name="l00059"></a>00059         <span class="keyword">const</span> byte *userkey_2 = length == 8 ? userkey_1 : userkey_1 + 8;<a name="l00060"></a>00060         <a class="code" href="class_s_a_f_e_r_1_1_base.html#7a0b1cf722b42cbadc175cf6ff93366d">keySchedule</a>.<a class="code" href="class_sec_block.html#90d46e577c951d81a2d25a4742a3e979" title="change size, without preserving contents">New</a>(1 + BLOCKSIZE * (1 + 2 * nof_rounds));<a name="l00061"></a>00061 <a name="l00062"></a>00062         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, j;<a name="l00063"></a>00063         byte *key = <a class="code" href="class_s_a_f_e_r_1_1_base.html#7a0b1cf722b42cbadc175cf6ff93366d">keySchedule</a>;<a name="l00064"></a>00064         <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> ka(BLOCKSIZE + 1), kb(BLOCKSIZE + 1);<a name="l00065"></a>00065 <a name="l00066"></a>00066         <span class="keywordflow">if</span> (MAX_ROUNDS &lt; nof_rounds)<a name="l00067"></a>00067                 nof_rounds = MAX_ROUNDS;<a name="l00068"></a>00068         *key++ = (<span class="keywordtype">unsigned</span> char)nof_rounds;<a name="l00069"></a>00069         ka[BLOCKSIZE] = 0;

⌨️ 快捷键说明

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