Crypto++
|
00001 // emsa2.cpp - written and placed in the public domain by Wei Dai 00002 00003 #include "pch.h" 00004 #include "emsa2.h" 00005 00006 #ifndef CRYPTOPP_IMPORTS 00007 00008 NAMESPACE_BEGIN(CryptoPP) 00009 00010 void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator &rng, 00011 const byte *recoverableMessage, size_t recoverableMessageLength, 00012 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, 00013 byte *representative, size_t representativeBitLength) const 00014 { 00015 assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); 00016 00017 if (representativeBitLength % 8 != 7) 00018 throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8"); 00019 00020 size_t digestSize = hash.DigestSize(); 00021 size_t representativeByteLength = BitsToBytes(representativeBitLength); 00022 00023 representative[0] = messageEmpty ? 0x4b : 0x6b; 00024 memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb 00025 byte *afterP2 = representative+representativeByteLength-digestSize-3; 00026 afterP2[0] = 0xba; 00027 hash.Final(afterP2+1); 00028 representative[representativeByteLength-2] = *hashIdentifier.first; 00029 representative[representativeByteLength-1] = 0xcc; 00030 } 00031 00032 NAMESPACE_END 00033 00034 #endif