VMPCKSA3Engine.cs 1.1 KB

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