1
// emsa2.cpp - written and placed in the public domain by Wei Dai
6
#ifndef CRYPTOPP_IMPORTS
8
NAMESPACE_BEGIN(CryptoPP)
10
void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator &rng,
11
const byte *recoverableMessage, size_t recoverableMessageLength,
12
HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
13
byte *representative, size_t representativeBitLength) const
15
assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
17
if (representativeBitLength % 8 != 7)
18
throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
20
size_t digestSize = hash.DigestSize();
21
size_t representativeByteLength = BitsToBytes(representativeBitLength);
23
representative[0] = messageEmpty ? 0x4b : 0x6b;
24
memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb
25
byte *afterP2 = representative+representativeByteLength-digestSize-3;
27
hash.Final(afterP2+1);
28
representative[representativeByteLength-2] = *hashIdentifier.first;
29
representative[representativeByteLength-1] = 0xcc;