summaryrefslogtreecommitdiff
path: root/mysys_ssl
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2017-03-30 12:48:42 +0200
committerSergei Golubchik <serg@mariadb.org>2017-03-30 12:48:42 +0200
commitda4d71d10d23c1ac2d10b72baee14991ccb7a146 (patch)
tree7cdf3a8c8e72ca7c1c8105427c04123f025bd870 /mysys_ssl
parent9ec85009985d644ce7ae797bc3572d0ad0f69bb0 (diff)
parenta00517ac9707ffd51c092f5af5d198c5ee789bb4 (diff)
downloadmariadb-git-da4d71d10d23c1ac2d10b72baee14991ccb7a146.tar.gz
Merge branch '10.1' into 10.2
Diffstat (limited to 'mysys_ssl')
-rw-r--r--mysys_ssl/CMakeLists.txt26
-rw-r--r--mysys_ssl/my_rnd.cc103
-rw-r--r--mysys_ssl/my_sha.ic188
-rw-r--r--mysys_ssl/my_sha1.cc136
-rw-r--r--mysys_ssl/my_sha2.cc68
-rw-r--r--mysys_ssl/my_sha224.cc18
-rw-r--r--mysys_ssl/my_sha256.cc18
-rw-r--r--mysys_ssl/my_sha384.cc18
-rw-r--r--mysys_ssl/my_sha512.cc18
9 files changed, 278 insertions, 315 deletions
diff --git a/mysys_ssl/CMakeLists.txt b/mysys_ssl/CMakeLists.txt
index 8a8f81d70ae..4f6f7458c5b 100644
--- a/mysys_ssl/CMakeLists.txt
+++ b/mysys_ssl/CMakeLists.txt
@@ -21,25 +21,29 @@ IF(SSL_DEFINES)
ADD_DEFINITIONS(${SSL_DEFINES})
ENDIF()
+SET(MYSYS_SSL_HIDDEN_SOURCES
+ my_sha1.cc
+ my_sha224.cc
+ my_sha256.cc
+ my_sha384.cc
+ my_sha512.cc
+ my_md5.cc
+ )
+
+SET(MYSYS_SSL_SOURCES
+ ${MYSYS_SSL_HIDDEN_SOURCES}
+ my_crypt.cc
+ )
+
# We do RESTRICT_SYMBOL_EXPORTS(yassl) elsewhere.
# In order to get correct symbol visibility, these files
# must be compiled with "-fvisibility=hidden"
IF(WITH_SSL STREQUAL "bundled" AND HAVE_VISIBILITY_HIDDEN)
SET_SOURCE_FILES_PROPERTIES(
- my_md5.cc
- my_sha1.cc
- my_sha2.cc
+ ${MYSYS_SSL_HIDDEN_SOURCES}
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
ENDIF()
-SET(MYSYS_SSL_SOURCES
- my_sha1.cc
- my_sha2.cc
- my_md5.cc
- my_rnd.cc
- my_crypt.cc
- )
-
ADD_CONVENIENCE_LIBRARY(mysys_ssl ${MYSYS_SSL_SOURCES})
TARGET_LINK_LIBRARIES(mysys_ssl dbug strings ${SSL_LIBRARIES})
DTRACE_INSTRUMENT(mysys_ssl)
diff --git a/mysys_ssl/my_rnd.cc b/mysys_ssl/my_rnd.cc
deleted file mode 100644
index aa8fb63cd4d..00000000000
--- a/mysys_ssl/my_rnd.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
-
- 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 <my_global.h>
-#include <my_rnd.h>
-#include <m_string.h>
-
-#if defined(HAVE_YASSL)
-#if defined(YASSL_PREFIX)
-#define RAND_bytes yaRAND_bytes
-#endif /* YASSL_PREFIX */
-
-#include <openssl/ssl.h>
-
-#elif defined(HAVE_OPENSSL)
-#include <openssl/rand.h>
-#endif /* HAVE_YASSL */
-
-
-/*
- A wrapper to use OpenSSL/yaSSL PRNGs.
-*/
-
-extern "C" {
-
-/*
- Initialize random generator
-
- NOTES
- MySQL's password checks depends on this, so don't do any changes
- that changes the random numbers that are generated!
-*/
-
-void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2)
-{
-#ifdef HAVE_valgrind
- bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */
-#endif
- rand_st->max_value= 0x3FFFFFFFL;
- rand_st->max_value_dbl=(double) rand_st->max_value;
- rand_st->seed1=seed1%rand_st->max_value ;
- rand_st->seed2=seed2%rand_st->max_value;
-}
-
-/**
- Generate random number.
-
- @param rand_st [INOUT] Structure used for number generation.
-
- @retval Generated pseudo random number.
-*/
-
-double my_rnd(struct my_rnd_struct *rand_st)
-{
- rand_st->seed1= (rand_st->seed1*3+rand_st->seed2) % rand_st->max_value;
- rand_st->seed2= (rand_st->seed1+rand_st->seed2+33) % rand_st->max_value;
- return (((double) rand_st->seed1) / rand_st->max_value_dbl);
-}
-
-/**
- Generate a random number using the OpenSSL/yaSSL supplied
- random number generator if available.
-
- @param rand_st [INOUT] Structure used for number generation
- only if none of the SSL libraries are
- available.
-
- @retval Generated random number.
-*/
-
-double my_rnd_ssl(struct my_rnd_struct *rand_st)
-{
-
-#if defined(HAVE_YASSL) || defined(HAVE_OPENSSL)
- int rc;
- unsigned int res;
-
-#if defined(HAVE_YASSL)
- rc= yaSSL::RAND_bytes((unsigned char *) &res, sizeof (unsigned int));
-#else
- rc= RAND_bytes((unsigned char *) &res, sizeof (unsigned int));
-#endif /* HAVE_YASSL */
- if (rc)
- return (double)res / (double)UINT_MAX;
-
-#endif /* defined(HAVE_YASSL) || defined(HAVE_OPENSSL) */
- return my_rnd(rand_st);
-}
-
-}
diff --git a/mysys_ssl/my_sha.ic b/mysys_ssl/my_sha.ic
new file mode 100644
index 00000000000..a7ec8bad593
--- /dev/null
+++ b/mysys_ssl/my_sha.ic
@@ -0,0 +1,188 @@
+/* Copyright (c) 2012, Oracle and/or its affiliates.
+ Copyright (c) 2014, 2017, MariaDB
+
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+
+/**
+ @file
+
+ @brief
+ Wrapper functions for OpenSSL, YaSSL implementations. Also provides a
+ Compatibility layer to make available YaSSL's SHAn implementation.
+*/
+
+#include <my_global.h>
+#include <stdarg.h>
+
+#define HASH_SIZE (NUM > 1 ? NUM/8 : 20)
+
+#if defined(HAVE_YASSL)
+#include "sha.hpp"
+
+#define xCONTEXT(x) TaoCrypt::SHA ## x
+#define yCONTEXT(y) xCONTEXT(y)
+#define CONTEXT yCONTEXT(NUM)
+#define SHA1 SHA
+
+static void sha_init(CONTEXT *context)
+{
+ context->Init();
+}
+
+/*
+ this is a variant of sha_init to be used in this file only.
+ does nothing for yassl, because the context's constructor was called automatically.
+*/
+static void sha_init_fast(CONTEXT *context)
+{
+}
+
+static void sha_input(CONTEXT *context, const uchar *buf, unsigned len)
+{
+ context->Update((const TaoCrypt::byte *) buf, len);
+}
+
+static void sha_result(CONTEXT *context, uchar digest[HASH_SIZE])
+{
+ context->Final((TaoCrypt::byte *) digest);
+}
+
+#elif defined(HAVE_OPENSSL)
+#include <openssl/sha.h>
+
+#define xCONTEXT(x) SHA ## x ## _CTX
+#define yCONTEXT(y) xCONTEXT(y)
+#define CONTEXT yCONTEXT(NUM)
+#define SHA1_CTX SHA_CTX
+#define SHA224_CTX SHA256_CTX
+#define SHA384_CTX SHA512_CTX
+
+#define xSHA_Init(x) SHA ## x ## _Init
+#define xSHA_Update(x) SHA ## x ## _Update
+#define xSHA_Final(x) SHA ## x ## _Final
+#define ySHA_Init(y) xSHA_Init(y)
+#define ySHA_Update(y) xSHA_Update(y)
+#define ySHA_Final(y) xSHA_Final(y)
+#define SHA_Init ySHA_Init(NUM)
+#define SHA_Update ySHA_Update(NUM)
+#define SHA_Final ySHA_Final(NUM)
+
+static void sha_init(CONTEXT *context)
+{
+ SHA_Init(context);
+}
+
+static void sha_init_fast(CONTEXT *context)
+{
+ sha_init(context);
+}
+
+static void sha_input(CONTEXT *context, const uchar *buf, unsigned len)
+{
+ SHA_Update(context, buf, len);
+}
+
+static void sha_result(CONTEXT *context, uchar digest[HASH_SIZE])
+{
+ SHA_Final(digest, context);
+}
+
+#endif /* HAVE_YASSL */
+
+#define xmy_sha_multi(x) my_sha ## x ## _multi
+#define xmy_sha_context_size(x) my_sha ## x ## _context_size
+#define xmy_sha_init(x) my_sha ## x ## _init
+#define xmy_sha_input(x) my_sha ## x ## _input
+#define xmy_sha_result(x) my_sha ## x ## _result
+#define xmy_sha(x) my_sha ## x
+#define ymy_sha_multi(y) xmy_sha_multi(y)
+#define ymy_sha_context_size(y) xmy_sha_context_size(y)
+#define ymy_sha_init(y) xmy_sha_init(y)
+#define ymy_sha_input(y) xmy_sha_input(y)
+#define ymy_sha_result(y) xmy_sha_result(y)
+#define ymy_sha(y) xmy_sha(y)
+#define my_sha_multi ymy_sha_multi(NUM)
+#define my_sha_context_size ymy_sha_context_size(NUM)
+#define my_sha_init ymy_sha_init(NUM)
+#define my_sha_input ymy_sha_input(NUM)
+#define my_sha_result ymy_sha_result(NUM)
+#define my_sha ymy_sha(NUM)
+
+/**
+ Wrapper function to compute SHAn message digest.
+
+ @param digest [out] Computed SHAn digest
+ @param buf [in] Message to be computed
+ @param len [in] Length of the message
+
+ @return void
+*/
+void my_sha(uchar *digest, const char *buf, size_t len)
+{
+ CONTEXT context;
+
+ sha_init_fast(&context);
+ sha_input(&context, (const uchar *)buf, len);
+ sha_result(&context, digest);
+}
+
+
+/**
+ Wrapper function to compute SHAn message digest for
+ two messages in order to emulate shaN(msg1, msg2).
+
+ @param digest [out] Computed SHAn 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_sha_multi(uchar *digest, ...)
+{
+ va_list args;
+ va_start(args, digest);
+
+ CONTEXT context;
+ const uchar *str;
+
+ sha_init_fast(&context);
+ for (str= va_arg(args, const uchar*); str; str= va_arg(args, const uchar*))
+ sha_input(&context, str, va_arg(args, size_t));
+
+ sha_result(&context, digest);
+ va_end(args);
+}
+
+size_t my_sha_context_size()
+{
+ return sizeof(CONTEXT);
+}
+
+void my_sha_init(void *context)
+{
+ sha_init((CONTEXT *)context);
+}
+
+void my_sha_input(void *context, const uchar *buf, size_t len)
+{
+ sha_input((CONTEXT *)context, buf, len);
+}
+
+void my_sha_result(void *context, uchar *digest)
+{
+ sha_result((CONTEXT *)context, digest);
+}
diff --git a/mysys_ssl/my_sha1.cc b/mysys_ssl/my_sha1.cc
index 9b12d1f1ae8..dc6a7a46179 100644
--- a/mysys_ssl/my_sha1.cc
+++ b/mysys_ssl/my_sha1.cc
@@ -1,5 +1,4 @@
-/* Copyright (c) 2012, Oracle and/or its affiliates.
- Copyright (c) 2014, SkySQL Ab.
+/* Copyright (c) 2017, MariaDB
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
@@ -14,135 +13,6 @@
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+#define NUM 1
-/**
- @file
-
- @brief
- Wrapper functions for OpenSSL, YaSSL implementations. Also provides a
- Compatibility layer to make available YaSSL's SHA1 implementation.
-*/
-
-#include <my_global.h>
-#include <sha1.h>
-#include <stdarg.h>
-
-#if defined(HAVE_YASSL)
-#include "sha.hpp"
-
-typedef TaoCrypt::SHA SHA_CTX;
-
-static void sha1_init(SHA_CTX *context)
-{
- context->Init();
-}
-
-/*
- 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.
-*/
-static void sha1_init_fast(SHA_CTX *context)
-{
-}
-
-static void sha1_input(SHA_CTX *context, const uchar *buf, unsigned len)
-{
- context->Update((const TaoCrypt::byte *) buf, len);
-}
-
-static void sha1_result(SHA_CTX *context, uchar digest[SHA1_HASH_SIZE])
-{
- context->Final((TaoCrypt::byte *) digest);
-}
-
-#elif defined(HAVE_OPENSSL)
-#include <openssl/sha.h>
-
-static void sha1_init(SHA_CTX *context)
-{
- SHA1_Init(context);
-}
-
-static void sha1_init_fast(SHA_CTX *context)
-{
- sha1_init(context);
-}
-
-static void sha1_input(SHA_CTX *context, const uchar *buf, unsigned len)
-{
- SHA1_Update(context, buf, len);
-}
-
-static void sha1_result(SHA_CTX *context, uchar digest[SHA1_HASH_SIZE])
-{
- SHA1_Final(digest, context);
-}
-
-#endif /* HAVE_YASSL */
-
-/**
- Wrapper function to compute SHA1 message digest.
-
- @param digest [out] Computed SHA1 digest
- @param buf [in] Message to be computed
- @param len [in] Length of the message
-
- @return void
-*/
-void my_sha1(uchar *digest, const char *buf, size_t len)
-{
- SHA_CTX sha1_context;
-
- sha1_init_fast(&sha1_context);
- sha1_input(&sha1_context, (const uchar *)buf, len);
- sha1_result(&sha1_context, digest);
-}
-
-
-/**
- Wrapper function to compute SHA1 message digest for
- two messages in order to emulate sha1(msg1, msg2).
-
- @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
-
- @return void
-*/
-void my_sha1_multi(uchar *digest, ...)
-{
- va_list args;
- va_start(args, digest);
-
- SHA_CTX sha1_context;
- 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);
-}
+#include "my_sha.ic"
diff --git a/mysys_ssl/my_sha2.cc b/mysys_ssl/my_sha2.cc
deleted file mode 100644
index 00200337f08..00000000000
--- a/mysys_ssl/my_sha2.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
-
- 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,
- 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
-
-
-/**
- @file
- A compatibility layer to our built-in SSL implementation, to mimic the
- oft-used external library, OpenSSL.
-*/
-
-#include <my_global.h>
-#include <sha2.h>
-
-#ifdef HAVE_YASSL
-
-/*
- If TaoCrypt::SHA512 or ::SHA384 are not defined (but ::SHA256 is), it's
- probably that neither of config.h's SIZEOF_LONG or SIZEOF_LONG_LONG are
- 64 bits long. At present, both OpenSSL and YaSSL require 64-bit integers
- for SHA-512. (The SIZEOF_* definitions come from autoconf's config.h .)
-*/
-
-# define GEN_YASSL_SHA2_BRIDGE(size) \
-unsigned char* SHA##size(const unsigned char *input_ptr, size_t input_length, \
- char unsigned *output_ptr) { \
- TaoCrypt::SHA##size hasher; \
- \
- hasher.Update(input_ptr, input_length); \
- hasher.Final(output_ptr); \
- return(output_ptr); \
-}
-
-
-/**
- @fn SHA512
- @fn SHA384
- @fn SHA256
- @fn SHA224
-
- Instantiate an hash object, fill in the cleartext value, compute the digest,
- and extract the result from the object.
-
- (Generate the functions. See similar .h code for the prototypes.)
-*/
-# ifndef OPENSSL_NO_SHA512
-GEN_YASSL_SHA2_BRIDGE(512);
-GEN_YASSL_SHA2_BRIDGE(384);
-# else
-# warning Some SHA2 functionality is missing. See OPENSSL_NO_SHA512.
-# endif
-GEN_YASSL_SHA2_BRIDGE(256);
-GEN_YASSL_SHA2_BRIDGE(224);
-
-# undef GEN_YASSL_SHA2_BRIDGE
-
-#endif /* HAVE_YASSL */
diff --git a/mysys_ssl/my_sha224.cc b/mysys_ssl/my_sha224.cc
new file mode 100644
index 00000000000..7e8b481256b
--- /dev/null
+++ b/mysys_ssl/my_sha224.cc
@@ -0,0 +1,18 @@
+/* Copyright (c) 2017, MariaDB
+
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#define NUM 224
+
+#include "my_sha.ic"
diff --git a/mysys_ssl/my_sha256.cc b/mysys_ssl/my_sha256.cc
new file mode 100644
index 00000000000..8c1a4662009
--- /dev/null
+++ b/mysys_ssl/my_sha256.cc
@@ -0,0 +1,18 @@
+/* Copyright (c) 2017, MariaDB
+
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#define NUM 256
+
+#include "my_sha.ic"
diff --git a/mysys_ssl/my_sha384.cc b/mysys_ssl/my_sha384.cc
new file mode 100644
index 00000000000..3bad6b39248
--- /dev/null
+++ b/mysys_ssl/my_sha384.cc
@@ -0,0 +1,18 @@
+/* Copyright (c) 2017, MariaDB
+
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#define NUM 384
+
+#include "my_sha.ic"
diff --git a/mysys_ssl/my_sha512.cc b/mysys_ssl/my_sha512.cc
new file mode 100644
index 00000000000..8077efd3b57
--- /dev/null
+++ b/mysys_ssl/my_sha512.cc
@@ -0,0 +1,18 @@
+/* Copyright (c) 2017, MariaDB
+
+ 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,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#define NUM 512
+
+#include "my_sha.ic"