11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci/* We need to use some engine deprecated APIs */
111cb0ef41Sopenharmony_ci#define OPENSSL_SUPPRESS_DEPRECATED
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#include "eng_local.h"
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cistatic ENGINE_TABLE *dh_table = NULL;
161cb0ef41Sopenharmony_cistatic const int dummy_nid = 1;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_civoid ENGINE_unregister_DH(ENGINE *e)
191cb0ef41Sopenharmony_ci{
201cb0ef41Sopenharmony_ci    engine_table_unregister(&dh_table, e);
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cistatic void engine_unregister_all_DH(void)
241cb0ef41Sopenharmony_ci{
251cb0ef41Sopenharmony_ci    engine_table_cleanup(&dh_table);
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciint ENGINE_register_DH(ENGINE *e)
291cb0ef41Sopenharmony_ci{
301cb0ef41Sopenharmony_ci    if (e->dh_meth)
311cb0ef41Sopenharmony_ci        return engine_table_register(&dh_table,
321cb0ef41Sopenharmony_ci                                     engine_unregister_all_DH, e, &dummy_nid,
331cb0ef41Sopenharmony_ci                                     1, 0);
341cb0ef41Sopenharmony_ci    return 1;
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_civoid ENGINE_register_all_DH(void)
381cb0ef41Sopenharmony_ci{
391cb0ef41Sopenharmony_ci    ENGINE *e;
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci    for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
421cb0ef41Sopenharmony_ci        ENGINE_register_DH(e);
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciint ENGINE_set_default_DH(ENGINE *e)
461cb0ef41Sopenharmony_ci{
471cb0ef41Sopenharmony_ci    if (e->dh_meth)
481cb0ef41Sopenharmony_ci        return engine_table_register(&dh_table,
491cb0ef41Sopenharmony_ci                                     engine_unregister_all_DH, e, &dummy_nid,
501cb0ef41Sopenharmony_ci                                     1, 1);
511cb0ef41Sopenharmony_ci    return 1;
521cb0ef41Sopenharmony_ci}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci/*
551cb0ef41Sopenharmony_ci * Exposed API function to get a functional reference from the implementation
561cb0ef41Sopenharmony_ci * table (ie. try to get a functional reference from the tabled structural
571cb0ef41Sopenharmony_ci * references).
581cb0ef41Sopenharmony_ci */
591cb0ef41Sopenharmony_ciENGINE *ENGINE_get_default_DH(void)
601cb0ef41Sopenharmony_ci{
611cb0ef41Sopenharmony_ci    return ossl_engine_table_select(&dh_table, dummy_nid,
621cb0ef41Sopenharmony_ci                                    OPENSSL_FILE, OPENSSL_LINE);
631cb0ef41Sopenharmony_ci}
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci/* Obtains an DH implementation from an ENGINE functional reference */
661cb0ef41Sopenharmony_ciconst DH_METHOD *ENGINE_get_DH(const ENGINE *e)
671cb0ef41Sopenharmony_ci{
681cb0ef41Sopenharmony_ci    return e->dh_meth;
691cb0ef41Sopenharmony_ci}
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci/* Sets an DH implementation in an ENGINE structure */
721cb0ef41Sopenharmony_ciint ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
731cb0ef41Sopenharmony_ci{
741cb0ef41Sopenharmony_ci    e->dh_meth = dh_meth;
751cb0ef41Sopenharmony_ci    return 1;
761cb0ef41Sopenharmony_ci}
77