BlowFishKeygen.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network;
  16. import com.l2jserver.util.Rnd;
  17. /**
  18. * Blowfish keygen for GameServer client connections.
  19. * @author KenM
  20. */
  21. public class BlowFishKeygen
  22. {
  23. private static final int CRYPT_KEYS_SIZE = 20;
  24. private static final byte[][] CRYPT_KEYS = new byte[CRYPT_KEYS_SIZE][16];
  25. static
  26. {
  27. // init the GS encryption keys on class load
  28. for (int i = 0; i < CRYPT_KEYS_SIZE; i++)
  29. {
  30. // randomize the 8 first bytes
  31. for (int j = 0; j < CRYPT_KEYS[i].length; j++)
  32. {
  33. CRYPT_KEYS[i][j] = (byte) Rnd.get(255);
  34. }
  35. // the last 8 bytes are static
  36. CRYPT_KEYS[i][8] = (byte) 0xc8;
  37. CRYPT_KEYS[i][9] = (byte) 0x27;
  38. CRYPT_KEYS[i][10] = (byte) 0x93;
  39. CRYPT_KEYS[i][11] = (byte) 0x01;
  40. CRYPT_KEYS[i][12] = (byte) 0xa1;
  41. CRYPT_KEYS[i][13] = (byte) 0x6c;
  42. CRYPT_KEYS[i][14] = (byte) 0x31;
  43. CRYPT_KEYS[i][15] = (byte) 0x97;
  44. }
  45. }
  46. // block instantiation
  47. private BlowFishKeygen()
  48. {
  49. }
  50. /**
  51. * Returns a key from this keygen pool, the logical ownership is retained by this keygen.<BR>
  52. * Thus when getting a key with interests other then read-only a copy must be performed.<BR>
  53. * @return A key from this keygen pool.
  54. */
  55. public static byte[] getRandomKey()
  56. {
  57. return CRYPT_KEYS[Rnd.get(CRYPT_KEYS_SIZE)];
  58. }
  59. }