JPakeRound1Payload.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Agreement.JPake
  6. {
  7. /// <summary>
  8. /// The payload sent/received during the first round of a J-PAKE exchange.
  9. ///
  10. /// Each JPAKEParticipant creates and sends an instance of this payload to
  11. /// the other. The payload to send should be created via
  12. /// JPAKEParticipant.CreateRound1PayloadToSend().
  13. ///
  14. /// Each participant must also validate the payload received from the other.
  15. /// The received payload should be validated via
  16. /// JPAKEParticipant.ValidateRound1PayloadReceived(JPakeRound1Payload).
  17. /// </summary>
  18. public class JPakeRound1Payload
  19. {
  20. /// <summary>
  21. /// The id of the JPAKEParticipant who created/sent this payload.
  22. /// </summary>
  23. private readonly string participantId;
  24. /// <summary>
  25. /// The value of g^x1
  26. /// </summary>
  27. private readonly BigInteger gx1;
  28. /// <summary>
  29. /// The value of g^x2
  30. /// </summary>
  31. private readonly BigInteger gx2;
  32. /// <summary>
  33. /// The zero knowledge proof for x1.
  34. ///
  35. /// This is a two element array, containing {g^v, r} for x1.
  36. /// </summary>
  37. private readonly BigInteger[] knowledgeProofForX1;
  38. /// <summary>
  39. /// The zero knowledge proof for x2.
  40. ///
  41. /// This is a two element array, containing {g^v, r} for x2.
  42. /// </summary>
  43. private readonly BigInteger[] knowledgeProofForX2;
  44. public JPakeRound1Payload(string participantId, BigInteger gx1, BigInteger gx2, BigInteger[] knowledgeProofForX1, BigInteger[] knowledgeProofForX2)
  45. {
  46. JPakeUtilities.ValidateNotNull(participantId, "participantId");
  47. JPakeUtilities.ValidateNotNull(gx1, "gx1");
  48. JPakeUtilities.ValidateNotNull(gx2, "gx2");
  49. JPakeUtilities.ValidateNotNull(knowledgeProofForX1, "knowledgeProofForX1");
  50. JPakeUtilities.ValidateNotNull(knowledgeProofForX2, "knowledgeProofForX2");
  51. this.participantId = participantId;
  52. this.gx1 = gx1;
  53. this.gx2 = gx2;
  54. this.knowledgeProofForX1 = new BigInteger[knowledgeProofForX1.Length];
  55. Array.Copy(knowledgeProofForX1, this.knowledgeProofForX1, knowledgeProofForX1.Length);
  56. this.knowledgeProofForX2 = new BigInteger[knowledgeProofForX2.Length];
  57. Array.Copy(knowledgeProofForX2, this.knowledgeProofForX2, knowledgeProofForX2.Length);
  58. }
  59. public virtual string ParticipantId
  60. {
  61. get { return participantId; }
  62. }
  63. public virtual BigInteger Gx1
  64. {
  65. get { return gx1; }
  66. }
  67. public virtual BigInteger Gx2
  68. {
  69. get { return gx2; }
  70. }
  71. public virtual BigInteger[] KnowledgeProofForX1
  72. {
  73. get
  74. {
  75. BigInteger[] kp = new BigInteger[knowledgeProofForX1.Length];
  76. Array.Copy(knowledgeProofForX1, kp, knowledgeProofForX1.Length);
  77. return kp;
  78. }
  79. }
  80. public virtual BigInteger[] KnowledgeProofForX2
  81. {
  82. get
  83. {
  84. BigInteger[] kp = new BigInteger[knowledgeProofForX2.Length];
  85. Array.Copy(knowledgeProofForX2, kp, knowledgeProofForX2.Length);
  86. return kp;
  87. }
  88. }
  89. }
  90. }
  91. #pragma warning restore
  92. #endif