aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/pk_ops.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 03:41:59 +0000
committerlloyd <[email protected]>2014-01-10 03:41:59 +0000
commit6894dca64c04936d07048c0e8cbf7e25858548c3 (patch)
tree5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/pubkey/pk_ops.h
parent9efa3be92442afb3d0b69890a36c7f122df18eda (diff)
Move lib into src
Diffstat (limited to 'src/lib/pubkey/pk_ops.h')
-rw-r--r--src/lib/pubkey/pk_ops.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/src/lib/pubkey/pk_ops.h b/src/lib/pubkey/pk_ops.h
new file mode 100644
index 000000000..8a08ef430
--- /dev/null
+++ b/src/lib/pubkey/pk_ops.h
@@ -0,0 +1,163 @@
+/*
+* PK Operation Types
+* (C) 2010 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_PK_OPERATIONS_H__
+#define BOTAN_PK_OPERATIONS_H__
+
+#include <botan/secmem.h>
+#include <botan/rng.h>
+
+namespace Botan {
+
+namespace PK_Ops {
+
+/**
+* Public key encryption interface
+*/
+class BOTAN_DLL Encryption
+ {
+ public:
+ virtual size_t max_input_bits() const = 0;
+
+ virtual secure_vector<byte> encrypt(const byte msg[], size_t msg_len,
+ RandomNumberGenerator& rng) = 0;
+
+ virtual ~Encryption() {}
+ };
+
+/**
+* Public key decryption interface
+*/
+class BOTAN_DLL Decryption
+ {
+ public:
+ virtual size_t max_input_bits() const = 0;
+
+ virtual secure_vector<byte> decrypt(const byte msg[],
+ size_t msg_len) = 0;
+
+ virtual ~Decryption() {}
+ };
+
+/**
+* Public key signature creation interface
+*/
+class BOTAN_DLL Signature
+ {
+ public:
+ /**
+ * Find out the number of message parts supported by this scheme.
+ * @return number of message parts
+ */
+ virtual size_t message_parts() const { return 1; }
+
+ /**
+ * Find out the message part size supported by this scheme/key.
+ * @return size of the message parts
+ */
+ virtual size_t message_part_size() const { return 0; }
+
+ /**
+ * Get the maximum message size in bits supported by this public key.
+ * @return maximum message in bits
+ */
+ virtual size_t max_input_bits() const = 0;
+
+ /*
+ * Perform a signature operation
+ * @param msg the message
+ * @param msg_len the length of msg in bytes
+ * @param rng a random number generator
+ */
+ virtual secure_vector<byte> sign(const byte msg[], size_t msg_len,
+ RandomNumberGenerator& rng) = 0;
+
+ virtual ~Signature() {}
+ };
+
+/**
+* Public key signature verification interface
+*/
+class BOTAN_DLL Verification
+ {
+ public:
+ /**
+ * Get the maximum message size in bits supported by this public key.
+ * @return maximum message in bits
+ */
+ virtual size_t max_input_bits() const = 0;
+
+ /**
+ * Find out the number of message parts supported by this scheme.
+ * @return number of message parts
+ */
+ virtual size_t message_parts() const { return 1; }
+
+ /**
+ * Find out the message part size supported by this scheme/key.
+ * @return size of the message parts
+ */
+ virtual size_t message_part_size() const { return 0; }
+
+ /**
+ * @return boolean specifying if this key type supports message
+ * recovery and thus if you need to call verify() or verify_mr()
+ */
+ virtual bool with_recovery() const = 0;
+
+ /*
+ * Perform a signature check operation
+ * @param msg the message
+ * @param msg_len the length of msg in bytes
+ * @param sig the signature
+ * @param sig_len the length of sig in bytes
+ * @returns if signature is a valid one for message
+ */
+ virtual bool verify(const byte[], size_t,
+ const byte[], size_t)
+ {
+ throw Invalid_State("Message recovery required");
+ }
+
+ /*
+ * Perform a signature operation (with message recovery)
+ * Only call this if with_recovery() returns true
+ * @param msg the message
+ * @param msg_len the length of msg in bytes
+ * @returns recovered message
+ */
+ virtual secure_vector<byte> verify_mr(const byte[],
+ size_t)
+ {
+ throw Invalid_State("Message recovery not supported");
+ }
+
+ virtual ~Verification() {}
+ };
+
+/**
+* A generic key agreement Operation (eg DH or ECDH)
+*/
+class BOTAN_DLL Key_Agreement
+ {
+ public:
+ /*
+ * Perform a key agreement operation
+ * @param w the other key value
+ * @param w_len the length of w in bytes
+ * @returns the agreed key
+ */
+ virtual secure_vector<byte> agree(const byte w[], size_t w_len) = 0;
+
+ virtual ~Key_Agreement() {}
+ };
+
+}
+
+}
+
+#endif