Improve Transcript API
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
-using System.Collections.Generic;
-using System.Linq;
using System.Text;
-using NBitcoin.Secp256k1;
using WalletWasabi.Crypto.Groups;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Crypto.ZeroKnowledge;
@@ -75,10 +72,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
var publicNonceGenerator3 = transcript3.CreateSyntheticPublicNoncesProvider(witness2, rnd);
var publicNonceGenerator4 = transcript4.CreateSyntheticPublicNoncesProvider(witness2, rnd);
- var publicNonce1 = publicNonceGenerator1().First();
- var publicNonce2 = publicNonceGenerator2().First();
- var publicNonce3 = publicNonceGenerator3().First();
- var publicNonce4 = publicNonceGenerator4().First();
+ var publicNonce1 = publicNonceGenerator1.GetScalar();
+ var publicNonce2 = publicNonceGenerator2.GetScalar();
+ var publicNonce3 = publicNonceGenerator3.GetScalar();
+ var publicNonce4 = publicNonceGenerator4.GetScalar();
Assert.NotEqual(publicNonce1, publicNonce2);
Assert.NotEqual(publicNonce1, publicNonce3);

ADD
WalletWasabi/Crypto/ZeroKnowledge/SyntheticPublicNoncesProvider.cs
+using NBitcoin.Secp256k1;
+using System.Collections.Generic;
+using System.Linq;
+using WalletWasabi.Crypto.Randomness;
+using WalletWasabi.Crypto.StrobeProtocol;
+
+namespace WalletWasabi.Crypto.ZeroKnowledge
+{
+ public class SyntheticPublicNoncesProvider
+ {
+ private readonly Strobe128 _strobe;
+
+ public SyntheticPublicNoncesProvider(Strobe128 strobe, IEnumerable<Scalar> secrets, WasabiRandom random)
+ {
+ _strobe = strobe;
+
+ // add secret inputs as key material
+ foreach (var secret in secrets)
+ {
+ _strobe.Key(secret.ToBytes(), false);
+ }
+
+ _strobe.Key(random.GetBytes(32), false);
+ }
+
+ public IEnumerable<Scalar> Sequence()
+ {
+ while (true)
+ {
+ yield return new Scalar(_strobe.Prf(32, false));
+ }
+ }
+
+ public Scalar GetScalar() =>
+ Sequence().First();
+
+ public ScalarVector GetScalar(uint len) =>
+ new ScalarVector(Sequence().Take((int)len));
+ }
+}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Transcript.cs
WalletWasabi/Crypto/ZeroKnowledge/Transcript.cs
@@ -9,8 +9,6 @@ using WalletWasabi.Crypto.StrobeProtocol;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public delegate IEnumerable<Scalar> PublicNoncesSequence();
-
// High level API for transcripts of compound Sigma protocol style proofs
// implements synthetic nonces and Fiat-Shamir challenges.
public sealed class Transcript
@@ -51,34 +49,8 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
new Transcript(_strobe.MakeCopy());
// Generate synthetic nonce using current state combined with additional randomness.
- public PublicNoncesSequence CreateSyntheticPublicNoncesProvider(IEnumerable<Scalar> secrets, WasabiRandom random)
- {
- // To integrate prior inputs for deterministic component of nonce
- // generation, first clone the state at the current point in the
- // transcript, which should already have the statement tag and public
- // inputs committed.
- var forked = _strobe.MakeCopy();
-
- // add secret inputs as key material
- foreach (var secret in secrets)
- {
- forked.Key(secret.ToBytes(), false);
- }
-
- // Add additional randomness
- forked.Key(random.GetBytes(KeySizeInBytes), false);
-
- IEnumerable<Scalar> NoncesGenerator()
- {
- while (true)
- {
- yield return new Scalar(forked.Prf(KeySizeInBytes, false));
- }
- }
-
- // Generate a new scalar for each secret using this updated state as a seed.
- return NoncesGenerator;
- }
+ public SyntheticPublicNoncesProvider CreateSyntheticPublicNoncesProvider(IEnumerable<Scalar> secrets, WasabiRandom random)
+ => new SyntheticPublicNoncesProvider(_strobe.MakeCopy(), secrets, random);
public void CommitPublicNonces(IEnumerable<GroupElement> nonces)
{
@@ -86,6 +58,12 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
AddMessages(NonceTag, nonces.Select(x => x.ToBytes()));
}
+ public void CommitStatement(Statement statement)
+ {
+ CryptoGuard.NotNullOrInfinity(nameof(statement.Generators), statement.Generators);
+ AddMessages(StatementTag, statement.Generators.Select(x => x.ToBytes()));
+ }
+
// Generate Fiat Shamir challenges
public Scalar GenerateChallenge()
{

Improve Transcript API