/// <summary> /// Creates and returns the payload to send to the other participant during round 1. /// /// After execution, the State state} will be STATE_ROUND_1_CREATED}. /// </summary> public virtual JPakeRound1Payload CreateRound1PayloadToSend() { if (this.state >= STATE_ROUND_1_CREATED) { throw new InvalidOperationException("Round 1 payload already created for " + this.participantId); } this.x1 = JPakeUtilities.GenerateX1(q, random); this.x2 = JPakeUtilities.GenerateX2(q, random); this.gx1 = JPakeUtilities.CalculateGx(p, g, x1); this.gx2 = JPakeUtilities.CalculateGx(p, g, x2); BigInteger[] knowledgeProofForX1 = JPakeUtilities.CalculateZeroKnowledgeProof(p, q, g, gx1, x1, participantId, digest, random); BigInteger[] knowledgeProofForX2 = JPakeUtilities.CalculateZeroKnowledgeProof(p, q, g, gx2, x2, participantId, digest, random); this.state = STATE_ROUND_1_CREATED; return(new JPakeRound1Payload(participantId, gx1, gx2, knowledgeProofForX1, knowledgeProofForX2)); }
/// <summary> /// Creates and returns the payload to send to the other participant during round 2. /// /// ValidateRound1PayloadReceived(JPakeRound1Payload) must be called prior to this method. /// /// After execution, the State state will be STATE_ROUND_2_CREATED. /// /// Throws InvalidOperationException if called prior to ValidateRound1PayloadReceived(JPakeRound1Payload), or multiple times /// </summary> public virtual JPakeRound2Payload CreateRound2PayloadToSend() { if (this.state >= STATE_ROUND_2_CREATED) { throw new InvalidOperationException("Round 2 payload already created for " + this.participantId); } if (this.state < STATE_ROUND_1_VALIDATED) { throw new InvalidOperationException("Round 1 payload must be validated prior to creating round 2 payload for " + this.participantId); } BigInteger gA = JPakeUtilities.CalculateGA(p, gx1, gx3, gx4); BigInteger s = JPakeUtilities.CalculateS(password); BigInteger x2s = JPakeUtilities.CalculateX2s(q, x2, s); BigInteger A = JPakeUtilities.CalculateA(p, q, gA, x2s); BigInteger[] knowledgeProofForX2s = JPakeUtilities.CalculateZeroKnowledgeProof(p, q, gA, A, x2s, participantId, digest, random); this.state = STATE_ROUND_2_CREATED; return(new JPakeRound2Payload(participantId, A, knowledgeProofForX2s)); }