Commit b6afdd09 authored by unknown's avatar unknown

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
parent 15c99d52
......@@ -65,3 +65,4 @@ worm@altair.is.lan
zak@balfor.local
zak@linux.local
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_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
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 @@
** Tnu Samuel <tonu@please.do.not.remove.this.spam.ee>
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
** 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"
......@@ -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_alldbs=0,opt_create_db=0,opt_first_slave=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 char insert_pat[12 * 1024],*opt_password=0,*current_user=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.",
(gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG,
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',
"'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,
......@@ -340,8 +345,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
usage();
exit(0);
case (int) OPT_OPTIMIZE:
extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
opt_disable_keys=1;
extended_insert=opt_drop=opt_lock=quick=create_options=opt_disable_keys=
lock_tables=1;
if (opt_single_transaction) lock_tables=0;
break;
case (int) OPT_TABLES:
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);
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)
{
......@@ -1372,6 +1384,18 @@ int main(int argc, char **argv)
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)
dump_all_databases();
/* Only one database and selected table(s) */
......@@ -1416,6 +1440,19 @@ int main(int argc, char **argv)
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);
fputs("\n", md_result_file);
if (md_result_file != stdout)
......
/* 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
/* 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 */
/* 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');
md5('hello')
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),'*');
repeat('monty',5) concat('*',space(5),'*')
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 soundex(''),soundex('he'),soundex('hello all folks');
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 reverse('abc'),reverse('abcd');
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 \
my_net.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 \
thr_mutex.c thr_rwlock.c
libmysys_a_LIBADD = @THREAD_LOBJECTS@
......
/* 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;
}
This diff is collapsed.
This diff is collapsed.
......@@ -32,6 +32,16 @@ Item *create_func_acos(Item* 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)
{
return new Item_func_ascii(a);
......@@ -327,6 +337,11 @@ Item *create_func_sin(Item* 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)
{
return new Item_func_repeat(new Item_string(" ",1),a);
......
......@@ -18,6 +18,8 @@
Item *create_func_abs(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_asin(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_sign(Item* a);
Item *create_func_sin(Item* a);
Item *create_func_sha(Item* a);
Item *create_func_soundex(Item* a);
Item *create_func_space(Item *);
Item *create_func_sqrt(Item* a);
......
......@@ -34,6 +34,8 @@
#include <openssl/des.h>
#endif /* HAVE_OPENSSL */
#include "md5.h"
#include "sha1.h"
#include "my_aes.h"
String empty_string("");
......@@ -99,6 +101,115 @@ void Item_func_md5::fix_length_and_dec()
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
** If only one arg which is ok, return value of arg
......
......@@ -52,6 +52,34 @@ public:
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
{
String tmp_value;
......
......@@ -392,6 +392,8 @@ static SYMBOL sql_functions[] = {
{ "ABS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_abs)},
{ "ACOS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_acos)},
{ "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)},
{ "ASIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_asin)},
{ "ATAN", SYM(ATAN),0,0},
......@@ -494,6 +496,8 @@ static SYMBOL sql_functions[] = {
{ "SUBDATE", SYM(DATE_SUB_INTERVAL),0,0},
{ "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)},
{ "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)},
{ "SPACE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)},
{ "SQRT", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment