1 /**
2 * Engine
3 * 
4 * Copyright:
5 * (C) 1999-2007 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.engine.engine;
12 
13 import botan.constants;
14 public import botan.algo_base.scan_token;
15 public import botan.block.block_cipher;
16 public import botan.stream.stream_cipher;
17 public import botan.hash.hash;
18 public import botan.mac.mac;
19 public import botan.pbkdf.pbkdf;
20 public import botan.math.numbertheory.pow_mod;
21 public import botan.pubkey.pk_keys;
22 public import botan.pubkey.pk_ops;
23 public import botan.rng.rng;
24 public import botan.math.bigint.bigint;
25 public import botan.filters.key_filt;
26 public import botan.algo_factory.algo_factory;
27 public import botan.utils.types;
28 
29 /**
30 * Base class for all engines. All non-pure abstract functions simply
31 * return NULL, indicating the algorithm in question is not
32 * supported. Subclasses can reimplement whichever function(s)
33 * they want to hook in a particular type.
34 */
35 interface Engine
36 {
37 public:
38     /**
39     * Returns: name of this engine
40     */
41     string providerName() const;
42 
43     /**
44     * Params:
45     *  algo_spec = the algorithm name/specification
46     *  af = an algorithm factory object
47     * Returns: newly allocated object, or NULL
48     */
49     BlockCipher findBlockCipher(in SCANToken algo_spec, AlgorithmFactory af) const;
50 
51 
52     /**
53     * Params:
54     *  algo_spec = the algorithm name/specification
55     *  af = an algorithm factory object
56     * Returns: newly allocated object, or NULL
57     */
58     StreamCipher findStreamCipher(in SCANToken algo_spec, AlgorithmFactory af) const;
59 
60     /**
61     * Params:
62     *  algo_spec = the algorithm name/specification
63     *  af = an algorithm factory object
64     * Returns: newly allocated object, or NULL
65     */
66     HashFunction findHash(in SCANToken algo_spec, AlgorithmFactory af) const;
67 
68 
69     /**
70     * Params:
71     *  algo_spec = the algorithm name/specification
72     *  af = an algorithm factory object
73     * Returns: newly allocated object, or NULL
74     */
75     MessageAuthenticationCode findMac(in SCANToken algo_spec, AlgorithmFactory af) const;
76 
77     /**
78     * Params:
79     *  algo_spec = the algorithm name/specification
80     *  af = an algorithm factory object
81     * Returns: newly allocated object, or NULL
82     */
83     PBKDF findPbkdf(in SCANToken algo_spec, AlgorithmFactory af) const;
84 
85     /**
86     * Return a new cipher object
87     * Params:
88     *  algo_spec = the algorithm name/specification
89     *  dir = specifies if encryption or decryption is desired
90     *  af = an algorithm factory object
91     * Returns: newly allocated object, or NULL
92     */
93     KeyedFilter getCipher(in string algo_spec, CipherDir dir, AlgorithmFactory af) const;
94 
95     static if (BOTAN_HAS_PUBLIC_KEY_CRYPTO):
96 
97     /**
98     * Params:
99     *  n = the modulus
100     *  hints = any use hints
101     * Returns: newly allocated object, or NULL
102     */
103     ModularExponentiator modExp(const ref BigInt n, PowerMod.UsageHints hints) const;
104 
105 
106     /**
107     * Return a new operator object for this key, if possible
108     * Params:
109     *  key = the key we want an operator for
110     *  rng = a random number generator
111     * Returns: newly allocated operator object, or NULL
112     */
113     KeyAgreement getKeyAgreementOp(in PrivateKey key, RandomNumberGenerator rng) const;
114 
115     /**
116     * Return a new operator object for this key, if possible
117     * Params:
118     *  key = the key we want an operator for
119     *  rng = a random number generator
120     * Returns: newly allocated operator object, or NULL
121     */
122     Signature getSignatureOp(in PrivateKey key, RandomNumberGenerator rng) const;
123 
124     /**
125     * Return a new operator object for this key, if possible
126     * Params:
127     *  key = the key we want an operator for
128     *  rng = a random number generator
129     * Returns: newly allocated operator object, or NULL
130     */
131     Verification getVerifyOp(in PublicKey key, RandomNumberGenerator rng) const;
132 
133     /**
134     * Return a new operator object for this key, if possible
135     * Params:
136     *  key = the key we want an operator for
137     *  rng = a random number generator
138     * Returns: newly allocated operator object, or NULL
139     */
140     Encryption getEncryptionOp(in PublicKey key, RandomNumberGenerator rng) const;
141 
142     /**
143     * Return a new operator object for this key, if possible
144     * Params:
145     *  key = the key we want an operator for
146     *  rng = a random number generator
147     * Returns: newly allocated operator object, or NULL
148     */
149     Decryption getDecryptionOp(in PrivateKey key, RandomNumberGenerator rng) const;
150 }