diff options
author | Sergei Golubchik <serg@mariadb.org> | 2015-03-31 19:00:51 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2015-04-08 10:58:50 +0200 |
commit | ef5b4889c2bc1d463291d4d80091c79183ec1196 (patch) | |
tree | 41a4b6c7aa57daee2cb617045b87c59c5d520706 /plugin | |
parent | c91e3260e2678078c0bb29d8daa90fb52cefaab7 (diff) | |
download | mariadb-git-ef5b4889c2bc1d463291d4d80091c79183ec1196.tar.gz |
optimize encryption api
only one encryption key lookup in most cases instead of three
(has_key, get_key_size, get_key).
Diffstat (limited to 'plugin')
3 files changed, 34 insertions, 63 deletions
diff --git a/plugin/debug_key_management/debug_key_management_plugin.cc b/plugin/debug_key_management/debug_key_management_plugin.cc index 1d332e62381..7ade1b8fde7 100644 --- a/plugin/debug_key_management/debug_key_management_plugin.cc +++ b/plugin/debug_key_management/debug_key_management_plugin.cc @@ -28,6 +28,8 @@ #include <string.h> #include <myisampack.h> +#define KEY_SIZE 16 + static uint key_version; static MYSQL_SYSVAR_UINT(version, key_version, PLUGIN_VAR_RQCMDARG, @@ -43,30 +45,25 @@ static unsigned int get_latest_key_version() return key_version; } -static int get_key(unsigned int version, unsigned char* dstbuf, unsigned buflen) +static unsigned int get_key(unsigned int version, unsigned char* dstbuf, unsigned *buflen) { - if (buflen < 4) - return 1; - memset(dstbuf, 0, buflen); + if (*buflen < KEY_SIZE) + { + *buflen= KEY_SIZE; + return KEY_BUFFER_TOO_SMALL; + } + *buflen= KEY_SIZE; + if (!dstbuf) + return 0; + + memset(dstbuf, 0, KEY_SIZE); mi_int4store(dstbuf, version); return 0; } -static unsigned int has_key(unsigned int ver) -{ - return 1; -} - -static unsigned int get_key_size(unsigned int ver) -{ - return 16; -} - struct st_mariadb_encryption_key_management debug_key_management_plugin= { MariaDB_ENCRYPTION_KEY_MANAGEMENT_INTERFACE_VERSION, get_latest_key_version, - has_key, - get_key_size, get_key }; diff --git a/plugin/example_key_management/example_key_management_plugin.cc b/plugin/example_key_management/example_key_management_plugin.cc index 6548baef20c..28cae3c311e 100644 --- a/plugin/example_key_management/example_key_management_plugin.cc +++ b/plugin/example_key_management/example_key_management_plugin.cc @@ -58,32 +58,21 @@ get_latest_key_version() return key_version; } -static int -get_key(unsigned int version, unsigned char* dstbuf, unsigned buflen) +static unsigned int +get_key(unsigned int version, unsigned char* dstbuf, unsigned *buflen) { - unsigned char *dst = dstbuf; - unsigned len = 0; - for (; len + MD5_HASH_SIZE <= buflen; len += MD5_HASH_SIZE) - { - compute_md5_hash(dst, (const char*)&version, sizeof(version)); - dst += MD5_HASH_SIZE; - version++; - } - if (len < buflen) + if (*buflen < MD5_HASH_SIZE) { - memset(dst, 0, buflen - len); + *buflen= MD5_HASH_SIZE; + return KEY_BUFFER_TOO_SMALL; } - return 0; -} + *buflen= MD5_HASH_SIZE; + if (!dstbuf) + return 0; -static unsigned int has_key_func(unsigned int keyID) -{ - return true; -} + my_md5(dstbuf, (const char*)&version, sizeof(version)); -static unsigned int get_key_size(unsigned int keyID) -{ - return 16; + return 0; } static int example_key_management_plugin_init(void *p) @@ -115,8 +104,6 @@ static int example_key_management_plugin_deinit(void *p) struct st_mariadb_encryption_key_management example_key_management_plugin= { MariaDB_ENCRYPTION_KEY_MANAGEMENT_INTERFACE_VERSION, get_latest_key_version, - has_key_func, - get_key_size, get_key }; diff --git a/plugin/file_key_management/file_key_management_plugin.cc b/plugin/file_key_management/file_key_management_plugin.cc index 125f5b6e91d..60007e4487d 100644 --- a/plugin/file_key_management/file_key_management_plugin.cc +++ b/plugin/file_key_management/file_key_management_plugin.cc @@ -67,36 +67,25 @@ static unsigned int get_highest_key_used_in_key_file() return 0; } -static unsigned int has_key_from_key_file(unsigned int key_id) +static unsigned int get_key_from_key_file(unsigned int key_id, + unsigned char* dstbuf, unsigned *buflen) { keyentry* entry = get_key(key_id); - return entry != NULL; -} - -static unsigned int get_key_size_from_key_file(unsigned int key_id) -{ - keyentry* entry = get_key(key_id); - - return entry ? entry->length : CRYPT_KEY_UNKNOWN; -} + if (entry == NULL) + return BAD_ENCRYPTION_KEY_VERSION; -static int get_key_from_key_file(unsigned int key_id, unsigned char* dstbuf, - unsigned buflen) -{ - keyentry* entry = get_key(key_id); - - if (entry != NULL) + if (*buflen < entry->length) { - if (buflen < entry->length) - return CRYPT_BUFFER_TO_SMALL; + *buflen= entry->length; + return KEY_BUFFER_TOO_SMALL; + } + *buflen= entry->length; + if (dstbuf) memcpy(dstbuf, entry->key, entry->length); - return CRYPT_KEY_OK; - } - else - return CRYPT_KEY_UNKNOWN; + return 0; } static int file_key_management_plugin_init(void *p) @@ -108,8 +97,6 @@ static int file_key_management_plugin_init(void *p) struct st_mariadb_encryption_key_management file_key_management_plugin= { MariaDB_ENCRYPTION_KEY_MANAGEMENT_INTERFACE_VERSION, get_highest_key_used_in_key_file, - has_key_from_key_file, - get_key_size_from_key_file, get_key_from_key_file }; |