Commit d5058037 authored by peter@linux.local's avatar peter@linux.local

This is just code style/minor optimizations cleanup changeset

parent 7e80b058
...@@ -1384,18 +1384,17 @@ int main(int argc, char **argv) ...@@ -1384,18 +1384,17 @@ 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) else if (opt_single_transaction)
{
/* There is no sense to start transaction if all tables are locked */
if (mysql_query(sock, "BEGIN"))
{ {
if (mysql_query(sock, "BEGIN")) my_printf_error(0, "Error: Couldn't execute 'BEGIN': %s",
{
my_printf_error(0, "Error: Couldn't execute 'BEGIN': %s",
MYF(0), mysql_error(sock)); MYF(0), mysql_error(sock));
my_end(0); my_end(0);
return(first_error); 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) */
...@@ -1440,12 +1439,13 @@ int main(int argc, char **argv) ...@@ -1440,12 +1439,13 @@ 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 */ else if (opt_single_transaction) /* Just to make it beautiful enough */
{ {
/*
In case we were locking all tables, we did not start transaction
so there is no need to commit it.
*/
/* This should just free locks as we did not change anything */ /* This should just free locks as we did not change anything */
if (mysql_query(sock, "COMMIT")) if (mysql_query(sock, "COMMIT"))
{ {
......
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Header file for my_aes.c */ /* Header file for my_aes.c */
...@@ -33,7 +33,7 @@ extern "C" { ...@@ -33,7 +33,7 @@ extern "C" {
#endif #endif
/* /*
my_aes_crypt - Crypt buffer with AES encryption algorithm. my_aes_encrypt - Crypt buffer with AES encryption algorithm.
source - Pinter to data for encryption source - Pinter to data for encryption
source_length - size of encruption data source_length - size of encruption data
dest - buffer to place encrypted data (must be large enough) dest - buffer to place encrypted data (must be large enough)
...@@ -65,7 +65,8 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, ...@@ -65,7 +65,8 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest,
/* /*
my_aes_get_size - get size of buffer which will be large enough for encrypted data my_aes_get_size - get size of buffer which will be large enough for encrypted
data
source_length - length of data to be encrypted source_length - length of data to be encrypted
returns - size of buffer required to store encrypted data returns - size of buffer required to store encrypted data
......
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* /*
rijndael-alg-fst.h rijndael-alg-fst.h
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* /*
sha1.h sha1.h
......
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* MY_AES.C Implementation of AES Encryption for MySQL */ /*
Implementation of AES Encryption for MySQL
Initial version by Peter Zaitsev June 2002
*/
#include "my_global.h" #include "my_global.h"
#include "m_string.h" #include "m_string.h"
#include <stdio.h>
#include "my_aes.h" #include "my_aes.h"
#define AES_ENCRYPT 1 enum encrypt_dir { AES_ENCRYPT, AES_DECRYPT };
#define AES_DECRYPT 2
#define AES_BLOCK_SIZE 16 #define AES_BLOCK_SIZE 16
/* Block size in bytes */ /* Block size in bytes */
...@@ -75,6 +76,18 @@ static int my_aes_create_key(KEYINSTANCE* aes_key,char direction, char* key, ...@@ -75,6 +76,18 @@ static int my_aes_create_key(KEYINSTANCE* aes_key,char direction, char* key,
} }
/*
my_aes_encrypt - 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, int my_aes_encrypt(const char* source, int source_length, const char* dest,
const char* key, int key_length) const char* key, int key_length)
{ {
...@@ -85,7 +98,7 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest, ...@@ -85,7 +98,7 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest,
char pad_len; /* pad size for the last block */ char pad_len; /* pad size for the last block */
int i; int i;
if ( (rc=my_aes_create_key(&aes_key,AES_ENCRYPT,key,key_length)) ) if ((rc=my_aes_create_key(&aes_key,AES_ENCRYPT,key,key_length)))
return rc; return rc;
num_blocks = source_length/AES_BLOCK_SIZE; num_blocks = source_length/AES_BLOCK_SIZE;
...@@ -104,7 +117,20 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest, ...@@ -104,7 +117,20 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest,
rijndaelEncrypt(aes_key.rk, aes_key.nr, block, dest); rijndaelEncrypt(aes_key.rk, aes_key.nr, block, dest);
return AES_BLOCK_SIZE*(num_blocks + 1); return AES_BLOCK_SIZE*(num_blocks + 1);
} }
/*
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, int my_aes_decrypt(const char* source, int source_length, const char* dest,
const char* key, int key_length) const char* key, int key_length)
{ {
...@@ -115,7 +141,7 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, ...@@ -115,7 +141,7 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest,
char pad_len; /* pad size for the last block */ char pad_len; /* pad size for the last block */
int i; int i;
if ( (rc=my_aes_create_key(&aes_key,AES_DECRYPT,key,key_length)) ) if ((rc=my_aes_create_key(&aes_key,AES_DECRYPT,key,key_length)))
return rc; return rc;
num_blocks = source_length/AES_BLOCK_SIZE; num_blocks = source_length/AES_BLOCK_SIZE;
...@@ -143,6 +169,14 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, ...@@ -143,6 +169,14 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest,
return AES_BLOCK_SIZE*num_blocks - pad_len; return AES_BLOCK_SIZE*num_blocks - pad_len;
} }
/*
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) int my_aes_get_size(int source_length)
{ {
......
/* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2002 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
at your option) any later version. at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
/** rijndael-alg-fst.c
* rijndael-alg-fst.c
* @version 3.0 (December 2000)
* @version 3.0 (December 2000)
* Optimised ANSI C code for the Rijndael cipher (now AES)
* Optimised ANSI C code for the Rijndael cipher (now AES)
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> @author Paulo Barreto <paulo.barreto@terra.com.br>
* @author Paulo Barreto <paulo.barreto@terra.com.br>
* This code is hereby placed in the public domain.
* This code is hereby placed in the public domain.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <my_global.h> #include <my_global.h>
...@@ -47,11 +36,13 @@ ...@@ -47,11 +36,13 @@
#include "rijndael.h" #include "rijndael.h"
/* /*
May be defined to use fastest and much larger code (~10K extra code)
#define FULL_UNROLL #define FULL_UNROLL
May be defined to use fastest and much larger code.
*/ */
#ifdef NOT_USED
/* /*
Te0[x] = S [x].[02, 01, 01, 03]; Te0[x] = S [x].[02, 01, 01, 03];
Te1[x] = S [x].[03, 02, 01, 01]; Te1[x] = S [x].[03, 02, 01, 01];
...@@ -66,6 +57,8 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e]; ...@@ -66,6 +57,8 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
Td4[x] = Si[x].[01, 01, 01, 01]; Td4[x] = Si[x].[01, 01, 01, 01];
*/ */
#endif
static const uint32 Te0[256]= static const uint32 Te0[256]=
{ {
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
...@@ -801,9 +794,7 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], ...@@ -801,9 +794,7 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
rk[6] = rk[2] ^ rk[5]; rk[6] = rk[2] ^ rk[5];
rk[7] = rk[3] ^ rk[6]; rk[7] = rk[3] ^ rk[6];
if (++i == 10) if (++i == 10)
{
return 10; return 10;
}
rk += 4; rk += 4;
} }
} }
...@@ -814,12 +805,12 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], ...@@ -814,12 +805,12 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
for (;;) for (;;)
{ {
temp = rk[ 5]; temp = rk[ 5];
rk[ 6] = rk[ 0] ^ rk[ 6] = (rk[ 0] ^
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^ (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
(Te4[(temp ) & 0xff] & 0x0000ff00) ^ (Te4[(temp ) & 0xff] & 0x0000ff00) ^
(Te4[(temp >> 24) ] & 0x000000ff) ^ (Te4[(temp >> 24) ] & 0x000000ff) ^
rcon[i]; rcon[i]);
rk[ 7] = rk[ 1] ^ rk[ 6]; rk[ 7] = rk[ 1] ^ rk[ 6];
rk[ 8] = rk[ 2] ^ rk[ 7]; rk[ 8] = rk[ 2] ^ rk[ 7];
rk[ 9] = rk[ 3] ^ rk[ 8]; rk[ 9] = rk[ 3] ^ rk[ 8];
...@@ -839,12 +830,12 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], ...@@ -839,12 +830,12 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
for (;;) for (;;)
{ {
temp = rk[ 7]; temp = rk[ 7];
rk[ 8] = rk[ 0] ^ rk[ 8] = (rk[ 0] ^
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^ (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
(Te4[(temp ) & 0xff] & 0x0000ff00) ^ (Te4[(temp ) & 0xff] & 0x0000ff00) ^
(Te4[(temp >> 24) ] & 0x000000ff) ^ (Te4[(temp >> 24) ] & 0x000000ff) ^
rcon[i]; rcon[i]);
rk[ 9] = rk[ 1] ^ rk[ 8]; rk[ 9] = rk[ 1] ^ rk[ 8];
rk[10] = rk[ 2] ^ rk[ 9]; rk[10] = rk[ 2] ^ rk[ 9];
rk[11] = rk[ 3] ^ rk[10]; rk[11] = rk[ 3] ^ rk[10];
...@@ -853,11 +844,11 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], ...@@ -853,11 +844,11 @@ int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[],
return 14; return 14;
} }
temp = rk[11]; temp = rk[11];
rk[12] = rk[ 4] ^ rk[12] = (rk[ 4] ^
(Te4[(temp >> 24) ] & 0xff000000) ^ (Te4[(temp >> 24) ] & 0xff000000) ^
(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
(Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
(Te4[(temp ) & 0xff] & 0x000000ff); (Te4[(temp ) & 0xff] & 0x000000ff));
rk[13] = rk[ 5] ^ rk[12]; rk[13] = rk[ 5] ^ rk[12];
rk[14] = rk[ 6] ^ rk[13]; rk[14] = rk[ 6] ^ rk[13];
rk[15] = rk[ 7] ^ rk[14]; rk[15] = rk[ 7] ^ rk[14];
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* /*
sha1.c sha1.c
Original Source from: http://www.faqs.org/rfcs/rfc3174.html Original Source from: http://www.faqs.org/rfcs/rfc3174.html
...@@ -47,13 +47,15 @@ ...@@ -47,13 +47,15 @@
*/ */
/* /*
Modified by 2002 by Peter Zaitsev to Modified 2002 by Peter Zaitsev to
- fit to new prototypes according to MySQL standard - fit to new prototypes according to MySQL standard
- Some optimizations - Some optimizations
- All checking is now done in debug only mode - All checking is now done in debug only mode
- More comments - More comments
*/ */
#include "my_global.h"
#include "m_string.h"
#include "sha1.h" #include "sha1.h"
/* /*
...@@ -160,11 +162,8 @@ int sha1_result( SHA1_CONTEXT *context, ...@@ -160,11 +162,8 @@ int sha1_result( SHA1_CONTEXT *context,
#endif #endif
SHA1PadMessage(context); SHA1PadMessage(context);
for (i=0; i<64; i++) /* message may be sensitive, clear it out */
{ bzero((char*) context->Message_Block,64);
/* message may be sensitive, clear it out */
context->Message_Block[i] = 0;
}
context->Length = 0; /* and clear length */ context->Length = 0; /* and clear length */
context->Computed = 1; context->Computed = 1;
...@@ -174,8 +173,8 @@ int sha1_result( SHA1_CONTEXT *context, ...@@ -174,8 +173,8 @@ int sha1_result( SHA1_CONTEXT *context,
for (i = 0; i < SHA1_HASH_SIZE; i++) for (i = 0; i < SHA1_HASH_SIZE; i++)
{ {
Message_Digest[i] = context->Intermediate_Hash[i>>2] Message_Digest[i] = (context->Intermediate_Hash[i>>2] >> 8
>> 8 * ( 3 - ( i & 0x03 ) ); * ( 3 - ( i & 0x03 ) ));
} }
return SHA_SUCCESS; return SHA_SUCCESS;
...@@ -225,12 +224,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, ...@@ -225,12 +224,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
{ {
return context->Corrupted; return context->Corrupted;
} }
while (length-- && !context->Corrupted)
#else
while (length--)
#endif #endif
while (length--)
{ {
context->Message_Block[context->Message_Block_Index++] = context->Message_Block[context->Message_Block_Index++] =
(*message_array & 0xFF); (*message_array & 0xFF);
...@@ -245,6 +241,7 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, ...@@ -245,6 +241,7 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
{ {
/* Message is too long */ /* Message is too long */
context->Corrupted = 1; context->Corrupted = 1;
return 1;
} }
#endif #endif
...@@ -252,10 +249,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, ...@@ -252,10 +249,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
{ {
SHA1ProcessMessageBlock(context); SHA1ProcessMessageBlock(context);
} }
message_array++;
message_array++;
} }
return SHA_SUCCESS; return SHA_SUCCESS;
} }
...@@ -281,8 +277,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, ...@@ -281,8 +277,9 @@ int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array,
*/ */
/* Constants defined in SHA-1 */
static const uint32 K[]= static const uint32 K[]=
{ /* Constants defined in SHA-1 */ {
0x5A827999, 0x5A827999,
0x6ED9EBA1, 0x6ED9EBA1,
0x8F1BBCDC, 0x8F1BBCDC,
...@@ -312,7 +309,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context) ...@@ -312,7 +309,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
} }
for(t = 16; t < 80; t++) for (t = 16; t < 80; t++)
{ {
W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]);
} }
...@@ -323,7 +320,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context) ...@@ -323,7 +320,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
D = context->Intermediate_Hash[3]; D = context->Intermediate_Hash[3];
E = context->Intermediate_Hash[4]; E = context->Intermediate_Hash[4];
for(t = 0; t < 20; t++) for (t = 0; t < 20; t++)
{ {
temp = SHA1CircularShift(5,A) + temp = SHA1CircularShift(5,A) +
((B & C) | ((~B) & D)) + E + W[t] + K[0]; ((B & C) | ((~B) & D)) + E + W[t] + K[0];
...@@ -334,7 +331,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context) ...@@ -334,7 +331,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
A = temp; A = temp;
} }
for(t = 20; t < 40; t++) for (t = 20; t < 40; t++)
{ {
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
E = D; E = D;
...@@ -344,7 +341,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context) ...@@ -344,7 +341,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
A = temp; A = temp;
} }
for(t = 40; t < 60; t++) for (t = 40; t < 60; t++)
{ {
temp = SHA1CircularShift(5,A) + temp = SHA1CircularShift(5,A) +
((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
...@@ -355,7 +352,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context) ...@@ -355,7 +352,7 @@ void SHA1ProcessMessageBlock(SHA1_CONTEXT *context)
A = temp; A = temp;
} }
for(t = 60; t < 80; t++) for (t = 60; t < 80; t++)
{ {
temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
E = D; E = D;
...@@ -408,33 +405,6 @@ void SHA1PadMessage(SHA1_CONTEXT *context) ...@@ -408,33 +405,6 @@ void SHA1PadMessage(SHA1_CONTEXT *context)
block. 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; int i=context->Message_Block_Index;
if (i > 55) if (i > 55)
...@@ -444,9 +414,9 @@ void SHA1PadMessage(SHA1_CONTEXT *context) ...@@ -444,9 +414,9 @@ void SHA1PadMessage(SHA1_CONTEXT *context)
sizeof(context->Message_Block[0])*(64-i)); sizeof(context->Message_Block[0])*(64-i));
context->Message_Block_Index=64; context->Message_Block_Index=64;
SHA1ProcessMessageBlock(context);
/* This function sets context->Message_Block_Index to zero */ /* This function sets context->Message_Block_Index to zero */
SHA1ProcessMessageBlock(context);
bzero((char*) &context->Message_Block[0], bzero((char*) &context->Message_Block[0],
sizeof(context->Message_Block[0])*56); sizeof(context->Message_Block[0])*56);
context->Message_Block_Index=56; context->Message_Block_Index=56;
...@@ -460,8 +430,6 @@ void SHA1PadMessage(SHA1_CONTEXT *context) ...@@ -460,8 +430,6 @@ void SHA1PadMessage(SHA1_CONTEXT *context)
context->Message_Block_Index=56; context->Message_Block_Index=56;
} }
#endif
/* /*
Store the message length as the last 8 octets Store the message length as the last 8 octets
*/ */
......
...@@ -108,21 +108,16 @@ String *Item_func_sha::val_str(String *str) ...@@ -108,21 +108,16 @@ String *Item_func_sha::val_str(String *str)
if (sptr) /* If we got value different from NULL */ if (sptr) /* If we got value different from NULL */
{ {
SHA1_CONTEXT context; /* Context used to generate SHA1 hash */ SHA1_CONTEXT context; /* Context used to generate SHA1 hash */
/* Temporary buffer to store 160bit digest */ /* Temporary buffer to store 160bit digest */
uint8_t digest[SHA1_HASH_SIZE]; uint8_t digest[SHA1_HASH_SIZE];
null_value=0;
sha1_reset(&context); /* We do not have to check for error here */ 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 */ /* No need to check error as the only case would be too long message */
sha1_input(&context,(const unsigned char *) sptr->ptr(), sptr->length()); sha1_input(&context,(const unsigned char *) sptr->ptr(), sptr->length());
/* Ensure that memory is free and we got result */
if (str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest)) ) if ( !( str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest)) ) )
// Ensure that memory is free
{ {
null_value=1; sprintf((char *) str->ptr(),
return 0; "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\
}
sprintf((char *) str->ptr(),
"%02x%02x%02x%02x%02x%02x%02x%02x%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[0], digest[1], digest[2], digest[3],
digest[4], digest[5], digest[6], digest[7], digest[4], digest[5], digest[6], digest[7],
...@@ -130,9 +125,11 @@ String *Item_func_sha::val_str(String *str) ...@@ -130,9 +125,11 @@ String *Item_func_sha::val_str(String *str)
digest[12], digest[13], digest[14], digest[15], digest[12], digest[13], digest[14], digest[15],
digest[16], digest[17], digest[18], digest[19]); digest[16], digest[17], digest[18], digest[19]);
str->length((uint) SHA1_HASH_SIZE*2); str->length((uint) SHA1_HASH_SIZE*2);
return str; null_value=0;
} return str;
}
}
null_value=1; null_value=1;
return 0; return 0;
} }
...@@ -141,10 +138,10 @@ void Item_func_sha::fix_length_and_dec() ...@@ -141,10 +138,10 @@ void Item_func_sha::fix_length_and_dec()
{ {
max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash
} }
/* Implementation of AES encryption routines */ /* Implementation of AES encryption routines */
String *Item_func_aes_encrypt::val_str(String *str) String *Item_func_aes_encrypt::val_str(String *str)
{ {
String * sptr = args[0]->val_str(str); // String to encrypt String * sptr = args[0]->val_str(str); // String to encrypt
...@@ -163,7 +160,7 @@ String *Item_func_aes_encrypt::val_str(String *str) ...@@ -163,7 +160,7 @@ String *Item_func_aes_encrypt::val_str(String *str)
key->length()) == aes_length) key->length()) == aes_length)
{ {
// we have to get expected result length // we have to get expected result length
str->length((uint)aes_length); str->length((uint) aes_length);
return str; return str;
} }
} }
...@@ -193,10 +190,10 @@ String *Item_func_aes_decrypt::val_str(String *str) ...@@ -193,10 +190,10 @@ String *Item_func_aes_decrypt::val_str(String *str)
length=my_aes_decrypt(sptr->ptr(),sptr->length(),str->ptr(), length=my_aes_decrypt(sptr->ptr(),sptr->length(),str->ptr(),
key->ptr(),key->length()); key->ptr(),key->length());
if (length>=0) // if we got correct data data if (length>=0) // if we got correct data data
{ {
str->length((uint)length); str->length((uint) length);
return str; return str;
} }
} }
} }
// Bad parameters. No memory or bad data will all go here // Bad parameters. No memory or bad data will all go here
...@@ -208,8 +205,8 @@ void Item_func_aes_decrypt::fix_length_and_dec() ...@@ -208,8 +205,8 @@ void Item_func_aes_decrypt::fix_length_and_dec()
{ {
max_length=args[0]->max_length; 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
......
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