From dec416d649715617e0eb66b18d69f6dbe9c308b3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 10 Jun 2008 17:20:02 +0000 Subject: Pass a RNG reference to the EMSA encoder functions --- src/emsa1.cpp | 60 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'src/emsa1.cpp') 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 EMSA1::raw_data() +SecureVector emsa1_encoding(const MemoryRegion& msg, + u32bit output_bits) { - return hash->final(); - } - -/************************************************* -* EMSA1 Encode Operation * -*************************************************/ -SecureVector EMSA1::encoding_of(const MemoryRegion& 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 EMSA1::encoding_of(const MemoryRegion& msg, return digest; } +} + +/************************************************* +* EMSA1 Update Operation * +*************************************************/ +void EMSA1::update(const byte input[], u32bit length) + { + hash->update(input, length); + } + +/************************************************* +* Return the raw (unencoded) data * +*************************************************/ +SecureVector EMSA1::raw_data() + { + return hash->final(); + } + +/************************************************* +* EMSA1 Encode Operation * +*************************************************/ +SecureVector EMSA1::encoding_of(const MemoryRegion& 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& coded, const MemoryRegion& raw, u32bit key_bits) throw() { try { - SecureVector our_coding = encoding_of(raw, key_bits); + if(raw.size() != hash->OUTPUT_LENGTH) + throw Encoding_Error("EMSA1::encoding_of: Invalid size for input"); + + SecureVector our_coding = emsa1_encoding(raw, key_bits); if(our_coding == coded) return true; if(our_coding[0] != 0) return false; -- cgit v1.2.3