blob: ce60de46efe3fecf73d00bcc36b91b8f8255f386 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/* 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
David Benjamin4512b792017-08-18 19:21:50 -040025// 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.
Adam Langley95c29f32014-06-20 12:00:00 -070034
35
David Benjamin4512b792017-08-18 19:21:50 -040036// Allocation and destruction.
Adam Langley95c29f32014-06-20 12:00:00 -070037
David Benjamin4512b792017-08-18 19:21:50 -040038// ENGINE_new returns an empty ENGINE that uses the default method for all
39// algorithms.
David Benjaminc44d2f42014-08-20 16:24:00 -040040OPENSSL_EXPORT ENGINE *ENGINE_new(void);
Adam Langley95c29f32014-06-20 12:00:00 -070041
David Benjamin4512b792017-08-18 19:21:50 -040042// ENGINE_free decrements the reference counts for all methods linked from
David Benjamin9df41ae2019-04-16 12:49:41 -050043// |engine| and frees |engine| itself. It returns one.
44OPENSSL_EXPORT int ENGINE_free(ENGINE *engine);
Adam Langley95c29f32014-06-20 12:00:00 -070045
46
David Benjamin4512b792017-08-18 19:21:50 -040047// 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.
Adam Langley95c29f32014-06-20 12:00:00 -070055
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070056OPENSSL_EXPORT int ENGINE_set_RSA_method(ENGINE *engine,
57 const RSA_METHOD *method,
58 size_t method_size);
59OPENSSL_EXPORT RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine);
Adam Langley95c29f32014-06-20 12:00:00 -070060
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070061OPENSSL_EXPORT int ENGINE_set_ECDSA_method(ENGINE *engine,
62 const ECDSA_METHOD *method,
63 size_t method_size);
64OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine);
Adam Langley95c29f32014-06-20 12:00:00 -070065
66
David Benjamin4512b792017-08-18 19:21:50 -040067// Generic method functions.
68//
69// These functions take a void* type but actually operate on all method
70// structures.
Adam Langley95c29f32014-06-20 12:00:00 -070071
David Benjamin4512b792017-08-18 19:21:50 -040072// METHOD_ref increments the reference count of |method|. This is a no-op for
73// now because all methods are currently static.
Adam Langley4e04ee82015-02-03 17:20:06 -080074void METHOD_ref(void *method);
Adam Langley95c29f32014-06-20 12:00:00 -070075
David Benjamin4512b792017-08-18 19:21:50 -040076// METHOD_unref decrements the reference count of |method| and frees it if the
77// reference count drops to zero. This is a no-op for now because all methods
78// are currently static.
Adam Langley4e04ee82015-02-03 17:20:06 -080079void METHOD_unref(void *method);
Adam Langley95c29f32014-06-20 12:00:00 -070080
81
David Benjamin4512b792017-08-18 19:21:50 -040082// Private functions.
Adam Langley95c29f32014-06-20 12:00:00 -070083
David Benjamin4512b792017-08-18 19:21:50 -040084// openssl_method_common_st contains the common part of all method structures.
85// This must be the first member of all method structures.
Adam Langley95c29f32014-06-20 12:00:00 -070086struct openssl_method_common_st {
David Benjamin4512b792017-08-18 19:21:50 -040087 int references; // dummy – not used.
Adam Langley95c29f32014-06-20 12:00:00 -070088 char is_static;
89};
90
91
92#if defined(__cplusplus)
David Benjamin4512b792017-08-18 19:21:50 -040093} // extern C
Matt Braithwaited17d74d2016-08-17 20:10:28 -070094
95extern "C++" {
96
Joshua Liebow-Feeser8c7c6352018-08-26 18:53:36 -070097BSSL_NAMESPACE_BEGIN
Matt Braithwaited17d74d2016-08-17 20:10:28 -070098
Matt Braithwaited17d74d2016-08-17 20:10:28 -070099BORINGSSL_MAKE_DELETER(ENGINE, ENGINE_free)
100
Joshua Liebow-Feeser8c7c6352018-08-26 18:53:36 -0700101BSSL_NAMESPACE_END
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700102
David Benjamin4512b792017-08-18 19:21:50 -0400103} // extern C++
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700104
Adam Langley95c29f32014-06-20 12:00:00 -0700105#endif
106
Adam Langley7ea84812014-10-09 16:26:09 -0700107#define ENGINE_R_OPERATION_NOT_SUPPORTED 100
108
David Benjamin4512b792017-08-18 19:21:50 -0400109#endif // OPENSSL_HEADER_ENGINE_H