1 /**
2 * PK Operation Types
3 * 
4 * Copyright:
5 * (C) 2010 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 module botan.pubkey.pk_ops;
12 
13 import botan.constants;
14 static if (BOTAN_HAS_PUBLIC_KEY_CRYPTO):
15 
16 public import botan.asn1.alg_id;
17 public import botan.rng.rng;
18 public import botan.pubkey.pk_keys;
19 import memutils.vector;
20 
21 /**
22 * Public key encryption interface
23 */
24 interface Encryption
25 {
26 public:
27     abstract size_t maxInputBits() const;
28 
29     abstract SecureVector!ubyte encrypt(const(ubyte)* msg, size_t msg_len, RandomNumberGenerator rng);
30 
31 }
32 
33 /**
34 * Public key decryption interface
35 */
36 interface Decryption
37 {
38 public:
39     abstract size_t maxInputBits() const;
40 
41     abstract SecureVector!ubyte decrypt(const(ubyte)* msg, size_t msg_len);
42 
43 }
44 
45 /**
46 * Public key signature creation interface
47 */
48 interface Signature
49 {
50 public:
51     /**
52     * Find out the number of message parts supported by this scheme.
53     * Returns: number of message parts
54     */
55     abstract size_t messageParts() const;
56 
57     /**
58     * Find out the message part size supported by this scheme/key.
59     * Returns: size of the message parts
60     */
61     abstract size_t messagePartSize() const;
62 
63     /**
64     * Get the maximum message size in bits supported by this public key.
65     * Returns: maximum message in bits
66     */
67     abstract size_t maxInputBits() const;
68 
69     /*
70     * Perform a signature operation
71     * Params:
72     *  msg = the message
73     *  msg_len = the length of msg in bytes
74     *  rng = a random number generator
75     */
76     abstract SecureVector!ubyte sign(const(ubyte)* msg, size_t msg_len, RandomNumberGenerator rng);
77 
78 }
79 
80 /**
81 * Public key signature verification interface
82 */
83 interface Verification
84 {
85 public:
86     /**
87     * Get the maximum message size in bits supported by this public key.
88     * Returns: maximum message in bits
89     */
90     abstract size_t maxInputBits() const;
91 
92     /**
93     * Find out the number of message parts supported by this scheme.
94     * Returns: number of message parts
95     */
96     abstract size_t messageParts() const;
97 
98     /**
99     * Find out the message part size supported by this scheme/key.
100     * Returns: size of the message parts
101     */
102     abstract size_t messagePartSize() const;
103 
104     /**
105     * Returns: boolean specifying if this key type supports message
106     * recovery and thus if you need to call verify() or verifyMr()
107     */
108     abstract bool withRecovery() const;
109 
110     /*
111     * Perform a signature check operation
112     * Params:
113     *  msg = the message
114     *  msg_len = the length of msg in bytes
115     *  sig = the signature
116     *  sig_len = the length of sig in bytes
117     * Returns: true if signature is a valid one for message
118     */
119     abstract bool verify(const(ubyte)* msg, size_t msg_len, const(ubyte)* sig, size_t sig_len);
120 
121     /*
122     * Perform a signature operation (with message recovery)
123     * Only call this if withRecovery() returns true
124     * Params:
125     *  msg = the message
126     *  msg_len = the length of msg in bytes
127     * Returns:s recovered message
128     */
129     abstract SecureVector!ubyte verifyMr(const(ubyte)* msg, size_t msg_len);
130 
131 }
132 
133 /**
134 * A generic key agreement Operation (eg DH or ECDH)
135 */
136 interface KeyAgreement
137 {
138 public:
139     /*
140     * Perform a key agreement operation
141     * Params:
142     *  w = the other key value
143     *  w_len = the length of w in bytes
144     * Returns:s the agreed key
145     */
146     abstract SecureVector!ubyte agree(const(ubyte)* w, size_t w_len);
147 }