5#ifndef CRYPTOPP_IMPORTS
11NAMESPACE_BEGIN(CryptoPP)
15size_t
OAEP_Base::MaxUnpaddedLength(
size_t paddedLength)
const
25 if (oaepBlockLen % 8 != 0)
33 const size_t hLen = pHash->DigestSize();
34 const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen;
35 byte *
const maskedSeed = oaepBlock;
36 byte *
const maskedDB = oaepBlock+seedLen;
39 parameters.
GetValue(Name::EncodingParameters(), encodingParameters);
42 pHash->CalculateDigest(maskedDB, encodingParameters.
begin(), encodingParameters.
size());
43 memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1);
44 maskedDB[dbLen-inputLength-1] = 0x01;
45 memcpy(maskedDB+dbLen-inputLength, input, inputLength);
49 pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen);
50 pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen);
58 if (oaepBlockLen % 8 != 0)
60 invalid = (oaepBlock[0] != 0) || invalid;
66 const size_t hLen = pHash->DigestSize();
67 const size_t seedLen = hLen, dbLen = oaepBlockLen-seedLen;
69 invalid = (oaepBlockLen < 2*hLen+1) || invalid;
72 byte *
const maskedSeed = t;
73 byte *
const maskedDB = t+seedLen;
76 pMGF->GenerateAndMask(*pHash, maskedSeed, seedLen, maskedDB, dbLen);
77 pMGF->GenerateAndMask(*pHash, maskedDB, dbLen, maskedSeed, seedLen);
80 parameters.
GetValue(Name::EncodingParameters(), encodingParameters);
83 byte *M = std::find(maskedDB+hLen, maskedDB+dbLen, 0x01);
84 invalid = (M == maskedDB+dbLen) || invalid;
85 invalid = (
FindIfNot(maskedDB+hLen, M,
byte(0)) != M) || invalid;
86 invalid = !pHash->VerifyDigest(maskedDB, encodingParameters.
begin(), encodingParameters.
size()) || invalid;
92 memcpy(output, M, maskedDB+dbLen-M);
Used to pass byte array input as part of a NameValuePairs object.
const byte * begin() const
Pointer to the first byte in the memory block.
size_t size() const
Length of the memory block.
Interface for retrieving values given their names.
bool GetValue(const char *name, T &value) const
Get a named value.
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 void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Pointer that overloads operator ->
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
InputIt FindIfNot(InputIt first, InputIt last, const T &value)
Finds first element not in a range.
Classes for optimal asymmetric encryption padding.
Classes for automatic resource management.
Returns a decoding results.