| 193 | // Private Decrypt |
| 194 | template<class Pad> |
| 195 | word32 RSA_Decryptor<Pad>::Decrypt(const byte* cipher, word32 sz, byte* plain, |
| 196 | RandomNumberGenerator& rng) |
| 197 | { |
| 198 | PK_Lengths lengths(key_.GetModulus()); |
| 199 | |
| 200 | if (sz != lengths.FixedCiphertextLength()) |
| 201 | return 0; |
| 202 | |
| 203 | ByteBlock paddedBlock(lengths.PaddedBlockByteLength()); |
| 204 | Integer x = key_.CalculateInverse(rng, Integer(cipher, |
| 205 | lengths.FixedCiphertextLength()).Ref()); |
| 206 | if (x.ByteCount() > paddedBlock.size()) |
| 207 | x = Integer::Zero(); // don't return false, prevents timing attack |
| 208 | x.Encode(paddedBlock.get_buffer(), paddedBlock.size()); |
| 209 | return padding_.UnPad(paddedBlock.get_buffer(), |
| 210 | lengths.PaddedBlockBitLength(), plain); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | // Private SSL type (block 1) Encrypt |