175584Sru/* 2151497Sru * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. 3151497Sru * 475584Sru * Licensed under the Apache License 2.0 (the "License"). You may not use 575584Sru * this file except in compliance with the License. You can obtain a copy 675584Sru * in the file LICENSE in the source distribution or at 775584Sru * https://www.openssl.org/source/license.html 875584Sru */ 975584Sru 1075584Sru/* We need to use some engine deprecated APIs */ 1175584Sru#define OPENSSL_SUPPRESS_DEPRECATED 1275584Sru 1375584Sru#include "eng_local.h" 1475584Sru 1575584Srustatic ENGINE_TABLE *dh_table = NULL; 1675584Srustatic const int dummy_nid = 1; 1775584Sru 1875584Sruvoid ENGINE_unregister_DH(ENGINE *e) 1975584Sru{ 20151497Sru engine_table_unregister(&dh_table, e); 2175584Sru} 2275584Sru 2375584Srustatic void engine_unregister_all_DH(void) 2475584Sru{ 2575584Sru engine_table_cleanup(&dh_table); 2675584Sru} 2775584Sru 2875584Sruint ENGINE_register_DH(ENGINE *e) 2975584Sru{ 3075584Sru if (e->dh_meth) 3175584Sru return engine_table_register(&dh_table, 3275584Sru engine_unregister_all_DH, e, &dummy_nid, 3375584Sru 1, 0); 3475584Sru return 1; 3575584Sru} 3675584Sru 3775584Sruvoid ENGINE_register_all_DH(void) 3875584Sru{ 3975584Sru ENGINE *e; 4075584Sru 4175584Sru for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) 4275584Sru ENGINE_register_DH(e); 4375584Sru} 4475584Sru 4575584Sruint ENGINE_set_default_DH(ENGINE *e) 4675584Sru{ 4775584Sru if (e->dh_meth) 4875584Sru return engine_table_register(&dh_table, 4975584Sru engine_unregister_all_DH, e, &dummy_nid, 5075584Sru 1, 1); 5175584Sru return 1; 5275584Sru} 5375584Sru 5475584Sru/* 5575584Sru * Exposed API function to get a functional reference from the implementation 5675584Sru * table (ie. try to get a functional reference from the tabled structural 5775584Sru * references). 5875584Sru */ 5975584SruENGINE *ENGINE_get_default_DH(void) 6075584Sru{ 6175584Sru return ossl_engine_table_select(&dh_table, dummy_nid, 6275584Sru OPENSSL_FILE, OPENSSL_LINE); 6375584Sru} 6475584Sru 6575584Sru/* Obtains an DH implementation from an ENGINE functional reference */ 6675584Sruconst DH_METHOD *ENGINE_get_DH(const ENGINE *e) 6775584Sru{ 6875584Sru return e->dh_meth; 6975584Sru} 7075584Sru 7175584Sru/* Sets an DH implementation in an ENGINE structure */ 7275584Sruint ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) 7375584Sru{ 7475584Sru e->dh_meth = dh_meth; 7575584Sru return 1; 7675584Sru} 7775584Sru