mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
This changeset is mostly new version of previous commit modified according
to Monty's code style and optimization comments client/client_priv.h: New value for --single-transaction option client/mysqldump.c: Add --single-transaction option for consistent dumps mysql-test/r/func_str.result: New functions test results mysql-test/t/func_str.test: Tests for SHA/AES functions mysys/Makefile.am: Extra files require compilation now sql/item_create.cc: New functions sql/item_create.h: New functions sql/item_strfunc.cc: Implementation of SHA/AES_ENCRYPT/AES_DECRYPT sql/item_strfunc.h: Required class definition sql/lex.h: Add symbols for implemented functions BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
This commit is contained in:
@ -65,3 +65,4 @@ worm@altair.is.lan
|
|||||||
zak@balfor.local
|
zak@balfor.local
|
||||||
zak@linux.local
|
zak@linux.local
|
||||||
tfr@indrek.tfr.cafe.ee
|
tfr@indrek.tfr.cafe.ee
|
||||||
|
peter@linux.local
|
||||||
|
@ -37,4 +37,4 @@ enum options { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET,
|
|||||||
OPT_SELECT_LIMIT, OPT_MAX_JOIN_SIZE, OPT_SSL_SSL,
|
OPT_SELECT_LIMIT, OPT_MAX_JOIN_SIZE, OPT_SSL_SSL,
|
||||||
OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
|
OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
|
||||||
OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT, OPT_LOCAL_INFILE,
|
OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT, OPT_LOCAL_INFILE,
|
||||||
OPT_PROMPT, OPT_IGN_LINES };
|
OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION };
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
** T<>nu Samuel <tonu@please.do.not.remove.this.spam.ee>
|
** T<>nu Samuel <tonu@please.do.not.remove.this.spam.ee>
|
||||||
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
|
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
|
||||||
** and adapted to mysqldump 05/11/01 by Jani Tolonen
|
** and adapted to mysqldump 05/11/01 by Jani Tolonen
|
||||||
|
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DUMP_VERSION "9.06"
|
#define DUMP_VERSION "9.06"
|
||||||
@ -76,7 +77,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0,
|
|||||||
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
|
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
|
||||||
opt_alldbs=0,opt_create_db=0,opt_first_slave=0,
|
opt_alldbs=0,opt_create_db=0,opt_first_slave=0,
|
||||||
opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0,
|
opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0,
|
||||||
tty_password=0;
|
tty_password=0,opt_single_transaction=0;
|
||||||
static MYSQL mysql_connection,*sock=0;
|
static MYSQL mysql_connection,*sock=0;
|
||||||
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
|
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
|
||||||
*current_host=0,*path=0,*fields_terminated=0,
|
*current_host=0,*path=0,*fields_terminated=0,
|
||||||
@ -171,6 +172,10 @@ static struct my_option my_long_options[] =
|
|||||||
"Wrap tables with autocommit/commit statements.",
|
"Wrap tables with autocommit/commit statements.",
|
||||||
(gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG,
|
(gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG,
|
||||||
0, 0, 0, 0, 0, 0},
|
0, 0, 0, 0, 0, 0},
|
||||||
|
{"single-transaction", OPT_TRANSACTION,
|
||||||
|
"Dump all tables in single transaction to get consistent snapshot. Mutually exclusive with --lock-tables.",
|
||||||
|
(gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG,
|
||||||
|
0, 0, 0, 0, 0, 0},
|
||||||
{"no-create-db", 'n',
|
{"no-create-db", 'n',
|
||||||
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}",
|
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}",
|
||||||
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
|
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
|
||||||
@ -340,8 +345,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
|||||||
usage();
|
usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
case (int) OPT_OPTIMIZE:
|
case (int) OPT_OPTIMIZE:
|
||||||
extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
|
extended_insert=opt_drop=opt_lock=quick=create_options=opt_disable_keys=
|
||||||
opt_disable_keys=1;
|
lock_tables=1;
|
||||||
|
if (opt_single_transaction) lock_tables=0;
|
||||||
break;
|
break;
|
||||||
case (int) OPT_TABLES:
|
case (int) OPT_TABLES:
|
||||||
opt_databases=0;
|
opt_databases=0;
|
||||||
@ -371,6 +377,12 @@ static int get_options(int *argc, char ***argv)
|
|||||||
"%s: You must use option --tab with --fields-...\n", my_progname);
|
"%s: You must use option --tab with --fields-...\n", my_progname);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt_single_transaction && lock_tables)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: You can't use --lock-tables and --single-transaction at the same time.\n", my_progname);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (enclosed && opt_enclosed)
|
if (enclosed && opt_enclosed)
|
||||||
{
|
{
|
||||||
@ -1372,6 +1384,18 @@ int main(int argc, char **argv)
|
|||||||
return(first_error);
|
return(first_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* There is no sense to start transaction if all tables are locked */
|
||||||
|
else if (opt_single_transaction)
|
||||||
|
{
|
||||||
|
if (mysql_query(sock, "BEGIN"))
|
||||||
|
{
|
||||||
|
my_printf_error(0, "Error: Couldn't execute 'BEGIN': %s",
|
||||||
|
MYF(0), mysql_error(sock));
|
||||||
|
my_end(0);
|
||||||
|
return(first_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if (opt_alldbs)
|
if (opt_alldbs)
|
||||||
dump_all_databases();
|
dump_all_databases();
|
||||||
/* Only one database and selected table(s) */
|
/* Only one database and selected table(s) */
|
||||||
@ -1416,6 +1440,19 @@ int main(int argc, char **argv)
|
|||||||
MYF(0), mysql_error(sock));
|
MYF(0), mysql_error(sock));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
In case we were locking all tables, we did not start transaction
|
||||||
|
so there is no need to commit it.
|
||||||
|
*/
|
||||||
|
else if (opt_single_transaction) /* Just to make it beautiful enough */
|
||||||
|
{
|
||||||
|
/* This should just free locks as we did not change anything */
|
||||||
|
if (mysql_query(sock, "COMMIT"))
|
||||||
|
{
|
||||||
|
my_printf_error(0, "Error: Couldn't execute 'COMMIT': %s",
|
||||||
|
MYF(0), mysql_error(sock));
|
||||||
|
}
|
||||||
|
}
|
||||||
dbDisconnect(current_host);
|
dbDisconnect(current_host);
|
||||||
fputs("\n", md_result_file);
|
fputs("\n", md_result_file);
|
||||||
if (md_result_file != stdout)
|
if (md_result_file != stdout)
|
||||||
|
83
include/my_aes.h
Normal file
83
include/my_aes.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
|
/* Header file for my_aes.c */
|
||||||
|
/* Wrapper to give simple interface for MySQL to AES standard encryption */
|
||||||
|
|
||||||
|
#ifndef __MY_AES_H
|
||||||
|
#define __MY_AES_H
|
||||||
|
|
||||||
|
#include "my_global.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "rijndael.h"
|
||||||
|
|
||||||
|
#define AES_KEY_LENGTH 128
|
||||||
|
/* Must be 128 192 or 256 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
my_aes_crypt - Crypt buffer with AES encryption algorithm.
|
||||||
|
source - Pinter to data for encryption
|
||||||
|
source_length - size of encruption data
|
||||||
|
dest - buffer to place encrypted data (must be large enough)
|
||||||
|
key - Key to be used for encryption
|
||||||
|
kel_length - Lenght of the key. Will handle keys of any length
|
||||||
|
|
||||||
|
returns - size of encrypted data, or negative in case of error.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int my_aes_encrypt(const char* source, int source_length, const char* dest,
|
||||||
|
const char* key, int key_length);
|
||||||
|
|
||||||
|
/*
|
||||||
|
my_aes_decrypt - DeCrypt buffer with AES encryption algorithm.
|
||||||
|
source - Pinter to data for decryption
|
||||||
|
source_length - size of encrypted data
|
||||||
|
dest - buffer to place decrypted data (must be large enough)
|
||||||
|
key - Key to be used for decryption
|
||||||
|
kel_length - Lenght of the key. Will handle keys of any length
|
||||||
|
|
||||||
|
returns - size of original data, or negative in case of error.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int my_aes_decrypt(const char* source, int source_length, const char* dest,
|
||||||
|
const char* key, int key_length);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
my_aes_get_size - get size of buffer which will be large enough for encrypted data
|
||||||
|
source_length - length of data to be encrypted
|
||||||
|
|
||||||
|
returns - size of buffer required to store encrypted data
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int my_aes_get_size(int source_length);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
48
include/rijndael.h
Normal file
48
include/rijndael.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
rijndael-alg-fst.h
|
||||||
|
|
||||||
|
@version 3.0 (December 2000)
|
||||||
|
Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||||
|
@author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||||
|
@author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||||
|
@author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||||
|
|
||||||
|
This code is hereby placed in the public domain.
|
||||||
|
|
||||||
|
Modified by Peter Zaitsev to fit MySQL coding style.
|
||||||
|
|
||||||
|
*/
|
||||||
|
#ifndef __RIJNDAEL_ALG_FST_H
|
||||||
|
#define __RIJNDAEL_ALG_FST_H
|
||||||
|
|
||||||
|
#define MAXKC (256/32)
|
||||||
|
#define MAXKB (256/8)
|
||||||
|
#define MAXNR 14
|
||||||
|
|
||||||
|
int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
|
||||||
|
int keyBits);
|
||||||
|
int rijndaelKeySetupDec(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
|
||||||
|
int keyBits);
|
||||||
|
void rijndaelEncrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
|
||||||
|
const uint8 pt[16], uint8 ct[16]);
|
||||||
|
void rijndaelDecrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
|
||||||
|
const uint8 ct[16], uint8 pt[16]);
|
||||||
|
|
||||||
|
#endif /* __RIJNDAEL_ALG_FST_H */
|
85
include/sha1.h
Normal file
85
include/sha1.h
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
sha1.h
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This is the header file for code which implements the Secure
|
||||||
|
Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
|
||||||
|
April 17, 1995.
|
||||||
|
|
||||||
|
Many of the variable names in this code, especially the
|
||||||
|
single character names, were used because those were the names
|
||||||
|
used in the publication.
|
||||||
|
|
||||||
|
Please read the file sha1.c for more information.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Modified 2002 by Peter Zaitsev to better follow MySQL standards */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _SHA1_H_
|
||||||
|
#define _SHA1_H_
|
||||||
|
|
||||||
|
#include "my_global.h"
|
||||||
|
|
||||||
|
/* Required for uint32, uint8, int16 ulonglong types */
|
||||||
|
|
||||||
|
enum sha_result_codes
|
||||||
|
{
|
||||||
|
SHA_SUCCESS = 0,
|
||||||
|
SHA_NULL, /* Null pointer parameter */
|
||||||
|
SHA_INPUT_TOO_LONG, /* input data too long */
|
||||||
|
SHA_STATE_ERROR /* called Input after Result */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SHA1_HASH_SIZE 20 /* Hash size in bytes */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This structure will hold context information for the SHA-1
|
||||||
|
hashing operation
|
||||||
|
*/
|
||||||
|
typedef struct SHA1_CONTEXT
|
||||||
|
{
|
||||||
|
ulonglong Length; /* Message length in bits */
|
||||||
|
uint32 Intermediate_Hash[SHA1_HASH_SIZE/4]; /* Message Digest */
|
||||||
|
int Computed; /* Is the digest computed? */
|
||||||
|
int Corrupted; /* Is the message digest corrupted? */
|
||||||
|
int16 Message_Block_Index; /* Index into message block array */
|
||||||
|
uint8 Message_Block[64]; /* 512-bit message blocks */
|
||||||
|
} SHA1_CONTEXT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function Prototypes
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int sha1_reset( SHA1_CONTEXT* );
|
||||||
|
int sha1_input( SHA1_CONTEXT*, const uint8 *, unsigned int );
|
||||||
|
int sha1_result( SHA1_CONTEXT* , uint8 Message_Digest[SHA1_HASH_SIZE] );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -83,6 +83,36 @@ soundex('') soundex('he') soundex('hello all folks')
|
|||||||
select md5('hello');
|
select md5('hello');
|
||||||
md5('hello')
|
md5('hello')
|
||||||
5d41402abc4b2a76b9719d911017c592
|
5d41402abc4b2a76b9719d911017c592
|
||||||
|
select sha('abc');
|
||||||
|
sha('abc')
|
||||||
|
a9993e364706816aba3e25717850c26c9cd0d89d
|
||||||
|
select sha1('abc');
|
||||||
|
sha1('abc')
|
||||||
|
a9993e364706816aba3e25717850c26c9cd0d89d
|
||||||
|
select aes_decrypt(aes_encrypt('abc','1'),'1');
|
||||||
|
aes_decrypt(aes_encrypt('abc','1'),'1')
|
||||||
|
abc
|
||||||
|
select aes_decrypt(aes_encrypt('abc','1'),1);
|
||||||
|
aes_decrypt(aes_encrypt('abc','1'),1)
|
||||||
|
abc
|
||||||
|
select aes_encrypt(NULL,"a");
|
||||||
|
aes_encrypt(NULL,"a")
|
||||||
|
NULL
|
||||||
|
select aes_encrypt("a",NULL);
|
||||||
|
aes_encrypt("a",NULL)
|
||||||
|
NULL
|
||||||
|
select aes_decrypt(NULL,"a");
|
||||||
|
aes_decrypt(NULL,"a")
|
||||||
|
NULL
|
||||||
|
select aes_decrypt("a",NULL);
|
||||||
|
aes_decrypt("a",NULL)
|
||||||
|
NULL
|
||||||
|
select aes_decrypt("a","a");
|
||||||
|
aes_decrypt("a","a")
|
||||||
|
NULL
|
||||||
|
select aes_decrypt(aes_encrypt("","a"),"a");
|
||||||
|
aes_decrypt(aes_encrypt("","a"),"a")
|
||||||
|
|
||||||
select repeat('monty',5),concat('*',space(5),'*');
|
select repeat('monty',5),concat('*',space(5),'*');
|
||||||
repeat('monty',5) concat('*',space(5),'*')
|
repeat('monty',5) concat('*',space(5),'*')
|
||||||
montymontymontymontymonty * *
|
montymontymontymontymonty * *
|
||||||
|
@ -37,6 +37,16 @@ select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb')
|
|||||||
select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
|
select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
|
||||||
select soundex(''),soundex('he'),soundex('hello all folks');
|
select soundex(''),soundex('he'),soundex('hello all folks');
|
||||||
select md5('hello');
|
select md5('hello');
|
||||||
|
select sha('abc');
|
||||||
|
select sha1('abc');
|
||||||
|
select aes_decrypt(aes_encrypt('abc','1'),'1');
|
||||||
|
select aes_decrypt(aes_encrypt('abc','1'),1);
|
||||||
|
select aes_encrypt(NULL,"a");
|
||||||
|
select aes_encrypt("a",NULL);
|
||||||
|
select aes_decrypt(NULL,"a");
|
||||||
|
select aes_decrypt("a",NULL);
|
||||||
|
select aes_decrypt("a","a");
|
||||||
|
select aes_decrypt(aes_encrypt("","a"),"a");
|
||||||
select repeat('monty',5),concat('*',space(5),'*');
|
select repeat('monty',5),concat('*',space(5),'*');
|
||||||
select reverse('abc'),reverse('abcd');
|
select reverse('abc'),reverse('abcd');
|
||||||
select rpad('a',4,'1'),rpad('a',4,'12'),rpad('abcd',3,'12');
|
select rpad('a',4,'1'),rpad('a',4,'12'),rpad('abcd',3,'12');
|
||||||
|
@ -48,7 +48,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
|
|||||||
default.c my_compress.c checksum.c raid.cc \
|
default.c my_compress.c checksum.c raid.cc \
|
||||||
my_net.c \
|
my_net.c \
|
||||||
my_vsnprintf.c charset.c my_bitmap.c my_bit.c md5.c \
|
my_vsnprintf.c charset.c my_bitmap.c my_bit.c md5.c \
|
||||||
my_gethostbyname.c
|
my_gethostbyname.c rijndael.c my_aes.c sha1.c
|
||||||
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
|
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
|
||||||
thr_mutex.c thr_rwlock.c
|
thr_mutex.c thr_rwlock.c
|
||||||
libmysys_a_LIBADD = @THREAD_LOBJECTS@
|
libmysys_a_LIBADD = @THREAD_LOBJECTS@
|
||||||
|
153
mysys/my_aes.c
Normal file
153
mysys/my_aes.c
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
|
||||||
|
/* MY_AES.C Implementation of AES Encryption for MySQL */
|
||||||
|
|
||||||
|
|
||||||
|
#include "my_global.h"
|
||||||
|
#include "m_string.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "my_aes.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define AES_ENCRYPT 1
|
||||||
|
#define AES_DECRYPT 2
|
||||||
|
|
||||||
|
#define AES_BLOCK_SIZE 16
|
||||||
|
/* Block size in bytes */
|
||||||
|
|
||||||
|
#define AES_BAD_DATA -1
|
||||||
|
/* If bad data discovered during decoding */
|
||||||
|
|
||||||
|
|
||||||
|
/* The structure for key information */
|
||||||
|
typedef struct {
|
||||||
|
int nr; /* Number of rounds */
|
||||||
|
uint32 rk[4*(MAXNR + 1)]; /* key schedule */
|
||||||
|
} KEYINSTANCE;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is internal function just keeps joint code of Key generation
|
||||||
|
rkey - Address of Key Instance to be created
|
||||||
|
direction - Direction (are we encoding or decoding)
|
||||||
|
key - key to use for real key creation
|
||||||
|
key_length - length of the key
|
||||||
|
|
||||||
|
returns - returns 0 on success and negative on error
|
||||||
|
*/
|
||||||
|
static int my_aes_create_key(KEYINSTANCE* aes_key,char direction, char* key,
|
||||||
|
int key_length)
|
||||||
|
{
|
||||||
|
char rkey[AES_KEY_LENGTH/8]; /* The real key to be used for encryption */
|
||||||
|
char *ptr; /* Start of the real key*/
|
||||||
|
char *rkey_end=rkey+AES_KEY_LENGTH/8; /* Real key boundary */
|
||||||
|
char *sptr; /* Start of the working key */
|
||||||
|
char *key_end=key+key_length; /* Working key boundary*/
|
||||||
|
|
||||||
|
bzero(rkey,AES_KEY_LENGTH/8); /* Set initial key */
|
||||||
|
|
||||||
|
for (ptr= rkey, sptr= key; sptr < key_end; ptr++,sptr++)
|
||||||
|
{
|
||||||
|
if (ptr == rkey_end)
|
||||||
|
ptr= rkey; /* Just loop over tmp_key until we used all key */
|
||||||
|
*ptr^= *sptr;
|
||||||
|
}
|
||||||
|
if (direction==AES_DECRYPT)
|
||||||
|
aes_key->nr = rijndaelKeySetupDec(aes_key->rk, rkey, AES_KEY_LENGTH);
|
||||||
|
else
|
||||||
|
aes_key->nr = rijndaelKeySetupEnc(aes_key->rk, rkey, AES_KEY_LENGTH);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int my_aes_encrypt(const char* source, int source_length, const char* dest,
|
||||||
|
const char* key, int key_length)
|
||||||
|
{
|
||||||
|
KEYINSTANCE aes_key;
|
||||||
|
char block[AES_BLOCK_SIZE]; /* 128 bit block used for padding */
|
||||||
|
int rc; /* result codes */
|
||||||
|
int num_blocks; /* number of complete blocks */
|
||||||
|
char pad_len; /* pad size for the last block */
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ( (rc=my_aes_create_key(&aes_key,AES_ENCRYPT,key,key_length)) )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
num_blocks = source_length/AES_BLOCK_SIZE;
|
||||||
|
|
||||||
|
for (i = num_blocks; i > 0; i--) /* Encode complete blocks */
|
||||||
|
{
|
||||||
|
rijndaelEncrypt(aes_key.rk, aes_key.nr, source, dest);
|
||||||
|
source+= AES_BLOCK_SIZE;
|
||||||
|
dest+= AES_BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode the rest. We always have incomplete block */
|
||||||
|
pad_len = AES_BLOCK_SIZE - (source_length - AES_BLOCK_SIZE*num_blocks);
|
||||||
|
memcpy(block, source, 16 - pad_len);
|
||||||
|
bfill(block + AES_BLOCK_SIZE - pad_len, pad_len, pad_len);
|
||||||
|
rijndaelEncrypt(aes_key.rk, aes_key.nr, block, dest);
|
||||||
|
return AES_BLOCK_SIZE*(num_blocks + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int my_aes_decrypt(const char* source, int source_length, const char* dest,
|
||||||
|
const char* key, int key_length)
|
||||||
|
{
|
||||||
|
KEYINSTANCE aes_key;
|
||||||
|
char block[AES_BLOCK_SIZE]; /* 128 bit block used for padding */
|
||||||
|
int rc; /* result codes */
|
||||||
|
int num_blocks; /* number of complete blocks */
|
||||||
|
char pad_len; /* pad size for the last block */
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ( (rc=my_aes_create_key(&aes_key,AES_DECRYPT,key,key_length)) )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
num_blocks = source_length/AES_BLOCK_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
if ( (source_length!=num_blocks*AES_BLOCK_SIZE) || num_blocks==0)
|
||||||
|
return AES_BAD_DATA; /* Input size has to be even and at leas one block */
|
||||||
|
|
||||||
|
|
||||||
|
for (i = num_blocks-1; i > 0; i--) /* Decode all but last blocks */
|
||||||
|
{
|
||||||
|
rijndaelDecrypt(aes_key.rk, aes_key.nr, source, dest);
|
||||||
|
source+= AES_BLOCK_SIZE;
|
||||||
|
dest+= AES_BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
rijndaelDecrypt(aes_key.rk, aes_key.nr, source, block);
|
||||||
|
pad_len = block[AES_BLOCK_SIZE-1]; /* Just use last char in the block as size*/
|
||||||
|
|
||||||
|
if (pad_len > AES_BLOCK_SIZE)
|
||||||
|
return AES_BAD_DATA;
|
||||||
|
/* We could also check whole padding but we do not really need this */
|
||||||
|
|
||||||
|
memcpy(dest, block, AES_BLOCK_SIZE - pad_len);
|
||||||
|
|
||||||
|
return AES_BLOCK_SIZE*num_blocks - pad_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int my_aes_get_size(int source_length)
|
||||||
|
{
|
||||||
|
return AES_BLOCK_SIZE*(source_length/AES_BLOCK_SIZE)+AES_BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
1452
mysys/rijndael.c
Normal file
1452
mysys/rijndael.c
Normal file
File diff suppressed because it is too large
Load Diff
480
mysys/sha1.c
Normal file
480
mysys/sha1.c
Normal file
@ -0,0 +1,480 @@
|
|||||||
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
/*
|
||||||
|
sha1.c
|
||||||
|
Original Source from: http://www.faqs.org/rfcs/rfc3174.html
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This file implements the Secure Hashing Algorithm 1 as
|
||||||
|
defined in FIPS PUB 180-1 published April 17, 1995.
|
||||||
|
|
||||||
|
The SHA-1, produces a 160-bit message digest for a given
|
||||||
|
data stream. It should take about 2**n steps to find a
|
||||||
|
message with the same digest as a given message and
|
||||||
|
2**(n/2) to find any two messages with the same digest,
|
||||||
|
when n is the digest size in bits. Therefore, this
|
||||||
|
algorithm can serve as a means of providing a
|
||||||
|
"fingerprint" for a message.
|
||||||
|
|
||||||
|
Portability Issues:
|
||||||
|
SHA-1 is defined in terms of 32-bit "words". This code
|
||||||
|
uses <stdint.h> (included via "sha1.h" to define 32 and 8
|
||||||
|
bit unsigned integer types. If your C compiler does not
|
||||||
|
support 32 bit unsigned integers, this code is not
|
||||||
|
appropriate.
|
||||||
|
|
||||||
|
Caveats:
|
||||||
|
SHA-1 is designed to work with messages less than 2^64 bits
|
||||||
|
long. Although SHA-1 allows a message digest to be generated
|
||||||
|
for messages of any number of bits less than 2^64, this
|
||||||
|
implementation only works with messages with a length that is
|
||||||
|
a multiple of the size of an 8-bit character.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Modified by 2002 by Peter Zaitsev to
|
||||||
|
- fit to new prototypes according to MySQL standard
|
||||||
|
- Some optimizations
|
||||||
|
- All checking is now done in debug only mode
|
||||||
|
- More comments
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sha1.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Define the SHA1 circular left shift macro
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SHA1CircularShift(bits,word) \
|
||||||
|
(((word) << (bits)) | ((word) >> (32-(bits))))
|
||||||
|
|
||||||
|
/* Local Function Prototyptes */
|
||||||
|
void SHA1PadMessage(SHA1_CONTEXT*);
|
||||||
|
void SHA1ProcessMessageBlock(SHA1_CONTEXT*);
|
||||||
|
|
||||||
|
/*
|
||||||
|
sha1_reset
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This function will initialize the SHA1Context in preparation
|
||||||
|
for computing a new SHA1 message digest.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
context: [in/out]
|
||||||
|
The context to reset.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sha Error Code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
const uint32 sha_const_key[5]=
|
||||||
|
{
|
||||||
|
0x67452301,
|
||||||
|
0xEFCDAB89,
|
||||||
|
0x98BADCFE,
|
||||||
|
0x10325476,
|
||||||
|
0xC3D2E1F0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int sha1_reset(SHA1_CONTEXT *context)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifndef DBUG_OFF
|
||||||
|
if (!context)
|
||||||
|
{
|
||||||
|
return SHA_NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
context->Length = 0;
|
||||||
|
context->Message_Block_Index = 0;
|
||||||
|
|
||||||
|
context->Intermediate_Hash[0] = sha_const_key[0];
|
||||||
|
context->Intermediate_Hash[1] = sha_const_key[1];
|
||||||
|
context->Intermediate_Hash[2] = sha_const_key[2];
|
||||||
|
context->Intermediate_Hash[3] = sha_const_key[3];
|
||||||
|
context->Intermediate_Hash[4] = sha_const_key[4];
|
||||||
|
|
||||||
|
context->Computed = 0;
|
||||||
|
context->Corrupted = 0;
|
||||||
|
|
||||||
|
return SHA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
sha1_result
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This function will return the 160-bit message digest into the
|
||||||
|
Message_Digest array provided by the caller.
|
||||||
|
NOTE: The first octet of hash is stored in the 0th element,
|
||||||
|
the last octet of hash in the 19th element.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
context: [in/out]
|
||||||
|
The context to use to calculate the SHA-1 hash.
|
||||||
|
Message_Digest: [out]
|
||||||
|
Where the digest is returned.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sha Error Code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int sha1_result( SHA1_CONTEXT *context,
|
||||||
|
uint8 Message_Digest[SHA1_HASH_SIZE])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#ifndef DBUG_OFF
|
||||||
|
if (!context || !Message_Digest)
|
||||||
|
{
|
||||||
|
return SHA_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->Corrupted)
|
||||||
|
{
|
||||||
|
return context->Corrupted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context->Computed)
|
||||||
|
{
|
||||||
|
|
||||||
|
#endif
|
||||||
|
SHA1PadMessage(context);
|
||||||
|
for (i=0; i<64; i++)
|
||||||
|
{
|
||||||
|
/* message may be sensitive, clear it out */
|
||||||
|
context->Message_Block[i] = 0;
|
||||||
|
}
|
||||||
|
context->Length = 0; /* and clear length */
|
||||||
|
context->Computed = 1;
|
||||||
|
|
||||||
|
#ifndef DBUG_OFF
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (i = 0; i < SHA1_HASH_SIZE; i++)
|
||||||
|
{
|
||||||
|
Message_Digest[i] = context->Intermediate_Hash[i>>2]
|
||||||
|
>> 8 * ( 3 - ( i & 0x03 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
sha1_input
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This function accepts an array of octets as the next portion
|
||||||
|
of the message.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
context: [in/out]
|
||||||
|
The SHA context to update
|
||||||
|
message_array: [in]
|
||||||
|
An array of characters representing the next portion of
|
||||||
|
the message.
|
||||||
|
length: [in]
|
||||||
|
The length of the message in message_array
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
sha Error Code.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
|
||||||
|
unsigned length)
|
||||||
|
{
|
||||||
|
if (!length)
|
||||||
|
{
|
||||||
|
return SHA_SUCCESS;
|
||||||
|
}
|
||||||
|
#ifndef DBUG_OFF
|
||||||
|
/* We assume client konows what it is doing in non-debug mode */
|
||||||
|
if (!context || !message_array)
|
||||||
|
{
|
||||||
|
return SHA_NULL;
|
||||||
|
}
|
||||||
|
if (context->Computed)
|
||||||
|
{
|
||||||
|
context->Corrupted = SHA_STATE_ERROR;
|
||||||
|
return SHA_STATE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context->Corrupted)
|
||||||
|
{
|
||||||
|
return context->Corrupted;
|
||||||
|
}
|
||||||
|
while (length-- && !context->Corrupted)
|
||||||
|
|
||||||
|
#else
|
||||||
|
while (length--)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] =
|
||||||
|
(*message_array & 0xFF);
|
||||||
|
context->Length += 8; /* Length is in bits */
|
||||||
|
|
||||||
|
#ifndef DBUG_OFF
|
||||||
|
/*
|
||||||
|
Then we're not debugging we assume we never will get message longer
|
||||||
|
2^64 bits.
|
||||||
|
*/
|
||||||
|
if (context->Length == 0)
|
||||||
|
{
|
||||||
|
/* Message is too long */
|
||||||
|
context->Corrupted = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (context->Message_Block_Index == 64)
|
||||||
|
{
|
||||||
|
SHA1ProcessMessageBlock(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
message_array++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHA_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
SHA1ProcessMessageBlock
|
||||||
|
|
||||||
|
Description:
|
||||||
|
This function will process the next 512 bits of the message
|
||||||
|
stored in the Message_Block array.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Nothing.
|
||||||
|
|
||||||
|
Comments:
|
||||||
|
|
||||||
|
Many of the variable names in this code, especially the
|
||||||
|
single character names, were used because those were the
|
||||||
|
names used in the publication.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const uint32 K[]=
|
||||||
|
{ /* Constants defined in SHA-1 */
|
||||||
|
0x5A827999,
|
||||||
|
0x6ED9EBA1,
|
||||||
|
0x8F1BBCDC,
|
||||||
|
0xCA62C1D6
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
|
||||||
|
{
|
||||||
|
int t; /* Loop counter */
|
||||||
|
uint32 temp; /* Temporary word value */
|
||||||
|
uint32 W[80]; /* Word sequence */
|
||||||
|
uint32 A, B, C, D, E; /* Word buffers */
|
||||||
|
int index;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Initialize the first 16 words in the array W
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (t = 0; t < 16; t++)
|
||||||
|
{
|
||||||
|
index=t*4;
|
||||||
|
W[t] = context->Message_Block[index] << 24;
|
||||||
|
W[t] |= context->Message_Block[index + 1] << 16;
|
||||||
|
W[t] |= context->Message_Block[index + 2] << 8;
|
||||||
|
W[t] |= context->Message_Block[index + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(t = 16; t < 80; t++)
|
||||||
|
{
|
||||||
|
W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
|
||||||
|
}
|
||||||
|
|
||||||
|
A = context->Intermediate_Hash[0];
|
||||||
|
B = context->Intermediate_Hash[1];
|
||||||
|
C = context->Intermediate_Hash[2];
|
||||||
|
D = context->Intermediate_Hash[3];
|
||||||
|
E = context->Intermediate_Hash[4];
|
||||||
|
|
||||||
|
for(t = 0; t < 20; t++)
|
||||||
|
{
|
||||||
|
temp = SHA1CircularShift(5,A) +
|
||||||
|
((B & C) | ((~B) & D)) + E + W[t] + K[0];
|
||||||
|
E = D;
|
||||||
|
D = C;
|
||||||
|
C = SHA1CircularShift(30,B);
|
||||||
|
B = A;
|
||||||
|
A = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(t = 20; t < 40; t++)
|
||||||
|
{
|
||||||
|
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
|
||||||
|
E = D;
|
||||||
|
D = C;
|
||||||
|
C = SHA1CircularShift(30,B);
|
||||||
|
B = A;
|
||||||
|
A = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(t = 40; t < 60; t++)
|
||||||
|
{
|
||||||
|
temp = SHA1CircularShift(5,A) +
|
||||||
|
((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
|
||||||
|
E = D;
|
||||||
|
D = C;
|
||||||
|
C = SHA1CircularShift(30,B);
|
||||||
|
B = A;
|
||||||
|
A = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(t = 60; t < 80; t++)
|
||||||
|
{
|
||||||
|
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
|
||||||
|
E = D;
|
||||||
|
D = C;
|
||||||
|
C = SHA1CircularShift(30,B);
|
||||||
|
B = A;
|
||||||
|
A = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
context->Intermediate_Hash[0] += A;
|
||||||
|
context->Intermediate_Hash[1] += B;
|
||||||
|
context->Intermediate_Hash[2] += C;
|
||||||
|
context->Intermediate_Hash[3] += D;
|
||||||
|
context->Intermediate_Hash[4] += E;
|
||||||
|
|
||||||
|
context->Message_Block_Index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
SHA1PadMessage
|
||||||
|
|
||||||
|
|
||||||
|
Description:
|
||||||
|
According to the standard, the message must be padded to an even
|
||||||
|
512 bits. The first padding bit must be a '1'. The last 64
|
||||||
|
bits represent the length of the original message. All bits in
|
||||||
|
between should be 0. This function will pad the message
|
||||||
|
according to those rules by filling the Message_Block array
|
||||||
|
accordingly. It will also call the ProcessMessageBlock function
|
||||||
|
provided appropriately. When it returns, it can be assumed that
|
||||||
|
the message digest has been computed.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
context: [in/out]
|
||||||
|
The context to pad
|
||||||
|
ProcessMessageBlock: [in]
|
||||||
|
The appropriate SHA*ProcessMessageBlock function
|
||||||
|
Returns:
|
||||||
|
Nothing.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SHA1PadMessage(SHA1_CONTEXT *context)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Check to see if the current message block is too small to hold
|
||||||
|
the initial padding bits and length. If so, we will pad the
|
||||||
|
block, process it, and then continue padding into a second
|
||||||
|
block.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef SHA_OLD_CODE
|
||||||
|
|
||||||
|
if (context->Message_Block_Index > 55)
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] = 0x80;
|
||||||
|
while (context->Message_Block_Index < 64)
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA1ProcessMessageBlock(context);
|
||||||
|
|
||||||
|
while (context->Message_Block_Index < 56)
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] = 0x80;
|
||||||
|
while (context->Message_Block_Index < 56)
|
||||||
|
{
|
||||||
|
context->Message_Block[context->Message_Block_Index++] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
int i=context->Message_Block_Index;
|
||||||
|
|
||||||
|
if (i > 55)
|
||||||
|
{
|
||||||
|
context->Message_Block[i++] = 0x80;
|
||||||
|
bzero((char*) &context->Message_Block[i],
|
||||||
|
sizeof(context->Message_Block[0])*(64-i));
|
||||||
|
context->Message_Block_Index=64;
|
||||||
|
|
||||||
|
SHA1ProcessMessageBlock(context);
|
||||||
|
|
||||||
|
/* This function sets context->Message_Block_Index to zero */
|
||||||
|
bzero((char*) &context->Message_Block[0],
|
||||||
|
sizeof(context->Message_Block[0])*56);
|
||||||
|
context->Message_Block_Index=56;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context->Message_Block[i++] = 0x80;
|
||||||
|
bzero((char*) &context->Message_Block[i],
|
||||||
|
sizeof(context->Message_Block[0])*(56-i));
|
||||||
|
context->Message_Block_Index=56;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
Store the message length as the last 8 octets
|
||||||
|
*/
|
||||||
|
|
||||||
|
context->Message_Block[56] = context->Length >> 56;
|
||||||
|
context->Message_Block[57] = context->Length >> 48;
|
||||||
|
context->Message_Block[58] = context->Length >> 40;
|
||||||
|
context->Message_Block[59] = context->Length >> 32;
|
||||||
|
context->Message_Block[60] = context->Length >> 24;
|
||||||
|
context->Message_Block[61] = context->Length >> 16;
|
||||||
|
context->Message_Block[62] = context->Length >> 8;
|
||||||
|
context->Message_Block[63] = context->Length;
|
||||||
|
|
||||||
|
SHA1ProcessMessageBlock(context);
|
||||||
|
}
|
||||||
|
|
@ -32,6 +32,16 @@ Item *create_func_acos(Item* a)
|
|||||||
return new Item_func_acos(a);
|
return new Item_func_acos(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item *create_func_aes_encrypt(Item* a, Item* b)
|
||||||
|
{
|
||||||
|
return new Item_func_aes_encrypt(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
Item *create_func_aes_decrypt(Item* a, Item* b)
|
||||||
|
{
|
||||||
|
return new Item_func_aes_decrypt(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
Item *create_func_ascii(Item* a)
|
Item *create_func_ascii(Item* a)
|
||||||
{
|
{
|
||||||
return new Item_func_ascii(a);
|
return new Item_func_ascii(a);
|
||||||
@ -327,6 +337,11 @@ Item *create_func_sin(Item* a)
|
|||||||
return new Item_func_sin(a);
|
return new Item_func_sin(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item *create_func_sha(Item* a)
|
||||||
|
{
|
||||||
|
return new Item_func_sha(a);
|
||||||
|
}
|
||||||
|
|
||||||
Item *create_func_space(Item *a)
|
Item *create_func_space(Item *a)
|
||||||
{
|
{
|
||||||
return new Item_func_repeat(new Item_string(" ",1),a);
|
return new Item_func_repeat(new Item_string(" ",1),a);
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
Item *create_func_abs(Item* a);
|
Item *create_func_abs(Item* a);
|
||||||
Item *create_func_acos(Item* a);
|
Item *create_func_acos(Item* a);
|
||||||
|
Item *create_func_aes_encrypt(Item* a, Item* b);
|
||||||
|
Item *create_func_aes_decrypt(Item* a, Item* b);
|
||||||
Item *create_func_ascii(Item* a);
|
Item *create_func_ascii(Item* a);
|
||||||
Item *create_func_asin(Item* a);
|
Item *create_func_asin(Item* a);
|
||||||
Item *create_func_bin(Item* a);
|
Item *create_func_bin(Item* a);
|
||||||
@ -75,6 +77,7 @@ Item *create_func_rtrim(Item* a);
|
|||||||
Item *create_func_sec_to_time(Item* a);
|
Item *create_func_sec_to_time(Item* a);
|
||||||
Item *create_func_sign(Item* a);
|
Item *create_func_sign(Item* a);
|
||||||
Item *create_func_sin(Item* a);
|
Item *create_func_sin(Item* a);
|
||||||
|
Item *create_func_sha(Item* a);
|
||||||
Item *create_func_soundex(Item* a);
|
Item *create_func_soundex(Item* a);
|
||||||
Item *create_func_space(Item *);
|
Item *create_func_space(Item *);
|
||||||
Item *create_func_sqrt(Item* a);
|
Item *create_func_sqrt(Item* a);
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#include <openssl/des.h>
|
#include <openssl/des.h>
|
||||||
#endif /* HAVE_OPENSSL */
|
#endif /* HAVE_OPENSSL */
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
#include "sha1.h"
|
||||||
|
#include "my_aes.h"
|
||||||
|
|
||||||
String empty_string("");
|
String empty_string("");
|
||||||
|
|
||||||
@ -99,6 +101,115 @@ void Item_func_md5::fix_length_and_dec()
|
|||||||
max_length=32;
|
max_length=32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String *Item_func_sha::val_str(String *str)
|
||||||
|
{
|
||||||
|
String * sptr= args[0]->val_str(str);
|
||||||
|
if (sptr) /* If we got value different from NULL */
|
||||||
|
{
|
||||||
|
SHA1_CONTEXT context; /* Context used to generate SHA1 hash */
|
||||||
|
/* Temporary buffer to store 160bit digest */
|
||||||
|
uint8_t digest[SHA1_HASH_SIZE];
|
||||||
|
null_value=0;
|
||||||
|
sha1_reset(&context); /* We do not have to check for error here */
|
||||||
|
/* No need to check error as the only case would be too long message */
|
||||||
|
sha1_input(&context,(const unsigned char *) sptr->ptr(), sptr->length());
|
||||||
|
|
||||||
|
if (str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest)) )
|
||||||
|
// Ensure that memory is free
|
||||||
|
{
|
||||||
|
null_value=1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
sprintf((char *) str->ptr(),
|
||||||
|
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\
|
||||||
|
%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||||
|
digest[0], digest[1], digest[2], digest[3],
|
||||||
|
digest[4], digest[5], digest[6], digest[7],
|
||||||
|
digest[8], digest[9], digest[10], digest[11],
|
||||||
|
digest[12], digest[13], digest[14], digest[15],
|
||||||
|
digest[16], digest[17], digest[18], digest[19]);
|
||||||
|
|
||||||
|
str->length((uint) SHA1_HASH_SIZE*2);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
null_value=1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item_func_sha::fix_length_and_dec()
|
||||||
|
{
|
||||||
|
max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Implementation of AES encryption routines */
|
||||||
|
|
||||||
|
String *Item_func_aes_encrypt::val_str(String *str)
|
||||||
|
{
|
||||||
|
String * sptr = args[0]->val_str(str); // String to encrypt
|
||||||
|
String tmp_value; // required to handle second parameter
|
||||||
|
String * key= args[1]->val_str(&tmp_value); // key
|
||||||
|
int aes_length;
|
||||||
|
if (sptr && key) // we need both arguments to be not NULL
|
||||||
|
{
|
||||||
|
null_value=0;
|
||||||
|
aes_length=my_aes_get_size(sptr->length()); // calculate result length
|
||||||
|
|
||||||
|
if ( !str->alloc(aes_length) ) // Ensure that memory is free
|
||||||
|
{
|
||||||
|
// finally encrypt directly to allocated buffer.
|
||||||
|
if (my_aes_encrypt(sptr->ptr(),sptr->length(),str->ptr(),key->ptr(),
|
||||||
|
key->length()) == aes_length)
|
||||||
|
{
|
||||||
|
// we have to get expected result length
|
||||||
|
str->length((uint)aes_length);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
null_value=1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item_func_aes_encrypt::fix_length_and_dec()
|
||||||
|
{
|
||||||
|
max_length=my_aes_get_size(args[0]->max_length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String *Item_func_aes_decrypt::val_str(String *str)
|
||||||
|
{
|
||||||
|
String * sptr= args[0]->val_str(str); // String to decrypt
|
||||||
|
String tmp_value; // temporary string required for parsing
|
||||||
|
String * key= args[1]->val_str(&tmp_value); // key
|
||||||
|
int length; // original length after decrypt
|
||||||
|
if (sptr && key) // Need to have both arguments not NULL
|
||||||
|
{
|
||||||
|
null_value=0;
|
||||||
|
if ( !str->alloc(sptr->length()) ) // Ensure that memory is free
|
||||||
|
{
|
||||||
|
// finally decencrypt directly to allocated buffer.
|
||||||
|
length=my_aes_decrypt(sptr->ptr(),sptr->length(),str->ptr(),
|
||||||
|
key->ptr(),key->length());
|
||||||
|
if (length>=0) // if we got correct data data
|
||||||
|
{
|
||||||
|
str->length((uint)length);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bad parameters. No memory or bad data will all go here
|
||||||
|
null_value=1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item_func_aes_decrypt::fix_length_and_dec()
|
||||||
|
{
|
||||||
|
max_length=args[0]->max_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Concatinate args with the following premissess
|
** Concatinate args with the following premissess
|
||||||
** If only one arg which is ok, return value of arg
|
** If only one arg which is ok, return value of arg
|
||||||
|
@ -52,6 +52,34 @@ public:
|
|||||||
const char *func_name() const { return "md5"; }
|
const char *func_name() const { return "md5"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Item_func_sha :public Item_str_func
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Item_func_sha(Item *a) :Item_str_func(a) {}
|
||||||
|
String *val_str(String *);
|
||||||
|
void fix_length_and_dec();
|
||||||
|
const char *func_name() const { return "sha"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class Item_func_aes_encrypt :public Item_str_func
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Item_func_aes_encrypt(Item *a, Item *b) :Item_str_func(a,b) {}
|
||||||
|
String *val_str(String *);
|
||||||
|
void fix_length_and_dec();
|
||||||
|
const char *func_name() const { return "aes_encrypt"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class Item_func_aes_decrypt :public Item_str_func
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Item_func_aes_decrypt(Item *a, Item *b) :Item_str_func(a,b) {}
|
||||||
|
String *val_str(String *);
|
||||||
|
void fix_length_and_dec();
|
||||||
|
const char *func_name() const { return "aes_decrypt"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Item_func_concat :public Item_str_func
|
class Item_func_concat :public Item_str_func
|
||||||
{
|
{
|
||||||
String tmp_value;
|
String tmp_value;
|
||||||
|
@ -392,6 +392,8 @@ static SYMBOL sql_functions[] = {
|
|||||||
{ "ABS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_abs)},
|
{ "ABS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_abs)},
|
||||||
{ "ACOS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_acos)},
|
{ "ACOS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_acos)},
|
||||||
{ "ADDDATE", SYM(DATE_ADD_INTERVAL),0,0},
|
{ "ADDDATE", SYM(DATE_ADD_INTERVAL),0,0},
|
||||||
|
{ "AES_ENCRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_encrypt)},
|
||||||
|
{ "AES_DECRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_decrypt)},
|
||||||
{ "ASCII", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ascii)},
|
{ "ASCII", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ascii)},
|
||||||
{ "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)},
|
{ "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)},
|
||||||
{ "ATAN", SYM(ATAN),0,0},
|
{ "ATAN", SYM(ATAN),0,0},
|
||||||
@ -494,6 +496,8 @@ static SYMBOL sql_functions[] = {
|
|||||||
{ "SUBDATE", SYM(DATE_SUB_INTERVAL),0,0},
|
{ "SUBDATE", SYM(DATE_SUB_INTERVAL),0,0},
|
||||||
{ "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)},
|
{ "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)},
|
||||||
{ "SIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)},
|
{ "SIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)},
|
||||||
|
{ "SHA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)},
|
||||||
|
{ "SHA1", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)},
|
||||||
{ "SOUNDEX", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_soundex)},
|
{ "SOUNDEX", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_soundex)},
|
||||||
{ "SPACE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)},
|
{ "SPACE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)},
|
||||||
{ "SQRT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},
|
{ "SQRT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},
|
||||||
|
Reference in New Issue
Block a user