1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* crypto/engine/eng_lib.c */ 2656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * project 2000. 4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ==================================================================== 6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 7656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Redistribution and use in source and binary forms, with or without 9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modification, are permitted provided that the following conditions 10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * are met: 11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1. Redistributions of source code must retain the above copyright 13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer. 14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * notice, this list of conditions and the following disclaimer in 17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * the documentation and/or other materials provided with the 18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * distribution. 19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 3. All advertising materials mentioning features or use of this 21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * software must display the following acknowledgment: 22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes software developed by the OpenSSL Project 23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * endorse or promote products derived from this software without 27656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * prior written permission. For written permission, please contact 28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * licensing@OpenSSL.org. 29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5. Products derived from this software may not be called "OpenSSL" 31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * nor may "OpenSSL" appear in their names without prior written 32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * permission of the OpenSSL Project. 33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 6. Redistributions of any form whatsoever must retain the following 35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * acknowledgment: 36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "This product includes software developed by the OpenSSL Project 37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OF THE POSSIBILITY OF SUCH DAMAGE. 51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ==================================================================== 52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This product includes cryptographic software written by Eric Young 54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * (eay@cryptsoft.com). This product includes software written by Tim 55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Hudson (tjh@cryptsoft.com). 56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */ 58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include "eng_int.h" 60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/rand.h> 61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* The "new"/"free" stuff first */ 63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectENGINE *ENGINE_new(void) 65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINE *ret; 67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE)); 69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(ret == NULL) 70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE); 72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return NULL; 73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 74656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project memset(ret, 0, sizeof(ENGINE)); 75656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ret->struct_ref = 1; 76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project engine_ref_debug(ret, 0, 1) 77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data); 78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return ret; 79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 81656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Placed here (close proximity to ENGINE_new) so that modifications to the 82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * elements of the ENGINE structure are more likely to be caught and changed 83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * here. */ 84656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid engine_set_all_null(ENGINE *e) 85656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->id = NULL; 87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->name = NULL; 88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->rsa_meth = NULL; 89656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->dsa_meth = NULL; 90656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->dh_meth = NULL; 91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->rand_meth = NULL; 92656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->store_meth = NULL; 93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->ciphers = NULL; 94656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->digests = NULL; 95656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->destroy = NULL; 96656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->init = NULL; 97656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->finish = NULL; 98656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->ctrl = NULL; 99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->load_privkey = NULL; 100656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->load_pubkey = NULL; 101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->cmd_defns = NULL; 102656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->flags = 0; 103656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 104656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 105656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint engine_free_util(ENGINE *e, int locked) 106656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 107656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project int i; 108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 109656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(e == NULL) 110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 111656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL, 112656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ERR_R_PASSED_NULL_PARAMETER); 113656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 0; 114656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 115656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(locked) 116656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE); 117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project else 118656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project i = --e->struct_ref; 119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project engine_ref_debug(e, 0, -1) 120656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (i > 0) return 1; 121656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef REF_CHECK 122656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if (i < 0) 123656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 124656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project fprintf(stderr,"ENGINE_free, bad structural reference count\n"); 125656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project abort(); 126656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 127656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif 128656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* Give the ENGINE a chance to do any structural cleanup corresponding 129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * to allocation it did in its constructor (eg. unload error strings) */ 130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(e->destroy) 131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->destroy(e); 132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data); 133656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project OPENSSL_free(e); 134656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 135656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 136656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 137656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_free(ENGINE *e) 138656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 139656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return engine_free_util(e, 1); 140656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 141656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Cleanup stuff */ 143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ENGINE_cleanup() is coded such that anything that does work that will need 145656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * cleanup can register a "cleanup" callback here. That way we don't get linker 146656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * bloat by referring to all *possible* cleanups, but any linker bloat into code 147656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * "X" will cause X's cleanup function to end up here. */ 148656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL; 149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int int_cleanup_check(int create) 150656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(cleanup_stack) return 1; 152656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(!create) return 0; 153656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null(); 154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return (cleanup_stack ? 1 : 0); 155656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb) 157656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 158656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof( 159656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINE_CLEANUP_ITEM)); 160656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(!item) return NULL; 161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project item->cb = cb; 162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return item; 163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 164656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb) 165656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 166656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINE_CLEANUP_ITEM *item; 167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(!int_cleanup_check(1)) return; 168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project item = int_cleanup_item(cb); 169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(item) 170656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0); 171656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 172656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb) 173656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 174656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINE_CLEANUP_ITEM *item; 175656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(!int_cleanup_check(1)) return; 176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project item = int_cleanup_item(cb); 177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(item) 178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item); 179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 180656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* The API function that performs all cleanup */ 181656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item) 182656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 183656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project (*(item->cb))(); 184656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project OPENSSL_free(item); 185656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 186656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid ENGINE_cleanup(void) 187656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 188656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(int_cleanup_check(0)) 189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack, 191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project engine_cleanup_cb_free); 192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project cleanup_stack = NULL; 193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 194656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project /* FIXME: This should be handled (somehow) through RAND, eg. by it 195656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * registering a cleanup callback. */ 196656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project RAND_set_rand_method(NULL); 197656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 198656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 199656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Now the "ex_data" support */ 200656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 201656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 202656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 203656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 204656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp, 205656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project new_func, dup_func, free_func); 206656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 207656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 208656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_ex_data(ENGINE *e, int idx, void *arg) 209656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 210656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(CRYPTO_set_ex_data(&e->ex_data, idx, arg)); 211656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 212656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 213656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid *ENGINE_get_ex_data(const ENGINE *e, int idx) 214656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 215656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return(CRYPTO_get_ex_data(&e->ex_data, idx)); 216656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 217656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 218656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Functions to get/set an ENGINE's elements - mainly to avoid exposing the 219656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ENGINE structure itself. */ 220656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 221656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_id(ENGINE *e, const char *id) 222656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 223656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(id == NULL) 224656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 225656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINEerr(ENGINE_F_ENGINE_SET_ID, 226656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ERR_R_PASSED_NULL_PARAMETER); 227656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 0; 228656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 229656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->id = id; 230656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 231656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 232656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 233656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_name(ENGINE *e, const char *name) 234656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 235656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project if(name == NULL) 236656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 237656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ENGINEerr(ENGINE_F_ENGINE_SET_NAME, 238656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project ERR_R_PASSED_NULL_PARAMETER); 239656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 0; 240656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 241656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->name = name; 242656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 243656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 244656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 245656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f) 246656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 247656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->destroy = destroy_f; 248656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 249656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 250656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 251656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f) 252656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 253656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->init = init_f; 254656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 255656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 256656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 257656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f) 258656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 259656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->finish = finish_f; 260656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 261656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 262656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 263656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f) 264656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 265656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->ctrl = ctrl_f; 266656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 267656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 268656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 269656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_flags(ENGINE *e, int flags) 270656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 271656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->flags = flags; 272656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 273656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 274656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 275656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns) 276656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 277656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project e->cmd_defns = defns; 278656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return 1; 279656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 280656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 281656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst char *ENGINE_get_id(const ENGINE *e) 282656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 283656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->id; 284656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 285656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 286656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst char *ENGINE_get_name(const ENGINE *e) 287656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 288656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->name; 289656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 290656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 291656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e) 292656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 293656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->destroy; 294656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 295656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 296656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e) 297656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 298656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->init; 299656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 300656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 301656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e) 302656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 303656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->finish; 304656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 305656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 306656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e) 307656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 308656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->ctrl; 309656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 310656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 311656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint ENGINE_get_flags(const ENGINE *e) 312656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 313656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->flags; 314656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 315656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 316656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e) 317656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 318656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return e->cmd_defns; 319656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 320656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 321656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* eng_lib.o is pretty much linked into anything that touches ENGINE already, so 322656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * put the "static_state" hack here. */ 323656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 324656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectstatic int internal_static_hack = 0; 325656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project 326656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid *ENGINE_get_static_state(void) 327656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project { 328656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project return &internal_static_hack; 329656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project } 330