2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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 "internal/objects.h"
14 #include <openssl/x509.h>
15 #include "internal/evp_int.h"
17 int EVP_add_cipher(const EVP_CIPHER
*c
)
24 r
= OBJ_NAME_add(OBJ_nid2sn(c
->nid
), OBJ_NAME_TYPE_CIPHER_METH
,
28 r
= OBJ_NAME_add(OBJ_nid2ln(c
->nid
), OBJ_NAME_TYPE_CIPHER_METH
,
33 int EVP_add_digest(const EVP_MD
*md
)
38 name
= OBJ_nid2sn(md
->type
);
39 r
= OBJ_NAME_add(name
, OBJ_NAME_TYPE_MD_METH
, (const char *)md
);
42 r
= OBJ_NAME_add(OBJ_nid2ln(md
->type
), OBJ_NAME_TYPE_MD_METH
,
47 if (md
->pkey_type
&& md
->type
!= md
->pkey_type
) {
48 r
= OBJ_NAME_add(OBJ_nid2sn(md
->pkey_type
),
49 OBJ_NAME_TYPE_MD_METH
| OBJ_NAME_ALIAS
, name
);
52 r
= OBJ_NAME_add(OBJ_nid2ln(md
->pkey_type
),
53 OBJ_NAME_TYPE_MD_METH
| OBJ_NAME_ALIAS
, name
);
58 const EVP_CIPHER
*EVP_get_cipherbyname(const char *name
)
62 if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
))
65 cp
= (const EVP_CIPHER
*)OBJ_NAME_get(name
, OBJ_NAME_TYPE_CIPHER_METH
);
69 const EVP_MD
*EVP_get_digestbyname(const char *name
)
73 if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
))
76 cp
= (const EVP_MD
*)OBJ_NAME_get(name
, OBJ_NAME_TYPE_MD_METH
);
80 void evp_cleanup_int(void)
82 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH
);
83 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH
);
85 * The above calls will only clean out the contents of the name hash
86 * table, but not the hash table itself. The following line does that
87 * part. -- Richard Levitte
94 evp_app_cleanup_int();
99 void (*fn
) (const EVP_CIPHER
*ciph
,
100 const char *from
, const char *to
, void *arg
);
103 static void do_all_cipher_fn(const OBJ_NAME
*nm
, void *arg
)
105 struct doall_cipher
*dc
= arg
;
107 dc
->fn(NULL
, nm
->name
, nm
->data
, dc
->arg
);
109 dc
->fn((const EVP_CIPHER
*)nm
->data
, nm
->name
, NULL
, dc
->arg
);
112 void EVP_CIPHER_do_all(void (*fn
) (const EVP_CIPHER
*ciph
,
113 const char *from
, const char *to
, void *x
),
116 struct doall_cipher dc
;
119 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
);
123 OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH
, do_all_cipher_fn
, &dc
);
126 void EVP_CIPHER_do_all_sorted(void (*fn
) (const EVP_CIPHER
*ciph
,
127 const char *from
, const char *to
,
130 struct doall_cipher dc
;
133 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS
, NULL
);
137 OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH
, do_all_cipher_fn
, &dc
);
142 void (*fn
) (const EVP_MD
*ciph
,
143 const char *from
, const char *to
, void *arg
);
146 static void do_all_md_fn(const OBJ_NAME
*nm
, void *arg
)
148 struct doall_md
*dc
= arg
;
150 dc
->fn(NULL
, nm
->name
, nm
->data
, dc
->arg
);
152 dc
->fn((const EVP_MD
*)nm
->data
, nm
->name
, NULL
, dc
->arg
);
155 void EVP_MD_do_all(void (*fn
) (const EVP_MD
*md
,
156 const char *from
, const char *to
, void *x
),
162 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
);
166 OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH
, do_all_md_fn
, &dc
);
169 void EVP_MD_do_all_sorted(void (*fn
) (const EVP_MD
*md
,
170 const char *from
, const char *to
,
175 OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS
, NULL
);
179 OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_MD_METH
, do_all_md_fn
, &dc
);