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 #include "apr_thread_proc.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
41 #if APU_HAVE_CRYPTO
42 
43 #ifndef APU_CRYPTO_RECOMMENDED_DRIVER
44 #if APU_HAVE_COMMONCRYPTO
45 #define APU_CRYPTO_RECOMMENDED_DRIVER "commoncrypto"
46 #elif APU_HAVE_OPENSSL
47 #define APU_CRYPTO_RECOMMENDED_DRIVER "openssl"
48 #elif APU_HAVE_NSS
49 #define APU_CRYPTO_RECOMMENDED_DRIVER "nss"
50 #elif APU_HAVE_MSCNG
51 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscng"
52 #elif APU_HAVE_MSCAPI
53 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscapi"
54 #endif
55 #endif /* APU_CRYPTO_RECOMMENDED_DRIVER */
56 
98 typedef enum
99 {
100  APR_KEY_NONE, APR_KEY_3DES_192,
101  APR_KEY_AES_128,
102  APR_KEY_AES_192,
103  APR_KEY_AES_256
105 } apr_crypto_block_key_type_e;
106 
107 typedef enum
108 {
109  APR_MODE_NONE,
110  APR_MODE_ECB,
111  APR_MODE_CBC
113 } apr_crypto_block_key_mode_e;
114 
115 /* These are opaque structs. Instantiation is up to each backend */
116 typedef struct apr_crypto_driver_t apr_crypto_driver_t;
117 typedef struct apr_crypto_t apr_crypto_t;
118 typedef struct apr_crypto_config_t apr_crypto_config_t;
119 typedef struct apr_crypto_key_t apr_crypto_key_t;
120 typedef struct apr_crypto_block_t apr_crypto_block_t;
121 
122 typedef struct apr_crypto_block_key_type_t {
123  apr_crypto_block_key_type_e type;
124  int keysize;
125  int blocksize;
126  int ivsize;
127 } apr_crypto_block_key_type_t;
128 
129 typedef struct apr_crypto_block_key_mode_t {
130  apr_crypto_block_key_mode_e mode;
131 } apr_crypto_block_key_mode_t;
132 
133 typedef struct apr_crypto_passphrase_t {
134  const char *pass;
135  apr_size_t passLen;
136  const unsigned char * salt;
137  apr_size_t saltLen;
138  int iterations;
139 } apr_crypto_passphrase_t;
140 
141 typedef struct apr_crypto_secret_t {
142  const unsigned char *secret;
143  apr_size_t secretLen;
144 } apr_crypto_secret_t;
145 
146 typedef enum {
148  APR_CRYPTO_KTYPE_PASSPHRASE = 1,
150  APR_CRYPTO_KTYPE_SECRET = 2,
151 } apr_crypto_key_type;
152 
153 typedef struct apr_crypto_key_rec_t {
154  apr_crypto_key_type ktype;
155  apr_crypto_block_key_type_e type;
156  apr_crypto_block_key_mode_e mode;
157  int pad;
158  union {
159  apr_crypto_passphrase_t passphrase;
160  apr_crypto_secret_t secret;
161  } k;
162 } apr_crypto_key_rec_t;
163 
170 APR_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
171 
172 /* TODO: doxygen */
173 APR_DECLARE(apr_status_t) apr_crypto_lib_version(const char *name,
174  const char **version);
175 APR_DECLARE(apr_status_t) apr_crypto_lib_init(const char *name,
176  const char *params,
177  const apu_err_t **result,
178  apr_pool_t *pool);
179 APR_DECLARE(apr_status_t) apr_crypto_lib_term(const char *name);
180 APR_DECLARE(int) apr_crypto_lib_is_active(const char *name);
181 
189 APR_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
190  apr_size_t size);
191 
199 APR_DECLARE(apr_status_t) apr_crypto_memzero(void *buffer, apr_size_t size);
200 
210 APR_DECLARE(int) apr_crypto_equals(const void *buf1, const void *buf2,
211  apr_size_t size);
212 
231 APR_DECLARE(apr_status_t) apr_crypto_get_driver(
232  const apr_crypto_driver_t **driver, const char *name,
233  const char *params, const apu_err_t **result, apr_pool_t *pool);
234 
241 APR_DECLARE(const char *) apr_crypto_driver_name(
242  const apr_crypto_driver_t *driver);
243 
251 APR_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
252  const apr_crypto_t *f);
253 
270  apr_crypto_make(apr_crypto_t **f, const apr_crypto_driver_t *driver,
271  const char *params, apr_pool_t *pool);
272 
282 APR_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
283  const apr_crypto_t *f);
284 
294 APR_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
295  const apr_crypto_t *f);
296 
313 APR_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 APR_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 APR_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 APR_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 APR_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
413  apr_size_t *outlen, apr_crypto_block_t *ctx);
414 
428 APR_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 APR_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 APR_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
473  apr_size_t *outlen, apr_crypto_block_t *ctx);
474 
481 APR_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
482 
489 APR_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
490 
498  apr_crypto_shutdown(const apr_crypto_driver_t *driver);
499 
500 
501 #if APU_HAVE_CRYPTO_PRNG
502 
523 #define APR_CRYPTO_PRNG_SEED_SIZE 32
524 
525 #define APR_CRYPTO_PRNG_LOCKED (0x1)
526 #define APR_CRYPTO_PRNG_PER_THREAD (0x2)
527 #define APR_CRYPTO_PRNG_MASK (0x3)
528 
530 typedef struct apr_crypto_prng_t apr_crypto_prng_t;
531 
544 APR_DECLARE(apr_status_t) apr_crypto_prng_init(apr_pool_t *pool,
545  apr_size_t bufsize,
546  const unsigned char seed[],
547  int flags);
553 APR_DECLARE(apr_status_t) apr_crypto_prng_term(void);
554 
562 APR_DECLARE(apr_status_t) apr_crypto_prng_after_fork(apr_proc_t *proc);
563 
572 APR_DECLARE(apr_status_t) apr_crypto_random_bytes(void *buf, apr_size_t len);
573 
574 #if APR_HAS_THREADS
575 
585 APR_DECLARE(apr_status_t) apr_crypto_random_thread_bytes(void *buf,
586  apr_size_t len);
587 #endif
588 
607 APR_DECLARE(apr_status_t) apr_crypto_prng_create(apr_crypto_prng_t **pcprng,
608  apr_size_t bufsize, int flags,
609  const unsigned char seed[],
610  apr_pool_t *pool);
611 
618 APR_DECLARE(apr_status_t) apr_crypto_prng_destroy(apr_crypto_prng_t *cprng);
619 
628 APR_DECLARE(apr_status_t) apr_crypto_prng_reseed(apr_crypto_prng_t *cprng,
629  const unsigned char seed[]);
630 
639 APR_DECLARE(apr_status_t) apr_crypto_prng_bytes(apr_crypto_prng_t *cprng,
640  void *buf, apr_size_t len);
641 #endif /* APU_HAVE_CRYPTO_PRNG */
642 
643 #endif /* APU_HAVE_CRYPTO */
644 
647 #ifdef __cplusplus
648 }
649 #endif
650 
651 #endif
size_t apr_size_t
Definition: apr.h:375
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:552
APR Hash Tables.
Definition: apr_thread_proc.h:144
APR-Util Error Codes.
dav_buffer apr_size_t size
Definition: mod_dav.h:457
APR memory allocation.
APR Table library.
struct apr_hash_t apr_hash_t
Definition: apr_hash.h:52
apr_pool_t * p
APR Thread and Process Library.
#define APR_DECLARE(x)
Definition: macros.h:6
dav_buffer const void apr_size_t apr_size_t pad
Definition: mod_dav.h:477
const char * name
Definition: mod_dav.h:726
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
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1346