Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
apr_crypto.h
Go to the documentation of this file.
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_H
18 #define APR_CRYPTO_H
19 
20 #include "apu.h"
21 #include "apr_pools.h"
22 #include "apr_tables.h"
23 #include "apr_hash.h"
24 #include "apu_errno.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
40 #if APU_HAVE_CRYPTO
41 
42 #ifndef APU_CRYPTO_RECOMMENDED_DRIVER
43 #if APU_HAVE_COMMONCRYPTO
44 #define APU_CRYPTO_RECOMMENDED_DRIVER "commoncrypto"
45 #else
46 #if APU_HAVE_OPENSSL
47 #define APU_CRYPTO_RECOMMENDED_DRIVER "openssl"
48 #else
49 #if APU_HAVE_NSS
50 #define APU_CRYPTO_RECOMMENDED_DRIVER "nss"
51 #else
52 #if APU_HAVE_MSCNG
53 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscng"
54 #else
55 #if APU_HAVE_MSCAPI
56 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscapi"
57 #else
58 #endif
59 #endif
60 #endif
61 #endif
62 #endif
63 #endif
64 
106 typedef enum
107 {
108  APR_KEY_NONE, APR_KEY_3DES_192,
109  APR_KEY_AES_128,
110  APR_KEY_AES_192,
111  APR_KEY_AES_256
113 } apr_crypto_block_key_type_e;
114 
115 typedef enum
116 {
117  APR_MODE_NONE,
118  APR_MODE_ECB,
119  APR_MODE_CBC
121 } apr_crypto_block_key_mode_e;
122 
123 /* These are opaque structs. Instantiation is up to each backend */
124 typedef struct apr_crypto_driver_t apr_crypto_driver_t;
125 typedef struct apr_crypto_t apr_crypto_t;
126 typedef struct apr_crypto_config_t apr_crypto_config_t;
127 typedef struct apr_crypto_key_t apr_crypto_key_t;
128 typedef struct apr_crypto_block_t apr_crypto_block_t;
129 
130 typedef struct apr_crypto_block_key_type_t {
131  apr_crypto_block_key_type_e type;
132  int keysize;
133  int blocksize;
134  int ivsize;
135 } apr_crypto_block_key_type_t;
136 
137 typedef struct apr_crypto_block_key_mode_t {
138  apr_crypto_block_key_mode_e mode;
139 } apr_crypto_block_key_mode_t;
140 
141 typedef struct apr_crypto_passphrase_t {
142  const char *pass;
143  apr_size_t passLen;
144  const unsigned char * salt;
145  apr_size_t saltLen;
146  int iterations;
147 } apr_crypto_passphrase_t;
148 
149 typedef struct apr_crypto_secret_t {
150  const unsigned char *secret;
151  apr_size_t secretLen;
152 } apr_crypto_secret_t;
153 
154 typedef enum {
156  APR_CRYPTO_KTYPE_PASSPHRASE = 1,
158  APR_CRYPTO_KTYPE_SECRET = 2,
159 } apr_crypto_key_type;
160 
161 typedef struct apr_crypto_key_rec_t {
162  apr_crypto_key_type ktype;
163  apr_crypto_block_key_type_e type;
164  apr_crypto_block_key_mode_e mode;
165  int pad;
166  union {
167  apr_crypto_passphrase_t passphrase;
168  apr_crypto_secret_t secret;
169  } k;
170 } apr_crypto_key_rec_t;
171 
178 APR_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
179 
187 APR_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
188  apr_size_t size);
189 
197 APR_DECLARE(apr_status_t) apr_crypto_memzero(void *buffer, apr_size_t size);
198 
208 APR_DECLARE(int) apr_crypto_equals(const void *buf1, const void *buf2,
209  apr_size_t size);
210 
229 APR_DECLARE(apr_status_t) apr_crypto_get_driver(
230  const apr_crypto_driver_t **driver, const char *name,
231  const char *params, const apu_err_t **result, apr_pool_t *pool);
232 
239 APR_DECLARE(const char *) apr_crypto_driver_name(
240  const apr_crypto_driver_t *driver);
241 
249 APR_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
250  const apr_crypto_t *f);
251 
268  apr_crypto_make(apr_crypto_t **f, const apr_crypto_driver_t *driver,
269  const char *params, apr_pool_t *pool);
270 
280 APR_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
281  const apr_crypto_t *f);
282 
292 APR_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
293  const apr_crypto_t *f);
294 
311 APR_DECLARE(apr_status_t) apr_crypto_key(apr_crypto_key_t **key,
312  const apr_crypto_key_rec_t *rec, const apr_crypto_t *f, apr_pool_t *p);
313 
343 APR_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key,
344  apr_size_t *ivSize, const char *pass, apr_size_t passLen,
345  const unsigned char * salt, apr_size_t saltLen,
346  const apr_crypto_block_key_type_e type,
347  const apr_crypto_block_key_mode_e mode, const int doPad,
348  const int iterations, const apr_crypto_t *f, apr_pool_t *p);
349 
366 APR_DECLARE(apr_status_t) apr_crypto_block_encrypt_init(
367  apr_crypto_block_t **ctx, const unsigned char **iv,
368  const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p);
369 
388 APR_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out,
389  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
390  apr_crypto_block_t *ctx);
391 
410 APR_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
411  apr_size_t *outlen, apr_crypto_block_t *ctx);
412 
426 APR_DECLARE(apr_status_t) apr_crypto_block_decrypt_init(
427  apr_crypto_block_t **ctx, apr_size_t *blockSize,
428  const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p);
429 
448 APR_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out,
449  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
450  apr_crypto_block_t *ctx);
451 
470 APR_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
471  apr_size_t *outlen, apr_crypto_block_t *ctx);
472 
479 APR_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
480 
487 APR_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
488 
496  apr_crypto_shutdown(const apr_crypto_driver_t *driver);
497 
498 #endif /* APU_HAVE_CRYPTO */
499 
502 #ifdef __cplusplus
503 }
504 #endif
505 
506 #endif
size_t apr_size_t
Definition: apr.h:375
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:556
APR Hash Tables.
APR-Util Error Codes.
dav_buffer apr_size_t size
Definition: mod_dav.h:461
APR memory allocation.
APR Table library.
struct apr_hash_t apr_hash_t
Definition: apr_hash.h:52
apr_pool_t * p
#define APR_DECLARE(x)
Definition: macros.h:6
dav_buffer const void apr_size_t apr_size_t pad
Definition: mod_dav.h:481
const char * name
Definition: mod_dav.h:730
Definition: apu_errno.h:161
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int apr_status_t
Definition: apr_errno.h:44