You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /*
  2. Copyright (c) 2000, 2003, 2005, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
  3. Use is subject to license terms.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. 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.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. /*
  16. Functions to handle the encode() and decode() functions
  17. The strongness of this crypt is large based on how good the random
  18. generator is. It should be ok for short strings, but for communication one
  19. needs something like 'ssh'.
  20. */
  21. #ifdef USE_PRAGMA_IMPLEMENTATION
  22. #pragma implementation // gcc: Class implementation
  23. #endif
  24. #include "mysql_priv.h"
  25. void SQL_CRYPT::init(ulong *rand_nr)
  26. {
  27. uint i;
  28. randominit(&rand,rand_nr[0],rand_nr[1]);
  29. for (i=0 ; i<=255; i++)
  30. decode_buff[i]= (char) i;
  31. for (i=0 ; i<= 255 ; i++)
  32. {
  33. int idx= (uint) (my_rnd(&rand)*255.0);
  34. char a= decode_buff[idx];
  35. decode_buff[idx]= decode_buff[i];
  36. decode_buff[+i]=a;
  37. }
  38. for (i=0 ; i <= 255 ; i++)
  39. encode_buff[(uchar) decode_buff[i]]=i;
  40. org_rand=rand;
  41. shift=0;
  42. }
  43. void SQL_CRYPT::encode(char *str,uint length)
  44. {
  45. for (uint i=0; i < length; i++)
  46. {
  47. shift^=(uint) (my_rnd(&rand)*255.0);
  48. uint idx= (uint) (uchar) str[0];
  49. *str++ = (char) ((uchar) encode_buff[idx] ^ shift);
  50. shift^= idx;
  51. }
  52. }
  53. void SQL_CRYPT::decode(char *str,uint length)
  54. {
  55. for (uint i=0; i < length; i++)
  56. {
  57. shift^=(uint) (my_rnd(&rand)*255.0);
  58. uint idx= (uint) ((uchar) str[0] ^ shift);
  59. *str = decode_buff[idx];
  60. shift^= (uint) (uchar) *str++;
  61. }
  62. }