aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-03-19 14:40:31 +0000
committerlloyd <[email protected]>2009-03-19 14:40:31 +0000
commit96a6948055bb0a497eab1a9a4a86cb2bb648a5b5 (patch)
tree30478d7708aa4dacc6805fbd7dfa337c5aac0d7b
parentb14127fc125dbbfc841ef8248bc797896dd2223f (diff)
Add back the public key filters, at the request of Andreas Podgurski on
the mailing list.
-rw-r--r--src/pubkey/pubkey/info.txt2
-rw-r--r--src/pubkey/pubkey/pk_filts.cpp113
-rw-r--r--src/pubkey/pubkey/pk_filts.h89
3 files changed, 204 insertions, 0 deletions
diff --git a/src/pubkey/pubkey/info.txt b/src/pubkey/pubkey/info.txt
index 72fe5b3eb..83b2c80cc 100644
--- a/src/pubkey/pubkey/info.txt
+++ b/src/pubkey/pubkey/info.txt
@@ -17,6 +17,8 @@ rng
<add>
pk_algs.cpp
pk_algs.h
+pk_filts.cpp
+pk_filts.h
pk_keys.cpp
pk_keys.h
pkcs8.cpp
diff --git a/src/pubkey/pubkey/pk_filts.cpp b/src/pubkey/pubkey/pk_filts.cpp
new file mode 100644
index 000000000..7fcb003e7
--- /dev/null
+++ b/src/pubkey/pubkey/pk_filts.cpp
@@ -0,0 +1,113 @@
+/*
+* PK Filters Source File
+* (C) 1999-2009 Jack Lloyd
+*/
+
+#include <botan/pk_filts.h>
+
+namespace Botan {
+
+/*
+* Append to the buffer
+*/
+void PK_Encryptor_Filter::write(const byte input[], u32bit length)
+ {
+ buffer.append(input, length);
+ }
+
+/*
+* Encrypt the message
+*/
+void PK_Encryptor_Filter::end_msg()
+ {
+ send(cipher->encrypt(buffer, buffer.size(), rng));
+ buffer.destroy();
+ }
+
+/*
+* Append to the buffer
+*/
+void PK_Decryptor_Filter::write(const byte input[], u32bit length)
+ {
+ buffer.append(input, length);
+ }
+
+/*
+* Decrypt the message
+*/
+void PK_Decryptor_Filter::end_msg()
+ {
+ send(cipher->decrypt(buffer, buffer.size()));
+ buffer.destroy();
+ }
+
+/*
+* Add more data
+*/
+void PK_Signer_Filter::write(const byte input[], u32bit length)
+ {
+ signer->update(input, length);
+ }
+
+/*
+* Sign the message
+*/
+void PK_Signer_Filter::end_msg()
+ {
+ send(signer->signature(rng));
+ }
+
+/*
+* Add more data
+*/
+void PK_Verifier_Filter::write(const byte input[], u32bit length)
+ {
+ verifier->update(input, length);
+ }
+
+/*
+* Verify the message
+*/
+void PK_Verifier_Filter::end_msg()
+ {
+ if(signature.is_empty())
+ throw Exception("PK_Verifier_Filter: No signature to check against");
+ bool is_valid = verifier->check_signature(signature, signature.size());
+ send((is_valid ? 1 : 0));
+ }
+
+/*
+* Set the signature to check
+*/
+void PK_Verifier_Filter::set_signature(const byte sig[], u32bit length)
+ {
+ signature.set(sig, length);
+ }
+
+/*
+* Set the signature to check
+*/
+void PK_Verifier_Filter::set_signature(const MemoryRegion<byte>& sig)
+ {
+ signature = sig;
+ }
+
+/*
+* PK_Verifier_Filter Constructor
+*/
+PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v, const byte sig[],
+ u32bit length) :
+ verifier(v), signature(sig, length)
+ {
+ }
+
+/*
+* PK_Verifier_Filter Constructor
+*/
+PK_Verifier_Filter::PK_Verifier_Filter(PK_Verifier* v,
+ const MemoryRegion<byte>& sig) :
+ verifier(v), signature(sig)
+ {
+ }
+
+}
diff --git a/src/pubkey/pubkey/pk_filts.h b/src/pubkey/pubkey/pk_filts.h
new file mode 100644
index 000000000..c127e709f
--- /dev/null
+++ b/src/pubkey/pubkey/pk_filts.h
@@ -0,0 +1,89 @@
+/*
+* PK Filters Header File
+* (C) 1999-2009 Jack Lloyd
+*/
+
+#ifndef BOTAN_PK_FILTERS_H__
+#define BOTAN_PK_FILTERS_H__
+
+#include <botan/filter.h>
+#include <botan/pubkey.h>
+
+namespace Botan {
+
+/*
+* PK_Encryptor Filter
+*/
+class BOTAN_DLL PK_Encryptor_Filter : public Filter
+ {
+ public:
+ void write(const byte[], u32bit);
+ void end_msg();
+ PK_Encryptor_Filter(PK_Encryptor* c,
+ RandomNumberGenerator& rng_ref) :
+ cipher(c), rng(rng_ref) {}
+ ~PK_Encryptor_Filter() { delete cipher; }
+ private:
+ PK_Encryptor* cipher;
+ RandomNumberGenerator& rng;
+ SecureVector<byte> buffer;
+ };
+
+/*
+* PK_Decryptor Filter
+*/
+class BOTAN_DLL PK_Decryptor_Filter : public Filter
+ {
+ public:
+ void write(const byte[], u32bit);
+ void end_msg();
+ PK_Decryptor_Filter(PK_Decryptor* c) : cipher(c) {}
+ ~PK_Decryptor_Filter() { delete cipher; }
+ private:
+ PK_Decryptor* cipher;
+ SecureVector<byte> buffer;
+ };
+
+/*
+* PK_Signer Filter
+*/
+class BOTAN_DLL PK_Signer_Filter : public Filter
+ {
+ public:
+ void write(const byte[], u32bit);
+ void end_msg();
+
+ PK_Signer_Filter(PK_Signer* s,
+ RandomNumberGenerator& rng_ref) :
+ signer(s), rng(rng_ref) {}
+
+ ~PK_Signer_Filter() { delete signer; }
+ private:
+ PK_Signer* signer;
+ RandomNumberGenerator& rng;
+ };
+
+/*
+* PK_Verifier Filter
+*/
+class BOTAN_DLL PK_Verifier_Filter : public Filter
+ {
+ public:
+ void write(const byte[], u32bit);
+ void end_msg();
+
+ void set_signature(const byte[], u32bit);
+ void set_signature(const MemoryRegion<byte>&);
+
+ PK_Verifier_Filter(PK_Verifier* v) : verifier(v) {}
+ PK_Verifier_Filter(PK_Verifier*, const byte[], u32bit);
+ PK_Verifier_Filter(PK_Verifier*, const MemoryRegion<byte>&);
+ ~PK_Verifier_Filter() { delete verifier; }
+ private:
+ PK_Verifier* verifier;
+ SecureVector<byte> signature;
+ };
+
+}
+
+#endif