16 #ifndef CRYPTOPP_IMPORTS 20 size_t saltLen =
SaltLen(digestLength);
21 size_t minPadLen =
MinPadLen(digestLength);
22 return 9 + 8*(minPadLen + saltLen + digestLength + hashIdentifierLength);
48 const byte *recoverableMessage,
size_t recoverableMessageLength,
50 byte *representative,
size_t representativeBitLength)
const 56 const size_t u = hashIdentifier.second + 1;
57 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
59 const size_t saltSize =
SaltLen(digestSize);
60 byte *
const h = representative + representativeByteLength - u - digestSize;
71 hash.
Update(recoverableMessage, recoverableMessageLength);
72 hash.
Update(digest, digestSize);
73 hash.
Update(salt, saltSize);
77 GetMGF().
GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize,
false);
78 byte *xorStart = representative + representativeByteLength - u - digestSize - salt.
size() - recoverableMessageLength - 1;
80 if (recoverableMessage && recoverableMessageLength)
81 xorbuf(xorStart + 1, recoverableMessage, recoverableMessageLength);
82 xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.
size());
83 if (hashIdentifier.first && hashIdentifier.second)
85 memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second);
86 representative[representativeByteLength - 1] = 0xcc;
90 representative[representativeByteLength - 1] = 0xbc;
92 if (representativeBitLength % 8 != 0)
93 representative[0] = (
byte)
Crop(representative[0], representativeBitLength % 8);
98 byte *representative,
size_t representativeBitLength,
99 byte *recoverableMessage)
const 104 const size_t u = hashIdentifier.second + 1;
105 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
107 const size_t saltSize =
SaltLen(digestSize);
108 const byte *
const h = representative + representativeByteLength - u - digestSize;
117 valid = (representative[representativeByteLength - 1] == (hashIdentifier.second ? 0xcc : 0xbc)) && valid;
119 if (hashIdentifier.first && hashIdentifier.second)
120 valid =
VerifyBufsEqual(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) && valid;
122 GetMGF().
GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize);
123 if (representativeBitLength % 8 != 0)
124 representative[0] = (
byte)
Crop(representative[0], representativeBitLength % 8);
127 byte *salt = representative + representativeByteLength - u - digestSize - saltSize;
128 byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to<byte>(),
byte(0)));
129 recoverableMessageLength = salt-M-1;
131 (
size_t)(M - representative - (representativeBitLength % 8 != 0)) >=
MinPadLen(digestSize) &&
132 recoverableMessageLength <=
MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize))
134 if (recoverableMessage)
135 memcpy(recoverableMessage, M+1, recoverableMessageLength);
139 recoverableMessageLength = 0;
148 hash.
Update(recoverableMessage, recoverableMessageLength);
149 hash.
Update(digest, digestSize);
150 hash.
Update(salt, saltSize);
151 valid = hash.
Verify(h) && valid;
153 if (!
AllowRecovery() && valid && recoverableMessageLength != 0)
Utility functions for the Crypto++ library.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULL)
Access a block of memory.
#define NAMESPACE_BEGIN(x)
RIPEMD-160 message digest.
size_type size() const
Provides the count of elements in the SecBlock.
Interface for random number generators.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
virtual bool AllowRecovery() const =0
virtual size_t MinPadLen(size_t hashLen) const =0
bool AllowNonrecoverablePart() const
Returns a decoding results.
bool IsProbabilistic() const
virtual void GenerateAndMask(HashTransformation &hash, byte *output, size_t outputLength, const byte *input, size_t inputLength, bool mask=true) const =0
Generate and apply mask.
A method was called which was not implemented.
T Crop(T value, size_t bits)
Truncates the value to the specified number of bits.
bool RecoverablePartFirst() const
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
size_t MinRepresentativeBitLength(size_t hashIdentifierLength, size_t digestLength) const
size_t MaxRecoverableLength(size_t representativeBitLength, size_t hashIdentifierLength, size_t digestLength) const
Safely right shift values when undefined behavior could occur.
#define CRYPTOPP_ASSERT(exp)
void xorbuf(byte *buf, const byte *mask, size_t count)
Performs an XOR of a buffer with a mask.
virtual size_t SaltLen(size_t hashLen) const =0
void ComputeMessageRepresentative(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, byte *representative, size_t representativeBitLength) const
void * memcpy(void *a, const void *b, size_t c)
#define CRYPTOPP_UNUSED(x)
bool isValidCoding
Flag to indicate the decoding is valid.
virtual const MaskGeneratingFunction & GetMGF() const =0
DecodingResult RecoverMessageFromRepresentative(HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, byte *representative, size_t representativeBitLength, byte *recoverableMessage) const
std::pair< const byte *, unsigned int > HashIdentifier
RIPEMD-128 message digest.
Classes for probablistic signature schemes.
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
Performs a near constant-time comparison of two equally sized buffers.