From 66b163323d39ac5c0be30fd0b1c0fd91b64a55f3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 29 Oct 2010 15:15:30 +0000 Subject: Make MemoryRegion::set protected, change all callers --- src/pubkey/pubkey.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/pubkey/pubkey.cpp') 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 -PK_Encryptor_EME::enc(const byte msg[], +PK_Encryptor_EME::enc(const byte in[], size_t length, RandomNumberGenerator& rng) const { - SecureVector message; if(eme) - message = eme->encode(msg, length, op->max_input_bits(), rng); - else - message.set(msg, length); + { + SecureVector 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); + } } /* -- cgit v1.2.3