/src/boringssl/crypto/engine/engine.cc
Line | Count | Source |
1 | | // Copyright 2014 The BoringSSL Authors |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <openssl/engine.h> |
16 | | |
17 | | #include <assert.h> |
18 | | #include <string.h> |
19 | | |
20 | | #include <openssl/ec_key.h> |
21 | | #include <openssl/err.h> |
22 | | #include <openssl/mem.h> |
23 | | #include <openssl/rsa.h> |
24 | | |
25 | | #include "../internal.h" |
26 | | #include "../mem_internal.h" |
27 | | |
28 | | |
29 | | using namespace bssl; |
30 | | |
31 | | struct engine_st { |
32 | | RSA_METHOD *rsa_method; |
33 | | ECDSA_METHOD *ecdsa_method; |
34 | | }; |
35 | | |
36 | 0 | ENGINE *ENGINE_new() { return New<ENGINE>(); } |
37 | | |
38 | 0 | int ENGINE_free(ENGINE *engine) { |
39 | | // Methods are currently required to be static so are not unref'ed. |
40 | 0 | Delete(engine); |
41 | 0 | return 1; |
42 | 0 | } |
43 | | |
44 | | // set_method takes a pointer to a method and its given size and sets |
45 | | // |*out_member| to point to it. This function might want to be extended in the |
46 | | // future to support making a copy of the method so that a stable ABI for |
47 | | // ENGINEs can be supported. But, for the moment, all *_METHODS must be |
48 | | // static. |
49 | | static int set_method(void **out_member, const void *method, size_t method_size, |
50 | 0 | size_t compiled_size) { |
51 | 0 | const struct openssl_method_common_st *common = |
52 | 0 | reinterpret_cast<const openssl_method_common_st *>(method); |
53 | 0 | if (method_size != compiled_size || !common->is_static) { |
54 | 0 | return 0; |
55 | 0 | } |
56 | | |
57 | 0 | *out_member = (void *)method; |
58 | 0 | return 1; |
59 | 0 | } |
60 | | |
61 | | int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method, |
62 | 0 | size_t method_size) { |
63 | 0 | return set_method((void **)&engine->rsa_method, method, method_size, |
64 | 0 | sizeof(RSA_METHOD)); |
65 | 0 | } |
66 | | |
67 | 0 | RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine) { |
68 | 0 | return engine->rsa_method; |
69 | 0 | } |
70 | | |
71 | | int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method, |
72 | 0 | size_t method_size) { |
73 | 0 | return set_method((void **)&engine->ecdsa_method, method, method_size, |
74 | 0 | sizeof(ECDSA_METHOD)); |
75 | 0 | } |
76 | | |
77 | 0 | ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) { |
78 | 0 | return engine->ecdsa_method; |
79 | 0 | } |
80 | | |
81 | 138k | void METHOD_ref(void *method_in) { |
82 | 138k | assert(((struct openssl_method_common_st *)method_in)->is_static); |
83 | 138k | } |
84 | | |
85 | 138k | void METHOD_unref(void *method_in) { |
86 | 138k | struct openssl_method_common_st *method = |
87 | 138k | reinterpret_cast<openssl_method_common_st *>(method_in); |
88 | | |
89 | 138k | if (method == nullptr) { |
90 | 0 | return; |
91 | 0 | } |
92 | 138k | assert(method->is_static); |
93 | 138k | } |
94 | | |
95 | | OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED) |