5 #ifndef CRYPTOPP_PKCSPAD_CPP
6 #define CRYPTOPP_PKCSPAD_CPP
17 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};
20 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};
23 template<>
const byte PKCS_DigestDecoration<RIPEMD160>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14};
26 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};
30 #ifndef CRYPTOPP_IS_DLL
31 template<>
const byte PKCS_DigestDecoration<SHA1>::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14};
34 template<>
const byte PKCS_DigestDecoration<SHA224>::decoration[] = {0x30,0x2d,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04,0x05,0x00,0x04,0x1c};
37 template<>
const byte PKCS_DigestDecoration<SHA256>::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20};
40 template<>
const byte PKCS_DigestDecoration<SHA384>::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30};
43 template<>
const byte PKCS_DigestDecoration<SHA512>::decoration[] = {0x30,0x51,0x30,0x0d, 0x06,0x09,0x60,0x86, 0x48,0x01,0x65,0x03, 0x04,0x02,0x03,0x05, 0x00,0x04,0x40};
48 template<>
const byte PKCS_DigestDecoration<SHA3_256>::decoration[] = {0x30,0x31,0x30,0x0d, 0x06,0x09,0x60,0x86, 0x48,0x01,0x65,0x03, 0x04,0x02,0x08,0x05, 0x00,0x04,0x20};
51 template<>
const byte PKCS_DigestDecoration<SHA3_384>::decoration[] = {0x30,0x41,0x30,0x0d, 0x06,0x09,0x60,0x86, 0x48,0x01,0x65,0x03, 0x04,0x02,0x09,0x05, 0x00,0x04,0x30};
54 template<>
const byte PKCS_DigestDecoration<SHA3_512>::decoration[] = {0x30,0x51,0x30,0x0d, 0x06,0x09,0x60,0x86, 0x48,0x01,0x65,0x03, 0x04,0x02,0x0a,0x05, 0x00,0x04,0x40};
63 void PKCS_EncryptionPaddingScheme::Pad(
RandomNumberGenerator& rng,
const byte *input,
size_t inputLen,
byte *pkcsBlock,
size_t pkcsBlockLen,
const NameValuePairs& parameters)
const
65 CRYPTOPP_UNUSED(parameters);
69 if (pkcsBlockLen % 8 != 0)
79 for (
unsigned i = 1; i < pkcsBlockLen-inputLen-1; i++)
82 pkcsBlock[pkcsBlockLen-inputLen-1] = 0;
83 std::memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen);
86 DecodingResult PKCS_EncryptionPaddingScheme::Unpad(
const byte *pkcsBlock,
size_t pkcsBlockLen,
byte *output,
const NameValuePairs& parameters)
const
88 CRYPTOPP_UNUSED(parameters);
93 if (pkcsBlockLen % 8 != 0)
95 invalid = (pkcsBlock[0] != 0) || invalid;
101 invalid = (pkcsBlock[0] != 2) || invalid;
105 size_t separatorIndex = 0;
106 size_t foundSeparator = 0;
108 for (
size_t j = 1; j < pkcsBlockLen; j++)
111 size_t isZero = (pkcsBlock[j] == 0) ? 1 : 0;
112 size_t notFoundYet = 1 - foundSeparator;
116 size_t mask = -(isZero & notFoundYet);
117 separatorIndex = (separatorIndex & ~mask) | (j & mask);
120 foundSeparator |= isZero;
124 size_t i = separatorIndex + 1;
127 size_t outputLen = pkcsBlockLen - i;
128 invalid = (outputLen > maxOutputLen) || invalid;
129 invalid = (foundSeparator == 0) || invalid;
133 std::memcpy (output, pkcsBlock+i, outputLen);
141 #ifndef CRYPTOPP_IMPORTS
143 void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(
RandomNumberGenerator &rng,
144 const byte *recoverableMessage,
size_t recoverableMessageLength,
146 byte *representative,
size_t representativeBitLength)
const
148 CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
149 CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
152 size_t pkcsBlockLen = representativeBitLength;
154 if (pkcsBlockLen % 8 != 0)
156 representative[0] = 0;
161 representative[0] = 1;
164 byte *pPadding = representative + 1;
165 byte *pDigest = representative + pkcsBlockLen - digestSize;
166 byte *pHashId = pDigest - hashIdentifier.second;
167 byte *pSeparator = pHashId - 1;
170 std::memset(pPadding, 0xff, pSeparator-pPadding);
172 std::memcpy(pHashId, hashIdentifier.first, hashIdentifier.second);
Interface for retrieving values given their names.
PKCS #1 decoration data structure.
size_t MaxUnpaddedLength(size_t paddedLength) const
max size of unpadded message in bytes, given max size of padded message in bits (1 less than size of ...
Interface for random number generators.
virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL)
Generate a random 32 bit word in the range min to max, inclusive.
Classes and functions for various padding schemes used in public key algorithms.
Forward declarations for hash functions used in signature encoding methods.
Utility functions for the Crypto++ library.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
Crypto++ library namespace.
Classes for PKCS padding schemes.
Returns a decoding results.
Debugging and diagnostic assertions.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.