Apache Portable Runtime Utility Library
 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_OPENSSL
44 #define APU_CRYPTO_RECOMMENDED_DRIVER "openssl"
45 #else
46 #if APU_HAVE_NSS
47 #define APU_CRYPTO_RECOMMENDED_DRIVER "nss"
48 #else
49 #if APU_HAVE_MSCNG
50 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscng"
51 #else
52 #if APU_HAVE_MSCAPI
53 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscapi"
54 #else
55 #endif
56 #endif
57 #endif
58 #endif
59 #endif
60 
102 typedef enum
103 {
104  APR_KEY_NONE, APR_KEY_3DES_192,
105  APR_KEY_AES_128,
106  APR_KEY_AES_192,
107  APR_KEY_AES_256
109 } apr_crypto_block_key_type_e;
110 
111 typedef enum
112 {
113  APR_MODE_NONE,
114  APR_MODE_ECB,
115  APR_MODE_CBC
117 } apr_crypto_block_key_mode_e;
118 
119 /* These are opaque structs. Instantiation is up to each backend */
120 typedef struct apr_crypto_driver_t apr_crypto_driver_t;
121 typedef struct apr_crypto_t apr_crypto_t;
122 typedef struct apr_crypto_config_t apr_crypto_config_t;
123 typedef struct apr_crypto_key_t apr_crypto_key_t;
124 typedef struct apr_crypto_block_t apr_crypto_block_t;
125 
132 APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
133 
142 APU_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
143  apr_size_t size);
144 
163 APU_DECLARE(apr_status_t) apr_crypto_get_driver(
164  const apr_crypto_driver_t **driver,
165  const char *name, const char *params, const apu_err_t **result,
166  apr_pool_t *pool);
167 
174 APU_DECLARE(const char *) apr_crypto_driver_name(
175  const apr_crypto_driver_t *driver);
176 
184 APU_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
185  const apr_crypto_t *f);
186 
202 APU_DECLARE(apr_status_t) apr_crypto_make(apr_crypto_t **f,
203  const apr_crypto_driver_t *driver, const char *params,
204  apr_pool_t *pool);
205 
214 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
215  const apr_crypto_t *f);
216 
225 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
226  const apr_crypto_t *f);
227 
256 APU_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key,
257  apr_size_t *ivSize, const char *pass, apr_size_t passLen,
258  const unsigned char * salt, apr_size_t saltLen,
259  const apr_crypto_block_key_type_e type,
260  const apr_crypto_block_key_mode_e mode, const int doPad,
261  const int iterations, const apr_crypto_t *f, apr_pool_t *p);
262 
279 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_init(
280  apr_crypto_block_t **ctx, const unsigned char **iv,
281  const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p);
282 
301 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out,
302  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
303  apr_crypto_block_t *ctx);
304 
323 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
324  apr_size_t *outlen, apr_crypto_block_t *ctx);
325 
339 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_init(
340  apr_crypto_block_t **ctx, apr_size_t *blockSize,
341  const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p);
342 
361 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out,
362  apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
363  apr_crypto_block_t *ctx);
364 
383 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
384  apr_size_t *outlen, apr_crypto_block_t *ctx);
385 
392 APU_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
393 
400 APU_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
401 
408 APU_DECLARE(apr_status_t) apr_crypto_shutdown(
409  const apr_crypto_driver_t *driver);
410 
411 #endif /* APU_HAVE_CRYPTO */
412 
415 #ifdef __cplusplus
416 }
417 #endif
418 
419 #endif