Apache Portable Runtime Utility Library
|
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_COMMONCRYPTO 00044 #define APU_CRYPTO_RECOMMENDED_DRIVER "commoncrypto" 00045 #else 00046 #if APU_HAVE_OPENSSL 00047 #define APU_CRYPTO_RECOMMENDED_DRIVER "openssl" 00048 #else 00049 #if APU_HAVE_NSS 00050 #define APU_CRYPTO_RECOMMENDED_DRIVER "nss" 00051 #else 00052 #if APU_HAVE_MSCNG 00053 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscng" 00054 #else 00055 #if APU_HAVE_MSCAPI 00056 #define APU_CRYPTO_RECOMMENDED_DRIVER "mscapi" 00057 #else 00058 #endif 00059 #endif 00060 #endif 00061 #endif 00062 #endif 00063 #endif 00064 00106 typedef enum 00107 { 00108 APR_KEY_NONE, APR_KEY_3DES_192, 00109 APR_KEY_AES_128, 00110 APR_KEY_AES_192, 00111 APR_KEY_AES_256 00113 } apr_crypto_block_key_type_e; 00114 00115 typedef enum 00116 { 00117 APR_MODE_NONE, 00118 APR_MODE_ECB, 00119 APR_MODE_CBC 00121 } apr_crypto_block_key_mode_e; 00122 00123 /* These are opaque structs. Instantiation is up to each backend */ 00124 typedef struct apr_crypto_driver_t apr_crypto_driver_t; 00125 typedef struct apr_crypto_t apr_crypto_t; 00126 typedef struct apr_crypto_config_t apr_crypto_config_t; 00127 typedef struct apr_crypto_key_t apr_crypto_key_t; 00128 typedef struct apr_crypto_block_t apr_crypto_block_t; 00129 00130 typedef struct apr_crypto_block_key_type_t { 00131 apr_crypto_block_key_type_e type; 00132 int keysize; 00133 int blocksize; 00134 int ivsize; 00135 } apr_crypto_block_key_type_t; 00136 00137 typedef struct apr_crypto_block_key_mode_t { 00138 apr_crypto_block_key_mode_e mode; 00139 } apr_crypto_block_key_mode_t; 00140 00141 typedef struct apr_crypto_passphrase_t { 00142 const char *pass; 00143 apr_size_t passLen; 00144 const unsigned char * salt; 00145 apr_size_t saltLen; 00146 int iterations; 00147 } apr_crypto_passphrase_t; 00148 00149 typedef struct apr_crypto_secret_t { 00150 const unsigned char *secret; 00151 apr_size_t secretLen; 00152 } apr_crypto_secret_t; 00153 00154 typedef enum { 00156 APR_CRYPTO_KTYPE_PASSPHRASE = 1, 00158 APR_CRYPTO_KTYPE_SECRET = 2, 00159 } apr_crypto_key_type; 00160 00161 typedef struct apr_crypto_key_rec_t { 00162 apr_crypto_key_type ktype; 00163 apr_crypto_block_key_type_e type; 00164 apr_crypto_block_key_mode_e mode; 00165 int pad; 00166 union { 00167 apr_crypto_passphrase_t passphrase; 00168 apr_crypto_secret_t secret; 00169 } k; 00170 } apr_crypto_key_rec_t; 00171 00178 APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool); 00179 00187 APU_DECLARE(apr_status_t) apr_crypto_clear(apr_pool_t *pool, void *buffer, 00188 apr_size_t size); 00189 00197 APU_DECLARE(apr_status_t) apr_crypto_memzero(void *buffer, apr_size_t size); 00198 00208 APU_DECLARE(int) apr_crypto_equals(const void *buf1, const void *buf2, 00209 apr_size_t size); 00210 00229 APU_DECLARE(apr_status_t) apr_crypto_get_driver( 00230 const apr_crypto_driver_t **driver, 00231 const char *name, const char *params, const apu_err_t **result, 00232 apr_pool_t *pool); 00233 00240 APU_DECLARE(const char *) apr_crypto_driver_name( 00241 const apr_crypto_driver_t *driver); 00242 00250 APU_DECLARE(apr_status_t) apr_crypto_error(const apu_err_t **result, 00251 const apr_crypto_t *f); 00252 00268 APU_DECLARE(apr_status_t) apr_crypto_make(apr_crypto_t **f, 00269 const apr_crypto_driver_t *driver, const char *params, 00270 apr_pool_t *pool); 00271 00281 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_types(apr_hash_t **types, 00282 const apr_crypto_t *f); 00283 00293 APU_DECLARE(apr_status_t) apr_crypto_get_block_key_modes(apr_hash_t **modes, 00294 const apr_crypto_t *f); 00295 00312 APU_DECLARE(apr_status_t) apr_crypto_key(apr_crypto_key_t **key, 00313 const apr_crypto_key_rec_t *rec, const apr_crypto_t *f, apr_pool_t *p); 00314 00344 APU_DECLARE(apr_status_t) apr_crypto_passphrase(apr_crypto_key_t **key, 00345 apr_size_t *ivSize, const char *pass, apr_size_t passLen, 00346 const unsigned char * salt, apr_size_t saltLen, 00347 const apr_crypto_block_key_type_e type, 00348 const apr_crypto_block_key_mode_e mode, const int doPad, 00349 const int iterations, const apr_crypto_t *f, apr_pool_t *p); 00350 00367 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_init( 00368 apr_crypto_block_t **ctx, const unsigned char **iv, 00369 const apr_crypto_key_t *key, apr_size_t *blockSize, apr_pool_t *p); 00370 00389 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt(unsigned char **out, 00390 apr_size_t *outlen, const unsigned char *in, apr_size_t inlen, 00391 apr_crypto_block_t *ctx); 00392 00411 APU_DECLARE(apr_status_t) apr_crypto_block_encrypt_finish(unsigned char *out, 00412 apr_size_t *outlen, apr_crypto_block_t *ctx); 00413 00427 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_init( 00428 apr_crypto_block_t **ctx, apr_size_t *blockSize, 00429 const unsigned char *iv, const apr_crypto_key_t *key, apr_pool_t *p); 00430 00449 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt(unsigned char **out, 00450 apr_size_t *outlen, const unsigned char *in, apr_size_t inlen, 00451 apr_crypto_block_t *ctx); 00452 00471 APU_DECLARE(apr_status_t) apr_crypto_block_decrypt_finish(unsigned char *out, 00472 apr_size_t *outlen, apr_crypto_block_t *ctx); 00473 00480 APU_DECLARE(apr_status_t) apr_crypto_block_cleanup(apr_crypto_block_t *ctx); 00481 00488 APU_DECLARE(apr_status_t) apr_crypto_cleanup(apr_crypto_t *f); 00489 00496 APU_DECLARE(apr_status_t) apr_crypto_shutdown( 00497 const apr_crypto_driver_t *driver); 00498 00499 #endif /* APU_HAVE_CRYPTO */ 00500 00503 #ifdef __cplusplus 00504 } 00505 #endif 00506 00507 #endif