1 /* 2 * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #include "eng_local.h" 11 12 static ENGINE_TABLE *dh_table = NULL; 13 static const int dummy_nid = 1; 14 15 void ENGINE_unregister_DH(ENGINE *e) 16 { 17 engine_table_unregister(&dh_table, e); 18 } 19 20 static void engine_unregister_all_DH(void) 21 { 22 engine_table_cleanup(&dh_table); 23 } 24 25 int ENGINE_register_DH(ENGINE *e) 26 { 27 if (e->dh_meth) 28 return engine_table_register(&dh_table, 29 engine_unregister_all_DH, e, &dummy_nid, 30 1, 0); 31 return 1; 32 } 33 34 void ENGINE_register_all_DH(void) 35 { 36 ENGINE *e; 37 38 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) 39 ENGINE_register_DH(e); 40 } 41 42 int ENGINE_set_default_DH(ENGINE *e) 43 { 44 if (e->dh_meth) 45 return engine_table_register(&dh_table, 46 engine_unregister_all_DH, e, &dummy_nid, 47 1, 1); 48 return 1; 49 } 50 51 /* 52 * Exposed API function to get a functional reference from the implementation 53 * table (ie. try to get a functional reference from the tabled structural 54 * references). 55 */ 56 ENGINE *ENGINE_get_default_DH(void) 57 { 58 return engine_table_select(&dh_table, dummy_nid); 59 } 60 61 /* Obtains an DH implementation from an ENGINE functional reference */ 62 const DH_METHOD *ENGINE_get_DH(const ENGINE *e) 63 { 64 return e->dh_meth; 65 } 66 67 /* Sets an DH implementation in an ENGINE structure */ 68 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) 69 { 70 e->dh_meth = dh_meth; 71 return 1; 72 } 73