/src/boringssl/crypto/engine/engine.c
Line | Count | Source (jump to first uncovered line) |
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 { |
30 | | RSA_METHOD *rsa_method; |
31 | | ECDSA_METHOD *ecdsa_method; |
32 | | }; |
33 | | |
34 | 0 | ENGINE *ENGINE_new(void) { return OPENSSL_zalloc(sizeof(ENGINE)); } |
35 | | |
36 | 0 | int ENGINE_free(ENGINE *engine) { |
37 | | // Methods are currently required to be static so are not unref'ed. |
38 | 0 | OPENSSL_free(engine); |
39 | 0 | return 1; |
40 | 0 | } |
41 | | |
42 | | // set_method takes a pointer to a method and its given size and sets |
43 | | // |*out_member| to point to it. This function might want to be extended in the |
44 | | // future to support making a copy of the method so that a stable ABI for |
45 | | // ENGINEs can be supported. But, for the moment, all *_METHODS must be |
46 | | // static. |
47 | | static int set_method(void **out_member, const void *method, size_t method_size, |
48 | 0 | size_t compiled_size) { |
49 | 0 | const struct openssl_method_common_st *common = method; |
50 | 0 | if (method_size != compiled_size || !common->is_static) { |
51 | 0 | return 0; |
52 | 0 | } |
53 | | |
54 | 0 | *out_member = (void*) method; |
55 | 0 | return 1; |
56 | 0 | } |
57 | | |
58 | | int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method, |
59 | 0 | size_t method_size) { |
60 | 0 | return set_method((void **)&engine->rsa_method, method, method_size, |
61 | 0 | sizeof(RSA_METHOD)); |
62 | 0 | } |
63 | | |
64 | 0 | RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine) { |
65 | 0 | return engine->rsa_method; |
66 | 0 | } |
67 | | |
68 | | int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method, |
69 | 0 | size_t method_size) { |
70 | 0 | return set_method((void **)&engine->ecdsa_method, method, method_size, |
71 | 0 | sizeof(ECDSA_METHOD)); |
72 | 0 | } |
73 | | |
74 | 0 | ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) { |
75 | 0 | return engine->ecdsa_method; |
76 | 0 | } |
77 | | |
78 | 0 | void METHOD_ref(void *method_in) { |
79 | 0 | assert(((struct openssl_method_common_st*) method_in)->is_static); |
80 | 0 | } |
81 | | |
82 | 0 | void METHOD_unref(void *method_in) { |
83 | 0 | struct openssl_method_common_st *method = method_in; |
84 | |
|
85 | 0 | if (method == NULL) { |
86 | 0 | return; |
87 | 0 | } |
88 | 0 | assert(method->is_static); |
89 | 0 | } |
90 | | |
91 | | OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED) |