// emsa2.cpp - written and placed in the public domain by Wei Dai#include "pch.h"#include "emsa2.h"#ifndef CRYPTOPP_IMPORTSNAMESPACE_BEGIN(CryptoPP)voidEMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator&/*rng*/,constbyte*recoverableMessage,size_trecoverableMessageLength,HashTransformation&hash,HashIdentifierhashIdentifier,boolmessageEmpty,byte*representative,size_trepresentativeBitLength)const{CRYPTOPP_UNUSED(recoverableMessage),CRYPTOPP_UNUSED(recoverableMessageLength),CRYPTOPP_UNUSED(representativeBitLength);assert(representativeBitLength>=MinRepresentativeBitLength(hashIdentifier.second,hash.DigestSize()));if(representativeBitLength%8!=7)throwPK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");size_tdigestSize=hash.DigestSize();size_trepresentativeByteLength=BitsToBytes(representativeBitLength);representative[0]=messageEmpty?0x4b:0x6b;memset(representative+1,0xbb,representativeByteLength-digestSize-4);// pad with 0xbbbyte*afterP2=representative+representativeByteLength-digestSize-3;afterP2[0]=0xba;hash.Final(afterP2+1);representative[representativeByteLength-2]=*hashIdentifier.first;representative[representativeByteLength-1]=0xcc;}NAMESPACE_END#endif