diff options
author | lloyd <[email protected]> | 2009-03-19 14:40:31 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-03-19 14:40:31 +0000 |
commit | 96a6948055bb0a497eab1a9a4a86cb2bb648a5b5 (patch) | |
tree | 30478d7708aa4dacc6805fbd7dfa337c5aac0d7b /src/pubkey | |
parent | b14127fc125dbbfc841ef8248bc797896dd2223f (diff) |
Add back the public key filters, at the request of Andreas Podgurski on
the mailing list.
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/pubkey/info.txt | 2 | ||||
-rw-r--r-- | src/pubkey/pubkey/pk_filts.cpp | 113 | ||||
-rw-r--r-- | src/pubkey/pubkey/pk_filts.h | 89 |
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 |