2 * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 /* We need to use some engine deprecated APIs */
11 #define OPENSSL_SUPPRESS_DEPRECATED
13 #include "eng_local.h"
15 static ENGINE_TABLE *cipher_table = NULL;
17 void ENGINE_unregister_ciphers(ENGINE *e)
19 engine_table_unregister(&cipher_table, e);
22 static void engine_unregister_all_ciphers(void)
24 engine_table_cleanup(&cipher_table);
27 int ENGINE_register_ciphers(ENGINE *e)
31 int num_nids = e->ciphers(e, NULL, &nids, 0);
33 return engine_table_register(&cipher_table,
34 engine_unregister_all_ciphers, e,
40 void ENGINE_register_all_ciphers(void)
44 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
45 ENGINE_register_ciphers(e);
48 int ENGINE_set_default_ciphers(ENGINE *e)
52 int num_nids = e->ciphers(e, NULL, &nids, 0);
54 return engine_table_register(&cipher_table,
55 engine_unregister_all_ciphers, e,
62 * Exposed API function to get a functional reference from the implementation
63 * table (ie. try to get a functional reference from the tabled structural
64 * references) for a given cipher 'nid'
66 ENGINE *ENGINE_get_cipher_engine(int nid)
68 return engine_table_select(&cipher_table, nid);
71 /* Obtains a cipher implementation from an ENGINE functional reference */
72 const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid)
74 const EVP_CIPHER *ret;
75 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
76 if (!fn || !fn(e, &ret, NULL, nid)) {
77 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, ENGINE_R_UNIMPLEMENTED_CIPHER);
83 /* Gets the cipher callback from an ENGINE structure */
84 ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e)
89 /* Sets the cipher callback in an ENGINE structure */
90 int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f)