public PublicKey(string hex) { byte[] data = StrUtils.HexToBytes(hex); CompressedRistretto compressed = new CompressedRistretto(data); this.Key = compressed.Decompress(); }
public KeyPair(RNGCryptoServiceProvider rng) { byte[] b = new byte[64]; rng.GetBytes(b); this.PrivateKey = Scalar.FromBytesModOrderWide(b); this.PublicKey = Constants.RISTRETTO_GENERATOR.Multiply(this.PrivateKey); }
static Scalar HashMessage(RistrettoElement point, byte[] data) { try { using var sha = SHA512.Create(); sha.Initialize(); var combined = point.Compress().ToByteArray().Concat(data).ToArray(); byte[] hashed = sha.ComputeHash(combined); return(Scalar.FromBytesModOrderWide(hashed)); } catch (Exception e) { Console.WriteLine(e.StackTrace); } return(null); }
/// <summary> /// checks that a signature is valid for a set of public keys and messages /// </summary> /// <param name="publicKeys"></param> /// <param name="messages"></param> /// <returns></returns> public Either <Error, Void> Verify(IList <RistrettoElement> publicKeys, IList <byte[]> messages) { if (!(publicKeys.Count() == messages.Count() && publicKeys.Count() == this.Parameters.Count())) { return(new Either <Error, Void>(new InvalidFormat())); } RistrettoElement zP = Constants.RISTRETTO_GENERATOR.Multiply(this.Z); RistrettoElement eiXi = RistrettoElement.IDENTITY; for (int i = 0; i < publicKeys.Count(); i++) { Scalar e = HashMessage(publicKeys[i], messages[i]); eiXi = eiXi.Add(publicKeys[i].Multiply(e)); } RistrettoElement diAi = RistrettoElement.IDENTITY; foreach (RistrettoElement item in Parameters) { List <RistrettoElement> ristrettoElements = new List <RistrettoElement> { item }; Scalar d = HashPoints(ristrettoElements); diAi = diAi.Add(item.Multiply(d)); } RistrettoElement res = zP.Add(eiXi).Subtract(diAi); if (res.Equals(RistrettoElement.IDENTITY)) { return(new Right(null)); } else { return(new InvalidSignature()); } }
public PublicKey(byte[] data) { CompressedRistretto compressed = new CompressedRistretto(data); this.Key = compressed.Decompress(); }
public PublicKey(RistrettoElement publicKey) { this.Key = publicKey; }
public KeyPair(byte[] b) { this.PrivateKey = Scalar.FromBytesModOrderWide(b); this.PublicKey = Constants.RISTRETTO_GENERATOR.Multiply(this.PrivateKey); }
public KeyPair(string hex) { byte[] b = StrUtils.HexToBytes(hex); this.PrivateKey = Scalar.FromBytesModOrder(b); this.PublicKey = Constants.RISTRETTO_GENERATOR.Multiply(this.PrivateKey); }