Operations on vectors
RENAME
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/LinearRelation.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/LinearRelationTests.cs
MODIFY
WalletWasabi/Crypto/Groups/GroupElement.cs
WalletWasabi/Crypto/Groups/GroupElement.cs
@@ -7,7 +7,7 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.Groups
{
- public class GroupElement : IEquatable<GroupElement>
+ public class GroupElement : IEquatable<GroupElement>, IByteSerializable
{
public GroupElement(GE groupElement)
{

ADD
WalletWasabi/Crypto/Groups/IByteSerializable.cs
+namespace WalletWasabi.Crypto.Groups
+{
+ public interface IByteSerializable
+ {
+ byte[] ToBytes();
+ }
+}

MODIFY
WalletWasabi/Crypto/ScalarVector.cs
WalletWasabi/Crypto/ScalarVector.cs
@@ -31,6 +31,22 @@ namespace WalletWasabi.Crypto
return Enumerable.Zip(scalars, groupElements, (s, g) => s * g).Sum();
}
+ public static ScalarVector operator *(Scalar scalar, ScalarVector scalars)
+ {
+ Guard.NotNull(nameof(scalars), scalars);
+
+ return new ScalarVector( scalars.Select(si => scalar * si));
+ }
+
+ public static ScalarVector operator +(ScalarVector scalars1, ScalarVector scalars2)
+ {
+ Guard.NotNull(nameof(scalars1), scalars1);
+ Guard.NotNull(nameof(scalars2), scalars2);
+ Guard.True(nameof(scalars1.Count), scalars1.Count == scalars2.Count);
+
+ return new ScalarVector( Enumerable.Zip(scalars1, scalars2, (s1, s2) => s1 + s2) );
+ }
+
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Equation.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Equation.cs
using NBitcoin.Secp256k1;
using System.Linq;
-using WalletWasabi.Crypto;
using WalletWasabi.Crypto.Groups;
using WalletWasabi.Helpers;
@@ -17,8 +16,9 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
{
public Equation(GroupElement publicPoint, GroupElementVector generators)
{
+ CryptoGuard.NotInfinity(nameof(generators), generators);
PublicPoint = CryptoGuard.NotInfinity(nameof(publicPoint), publicPoint);
- Generators = (GroupElementVector)Guard.NotNullOrEmpty(nameof(generators), generators);
+ Generators = generators;
}
// Knowledge of representation asserts
@@ -50,12 +50,12 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
}
// Given a witness and secret nonces, respond to a challenge proving the equation holds w.r.t the witness
- internal ScalarVector Respond(ScalarVector witness, ScalarVector secretNonces, Scalar challenge)
+ internal ScalarVector Respond(ScalarVector witnesses, ScalarVector secretNonces, Scalar challenge)
{
// By canceling G on both sides of the verification equation above we can
// obtain a formula for the response s given k, e and x:
// s = k + ex
- return new ScalarVector(witness.Zip(secretNonces, (secret, secretNonce) => secretNonce + challenge * secret));
+ return secretNonces + challenge * witnesses;
}
}
}

Operations on vectors