aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-05-24 19:56:35 +0000
committerlloyd <[email protected]>2008-05-24 19:56:35 +0000
commit7d9843775ec5d28c15d1070223185575cebe46ec (patch)
tree04d7053b50c57efc7654bcb082d7850bc1187926
parent8283202b8bfd5fe088f87a91a3158bef0072311f (diff)
Pass an RNG reference to EME::pad
PK_Encryptor_MR_with_EME::enc references the global PRNG currently
-rw-r--r--include/eme.h7
-rw-r--r--include/pk_util.h12
-rw-r--r--src/eme1.cpp7
-rw-r--r--src/eme_pkcs.cpp3
-rw-r--r--src/pk_util.cpp10
-rw-r--r--src/pubkey.cpp9
6 files changed, 32 insertions, 16 deletions
diff --git a/include/eme.h b/include/eme.h
index 738ed5e1e..42eecea4e 100644
--- a/include/eme.h
+++ b/include/eme.h
@@ -21,8 +21,10 @@ class BOTAN_DLL EME1 : public EME
EME1(const std::string&, const std::string&, const std::string& = "");
~EME1() { delete mgf; }
private:
- SecureVector<byte> pad(const byte[], u32bit, u32bit) const;
+ SecureVector<byte> pad(const byte[], u32bit, u32bit,
+ RandomNumberGenerator&) const;
SecureVector<byte> unpad(const byte[], u32bit, u32bit) const;
+
const u32bit HASH_LENGTH;
SecureVector<byte> Phash;
MGF* mgf;
@@ -36,7 +38,8 @@ class BOTAN_DLL EME_PKCS1v15 : public EME
public:
u32bit maximum_input_size(u32bit) const;
private:
- SecureVector<byte> pad(const byte[], u32bit, u32bit) const;
+ SecureVector<byte> pad(const byte[], u32bit, u32bit,
+ RandomNumberGenerator&) const;
SecureVector<byte> unpad(const byte[], u32bit, u32bit) const;
};
diff --git a/include/pk_util.h b/include/pk_util.h
index 5888b6ac0..1803a59a2 100644
--- a/include/pk_util.h
+++ b/include/pk_util.h
@@ -17,14 +17,20 @@ class BOTAN_DLL EME
{
public:
virtual u32bit maximum_input_size(u32bit) const = 0;
- SecureVector<byte> encode(const byte[], u32bit, u32bit) const;
- SecureVector<byte> encode(const MemoryRegion<byte>&, u32bit) const;
+
+ SecureVector<byte> encode(const byte[], u32bit, u32bit,
+ RandomNumberGenerator&) const;
+ SecureVector<byte> encode(const MemoryRegion<byte>&, u32bit,
+ RandomNumberGenerator&) const;
+
SecureVector<byte> decode(const byte[], u32bit, u32bit) const;
SecureVector<byte> decode(const MemoryRegion<byte>&, u32bit) const;
virtual ~EME() {}
private:
- virtual SecureVector<byte> pad(const byte[], u32bit, u32bit) const = 0;
+ virtual SecureVector<byte> pad(const byte[], u32bit, u32bit,
+ RandomNumberGenerator&) const = 0;
+
virtual SecureVector<byte> unpad(const byte[], u32bit, u32bit) const = 0;
};
diff --git a/src/eme1.cpp b/src/eme1.cpp
index 43b5a0027..ca96e29e0 100644
--- a/src/eme1.cpp
+++ b/src/eme1.cpp
@@ -4,9 +4,7 @@
*************************************************/
#include <botan/eme.h>
-#include <botan/libstate.h>
#include <botan/lookup.h>
-#include <botan/look_pk.h>
#include <memory>
namespace Botan {
@@ -15,7 +13,8 @@ namespace Botan {
* EME1 Pad Operation *
*************************************************/
SecureVector<byte> EME1::pad(const byte in[], u32bit in_length,
- u32bit key_length) const
+ u32bit key_length,
+ RandomNumberGenerator& rng) const
{
key_length /= 8;
@@ -26,7 +25,7 @@ SecureVector<byte> EME1::pad(const byte in[], u32bit in_length,
out.clear();
- global_state().randomize(out, HASH_LENGTH);
+ rng.randomize(out, HASH_LENGTH);
out.copy(HASH_LENGTH, Phash, Phash.size());
out[out.size() - in_length - 1] = 0x01;
diff --git a/src/eme_pkcs.cpp b/src/eme_pkcs.cpp
index 8296681d8..e6c9ae2d2 100644
--- a/src/eme_pkcs.cpp
+++ b/src/eme_pkcs.cpp
@@ -12,7 +12,8 @@ namespace Botan {
* PKCS1 Pad Operation *
*************************************************/
SecureVector<byte> EME_PKCS1v15::pad(const byte in[], u32bit inlen,
- u32bit olen) const
+ u32bit olen,
+ RandomNumberGenerator&) const
{
olen /= 8;
diff --git a/src/pk_util.cpp b/src/pk_util.cpp
index 86f3578ab..c5f7f8d67 100644
--- a/src/pk_util.cpp
+++ b/src/pk_util.cpp
@@ -11,18 +11,20 @@ namespace Botan {
* Encode a message *
*************************************************/
SecureVector<byte> EME::encode(const byte msg[], u32bit msg_len,
- u32bit key_bits) const
+ u32bit key_bits,
+ RandomNumberGenerator& rng) const
{
- return pad(msg, msg_len, key_bits);
+ return pad(msg, msg_len, key_bits, rng);
}
/*************************************************
* Encode a message *
*************************************************/
SecureVector<byte> EME::encode(const MemoryRegion<byte>& msg,
- u32bit key_bits) const
+ u32bit key_bits,
+ RandomNumberGenerator& rng) const
{
- return pad(msg, msg.size(), key_bits);
+ return pad(msg, msg.size(), key_bits, rng);
}
/*************************************************
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index afc38dc8a..0a4162711 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -10,6 +10,7 @@
#include <botan/bigint.h>
#include <botan/parsing.h>
#include <botan/bit_ops.h>
+#include <botan/libstate.h>
#include <memory>
namespace Botan {
@@ -62,8 +63,12 @@ SecureVector<byte> PK_Encryptor_MR_with_EME::enc(const byte msg[],
u32bit length) const
{
SecureVector<byte> message;
- if(encoder) message = encoder->encode(msg, length, key.max_input_bits());
- else message.set(msg, length);
+ if(encoder)
+ message = encoder->encode(msg, length,
+ key.max_input_bits(),
+ global_state().prng_reference());
+ else
+ message.set(msg, length);
if(8*(message.size() - 1) + high_bit(message[0]) > key.max_input_bits())
throw Exception("PK_Encryptor_MR_with_EME: Input is too large");