📄 dmac_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++: dmac.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>dmac.h</h1><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef CRYPTOPP_DMAC_H</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_DMAC_H</span>00003 <span class="preprocessor"></span>00004 <span class="preprocessor">#include "cbcmac.h"</span>00005 00006 NAMESPACE_BEGIN(CryptoPP)00007 00008 <span class="keyword">template</span> <<span class="keyword">class</span> T>00009 <span class="keyword">class </span>DMAC_Base : <span class="keyword">public</span> <a class="code" href="class_same_key_length_as.html">SameKeyLengthAs</a><T>, <span class="keyword">public</span> <a class="code" href="class_message_authentication_code.html">MessageAuthenticationCode</a>00010 {00011 <span class="keyword">public</span>:00012 <span class="keyword">static</span> std::string StaticAlgorithmName() {<span class="keywordflow">return</span> std::string(<span class="stringliteral">"DMAC("</span>) + T::StaticAlgorithmName() + <span class="stringliteral">")"</span>;}00013 00014 <span class="keyword">enum</span> {DIGESTSIZE=T::BLOCKSIZE};00015 00016 DMAC_Base() {}00017 00018 <span class="keywordtype">void</span> CheckedSetKey(<span class="keywordtype">void</span> *, Empty empty, <span class="keyword">const</span> byte *key, <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">NameValuePairs</a> &params);00019 <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00020 <span class="keywordtype">void</span> TruncatedFinal(byte *mac, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size);00021 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DigestSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> DIGESTSIZE;}00022 00023 <span class="keyword">private</span>:00024 byte *GenerateSubKeys(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylength);00025 00026 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_subkeylength;00027 <a class="code" href="class_sec_block.html">SecByteBlock</a> m_subkeys;00028 <a class="code" href="class_c_b_c___m_a_c.html">CBC_MAC<T></a> m_mac1;00029 <span class="keyword">typename</span> T::Encryption m_f2;00030 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_counter;00031 };00032 <span class="comment"></span>00033 <span class="comment">//! DMAC</span>00034 <span class="comment"></span><span class="comment">/*! Based on "CBC MAC for Real-Time Data Sources" by Erez Petrank</span>00035 <span class="comment"> and Charles Rackoff. T should be BlockTransformation class.</span>00036 <span class="comment">*/</span>00037 <span class="keyword">template</span> <<span class="keyword">class</span> T><a name="l00038"></a><a class="code" href="class_d_m_a_c.html">00038</a> <span class="keyword">class </span><a class="code" href="class_d_m_a_c.html">DMAC</a> : <span class="keyword">public</span> <a class="code" href="class_message_authentication_code_final_template.html">MessageAuthenticationCodeFinalTemplate</a><DMAC_Base<T> >00039 {00040 <span class="keyword">public</span>:00041 <a class="code" href="class_d_m_a_c.html">DMAC</a>() {}00042 <a class="code" href="class_d_m_a_c.html">DMAC</a>(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length=DMAC_Base<T>::DEFAULT_KEYLENGTH)00043 {<a class="code" href="class_message_authentication_code_final_template.html#_message_authentication_code_final_templatea3">SetKey</a>(key, length);}00044 };00045 00046 <span class="keyword">template</span> <<span class="keyword">class</span> T>00047 <span class="keywordtype">void</span> DMAC_Base<T>::CheckedSetKey(<span class="keywordtype">void</span> *, Empty empty, <span class="keyword">const</span> byte *key, <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">NameValuePairs</a> &params)00048 {00049 m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);00050 m_subkeys.resize(2*STDMAX((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)T::BLOCKSIZE, m_subkeylength));00051 m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params);00052 m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params);00053 m_counter = 0;00054 m_subkeys.resize(0);00055 }00056 00057 <span class="keyword">template</span> <<span class="keyword">class</span> T>00058 <span class="keywordtype">void</span> DMAC_Base<T>::Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00059 {00060 m_mac1.Update(input, length);00061 m_counter = (m_counter + length) % T::BLOCKSIZE;00062 }00063 00064 <span class="keyword">template</span> <<span class="keyword">class</span> T>00065 <span class="keywordtype">void</span> DMAC_Base<T>::TruncatedFinal(byte *mac, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size)00066 {00067 ThrowIfInvalidTruncatedSize(size);00068 00069 byte pad[T::BLOCKSIZE];00070 byte padByte = byte(T::BLOCKSIZE-m_counter);00071 memset(pad, padByte, padByte);00072 m_mac1.Update(pad, padByte);00073 m_mac1.TruncatedFinal(mac, size);00074 m_f2.ProcessBlock(mac);00075 }00076 00077 <span class="keyword">template</span> <<span class="keyword">class</span> T>00078 byte *DMAC_Base<T>::GenerateSubKeys(<span class="keyword">const</span> byte *key, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keylength)00079 {00080 <span class="keyword">typename</span> T::Encryption cipher(key, keylength);00081 memset(m_subkeys, 0, m_subkeys.size());00082 cipher.ProcessBlock(m_subkeys);00083 m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1;00084 cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2);00085 <span class="keywordflow">return</span> m_subkeys;00086 }00087 00088 NAMESPACE_END00089 00090 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:12 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 + -