The interface implemented by applications to provide custom encryption. More...
Public Attributes | |
int(* | encrypt )(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) |
Callback to encrypt a chunk of data. More... | |
int(* | decrypt )(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) |
Callback to decrypt a chunk of data. More... | |
int(* | sizing )(WT_ENCRYPTOR *encryptor, WT_SESSION *session, size_t *expansion_constantp) |
Callback to size a destination buffer for encryption. More... | |
int(* | customize )(WT_ENCRYPTOR *encryptor, WT_SESSION *session, WT_CONFIG_ARG *encrypt_config, WT_ENCRYPTOR **customp) |
If non-NULL, this callback is called to customize the encryptor. More... | |
int(* | terminate )(WT_ENCRYPTOR *encryptor, WT_SESSION *session) |
If non-NULL, a callback performed when the database is closed. More... | |
The interface implemented by applications to provide custom encryption.
Encryptors must implement the WT_ENCRYPTOR interface: the WT_ENCRYPTOR::encrypt, WT_ENCRYPTOR::decrypt and WT_ENCRYPTOR::sizing callbacks must be specified, WT_ENCRYPTOR::customize and WT_ENCRYPTOR::terminate are optional. To build your own encryptor, use one of the encryptors in ext/encryptors
as a template: ext/encryptors/nop_encrypt
is a simple encryptor that passes through data unchanged, and is a reasonable starting point; ext/encryptors/rotn_encrypt
is an encryptor implementing a simple rotation cipher, it shows the use of keyid
, secretkey
, and implements the WT_ENCRYPTOR::customize and WT_ENCRYPTOR::terminate callbacks.
Applications register their implementation with WiredTiger by calling WT_CONNECTION::add_encryptor.
int(* WT_ENCRYPTOR::customize) (WT_ENCRYPTOR *encryptor, WT_SESSION *session, WT_CONFIG_ARG *encrypt_config, WT_ENCRYPTOR **customp) |
If non-NULL, this callback is called to customize the encryptor.
The customize function is called whenever a keyid is used for the first time with this encryptor, whether it be in the wiredtiger_open call or the WT_SESSION::create call. This gives the algorithm an opportunity to retrieve and save keys in a customized encryptor. If the callback returns a non-NULL encryptor, that instance is used instead of this one for any callbacks.
[in] | encrypt_config | the "encryption" portion of the configuration from the wiredtiger_open or WT_SESSION::create call |
[out] | customp | the new modified encryptor, or NULL. |
int(* WT_ENCRYPTOR::decrypt) (WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) |
Callback to decrypt a chunk of data.
WT_ENCRYPTOR::decrypt takes a source buffer and a destination buffer. The contents are switched from encrypt:
the source buffer is the encrypted value, and the destination buffer is sized to be the original size. If the callback successfully decrypts the source buffer to the destination buffer, it returns 0. If an error occurs, it returns an errno or WiredTiger error code.
On entry, src
will point to memory, with the length of the memory in src_len
. After successful completion, the callback should return 0
and set result_lenp
to the number of bytes required for the decrypted representation.
If the dst
buffer is not big enough to hold the decrypted data, the callback should return an error.
This callback cannot be NULL.
[in] | src | the data to decrypt |
[in] | src_len | the length of the data to decrypt |
[in] | dst | the destination buffer |
[in] | dst_len | the length of the destination buffer |
[out] | result_lenp | the length of the decrypted data |
int(* WT_ENCRYPTOR::encrypt) (WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) |
Callback to encrypt a chunk of data.
WT_ENCRYPTOR::encrypt takes a source buffer and a destination buffer. The callback encrypts the source buffer (plain text) into the destination buffer.
On entry, src
will point to memory, with the length of the memory in src_len
. After successful completion, the callback should return 0
and set result_lenp
to the number of bytes required for the encrypted representation.
On entry, dst
points to the destination buffer with a length of dst_len
. The destination buffer will be at least src_len plus the size returned by that WT_ENCRYPT::sizing.
This callback cannot be NULL.
[in] | src | the data to encrypt |
[in] | src_len | the length of the data to encrypt |
[in] | dst | the destination buffer |
[in] | dst_len | the length of the destination buffer |
[out] | result_lenp | the length of the encrypted data |
int(* WT_ENCRYPTOR::sizing) (WT_ENCRYPTOR *encryptor, WT_SESSION *session, size_t *expansion_constantp) |
Callback to size a destination buffer for encryption.
WT_ENCRYPTOR::sizing is an callback that returns the number of additional bytes that is needed when encrypting a text buffer. This is always necessary, since encryptors typically generate encrypted text that is larger than the plain text input. Without such a call, WiredTiger would have no way to know the worst case for the encrypted buffer size. The WiredTiger encryption infrastructure assumes that buffer sizing is not dependent on the number of bytes of input, that there is a one to one relationship in number of bytes needed between input and output.
This callback cannot be NULL.
The callback should set expansion_constantp
to the additional number of bytes needed.
[out] | expansion_constantp | the additional number of bytes needed when encrypting. |
int(* WT_ENCRYPTOR::terminate) (WT_ENCRYPTOR *encryptor, WT_SESSION *session) |
If non-NULL, a callback performed when the database is closed.
It is called for each encryptor that was added using WT_CONNECTION::add_encryptor or returned by the WT_ENCRYPTOR::customize callback.
The WT_ENCRYPTOR::terminate callback is intended to allow cleanup, the handle will not be subsequently accessed by WiredTiger.