コード例 #1
0
        public void ShouldVerifyRandomlyGeneratedSignatures(ModeValues mode, DigestSizes digest, Curve curveEnum)
        {
            var nonces = new List <BigInteger>();

            var hashFunction = new HashFunction(mode, digest);
            var shaFactory   = new NativeShaFactory();
            var sha          = shaFactory.GetShaInstance(hashFunction);
            var hmacFactory  = new HmacFactory(shaFactory);
            var hmac         = hmacFactory.GetHmacInstance(hashFunction);

            var subject = new EccDsa(sha, new DeterministicNonceProvider(hmac), EntropyProviderTypes.Random);

            var curveFactory = new EccCurveFactory();
            var curve        = curveFactory.GetCurve(curveEnum);
            var domainParams = new EccDomainParameters(curve);
            var key          = subject.GenerateKeyPair(domainParams).KeyPair;

            var rand = new Random800_90();

            for (var i = 0; i < 100; i++)
            {
                var message = rand.GetRandomBitString(1024);

                var signature = subject.Sign(domainParams, key, message).Signature;
                var verify    = subject.Verify(domainParams, key, message, signature);

                nonces.Add(signature.R);

                Assert.IsTrue(verify.Success, verify.ErrorMessage);
            }

            // Check nonces for uniqueness
            Assert.AreEqual(nonces.Count, nonces.Distinct().Count(), "Repeated nonce detected");
        }
コード例 #2
0
ファイル: EccMqvTests.cs プロジェクト: usnistgov/ACVP-Server
        public void ShouldComputeCorrectZ(
            string label,
            Curve curveEnum,
            EccKeyPair sPartyA,
            EccKeyPair ePartyA,
            EccKeyPair sPartyB,
            EccKeyPair ePartyB,
            BitString expectedZ)
        {
            var curve = _curveFactory.GetCurve(curveEnum);

            EccDomainParameters dp = new EccDomainParameters(curve);

            var result = _subject.GenerateSharedSecretZ(
                dp,
                sPartyA,
                sPartyB,
                ePartyA,
                ePartyA,
                ePartyB
                );

            Assert.That(result.Success);
            Assert.AreEqual(expectedZ, result.SharedSecretZ);
        }