Ejemplo n.º 1
0
        private FpPoint MakePoint()
        {
            var rng    = new SecureRandom();
            var phe    = new PheCrypto();
            var swu    = new Swu(phe.Curve.Q, phe.Curve.B.ToBigInteger());
            var random = new byte[Swu.PointHashLen];

            rng.NextBytes(random);
            var(x, y) = swu.HashToPoint(random);
            var xField  = phe.Curve.FromBigInteger(x);
            var yField  = phe.Curve.FromBigInteger(y);
            var ecpoint = phe.Curve.CreatePoint(x, y);

            return((FpPoint)ecpoint);
        }
Ejemplo n.º 2
0
        public void TestPoint_Encoding()
        {
            var rng    = new SecureRandom();
            var phe    = new PheCrypto();
            var swu    = new Swu(phe.Curve.Q, phe.Curve.B.ToBigInteger());
            var random = new byte[Swu.PointHashLen];

            rng.NextBytes(random);
            var(x, y) = swu.HashToPoint(random);
            var xField  = phe.Curve.FromBigInteger(x);
            var yField  = phe.Curve.FromBigInteger(y);
            var ecpoint = phe.Curve.CreatePoint(x, y);

            var encoded = ecpoint.GetEncoded();
            var decoded = phe.Curve.DecodePoint(encoded);

            Assert.Equal(ecpoint, decoded);
        }
Ejemplo n.º 3
0
        public void Should_GeneratePointOnCurve_When_RandomHashesArePassed()
        {
            var curveParams = NistNamedCurves.GetByName("P-256");

            var swu    = new Swu(((FpCurve)curveParams.Curve).Q, curveParams.Curve.B.ToBigInteger());
            var rng    = new SecureRandom();
            var sha    = new Sha512tDigest(256);
            var random = new byte[32];

            for (int i = 0; i <= 10000; i++)
            {
                var hash = new byte[32];

                rng.NextBytes(random);
                sha.BlockUpdate(random, 0, random.Length);
                sha.DoFinal(hash, 0);

                var(x, y) = swu.HashToPoint(hash);
                Assert.True(curveParams.Curve.CreatePoint(x, y).IsValid());

                sha.Reset();
            }
        }