summaryrefslogtreecommitdiff
path: root/plugin/file_key_management
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-03-31 19:00:51 +0200
committerSergei Golubchik <serg@mariadb.org>2015-04-08 10:58:50 +0200
commitef5b4889c2bc1d463291d4d80091c79183ec1196 (patch)
tree41a4b6c7aa57daee2cb617045b87c59c5d520706 /plugin/file_key_management
parentc91e3260e2678078c0bb29d8daa90fb52cefaab7 (diff)
downloadmariadb-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/file_key_management')
-rw-r--r--plugin/file_key_management/file_key_management_plugin.cc35
1 files changed, 11 insertions, 24 deletions
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
};