]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/engine/tb_rand.c
deprecate engines in libcrypto
[thirdparty/openssl.git] / crypto / engine / tb_rand.c
CommitLineData
b1322259 1/*
83cf7abf 2 * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
354c3ace 3 *
3c120f91 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
b1322259
RS
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
354c3ace
BL
8 */
9
e4468e6d
P
10/* We need to use some engine deprecated APIs */
11#define OPENSSL_SUPPRESS_DEPRECATED
12
706457b7 13#include "eng_local.h"
354c3ace 14
b6d1e52d
GT
15static ENGINE_TABLE *rand_table = NULL;
16static const int dummy_nid = 1;
354c3ace 17
b6d1e52d 18void ENGINE_unregister_RAND(ENGINE *e)
0f113f3e
MC
19{
20 engine_table_unregister(&rand_table, e);
21}
354c3ace 22
6d52f260 23static void engine_unregister_all_RAND(void)
0f113f3e
MC
24{
25 engine_table_cleanup(&rand_table);
26}
354c3ace 27
b6d1e52d 28int ENGINE_register_RAND(ENGINE *e)
0f113f3e
MC
29{
30 if (e->rand_meth)
31 return engine_table_register(&rand_table,
32 engine_unregister_all_RAND, e,
33 &dummy_nid, 1, 0);
34 return 1;
35}
354c3ace 36
3cb7c5cf 37void ENGINE_register_all_RAND(void)
0f113f3e
MC
38{
39 ENGINE *e;
354c3ace 40
0f113f3e
MC
41 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
42 ENGINE_register_RAND(e);
43}
354c3ace 44
b6d1e52d 45int ENGINE_set_default_RAND(ENGINE *e)
0f113f3e
MC
46{
47 if (e->rand_meth)
48 return engine_table_register(&rand_table,
49 engine_unregister_all_RAND, e,
50 &dummy_nid, 1, 1);
51 return 1;
52}
0e360199 53
0f113f3e
MC
54/*
55 * Exposed API function to get a functional reference from the implementation
b6d1e52d 56 * table (ie. try to get a functional reference from the tabled structural
0f113f3e
MC
57 * references).
58 */
b6d1e52d 59ENGINE *ENGINE_get_default_RAND(void)
0f113f3e
MC
60{
61 return engine_table_select(&rand_table, dummy_nid);
62}
0e360199 63
b6d1e52d
GT
64/* Obtains an RAND implementation from an ENGINE functional reference */
65const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
0f113f3e
MC
66{
67 return e->rand_meth;
68}
0e360199 69
b6d1e52d
GT
70/* Sets an RAND implementation in an ENGINE structure */
71int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
0f113f3e
MC
72{
73 e->rand_meth = rand_meth;
74 return 1;
75}