MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_sha1.cc
Go to the documentation of this file.
1 /* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 
25 #include <my_global.h>
26 #include <sha1.h>
27 
28 #if defined(HAVE_YASSL)
29 #include "sha.hpp"
30 
40 void mysql_sha1_yassl(uint8 *digest, const char *buf, int len)
41 {
42  TaoCrypt::SHA hasher;
43  hasher.Update((const TaoCrypt::byte *) buf, len);
44  hasher.Final ((TaoCrypt::byte *) digest);
45 }
46 
59 void mysql_sha1_multi_yassl(uint8 *digest, const char *buf1, int len1,
60  const char *buf2, int len2)
61 {
62  TaoCrypt::SHA hasher;
63  hasher.Update((const TaoCrypt::byte *) buf1, len1);
64  hasher.Update((const TaoCrypt::byte *) buf2, len2);
65  hasher.Final((TaoCrypt::byte *) digest);
66 }
67 
68 #elif defined(HAVE_OPENSSL)
69 #include <openssl/sha.h>
70 
71 int mysql_sha1_reset(SHA_CTX *context)
72 {
73  return SHA1_Init(context);
74 }
75 
76 
77 int mysql_sha1_input(SHA_CTX *context, const uint8 *message_array,
78  unsigned length)
79 {
80  return SHA1_Update(context, message_array, length);
81 }
82 
83 
84 int mysql_sha1_result(SHA_CTX *context,
85  uint8 Message_Digest[SHA1_HASH_SIZE])
86 {
87  return SHA1_Final(Message_Digest, context);
88 }
89 
90 #endif /* HAVE_YASSL */
91 
101 void compute_sha1_hash(uint8 *digest, const char *buf, int len)
102 {
103 #if defined(HAVE_YASSL)
104  mysql_sha1_yassl(digest, buf, len);
105 #elif defined(HAVE_OPENSSL)
106  SHA_CTX sha1_context;
107 
108  mysql_sha1_reset(&sha1_context);
109  mysql_sha1_input(&sha1_context, (const uint8 *) buf, len);
110  mysql_sha1_result(&sha1_context, digest);
111 #endif /* HAVE_YASSL */
112 }
113 
114 
127 void compute_sha1_hash_multi(uint8 *digest, const char *buf1, int len1,
128  const char *buf2, int len2)
129 {
130 #if defined(HAVE_YASSL)
131  mysql_sha1_multi_yassl(digest, buf1, len1, buf2, len2);
132 #elif defined(HAVE_OPENSSL)
133  SHA_CTX sha1_context;
134 
135  mysql_sha1_reset(&sha1_context);
136  mysql_sha1_input(&sha1_context, (const uint8 *) buf1, len1);
137  mysql_sha1_input(&sha1_context, (const uint8 *) buf2, len2);
138  mysql_sha1_result(&sha1_context, digest);
139 #endif /* HAVE_YASSL */
140 }
141