Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | #ifndef OPENSSL_HEADER_ENGINE_H |
| 16 | #define OPENSSL_HEADER_ENGINE_H |
| 17 | |
| 18 | #include <openssl/base.h> |
| 19 | |
| 20 | #if defined(__cplusplus) |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 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. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 34 | |
| 35 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 36 | // Allocation and destruction. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 37 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 38 | // ENGINE_new returns an empty ENGINE that uses the default method for all |
| 39 | // algorithms. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 40 | OPENSSL_EXPORT ENGINE *ENGINE_new(void); |
| 41 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 42 | // ENGINE_free decrements the reference counts for all methods linked from |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 43 | // |engine| and frees |engine| itself. It returns one. |
| 44 | OPENSSL_EXPORT int ENGINE_free(ENGINE *engine); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 45 | |
| 46 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 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. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 55 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 56 | OPENSSL_EXPORT int ENGINE_set_RSA_method(ENGINE *engine, |
| 57 | const RSA_METHOD *method, |
| 58 | size_t method_size); |
| 59 | OPENSSL_EXPORT RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine); |
| 60 | |
| 61 | OPENSSL_EXPORT int ENGINE_set_ECDSA_method(ENGINE *engine, |
| 62 | const ECDSA_METHOD *method, |
| 63 | size_t method_size); |
| 64 | OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine); |
| 65 | |
| 66 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 67 | // Generic method functions. |
| 68 | // |
| 69 | // These functions take a void* type but actually operate on all method |
| 70 | // structures. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 71 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 72 | // METHOD_ref increments the reference count of |method|. This is a no-op for |
| 73 | // now because all methods are currently static. |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 74 | void METHOD_ref(void *method); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 75 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 76 | // 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 Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 79 | void METHOD_unref(void *method); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 80 | |
| 81 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 82 | // Private functions. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 83 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 84 | // openssl_method_common_st contains the common part of all method structures. |
| 85 | // This must be the first member of all method structures. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 86 | struct openssl_method_common_st { |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 87 | int references; // dummy – not used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 88 | char is_static; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | #if defined(__cplusplus) |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 93 | } // extern C |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 94 | |
| 95 | extern "C++" { |
| 96 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 97 | BSSL_NAMESPACE_BEGIN |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 98 | |
| 99 | BORINGSSL_MAKE_DELETER(ENGINE, ENGINE_free) |
| 100 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 101 | BSSL_NAMESPACE_END |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 102 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 103 | } // extern C++ |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 104 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | #define ENGINE_R_OPERATION_NOT_SUPPORTED 100 |
| 108 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 109 | #endif // OPENSSL_HEADER_ENGINE_H |