aboutsummaryrefslogtreecommitdiffstats
path: root/src/emsa1.cpp
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/emsa1.cpp
parent2aef9fa5bc25984a838a51a93ac0e918d2d1bbac (diff)
Pass a RNG reference to the EMSA encoder functions
Diffstat (limited to 'src/emsa1.cpp')
-rw-r--r--src/emsa1.cpp60
1 files changed, 37 insertions, 23 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;