diff options
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 8 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 8 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 8 | ||||
-rw-r--r-- | include/mysql/service_sha1.h | 14 | ||||
-rw-r--r-- | include/service_versions.h | 2 | ||||
-rw-r--r-- | mysys_ssl/my_sha1.cc | 119 | ||||
-rw-r--r-- | sql/sql_plugin_services.h | 8 |
7 files changed, 102 insertions, 65 deletions
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 98fd089570d..48bb552857d 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -112,9 +112,17 @@ void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); extern struct my_sha1_service_st { void (*my_sha1_type)(unsigned char*, const char*, size_t); void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); } *my_sha1_service; void my_sha1(unsigned char*, const char*, size_t); void my_sha1_multi(unsigned char*, ...); +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_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 6d52c5be7f0..4b45a1f44fd 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -112,9 +112,17 @@ void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); extern struct my_sha1_service_st { void (*my_sha1_type)(unsigned char*, const char*, size_t); void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); } *my_sha1_service; void my_sha1(unsigned char*, const char*, size_t); void my_sha1_multi(unsigned char*, ...); +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_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 cb3e7cafc97..e1e3704e506 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -112,9 +112,17 @@ void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); extern struct my_sha1_service_st { void (*my_sha1_type)(unsigned char*, const char*, size_t); void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); } *my_sha1_service; void my_sha1(unsigned char*, const char*, size_t); void my_sha1_multi(unsigned char*, ...); +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_logger.h> typedef struct logger_handle_st LOGGER_HANDLE; extern struct logger_service_st { diff --git a/include/mysql/service_sha1.h b/include/mysql/service_sha1.h index 01f5ba81566..609e173e8ce 100644 --- a/include/mysql/service_sha1.h +++ b/include/mysql/service_sha1.h @@ -1,5 +1,5 @@ #ifndef MYSQL_SERVICE_SHA1_INCLUDED -/* Copyright (c) 2013, Monty Program Ab +/* Copyright (c) 2013, 2014, 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 @@ -34,17 +34,29 @@ extern "C" { extern struct my_sha1_service_st { void (*my_sha1_type)(unsigned char*, const char*, size_t); void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); } *my_sha1_service; #ifdef MYSQL_DYNAMIC_PLUGIN #define my_sha1(A,B,C) my_sha1_service->my_sha1_type(A,B,C) #define my_sha1_multi my_sha1_service->my_sha1_multi_type +#define my_sha1_context_size_type() my_sha1_service->my_sha1_context_size_type() +#define my_sha1_init_type(A) my_sha1_service->my_sha1_init_type(A) +#define my_sha1_input_type(A,B,C) my_sha1_service->my_sha1_input_type(A,B,C) +#define my_sha1_result_type(A,B) my_sha1_service->my_sha1_result_type(A,B) #else void my_sha1(unsigned char*, const char*, size_t); void my_sha1_multi(unsigned char*, ...); +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); #endif diff --git a/include/service_versions.h b/include/service_versions.h index cca190b811c..765a15f12e5 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -28,7 +28,7 @@ #define VERSION_thd_wait 0x0100 #define VERSION_progress_report 0x0100 #define VERSION_thd_timezone 0x0100 -#define VERSION_my_sha1 0x0100 +#define VERSION_my_sha1 0x0101 #define VERSION_logger 0x0100 #define VERSION_thd_autoinc 0x0100 #define VERSION_thd_error_context 0x0100 diff --git a/mysys_ssl/my_sha1.cc b/mysys_ssl/my_sha1.cc index fc8f88856bb..9b12d1f1ae8 100644 --- a/mysys_ssl/my_sha1.cc +++ b/mysys_ssl/my_sha1.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 @@ -29,66 +30,52 @@ #if defined(HAVE_YASSL) #include "sha.hpp" -/** - Compute SHA1 message digest using YaSSL. +typedef TaoCrypt::SHA SHA_CTX; - @param digest [out] Computed SHA1 digest - @param buf [in] Message to be computed - @param len [in] Length of the message +static void sha1_init(SHA_CTX *context) +{ + context->Init(); +} - @return void +/* + this is a variant of sha1_init to be used in this file only. + does nothing for yassl, because the context's constructor was called automatically. */ -void mysql_sha1_yassl(uint8 *digest, const char *buf, int len) +static void sha1_init_fast(SHA_CTX *context) { - TaoCrypt::SHA hasher; - hasher.Update((const TaoCrypt::byte *) buf, len); - hasher.Final ((TaoCrypt::byte *) digest); } -/** - Compute SHA1 message digest for two messages in order to - emulate sha1(msg1, msg2) using YaSSL. - - @param digest [out] Computed SHA1 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 +static void sha1_input(SHA_CTX *context, const uchar *buf, unsigned len) +{ + context->Update((const TaoCrypt::byte *) buf, len); +} - @return void -*/ -void mysql_sha1_multi_yassl(uint8 *digest, va_list args) +static void sha1_result(SHA_CTX *context, uchar digest[SHA1_HASH_SIZE]) { - const char *str; - TaoCrypt::SHA hasher; - - for (str= va_arg(args, const char*); str; str= va_arg(args, const char*)) - { - hasher.Update((const TaoCrypt::byte *) str, va_arg(args, size_t)); - } - hasher.Final((TaoCrypt::byte *) digest); + context->Final((TaoCrypt::byte *) digest); } #elif defined(HAVE_OPENSSL) #include <openssl/sha.h> -int mysql_sha1_reset(SHA_CTX *context) +static void sha1_init(SHA_CTX *context) { - return SHA1_Init(context); + SHA1_Init(context); } - -int mysql_sha1_input(SHA_CTX *context, const uint8 *message_array, - unsigned length) +static void sha1_init_fast(SHA_CTX *context) { - return SHA1_Update(context, message_array, length); + sha1_init(context); } +static void sha1_input(SHA_CTX *context, const uchar *buf, unsigned len) +{ + SHA1_Update(context, buf, len); +} -int mysql_sha1_result(SHA_CTX *context, - uint8 Message_Digest[SHA1_HASH_SIZE]) +static void sha1_result(SHA_CTX *context, uchar digest[SHA1_HASH_SIZE]) { - return SHA1_Final(Message_Digest, context); + SHA1_Final(digest, context); } #endif /* HAVE_YASSL */ @@ -102,17 +89,13 @@ int mysql_sha1_result(SHA_CTX *context, @return void */ -void my_sha1(uint8 *digest, const char *buf, size_t len) +void my_sha1(uchar *digest, const char *buf, size_t len) { -#if defined(HAVE_YASSL) - mysql_sha1_yassl(digest, buf, len); -#elif defined(HAVE_OPENSSL) SHA_CTX sha1_context; - mysql_sha1_reset(&sha1_context); - mysql_sha1_input(&sha1_context, (const uint8 *) buf, len); - mysql_sha1_result(&sha1_context, digest); -#endif /* HAVE_YASSL */ + sha1_init_fast(&sha1_context); + sha1_input(&sha1_context, (const uchar *)buf, len); + sha1_result(&sha1_context, digest); } @@ -128,24 +111,38 @@ void my_sha1(uint8 *digest, const char *buf, size_t len) @return void */ -void my_sha1_multi(uint8 *digest, ...) +void my_sha1_multi(uchar *digest, ...) { va_list args; va_start(args, digest); -#if defined(HAVE_YASSL) - mysql_sha1_multi_yassl(digest, args); -#elif defined(HAVE_OPENSSL) SHA_CTX sha1_context; - const char *str; - - mysql_sha1_reset(&sha1_context); - for (str= va_arg(args, const char*); str; str= va_arg(args, const char*)) - { - mysql_sha1_input(&sha1_context, (const uint8 *) str, va_arg(args, size_t)); - } - mysql_sha1_result(&sha1_context, digest); -#endif /* HAVE_YASSL */ + const uchar *str; + + sha1_init_fast(&sha1_context); + for (str= va_arg(args, const uchar*); str; str= va_arg(args, const uchar*)) + sha1_input(&sha1_context, str, va_arg(args, size_t)); + + sha1_result(&sha1_context, digest); va_end(args); } +size_t my_sha1_context_size() +{ + return sizeof(SHA_CTX); +} + +void my_sha1_init(void *context) +{ + sha1_init((SHA_CTX *)context); +} + +void my_sha1_input(void *context, const uchar *buf, size_t len) +{ + sha1_input((SHA_CTX *)context, buf, len); +} + +void my_sha1_result(void *context, uchar *digest) +{ + sha1_result((SHA_CTX *)context, digest); +} diff --git a/sql/sql_plugin_services.h b/sql/sql_plugin_services.h index 38b4c4074be..43e711d145e 100644 --- a/sql/sql_plugin_services.h +++ b/sql/sql_plugin_services.h @@ -1,5 +1,5 @@ /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. - Copyright (c) 2012, 2013, Monty Program Ab + Copyright (c) 2012, 2014, 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 @@ -61,7 +61,11 @@ static struct thd_timezone_service_st thd_timezone_handler= { static struct my_sha1_service_st my_sha1_handler = { my_sha1, - my_sha1_multi + my_sha1_multi, + my_sha1_context_size, + my_sha1_init, + my_sha1_input, + my_sha1_result }; static struct logger_service_st logger_service_handler= { |