Apache Portable Runtime Utility Library
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
27extern "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
106typedef 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
115typedef 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 */
124typedef struct apr_crypto_driver_t apr_crypto_driver_t;
125typedef struct apr_crypto_t apr_crypto_t;
126typedef struct apr_crypto_config_t apr_crypto_config_t;
127typedef struct apr_crypto_key_t apr_crypto_key_t;
128typedef struct apr_crypto_block_t apr_crypto_block_t;
129
130typedef 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
137typedef struct apr_crypto_block_key_mode_t {
138 apr_crypto_block_key_mode_e mode;
139} apr_crypto_block_key_mode_t;
140
141typedef 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
149typedef struct apr_crypto_secret_t {
150 const unsigned char *secret;
151 apr_size_t secretLen;
152} apr_crypto_secret_t;
153
154typedef enum {
156 APR_CRYPTO_KTYPE_PASSPHRASE = 1,
158 APR_CRYPTO_KTYPE_SECRET = 2,
159} apr_crypto_key_type;
160
161typedef 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
178APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
179
187APU_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
188 apr_size_t size);
189
197APU_DECLARE(apr_status_t) apr_crypto_memzero(void *buffer, apr_size_t size);
198
208APU_DECLARE(int) apr_crypto_equals(const void *buf1, const void *buf2,
209 apr_size_t size);
210
229APU_DECLARE(apr_status_t) apr_crypto_get_driver(
230 const apr_crypto_driver_t **driver,
231 const char *name, const char *params, const apu_err_t **result,
232 apr_pool_t *pool);
233
240APU_DECLARE(const char *) apr_crypto_driver_name(
241 const apr_crypto_driver_t *driver);
242
250APU_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
251 const apr_crypto_t *f);
252
268APU_DECLARE(apr_status_t) apr_crypto_make(apr_crypto_t **f,
269 const apr_crypto_driver_t *driver, const char *params,
270 apr_pool_t *pool);
271
281APU_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
282 const apr_crypto_t *f);
283
293APU_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
294 const apr_crypto_t *f);
295
312APU_DECLARE(apr_status_t) apr_crypto_key(apr_crypto_key_t **key,
313 const apr_crypto_key_rec_t *rec, const apr_crypto_t *f, apr_pool_t *p);
314
344APU_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key,
345 apr_size_t *ivSize, const char *pass, apr_size_t passLen,
346 const unsigned char * salt, apr_size_t saltLen,
347 const apr_crypto_block_key_type_e type,
348 const apr_crypto_block_key_mode_e mode, const int doPad,
349 const int iterations, const apr_crypto_t *f, apr_pool_t *p);
350
367APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_init(
368 apr_crypto_block_t **ctx, const unsigned char **iv,
369 const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p);
370
389APU_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out,
390 apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
391 apr_crypto_block_t *ctx);
392
411APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
412 apr_size_t *outlen, apr_crypto_block_t *ctx);
413
427APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_init(
428 apr_crypto_block_t **ctx, apr_size_t *blockSize,
429 const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p);
430
449APU_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out,
450 apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
451 apr_crypto_block_t *ctx);
452
471APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
472 apr_size_t *outlen, apr_crypto_block_t *ctx);
473
480APU_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
481
488APU_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
489
496APU_DECLARE(apr_status_t) apr_crypto_shutdown(
497 const apr_crypto_driver_t *driver);
498
499#endif /* APU_HAVE_CRYPTO */
500
503#ifdef __cplusplus
504}
505#endif
506
507#endif
APR-Util Error Codes.
Definition: apu_errno.h:161