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_digest_engine(), the function 59280304Sjkim * that is used by EVP to hook in digest code and cache defaults (etc), will 60280304Sjkim * display brief debugging summaries to stderr with the 'nid'. 61280304Sjkim */ 62109998Smarkm/* #define ENGINE_DIGEST_DEBUG */ 63109998Smarkm 64109998Smarkmstatic ENGINE_TABLE *digest_table = NULL; 65109998Smarkm 66109998Smarkmvoid ENGINE_unregister_digests(ENGINE *e) 67280304Sjkim{ 68280304Sjkim engine_table_unregister(&digest_table, e); 69280304Sjkim} 70109998Smarkm 71109998Smarkmstatic void engine_unregister_all_digests(void) 72280304Sjkim{ 73280304Sjkim engine_table_cleanup(&digest_table); 74280304Sjkim} 75109998Smarkm 76109998Smarkmint ENGINE_register_digests(ENGINE *e) 77280304Sjkim{ 78280304Sjkim if (e->digests) { 79280304Sjkim const int *nids; 80280304Sjkim int num_nids = e->digests(e, NULL, &nids, 0); 81280304Sjkim if (num_nids > 0) 82280304Sjkim return engine_table_register(&digest_table, 83280304Sjkim engine_unregister_all_digests, e, 84280304Sjkim nids, num_nids, 0); 85280304Sjkim } 86280304Sjkim return 1; 87280304Sjkim} 88109998Smarkm 89109998Smarkmvoid ENGINE_register_all_digests() 90280304Sjkim{ 91280304Sjkim ENGINE *e; 92109998Smarkm 93280304Sjkim for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) 94280304Sjkim ENGINE_register_digests(e); 95280304Sjkim} 96109998Smarkm 97109998Smarkmint ENGINE_set_default_digests(ENGINE *e) 98280304Sjkim{ 99280304Sjkim if (e->digests) { 100280304Sjkim const int *nids; 101280304Sjkim int num_nids = e->digests(e, NULL, &nids, 0); 102280304Sjkim if (num_nids > 0) 103280304Sjkim return engine_table_register(&digest_table, 104280304Sjkim engine_unregister_all_digests, e, 105280304Sjkim nids, num_nids, 1); 106280304Sjkim } 107280304Sjkim return 1; 108280304Sjkim} 109109998Smarkm 110280304Sjkim/* 111280304Sjkim * Exposed API function to get a functional reference from the implementation 112109998Smarkm * table (ie. try to get a functional reference from the tabled structural 113280304Sjkim * references) for a given digest 'nid' 114280304Sjkim */ 115109998SmarkmENGINE *ENGINE_get_digest_engine(int nid) 116280304Sjkim{ 117280304Sjkim return engine_table_select(&digest_table, nid); 118280304Sjkim} 119109998Smarkm 120109998Smarkm/* Obtains a digest implementation from an ENGINE functional reference */ 121109998Smarkmconst EVP_MD *ENGINE_get_digest(ENGINE *e, int nid) 122280304Sjkim{ 123280304Sjkim const EVP_MD *ret; 124280304Sjkim ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); 125280304Sjkim if (!fn || !fn(e, &ret, NULL, nid)) { 126280304Sjkim ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, ENGINE_R_UNIMPLEMENTED_DIGEST); 127280304Sjkim return NULL; 128280304Sjkim } 129280304Sjkim return ret; 130280304Sjkim} 131109998Smarkm 132109998Smarkm/* Gets the digest callback from an ENGINE structure */ 133109998SmarkmENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e) 134280304Sjkim{ 135280304Sjkim return e->digests; 136280304Sjkim} 137109998Smarkm 138109998Smarkm/* Sets the digest callback in an ENGINE structure */ 139109998Smarkmint ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f) 140280304Sjkim{ 141280304Sjkim e->digests = f; 142280304Sjkim return 1; 143280304Sjkim} 144