| 138 | } |
| 139 | |
| 140 | DecodingResult TF_DecryptorBase::Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const |
| 141 | { |
| 142 | if (ciphertextLength != FixedCiphertextLength()) |
| 143 | throw InvalidArgument(AlgorithmName() + ": ciphertext length of " + IntToString(ciphertextLength) + " doesn't match the required length of " + IntToString(FixedCiphertextLength()) + " for this key"); |
| 144 | |
| 145 | SecByteBlock paddedBlock(PaddedBlockByteLength()); |
| 146 | Integer x = GetTrapdoorFunctionInterface().CalculateInverse(rng, Integer(ciphertext, ciphertextLength)); |
| 147 | if (x.ByteCount() > paddedBlock.size()) |
| 148 | x = Integer::Zero(); // don't return false here to prevent timing attack |
| 149 | x.Encode(paddedBlock, paddedBlock.size()); |
| 150 | return GetMessageEncodingInterface().Unpad(paddedBlock, PaddedBlockBitLength(), plaintext, parameters); |
| 151 | } |
| 152 | |
| 153 | void TF_EncryptorBase::Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters) const |
| 154 | { |
no test coverage detected