• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2016, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #include <openssl/obj.h>
16 
17 #include <assert.h>
18 #include <string.h>
19 
20 #include <openssl/evp.h>
21 
22 #include "../../crypto/internal.h"
23 
24 
25 struct wrapped_callback {
26   void (*callback)(const OBJ_NAME *, void *arg);
27   void *arg;
28 };
29 
cipher_callback(const EVP_CIPHER * cipher,const char * name,const char * unused,void * arg)30 static void cipher_callback(const EVP_CIPHER *cipher, const char *name,
31                             const char *unused, void *arg) {
32   const struct wrapped_callback *wrapped = (struct wrapped_callback *)arg;
33   OBJ_NAME obj_name;
34 
35   OPENSSL_memset(&obj_name, 0, sizeof(obj_name));
36   obj_name.type = OBJ_NAME_TYPE_CIPHER_METH;
37   obj_name.name = name;
38   obj_name.data = (const char *)cipher;
39 
40   wrapped->callback(&obj_name, wrapped->arg);
41 }
42 
md_callback(const EVP_MD * md,const char * name,const char * unused,void * arg)43 static void md_callback(const EVP_MD *md, const char *name, const char *unused,
44                         void *arg) {
45   const struct wrapped_callback *wrapped = (struct wrapped_callback*) arg;
46   OBJ_NAME obj_name;
47 
48   OPENSSL_memset(&obj_name, 0, sizeof(obj_name));
49   obj_name.type = OBJ_NAME_TYPE_MD_METH;
50   obj_name.name = name;
51   obj_name.data = (const char *)md;
52 
53   wrapped->callback(&obj_name, wrapped->arg);
54 }
55 
OBJ_NAME_do_all_sorted(int type,void (* callback)(const OBJ_NAME *,void * arg),void * arg)56 void OBJ_NAME_do_all_sorted(int type,
57                             void (*callback)(const OBJ_NAME *, void *arg),
58                             void *arg) {
59   struct wrapped_callback wrapped;
60   wrapped.callback = callback;
61   wrapped.arg = arg;
62 
63   if (type == OBJ_NAME_TYPE_CIPHER_METH) {
64     EVP_CIPHER_do_all_sorted(cipher_callback, &wrapped);
65   } else if (type == OBJ_NAME_TYPE_MD_METH) {
66     EVP_MD_do_all_sorted(md_callback, &wrapped);
67   } else {
68     assert(0);
69   }
70 }
71 
OBJ_NAME_do_all(int type,void (* callback)(const OBJ_NAME *,void * arg),void * arg)72 void OBJ_NAME_do_all(int type, void (*callback)(const OBJ_NAME *, void *arg),
73                      void *arg) {
74   OBJ_NAME_do_all_sorted(type, callback, arg);
75 }
76