plugin_encryption.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef MYSQL_PLUGIN_ENCRYPTION_INCLUDED
  2. /* Copyright (C) 2014, 2015 Sergei Golubchik and MariaDB
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. /**
  14. @file
  15. Encryption Plugin API.
  16. This file defines the API for server plugins that manage encryption
  17. keys for MariaDB on-disk data encryption.
  18. */
  19. #define MYSQL_PLUGIN_ENCRYPTION_INCLUDED
  20. #include <mysql/plugin.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define MariaDB_ENCRYPTION_INTERFACE_VERSION 0x0300
  25. /**
  26. Encryption plugin descriptor
  27. */
  28. struct st_mariadb_encryption
  29. {
  30. int interface_version; /**< version plugin uses */
  31. /*********** KEY MANAGEMENT ********************************************/
  32. /**
  33. function returning latest key version for a given key id
  34. @return a version or ENCRYPTION_KEY_VERSION_INVALID to indicate an error.
  35. */
  36. unsigned int (*get_latest_key_version)(unsigned int key_id);
  37. /**
  38. function returning a key for a key version
  39. @param version the requested key version
  40. @param key the key will be stored there. Can be NULL -
  41. in which case no key will be returned
  42. @param key_length in: key buffer size
  43. out: the actual length of the key
  44. This method can be used to query the key length - the required
  45. buffer size - by passing key==NULL.
  46. If the buffer size is less than the key length the content of the
  47. key buffer is undefined (the plugin is free to partially fill it with
  48. the key data or leave it untouched).
  49. @return 0 on success, or
  50. ENCRYPTION_KEY_VERSION_INVALID, ENCRYPTION_KEY_BUFFER_TOO_SMALL
  51. or any other non-zero number for errors
  52. */
  53. unsigned int (*get_key)(unsigned int key_id, unsigned int version,
  54. unsigned char *key, unsigned int *key_length);
  55. /*********** ENCRYPTION ************************************************/
  56. /*
  57. the caller uses encryption as follows:
  58. 1. create the encryption context object of the crypt_ctx_size() bytes.
  59. 2. initialize it with crypt_ctx_init().
  60. 3. repeat crypt_ctx_update() until there are no more data to encrypt.
  61. 4. write the remaining output bytes and destroy the context object
  62. with crypt_ctx_finish().
  63. */
  64. /**
  65. returns the size of the encryption context object in bytes
  66. */
  67. unsigned int (*crypt_ctx_size)(unsigned int key_id, unsigned int key_version);
  68. /**
  69. initializes the encryption context object.
  70. */
  71. int (*crypt_ctx_init)(void *ctx, const unsigned char* key, unsigned int klen,
  72. const unsigned char* iv, unsigned int ivlen,
  73. int flags, unsigned int key_id,
  74. unsigned int key_version);
  75. /**
  76. processes (encrypts or decrypts) a chunk of data
  77. writes the output to th dst buffer. note that it might write
  78. more bytes that were in the input. or less. or none at all.
  79. */
  80. int (*crypt_ctx_update)(void *ctx, const unsigned char* src, unsigned int slen,
  81. unsigned char* dst, unsigned int* dlen);
  82. /**
  83. writes the remaining output bytes and destroys the encryption context
  84. crypt_ctx_update might've cached part of the output in the context,
  85. this method will flush these data out.
  86. */
  87. int (*crypt_ctx_finish)(void *ctx, unsigned char* dst, unsigned int* dlen);
  88. /**
  89. returns the length of the encrypted data
  90. it returns the exact length, given only the source length.
  91. which means, this API only supports encryption algorithms where
  92. the length of the encrypted data only depends on the length of the
  93. input (a.k.a. compression is not supported).
  94. */
  95. unsigned int (*encrypted_length)(unsigned int slen, unsigned int key_id, unsigned int key_version);
  96. };
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif