blob: d3d278a69b77a4bec518e4ea2a67d688eb936c3f [file] [log] [blame]
Adam Langleyd9e397b2015-01-22 14:27:53 -08001/* 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#ifndef OPENSSL_HEADER_ENGINE_H
16#define OPENSSL_HEADER_ENGINE_H
17
18#include <openssl/base.h>
19
20#if defined(__cplusplus)
21extern "C" {
22#endif
23
24
25/* Engines are collections of methods. Methods are tables of function pointers,
26 * defined for certain algorithms, that allow operations on those algorithms to
27 * be overridden via a callback. This can be used, for example, to implement an
28 * RSA* that forwards operations to a hardware module.
29 *
30 * Methods are reference counted but |ENGINE|s are not. When creating a method,
31 * you should zero the whole structure and fill in the function pointers that
32 * you wish before setting it on an |ENGINE|. Any functions pointers that
33 * are NULL indicate that the default behaviour should be used. */
34
35
36/* Allocation and destruction. */
37
38/* ENGINE_new returns an empty ENGINE that uses the default method for all
39 * algorithms. */
40OPENSSL_EXPORT ENGINE *ENGINE_new(void);
41
42/* ENGINE_free decrements the reference counts for all methods linked from
43 * |engine| and frees |engine| itself. */
44OPENSSL_EXPORT void ENGINE_free(ENGINE *engine);
45
46
47/* Method accessors.
48 *
49 * Method accessors take a method pointer and the size of the structure. The
50 * size allows for ABI compatibility in the case that the method structure is
51 * extended with extra elements at the end. Methods are always copied by the
52 * set functions.
53 *
54 * Set functions return one on success and zero on allocation failure. */
55
56OPENSSL_EXPORT int ENGINE_set_DH_method(ENGINE *engine, const DH_METHOD *method,
57 size_t method_size);
58OPENSSL_EXPORT DH_METHOD *ENGINE_get_DH_method(const ENGINE *engine);
59
60OPENSSL_EXPORT int ENGINE_set_DSA_method(ENGINE *engine,
61 const DSA_METHOD *method,
62 size_t method_size);
63OPENSSL_EXPORT DSA_METHOD *ENGINE_get_DSA_method(const ENGINE *engine);
64
65OPENSSL_EXPORT int ENGINE_set_RSA_method(ENGINE *engine,
66 const RSA_METHOD *method,
67 size_t method_size);
68OPENSSL_EXPORT RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine);
69
70OPENSSL_EXPORT int ENGINE_set_ECDSA_method(ENGINE *engine,
71 const ECDSA_METHOD *method,
72 size_t method_size);
73OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine);
74
75
76/* Generic method functions.
77 *
78 * These functions take a void* type but actually operate on all method
79 * structures. */
80
Adam Langleye9ada862015-05-11 17:20:37 -070081/* METHOD_ref increments the reference count of |method|. This is a no-op for
82 * now because all methods are currently static. */
83void METHOD_ref(void *method);
Adam Langleyd9e397b2015-01-22 14:27:53 -080084
85/* METHOD_unref decrements the reference count of |method| and frees it if the
Adam Langleye9ada862015-05-11 17:20:37 -070086 * reference count drops to zero. This is a no-op for now because all methods
87 * are currently static. */
88void METHOD_unref(void *method);
Adam Langleyd9e397b2015-01-22 14:27:53 -080089
90
91/* Private functions. */
92
93/* openssl_method_common_st contains the common part of all method structures.
94 * This must be the first member of all method structures. */
95struct openssl_method_common_st {
Adam Langleyf4e42722015-06-04 17:45:09 -070096 int references; /* dummy – not used. */
Adam Langleyd9e397b2015-01-22 14:27:53 -080097 char is_static;
98};
99
100
101#if defined(__cplusplus)
102} /* extern C */
103#endif
104
105#define ENGINE_R_OPERATION_NOT_SUPPORTED 100
106
107#endif /* OPENSSL_HEADER_ENGINE_H */