diff options
author | unknown <peter@linux.local> | 2002-06-14 15:14:30 +0400 |
---|---|---|
committer | unknown <peter@linux.local> | 2002-06-14 15:14:30 +0400 |
commit | 8451d47ac70f5840ec1d5fcfee2982f2a8cedc49 (patch) | |
tree | f47e08fb9e4c935c0c094ada6d7b5861615d6609 /mysys/my_aes.c | |
parent | 2325b78d128dc1052f86a3630b35f0b37d809738 (diff) | |
download | mariadb-git-8451d47ac70f5840ec1d5fcfee2982f2a8cedc49.tar.gz |
This is just code style/minor optimizations cleanup changeset
client/mysqldump.c:
Changes adviced by Monty
include/my_aes.h:
Changes adviced by Monty
include/rijndael.h:
Changes adviced by Monty
include/sha1.h:
Changes adviced by Monty
mysys/my_aes.c:
Changes adviced by Monty
mysys/rijndael.c:
Changes adviced by Monty
mysys/sha1.c:
Changes adviced by Monty
sql/item_strfunc.cc:
Changes adviced by Monty
Diffstat (limited to 'mysys/my_aes.c')
-rw-r--r-- | mysys/my_aes.c | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/mysys/my_aes.c b/mysys/my_aes.c index 48744b79cdf..e1c538ef29c 100644 --- a/mysys/my_aes.c +++ b/mysys/my_aes.c @@ -1,31 +1,32 @@ -/* 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. +/* 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. + 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 */ + 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 */ +/* + Implementation of AES Encryption for MySQL + Initial version by Peter Zaitsev June 2002 +*/ #include "my_global.h" #include "m_string.h" -#include <stdio.h> #include "my_aes.h" -#define AES_ENCRYPT 1 -#define AES_DECRYPT 2 +enum encrypt_dir { AES_ENCRYPT, AES_DECRYPT }; #define AES_BLOCK_SIZE 16 /* Block size in bytes */ @@ -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, const char* key, int key_length) { @@ -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 */ 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; num_blocks = source_length/AES_BLOCK_SIZE; @@ -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); 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, const char* key, int key_length) { @@ -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 */ 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; num_blocks = source_length/AES_BLOCK_SIZE; @@ -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; } + + +/* +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) { |