From 96a6948055bb0a497eab1a9a4a86cb2bb648a5b5 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 19 Mar 2009 14:40:31 +0000 Subject: Add back the public key filters, at the request of Andreas Podgurski on the mailing list. --- src/pubkey/pubkey/info.txt | 2 + src/pubkey/pubkey/pk_filts.cpp | 113 +++++++++++++++++++++++++++++++++++++++++ src/pubkey/pubkey/pk_filts.h | 89 ++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 src/pubkey/pubkey/pk_filts.cpp create mode 100644 src/pubkey/pubkey/pk_filts.h (limited to 'src/pubkey') 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 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 + +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& 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& 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 +#include + +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 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 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&); + + PK_Verifier_Filter(PK_Verifier* v) : verifier(v) {} + PK_Verifier_Filter(PK_Verifier*, const byte[], u32bit); + PK_Verifier_Filter(PK_Verifier*, const MemoryRegion&); + ~PK_Verifier_Filter() { delete verifier; } + private: + PK_Verifier* verifier; + SecureVector signature; + }; + +} + +#endif -- cgit v1.2.3