diff options
author | lloyd <[email protected]> | 2010-10-29 15:15:30 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-29 15:15:30 +0000 |
commit | 66b163323d39ac5c0be30fd0b1c0fd91b64a55f3 (patch) | |
tree | e745b4824105f600ec5452e591a112229bc01478 /src/pubkey/pubkey.cpp | |
parent | 89a2e78d2ff2f0266825708a0294b13a4c370a29 (diff) |
Make MemoryRegion::set protected, change all callers
Diffstat (limited to 'src/pubkey/pubkey.cpp')
-rw-r--r-- | src/pubkey/pubkey.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp index a5ec60df3..6e63f9fc9 100644 --- a/src/pubkey/pubkey.cpp +++ b/src/pubkey/pubkey.cpp @@ -45,20 +45,27 @@ PK_Encryptor_EME::PK_Encryptor_EME(const Public_Key& key, * Encrypt a message */ SecureVector<byte> -PK_Encryptor_EME::enc(const byte msg[], +PK_Encryptor_EME::enc(const byte in[], size_t length, RandomNumberGenerator& rng) const { - SecureVector<byte> message; if(eme) - message = eme->encode(msg, length, op->max_input_bits(), rng); - else - message.set(msg, length); + { + SecureVector<byte> encoded = + eme->encode(in, length, op->max_input_bits(), rng); + + if(8*(encoded.size() - 1) + high_bit(encoded[0]) > op->max_input_bits()) + throw Invalid_Argument("PK_Encryptor_EME: Input is too large"); - if(8*(message.size() - 1) + high_bit(message[0]) > op->max_input_bits()) - throw Invalid_Argument("PK_Encryptor_EME: Input is too large"); + return op->encrypt(&encoded[0], encoded.size(), rng); + } + else + { + if(8*(length - 1) + high_bit(in[0]) > op->max_input_bits()) + throw Invalid_Argument("PK_Encryptor_EME: Input is too large"); - return op->encrypt(&message[0], message.size(), rng); + return op->encrypt(&in[0], length, rng); + } } /* |