BlowFishKeygen.java 2.0 KB

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