aboutsummaryrefslogtreecommitdiffstats
path: root/src/pk_pad/emsa3
diff options
context:
space:
mode:
Diffstat (limited to 'src/pk_pad/emsa3')
-rw-r--r--src/pk_pad/emsa3/emsa3.cpp97
-rw-r--r--src/pk_pad/emsa3/emsa3.h38
-rw-r--r--src/pk_pad/emsa3/modinfo.txt10
3 files changed, 145 insertions, 0 deletions
diff --git a/src/pk_pad/emsa3/emsa3.cpp b/src/pk_pad/emsa3/emsa3.cpp
new file mode 100644
index 000000000..60880d1aa
--- /dev/null
+++ b/src/pk_pad/emsa3/emsa3.cpp
@@ -0,0 +1,97 @@
+/*************************************************
+* EMSA3 Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/emsa3.h>
+#include <botan/hash_id.h>
+#include <botan/lookup.h>
+
+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 *
+*************************************************/
+void EMSA3::update(const byte input[], u32bit length)
+ {
+ hash->update(input, length);
+ }
+
+/*************************************************
+* Return the raw (unencoded) data *
+*************************************************/
+SecureVector<byte> EMSA3::raw_data()
+ {
+ return hash->final();
+ }
+
+/*************************************************
+* EMSA3 Encode Operation *
+*************************************************/
+SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
+ u32bit output_bits,
+ RandomNumberGenerator&)
+ {
+ return emsa3_encoding(msg, output_bits, hash_id,
+ hash->OUTPUT_LENGTH);
+ }
+
+/*************************************************
+* 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;
+ }
+ }
+
+/*************************************************
+* EMSA3 Constructor *
+*************************************************/
+EMSA3::EMSA3(const std::string& hash_name)
+ {
+ hash_id = pkcs_hash_id(hash_name);
+ hash = get_hash(hash_name);
+ }
+
+}
diff --git a/src/pk_pad/emsa3/emsa3.h b/src/pk_pad/emsa3/emsa3.h
new file mode 100644
index 000000000..fa8521216
--- /dev/null
+++ b/src/pk_pad/emsa3/emsa3.h
@@ -0,0 +1,38 @@
+/*************************************************
+* EMSA3 Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_EMSA3_H__
+#define BOTAN_EMSA3_H__
+
+#include <botan/pk_util.h>
+
+namespace Botan {
+
+/*************************************************
+* EMSA3 *
+*************************************************/
+class BOTAN_DLL EMSA3 : public EMSA
+ {
+ public:
+ EMSA3(const std::string&);
+ ~EMSA3() { delete hash; }
+ private:
+ void update(const byte[], u32bit);
+
+ SecureVector<byte> raw_data();
+
+ SecureVector<byte> encoding_of(const MemoryRegion<byte>&, u32bit,
+ RandomNumberGenerator& rng);
+
+ bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ u32bit) throw();
+
+ HashFunction* hash;
+ SecureVector<byte> hash_id;
+ };
+
+}
+
+#endif
diff --git a/src/pk_pad/emsa3/modinfo.txt b/src/pk_pad/emsa3/modinfo.txt
new file mode 100644
index 000000000..926f9a4e8
--- /dev/null
+++ b/src/pk_pad/emsa3/modinfo.txt
@@ -0,0 +1,10 @@
+realname "EMSA3"
+
+define EMSA3
+
+load_on auto
+
+<add>
+emsa3.h
+emsa3.cpp
+</add>