Example #1
0
        /// <summary>
        /// Creates a range proof that compares a UProve attribute to a target date.
        /// Target attribute MUST NOT be hashed.
        /// Value MUST be generated via RangeProofParameterFactory.EncodeYearAndDayAsUProveAttribute.
        /// </summary>
        /// <param name="prover">Token information.</param>
        /// <param name="attributeIndexForProver">1-based index of target attribute.</param>
        /// <param name="proofType">Range proof type</param>
        /// <param name="targetDate">Compare token attribute to this date.  (Time component is ignored).</param>
        /// <param name="minYear">Minimum year for attribute and target date.</param>
        /// <param name="maxYear">Maximum year for attribute and target date.</param>
        public RangeProof(
            ProverPresentationProtocolParameters prover,
            int attributeIndexForProver,
            VerifierRangeProofParameters.ProofType proofType,
            DateTime targetDate,
            int minYear,
            int maxYear)
        {
            // make sure target attribute is not hashed
            if (prover.IP.E[attributeIndexForProver - 1] == 0x01)
            {
                throw new ArgumentException("UProve attributes used in Range Proof must not be hashed.");
            }

            // generate Pedersen Commitments to token attribute
            ProverPresentationProtocolParameters[] provers = new ProverPresentationProtocolParameters[] { prover };
            int[] attributeIndices = new int[] { attributeIndexForProver };
            PedersenCommitment[] attributeCommitments = PedersenCommitment.PedersenCommmitmentsToAttributes(provers, attributeIndices);

            // create range proof
            ProverRangeProofParameters rangeProver = RangeProofParameterFactory.GetDateTimeProverParameters(
                new CryptoParameters(prover.IP),
                attributeCommitments[0],
                proofType,
                targetDate,
                minYear,
                maxYear);

            ConstructorHelper(rangeProver);

            // Add UProve Integration proof
            this.UPIProof = new UProveIntegrationProof(provers, attributeIndices, attributeCommitments);
            this.UPIProof.IsGroupSerializable = false;
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="verifier"></param>
        /// <param name="attributeIndexForVerifier"></param>
        /// <param name="proofType"></param>
        /// <param name="targetDate"></param>
        /// <param name="minYear"></param>
        /// <param name="maxYear"></param>
        /// <returns></returns>
        public bool Verify(
            VerifierPresentationProtocolParameters verifier,
            int attributeIndexForVerifier,
            VerifierRangeProofParameters.ProofType proofType,
            DateTime targetDate,
            int minYear,
            int maxYear)

        {
            // Verify target attribute is not hashed
            if (verifier.IP.E[attributeIndexForVerifier - 1] == 0x01)
            {
                return(false);
            }


            // Verify UProve Integration Proof
            if (this.UPIProof == null)
            {
                return(false);
            }
            VerifierPresentationProtocolParameters[] verifiers = new VerifierPresentationProtocolParameters[1] {
                verifier
            };
            int[] attributeIndices = new int[1] {
                attributeIndexForVerifier
            };
            if (!this.UPIProof.Verify(verifiers, attributeIndices))
            {
                return(false);
            }

            // Verify Range Proof
            VerifierRangeProofParameters rangeVerifier = RangeProofParameterFactory.GetDateTimeVerifierParameters(
                new CryptoParameters(verifier.IP),
                this.UPIProof.PedersenCommitmentValues[0],
                proofType,
                targetDate,
                minYear,
                maxYear);

            return(this.Verify(rangeVerifier));
        }
Example #3
0
        public static byte[] EncodeYearAndDayAsUProveAttribute(DateTime date, int minYear)
        {
            int encodedDate = RangeProofParameterFactory.EncodeYearAndDay(date, minYear);

            return(RangeProofParameterFactory.EncodeIntAsUProveAttribute(encodedDate));
        }