예제 #1
0
        public PublicKey(string hex)
        {
            byte[] data = StrUtils.HexToBytes(hex);
            CompressedRistretto compressed = new CompressedRistretto(data);

            this.Key = compressed.Decompress();
        }
예제 #2
0
 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);
 }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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());
            }
        }
예제 #5
0
        public PublicKey(byte[] data)
        {
            CompressedRistretto compressed = new CompressedRistretto(data);

            this.Key = compressed.Decompress();
        }
예제 #6
0
 public PublicKey(RistrettoElement publicKey)
 {
     this.Key = publicKey;
 }
예제 #7
0
 public KeyPair(byte[] b)
 {
     this.PrivateKey = Scalar.FromBytesModOrderWide(b);
     this.PublicKey  = Constants.RISTRETTO_GENERATOR.Multiply(this.PrivateKey);
 }
예제 #8
0
 public KeyPair(string hex)
 {
     byte[] b = StrUtils.HexToBytes(hex);
     this.PrivateKey = Scalar.FromBytesModOrder(b);
     this.PublicKey  = Constants.RISTRETTO_GENERATOR.Multiply(this.PrivateKey);
 }