1
/* Copyright (C) 2000-2001, 2003, 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
Functions to handle the encode() and decode() functions
20
The strongness of this crypt is large based on how good the random
21
generator is. It should be ok for short strings, but for communication one
22
needs something like 'ssh'.
25
#ifdef USE_PRAGMA_IMPLEMENTATION
26
#pragma implementation // gcc: Class implementation
29
#include "mysql_priv.h"
31
SQL_CRYPT::SQL_CRYPT(const char *password)
34
hash_password(rand_nr,password, strlen(password));
38
void SQL_CRYPT::crypt_init(ulong *rand_nr)
41
randominit(&rand,rand_nr[0],rand_nr[1]);
43
for (i=0 ; i<=255; i++)
44
decode_buff[i]= (char) i;
46
for (i=0 ; i<= 255 ; i++)
48
int idx= (uint) (my_rnd(&rand)*255.0);
49
char a= decode_buff[idx];
50
decode_buff[idx]= decode_buff[i];
53
for (i=0 ; i <= 255 ; i++)
54
encode_buff[(uchar) decode_buff[i]]=i;
60
void SQL_CRYPT::encode(char *str,uint length)
62
for (uint i=0; i < length; i++)
64
shift^=(uint) (my_rnd(&rand)*255.0);
65
uint idx= (uint) (uchar) str[0];
66
*str++ = (char) ((uchar) encode_buff[idx] ^ shift);
72
void SQL_CRYPT::decode(char *str,uint length)
74
for (uint i=0; i < length; i++)
76
shift^=(uint) (my_rnd(&rand)*255.0);
77
uint idx= (uint) ((uchar) str[0] ^ shift);
78
*str = decode_buff[idx];
79
shift^= (uint) (uchar) *str++;