📄 seckey_8h-source.html
字号:
<!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++: seckey.h 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 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 List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div><h1>seckey.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// seckey.h - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="comment">// This file contains helper classes/functions for implementing secret key algorithms.</span><a name="l00004"></a>00004 <a name="l00005"></a>00005 <span class="preprocessor">#ifndef CRYPTOPP_SECKEY_H</span><a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_SECKEY_H</span><a name="l00007"></a>00007 <span class="preprocessor"></span><a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="cryptlib_8h.html">cryptlib.h</a>"</span><a name="l00009"></a>00009 <span class="preprocessor">#include "misc.h"</span><a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="simple_8h.html">simple.h</a>"</span><a name="l00011"></a>00011 <a name="l00012"></a>00012 NAMESPACE_BEGIN(CryptoPP)<a name="l00013"></a>00013 <a name="l00014"></a>00014 inline <a class="code" href="cryptlib_8h.html#353ccabf5ddc119a6a33e92f7b9961c7" title="used to specify a direction for a cipher to operate in (encrypt or decrypt)">CipherDir</a> ReverseCipherDir(<a class="code" href="cryptlib_8h.html#353ccabf5ddc119a6a33e92f7b9961c7" title="used to specify a direction for a cipher to operate in (encrypt or decrypt)">CipherDir</a> dir)<a name="l00015"></a>00015 {<a name="l00016"></a>00016 <span class="keywordflow">return</span> (dir == <a class="code" href="cryptlib_8h.html#353ccabf5ddc119a6a33e92f7b9961c7244e5e74f856cdd5aafc1005877a2f61">ENCRYPTION</a>) ? <a class="code" href="cryptlib_8h.html#353ccabf5ddc119a6a33e92f7b9961c7b5f88847da182e7a1a8af64f4e18f048">DECRYPTION</a> : <a class="code" href="cryptlib_8h.html#353ccabf5ddc119a6a33e92f7b9961c7244e5e74f856cdd5aafc1005877a2f61">ENCRYPTION</a>;<a name="l00017"></a>00017 }<a name="l00018"></a>00018 <span class="comment"></span><a name="l00019"></a>00019 <span class="comment">//! to be inherited by block ciphers with fixed block size</span><a name="l00020"></a>00020 <span class="comment"></span><span class="keyword">template</span> <<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> N><a name="l00021"></a><a class="code" href="class_fixed_block_size.html">00021</a> <span class="keyword">class </span><a class="code" href="class_fixed_block_size.html" title="to be inherited by block ciphers with fixed block size">FixedBlockSize</a><a name="l00022"></a>00022 {<a name="l00023"></a>00023 <span class="keyword">public</span>:<a name="l00024"></a><a class="code" href="class_fixed_block_size.html#2b051f369471fbb83d9b61a90b06e99f">00024</a> CRYPTOPP_CONSTANT(<a class="code" href="class_fixed_block_size.html#2b051f369471fbb83d9b61a90b06e99f">BLOCKSIZE</a> = N)<a name="l00025"></a>00025 };<a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="comment">// ************** rounds ***************</span><a name="l00028"></a>00028 <span class="comment"></span><a name="l00029"></a>00029 <span class="comment">//! to be inherited by ciphers with fixed number of rounds</span><a name="l00030"></a>00030 <span class="comment"></span><span class="keyword">template</span> <<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> R><a name="l00031"></a><a class="code" href="class_fixed_rounds.html">00031</a> <span class="keyword">class </span><a class="code" href="class_fixed_rounds.html" title="to be inherited by ciphers with fixed number of rounds">FixedRounds</a><a name="l00032"></a>00032 {<a name="l00033"></a>00033 <span class="keyword">public</span>:<a name="l00034"></a><a class="code" href="class_fixed_rounds.html#910701ff30c578368793f5faae246108">00034</a> CRYPTOPP_CONSTANT(<a class="code" href="class_fixed_rounds.html#910701ff30c578368793f5faae246108">ROUNDS</a> = R)<a name="l00035"></a>00035 };<a name="l00036"></a>00036 <span class="comment"></span><a name="l00037"></a>00037 <span class="comment">//! to be inherited by ciphers with variable number of rounds</span><a name="l00038"></a>00038 <span class="comment"></span><span class="keyword">template</span> <<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> D, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> N=1, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> M=INT_MAX> <span class="comment">// use INT_MAX here because enums are treated as signed ints</span><a name="l00039"></a><a class="code" href="class_variable_rounds.html">00039</a> <span class="keyword">class </span><a class="code" href="class_variable_rounds.html" title="to be inherited by ciphers with variable number of rounds">VariableRounds</a><a name="l00040"></a>00040 {<a name="l00041"></a>00041 <span class="keyword">public</span>:<a name="l00042"></a><a class="code" href="class_variable_rounds.html#28b6780fe25e29c10db31ab5ddf457bc">00042</a> CRYPTOPP_CONSTANT(<a class="code" href="class_variable_rounds.html#28b6780fe25e29c10db31ab5ddf457bc">DEFAULT_ROUNDS</a> = D)<a name="l00043"></a><a class="code" href="class_variable_rounds.html#de59ae3b5198852159c4b9362b93b2a5">00043</a> CRYPTOPP_CONSTANT(<a class="code" href="class_variable_rounds.html#de59ae3b5198852159c4b9362b93b2a5">MIN_ROUNDS</a> = N)<a name="l00044"></a><a class="code" href="class_variable_rounds.html#ffcd1b51e2ca369beb86b9c98c86e46f">00044</a> CRYPTOPP_CONSTANT(<a class="code" href="class_variable_rounds.html#ffcd1b51e2ca369beb86b9c98c86e46f">MAX_ROUNDS</a> = M)<a name="l00045"></a><a class="code" href="class_variable_rounds.html#356298696da2e721cffe8a70dcdec964">00045</a> static <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_variable_rounds.html#356298696da2e721cffe8a70dcdec964">StaticGetDefaultRounds</a>(<span class="keywordtype">size_t</span> keylength) {<span class="keywordflow">return</span> <a class="code" href="class_variable_rounds.html#28b6780fe25e29c10db31ab5ddf457bc">DEFAULT_ROUNDS</a>;}<a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keyword">protected</span>:<a name="l00048"></a><a class="code" href="class_variable_rounds.html#712e3fa69c57db159fa894287d5b326d">00048</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="class_variable_rounds.html#712e3fa69c57db159fa894287d5b326d">ThrowIfInvalidRounds</a>(<span class="keywordtype">int</span> rounds, <span class="keyword">const</span> <a class="code" href="class_algorithm.html" title="interface for all crypto algorithms">Algorithm</a> *alg)<a name="l00049"></a>00049 {<a name="l00050"></a>00050 <span class="keywordflow">if</span> (rounds < MIN_ROUNDS || rounds > <a class="code" href="class_variable_rounds.html#ffcd1b51e2ca369beb86b9c98c86e46f">MAX_ROUNDS</a>)<a name="l00051"></a>00051 <span class="keywordflow">throw</span> <a class="code" href="class_invalid_rounds.html" title="_">InvalidRounds</a>(alg-><a class="code" href="class_algorithm.html#4f31510a192d1121856efe8ad0a9b844" title="returns name of this algorithm, not universally implemented yet">AlgorithmName</a>(), rounds);<a name="l00052"></a>00052 }<a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="class_variable_rounds.html#29b6eb81e0829529f442106c4093d3c9">00054</a> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_variable_rounds.html#29b6eb81e0829529f442106c4093d3c9">GetRoundsAndThrowIfInvalid</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &param, <span class="keyword">const</span> <a class="code" href="class_algorithm.html" title="interface for all crypto algorithms">Algorithm</a> *alg)<a name="l00055"></a>00055 {<a name="l00056"></a>00056 <span class="keywordtype">int</span> rounds = param.<a class="code" href="class_name_value_pairs.html#7ddb654b7afcd1a04422a7b4b01366d9" title="get a named value with type int, with default">GetIntValueWithDefault</a>(<span class="stringliteral">"Rounds"</span>, <a class="code" href="class_variable_rounds.html#28b6780fe25e29c10db31ab5ddf457bc">DEFAULT_ROUNDS</a>);<a name="l00057"></a>00057 <a class="code" href="class_variable_rounds.html#712e3fa69c57db159fa894287d5b326d">ThrowIfInvalidRounds</a>(rounds, alg);<a name="l00058"></a>00058 <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)rounds;<a name="l00059"></a>00059 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -