From d8ed44353006ccb44b3f15c833241640711619a6 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() --- trunk/c5/pubkey.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trunk/c5/pubkey.cpp b/trunk/c5/pubkey.cpp index 7336e8bc..1159e534 100644 --- a/trunk/c5/pubkey.cpp +++ b/trunk/c5/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());