00001
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& ,
00011 const byte* recoverableMessage, size_t recoverableMessageLength,
00012 HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
00013 byte *representative, size_t representativeBitLength) const
00014 {
00015 CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength), CRYPTOPP_UNUSED(representativeBitLength);
00016 assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
00017
00018 if (representativeBitLength % 8 != 7)
00019 throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
00020
00021 size_t digestSize = hash.DigestSize();
00022 size_t representativeByteLength = BitsToBytes(representativeBitLength);
00023
00024 representative[0] = messageEmpty ? 0x4b : 0x6b;
00025 memset(representative+1, 0xbb, representativeByteLength-digestSize-4);
00026 byte *afterP2 = representative+representativeByteLength-digestSize-3;
00027 afterP2[0] = 0xba;
00028 hash.Final(afterP2+1);
00029 representative[representativeByteLength-2] = *hashIdentifier.first;
00030 representative[representativeByteLength-1] = 0xcc;
00031 }
00032
00033 NAMESPACE_END
00034
00035 #endif