]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/engine/eng_fat.c
CRYPTO: refactor ERR_raise()+ERR_add_error_data() to ERR_raise_data()
[thirdparty/openssl.git] / crypto / engine / eng_fat.c
CommitLineData
b1322259 1/*
e39e295e 2 * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
aa8f3d76 3 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
354c3ace 4 *
3c120f91 5 * Licensed under the Apache License 2.0 (the "License"). You may not use
b1322259
RS
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
354c3ace 9 */
b1322259 10
e4468e6d
P
11/* We need to use some engine deprecated APIs */
12#define OPENSSL_SUPPRESS_DEPRECATED
13
706457b7 14#include "eng_local.h"
df5eaa8a 15#include <openssl/conf.h>
354c3ace 16
b6d1e52d 17int ENGINE_set_default(ENGINE *e, unsigned int flags)
0f113f3e
MC
18{
19 if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
20 return 0;
21 if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
22 return 0;
b6d1e52d 23#ifndef OPENSSL_NO_RSA
0f113f3e
MC
24 if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e))
25 return 0;
b6d1e52d
GT
26#endif
27#ifndef OPENSSL_NO_DSA
0f113f3e
MC
28 if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e))
29 return 0;
b6d1e52d
GT
30#endif
31#ifndef OPENSSL_NO_DH
0f113f3e
MC
32 if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
33 return 0;
e172d60d 34#endif
10bf4fc2 35#ifndef OPENSSL_NO_EC
7d711cbc
DSH
36 if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e))
37 return 0;
b6d1e52d 38#endif
0f113f3e
MC
39 if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
40 return 0;
41 if ((flags & ENGINE_METHOD_PKEY_METHS)
42 && !ENGINE_set_default_pkey_meths(e))
43 return 0;
44 if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS)
45 && !ENGINE_set_default_pkey_asn1_meths(e))
46 return 0;
47 return 1;
48}
0e360199 49
df5eaa8a
DSH
50/* Set default algorithms using a string */
51
40889b9c 52static int int_def_cb(const char *alg, int len, void *arg)
0f113f3e
MC
53{
54 unsigned int *pflags = arg;
2747d73c
KR
55 if (alg == NULL)
56 return 0;
86885c28 57 if (strncmp(alg, "ALL", len) == 0)
0f113f3e 58 *pflags |= ENGINE_METHOD_ALL;
86885c28 59 else if (strncmp(alg, "RSA", len) == 0)
0f113f3e 60 *pflags |= ENGINE_METHOD_RSA;
86885c28 61 else if (strncmp(alg, "DSA", len) == 0)
0f113f3e 62 *pflags |= ENGINE_METHOD_DSA;
86885c28 63 else if (strncmp(alg, "DH", len) == 0)
0f113f3e 64 *pflags |= ENGINE_METHOD_DH;
7d711cbc
DSH
65 else if (strncmp(alg, "EC", len) == 0)
66 *pflags |= ENGINE_METHOD_EC;
86885c28 67 else if (strncmp(alg, "RAND", len) == 0)
0f113f3e 68 *pflags |= ENGINE_METHOD_RAND;
86885c28 69 else if (strncmp(alg, "CIPHERS", len) == 0)
0f113f3e 70 *pflags |= ENGINE_METHOD_CIPHERS;
86885c28 71 else if (strncmp(alg, "DIGESTS", len) == 0)
0f113f3e 72 *pflags |= ENGINE_METHOD_DIGESTS;
86885c28 73 else if (strncmp(alg, "PKEY", len) == 0)
0f113f3e 74 *pflags |= ENGINE_METHOD_PKEY_METHS | ENGINE_METHOD_PKEY_ASN1_METHS;
86885c28 75 else if (strncmp(alg, "PKEY_CRYPTO", len) == 0)
0f113f3e 76 *pflags |= ENGINE_METHOD_PKEY_METHS;
86885c28 77 else if (strncmp(alg, "PKEY_ASN1", len) == 0)
0f113f3e
MC
78 *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS;
79 else
80 return 0;
81 return 1;
82}
df5eaa8a 83
3822740c 84int ENGINE_set_default_string(ENGINE *e, const char *def_list)
0f113f3e
MC
85{
86 unsigned int flags = 0;
87 if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) {
a150f8e1
RL
88 ERR_raise_data(ERR_LIB_ENGINE, ENGINE_R_INVALID_STRING,
89 "str=%s", def_list);
0f113f3e
MC
90 return 0;
91 }
92 return ENGINE_set_default(e, flags);
93}
df5eaa8a 94
b6d1e52d 95int ENGINE_register_complete(ENGINE *e)
0f113f3e
MC
96{
97 ENGINE_register_ciphers(e);
98 ENGINE_register_digests(e);
b6d1e52d 99#ifndef OPENSSL_NO_RSA
0f113f3e 100 ENGINE_register_RSA(e);
b6d1e52d
GT
101#endif
102#ifndef OPENSSL_NO_DSA
0f113f3e 103 ENGINE_register_DSA(e);
b6d1e52d
GT
104#endif
105#ifndef OPENSSL_NO_DH
0f113f3e 106 ENGINE_register_DH(e);
e172d60d 107#endif
10bf4fc2 108#ifndef OPENSSL_NO_EC
7d711cbc 109 ENGINE_register_EC(e);
b6d1e52d 110#endif
0f113f3e
MC
111 ENGINE_register_RAND(e);
112 ENGINE_register_pkey_meths(e);
b35bb37a 113 ENGINE_register_pkey_asn1_meths(e);
0f113f3e
MC
114 return 1;
115}
0e360199 116
b6d1e52d 117int ENGINE_register_all_complete(void)
0f113f3e
MC
118{
119 ENGINE *e;
0e360199 120
0f113f3e
MC
121 for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
122 if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL))
123 ENGINE_register_complete(e);
124 return 1;
125}