summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2014-09-26 20:03:20 +0200
committerSergei Golubchik <serg@mariadb.org>2014-10-01 23:38:28 +0200
commitd6141a553c566b3c8f997ae811dd4c00d9019613 (patch)
tree7c2665d2864172a6f15a284d5f752407a0ce90fb
parent11b6452a0f2f0f99bbd7c2767ebca7d043a2f43c (diff)
downloadmariadb-git-d6141a553c566b3c8f997ae811dd4c00d9019613.tar.gz
MD5 service
-rw-r--r--include/my_md5.h2
-rw-r--r--include/mysql/plugin.h2
-rw-r--r--include/mysql/plugin_audit.h.pp15
-rw-r--r--include/mysql/plugin_auth.h.pp15
-rw-r--r--include/mysql/plugin_ftparser.h.pp15
-rw-r--r--include/mysql/service_md5.h69
-rw-r--r--include/mysql/services.h1
-rw-r--r--include/service_versions.h1
-rw-r--r--libservices/CMakeLists.txt1
-rw-r--r--libservices/my_md5_service.c18
-rw-r--r--mysys_ssl/my_md5.cc124
-rw-r--r--sql/item_strfunc.cc3
-rw-r--r--sql/sql_plugin_services.h10
-rw-r--r--sql/table.cc2
-rw-r--r--storage/perfschema/pfs_digest.cc2
-rw-r--r--storage/perfschema/table_events_statements.cc2
-rw-r--r--storage/perfschema/unittest/CMakeLists.txt2
17 files changed, 254 insertions, 30 deletions
diff --git a/include/my_md5.h b/include/my_md5.h
index 77557fb9346..141ea309cae 100644
--- a/include/my_md5.h
+++ b/include/my_md5.h
@@ -28,7 +28,7 @@
extern "C" {
#endif
-void compute_md5_hash(char *digest, const char *buf, int len);
+#define compute_md5_hash(A,B,C) my_md5(A,B,C)
/*
Convert an array of bytes to a hexadecimal representation.
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index ceb6ac93ff5..03bf59ad7ac 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -75,7 +75,7 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0104
/* MariaDB plugin interface version */
-#define MARIA_PLUGIN_INTERFACE_VERSION 0x0108
+#define MARIA_PLUGIN_INTERFACE_VERSION 0x0109
/*
The allowable types of plugins
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp
index 48bb552857d..ce456806fb8 100644
--- a/include/mysql/plugin_audit.h.pp
+++ b/include/mysql/plugin_audit.h.pp
@@ -123,6 +123,21 @@ size_t my_sha1_context_size();
void my_sha1_init(void *context);
void my_sha1_input(void *context, const unsigned char *buf, size_t len);
void my_sha1_result(void *context, unsigned char *digest);
+#include <mysql/service_md5.h>
+extern struct my_md5_service_st {
+ void (*my_md5_type)(unsigned char*, const char*, size_t);
+ void (*my_md5_multi_type)(unsigned char*, ...);
+ size_t (*my_md5_context_size_type)();
+ void (*my_md5_init_type)(void *);
+ void (*my_md5_input_type)(void *, const unsigned char *, size_t);
+ void (*my_md5_result_type)(void *, unsigned char *);
+} *my_md5_service;
+void my_md5(unsigned char*, const char*, size_t);
+void my_md5_multi(unsigned char*, ...);
+size_t my_md5_context_size();
+void my_md5_init(void *context);
+void my_md5_input(void *context, const unsigned char *buf, size_t len);
+void my_md5_result(void *context, unsigned char *digest);
#include <mysql/service_logger.h>
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp
index 4b45a1f44fd..fefbb06ab8c 100644
--- a/include/mysql/plugin_auth.h.pp
+++ b/include/mysql/plugin_auth.h.pp
@@ -123,6 +123,21 @@ size_t my_sha1_context_size();
void my_sha1_init(void *context);
void my_sha1_input(void *context, const unsigned char *buf, size_t len);
void my_sha1_result(void *context, unsigned char *digest);
+#include <mysql/service_md5.h>
+extern struct my_md5_service_st {
+ void (*my_md5_type)(unsigned char*, const char*, size_t);
+ void (*my_md5_multi_type)(unsigned char*, ...);
+ size_t (*my_md5_context_size_type)();
+ void (*my_md5_init_type)(void *);
+ void (*my_md5_input_type)(void *, const unsigned char *, size_t);
+ void (*my_md5_result_type)(void *, unsigned char *);
+} *my_md5_service;
+void my_md5(unsigned char*, const char*, size_t);
+void my_md5_multi(unsigned char*, ...);
+size_t my_md5_context_size();
+void my_md5_init(void *context);
+void my_md5_input(void *context, const unsigned char *buf, size_t len);
+void my_md5_result(void *context, unsigned char *digest);
#include <mysql/service_logger.h>
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp
index e1e3704e506..0d28f6a00ff 100644
--- a/include/mysql/plugin_ftparser.h.pp
+++ b/include/mysql/plugin_ftparser.h.pp
@@ -123,6 +123,21 @@ size_t my_sha1_context_size();
void my_sha1_init(void *context);
void my_sha1_input(void *context, const unsigned char *buf, size_t len);
void my_sha1_result(void *context, unsigned char *digest);
+#include <mysql/service_md5.h>
+extern struct my_md5_service_st {
+ void (*my_md5_type)(unsigned char*, const char*, size_t);
+ void (*my_md5_multi_type)(unsigned char*, ...);
+ size_t (*my_md5_context_size_type)();
+ void (*my_md5_init_type)(void *);
+ void (*my_md5_input_type)(void *, const unsigned char *, size_t);
+ void (*my_md5_result_type)(void *, unsigned char *);
+} *my_md5_service;
+void my_md5(unsigned char*, const char*, size_t);
+void my_md5_multi(unsigned char*, ...);
+size_t my_md5_context_size();
+void my_md5_init(void *context);
+void my_md5_input(void *context, const unsigned char *buf, size_t len);
+void my_md5_result(void *context, unsigned char *digest);
#include <mysql/service_logger.h>
typedef struct logger_handle_st LOGGER_HANDLE;
extern struct logger_service_st {
diff --git a/include/mysql/service_md5.h b/include/mysql/service_md5.h
new file mode 100644
index 00000000000..faf967a5739
--- /dev/null
+++ b/include/mysql/service_md5.h
@@ -0,0 +1,69 @@
+#ifndef MYSQL_SERVICE_MD5_INCLUDED
+/* Copyright (c) 2013, Monty Program Ab
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+/**
+ @file
+ my md5 service
+
+ Functions to calculate MD5 hash from a memory buffer
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdlib.h>
+#endif
+
+#define MY_MD5_HASH_SIZE 16 /* Hash size in bytes */
+
+extern struct my_md5_service_st {
+ void (*my_md5_type)(unsigned char*, const char*, size_t);
+ void (*my_md5_multi_type)(unsigned char*, ...);
+ size_t (*my_md5_context_size_type)();
+ void (*my_md5_init_type)(void *);
+ void (*my_md5_input_type)(void *, const unsigned char *, size_t);
+ void (*my_md5_result_type)(void *, unsigned char *);
+} *my_md5_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define my_md5(A,B,C) my_md5_service->my_md5_type(A,B,C)
+#define my_md5_multi my_md5_service->my_md5_multi_type
+#define my_md5_context_size() my_md5_service->my_md5_context_size_type()
+#define my_md5_init(A) my_md5_service->my_md5_init_type(A)
+#define my_md5_input(A,B,C) my_md5_service->my_md5_input_type(A,B,C)
+#define my_md5_result(A,B) my_md5_service->my_md5_result_type(A,B)
+
+#else
+
+void my_md5(unsigned char*, const char*, size_t);
+void my_md5_multi(unsigned char*, ...);
+size_t my_md5_context_size();
+void my_md5_init(void *context);
+void my_md5_input(void *context, const unsigned char *buf, size_t len);
+void my_md5_result(void *context, unsigned char *digest);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#define MYSQL_SERVICE_MD5_INCLUDED
+#endif
+
diff --git a/include/mysql/services.h b/include/mysql/services.h
index 62cac338703..a969cfb388e 100644
--- a/include/mysql/services.h
+++ b/include/mysql/services.h
@@ -27,6 +27,7 @@ extern "C" {
#include <mysql/service_kill_statement.h>
#include <mysql/service_thd_timezone.h>
#include <mysql/service_sha1.h>
+#include <mysql/service_md5.h>
#include <mysql/service_logger.h>
#include <mysql/service_thd_autoinc.h>
#include <mysql/service_thd_error_context.h>
diff --git a/include/service_versions.h b/include/service_versions.h
index 765a15f12e5..c9d7571fa10 100644
--- a/include/service_versions.h
+++ b/include/service_versions.h
@@ -29,6 +29,7 @@
#define VERSION_progress_report 0x0100
#define VERSION_thd_timezone 0x0100
#define VERSION_my_sha1 0x0101
+#define VERSION_my_md5 0x0100
#define VERSION_logger 0x0100
#define VERSION_thd_autoinc 0x0100
#define VERSION_thd_error_context 0x0100
diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt
index d70a98802f5..12f7d6cc1a8 100644
--- a/libservices/CMakeLists.txt
+++ b/libservices/CMakeLists.txt
@@ -25,6 +25,7 @@ SET(MYSQLSERVICES_SOURCES
progress_report_service.c
debug_sync_service.c
my_sha1_service.c
+ my_md5_service.c
kill_statement_service.c
logger_service.c)
diff --git a/libservices/my_md5_service.c b/libservices/my_md5_service.c
new file mode 100644
index 00000000000..f9db24d0179
--- /dev/null
+++ b/libservices/my_md5_service.c
@@ -0,0 +1,18 @@
+/* Copyright (c) 2013 Monty Program Ab
+ Use is subject to license terms.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include <service_versions.h>
+SERVICE_VERSION my_md5_service= (void*)VERSION_my_md5;
diff --git a/mysys_ssl/my_md5.cc b/mysys_ssl/my_md5.cc
index 4c14366a4e3..697655244eb 100644
--- a/mysys_ssl/my_md5.cc
+++ b/mysys_ssl/my_md5.cc
@@ -1,4 +1,5 @@
-/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2012, Oracle and/or its affiliates.
+ Copyright (c) 2014, SkySQL Ab.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,45 +25,124 @@
#include <my_global.h>
#include <my_md5.h>
+#include <stdarg.h>
#if defined(HAVE_YASSL)
-#include "my_config.h"
#include "md5.hpp"
-static void my_md5_hash(char *digest, const char *buf, int len)
+typedef TaoCrypt::MD5 MD5_CTX;
+
+static void md5_init(MD5_CTX *context)
+{
+ context->Init();
+}
+
+/*
+ this is a variant of md5_init to be used in this file only.
+ does nothing for yassl, because the context's constructor was called automatically.
+*/
+static void md5_init_fast(MD5_CTX *context)
+{
+}
+
+static void md5_input(MD5_CTX *context, const uchar *buf, unsigned len)
+{
+ context->Update((const TaoCrypt::byte *) buf, len);
+}
+
+static void md5_result(MD5_CTX *context, uchar digest[MD5_HASH_SIZE])
{
- TaoCrypt::MD5 hasher;
- hasher.Update((TaoCrypt::byte *) buf, len);
- hasher.Final((TaoCrypt::byte *) digest);
+ context->Final((TaoCrypt::byte *) digest);
}
#elif defined(HAVE_OPENSSL)
#include <openssl/md5.h>
-static void my_md5_hash(unsigned char* digest, unsigned const char *buf, int len)
+static void md5_init(MD5_CTX *context)
+{
+ MD5_Init(context);
+}
+
+static void md5_init_fast(MD5_CTX *context)
+{
+ md5_init(context);
+}
+
+static void md5_input(MD5_CTX *context, const uchar *buf, unsigned len)
+{
+ MD5_Update(context, buf, len);
+}
+
+static void md5_result(MD5_CTX *context, uchar digest[MD5_HASH_SIZE])
{
- MD5_CTX ctx;
- MD5_Init (&ctx);
- MD5_Update (&ctx, buf, len);
- MD5_Final (digest, &ctx);
+ MD5_Final(digest, context);
}
#endif /* HAVE_YASSL */
/**
- Wrapper function to compute MD5 message digest.
+ Wrapper function to compute MD5 message digest.
- @param digest [out] Computed MD5 digest
- @param buf [in] Message to be computed
- @param len [in] Length of the message
+ @param digest [out] Computed MD5 digest
+ @param buf [in] Message to be computed
+ @param len [in] Length of the message
- @return void
+ @return void
*/
-void compute_md5_hash(char *digest, const char *buf, int len)
+void my_md5(uchar *digest, const char *buf, size_t len)
{
-#if defined(HAVE_YASSL)
- my_md5_hash(digest, buf, len);
-#elif defined(HAVE_OPENSSL)
- my_md5_hash((unsigned char*)digest, (unsigned const char*)buf, len);
-#endif /* HAVE_YASSL */
+ MD5_CTX md5_context;
+
+ md5_init_fast(&md5_context);
+ md5_input(&md5_context, (const uchar *)buf, len);
+ md5_result(&md5_context, digest);
+}
+
+
+/**
+ Wrapper function to compute MD5 message digest for
+ two messages in order to emulate md5(msg1, msg2).
+
+ @param digest [out] Computed MD5 digest
+ @param buf1 [in] First message
+ @param len1 [in] Length of first message
+ @param buf2 [in] Second message
+ @param len2 [in] Length of second message
+
+ @return void
+*/
+void my_md5_multi(uchar *digest, ...)
+{
+ va_list args;
+ va_start(args, digest);
+
+ MD5_CTX md5_context;
+ const uchar *str;
+
+ md5_init_fast(&md5_context);
+ for (str= va_arg(args, const uchar*); str; str= va_arg(args, const uchar*))
+ md5_input(&md5_context, str, va_arg(args, size_t));
+
+ md5_result(&md5_context, digest);
+ va_end(args);
+}
+
+size_t my_md5_context_size()
+{
+ return sizeof(MD5_CTX);
+}
+
+void my_md5_init(void *context)
+{
+ md5_init((MD5_CTX *)context);
+}
+
+void my_md5_input(void *context, const uchar *buf, size_t len)
+{
+ md5_input((MD5_CTX *)context, buf, len);
+}
+
+void my_md5_result(void *context, uchar *digest)
+{
+ md5_result((MD5_CTX *)context, digest);
}
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index ec6ab0f3040..fa6ba706718 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -163,8 +163,7 @@ String *Item_func_md5::val_str_ascii(String *str)
uchar digest[16];
null_value=0;
- compute_md5_hash((char *) digest, (const char *) sptr->ptr(),
- sptr->length());
+ compute_md5_hash(digest, (const char *) sptr->ptr(), sptr->length());
if (str->alloc(32)) // Ensure that memory is free
{
null_value=1;
diff --git a/sql/sql_plugin_services.h b/sql/sql_plugin_services.h
index 43e711d145e..417c16c1112 100644
--- a/sql/sql_plugin_services.h
+++ b/sql/sql_plugin_services.h
@@ -68,6 +68,15 @@ static struct my_sha1_service_st my_sha1_handler = {
my_sha1_result
};
+static struct my_md5_service_st my_md5_handler = {
+ my_md5,
+ my_md5_multi,
+ my_md5_context_size,
+ my_md5_init,
+ my_md5_input,
+ my_md5_result
+};
+
static struct logger_service_st logger_service_handler= {
logger_init_mutexes,
logger_open,
@@ -100,6 +109,7 @@ static struct st_service_ref list_of_services[]=
{ "thd_kill_statement_service", VERSION_kill_statement, &thd_kill_statement_handler },
{ "thd_timezone_service", VERSION_thd_timezone, &thd_timezone_handler },
{ "my_sha1_service", VERSION_my_sha1, &my_sha1_handler},
+ { "my_md5_service", VERSION_my_md5, &my_md5_handler},
{ "logger_service", VERSION_logger, &logger_service_handler },
{ "thd_autoinc_service", VERSION_thd_autoinc, &thd_autoinc_handler },
{ "thd_error_context_service", VERSION_thd_error_context, &thd_error_conext_handler },
diff --git a/sql/table.cc b/sql/table.cc
index d720a16f6e5..4f642cadaa2 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -4125,7 +4125,7 @@ void TABLE::reset_item_list(List<Item> *item_list) const
void TABLE_LIST::calc_md5(char *buffer)
{
uchar digest[16];
- compute_md5_hash((char*) digest, select_stmt.str,
+ compute_md5_hash(digest, select_stmt.str,
select_stmt.length);
sprintf((char *) buffer,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
diff --git a/storage/perfschema/pfs_digest.cc b/storage/perfschema/pfs_digest.cc
index 473f4edce7a..bafc22e4b75 100644
--- a/storage/perfschema/pfs_digest.cc
+++ b/storage/perfschema/pfs_digest.cc
@@ -192,7 +192,7 @@ find_or_create_digest(PFS_thread *thread,
PFS_digest_key hash_key;
memset(& hash_key, 0, sizeof(hash_key));
/* Compute MD5 Hash of the tokens received. */
- compute_md5_hash((char *) hash_key.m_md5,
+ compute_md5_hash(hash_key.m_md5,
(char *) digest_storage->m_token_array,
digest_storage->m_byte_count);
/* Add the current schema to the key */
diff --git a/storage/perfschema/table_events_statements.cc b/storage/perfschema/table_events_statements.cc
index c6d0bc2e24e..d520c712e5b 100644
--- a/storage/perfschema/table_events_statements.cc
+++ b/storage/perfschema/table_events_statements.cc
@@ -296,7 +296,7 @@ void table_events_statements_common::make_row_part_2(PSI_digest_storage *digest)
safe_byte_count <= PSI_MAX_DIGEST_STORAGE_SIZE)
{
PFS_digest_key md5;
- compute_md5_hash((char *) md5.m_md5,
+ compute_md5_hash(md5.m_md5,
(char *) digest->m_token_array,
safe_byte_count);
diff --git a/storage/perfschema/unittest/CMakeLists.txt b/storage/perfschema/unittest/CMakeLists.txt
index 6add43de7f9..6ef9e91cf47 100644
--- a/storage/perfschema/unittest/CMakeLists.txt
+++ b/storage/perfschema/unittest/CMakeLists.txt
@@ -24,4 +24,4 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
ADD_DEFINITIONS(-DMYSQL_SERVER ${SSL_DEFINES})
MY_ADD_TESTS(pfs_instr_class pfs_instr_class-oom pfs_instr pfs_instr-oom pfs_account-oom pfs_host-oom pfs_timer pfs_user-oom pfs
- EXT "cc" LINK_LIBRARIES perfschema mysys)
+ EXT "cc" LINK_LIBRARIES perfschema mysys mysys_ssl)