aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-06-10 17:20:02 +0000
committerlloyd <[email protected]>2008-06-10 17:20:02 +0000
commitdec416d649715617e0eb66b18d69f6dbe9c308b3 (patch)
tree7ff26fe9cee0f11a15977106d985e78c01fb1e51 /src
parent2aef9fa5bc25984a838a51a93ac0e918d2d1bbac (diff)
Pass a RNG reference to the EMSA encoder functions
Diffstat (limited to 'src')
-rw-r--r--src/emsa1.cpp60
-rw-r--r--src/emsa2.cpp3
-rw-r--r--src/emsa3.cpp3
-rw-r--r--src/emsa4.cpp6
-rw-r--r--src/emsa_raw.cpp3
-rw-r--r--src/pk_util.cpp4
-rw-r--r--src/pubkey.cpp15
7 files changed, 60 insertions, 34 deletions
diff --git a/src/emsa1.cpp b/src/emsa1.cpp
index dd26342c2..8977356e8 100644
--- a/src/emsa1.cpp
+++ b/src/emsa1.cpp
@@ -8,30 +8,11 @@
namespace Botan {
-/*************************************************
-* EMSA1 Update Operation *
-*************************************************/
-void EMSA1::update(const byte input[], u32bit length)
- {
- hash->update(input, length);
- }
+namespace {
-/*************************************************
-* Return the raw (unencoded) data *
-*************************************************/
-SecureVector<byte> EMSA1::raw_data()
+SecureVector<byte> emsa1_encoding(const MemoryRegion<byte>& msg,
+ u32bit output_bits)
{
- return hash->final();
- }
-
-/*************************************************
-* EMSA1 Encode Operation *
-*************************************************/
-SecureVector<byte> EMSA1::encoding_of(const MemoryRegion<byte>& msg,
- u32bit output_bits)
- {
- if(msg.size() != hash->OUTPUT_LENGTH)
- throw Encoding_Error("EMSA1::encoding_of: Invalid size for input");
if(8*msg.size() <= output_bits)
return msg;
@@ -56,6 +37,36 @@ SecureVector<byte> EMSA1::encoding_of(const MemoryRegion<byte>& msg,
return digest;
}
+}
+
+/*************************************************
+* EMSA1 Update Operation *
+*************************************************/
+void EMSA1::update(const byte input[], u32bit length)
+ {
+ hash->update(input, length);
+ }
+
+/*************************************************
+* Return the raw (unencoded) data *
+*************************************************/
+SecureVector<byte> EMSA1::raw_data()
+ {
+ return hash->final();
+ }
+
+/*************************************************
+* EMSA1 Encode Operation *
+*************************************************/
+SecureVector<byte> EMSA1::encoding_of(const MemoryRegion<byte>& msg,
+ u32bit output_bits,
+ RandomNumberGenerator&)
+ {
+ if(msg.size() != hash->OUTPUT_LENGTH)
+ throw Encoding_Error("EMSA1::encoding_of: Invalid size for input");
+ return emsa1_encoding(msg, output_bits);
+ }
+
/*************************************************
* EMSA1 Decode/Verify Operation *
*************************************************/
@@ -63,7 +74,10 @@ bool EMSA1::verify(const MemoryRegion<byte>& coded,
const MemoryRegion<byte>& raw, u32bit key_bits) throw()
{
try {
- SecureVector<byte> our_coding = encoding_of(raw, key_bits);
+ if(raw.size() != hash->OUTPUT_LENGTH)
+ throw Encoding_Error("EMSA1::encoding_of: Invalid size for input");
+
+ SecureVector<byte> our_coding = emsa1_encoding(raw, key_bits);
if(our_coding == coded) return true;
if(our_coding[0] != 0) return false;
diff --git a/src/emsa2.cpp b/src/emsa2.cpp
index 052d9226a..f8d69737a 100644
--- a/src/emsa2.cpp
+++ b/src/emsa2.cpp
@@ -29,7 +29,8 @@ SecureVector<byte> EMSA2::raw_data()
* EMSA2 Encode Operation *
*************************************************/
SecureVector<byte> EMSA2::encoding_of(const MemoryRegion<byte>& msg,
- u32bit output_bits)
+ u32bit output_bits,
+ RandomNumberGenerator&)
{
u32bit output_length = (output_bits + 1) / 8;
diff --git a/src/emsa3.cpp b/src/emsa3.cpp
index 3c0aec50d..cf1aae3fa 100644
--- a/src/emsa3.cpp
+++ b/src/emsa3.cpp
@@ -29,7 +29,8 @@ SecureVector<byte> EMSA3::raw_data()
* EMSA3 Encode Operation *
*************************************************/
SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
- u32bit output_bits)
+ u32bit output_bits,
+ RandomNumberGenerator&)
{
if(msg.size() != hash->OUTPUT_LENGTH)
throw Encoding_Error("EMSA3::encoding_of: Bad input length");
diff --git a/src/emsa4.cpp b/src/emsa4.cpp
index 831afd590..6fb63fe0a 100644
--- a/src/emsa4.cpp
+++ b/src/emsa4.cpp
@@ -7,7 +7,6 @@
#include <botan/lookup.h>
#include <botan/look_pk.h>
#include <botan/bit_ops.h>
-#include <botan/libstate.h>
namespace Botan {
@@ -31,7 +30,8 @@ SecureVector<byte> EMSA4::raw_data()
* EMSA4 Encode Operation *
*************************************************/
SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
- u32bit output_bits)
+ u32bit output_bits,
+ RandomNumberGenerator& rng)
{
const u32bit HASH_SIZE = hash->OUTPUT_LENGTH;
@@ -43,7 +43,7 @@ SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
const u32bit output_length = (output_bits + 7) / 8;
SecureVector<byte> salt(SALT_SIZE);
- global_state().randomize(salt, SALT_SIZE);
+ rng.randomize(salt, SALT_SIZE);
for(u32bit j = 0; j != 8; ++j)
hash->update(0);
diff --git a/src/emsa_raw.cpp b/src/emsa_raw.cpp
index 7442a4f4f..b7ca16195 100644
--- a/src/emsa_raw.cpp
+++ b/src/emsa_raw.cpp
@@ -29,7 +29,8 @@ SecureVector<byte> EMSA_Raw::raw_data()
* EMSA-Raw Encode Operation *
*************************************************/
SecureVector<byte> EMSA_Raw::encoding_of(const MemoryRegion<byte>& msg,
- u32bit)
+ u32bit,
+ RandomNumberGenerator&)
{
return msg;
}
diff --git a/src/pk_util.cpp b/src/pk_util.cpp
index c5f7f8d67..24499ad83 100644
--- a/src/pk_util.cpp
+++ b/src/pk_util.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/pk_util.h>
+#include <botan/libstate.h>
namespace Botan {
@@ -53,7 +54,8 @@ bool EMSA::verify(const MemoryRegion<byte>& coded,
u32bit key_bits) throw()
{
try {
- return (coded == encoding_of(raw, key_bits));
+ return (coded == encoding_of(raw, key_bits,
+ global_state().prng_reference()));
}
catch(Invalid_Argument)
{
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index d151878c4..dc14c66b7 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -185,10 +185,13 @@ void PK_Signer::update(const MemoryRegion<byte>& in)
*************************************************/
SecureVector<byte> PK_Signer::signature()
{
+ RandomNumberGenerator& rng = global_state().prng_reference();
+
SecureVector<byte> encoded = emsa->encoding_of(emsa->raw_data(),
- key.max_input_bits());
- SecureVector<byte> plain_sig = key.sign(encoded, encoded.size(),
- global_state().prng_reference());
+ key.max_input_bits(),
+ rng);
+
+ SecureVector<byte> plain_sig = key.sign(encoded, encoded.size(), rng);
if(key.message_parts() == 1 || sig_format == IEEE_1363)
return plain_sig;
@@ -363,7 +366,11 @@ PK_Verifier_wo_MR::PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key& k,
bool PK_Verifier_wo_MR::validate_signature(const MemoryRegion<byte>& msg,
const byte sig[], u32bit sig_len)
{
- SecureVector<byte> encoded = emsa->encoding_of(msg, key.max_input_bits());
+ RandomNumberGenerator& rng = global_state().prng_reference();
+
+ SecureVector<byte> encoded =
+ emsa->encoding_of(msg, key.max_input_bits(), rng);
+
return key.verify(encoded, encoded.size(), sig, sig_len);
}