<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Crypto++: emsa2.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Crypto++</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">emsa2.cpp</div> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// emsa2.cpp - written and placed in the public domain by Wei Dai</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="emsa2_8h.html" title="This file contains various padding schemes for public key algorithms.">emsa2.h</a>"</span> <a name="l00005"></a>00005 <a name="l00006"></a>00006 <span class="preprocessor">#ifndef CRYPTOPP_IMPORTS</span> <a name="l00007"></a>00007 <span class="preprocessor"></span> <a name="l00008"></a>00008 NAMESPACE_BEGIN(CryptoPP) <a name="l00009"></a>00009 <a name="l00010"></a>00010 void <a class="code" href="class_e_m_s_a2_pad.html" title="_">EMSA2Pad</a>::ComputeMessageRepresentative(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <a name="l00011"></a>00011 const byte *recoverableMessage, <span class="keywordtype">size_t</span> recoverableMessageLength, <a name="l00012"></a>00012 <a class="code" href="class_hash_transformation.html" title="interface for hash functions and data processing part of MACs">HashTransformation</a> &hash, HashIdentifier hashIdentifier, <span class="keywordtype">bool</span> messageEmpty, <a name="l00013"></a>00013 byte *representative, <span class="keywordtype">size_t</span> representativeBitLength)<span class="keyword"> const</span> <a name="l00014"></a>00014 <span class="keyword"></span>{ <a name="l00015"></a>00015 assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="keywordflow">if</span> (representativeBitLength % 8 != 7) <a name="l00018"></a>00018 <span class="keywordflow">throw</span> <a class="code" href="class_p_k___signature_scheme_1_1_invalid_key_length.html" title="invalid key exception, may be thrown by any function in this class if the private or public key has a...">PK_SignatureScheme::InvalidKeyLength</a>(<span class="stringliteral">"EMSA2: EMSA2 requires a key length that is a multiple of 8"</span>); <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="keywordtype">size_t</span> digestSize = hash.DigestSize(); <a name="l00021"></a>00021 <span class="keywordtype">size_t</span> representativeByteLength = BitsToBytes(representativeBitLength); <a name="l00022"></a>00022 <a name="l00023"></a>00023 representative[0] = messageEmpty ? 0x4b : 0x6b; <a name="l00024"></a>00024 memset(representative+1, 0xbb, representativeByteLength-digestSize-4); <span class="comment">// pad with 0xbb</span> <a name="l00025"></a>00025 byte *afterP2 = representative+representativeByteLength-digestSize-3; <a name="l00026"></a>00026 afterP2[0] = 0xba; <a name="l00027"></a>00027 hash.Final(afterP2+1); <a name="l00028"></a>00028 representative[representativeByteLength-2] = *hashIdentifier.first; <a name="l00029"></a>00029 representative[representativeByteLength-1] = 0xcc; <a name="l00030"></a>00030 } <a name="l00031"></a>00031 <a name="l00032"></a>00032 NAMESPACE_END <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="preprocessor">#endif</span> </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Sun Oct 16 2011 for Crypto++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>