GME  13
apr_crypto.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APR_CRYPTO_H
00018 #define APR_CRYPTO_H
00019 
00020 #include "apu.h"
00021 #include "apr_pools.h"
00022 #include "apr_tables.h"
00023 #include "apr_hash.h"
00024 #include "apu_errno.h"
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00040 #if APU_HAVE_CRYPTO
00041 
00042 #ifndef APU_CRYPTO_RECOMMENDED_DRIVER
00043 #if APU_HAVE_OPENSSL
00044 #define APU_CRYPTO_RECOMMENDED_DRIVER "openssl"
00045 #else
00046 #if APU_HAVE_NSS
00047 #define APU_CRYPTO_RECOMMENDED_DRIVER "nss"
00048 #else
00049 #if APU_HAVE_MSCNG
00050 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscng"
00051 #else
00052 #if APU_HAVE_MSCAPI
00053 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscapi"
00054 #else
00055 #endif
00056 #endif
00057 #endif
00058 #endif
00059 #endif
00060 
00102 typedef enum
00103 {
00104     APR_KEY_NONE, APR_KEY_3DES_192, 
00105     APR_KEY_AES_128, 
00106     APR_KEY_AES_192, 
00107     APR_KEY_AES_256
00109 } apr_crypto_block_key_type_e;
00110 
00111 typedef enum
00112 {
00113     APR_MODE_NONE, 
00114     APR_MODE_ECB, 
00115     APR_MODE_CBC
00117 } apr_crypto_block_key_mode_e;
00118 
00119 /* These are opaque structs.  Instantiation is up to each backend */
00120 typedef struct apr_crypto_driver_t apr_crypto_driver_t;
00121 typedef struct apr_crypto_t apr_crypto_t;
00122 typedef struct apr_crypto_config_t apr_crypto_config_t;
00123 typedef struct apr_crypto_key_t apr_crypto_key_t;
00124 typedef struct apr_crypto_block_t apr_crypto_block_t;
00125 
00132 APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool);
00133 
00142 APU_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer,
00143         apr_size_t size);
00144 
00163 APU_DECLARE(apr_status_t) apr_crypto_get_driver(
00164         const apr_crypto_driver_t **driver,
00165         const char *name, const char *params, const apu_err_t **result,
00166         apr_pool_t *pool);
00167 
00174 APU_DECLARE(const char *) apr_crypto_driver_name(
00175         const apr_crypto_driver_t *driver);
00176 
00184 APU_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result,
00185         const apr_crypto_t *f);
00186 
00202 APU_DECLARE(apr_status_t) apr_crypto_make(apr_crypto_t **f,
00203         const apr_crypto_driver_t *driver, const char *params,
00204         apr_pool_t *pool);
00205 
00214 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types,
00215         const apr_crypto_t *f);
00216 
00225 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes,
00226         const apr_crypto_t *f);
00227 
00256 APU_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key,
00257         apr_size_t *ivSize, const char *pass, apr_size_t passLen,
00258         const unsigned char * salt, apr_size_t saltLen,
00259         const apr_crypto_block_key_type_e type,
00260         const apr_crypto_block_key_mode_e mode, const int doPad,
00261         const int iterations, const apr_crypto_t *f, apr_pool_t *p);
00262 
00279 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_init(
00280         apr_crypto_block_t **ctx, const unsigned char **iv,
00281         const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p);
00282 
00301 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out,
00302         apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
00303         apr_crypto_block_t *ctx);
00304 
00323 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out,
00324         apr_size_t *outlen, apr_crypto_block_t *ctx);
00325 
00339 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_init(
00340         apr_crypto_block_t **ctx, apr_size_t *blockSize,
00341         const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p);
00342 
00361 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out,
00362         apr_size_t *outlen, const unsigned char *in, apr_size_t inlen,
00363         apr_crypto_block_t *ctx);
00364 
00383 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out,
00384         apr_size_t *outlen, apr_crypto_block_t *ctx);
00385 
00392 APU_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx);
00393 
00400 APU_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f);
00401 
00408 APU_DECLARE(apr_status_t) apr_crypto_shutdown(
00409         const apr_crypto_driver_t *driver);
00410 
00411 #endif /* APU_HAVE_CRYPTO */
00412 
00415 #ifdef __cplusplus
00416 }
00417 #endif
00418 
00419 #endif