Botan: src/pubkey/pk_ops.h Source File

Botan 1.10.16

pk_ops.h
Go to the documentation of this file.
1 /*
2 * PK Operation Types
3 * (C) 2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_PK_OPERATIONS_H__
9 #define BOTAN_PK_OPERATIONS_H__
10
11 #include <botan/secmem.h>
12 #include <botan/rng.h>
13
14 namespace Botan {
15
16 namespace PK_Ops {
17
18 /**
19 * Public key encryption interface
20 */
21 class BOTAN_DLL Encryption
22 {
23 public:
24 virtual size_t max_input_bits() const = 0;
25
26 virtual SecureVector<byte> encrypt(const byte msg[], size_t msg_len,
27 RandomNumberGenerator& rng) = 0;
28
29 virtual ~Encryption() {}
30 };
31
32 /**
33 * Public key decryption interface
34 */
35 class BOTAN_DLL Decryption
36 {
37 public:
38 virtual size_t max_input_bits() const = 0;
39
40 virtual SecureVector<byte> decrypt(const byte msg[],
41 size_t msg_len) = 0;
42
43 virtual ~Decryption() {}
44 };
45
46 /**
47 * Public key signature creation interface
48 */
49 class BOTAN_DLL Signature
50 {
51 public:
52 /**
53 * Find out the number of message parts supported by this scheme.
54 * @return number of message parts
55 */
56 virtual size_t message_parts() const { return 1; }
57
58 /**
59 * Find out the message part size supported by this scheme/key.
60 * @return size of the message parts
61 */
62 virtual size_t message_part_size() const { return 0; }
63
64 /**
65 * Get the maximum message size in bits supported by this public key.
66 * @return maximum message in bits
67 */
68 virtual size_t max_input_bits() const = 0;
69
70 /*
71 * Perform a signature operation
72 * @param msg the message
73 * @param msg_len the length of msg in bytes
74 * @param rng a random number generator
75 */
76 virtual SecureVector<byte> sign(const byte msg[], size_t msg_len,
77 RandomNumberGenerator& rng) = 0;
78
79 virtual ~Signature() {}
80 };
81
82 /**
83 * Public key signature verification interface
84 */
85 class BOTAN_DLL Verification
86 {
87 public:
88 /**
89 * Get the maximum message size in bits supported by this public key.
90 * @return maximum message in bits
91 */
92 virtual size_t max_input_bits() const = 0;
93
94 /**
95 * Find out the number of message parts supported by this scheme.
96 * @return number of message parts
97 */
98 virtual size_t message_parts() const { return 1; }
99
100 /**
101 * Find out the message part size supported by this scheme/key.
102 * @return size of the message parts
103 */
104 virtual size_t message_part_size() const { return 0; }
105
106 /**
107 * @return boolean specifying if this key type supports message
108 * recovery and thus if you need to call verify() or verify_mr()
109 */
110 virtual bool with_recovery() const = 0;
111
112 /*
113 * Perform a signature check operation
114 * @param msg the message
115 * @param msg_len the length of msg in bytes
116 * @param sig the signature
117 * @param sig_len the length of sig in bytes
118 * @returns if signature is a valid one for message
119 */
120 virtual bool verify(const byte[], size_t,
121 const byte[], size_t)
122 {
123 throw Invalid_State("Message recovery required");
124 }
125
126 /*
127 * Perform a signature operation (with message recovery)
128 * Only call this if with_recovery() returns true
129 * @param msg the message
130 * @param msg_len the length of msg in bytes
131 * @returns recovered message
132 */
133 virtual SecureVector<byte> verify_mr(const byte[],
134 size_t)
135 {
136 throw Invalid_State("Message recovery not supported");
137 }
138
139 virtual ~Verification() {}
140 };
141
142 /**
143 * A generic key agreement Operation (eg DH or ECDH)
144 */
145 class BOTAN_DLL Key_Agreement
146 {
147 public:
148 /*
149 * Perform a key agreement operation
150 * @param w the other key value
151 * @param w_len the length of w in bytes
152 * @returns the agreed key
153 */
154 virtual SecureVector<byte> agree(const byte w[], size_t w_len) = 0;
155
156 virtual ~Key_Agreement() {}
157 };
158
159 }
160
161 }
162
163 #endif
Botan::PK_Ops::Verification::verify_mr
virtual SecureVector< byte > verify_mr(const byte[], size_t)
Definition: pk_ops.h:133
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::PK_Ops::Verification::message_parts
virtual size_t message_parts() const
Definition: pk_ops.h:98
Botan::PK_Ops::Signature::message_parts
virtual size_t message_parts() const
Definition: pk_ops.h:56
Botan::PK_Ops::Signature
Definition: pk_ops.h:49
Botan::Invalid_State
Definition: exceptn.h:25
Botan::PK_Ops::Verification::verify
virtual bool verify(const byte[], size_t, const byte[], size_t)
Definition: pk_ops.h:120
Botan::PK_Ops::Verification::message_part_size
virtual size_t message_part_size() const
Definition: pk_ops.h:104
Botan::PK_Ops::Verification::~Verification
virtual ~Verification()
Definition: pk_ops.h:139
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::PK_Ops::Signature::message_part_size
virtual size_t message_part_size() const
Definition: pk_ops.h:62
Botan::PK_Ops::Encryption::~Encryption
virtual ~Encryption()
Definition: pk_ops.h:29
Botan::PK_Ops::Decryption::~Decryption
virtual ~Decryption()
Definition: pk_ops.h:43
Botan
Definition: algo_base.h:14
Botan::PK_Ops::Key_Agreement
Definition: pk_ops.h:145
Botan::PK_Ops::Key_Agreement::~Key_Agreement
virtual ~Key_Agreement()
Definition: pk_ops.h:156
Botan::PK_Ops::Signature::~Signature
virtual ~Signature()
Definition: pk_ops.h:79
Botan::SecureVector< byte >
Botan::PK_Ops::Decryption
Definition: pk_ops.h:35
Botan::PK_Ops::Encryption
Definition: pk_ops.h:21
Botan::PK_Ops::Verification
Definition: pk_ops.h:85