engine.c
Go to the documentation of this file.
1 /* Copyright (c) 2014, 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/engine.h>
16 
17 #include <string.h>
18 #include <assert.h>
19 
20 #include <openssl/ec_key.h>
21 #include <openssl/err.h>
22 #include <openssl/mem.h>
23 #include <openssl/rsa.h>
24 #include <openssl/thread.h>
25 
26 #include "../internal.h"
27 
28 
29 struct engine_st {
32 };
33 
35  ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
36  if (engine == NULL) {
37  return NULL;
38  }
39 
40  OPENSSL_memset(engine, 0, sizeof(ENGINE));
41  return engine;
42 }
43 
44 int ENGINE_free(ENGINE *engine) {
45  // Methods are currently required to be static so are not unref'ed.
46  OPENSSL_free(engine);
47  return 1;
48 }
49 
50 // set_method takes a pointer to a method and its given size and sets
51 // |*out_member| to point to it. This function might want to be extended in the
52 // future to support making a copy of the method so that a stable ABI for
53 // ENGINEs can be supported. But, for the moment, all *_METHODS must be
54 // static.
55 static int set_method(void **out_member, const void *method, size_t method_size,
56  size_t compiled_size) {
57  const struct openssl_method_common_st *common = method;
58  if (method_size != compiled_size || !common->is_static) {
59  return 0;
60  }
61 
62  *out_member = (void*) method;
63  return 1;
64 }
65 
67  size_t method_size) {
68  return set_method((void **)&engine->rsa_method, method, method_size,
69  sizeof(RSA_METHOD));
70 }
71 
73  return engine->rsa_method;
74 }
75 
77  size_t method_size) {
78  return set_method((void **)&engine->ecdsa_method, method, method_size,
79  sizeof(ECDSA_METHOD));
80 }
81 
83  return engine->ecdsa_method;
84 }
85 
86 void METHOD_ref(void *method_in) {
87  assert(((struct openssl_method_common_st*) method_in)->is_static);
88 }
89 
90 void METHOD_unref(void *method_in) {
91  struct openssl_method_common_st *method = method_in;
92 
93  if (method == NULL) {
94  return;
95  }
96  assert(method->is_static);
97 }
98 
99 OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED)
openssl_method_common_st::is_static
char is_static
Definition: engine.h:88
ENGINE_new
ENGINE * ENGINE_new(void)
Definition: engine.c:34
string.h
METHOD_ref
void METHOD_ref(void *method_in)
Definition: engine.c:86
OPENSSL_memset
static void * OPENSSL_memset(void *dst, int c, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:835
OPENSSL_malloc
#define OPENSSL_malloc
Definition: boringssl_prefix_symbols.h:1885
ENGINE_set_RSA_method
int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method, size_t method_size)
Definition: engine.c:66
err.h
rsa.h
ec_key.h
ENGINE_set_ECDSA_method
int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method, size_t method_size)
Definition: engine.c:76
ENGINE_get_RSA_method
RSA_METHOD * ENGINE_get_RSA_method(const ENGINE *engine)
Definition: engine.c:72
OPENSSL_DECLARE_ERROR_REASON
#define OPENSSL_DECLARE_ERROR_REASON(lib, reason)
Definition: err.h:459
engine_st::ecdsa_method
ECDSA_METHOD * ecdsa_method
Definition: engine.c:31
ecdsa_method_st
Definition: ec_key.h:271
ENGINE_get_ECDSA_method
ECDSA_METHOD * ENGINE_get_ECDSA_method(const ENGINE *engine)
Definition: engine.c:82
METHOD_unref
void METHOD_unref(void *method_in)
Definition: engine.c:90
openssl_method_common_st
Definition: engine.h:86
rsa_meth_st
Definition: rsa.h:689
engine.h
engine_st
Definition: engine.c:29
engine_st::rsa_method
RSA_METHOD * rsa_method
Definition: engine.c:30
ENGINE_free
int ENGINE_free(ENGINE *engine)
Definition: engine.c:44
mem.h
method
NSString * method
Definition: ProtoMethod.h:28
thread.h
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
common
Definition: bloaty/third_party/googletest/googletest/scripts/common.py:1
set_method
static int set_method(void **out_member, const void *method, size_t method_size, size_t compiled_size)
Definition: engine.c:55


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:15