aboutsummaryrefslogtreecommitdiffstats
path: root/src/emsa3.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-06-27 15:37:29 +0000
committerlloyd <[email protected]>2008-06-27 15:37:29 +0000
commit9d77dd59ab4a7d122a20b0d89ae081a177f38287 (patch)
tree9a6c0bbda944a7494932cef883d348d1f16f804e /src/emsa3.cpp
parent59865d69871bdd936cf77a7fde38aa7657d04c40 (diff)
Reorganize the EMSA classes, and remove the last references to prng_reference
in the library ccode.
Diffstat (limited to 'src/emsa3.cpp')
-rw-r--r--src/emsa3.cpp66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/emsa3.cpp b/src/emsa3.cpp
index cf1aae3fa..35a9f6fe3 100644
--- a/src/emsa3.cpp
+++ b/src/emsa3.cpp
@@ -9,6 +9,36 @@
namespace Botan {
+namespace {
+
+/*************************************************
+* EMSA3 Encode Operation *
+*************************************************/
+SecureVector<byte> emsa3_encoding(const MemoryRegion<byte>& msg,
+ u32bit output_bits,
+ const MemoryRegion<byte>& hash_id,
+ u32bit hash_size)
+ {
+ if(msg.size() != hash_size)
+ throw Encoding_Error("EMSA3::encoding_of: Bad input length");
+
+ u32bit output_length = output_bits / 8;
+ if(output_length < hash_id.size() + hash_size + 10)
+ throw Encoding_Error("EMSA3::pad: Output length is too small");
+
+ SecureVector<byte> T(output_length);
+ const u32bit P_LENGTH = output_length - hash_size - hash_id.size() - 2;
+
+ T[0] = 0x01;
+ set_mem(T+1, P_LENGTH, 0xFF);
+ T[P_LENGTH+1] = 0x00;
+ T.copy(P_LENGTH+2, hash_id, hash_id.size());
+ T.copy(output_length-hash_size, msg, msg.size());
+ return T;
+ }
+
+}
+
/*************************************************
* EMSA3 Update Operation *
*************************************************/
@@ -32,23 +62,27 @@ SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
u32bit output_bits,
RandomNumberGenerator&)
{
- if(msg.size() != hash->OUTPUT_LENGTH)
- throw Encoding_Error("EMSA3::encoding_of: Bad input length");
-
- u32bit output_length = output_bits / 8;
- if(output_length < hash_id.size() + hash->OUTPUT_LENGTH + 10)
- throw Encoding_Error("EMSA3::pad: Output length is too small");
-
- SecureVector<byte> T(output_length);
- const u32bit P_LENGTH = output_length - hash->OUTPUT_LENGTH -
- hash_id.size() - 2;
+ return emsa3_encoding(msg, output_bits, hash_id,
+ hash->OUTPUT_LENGTH);
+ }
- T[0] = 0x01;
- set_mem(T+1, P_LENGTH, 0xFF);
- T[P_LENGTH+1] = 0x00;
- T.copy(P_LENGTH+2, hash_id, hash_id.size());
- T.copy(output_length-hash->OUTPUT_LENGTH, msg, msg.size());
- return T;
+/*************************************************
+* Default signature decoding *
+*************************************************/
+bool EMSA3::verify(const MemoryRegion<byte>& coded,
+ const MemoryRegion<byte>& raw,
+ u32bit key_bits) throw()
+ {
+ try
+ {
+ return (coded == emsa3_encoding(raw, key_bits,
+ hash_id,
+ hash->OUTPUT_LENGTH));
+ }
+ catch(...)
+ {
+ return false;
+ }
}
/*************************************************