📄 hmac_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++: hmac.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>hmac.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// hmac.h - written and placed in the public domain by Wei Dai</span><a name="l00002"></a>00002 <a name="l00003"></a>00003 <span class="preprocessor">#ifndef CRYPTOPP_HMAC_H</span><a name="l00004"></a>00004 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_HMAC_H</span><a name="l00005"></a>00005 <span class="preprocessor"></span><a name="l00006"></a>00006 <span class="preprocessor">#include "seckey.h"</span><a name="l00007"></a>00007 <span class="preprocessor">#include "secblock.h"</span><a name="l00008"></a>00008 <a name="l00009"></a>00009 NAMESPACE_BEGIN(CryptoPP)<a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="comment">//! _</span><a name="l00012"></a><a class="code" href="class_h_m_a_c___base.html">00012</a> <span class="comment"></span>class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE <a class="code" href="class_h_m_a_c___base.html" title="_">HMAC_Base</a> : public <a class="code" href="class_variable_key_length.html" title="support query of variable key length, template parameters are default, min, max,...">VariableKeyLength</a><16, 0, INT_MAX>, public <a class="code" href="class_message_authentication_code.html" title="interface for message authentication codes">MessageAuthenticationCode</a><a name="l00013"></a>00013 {<a name="l00014"></a>00014 <span class="keyword">public</span>:<a name="l00015"></a><a class="code" href="class_h_m_a_c___base.html#b593233a7322a1e4cb3fb4d8b298742a">00015</a> <a class="code" href="class_h_m_a_c___base.html" title="_">HMAC_Base</a>() : m_innerHashKeyed(false) {}<a name="l00016"></a>00016 <span class="keywordtype">void</span> UncheckedSetKey(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylength, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &params);<a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="keywordtype">void</span> Restart();<a name="l00019"></a>00019 <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">size_t</span> length);<a name="l00020"></a>00020 <span class="keywordtype">void</span> TruncatedFinal(byte *mac, <span class="keywordtype">size_t</span> size);<a name="l00021"></a><a class="code" href="class_h_m_a_c___base.html#3f8a783fe1da496cf33bf35d6376100b">00021</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OptimalBlockSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">const_cast<</span><a class="code" href="class_h_m_a_c___base.html" title="_">HMAC_Base</a>*<span class="keyword">></span>(<span class="keyword">this</span>)->AccessHash().OptimalBlockSize();}<a name="l00022"></a><a class="code" href="class_h_m_a_c___base.html#c47c7569f590e0a2ff2339d058c3337d">00022</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DigestSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">const_cast<</span><a class="code" href="class_h_m_a_c___base.html" title="_">HMAC_Base</a>*<span class="keyword">></span>(<span class="keyword">this</span>)->AccessHash().DigestSize();}<a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="keyword">protected</span>:<a name="l00025"></a>00025 <span class="keyword">virtual</span> <a class="code" href="class_hash_transformation.html" title="interface for hash functions and data processing part of MACs">HashTransformation</a> & AccessHash() =0;<a name="l00026"></a><a class="code" href="class_h_m_a_c___base.html#a5ec52ba47376b2ed7e707f649551c52">00026</a> byte * AccessIpad() {<span class="keywordflow">return</span> m_buf;}<a name="l00027"></a><a class="code" href="class_h_m_a_c___base.html#1eb74bfc58d11822a7bfe120d6be5ded">00027</a> byte * AccessOpad() {<span class="keywordflow">return</span> m_buf + AccessHash().BlockSize();}<a name="l00028"></a><a class="code" href="class_h_m_a_c___base.html#e434fa6e09440f0b64118c98fdc5cc2b">00028</a> byte * AccessInnerHash() {<span class="keywordflow">return</span> m_buf + 2*AccessHash().BlockSize();}<a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="keyword">private</span>:<a name="l00031"></a>00031 <span class="keywordtype">void</span> KeyInnerHash();<a name="l00032"></a>00032 <a name="l00033"></a>00033 <a class="code" href="class_sec_block.html" title="a block of memory allocated using A">SecByteBlock</a> m_buf;<a name="l00034"></a>00034 <span class="keywordtype">bool</span> m_innerHashKeyed;<a name="l00035"></a>00035 };<a name="l00036"></a>00036 <span class="comment"></span><a name="l00037"></a>00037 <span class="comment">//! <a href="http://www.weidai.com/scan-mirror/mac.html#HMAC">HMAC</a></span><a name="l00038"></a>00038 <span class="comment"></span><span class="comment">/*! HMAC(K, text) = H(K XOR opad, H(K XOR ipad, text)) */</span><a name="l00039"></a>00039 <span class="keyword">template</span> <<span class="keyword">class</span> T><a name="l00040"></a><a class="code" href="class_h_m_a_c.html">00040</a> <span class="keyword">class </span><a class="code" href="class_h_m_a_c.html" title="HMAC">HMAC</a> : <span class="keyword">public</span> <a class="code" href="class_message_authentication_code_impl.html" title="_">MessageAuthenticationCodeImpl</a><HMAC_Base, HMAC<T> ><a name="l00041"></a>00041 {<a name="l00042"></a>00042 <span class="keyword">public</span>:<a name="l00043"></a><a class="code" href="class_h_m_a_c.html#d3fd5a049bc734daff8c1f2983863488">00043</a> CRYPTOPP_CONSTANT(<a class="code" href="class_h_m_a_c.html#d3fd5a049bc734daff8c1f2983863488">DIGESTSIZE</a>=T::DIGESTSIZE)<a name="l00044"></a><a class="code" href="class_h_m_a_c.html#c0d6aa69389f52c26cbe95fceebf7f2c">00044</a> CRYPTOPP_CONSTANT(<a class="code" href="class_h_m_a_c.html#c0d6aa69389f52c26cbe95fceebf7f2c">BLOCKSIZE</a>=T::<a class="code" href="class_h_m_a_c.html#c0d6aa69389f52c26cbe95fceebf7f2c">BLOCKSIZE</a>)<a name="l00045"></a>00045 <a name="l00046"></a><a class="code" href="class_h_m_a_c.html#8ca0d4c7d1a29cd46906f6384e2fe615">00046</a> <a class="code" href="class_h_m_a_c.html" title="HMAC">HMAC</a>() {}<a name="l00047"></a><a class="code" href="class_h_m_a_c.html#84d6e40e7e5798283afbf40cb77dd19d">00047</a> <a class="code" href="class_h_m_a_c.html#8ca0d4c7d1a29cd46906f6384e2fe615">HMAC</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">size_t</span> length=<a class="code" href="class_variable_key_length.html#3788ee30b190bdc0c0e89d2721162614">HMAC_Base::DEFAULT_KEYLENGTH</a>)<a name="l00048"></a>00048 {this-><a class="code" href="class_simple_keying_interface.html#df3c29b3ef3af74788a58c7c49887fd7" title="set or reset the key of this object">SetKey</a>(key, length);}<a name="l00049"></a>00049 <a name="l00050"></a><a class="code" href="class_h_m_a_c.html#04d21d622f4f8d0d469d9e9231f0c3f8">00050</a> <span class="keyword">static</span> std::string <a class="code" href="class_h_m_a_c.html#04d21d622f4f8d0d469d9e9231f0c3f8">StaticAlgorithmName</a>() {<span class="keywordflow">return</span> std::string(<span class="stringliteral">"HMAC("</span>) + T::StaticAlgorithmName() + <span class="stringliteral">")"</span>;}<a name="l00051"></a><a class="code" href="class_h_m_a_c.html#9953ec5c13284a128ff177207ed5681b">00051</a> std::string <a class="code" href="class_h_m_a_c.html#9953ec5c13284a128ff177207ed5681b" title="returns name of this algorithm, not universally implemented yet">AlgorithmName</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> std::string(<span class="stringliteral">"HMAC("</span>) + m_hash.AlgorithmName() + <span class="stringliteral">")"</span>;}<a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="keyword">private</span>:<a name="l00054"></a>00054 <a class="code" href="class_hash_transformation.html" title="interface for hash functions and data processing part of MACs">HashTransformation</a> & AccessHash() {<span class="keywordflow">return</span> m_hash;}<a name="l00055"></a>00055 <a name="l00056"></a>00056 T m_hash;<a name="l00057"></a>00057 };<a name="l00058"></a>00058 <a name="l00059"></a>00059 NAMESPACE_END<a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Jun 1 11:11:21 2007 for Crypto++ by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -