5 #ifndef CRYPTOPP_PKCSPAD_CPP // SunCC workaround: compiler could cause this file to be included twice
6 #define CRYPTOPP_PKCSPAD_CPP
11 NAMESPACE_BEGIN(CryptoPP)
14 template<> const byte
PKCS_DigestDecoration<Weak1::MD2>::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x02,0x05,0x00,0x04,0x10};
17 template<>
const byte
PKCS_DigestDecoration<Weak1::MD5>::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x04,0x10};
20 template<>
const byte
PKCS_DigestDecoration<RIPEMD160>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14};
23 template<>
const byte
PKCS_DigestDecoration<Tiger>::decoration[] = {0x30,0x29,0x30,0x0D,0x06,0x09,0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0C,0x02,0x05,0x00,0x04,0x18};
28 return SaturatingSubtract(paddedLength/8, 10U);
31 void PKCS_EncryptionPaddingScheme::Pad(
RandomNumberGenerator &rng,
const byte *input,
size_t inputLen, byte *pkcsBlock,
size_t pkcsBlockLen,
const NameValuePairs ¶meters)
const
36 if (pkcsBlockLen % 8 != 0)
46 for (
unsigned i = 1; i < pkcsBlockLen-inputLen-1; i++)
49 pkcsBlock[pkcsBlockLen-inputLen-1] = 0;
50 memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen);
53 DecodingResult PKCS_EncryptionPaddingScheme::Unpad(
const byte *pkcsBlock,
size_t pkcsBlockLen, byte *output,
const NameValuePairs ¶meters)
const
59 if (pkcsBlockLen % 8 != 0)
61 invalid = (pkcsBlock[0] != 0) || invalid;
67 invalid = (pkcsBlock[0] != 2) || invalid;
71 while (i<pkcsBlockLen && pkcsBlock[i++]) {
73 assert(i==pkcsBlockLen || pkcsBlock[i-1]==0);
75 size_t outputLen = pkcsBlockLen - i;
76 invalid = (outputLen > maxOutputLen) || invalid;
81 memcpy (output, pkcsBlock+i, outputLen);
87 #ifndef CRYPTOPP_IMPORTS
89 void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(
RandomNumberGenerator &rng,
90 const byte *recoverableMessage,
size_t recoverableMessageLength,
92 byte *representative,
size_t representativeBitLength)
const
94 assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.
DigestSize()));
96 size_t pkcsBlockLen = representativeBitLength;
98 if (pkcsBlockLen % 8 != 0)
100 representative[0] = 0;
105 representative[0] = 1;
108 byte *pPadding = representative + 1;
109 byte *pDigest = representative + pkcsBlockLen - digestSize;
110 byte *pHashId = pDigest - hashIdentifier.second;
111 byte *pSeparator = pHashId - 1;
114 memset(pPadding, 0xff, pSeparator-pPadding);
116 memcpy(pHashId, hashIdentifier.first, hashIdentifier.second);