JPakeRound2Payload.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.JPake
  7. {
  8. /// <summary>
  9. /// The payload sent/received during the second round of a J-PAKE exchange.
  10. ///
  11. /// Each JPAKEParticipant creates and sends an instance
  12. /// of this payload to the other JPAKEParticipant.
  13. /// The payload to send should be created via
  14. /// JPAKEParticipant#createRound2PayloadToSend()
  15. ///
  16. /// Each JPAKEParticipant must also validate the payload
  17. /// received from the other JPAKEParticipant.
  18. /// The received payload should be validated via
  19. /// JPAKEParticipant#validateRound2PayloadReceived(JPakeRound2Payload)
  20. /// </summary>
  21. public class JPakeRound2Payload
  22. {
  23. /// <summary>
  24. /// The id of the JPAKEParticipant who created/sent this payload.
  25. /// </summary>
  26. private readonly string participantId;
  27. /// <summary>
  28. /// The value of A, as computed during round 2.
  29. /// </summary>
  30. private readonly BigInteger a;
  31. /// <summary>
  32. /// The zero knowledge proof for x2 * s.
  33. ///
  34. /// This is a two element array, containing {g^v, r} for x2 * s.
  35. /// </summary>
  36. private readonly BigInteger[] knowledgeProofForX2s;
  37. public JPakeRound2Payload(string participantId, BigInteger a, BigInteger[] knowledgeProofForX2s)
  38. {
  39. JPakeUtilities.ValidateNotNull(participantId, "participantId");
  40. JPakeUtilities.ValidateNotNull(a, "a");
  41. JPakeUtilities.ValidateNotNull(knowledgeProofForX2s, "knowledgeProofForX2s");
  42. this.participantId = participantId;
  43. this.a = a;
  44. this.knowledgeProofForX2s = new BigInteger[knowledgeProofForX2s.Length];
  45. knowledgeProofForX2s.CopyTo(this.knowledgeProofForX2s, 0);
  46. }
  47. public virtual string ParticipantId
  48. {
  49. get { return participantId; }
  50. }
  51. public virtual BigInteger A
  52. {
  53. get { return a; }
  54. }
  55. public virtual BigInteger[] KnowledgeProofForX2s
  56. {
  57. get
  58. {
  59. BigInteger[] kp = new BigInteger[knowledgeProofForX2s.Length];
  60. Array.Copy(knowledgeProofForX2s, kp, knowledgeProofForX2s.Length);
  61. return kp;
  62. }
  63. }
  64. }
  65. }
  66. #pragma warning restore
  67. #endif