summaryrefslogtreecommitdiff
path: root/pubkey.cpp
diff options
context:
space:
mode:
authorweidai <weidai11@users.noreply.github.com>2010-06-18 01:18:22 +0000
committerweidai <weidai11@users.noreply.github.com>2010-06-18 01:18:22 +0000
commit8af9520702f19e037458d3059ee0fafef2643875 (patch)
tree8011b0f0ccb51f655eb7ef93a34d39ecf8747370 /pubkey.cpp
parent0980f652669124cce6b5840380ebe9a4ffaea39f (diff)
downloadcryptopp-git-8af9520702f19e037458d3059ee0fafef2643875.tar.gz
check ciphertext length in TF_DecryptorBase::Decrypt()
Diffstat (limited to 'pubkey.cpp')
-rw-r--r--pubkey.cpp5
1 files changed, 4 insertions, 1 deletions
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 &parameters) 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());