📄 hmac_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: hmac.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>hmac.h</h1><div class="fragment"><pre>00001 <span class="comment">// hmac.h - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#ifndef CRYPTOPP_HMAC_H</span>00004 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_HMAC_H</span>00005 <span class="preprocessor"></span>00006 <span class="preprocessor">#include "seckey.h"</span>00007 <span class="preprocessor">#include "secblock.h"</span>00008 00009 NAMESPACE_BEGIN(CryptoPP)00010 00011 <span class="keyword">class </span>CRYPTOPP_DLL HMAC_Base : <span class="keyword">public</span> <a class="code" href="class_variable_key_length.html">VariableKeyLength</a><16, 0, UINT_MAX>, <span class="keyword">public</span> <a class="code" href="class_message_authentication_code.html">MessageAuthenticationCode</a>00012 {00013 <span class="keyword">public</span>:00014 HMAC_Base() : m_innerHashKeyed(false) {}00015 <span class="keywordtype">void</span> UncheckedSetKey(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylength);00016 00017 <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">Restart</a>();00018 <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca5">Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00019 <span class="keywordtype">void</span> <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca15">TruncatedFinal</a>(byte *mac, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size);00020 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca11">OptimalBlockSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> const_cast<HMAC_Base*>(<span class="keyword">this</span>)->AccessHash().OptimalBlockSize();}00021 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_hash_transformation.html#_x_m_a_c_ca9">DigestSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> const_cast<HMAC_Base*>(<span class="keyword">this</span>)->AccessHash().DigestSize();}00022 00023 <span class="keyword">protected</span>:00024 <span class="keyword">virtual</span> <a class="code" href="class_hash_transformation.html">HashTransformation</a> & AccessHash() =0;00025 <span class="keyword">virtual</span> byte * AccessIpad() =0;00026 <span class="keyword">virtual</span> byte * AccessOpad() =0;00027 <span class="keyword">virtual</span> byte * AccessInnerHash() =0;00028 00029 <span class="keyword">private</span>:00030 <span class="keywordtype">void</span> KeyInnerHash();00031 00032 <span class="keyword">enum</span> {IPAD=0x36, OPAD=0x5c};00033 00034 <span class="keywordtype">bool</span> m_innerHashKeyed;00035 };00036 <span class="comment"></span>00037 <span class="comment">//! <a href="http://www.weidai.com/scan-mirror/mac.html#HMAC">HMAC</a></span>00038 <span class="comment"></span><span class="comment">/*! HMAC(K, text) = H(K XOR opad, H(K XOR ipad, text)) */</span>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">HMAC</a> : <span class="keyword">public</span> <a class="code" href="class_message_authentication_code_final_template.html">MessageAuthenticationCodeFinalTemplate</a><HMAC_Base, HMAC<T> >00041 {00042 <span class="keyword">public</span>:00043 <span class="keyword">enum</span> {DIGESTSIZE=T::DIGESTSIZE, BLOCKSIZE=T::BLOCKSIZE};00044 00045 <a class="code" href="class_h_m_a_c.html">HMAC</a>() {}00046 <a class="code" href="class_h_m_a_c.html">HMAC</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length=HMAC_Base::DEFAULT_KEYLENGTH)00047 {<a class="code" href="class_message_authentication_code_final_template.html#_message_authentication_code_final_templatea3">SetKey</a>(key, length);}00048 00049 <span class="keyword">static</span> std::string StaticAlgorithmName() {<span class="keywordflow">return</span> std::string(<span class="stringliteral">"HMAC("</span>) + T::StaticAlgorithmName() + <span class="stringliteral">")"</span>;}00050 00051 <span class="keyword">private</span>:00052 <a class="code" href="class_hash_transformation.html">HashTransformation</a> & AccessHash() {<span class="keywordflow">return</span> m_hash;}00053 byte * AccessIpad() {<span class="keywordflow">return</span> m_ipad;}00054 byte * AccessOpad() {<span class="keywordflow">return</span> m_opad;}00055 byte * AccessInnerHash() {<span class="keywordflow">return</span> m_innerHash;}00056 00057 FixedSizeSecBlock<byte, BLOCKSIZE> m_ipad, m_opad;00058 FixedSizeSecBlock<byte, DIGESTSIZE> m_innerHash;00059 T m_hash;00060 };00061 00062 NAMESPACE_END00063 00064 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:16 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -