Skip to content

Commit 0995403

Browse files
authored
Merge pull request #52 from HenrikWM/f-use-point-as-argument2
Changing ECPublicKeyParameters to ECPoint
2 parents 7955ef7 + 051ae07 commit 0995403

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

samples/ClientServer/Client/Client.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static async Task Main(string[] args)
3939
var (Q, proofC, proofZ) = await _tokenApiClient.GenerateTokenAsync(ecParameters.Curve, P);
4040

4141
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
42-
var W = _initiator.RandomiseToken(ecParameters, publicKey, P, Q, proofC, proofZ, r);
42+
var W = _initiator.RandomiseToken(ecParameters, publicKey.Q, P, Q, proofC, proofZ, r);
4343

4444
// 4. Verify that the token (t,W) is correct.
4545
var isVerified = await _tokenApiClient.VerifyTokenAsync(t, W);

src/AnonymousTokens.Client/Protocol/Initiator.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public interface IInitiator
1414
public (byte[] t, BigInteger r, ECPoint P) Initiate(ECCurve curve);
1515
public bool VerifyProof(
1616
X9ECParameters ecParameters,
17-
ECPublicKeyParameters K,
17+
ECPoint K,
1818
ECPoint P,
1919
ECPoint Q,
2020
BigInteger c,
2121
BigInteger z);
2222
public ECPoint RandomiseToken(
2323
X9ECParameters ecParameters,
24-
ECPublicKeyParameters K,
24+
ECPoint K,
2525
ECPoint P,
2626
ECPoint Q,
2727
BigInteger c,
@@ -72,36 +72,36 @@ public Initiator()
7272
/// Used by the initiator. Verifies a transcript of a Chaum-Pedersen protocol instance, using the strong Fiat-Shamir transform.
7373
/// </summary>
7474
/// <param name="ecParameters">Curve parameters</param>
75-
/// <param name="K">The public key parameters for the token scheme</param>
75+
/// <param name="K">The public key point for the token scheme</param>
7676
/// <param name="P">Point initially submitted by the initiator</param>
7777
/// <param name="Q">Point received from the token service</param>
7878
/// <param name="c">Claimed challenge from the Chaum-Pedersen proof</param>
7979
/// <param name="z">Response from the Chaum-Pedersen proof</param>
8080
/// <returns>Returns true if the proof is valid and otherwise returns false</returns>
81-
public bool VerifyProof(X9ECParameters ecParameters, ECPublicKeyParameters K, ECPoint P, ECPoint Q, BigInteger c, BigInteger z)
81+
public bool VerifyProof(X9ECParameters ecParameters, ECPoint K, ECPoint P, ECPoint Q, BigInteger c, BigInteger z)
8282
{
8383
// Compute X = z*G + c*K = r*G
84-
ECPoint? X = ecParameters.G.Multiply(z).Add(K.Q.Multiply(c));
84+
ECPoint? X = ecParameters.G.Multiply(z).Add(K.Multiply(c));
8585

8686
// Compute Y = z*P + c*Q = r*P
8787
ECPoint? Y = P.Multiply(z).Add(Q.Multiply(c));
8888

8989
// Returns true if the challenge from the proof equals the new challenge
90-
return c.Equals(CPChallengeGenerator.CreateChallenge(ecParameters.G, P, K.Q, Q, X, Y));
90+
return c.Equals(CPChallengeGenerator.CreateChallenge(ecParameters.G, P, K, Q, X, Y));
9191
}
9292

9393
/// <summary>
9494
/// Used by the initiator. It first verifies that the incoming token is well-formed, and then removes the previously applied mask.
9595
/// </summary>
9696
/// <param name="ecParameters">Curve parameters</param>
97-
/// <param name="K">The public key parameters for the token scheme</param>
97+
/// <param name="K">The public key point for the token scheme</param>
9898
/// <param name="P">Masked point initially submitted to the token service</param>
9999
/// <param name="Q">Signed masked point returned from the token service</param>
100100
/// <param name="c">Claimed challenge from the Chaum-Pedersen proof</param>
101101
/// <param name="z">Response from the Chaum-Pedersen proof</param>
102102
/// <param name="r">Masking of the initial point</param>
103103
/// <returns>A randomised signature W on the point chosen by the initiator</returns>
104-
public ECPoint RandomiseToken(X9ECParameters ecParameters, ECPublicKeyParameters K, ECPoint P, ECPoint Q, BigInteger c, BigInteger z, BigInteger r)
104+
public ECPoint RandomiseToken(X9ECParameters ecParameters, ECPoint K, ECPoint P, ECPoint Q, BigInteger c, BigInteger z, BigInteger r)
105105
{
106106
ECCurve? curve = ecParameters.Curve;
107107

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1919
<Deterministic>true</Deterministic>
2020
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
21-
<Version>1.4.1</Version>
21+
<Version>2.0.0</Version>
2222
<RepositoryUrl>https://github.com/HenrikWM/anonymous-tokens</RepositoryUrl>
2323
<RepositoryType>git</RepositoryType>
2424
<LangVersion>latest</LangVersion>

test/AnonymousTokens.Benchmarks/Protocol.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void RunProtocolEndToEnd()
7373
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_privateKey, _publicKey.Q, _ecParameters, P);
7474

7575
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
76-
var W = _initiator.RandomiseToken(_ecParameters, _publicKey, P, Q, proofC, proofZ, r);
76+
var W = _initiator.RandomiseToken(_ecParameters, _publicKey.Q, P, Q, proofC, proofZ, r);
7777

7878
// 4. Verify that the token (t,W) is correct.
7979
var isVerified = _tokenVerifier.VerifyTokenAsync(_privateKey, _ecParameters.Curve, t, W).GetAwaiter().GetResult();
@@ -96,7 +96,7 @@ public void RunProtocolEndToEnd_WithGeneratedKeysAsync()
9696
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_privateKeyGenerated, _publicKeyGenerated.Q, _ecParameters, P);
9797

9898
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
99-
var W = _initiator.RandomiseToken(_ecParameters, _publicKeyGenerated, P, Q, proofC, proofZ, r);
99+
var W = _initiator.RandomiseToken(_ecParameters, _publicKeyGenerated.Q, P, Q, proofC, proofZ, r);
100100

101101
// 4. Verify that the token (t,W) is correct.
102102
var isVerified = _tokenVerifier.VerifyTokenAsync(_privateKeyGenerated, _ecParameters.Curve, t, W).GetAwaiter().GetResult();

test/AnonymousTokens.UnitTests/IntegrationTests/ProtocolTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async void Run()
5454
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_privateKey, _publicKey.Q, _ecParameters, P);
5555

5656
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
57-
var W = _initiator.RandomiseToken(_ecParameters, _publicKey, P, Q, proofC, proofZ, r);
57+
var W = _initiator.RandomiseToken(_ecParameters, _publicKey.Q, P, Q, proofC, proofZ, r);
5858

5959
// 4. Verify that the token (t,W) is correct.
6060
var isVerified = await _tokenVerifier.VerifyTokenAsync(_privateKey, _ecParameters.Curve, t, W);
@@ -77,7 +77,7 @@ public async void Run_FailWhenSeedIsReplayed()
7777
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_privateKey, _publicKey.Q, _ecParameters, P);
7878

7979
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
80-
var W = _initiator.RandomiseToken(_ecParameters, _publicKey, P, Q, proofC, proofZ, r);
80+
var W = _initiator.RandomiseToken(_ecParameters, _publicKey.Q, P, Q, proofC, proofZ, r);
8181

8282
// 4. Verify that the token (t,W) is correct.
8383
var isVerified = await _tokenVerifier.VerifyTokenAsync(_privateKey, _ecParameters.Curve, t, W);
@@ -107,7 +107,7 @@ public void Run_FailWhenKeysDontMatch()
107107
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_wrongPrivateKey, _publicKey.Q, _ecParameters, P);
108108

109109
// Verify the proof
110-
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey, P, Q, proofC, proofZ);
110+
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey.Q, P, Q, proofC, proofZ);
111111
Assert.False(isValid, "Keys were incorrect and the proof did not get verified");
112112
}
113113

@@ -127,7 +127,7 @@ public void Run_FailWhenTokenIsMalformed()
127127
var changedQ = Q.Twice();
128128

129129
// Try randomising the token
130-
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey, P, changedQ, proofC, proofZ);
130+
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey.Q, P, changedQ, proofC, proofZ);
131131
Assert.False(isValid, "The token was malformed and the proof did not get verified");
132132
}
133133

@@ -147,7 +147,7 @@ public void Run_FailWhenChallengeIsWrong()
147147
var changedC = proofC.Add(BigInteger.One);
148148

149149
// Try randomising the token
150-
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey, P, Q, changedC, proofZ);
150+
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey.Q, P, Q, changedC, proofZ);
151151
Assert.False(isValid, "The challenge was changed and the proof did not get verified");
152152
}
153153

@@ -167,7 +167,7 @@ public void Run_FailWhenResponseIsWrong()
167167
var changedZ = proofZ.Add(BigInteger.One);
168168

169169
// Try randomising the token
170-
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey, P, Q, proofC, changedZ);
170+
var isValid = _initiator.VerifyProof(_ecParameters, _publicKey.Q, P, Q, proofC, changedZ);
171171
Assert.False(isValid, "The response was changed and the proof did not get verified");
172172
}
173173

@@ -207,7 +207,7 @@ public async void Run_FailWhenWIsInvalid()
207207
var (Q, proofC, proofZ) = _tokenGenerator.GenerateToken(_privateKey, _publicKey.Q, _ecParameters, P);
208208

209209
// 3. Randomise the token Q, by removing the mask r: W = (1/r)*Q = k*T. Also checks that proof (c,z) is correct.
210-
var W = _initiator.RandomiseToken(_ecParameters, _publicKey, P, Q, proofC, proofZ, r);
210+
var W = _initiator.RandomiseToken(_ecParameters, _publicKey.Q, P, Q, proofC, proofZ, r);
211211

212212
// Create a new point with invalid coordinates
213213
var invalidW = _ecParameters.Curve.CreatePoint(W.XCoord.ToBigInteger().Add(BigInteger.One), W.YCoord.ToBigInteger());

0 commit comments

Comments
 (0)