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
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 APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
179 
187 APU_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
188  apr_size_t size);
189 
197 APU_DECLARE(apr_status_t) apr_crypto_memzero(void *buffer, apr_size_t size);
198 
208 APU_DECLARE(int) apr_crypto_equals(const void *buf1, const void *buf2,
209  apr_size_t size);
210 
229 APU_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 
240 APU_DECLARE(const char *) apr_crypto_driver_name(
241  const apr_crypto_driver_t *driver);
242 
250 APU_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
251  const apr_crypto_t *f);
252 
269 APU_DECLARE(apr_status_t) apr_crypto_make(apr_crypto_t **f,
270  const apr_crypto_driver_t *driver, const char *params,
271  apr_pool_t *pool);
272 
282 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
283  const apr_crypto_t *f);
284 
294 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
295  const apr_crypto_t *f);
296 
313 APU_DECLARE(apr_status_t) apr_crypto_key(apr_crypto_key_t **key,
314  const apr_crypto_key_rec_t *rec, const apr_crypto_t *f, apr_pool_t *p);
315 
345 APU_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key,
346  apr_size_t *ivSize, const char *pass, apr_size_t passLen,
347  const unsigned char * salt, apr_size_t saltLen,
348  const apr_crypto_block_key_type_e type,
349  const apr_crypto_block_key_mode_e mode, const int doPad,
350  const int iterations, const apr_crypto_t *f, apr_pool_t *p);
351 
368 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_init(
369  apr_crypto_block_t **ctx, const unsigned char **iv,
370  const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p);
371 
390 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out,
391  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
392  apr_crypto_block_t *ctx);
393 
412 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
413  apr_size_t *outlen, apr_crypto_block_t *ctx);
414 
428 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_init(
429  apr_crypto_block_t **ctx, apr_size_t *blockSize,
430  const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p);
431 
450 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out,
451  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
452  apr_crypto_block_t *ctx);
453 
472 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
473  apr_size_t *outlen, apr_crypto_block_t *ctx);
474 
481 APU_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
482 
489 APU_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
490 
497 APU_DECLARE(apr_status_t) apr_crypto_shutdown(
498  const apr_crypto_driver_t *driver);
499 
500 #endif /* APU_HAVE_CRYPTO */
501 
504 #ifdef __cplusplus
505 }
506 #endif
507 
508 #endif
APR-Util Error Codes.
Definition: apu_errno.h:161