1109998Smarkm/* crypto/engine/eng_fat.c */ 2109998Smarkm/* ==================================================================== 3109998Smarkm * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 4109998Smarkm * 5109998Smarkm * Redistribution and use in source and binary forms, with or without 6109998Smarkm * modification, are permitted provided that the following conditions 7109998Smarkm * are met: 8109998Smarkm * 9109998Smarkm * 1. Redistributions of source code must retain the above copyright 10280304Sjkim * notice, this list of conditions and the following disclaimer. 11109998Smarkm * 12109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright 13109998Smarkm * notice, this list of conditions and the following disclaimer in 14109998Smarkm * the documentation and/or other materials provided with the 15109998Smarkm * distribution. 16109998Smarkm * 17109998Smarkm * 3. All advertising materials mentioning features or use of this 18109998Smarkm * software must display the following acknowledgment: 19109998Smarkm * "This product includes software developed by the OpenSSL Project 20109998Smarkm * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 21109998Smarkm * 22109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23109998Smarkm * endorse or promote products derived from this software without 24109998Smarkm * prior written permission. For written permission, please contact 25109998Smarkm * licensing@OpenSSL.org. 26109998Smarkm * 27109998Smarkm * 5. Products derived from this software may not be called "OpenSSL" 28109998Smarkm * nor may "OpenSSL" appear in their names without prior written 29109998Smarkm * permission of the OpenSSL Project. 30109998Smarkm * 31109998Smarkm * 6. Redistributions of any form whatsoever must retain the following 32109998Smarkm * acknowledgment: 33109998Smarkm * "This product includes software developed by the OpenSSL Project 34109998Smarkm * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 35109998Smarkm * 36109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39109998Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE. 48109998Smarkm * ==================================================================== 49109998Smarkm * 50109998Smarkm * This product includes cryptographic software written by Eric Young 51109998Smarkm * (eay@cryptsoft.com). This product includes software written by Tim 52109998Smarkm * Hudson (tjh@cryptsoft.com). 53109998Smarkm * 54109998Smarkm */ 55160814Ssimon/* ==================================================================== 56160814Ssimon * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 57280304Sjkim * ECDH support in OpenSSL originally developed by 58160814Ssimon * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 59160814Ssimon */ 60109998Smarkm 61109998Smarkm#include "eng_int.h" 62109998Smarkm#include <openssl/conf.h> 63109998Smarkm 64109998Smarkmint ENGINE_set_default(ENGINE *e, unsigned int flags) 65280304Sjkim{ 66280304Sjkim if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) 67280304Sjkim return 0; 68280304Sjkim if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) 69280304Sjkim return 0; 70109998Smarkm#ifndef OPENSSL_NO_RSA 71280304Sjkim if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) 72280304Sjkim return 0; 73109998Smarkm#endif 74109998Smarkm#ifndef OPENSSL_NO_DSA 75280304Sjkim if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) 76280304Sjkim return 0; 77109998Smarkm#endif 78109998Smarkm#ifndef OPENSSL_NO_DH 79280304Sjkim if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) 80280304Sjkim return 0; 81109998Smarkm#endif 82160814Ssimon#ifndef OPENSSL_NO_ECDH 83280304Sjkim if ((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e)) 84280304Sjkim return 0; 85160814Ssimon#endif 86160814Ssimon#ifndef OPENSSL_NO_ECDSA 87280304Sjkim if ((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e)) 88280304Sjkim return 0; 89160814Ssimon#endif 90280304Sjkim if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) 91280304Sjkim return 0; 92280304Sjkim if ((flags & ENGINE_METHOD_PKEY_METHS) 93280304Sjkim && !ENGINE_set_default_pkey_meths(e)) 94280304Sjkim return 0; 95280304Sjkim if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS) 96280304Sjkim && !ENGINE_set_default_pkey_asn1_meths(e)) 97280304Sjkim return 0; 98280304Sjkim return 1; 99280304Sjkim} 100109998Smarkm 101109998Smarkm/* Set default algorithms using a string */ 102109998Smarkm 103109998Smarkmstatic int int_def_cb(const char *alg, int len, void *arg) 104280304Sjkim{ 105280304Sjkim unsigned int *pflags = arg; 106280304Sjkim if (alg == NULL) 107280304Sjkim return 0; 108280304Sjkim if (!strncmp(alg, "ALL", len)) 109280304Sjkim *pflags |= ENGINE_METHOD_ALL; 110280304Sjkim else if (!strncmp(alg, "RSA", len)) 111280304Sjkim *pflags |= ENGINE_METHOD_RSA; 112280304Sjkim else if (!strncmp(alg, "DSA", len)) 113280304Sjkim *pflags |= ENGINE_METHOD_DSA; 114280304Sjkim else if (!strncmp(alg, "ECDH", len)) 115280304Sjkim *pflags |= ENGINE_METHOD_ECDH; 116280304Sjkim else if (!strncmp(alg, "ECDSA", len)) 117280304Sjkim *pflags |= ENGINE_METHOD_ECDSA; 118280304Sjkim else if (!strncmp(alg, "DH", len)) 119280304Sjkim *pflags |= ENGINE_METHOD_DH; 120280304Sjkim else if (!strncmp(alg, "RAND", len)) 121280304Sjkim *pflags |= ENGINE_METHOD_RAND; 122280304Sjkim else if (!strncmp(alg, "CIPHERS", len)) 123280304Sjkim *pflags |= ENGINE_METHOD_CIPHERS; 124280304Sjkim else if (!strncmp(alg, "DIGESTS", len)) 125280304Sjkim *pflags |= ENGINE_METHOD_DIGESTS; 126280304Sjkim else if (!strncmp(alg, "PKEY", len)) 127280304Sjkim *pflags |= ENGINE_METHOD_PKEY_METHS | ENGINE_METHOD_PKEY_ASN1_METHS; 128280304Sjkim else if (!strncmp(alg, "PKEY_CRYPTO", len)) 129280304Sjkim *pflags |= ENGINE_METHOD_PKEY_METHS; 130280304Sjkim else if (!strncmp(alg, "PKEY_ASN1", len)) 131280304Sjkim *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS; 132280304Sjkim else 133280304Sjkim return 0; 134280304Sjkim return 1; 135280304Sjkim} 136109998Smarkm 137127128Snectarint ENGINE_set_default_string(ENGINE *e, const char *def_list) 138280304Sjkim{ 139280304Sjkim unsigned int flags = 0; 140280304Sjkim if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) { 141280304Sjkim ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, 142280304Sjkim ENGINE_R_INVALID_STRING); 143280304Sjkim ERR_add_error_data(2, "str=", def_list); 144280304Sjkim return 0; 145280304Sjkim } 146280304Sjkim return ENGINE_set_default(e, flags); 147280304Sjkim} 148109998Smarkm 149109998Smarkmint ENGINE_register_complete(ENGINE *e) 150280304Sjkim{ 151280304Sjkim ENGINE_register_ciphers(e); 152280304Sjkim ENGINE_register_digests(e); 153109998Smarkm#ifndef OPENSSL_NO_RSA 154280304Sjkim ENGINE_register_RSA(e); 155109998Smarkm#endif 156109998Smarkm#ifndef OPENSSL_NO_DSA 157280304Sjkim ENGINE_register_DSA(e); 158109998Smarkm#endif 159109998Smarkm#ifndef OPENSSL_NO_DH 160280304Sjkim ENGINE_register_DH(e); 161109998Smarkm#endif 162160814Ssimon#ifndef OPENSSL_NO_ECDH 163280304Sjkim ENGINE_register_ECDH(e); 164160814Ssimon#endif 165160814Ssimon#ifndef OPENSSL_NO_ECDSA 166280304Sjkim ENGINE_register_ECDSA(e); 167160814Ssimon#endif 168280304Sjkim ENGINE_register_RAND(e); 169280304Sjkim ENGINE_register_pkey_meths(e); 170280304Sjkim return 1; 171280304Sjkim} 172109998Smarkm 173109998Smarkmint ENGINE_register_all_complete(void) 174280304Sjkim{ 175280304Sjkim ENGINE *e; 176109998Smarkm 177280304Sjkim for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) 178280304Sjkim if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) 179280304Sjkim ENGINE_register_complete(e); 180280304Sjkim return 1; 181280304Sjkim} 182