~ubuntu-branches/ubuntu/saucy/apache2/saucy

« back to all changes in this revision

Viewing changes to srclib/apr-util/include/private/apr_crypto_internal.h

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-02-12 20:06:35 UTC
  • mfrom: (14.3.34 sid)
  • Revision ID: package-import@ubuntu.com-20120212200635-2u9d58jxqkmx91na
Tags: 2.2.22-1ubuntu1
* Merge from Debian testing.  Remaining changes:
  - debian/{control, rules}: Enable PIE hardening.
  - debian/{control, rules, apache2.2-common.ufw.profile}: Add ufw profiles.
  - debian/control: Add bzr tag and point it to our tree
  - debian/apache2.py, debian/apache2.2-common.install: Add apport hook.
  - debian/control, debian/ask-for-passphrase, debian/config-dir/mods-available/ssl.conf:
    Plymouth aware passphrase dialog program ask-for-passphrase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
 
2
 * contributor license agreements.  See the NOTICE file distributed with
 
3
 * this work for additional information regarding copyright ownership.
 
4
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
5
 * (the "License"); you may not use this file except in compliance with
 
6
 * the License.  You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef APR_CRYPTO_INTERNAL_H
 
18
#define APR_CRYPTO_INTERNAL_H
 
19
 
 
20
#include <stdarg.h>
 
21
 
 
22
#include "apr_crypto.h"
 
23
 
 
24
#ifdef __cplusplus
 
25
extern "C" {
 
26
#endif
 
27
 
 
28
#if APU_HAVE_CRYPTO
 
29
 
 
30
struct apr_crypto_driver_t {
 
31
 
 
32
    /** name */
 
33
    const char *name;
 
34
 
 
35
    /**
 
36
     * @brief: allow driver to perform once-only initialisation.
 
37
     * Called once only.
 
38
     * @param pool The pool to register the cleanup in.
 
39
     * @param params Optional init parameter string.
 
40
     * @param rc Driver-specific additional error code
 
41
     */
 
42
    apr_status_t (*init)(apr_pool_t *pool, const char *params, int *rc);
 
43
 
 
44
    /**
 
45
     * @brief Create a context for supporting encryption. Keys, certificates,
 
46
     *        algorithms and other parameters will be set per context. More than
 
47
     *        one context can be created at one time. A cleanup will be automatically
 
48
     *        registered with the given pool to guarantee a graceful shutdown.
 
49
     * @param f - context pointer will be written here
 
50
     * @param provider - provider to use
 
51
     * @param params - array of key parameters
 
52
     * @param pool - process pool
 
53
     * @return APR_ENOENGINE when the engine specified does not exist. APR_EINITENGINE
 
54
     * if the engine cannot be initialised.
 
55
     */
 
56
    apr_status_t (*make)(apr_crypto_t **f, const apr_crypto_driver_t *provider,
 
57
            const char *params, apr_pool_t *pool);
 
58
 
 
59
    /**
 
60
     * @brief Get a hash table of key types, keyed by the name of the type against
 
61
     * an integer pointer constant.
 
62
     *
 
63
     * @param types - hashtable of key types keyed to constants.
 
64
     * @param f - encryption context
 
65
     * @return APR_SUCCESS for success
 
66
     */
 
67
    apr_status_t (*get_block_key_types)(apr_hash_t **types,
 
68
            const apr_crypto_t *f);
 
69
 
 
70
    /**
 
71
     * @brief Get a hash table of key modes, keyed by the name of the mode against
 
72
     * an integer pointer constant.
 
73
     *
 
74
     * @param modes - hashtable of key modes keyed to constants.
 
75
     * @param f - encryption context
 
76
     * @return APR_SUCCESS for success
 
77
     */
 
78
    apr_status_t (*get_block_key_modes)(apr_hash_t **modes,
 
79
            const apr_crypto_t *f);
 
80
 
 
81
    /**
 
82
     * @brief Create a key from the given passphrase. By default, the PBKDF2
 
83
     *        algorithm is used to generate the key from the passphrase. It is expected
 
84
     *        that the same pass phrase will generate the same key, regardless of the
 
85
     *        backend crypto platform used. The key is cleaned up when the context
 
86
     *        is cleaned, and may be reused with multiple encryption or decryption
 
87
     *        operations.
 
88
     * @note If *key is NULL, a apr_crypto_key_t will be created from a pool. If
 
89
     *       *key is not NULL, *key must point at a previously created structure.
 
90
     * @param key The key returned, see note.
 
91
     * @param ivSize The size of the initialisation vector will be returned, based
 
92
     *               on whether an IV is relevant for this type of crypto.
 
93
     * @param pass The passphrase to use.
 
94
     * @param passLen The passphrase length in bytes
 
95
     * @param salt The salt to use.
 
96
     * @param saltLen The salt length in bytes
 
97
     * @param type 3DES_192, AES_128, AES_192, AES_256.
 
98
     * @param mode Electronic Code Book / Cipher Block Chaining.
 
99
     * @param doPad Pad if necessary.
 
100
     * @param iterations Iteration count
 
101
     * @param f The context to use.
 
102
     * @param p The pool to use.
 
103
     * @return Returns APR_ENOKEY if the pass phrase is missing or empty, or if a backend
 
104
     *         error occurred while generating the key. APR_ENOCIPHER if the type or mode
 
105
     *         is not supported by the particular backend. APR_EKEYTYPE if the key type is
 
106
     *         not known. APR_EPADDING if padding was requested but is not supported.
 
107
     *         APR_ENOTIMPL if not implemented.
 
108
     */
 
109
    apr_status_t (*passphrase)(apr_crypto_key_t **key, apr_size_t *ivSize,
 
110
            const char *pass, apr_size_t passLen, const unsigned char * salt,
 
111
            apr_size_t saltLen, const apr_crypto_block_key_type_e type,
 
112
            const apr_crypto_block_key_mode_e mode, const int doPad,
 
113
            const int iterations, const apr_crypto_t *f, apr_pool_t *p);
 
114
 
 
115
    /**
 
116
     * @brief Initialise a context for encrypting arbitrary data using the given key.
 
117
     * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If
 
118
     *       *ctx is not NULL, *ctx must point at a previously created structure.
 
119
     * @param ctx The block context returned, see note.
 
120
     * @param iv Optional initialisation vector. If the buffer pointed to is NULL,
 
121
     *           an IV will be created at random, in space allocated from the pool.
 
122
     *           If the buffer pointed to is not NULL, the IV in the buffer will be
 
123
     *           used.
 
124
     * @param key The key structure.
 
125
     * @param blockSize The block size of the cipher.
 
126
     * @param p The pool to use.
 
127
     * @return Returns APR_ENOIV if an initialisation vector is required but not specified.
 
128
     *         Returns APR_EINIT if the backend failed to initialise the context. Returns
 
129
     *         APR_ENOTIMPL if not implemented.
 
130
     */
 
131
    apr_status_t (*block_encrypt_init)(apr_crypto_block_t **ctx,
 
132
            const unsigned char **iv, const apr_crypto_key_t *key,
 
133
            apr_size_t *blockSize, apr_pool_t *p);
 
134
 
 
135
    /**
 
136
     * @brief Encrypt data provided by in, write it to out.
 
137
     * @note The number of bytes written will be written to outlen. If
 
138
     *       out is NULL, outlen will contain the maximum size of the
 
139
     *       buffer needed to hold the data, including any data
 
140
     *       generated by apr_crypto_block_encrypt_finish below. If *out points
 
141
     *       to NULL, a buffer sufficiently large will be created from
 
142
     *       the pool provided. If *out points to a not-NULL value, this
 
143
     *       value will be used as a buffer instead.
 
144
     * @param out Address of a buffer to which data will be written,
 
145
     *        see note.
 
146
     * @param outlen Length of the output will be written here.
 
147
     * @param in Address of the buffer to read.
 
148
     * @param inlen Length of the buffer to read.
 
149
     * @param ctx The block context to use.
 
150
     * @return APR_ECRYPT if an error occurred. Returns APR_ENOTIMPL if
 
151
     *         not implemented.
 
152
     */
 
153
    apr_status_t (*block_encrypt)(unsigned char **out, apr_size_t *outlen,
 
154
            const unsigned char *in, apr_size_t inlen, apr_crypto_block_t *ctx);
 
155
 
 
156
    /**
 
157
     * @brief Encrypt final data block, write it to out.
 
158
     * @note If necessary the final block will be written out after being
 
159
     *       padded. Typically the final block will be written to the
 
160
     *       same buffer used by apr_crypto_block_encrypt, offset by the
 
161
     *       number of bytes returned as actually written by the
 
162
     *       apr_crypto_block_encrypt() call. After this call, the context
 
163
     *       is cleaned and can be reused by apr_crypto_block_encrypt_init().
 
164
     * @param out Address of a buffer to which data will be written. This
 
165
     *            buffer must already exist, and is usually the same
 
166
     *            buffer used by apr_evp_crypt(). See note.
 
167
     * @param outlen Length of the output will be written here.
 
168
     * @param ctx The block context to use.
 
169
     * @return APR_ECRYPT if an error occurred.
 
170
     * @return APR_EPADDING if padding was enabled and the block was incorrectly
 
171
     *         formatted.
 
172
     * @return APR_ENOTIMPL if not implemented.
 
173
     */
 
174
    apr_status_t (*block_encrypt_finish)(unsigned char *out,
 
175
            apr_size_t *outlen, apr_crypto_block_t *ctx);
 
176
 
 
177
    /**
 
178
     * @brief Initialise a context for decrypting arbitrary data using the given key.
 
179
     * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If
 
180
     *       *ctx is not NULL, *ctx must point at a previously created structure.
 
181
     * @param ctx The block context returned, see note.
 
182
     * @param blockSize The block size of the cipher.
 
183
     * @param iv Optional initialisation vector. If the buffer pointed to is NULL,
 
184
     *           an IV will be created at random, in space allocated from the pool.
 
185
     *           If the buffer is not NULL, the IV in the buffer will be used.
 
186
     * @param key The key structure.
 
187
     * @param p The pool to use.
 
188
     * @return Returns APR_ENOIV if an initialisation vector is required but not specified.
 
189
     *         Returns APR_EINIT if the backend failed to initialise the context. Returns
 
190
     *         APR_ENOTIMPL if not implemented.
 
191
     */
 
192
    apr_status_t (*block_decrypt_init)(apr_crypto_block_t **ctx,
 
193
            apr_size_t *blockSize, const unsigned char *iv,
 
194
            const apr_crypto_key_t *key, apr_pool_t *p);
 
195
 
 
196
    /**
 
197
     * @brief Decrypt data provided by in, write it to out.
 
198
     * @note The number of bytes written will be written to outlen. If
 
199
     *       out is NULL, outlen will contain the maximum size of the
 
200
     *       buffer needed to hold the data, including any data
 
201
     *       generated by apr_crypto_block_decrypt_finish below. If *out points
 
202
     *       to NULL, a buffer sufficiently large will be created from
 
203
     *       the pool provided. If *out points to a not-NULL value, this
 
204
     *       value will be used as a buffer instead.
 
205
     * @param out Address of a buffer to which data will be written,
 
206
     *        see note.
 
207
     * @param outlen Length of the output will be written here.
 
208
     * @param in Address of the buffer to read.
 
209
     * @param inlen Length of the buffer to read.
 
210
     * @param ctx The block context to use.
 
211
     * @return APR_ECRYPT if an error occurred. Returns APR_ENOTIMPL if
 
212
     *         not implemented.
 
213
     */
 
214
    apr_status_t (*block_decrypt)(unsigned char **out, apr_size_t *outlen,
 
215
            const unsigned char *in, apr_size_t inlen, apr_crypto_block_t *ctx);
 
216
 
 
217
    /**
 
218
     * @brief Decrypt final data block, write it to out.
 
219
     * @note If necessary the final block will be written out after being
 
220
     *       padded. Typically the final block will be written to the
 
221
     *       same buffer used by apr_crypto_block_decrypt, offset by the
 
222
     *       number of bytes returned as actually written by the
 
223
     *       apr_crypto_block_decrypt() call. After this call, the context
 
224
     *       is cleaned and can be reused by apr_crypto_block_decrypt_init().
 
225
     * @param out Address of a buffer to which data will be written. This
 
226
     *            buffer must already exist, and is usually the same
 
227
     *            buffer used by apr_evp_crypt(). See note.
 
228
     * @param outlen Length of the output will be written here.
 
229
     * @param ctx The block context to use.
 
230
     * @return APR_ECRYPT if an error occurred.
 
231
     * @return APR_EPADDING if padding was enabled and the block was incorrectly
 
232
     *         formatted.
 
233
     * @return APR_ENOTIMPL if not implemented.
 
234
     */
 
235
    apr_status_t (*block_decrypt_finish)(unsigned char *out,
 
236
            apr_size_t *outlen, apr_crypto_block_t *ctx);
 
237
 
 
238
    /**
 
239
     * @brief Clean encryption / decryption context.
 
240
     * @note After cleanup, a context is free to be reused if necessary.
 
241
     * @param ctx The block context to use.
 
242
     * @return Returns APR_ENOTIMPL if not supported.
 
243
     */
 
244
    apr_status_t (*block_cleanup)(apr_crypto_block_t *ctx);
 
245
 
 
246
    /**
 
247
     * @brief Clean encryption / decryption context.
 
248
     * @note After cleanup, a context is free to be reused if necessary.
 
249
     * @param f The context to use.
 
250
     * @return Returns APR_ENOTIMPL if not supported.
 
251
     */
 
252
    apr_status_t (*cleanup)(apr_crypto_t *f);
 
253
 
 
254
    /**
 
255
     * @brief Clean encryption / decryption context.
 
256
     * @note After cleanup, a context is free to be reused if necessary.
 
257
     * @return Returns APR_ENOTIMPL if not supported.
 
258
     */
 
259
    apr_status_t (*shutdown)(void);
 
260
 
 
261
    /**
 
262
     * @brief: fetch the most recent error from this driver.
 
263
     * @param result - the result structure
 
264
     * @param f - context pointer
 
265
     * @return APR_SUCCESS for success.
 
266
     */
 
267
    apr_status_t (*error)(const apu_err_t **result, const apr_crypto_t *f);
 
268
 
 
269
};
 
270
 
 
271
#endif
 
272
 
 
273
#ifdef __cplusplus
 
274
}
 
275
#endif
 
276
 
 
277
#endif