VMPCKSA3Engine.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. namespace Org.BouncyCastle.Crypto.Engines
  4. {
  5. public class VmpcKsa3Engine
  6. : VmpcEngine
  7. {
  8. public override string AlgorithmName
  9. {
  10. get { return "VMPC-KSA3"; }
  11. }
  12. protected override void InitKey(
  13. byte[] keyBytes,
  14. byte[] ivBytes)
  15. {
  16. s = 0;
  17. P = new byte[256];
  18. for (int i = 0; i < 256; i++)
  19. {
  20. P[i] = (byte) i;
  21. }
  22. for (int m = 0; m < 768; m++)
  23. {
  24. s = P[(s + P[m & 0xff] + keyBytes[m % keyBytes.Length]) & 0xff];
  25. byte temp = P[m & 0xff];
  26. P[m & 0xff] = P[s & 0xff];
  27. P[s & 0xff] = temp;
  28. }
  29. for (int m = 0; m < 768; m++)
  30. {
  31. s = P[(s + P[m & 0xff] + ivBytes[m % ivBytes.Length]) & 0xff];
  32. byte temp = P[m & 0xff];
  33. P[m & 0xff] = P[s & 0xff];
  34. P[s & 0xff] = temp;
  35. }
  36. for (int m = 0; m < 768; m++)
  37. {
  38. s = P[(s + P[m & 0xff] + keyBytes[m % keyBytes.Length]) & 0xff];
  39. byte temp = P[m & 0xff];
  40. P[m & 0xff] = P[s & 0xff];
  41. P[s & 0xff] = temp;
  42. }
  43. n = 0;
  44. }
  45. }
  46. }
  47. #endif