15c87c606SMark Murray /* ==================================================================== 25c87c606SMark Murray * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 35c87c606SMark Murray * 45c87c606SMark Murray * Redistribution and use in source and binary forms, with or without 55c87c606SMark Murray * modification, are permitted provided that the following conditions 65c87c606SMark Murray * are met: 75c87c606SMark Murray * 85c87c606SMark Murray * 1. Redistributions of source code must retain the above copyright 95c87c606SMark Murray * notice, this list of conditions and the following disclaimer. 105c87c606SMark Murray * 115c87c606SMark Murray * 2. Redistributions in binary form must reproduce the above copyright 125c87c606SMark Murray * notice, this list of conditions and the following disclaimer in 135c87c606SMark Murray * the documentation and/or other materials provided with the 145c87c606SMark Murray * distribution. 155c87c606SMark Murray * 165c87c606SMark Murray * 3. All advertising materials mentioning features or use of this 175c87c606SMark Murray * software must display the following acknowledgment: 185c87c606SMark Murray * "This product includes software developed by the OpenSSL Project 195c87c606SMark Murray * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 205c87c606SMark Murray * 215c87c606SMark Murray * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 225c87c606SMark Murray * endorse or promote products derived from this software without 235c87c606SMark Murray * prior written permission. For written permission, please contact 245c87c606SMark Murray * licensing@OpenSSL.org. 255c87c606SMark Murray * 265c87c606SMark Murray * 5. Products derived from this software may not be called "OpenSSL" 275c87c606SMark Murray * nor may "OpenSSL" appear in their names without prior written 285c87c606SMark Murray * permission of the OpenSSL Project. 295c87c606SMark Murray * 305c87c606SMark Murray * 6. Redistributions of any form whatsoever must retain the following 315c87c606SMark Murray * acknowledgment: 325c87c606SMark Murray * "This product includes software developed by the OpenSSL Project 335c87c606SMark Murray * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 345c87c606SMark Murray * 355c87c606SMark Murray * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 365c87c606SMark Murray * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 375c87c606SMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 385c87c606SMark Murray * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 395c87c606SMark Murray * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 405c87c606SMark Murray * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 415c87c606SMark Murray * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 425c87c606SMark Murray * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 435c87c606SMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 445c87c606SMark Murray * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 455c87c606SMark Murray * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 465c87c606SMark Murray * OF THE POSSIBILITY OF SUCH DAMAGE. 475c87c606SMark Murray * ==================================================================== 485c87c606SMark Murray * 495c87c606SMark Murray * This product includes cryptographic software written by Eric Young 505c87c606SMark Murray * (eay@cryptsoft.com). This product includes software written by Tim 515c87c606SMark Murray * Hudson (tjh@cryptsoft.com). 525c87c606SMark Murray * 535c87c606SMark Murray */ 545c87c606SMark Murray 555c87c606SMark Murray #include <openssl/evp.h> 565c87c606SMark Murray #include <openssl/engine.h> 575c87c606SMark Murray #include "eng_int.h" 585c87c606SMark Murray 595c87c606SMark Murray /* If this symbol is defined then ENGINE_get_default_DSA(), the function that is 605c87c606SMark Murray * used by DSA to hook in implementation code and cache defaults (etc), will 615c87c606SMark Murray * display brief debugging summaries to stderr with the 'nid'. */ 625c87c606SMark Murray /* #define ENGINE_DSA_DEBUG */ 635c87c606SMark Murray 645c87c606SMark Murray static ENGINE_TABLE *dsa_table = NULL; 655c87c606SMark Murray static const int dummy_nid = 1; 665c87c606SMark Murray 675c87c606SMark Murray void ENGINE_unregister_DSA(ENGINE *e) 685c87c606SMark Murray { 695c87c606SMark Murray engine_table_unregister(&dsa_table, e); 705c87c606SMark Murray } 715c87c606SMark Murray 725c87c606SMark Murray static void engine_unregister_all_DSA(void) 735c87c606SMark Murray { 745c87c606SMark Murray engine_table_cleanup(&dsa_table); 755c87c606SMark Murray } 765c87c606SMark Murray 775c87c606SMark Murray int ENGINE_register_DSA(ENGINE *e) 785c87c606SMark Murray { 795c87c606SMark Murray if(e->dsa_meth) 805c87c606SMark Murray return engine_table_register(&dsa_table, 815c87c606SMark Murray engine_unregister_all_DSA, e, &dummy_nid, 1, 0); 825c87c606SMark Murray return 1; 835c87c606SMark Murray } 845c87c606SMark Murray 855c87c606SMark Murray void ENGINE_register_all_DSA() 865c87c606SMark Murray { 875c87c606SMark Murray ENGINE *e; 885c87c606SMark Murray 895c87c606SMark Murray for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e)) 905c87c606SMark Murray ENGINE_register_DSA(e); 915c87c606SMark Murray } 925c87c606SMark Murray 935c87c606SMark Murray int ENGINE_set_default_DSA(ENGINE *e) 945c87c606SMark Murray { 955c87c606SMark Murray if(e->dsa_meth) 965c87c606SMark Murray return engine_table_register(&dsa_table, 975c87c606SMark Murray engine_unregister_all_DSA, e, &dummy_nid, 1, 0); 985c87c606SMark Murray return 1; 995c87c606SMark Murray } 1005c87c606SMark Murray 1015c87c606SMark Murray /* Exposed API function to get a functional reference from the implementation 1025c87c606SMark Murray * table (ie. try to get a functional reference from the tabled structural 1035c87c606SMark Murray * references). */ 1045c87c606SMark Murray ENGINE *ENGINE_get_default_DSA(void) 1055c87c606SMark Murray { 1065c87c606SMark Murray return engine_table_select(&dsa_table, dummy_nid); 1075c87c606SMark Murray } 1085c87c606SMark Murray 1095c87c606SMark Murray /* Obtains an DSA implementation from an ENGINE functional reference */ 1105c87c606SMark Murray const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e) 1115c87c606SMark Murray { 1125c87c606SMark Murray return e->dsa_meth; 1135c87c606SMark Murray } 1145c87c606SMark Murray 1155c87c606SMark Murray /* Sets an DSA implementation in an ENGINE structure */ 1165c87c606SMark Murray int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth) 1175c87c606SMark Murray { 1185c87c606SMark Murray e->dsa_meth = dsa_meth; 1195c87c606SMark Murray return 1; 1205c87c606SMark Murray } 121