Loading Docs/manual.texi +6 −0 Original line number Diff line number Diff line Loading @@ -27645,6 +27645,12 @@ flag again, the @code{SQL_MAX_JOIN_SIZE} variable will be ignored. You can set a default value for this variable by starting @code{mysqld} with @code{-O max_join_size=#}. Note that if the result of the query is in the query cache, the above check will not be made, but MySQL will instead send the result to the client. We regard this as a feature as in this case the query result is already computed and it will not cause any big burden for the server to send the result to the client. @item SQL_QUERY_CACHE_TYPE = OFF | ON | DEMAND @item SQL_QUERY_CACHE_TYPE = 0 | 1 | 2 Set query cache setting for this thread. include/my_aes.h +31 −49 Original line number Diff line number Diff line Loading @@ -18,67 +18,49 @@ /* 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 */ C_MODE_START #ifdef __cplusplus extern "C" { #endif #define AES_KEY_LENGTH 128 /* Must be 128 192 or 256 */ /* my_aes_encrypt - Crypt buffer with AES encryption algorithm. source - Pinter to data for encryption source_length - size of encruption data source - Pointer to data for encryption source_length - size of encryption 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 kel_length - Length 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, char *dest, const char *key, int key_length); /* my_aes_decrypt - DeCrypt buffer with AES encryption algorithm. source - Pinter to data for decryption source - Pointer 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 kel_length - Length 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, 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 C_MODE_END include/rijndael.h +22 −28 Original line number Diff line number Diff line Loading @@ -25,16 +25,12 @@ @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 #define AES_MAXKC (256/32) #define AES_MAXKB (256/8) #define AES_MAXNR 14 int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], int keyBits); Loading @@ -44,5 +40,3 @@ 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 */ include/sha1.h +29 −46 Original line number Diff line number Diff line Loading @@ -15,9 +15,6 @@ 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. Loading @@ -28,17 +25,9 @@ Please read the file sha1.c for more information. Modified 2002 by Peter Zaitsev to better follow MySQL standards */ /* 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 { Loading @@ -54,6 +43,7 @@ enum sha_result_codes This structure will hold context information for the SHA-1 hashing operation */ typedef struct SHA1_CONTEXT { ulonglong Length; /* Message length in bits */ Loading @@ -65,20 +55,13 @@ typedef struct SHA1_CONTEXT } SHA1_CONTEXT; /* * Function Prototypes Function Prototypes */ #ifdef __cplusplus extern "C" { #endif C_MODE_START 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 C_MODE_END mysys/my_aes.c +116 −104 Original line number Diff line number Diff line Loading @@ -21,44 +21,50 @@ */ #include "my_global.h" #include "m_string.h" #include <my_global.h> #include <m_string.h> #include "my_aes.h" enum encrypt_dir { AES_ENCRYPT, AES_DECRYPT }; #define AES_BLOCK_SIZE 16 /* Block size in bytes */ #define AES_BLOCK_SIZE 16 /* Block size in bytes */ #define AES_BAD_DATA -1 /* If bad data discovered during decoding */ #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 */ uint32 rk[4*(AES_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 SYNOPSIS my_aes_create_key() aes_key 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 DESCRIPTION RESULT 0 ok -1 Error Note: The current impementation never returns this */ static int my_aes_create_key(KEYINSTANCE* aes_key,char direction, char* key, static int my_aes_create_key(KEYINSTANCE *aes_key, enum encrypt_dir direction, const 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*/ char *ptr; /* Start of the real key*/ const char *sptr; /* Start of the working key */ const char *key_end=key+key_length; /* Working key boundary*/ bzero(rkey,AES_KEY_LENGTH/8); /* Set initial key */ Loading @@ -77,18 +83,22 @@ 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. Crypt buffer with AES encryption algorithm. SYNOPSIS my_aes_encrypt() source Pointer to data for encryption source_length Size of encryption data dest Buffer to place encrypted data (must be large enough) key Key to be used for encryption key_length Length of the key. Will handle keys of any length RETURN >= 0 Size of encrypted data < 0 Error */ int my_aes_encrypt(const char* source, int source_length, const char* dest, int my_aes_encrypt(const char* source, int source_length, char* dest, const char* key, int key_length) { KEYINSTANCE aes_key; Loading Loading @@ -120,25 +130,29 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest, /* 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. DeCrypt buffer with AES encryption algorithm. SYNOPSIS my_aes_decrypt() source Pointer 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 key_length Length of the key. Will handle keys of any length RETURN >= 0 Size of encrypted data < 0 Error */ int my_aes_decrypt(const char* source, int source_length, const char* dest, int my_aes_decrypt(const char *source, int source_length, 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 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))) Loading @@ -146,10 +160,8 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, 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 */ return AES_BAD_DATA; /* Input size has to be even and at least one block */ for (i = num_blocks-1; i > 0; i--) /* Decode all but last blocks */ { Loading @@ -159,29 +171,29 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, } 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*/ pad_len = block[AES_BLOCK_SIZE-1]; /* 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; } /* 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 Get size of buffer which will be large enough for encrypted data SYNOPSIS my_aes_get_size() source_length Length of data to be encrypted RETURN Size of buffer required to store encrypted data */ int my_aes_get_size(int source_length) { return AES_BLOCK_SIZE*(source_length/AES_BLOCK_SIZE)+AES_BLOCK_SIZE; } Loading
Docs/manual.texi +6 −0 Original line number Diff line number Diff line Loading @@ -27645,6 +27645,12 @@ flag again, the @code{SQL_MAX_JOIN_SIZE} variable will be ignored. You can set a default value for this variable by starting @code{mysqld} with @code{-O max_join_size=#}. Note that if the result of the query is in the query cache, the above check will not be made, but MySQL will instead send the result to the client. We regard this as a feature as in this case the query result is already computed and it will not cause any big burden for the server to send the result to the client. @item SQL_QUERY_CACHE_TYPE = OFF | ON | DEMAND @item SQL_QUERY_CACHE_TYPE = 0 | 1 | 2 Set query cache setting for this thread.
include/my_aes.h +31 −49 Original line number Diff line number Diff line Loading @@ -18,67 +18,49 @@ /* 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 */ C_MODE_START #ifdef __cplusplus extern "C" { #endif #define AES_KEY_LENGTH 128 /* Must be 128 192 or 256 */ /* my_aes_encrypt - Crypt buffer with AES encryption algorithm. source - Pinter to data for encryption source_length - size of encruption data source - Pointer to data for encryption source_length - size of encryption 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 kel_length - Length 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, char *dest, const char *key, int key_length); /* my_aes_decrypt - DeCrypt buffer with AES encryption algorithm. source - Pinter to data for decryption source - Pointer 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 kel_length - Length 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, 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 C_MODE_END
include/rijndael.h +22 −28 Original line number Diff line number Diff line Loading @@ -25,16 +25,12 @@ @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 #define AES_MAXKC (256/32) #define AES_MAXKB (256/8) #define AES_MAXNR 14 int rijndaelKeySetupEnc(uint32 rk[/*4*(Nr + 1)*/], const uint8 cipherKey[], int keyBits); Loading @@ -44,5 +40,3 @@ 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 */
include/sha1.h +29 −46 Original line number Diff line number Diff line Loading @@ -15,9 +15,6 @@ 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. Loading @@ -28,17 +25,9 @@ Please read the file sha1.c for more information. Modified 2002 by Peter Zaitsev to better follow MySQL standards */ /* 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 { Loading @@ -54,6 +43,7 @@ enum sha_result_codes This structure will hold context information for the SHA-1 hashing operation */ typedef struct SHA1_CONTEXT { ulonglong Length; /* Message length in bits */ Loading @@ -65,20 +55,13 @@ typedef struct SHA1_CONTEXT } SHA1_CONTEXT; /* * Function Prototypes Function Prototypes */ #ifdef __cplusplus extern "C" { #endif C_MODE_START 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 C_MODE_END
mysys/my_aes.c +116 −104 Original line number Diff line number Diff line Loading @@ -21,44 +21,50 @@ */ #include "my_global.h" #include "m_string.h" #include <my_global.h> #include <m_string.h> #include "my_aes.h" enum encrypt_dir { AES_ENCRYPT, AES_DECRYPT }; #define AES_BLOCK_SIZE 16 /* Block size in bytes */ #define AES_BLOCK_SIZE 16 /* Block size in bytes */ #define AES_BAD_DATA -1 /* If bad data discovered during decoding */ #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 */ uint32 rk[4*(AES_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 SYNOPSIS my_aes_create_key() aes_key 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 DESCRIPTION RESULT 0 ok -1 Error Note: The current impementation never returns this */ static int my_aes_create_key(KEYINSTANCE* aes_key,char direction, char* key, static int my_aes_create_key(KEYINSTANCE *aes_key, enum encrypt_dir direction, const 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*/ char *ptr; /* Start of the real key*/ const char *sptr; /* Start of the working key */ const char *key_end=key+key_length; /* Working key boundary*/ bzero(rkey,AES_KEY_LENGTH/8); /* Set initial key */ Loading @@ -77,18 +83,22 @@ 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. Crypt buffer with AES encryption algorithm. SYNOPSIS my_aes_encrypt() source Pointer to data for encryption source_length Size of encryption data dest Buffer to place encrypted data (must be large enough) key Key to be used for encryption key_length Length of the key. Will handle keys of any length RETURN >= 0 Size of encrypted data < 0 Error */ int my_aes_encrypt(const char* source, int source_length, const char* dest, int my_aes_encrypt(const char* source, int source_length, char* dest, const char* key, int key_length) { KEYINSTANCE aes_key; Loading Loading @@ -120,25 +130,29 @@ int my_aes_encrypt(const char* source, int source_length, const char* dest, /* 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. DeCrypt buffer with AES encryption algorithm. SYNOPSIS my_aes_decrypt() source Pointer 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 key_length Length of the key. Will handle keys of any length RETURN >= 0 Size of encrypted data < 0 Error */ int my_aes_decrypt(const char* source, int source_length, const char* dest, int my_aes_decrypt(const char *source, int source_length, 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 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))) Loading @@ -146,10 +160,8 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, 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 */ return AES_BAD_DATA; /* Input size has to be even and at least one block */ for (i = num_blocks-1; i > 0; i--) /* Decode all but last blocks */ { Loading @@ -159,29 +171,29 @@ int my_aes_decrypt(const char* source, int source_length, const char* dest, } 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*/ pad_len = block[AES_BLOCK_SIZE-1]; /* 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; } /* 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 Get size of buffer which will be large enough for encrypted data SYNOPSIS my_aes_get_size() source_length Length of data to be encrypted RETURN Size of buffer required to store encrypted data */ int my_aes_get_size(int source_length) { return AES_BLOCK_SIZE*(source_length/AES_BLOCK_SIZE)+AES_BLOCK_SIZE; }