2 * Copyright 1995-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
11 #include "internal/cryptlib.h"
12 #include <openssl/evp.h>
13 #include <openssl/kdf.h>
14 #include "internal/objects.h"
15 #include <openssl/x509.h>
16 #include "internal/evp_int.h"
18 int EVP_add_cipher(const EVP_CIPHER
*c
)
25 r
= OBJ_NAME_add(OBJ_nid2sn(c
->nid
), OBJ_NAME_TYPE_CIPHER_METH
,
29 r
= OBJ_NAME_add(OBJ_nid2ln(c
->nid
), OBJ_NAME_TYPE_CIPHER_METH
,
34 int EVP_add_digest(const EVP_MD
*md
)
39 name
= OBJ_nid2sn(md
->type
);
40 r
= OBJ_NAME_add(name
, OBJ_NAME_TYPE_MD_METH
, (const char *)md
);
43 r
= OBJ_NAME_add(OBJ_nid2ln(md
->type
), OBJ_NAME_TYPE_MD_METH
,
48 if (md
->pkey_type
&& md
->type
!= md
->pkey_type
) {
49 r
= OBJ_NAME_add(OBJ_nid2sn(md
->pkey_type
),
50 OBJ_NAME_TYPE_MD_METH
| OBJ_NAME_ALIAS
, name
);
53 r
= OBJ_NAME_add(OBJ_nid2ln(md
->pkey_type
),
54 OBJ_NAME_TYPE_MD_METH
| OBJ_NAME_ALIAS
, name
);
59 /* TODO(3.0) Is this needed after changing to providers? */
60 int EVP_add_kdf(const EVP_KDF
*k
)
67 r
= OBJ_NAME_add(OBJ_nid2sn(k
->type
), OBJ_NAME_TYPE_KDF_METH
,
71 r
= OBJ_NAME_add(OBJ_nid2ln(k
->type
), OBJ_NAME_TYPE_KDF_METH
,
76 const EVP_CIPHER
*EVP_get_cipherbyname(const char *name
)
80 if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
))
83 cp
= (const EVP_CIPHER
*)OBJ_NAME_get(name
, OBJ_NAME_TYPE_CIPHER_METH
);
87 const EVP_MD
*EVP_get_digestbyname(const char *name
)
91 if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
))
94 cp
= (const EVP_MD
*)OBJ_NAME_get(name
, OBJ_NAME_TYPE_MD_METH
);
98 /* TODO(3.0) Is this API needed after implementing providers? */
99 const EVP_KDF
*EVP_get_kdfbyname(const char *name
)
103 if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_KDFS
, NULL
))
106 kdf
= (const EVP_KDF
*)OBJ_NAME_get(name
, OBJ_NAME_TYPE_KDF_METH
);
110 void evp_cleanup_int(void)
112 OBJ_NAME_cleanup(OBJ_NAME_TYPE_KDF_METH
);
113 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH
);
114 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH
);
116 * The above calls will only clean out the contents of the name hash
117 * table, but not the hash table itself. The following line does that
118 * part. -- Richard Levitte
120 OBJ_NAME_cleanup(-1);
125 evp_app_cleanup_int();
128 struct doall_cipher
{
130 void (*fn
) (const EVP_CIPHER
*ciph
,
131 const char *from
, const char *to
, void *arg
);
134 static void do_all_cipher_fn(const OBJ_NAME
*nm
, void *arg
)
136 struct doall_cipher
*dc
= arg
;
138 dc
->fn(NULL
, nm
->name
, nm
->data
, dc
->arg
);
140 dc
->fn((const EVP_CIPHER
*)nm
->data
, nm
->name
, NULL
, dc
->arg
);
143 void EVP_CIPHER_do_all(void (*fn
) (const EVP_CIPHER
*ciph
,
144 const char *from
, const char *to
, void *x
),
147 struct doall_cipher dc
;
150 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
);
154 OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH
, do_all_cipher_fn
, &dc
);
157 void EVP_CIPHER_do_all_sorted(void (*fn
) (const EVP_CIPHER
*ciph
,
158 const char *from
, const char *to
,
161 struct doall_cipher dc
;
164 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
);
168 OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH
, do_all_cipher_fn
, &dc
);
173 void (*fn
) (const EVP_MD
*ciph
,
174 const char *from
, const char *to
, void *arg
);
177 static void do_all_md_fn(const OBJ_NAME
*nm
, void *arg
)
179 struct doall_md
*dc
= arg
;
181 dc
->fn(NULL
, nm
->name
, nm
->data
, dc
->arg
);
183 dc
->fn((const EVP_MD
*)nm
->data
, nm
->name
, NULL
, dc
->arg
);
186 void EVP_MD_do_all(void (*fn
) (const EVP_MD
*md
,
187 const char *from
, const char *to
, void *x
),
193 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
);
197 OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH
, do_all_md_fn
, &dc
);
200 void EVP_MD_do_all_sorted(void (*fn
) (const EVP_MD
*md
,
201 const char *from
, const char *to
,
206 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
);
210 OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH
, do_all_md_fn
, &dc
);