mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 17:54:16 +01:00
MD5 service
This commit is contained in:
parent
11b6452a0f
commit
d6141a553c
17 changed files with 254 additions and 30 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
69
include/mysql/service_md5.h
Normal file
69
include/mysql/service_md5.h
Normal file
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
18
libservices/my_md5_service.c
Normal file
18
libservices/my_md5_service.c
Normal file
|
@ -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;
|
|
@ -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)
|
||||
{
|
||||
TaoCrypt::MD5 hasher;
|
||||
hasher.Update((TaoCrypt::byte *) buf, len);
|
||||
hasher.Final((TaoCrypt::byte *) digest);
|
||||
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])
|
||||
{
|
||||
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_CTX ctx;
|
||||
MD5_Init (&ctx);
|
||||
MD5_Update (&ctx, buf, len);
|
||||
MD5_Final (digest, &ctx);
|
||||
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_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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue