From 8af9520702f19e037458d3059ee0fafef2643875 Mon Sep 17 00:00:00 2001 From: weidai Date: Fri, 18 Jun 2010 01:18:22 +0000 Subject: [PATCH] check ciphertext length in TF_DecryptorBase::Decrypt() --- pubkey.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pubkey.cpp b/pubkey.cpp index 7336e8bc..1159e534 100644 --- a/pubkey.cpp +++ b/pubkey.cpp @@ -134,8 +134,11 @@ DecodingResult TF_VerifierBase::RecoverAndRestart(byte *recoveredMessage, PK_Mes DecodingResult TF_DecryptorBase::Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const { + if (ciphertextLength != FixedCiphertextLength()) + throw InvalidArgument(AlgorithmName() + ": ciphertext length of " + IntToString(ciphertextLength) + " doesn't match the required length of " + IntToString(FixedCiphertextLength()) + " for this key"); + SecByteBlock paddedBlock(PaddedBlockByteLength()); - Integer x = GetTrapdoorFunctionInterface().CalculateInverse(rng, Integer(ciphertext, FixedCiphertextLength())); + Integer x = GetTrapdoorFunctionInterface().CalculateInverse(rng, Integer(ciphertext, ciphertextLength)); if (x.ByteCount() > paddedBlock.size()) x = Integer::Zero(); // don't return false here to prevent timing attack x.Encode(paddedBlock, paddedBlock.size());