Example #1
0
        /// <summary>
        /// Used by the token verifier. It recreates the initial point from the initiator, signs it, and verifies that they are equal.
        /// </summary>
        /// <param name="k">The private key for the token scheme</param>
        /// <param name="curve">Curve parameters</param>
        /// <param name="t">Seed for the initial point chosen by the initiator</param>
        /// <param name="W">Token received from the initiator</param>
        /// <returns>True if the token is valid, otherwise false</returns>
        public async Task <bool> VerifyTokenAsync(
            BigInteger k,
            ECCurve curve,
            byte[] t,
            ECPoint W)
        {
            // Check if token t is received earlier
            if (await _seedStore.ExistsAsync(t))
            {
                return(false);
            }

            // Check that W is a valid point on the currect curve
            if (ECPointVerifier.PointIsValid(W, curve) == false)
            {
                throw new AnonymousTokensException("W is not a valid point on the curve");
            }

            await _seedStore.SaveAsync(t);

            ECPoint?T = ECCurveHash.HashToWeierstrassCurve(curve, t);

            if (T == null)
            {
                return(false);
            }

            ECPoint?V = T.Multiply(k);

            return(V.Equals(W));
        }
Example #2
0
        /// <summary>
        /// Used by the initiator. Generates an initial point to be submitted to the token service for signing.
        /// </summary>
        /// <param name="curve">Curve parameters</param>
        /// <returns>The seed t for a random point, the initial mask r of the point, and the masked point P</returns>
        public (byte[] t, BigInteger r, ECPoint P) Initiate(ECCurve curve)
        {
            BigInteger r = ECCurveRandomNumberGenerator.GenerateRandomNumber(curve, _random);

            // Sample random bytes t such that x = hash(t) is a valid
            // x-coordinate on the curve. Then T = HashToWeierstrassCurve(t).
            byte[]? t = new byte[32];
            ECPoint?T;

            for (; ;)
            {
                _random.NextBytes(t);
                T = ECCurveHash.HashToWeierstrassCurve(curve, t);
                if (T == null)
                {
                    continue;
                }
                break;
            }

            if (T == null)
            {
                throw new AnonymousTokensException("Point T is null after unsuccessfull hashing");
            }

            // Compute P = r*T
            ECPoint P = T.Multiply(r);

            return(t, r, P);
        }
        public void HashToWeierstrassCurve_tIsNotWithinRangeOfP_ReturnsNull(string randomBigInteger)
        {
            // Arrange
            var x9    = ECNamedCurveTable.GetByName("prime239v1");
            var curve = x9.Curve;

            byte[] t = new BigInteger(randomBigInteger).ToByteArray();

            // Act
            var actual = ECCurveHash.HashToWeierstrassCurve(curve, t);

            // Assert
            Assert.Null(actual);
        }