6 #ifndef CRYPTOPP_IMPORTS
14 void P1363_MGF1KDF2_Common(
HashTransformation &hash,
byte *output,
size_t outputLength,
const byte *input,
size_t inputLength,
const byte *derivationParams,
size_t derivationParamsLength,
bool mask,
unsigned int counterStart)
18 word32 counter = counterStart;
21 filter.Put(input, inputLength);
22 filter.PutWord32(counter++);
23 filter.Put(derivationParams, derivationParamsLength);
28 bool PK_DeterministicSignatureMessageEncodingMethod::VerifyMessageRepresentative(
30 byte *representative,
size_t representativeBitLength)
const
33 ComputeMessageRepresentative(
NullRNG(), NULLPTR, 0, hash, hashIdentifier, messageEmpty, computedRepresentative, representativeBitLength);
34 return VerifyBufsEqual(representative, computedRepresentative, computedRepresentative.size());
37 bool PK_RecoverableSignatureMessageEncodingMethod::VerifyMessageRepresentative(
39 byte *representative,
size_t representativeBitLength)
const
41 SecByteBlock recoveredMessage(MaxRecoverableLength(representativeBitLength, hashIdentifier.second, hash.
DigestSize()));
43 hash, hashIdentifier, messageEmpty, representative, representativeBitLength, recoveredMessage);
50 HashIdentifier
id = GetHashIdentifier();
51 const MessageEncodingInterface &encoding = GetMessageEncodingInterface();
53 if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(
id.second, ma.AccessHash().
DigestSize()))
56 size_t maxRecoverableLength = encoding.MaxRecoverableLength(MessageRepresentativeBitLength(), GetHashIdentifier().second, ma.AccessHash().
DigestSize());
58 if (maxRecoverableLength == 0)
59 {
throw NotImplemented(
"TF_SignerBase: this algorithm does not support message recovery or the key is too short");}
60 if (recoverableMessageLength > maxRecoverableLength)
61 throw InvalidArgument(
"TF_SignerBase: the recoverable message part is too long for the given key and algorithm");
63 ma.m_recoverableMessage.
Assign(recoverableMessage, recoverableMessageLength);
64 encoding.ProcessRecoverableMessage(
66 recoverableMessage, recoverableMessageLength,
67 NULLPTR, 0, ma.m_semisignature);
72 CRYPTOPP_UNUSED(restart);
75 HashIdentifier
id = GetHashIdentifier();
76 const MessageEncodingInterface &encoding = GetMessageEncodingInterface();
78 if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(
id.second, ma.AccessHash().
DigestSize()))
81 SecByteBlock representative(MessageRepresentativeLength());
82 encoding.ComputeMessageRepresentative(rng,
83 ma.m_recoverableMessage, ma.m_recoverableMessage.
size(),
84 ma.AccessHash(),
id, ma.m_empty,
85 representative, MessageRepresentativeBitLength());
88 Integer r(representative, representative.size());
89 size_t signatureLength = SignatureLength();
90 GetTrapdoorFunctionInterface().CalculateRandomizedInverse(rng, r).Encode(signature, signatureLength);
91 return signatureLength;
97 HashIdentifier
id = GetHashIdentifier();
98 const MessageEncodingInterface &encoding = GetMessageEncodingInterface();
100 if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(
id.second, ma.AccessHash().
DigestSize()))
103 ma.m_representative.
New(MessageRepresentativeLength());
104 Integer x = GetTrapdoorFunctionInterface().ApplyFunction(
Integer(signature, signatureLength));
105 if (x.BitCount() > MessageRepresentativeBitLength())
107 x.Encode(ma.m_representative, ma.m_representative.
size());
113 HashIdentifier
id = GetHashIdentifier();
114 const MessageEncodingInterface &encoding = GetMessageEncodingInterface();
116 if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(
id.second, ma.AccessHash().
DigestSize()))
119 bool result = encoding.VerifyMessageRepresentative(
120 ma.AccessHash(),
id, ma.m_empty, ma.m_representative, MessageRepresentativeBitLength());
128 HashIdentifier
id = GetHashIdentifier();
129 const MessageEncodingInterface &encoding = GetMessageEncodingInterface();
131 if (MessageRepresentativeBitLength() < encoding.MinRepresentativeBitLength(
id.second, ma.AccessHash().
DigestSize()))
134 DecodingResult result = encoding.RecoverMessageFromRepresentative(
135 ma.AccessHash(),
id, ma.m_empty, ma.m_representative, MessageRepresentativeBitLength(), recoveredMessage);
142 if (ciphertextLength != FixedCiphertextLength())
146 Integer x = GetTrapdoorFunctionInterface().CalculateInverse(rng,
Integer(ciphertext, ciphertextLength));
147 if (x.ByteCount() > paddedBlock.size())
149 x.Encode(paddedBlock, paddedBlock.size());
150 return GetMessageEncodingInterface().Unpad(paddedBlock, PaddedBlockBitLength(), plaintext, parameters);
155 if (plaintextLength > FixedMaxPlaintextLength())
157 if (FixedMaxPlaintextLength() < 1)
164 GetMessageEncodingInterface().Pad(rng, plaintext, plaintextLength, paddedBlock, PaddedBlockBitLength(), parameters);
165 GetTrapdoorFunctionInterface().ApplyRandomizedFunction(rng,
Integer(paddedBlock, paddedBlock.size())).Encode(ciphertext, FixedCiphertextLength());