14ee2ad04344446e610172a0e73949212923014dfSebastian Redl/* ====================================================================
22cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
32cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *
42cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * Redistribution and use in source and binary forms, with or without
52cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * modification, are permitted provided that the following conditions
62cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * are met:
72cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *
82cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * 1. Redistributions of source code must retain the above copyright
92cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *    notice, this list of conditions and the following disclaimer.
10a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl *
112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * 2. Redistributions in binary form must reproduce the above copyright
122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *    notice, this list of conditions and the following disclaimer in
132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *    the documentation and/or other materials provided with the
147faa2ec03a7ef120ac165bb45b6c70a8b20c9f1cSebastian Redl *    distribution.
1589d9980bbc2e4a4ac86673e6ec16fb9f5babb63bDouglas Gregor *
160eca89e9890db4d8336ce762a5b359a1d58ca02bArgyrios Kyrtzidis * 3. All advertising materials mentioning features or use of this
17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor *    software must display the following acknowledgment:
18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor *    "This product includes software developed by the OpenSSL Project
192cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *
212cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
222a7fb27913999d132cf9e10e03dc5271faa2e9d3John McCall *    endorse or promote products derived from this software without
2389eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis *    prior written permission. For written permission, please contact
240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor *    licensing@OpenSSL.org.
257a1fad38256eb4c5129359be85ba1ea1678eb5c9John McCall *
262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * 5. Products derived from this software may not be called "OpenSSL"
27a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall *    nor may "OpenSSL" appear in their names without prior written
286ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl *    permission of the OpenSSL Project.
297c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner *
306a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor * 6. Redistributions of any form whatsoever must retain the following
317c5d24efcd2e505b5739f7def08dfe25ce59a1b2Chris Lattner *    acknowledgment:
3283d63c78810556d26b62ac4cbae2eda6cdd2570cSteve Naroff *    "This product includes software developed by the OpenSSL Project
3314f79002e58556798e86168c63e48d533287eda5Douglas Gregor *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
3410e286aa8d39fb51a21412850265d9dae74613eeChris Lattner *
353251ceb90b3fec68e86d6dcfa58836e20a7205c3Douglas Gregor * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
3614f79002e58556798e86168c63e48d533287eda5Douglas Gregor * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37bd94500d3aa60092fb0f1e90f53fb0d03fa502a8Douglas Gregor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
382bec0410d268779f601bd509e0302a500af7ac6aDouglas Gregor * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
39ab41e63821dc60ad144d0684df8d79a9eef86b75Douglas Gregor * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
432596e429a61602312bdd149786045b8a90cd2d10Daniel Dunbar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45fbfd180495e7800975c6d9bdc6d24e706ef70e34Michael J. Spencer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
4614f79002e58556798e86168c63e48d533287eda5Douglas Gregor * OF THE POSSIBILITY OF SUCH DAMAGE.
4703013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer * ====================================================================
48f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor *
493c304bd9ec2b4611572d4cbae9e1727bbecb5dc9Chris Lattner * This product includes cryptographic software written by Eric Young
50cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor * (eay@cryptsoft.com).  This product includes software written by Tim
51f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor * Hudson (tjh@cryptsoft.com).
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor *
538538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl */
542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
55ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl#include "eng_int.h"
565f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner
575f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
585f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner * used by DSA to hook in implementation code and cache defaults (etc), will
596e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer * display brief debugging summaries to stderr with the 'nid'. */
60ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl/* #define ENGINE_DSA_DEBUG */
616e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramer
626e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramerstatic ENGINE_TABLE *dsa_table = NULL;
635f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic const int dummy_nid = 1;
645f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner
656e089c687cc2b914c46859ab7e46fe4c3c6b0afbBenjamin Kramervoid ENGINE_unregister_DSA(ENGINE *e)
66ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl	{
67ade5000c8763f4bec41f452d7efa3a9b2a6d4712Sebastian Redl	engine_table_unregister(&dsa_table, e);
682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	}
692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorstatic void engine_unregister_all_DSA(void)
7112b1c7615d4f9a2edc544be499f895f16ac100edChris Lattner	{
722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	engine_table_cleanup(&dsa_table);
733397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl	}
74a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl
7589eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidisint ENGINE_register_DSA(ENGINE *e)
762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	{
772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	if(e->dsa_meth)
782cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor		return engine_table_register(&dsa_table,
798538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl				engine_unregister_all_DSA, e, &dummy_nid, 1, 0);
802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	return 1;
8189eaf3af92c72c0c1aae807644e39cabc461d685Argyrios Kyrtzidis	}
828538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl
832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ENGINE_register_all_DSA()
842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	{
852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	ENGINE *e;
862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
872cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor		ENGINE_register_DSA(e);
892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	}
902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorint ENGINE_set_default_DSA(ENGINE *e)
922cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	{
932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	if(e->dsa_meth)
943397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl		return engine_table_register(&dsa_table,
952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor				engine_unregister_all_DSA, e, &dummy_nid, 1, 1);
962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	return 1;
972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	}
983397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl
992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/* Exposed API function to get a functional reference from the implementation
1008538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl * table (ie. try to get a functional reference from the tabled structural
1012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * references). */
1022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorENGINE *ENGINE_get_default_DSA(void)
1033397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl	{
1042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	return engine_table_select(&dsa_table, dummy_nid);
1058538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl	}
1062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/* Obtains an DSA implementation from an ENGINE functional reference */
1083397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redlconst DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump	{
1108538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl	return e->dsa_meth;
1112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	}
1122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl/* Sets an DSA implementation in an ENGINE structure */
114df1550fc59b51681d37225934fe4e3acac321621Richard Smithint ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
115df1550fc59b51681d37225934fe4e3acac321621Richard Smith	{
1168538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl	e->dsa_meth = dsa_meth;
1172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	return 1;
1182cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor	}
1193397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl