diff options
Diffstat (limited to 'include/private/apr_crypto_internal.h')
-rw-r--r-- | include/private/apr_crypto_internal.h | 130 |
1 files changed, 77 insertions, 53 deletions
diff --git a/include/private/apr_crypto_internal.h b/include/private/apr_crypto_internal.h index de109de5..b571451a 100644 --- a/include/private/apr_crypto_internal.h +++ b/include/private/apr_crypto_internal.h @@ -36,24 +36,47 @@ struct apr_crypto_driver_t { * @brief: allow driver to perform once-only initialisation. * Called once only. * @param pool The pool to register the cleanup in. - * @param params An array of optional init parameters. + * @param params Optional init parameter string. + * @param rc Driver-specific additional error code */ - apr_status_t (*init)(apr_pool_t *pool, const apr_array_header_t *params, int *rc); + apr_status_t (*init)(apr_pool_t *pool, const char *params, int *rc); /** * @brief Create a context for supporting encryption. Keys, certificates, * algorithms and other parameters will be set per context. More than * one context can be created at one time. A cleanup will be automatically * registered with the given pool to guarantee a graceful shutdown. - * @param driver - driver to use - * @param pool - process pool - * @param params - array of key parameters * @param f - context pointer will be written here + * @param provider - provider to use + * @param params - array of key parameters + * @param pool - process pool * @return APR_ENOENGINE when the engine specified does not exist. APR_EINITENGINE * if the engine cannot be initialised. */ - apr_status_t (*factory)(apr_pool_t *pool, const apr_array_header_t *params, - apr_crypto_t **f); + apr_status_t (*make)(apr_crypto_t **f, const apr_crypto_driver_t *provider, + const char *params, apr_pool_t *pool); + + /** + * @brief Get a hash table of key types, keyed by the name of the type against + * an integer pointer constant. + * + * @param types - hashtable of key types keyed to constants. + * @param f - encryption context + * @return APR_SUCCESS for success + */ + apr_status_t (*get_block_key_types)(apr_hash_t **types, + const apr_crypto_t *f); + + /** + * @brief Get a hash table of key modes, keyed by the name of the mode against + * an integer pointer constant. + * + * @param modes - hashtable of key modes keyed to constants. + * @param f - encryption context + * @return APR_SUCCESS for success + */ + apr_status_t (*get_block_key_modes)(apr_hash_t **modes, + const apr_crypto_t *f); /** * @brief Create a key from the given passphrase. By default, the PBKDF2 @@ -64,9 +87,9 @@ struct apr_crypto_driver_t { * operations. * @note If *key is NULL, a apr_crypto_key_t will be created from a pool. If * *key is not NULL, *key must point at a previously created structure. - * @param driver - driver to use - * @param p The pool to use. - * @param f The context to use. + * @param key The key returned, see note. + * @param ivSize The size of the initialisation vector will be returned, based + * on whether an IV is relevant for this type of crypto. * @param pass The passphrase to use. * @param passLen The passphrase length in bytes * @param salt The salt to use. @@ -74,43 +97,40 @@ struct apr_crypto_driver_t { * @param type 3DES_192, AES_128, AES_192, AES_256. * @param mode Electronic Code Book / Cipher Block Chaining. * @param doPad Pad if necessary. - * @param key The key returned, see note. - * @param ivSize The size of the initialisation vector will be returned, based - * on whether an IV is relevant for this type of crypto. + * @param iterations Iteration count + * @param f The context to use. + * @param p The pool to use. * @return Returns APR_ENOKEY if the pass phrase is missing or empty, or if a backend * error occurred while generating the key. APR_ENOCIPHER if the type or mode * is not supported by the particular backend. APR_EKEYTYPE if the key type is * not known. APR_EPADDING if padding was requested but is not supported. * APR_ENOTIMPL if not implemented. */ - apr_status_t (*passphrase)(apr_pool_t *p, const apr_crypto_t *f, + apr_status_t (*passphrase)(apr_crypto_key_t **key, apr_size_t *ivSize, const char *pass, apr_size_t passLen, const unsigned char * salt, apr_size_t saltLen, const apr_crypto_block_key_type_e type, const apr_crypto_block_key_mode_e mode, const int doPad, - const int iterations, apr_crypto_key_t **key, apr_size_t *ivSize); + const int iterations, const apr_crypto_t *f, apr_pool_t *p); /** * @brief Initialise a context for encrypting arbitrary data using the given key. * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If * *ctx is not NULL, *ctx must point at a previously created structure. - * @param p The pool to use. - * @param f The block factory to use. - * @param key The key structure. + * @param ctx The block context returned, see note. * @param iv Optional initialisation vector. If the buffer pointed to is NULL, * an IV will be created at random, in space allocated from the pool. * If the buffer pointed to is not NULL, the IV in the buffer will be * used. - * @param ctx The block context returned, see note. - * @param ivSize The size of the initialisation vector will be returned, based - * on whether an IV is relevant for this type of crypto. + * @param key The key structure. * @param blockSize The block size of the cipher. + * @param p The pool to use. * @return Returns APR_ENOIV if an initialisation vector is required but not specified. * Returns APR_EINIT if the backend failed to initialise the context. Returns * APR_ENOTIMPL if not implemented. */ - apr_status_t (*block_encrypt_init)(apr_pool_t *p, const apr_crypto_t *f, - const apr_crypto_key_t *key, const unsigned char **iv, - apr_crypto_block_t **ctx, apr_size_t *blockSize); + apr_status_t (*block_encrypt_init)(apr_crypto_block_t **ctx, + const unsigned char **iv, const apr_crypto_key_t *key, + apr_size_t *blockSize, apr_pool_t *p); /** * @brief Encrypt data provided by in, write it to out. @@ -121,17 +141,17 @@ struct apr_crypto_driver_t { * to NULL, a buffer sufficiently large will be created from * the pool provided. If *out points to a not-NULL value, this * value will be used as a buffer instead. - * @param ctx The block context to use. * @param out Address of a buffer to which data will be written, * see note. * @param outlen Length of the output will be written here. * @param in Address of the buffer to read. * @param inlen Length of the buffer to read. + * @param ctx The block context to use. * @return APR_ECRYPT if an error occurred. Returns APR_ENOTIMPL if * not implemented. */ - apr_status_t (*block_encrypt)(apr_crypto_block_t *ctx, unsigned char **out, - apr_size_t *outlen, const unsigned char *in, apr_size_t inlen); + apr_status_t (*block_encrypt)(unsigned char **out, apr_size_t *outlen, + const unsigned char *in, apr_size_t inlen, apr_crypto_block_t *ctx); /** * @brief Encrypt final data block, write it to out. @@ -141,38 +161,37 @@ struct apr_crypto_driver_t { * number of bytes returned as actually written by the * apr_crypto_block_encrypt() call. After this call, the context * is cleaned and can be reused by apr_crypto_block_encrypt_init(). - * @param ctx The block context to use. * @param out Address of a buffer to which data will be written. This * buffer must already exist, and is usually the same * buffer used by apr_evp_crypt(). See note. * @param outlen Length of the output will be written here. + * @param ctx The block context to use. * @return APR_ECRYPT if an error occurred. * @return APR_EPADDING if padding was enabled and the block was incorrectly * formatted. * @return APR_ENOTIMPL if not implemented. */ - apr_status_t (*block_encrypt_finish)(apr_crypto_block_t *ctx, - unsigned char *out, apr_size_t *outlen); + apr_status_t (*block_encrypt_finish)(unsigned char *out, + apr_size_t *outlen, apr_crypto_block_t *ctx); /** * @brief Initialise a context for decrypting arbitrary data using the given key. * @note If *ctx is NULL, a apr_crypto_block_t will be created from a pool. If * *ctx is not NULL, *ctx must point at a previously created structure. - * @param p The pool to use. - * @param f The block factory to use. - * @param key The key structure. + * @param ctx The block context returned, see note. + * @param blockSize The block size of the cipher. * @param iv Optional initialisation vector. If the buffer pointed to is NULL, * an IV will be created at random, in space allocated from the pool. * If the buffer is not NULL, the IV in the buffer will be used. - * @param ctx The block context returned, see note. - * @param blockSize The block size of the cipher. + * @param key The key structure. + * @param p The pool to use. * @return Returns APR_ENOIV if an initialisation vector is required but not specified. * Returns APR_EINIT if the backend failed to initialise the context. Returns * APR_ENOTIMPL if not implemented. */ - apr_status_t (*block_decrypt_init)(apr_pool_t *p, const apr_crypto_t *f, - const apr_crypto_key_t *key, const unsigned char *iv, - apr_crypto_block_t **ctx, apr_size_t *blockSize); + apr_status_t (*block_decrypt_init)(apr_crypto_block_t **ctx, + apr_size_t *blockSize, const unsigned char *iv, + const apr_crypto_key_t *key, apr_pool_t *p); /** * @brief Decrypt data provided by in, write it to out. @@ -183,17 +202,17 @@ struct apr_crypto_driver_t { * to NULL, a buffer sufficiently large will be created from * the pool provided. If *out points to a not-NULL value, this * value will be used as a buffer instead. - * @param ctx The block context to use. * @param out Address of a buffer to which data will be written, * see note. * @param outlen Length of the output will be written here. * @param in Address of the buffer to read. * @param inlen Length of the buffer to read. + * @param ctx The block context to use. * @return APR_ECRYPT if an error occurred. Returns APR_ENOTIMPL if * not implemented. */ - apr_status_t (*block_decrypt)(apr_crypto_block_t *ctx, unsigned char **out, - apr_size_t *outlen, const unsigned char *in, apr_size_t inlen); + apr_status_t (*block_decrypt)(unsigned char **out, apr_size_t *outlen, + const unsigned char *in, apr_size_t inlen, apr_crypto_block_t *ctx); /** * @brief Decrypt final data block, write it to out. @@ -203,44 +222,49 @@ struct apr_crypto_driver_t { * number of bytes returned as actually written by the * apr_crypto_block_decrypt() call. After this call, the context * is cleaned and can be reused by apr_crypto_block_decrypt_init(). - * @param ctx The block context to use. * @param out Address of a buffer to which data will be written. This * buffer must already exist, and is usually the same * buffer used by apr_evp_crypt(). See note. * @param outlen Length of the output will be written here. + * @param ctx The block context to use. * @return APR_ECRYPT if an error occurred. * @return APR_EPADDING if padding was enabled and the block was incorrectly * formatted. * @return APR_ENOTIMPL if not implemented. */ - apr_status_t (*block_decrypt_finish)(apr_crypto_block_t *ctx, - unsigned char *out, apr_size_t *outlen); + apr_status_t (*block_decrypt_finish)(unsigned char *out, + apr_size_t *outlen, apr_crypto_block_t *ctx); /** * @brief Clean encryption / decryption context. * @note After cleanup, a context is free to be reused if necessary. - * @param driver - driver to use * @param ctx The block context to use. * @return Returns APR_ENOTIMPL if not supported. */ apr_status_t (*block_cleanup)(apr_crypto_block_t *ctx); /** - * @brief Clean encryption / decryption factory. - * @note After cleanup, a factory is free to be reused if necessary. - * @param driver - driver to use - * @param f The factory to use. + * @brief Clean encryption / decryption context. + * @note After cleanup, a context is free to be reused if necessary. + * @param f The context to use. * @return Returns APR_ENOTIMPL if not supported. */ apr_status_t (*cleanup)(apr_crypto_t *f); /** - * @brief Clean encryption / decryption factory. - * @note After cleanup, a factory is free to be reused if necessary. - * @param pool The pool to use. + * @brief Clean encryption / decryption context. + * @note After cleanup, a context is free to be reused if necessary. * @return Returns APR_ENOTIMPL if not supported. */ - apr_status_t (*shutdown)(apr_pool_t *p); + apr_status_t (*shutdown)(void); + + /** + * @brief: fetch the most recent error from this driver. + * @param result - the result structure + * @param f - context pointer + * @return APR_SUCCESS for success. + */ + apr_status_t (*error)(const apu_err_t **result, const apr_crypto_t *f); }; |