MqvPrivateParameters.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. namespace Org.BouncyCastle.Crypto.Parameters
  4. {
  5. public class MqvPrivateParameters
  6. : ICipherParameters
  7. {
  8. private readonly ECPrivateKeyParameters staticPrivateKey;
  9. private readonly ECPrivateKeyParameters ephemeralPrivateKey;
  10. private readonly ECPublicKeyParameters ephemeralPublicKey;
  11. public MqvPrivateParameters(
  12. ECPrivateKeyParameters staticPrivateKey,
  13. ECPrivateKeyParameters ephemeralPrivateKey)
  14. : this(staticPrivateKey, ephemeralPrivateKey, null)
  15. {
  16. }
  17. public MqvPrivateParameters(
  18. ECPrivateKeyParameters staticPrivateKey,
  19. ECPrivateKeyParameters ephemeralPrivateKey,
  20. ECPublicKeyParameters ephemeralPublicKey)
  21. {
  22. if (staticPrivateKey == null)
  23. throw new ArgumentNullException("staticPrivateKey");
  24. if (ephemeralPrivateKey == null)
  25. throw new ArgumentNullException("ephemeralPrivateKey");
  26. ECDomainParameters parameters = staticPrivateKey.Parameters;
  27. if (!parameters.Equals(ephemeralPrivateKey.Parameters))
  28. throw new ArgumentException("Static and ephemeral private keys have different domain parameters");
  29. if (ephemeralPublicKey == null)
  30. {
  31. ephemeralPublicKey = new ECPublicKeyParameters(
  32. parameters.G.Multiply(ephemeralPrivateKey.D),
  33. parameters);
  34. }
  35. else if (!parameters.Equals(ephemeralPublicKey.Parameters))
  36. {
  37. throw new ArgumentException("Ephemeral public key has different domain parameters");
  38. }
  39. this.staticPrivateKey = staticPrivateKey;
  40. this.ephemeralPrivateKey = ephemeralPrivateKey;
  41. this.ephemeralPublicKey = ephemeralPublicKey;
  42. }
  43. public virtual ECPrivateKeyParameters StaticPrivateKey
  44. {
  45. get { return staticPrivateKey; }
  46. }
  47. public virtual ECPrivateKeyParameters EphemeralPrivateKey
  48. {
  49. get { return ephemeralPrivateKey; }
  50. }
  51. public virtual ECPublicKeyParameters EphemeralPublicKey
  52. {
  53. get { return ephemeralPublicKey; }
  54. }
  55. }
  56. }
  57. #endif