1109998Smarkm/* ====================================================================
2109998Smarkm * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
3109998Smarkm *
4109998Smarkm * Redistribution and use in source and binary forms, with or without
5109998Smarkm * modification, are permitted provided that the following conditions
6109998Smarkm * are met:
7109998Smarkm *
8109998Smarkm * 1. Redistributions of source code must retain the above copyright
9280304Sjkim *    notice, this list of conditions and the following disclaimer.
10109998Smarkm *
11109998Smarkm * 2. Redistributions in binary form must reproduce the above copyright
12109998Smarkm *    notice, this list of conditions and the following disclaimer in
13109998Smarkm *    the documentation and/or other materials provided with the
14109998Smarkm *    distribution.
15109998Smarkm *
16109998Smarkm * 3. All advertising materials mentioning features or use of this
17109998Smarkm *    software must display the following acknowledgment:
18109998Smarkm *    "This product includes software developed by the OpenSSL Project
19109998Smarkm *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20109998Smarkm *
21109998Smarkm * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22109998Smarkm *    endorse or promote products derived from this software without
23109998Smarkm *    prior written permission. For written permission, please contact
24109998Smarkm *    licensing@OpenSSL.org.
25109998Smarkm *
26109998Smarkm * 5. Products derived from this software may not be called "OpenSSL"
27109998Smarkm *    nor may "OpenSSL" appear in their names without prior written
28109998Smarkm *    permission of the OpenSSL Project.
29109998Smarkm *
30109998Smarkm * 6. Redistributions of any form whatsoever must retain the following
31109998Smarkm *    acknowledgment:
32109998Smarkm *    "This product includes software developed by the OpenSSL Project
33109998Smarkm *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34109998Smarkm *
35109998Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36109998Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37109998Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38109998Smarkm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
39109998Smarkm * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40109998Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41109998Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42109998Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43109998Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44109998Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45109998Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46109998Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE.
47109998Smarkm * ====================================================================
48109998Smarkm *
49109998Smarkm * This product includes cryptographic software written by Eric Young
50109998Smarkm * (eay@cryptsoft.com).  This product includes software written by Tim
51109998Smarkm * Hudson (tjh@cryptsoft.com).
52109998Smarkm *
53109998Smarkm */
54109998Smarkm
55109998Smarkm#include "eng_int.h"
56109998Smarkm
57280304Sjkim/*
58280304Sjkim * If this symbol is defined then ENGINE_get_default_DSA(), the function that
59280304Sjkim * is used by DSA to hook in implementation code and cache defaults (etc),
60280304Sjkim * will display brief debugging summaries to stderr with the 'nid'.
61280304Sjkim */
62109998Smarkm/* #define ENGINE_DSA_DEBUG */
63109998Smarkm
64109998Smarkmstatic ENGINE_TABLE *dsa_table = NULL;
65109998Smarkmstatic const int dummy_nid = 1;
66109998Smarkm
67109998Smarkmvoid ENGINE_unregister_DSA(ENGINE *e)
68280304Sjkim{
69280304Sjkim    engine_table_unregister(&dsa_table, e);
70280304Sjkim}
71109998Smarkm
72109998Smarkmstatic void engine_unregister_all_DSA(void)
73280304Sjkim{
74280304Sjkim    engine_table_cleanup(&dsa_table);
75280304Sjkim}
76109998Smarkm
77109998Smarkmint ENGINE_register_DSA(ENGINE *e)
78280304Sjkim{
79280304Sjkim    if (e->dsa_meth)
80280304Sjkim        return engine_table_register(&dsa_table,
81280304Sjkim                                     engine_unregister_all_DSA, e, &dummy_nid,
82280304Sjkim                                     1, 0);
83280304Sjkim    return 1;
84280304Sjkim}
85109998Smarkm
86109998Smarkmvoid ENGINE_register_all_DSA()
87280304Sjkim{
88280304Sjkim    ENGINE *e;
89109998Smarkm
90280304Sjkim    for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
91280304Sjkim        ENGINE_register_DSA(e);
92280304Sjkim}
93109998Smarkm
94109998Smarkmint ENGINE_set_default_DSA(ENGINE *e)
95280304Sjkim{
96280304Sjkim    if (e->dsa_meth)
97280304Sjkim        return engine_table_register(&dsa_table,
98280304Sjkim                                     engine_unregister_all_DSA, e, &dummy_nid,
99280304Sjkim                                     1, 1);
100280304Sjkim    return 1;
101280304Sjkim}
102109998Smarkm
103280304Sjkim/*
104280304Sjkim * Exposed API function to get a functional reference from the implementation
105109998Smarkm * table (ie. try to get a functional reference from the tabled structural
106280304Sjkim * references).
107280304Sjkim */
108109998SmarkmENGINE *ENGINE_get_default_DSA(void)
109280304Sjkim{
110280304Sjkim    return engine_table_select(&dsa_table, dummy_nid);
111280304Sjkim}
112109998Smarkm
113109998Smarkm/* Obtains an DSA implementation from an ENGINE functional reference */
114109998Smarkmconst DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
115280304Sjkim{
116280304Sjkim    return e->dsa_meth;
117280304Sjkim}
118109998Smarkm
119109998Smarkm/* Sets an DSA implementation in an ENGINE structure */
120109998Smarkmint ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
121280304Sjkim{
122280304Sjkim    e->dsa_meth = dsa_meth;
123280304Sjkim    return 1;
124280304Sjkim}
125