コード例 #1
0
ファイル: FipsKdf.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IBlockResult GetResult(int outputLength)
            {
                IMac md5Hmac  = new HMac(md5Provider.CreateEngine(EngineUsage.GENERAL));
                IMac sha1HMac = FipsShs.CreateHmac(FipsShs.Sha1HMac);

                return(new SimpleBlockResult(PRF_legacy(parameters, outputLength, md5Hmac, sha1HMac)));
            }
コード例 #2
0
ファイル: FipsDsa.cs プロジェクト: NDWX/BouncyCastle.FIPS
            /// <summary>
            /// Generate a new set of DSA domain parameters.
            /// </summary>
            /// <returns>A new set of DSADomainParameters</returns>
            public DsaDomainParameters GenerateDomainParameters()
            {
                if (parameters.P != null)
                {
                    byte[] seed = parameters.GetSeed();
                    if (seed != null && parameters.UsageIndex >= 0)
                    {
                        BigInteger g = DsaParametersGenerator.CalculateGenerator_FIPS186_3_Verifiable(FipsShs.CreateDigest(digestAlgorithm), parameters.P, parameters.Q, seed, parameters.UsageIndex);

                        return(new DsaDomainParameters(parameters.P, parameters.Q, g, new Org.BouncyCastle.Crypto.Asymmetric.DsaValidationParameters(seed, -1, parameters.UsageIndex)));
                    }
                    else
                    {
                        BigInteger g = DsaParametersGenerator.CalculateGenerator_FIPS186_3_Unverifiable(parameters.P, parameters.Q, random);

                        return(new DsaDomainParameters(parameters.P, parameters.Q, g, null));
                    }
                }
                else
                {
                    DsaParametersGenerator pGen = new DsaParametersGenerator(FipsShs.CreateDigest(digestAlgorithm));

                    DsaParameterGenerationParameters dsaGenParameters = new DsaParameterGenerationParameters(
                        parameters.L, parameters.N, parameters.Certainty, random, parameters.UsageIndex);

                    pGen.Init(dsaGenParameters);

                    DsaParameters p = pGen.GenerateParameters();

                    Org.BouncyCastle.Crypto.Internal.Parameters.DsaValidationParameters validationParameters = p.ValidationParameters;

                    return(new DsaDomainParameters(p.P, p.Q, p.G, new Org.BouncyCastle.Crypto.Asymmetric.DsaValidationParameters(validationParameters.GetSeed(), validationParameters.Counter, validationParameters.UsageIndex)));
                }
            }
コード例 #3
0
ファイル: FipsPrfKmg.cs プロジェクト: NDWX/BouncyCastle.FIPS
        public byte[] Generate(byte[] agreed)
        {
            IMac prfMac;

            if (prfAlgorithm == FipsPrfAlgorithm.AesCMac)
            {
                Internal.IBlockCipher aesEng = FipsAes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL);
                aesEng.Init(true, new KeyParameter(salt ?? new byte[16]));

                prfMac = new CMac(aesEng);
                prfMac.Init(null);
            }
            else
            {
                prfMac = FipsShs.CreateHmac((DigestAlgorithm)prfAlgorithm.BaseAlgorithm);
                prfMac.Init(new KeyParameter(salt ?? new byte[((HMac)prfMac).GetUnderlyingDigest().GetByteLength()]));
            }

            byte[] mac = Macs.DoFinal(prfMac, agreed, 0, agreed.Length);

            // ZEROIZE
            Arrays.Fill(agreed, (byte)0);

            return(mac);
        }
コード例 #4
0
            public ISigner CreateEngine(EngineUsage usage)
            {
                ISigner sig = new PssSigner(ENGINE_PROVIDER.CreateEngine(usage), FipsShs.CreateDigest(parameters.DigestAlgorithm), parameters.SaltLength, parameters.GetSalt());

                sig.Init((usage == EngineUsage.SIGNING), sigParams);

                return(sig);
            }
コード例 #5
0
ファイル: FipsDsa.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public ISigner CreateEngine(EngineUsage usage)
            {
                ISigner sig = new DsaDigestSigner(new DsaSigner(), FipsShs.CreateDigest(parameters.DigestAlgorithm));

                sig.Init((usage == EngineUsage.SIGNING), sigParams);

                return(sig);
            }
コード例 #6
0
ファイル: FipsDrbg.cs プロジェクト: NDWX/BouncyCastle.FIPS
 internal HMacDRBGProvider(FipsDigestAlgorithm algorithm, byte[] nonce, byte[] personalizationString, int securityStrength, byte[] primaryAdditionalInput)
 {
     CryptoStatus.IsReady();
     this.hMac  = FipsShs.CreateHmac(algorithm);
     this.nonce = nonce;
     this.personalizationString  = personalizationString;
     this.securityStrength       = securityStrength;
     this.primaryAdditionalInput = primaryAdditionalInput;
 }
コード例 #7
0
ファイル: FipsPbkd.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IPasswordBasedDeriver <Parameters> Build()
            {
                Parameters parameters = new Parameters(digestAlgorithm, converter, password, iterationCount, salt);

                Pkcs5S2ParametersGenerator gen = new Pkcs5S2ParametersGenerator(FipsShs.CreateHmac(parameters.Prf));

                gen.Init(parameters.Password, parameters.Salt, parameters.IterationCount);

                return(new PasswordBasedDeriver <Parameters>(parameters, gen));
            }
コード例 #8
0
ファイル: FipsKdf.cs プロジェクト: NDWX/BouncyCastle.FIPS
        private static byte[] PRF(TlsKdfWithPrfParameters parameters, int size)
        {
            byte[] label     = Strings.ToByteArray(parameters.Label);
            byte[] labelSeed = Arrays.Concatenate(label, parameters.SeedMaterial);

            IMac prfMac = FipsShs.CreateHmac(parameters.Prf);

            byte[] buf = new byte[size];
            hmac_hash(prfMac, parameters.Secret, labelSeed, buf);
            return(buf);
        }
コード例 #9
0
            public ISigner CreateEngine(EngineUsage usage)
            {
                ISigner sig;

                if (parameters.Algorithm.Mode == AlgorithmMode.PKCSv1_5)
                {
                    sig = new RsaDigestSigner(ENGINE_PROVIDER.CreateEngine(usage), FipsShs.CreateDigest(parameters.DigestAlgorithm));
                }
                else
                {
                    sig = new X931Signer(ENGINE_PROVIDER.CreateEngine(usage), FipsShs.CreateDigest(parameters.DigestAlgorithm), false);
                }

                sig.Init((usage == EngineUsage.SIGNING), sigParams);

                return(sig);
            }
コード例 #10
0
ファイル: FipsKdf.cs プロジェクト: NDWX/BouncyCastle.FIPS
            public IKdfCalculator <AgreementKdfParameters> From(byte[] shared)
            {
                AgreementKdfParameters parameters = new AgreementKdfParameters(new FipsKdfAlgorithm(algorithm, prf), shared, iv);

                if (parameters.Algorithm.Kdf == X963.Algorithm)
                {
                    IDerivationFunction df = new Kdf2BytesGenerator(FipsShs.CreateDigest((FipsDigestAlgorithm)parameters.Prf.BaseAlgorithm));

                    df.Init(new KdfParameters(parameters.GetShared(), parameters.GetIV()));

                    return(new AgreementKdfCalculator(parameters, df));
                }
                else
                {
                    IDerivationFunction df = new ConcatenationKdfGenerator(FipsShs.CreateDigest((FipsDigestAlgorithm)parameters.Prf.BaseAlgorithm));

                    df.Init(new KdfParameters(parameters.GetShared(), parameters.GetIV()));

                    return(new AgreementKdfCalculator(parameters, df));
                }
            }
コード例 #11
0
ファイル: FipsDsa.cs プロジェクト: NDWX/BouncyCastle.FIPS
            /// <summary>
            /// Do a full validation of g against p and q by including the seed and index
            /// associated with g's related parameters.
            /// </summary>
            /// <param name="p">The prime P.</param>
            /// <param name="q">The prime Q.</param>
            /// <param name="seed">The domain parameter seed used to generate p and q.</param>
            /// <param name="index">The 8 bit usage index for G.</param>
            /// <param name="g">The generator G associated with P and Q.</param>
            /// <returns>true if the generator is valid, false otherwise.</returns>
            public bool IsValidG(BigInteger p, BigInteger q, byte[] seed, byte index, BigInteger g)
            {
                IDigest hash = FipsShs.CreateDigest(digestAlgorithm);

                if (BigInteger.Two.CompareTo(g) > 0 || p.Subtract(BigInteger.One).CompareTo(g) < 0)
                {
                    return(false);
                }

                if (!g.ModPow(q, p).Equals(BigInteger.One))
                {
                    return(false);
                }

                BigInteger e     = p.Subtract(BigInteger.One).Divide(q);
                int        count = 0;

                byte[] counter = new byte[3];
                counter[0] = index;
                byte[] U = Arrays.ConcatenateAll(seed, Hex.Decode("6767656E"), counter);

                BigInteger computed_g = null;

                // in our case the wrap check for count terminates at it's largest value.
                while (++count < (1 << 16))
                {
                    Inc(U);

                    computed_g = Digest(hash, U).ModPow(e, p);

                    if (computed_g.CompareTo(BigInteger.One) <= 0)
                    {
                        continue;
                    }

                    break;
                }

                return(g.Equals(computed_g));
            }
コード例 #12
0
 public byte[] Generate(byte[] agreed)
 {
     return(Digests.DoFinal(FipsShs.CreateDigest(digestAlg), agreed, 0, agreed.Length));
 }
コード例 #13
0
ファイル: FipsEC.cs プロジェクト: NDWX/BouncyCastle.FIPS
 private static IDigest CreateDigest(DigestAlgorithm digestAlg)
 {
     return(digestAlg == null ? new NullDigest() : FipsShs.CreateDigest(digestAlg));
 }
コード例 #14
0
            internal override void Evaluate()
            {
                RsaDigestSigner signer = new RsaDigestSigner(provider.CreateEngine(EngineUsage.GENERAL), FipsShs.CreateDigest(FipsShs.Sha256));

                signer.Init(false, new RsaKeyParameters(false, katM, katE));

                signer.BlockUpdate(msg, 0, msg.Length);

                if (!signer.VerifySignature(FipsKats.Values[FipsKats.Vec.RsaStartupVerifySig]))
                {
                    Fail("self test signature verify failed.");
                }

                signer.Init(true, new ParametersWithRandom(testPrivKey, Utils.testRandom));

                signer.BlockUpdate(msg, 0, msg.Length);

                byte[] sig = signer.GenerateSignature();

                if (!Arrays.AreEqual(FipsKats.Values[FipsKats.Vec.RsaStartupResultSig], sig))
                {
                    Fail("self test signature generate failed.");
                }
            }
コード例 #15
0
ファイル: FipsDsa.cs プロジェクト: NDWX/BouncyCastle.FIPS
            /// <summary>
            /// Validate P and Q against the passed in seed and counter.
            /// </summary>
            /// <param name="p">The prime P.</param>
            /// <param name="q">The prime Q.</param>
            /// <param name="seed">The seed P and Q were derived from.</param>
            /// <param name="counter">The number of iterations required to derive P.</param>
            /// <returns>true if the P and Q values are the expected ones, false otherwise.</returns>
            public bool IsValidPAndQ(BigInteger p, BigInteger q, byte[] seed, int counter)
            {
                IDigest hash = FipsShs.CreateDigest(digestAlgorithm);

                if (Version.FipsPub186_2 == version)
                {
                    if (p.BitLength != 1024 || q.BitLength != 160 || counter > 4095)
                    {
                        return(false);
                    }

                    if (seed.Length < 20)
                    {
                        return(false);
                    }

                    BigInteger computed_q = Digest(hash, seed).Xor(Digest(hash, SeedPlus1(seed)));

                    computed_q = computed_q.SetBit(0).SetBit(159);

                    if (!q.Equals(computed_q) || !IsProbablePrime(q, getMinimumIterations(1024)))
                    {
                        return(false);
                    }

                    BigInteger extra = BigInteger.One.ShiftLeft(64);

                    int    i      = 0;
                    byte[] offset = Arrays.Clone(seed);
                    Inc(offset);

                    bool       computedPIsPrime = false;
                    BigInteger computed_p       = null;
                    while (i <= counter)
                    {
                        BigInteger W = BigInteger.Zero;
                        for (int j = 0; j <= 5; j++)
                        {
                            Inc(offset);
                            W = W.Add(Digest(hash, offset).ShiftLeft(160 * j));
                        }
                        // (V[6] mod 2**63) * 2**960
                        Inc(offset);
                        W = W.Add(
                            Digest(hash, offset).Mod(extra).ShiftLeft(160 * 6));

                        BigInteger X = W.SetBit(1023);
                        BigInteger c = X.Mod(q.ShiftLeft(1));

                        computed_p = X.Subtract(c.Subtract(BigInteger.One));

                        if (computed_p.BitLength == 1024)
                        {
                            if (IsProbablePrime(computed_p, getMinimumIterations(1024)))
                            {
                                computedPIsPrime = true;
                                break;
                            }
                        }
                        i++;
                    }

                    if (i != counter || !p.Equals(computed_p) || !computedPIsPrime)
                    {
                        return(false);
                    }
                }
                else
                {
                    int L = p.BitLength;
                    int N = q.BitLength;

                    if (!(L == 1024 && N == 160) &&
                        !(L == 2048 && N == 224) &&
                        !(L == 2048 && N == 256) &&
                        !(L == 3072 && N == 256))
                    {
                        return(false);
                    }

                    if (counter > (4 * L - 1))
                    {
                        return(false);
                    }

                    if (seed.Length * 8 < N)
                    {
                        return(false);
                    }

                    BigInteger twoPowNminus1 = BigInteger.One.ShiftLeft(N - 1);
                    BigInteger U             = Digest(hash, seed).Mod(twoPowNminus1);

                    BigInteger computed_q = U.SetBit(0).SetBit(N - 1);

                    if (!q.Equals(computed_q) || !IsProbablePrime(q, getMinimumIterations(L)))
                    {
                        return(false);
                    }

                    int outlen = hash.GetDigestSize() * 8;

                    int        n     = (L + outlen - 1) / outlen - 1;
                    int        b     = L - (n * outlen);
                    BigInteger extra = BigInteger.One.ShiftLeft(b);

                    int    i      = 0;
                    byte[] offset = Arrays.Clone(seed);

                    bool       computedPIsPrime = false;
                    BigInteger computed_p       = null;

                    while (i <= counter)
                    {
                        BigInteger W = BigInteger.Zero;
                        for (int j = 0; j < n; j++)
                        {
                            Inc(offset);
                            W = W.Add(Digest(hash, offset).ShiftLeft(outlen * j));
                        }

                        Inc(offset);
                        W = W.Add(Digest(hash, offset).Mod(extra).ShiftLeft(outlen * n));

                        BigInteger X = W.SetBit(L - 1);
                        BigInteger c = X.Mod(q.ShiftLeft(1));

                        computed_p = X.Subtract(c.Subtract(BigInteger.One));

                        if (computed_p.BitLength == L)
                        {
                            if (IsProbablePrime(computed_p, getMinimumIterations(L)))
                            {
                                computedPIsPrime = true;
                                break;
                            }
                        }
                        i++;
                    }

                    if (i != counter || !p.Equals(computed_p) || !computedPIsPrime)
                    {
                        return(false);
                    }
                }

                return(true);
            }
コード例 #16
0
ファイル: FipsDrbg.cs プロジェクト: NDWX/BouncyCastle.FIPS
 private static void DrbgStartUpTest()
 {
     SelfTestExecutor.Validate(
         Sha1.Algorithm, new DRBGHashSelfTest(Sha1.Algorithm,
                                              new DRBGTestVector(
                                                  FipsShs.CreateDigest(FipsShs.Sha1),
                                                  new KatEntropyProvider().Get(440),
                                                  true,
                                                  "2021222324",
                                                  128,
                                                  new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha1_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha1_B]
     })
                                              .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha224.Algorithm, new DRBGHashSelfTest(Sha224.Algorithm,
                                                new DRBGTestVector(
                                                    FipsShs.CreateDigest(FipsShs.Sha224),
                                                    new KatEntropyProvider().Get(440),
                                                    true,
                                                    "2021222324",
                                                    192,
                                                    new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha224_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha224_B]
     })
                                                .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha256.Algorithm, new DRBGHashSelfTest(Sha256.Algorithm,
                                                new DRBGTestVector(
                                                    FipsShs.CreateDigest(FipsShs.Sha256),
                                                    new KatEntropyProvider().Get(440),
                                                    true,
                                                    "2021222324",
                                                    256,
                                                    new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha256_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha256_B]
     })
                                                .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha384.Algorithm, new DRBGHashSelfTest(Sha384.Algorithm,
                                                new DRBGTestVector(
                                                    FipsShs.CreateDigest(FipsShs.Sha384),
                                                    new KatEntropyProvider().Get(440),
                                                    true,
                                                    "2021222324",
                                                    256,
                                                    new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha384_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha384_B]
     })
                                                .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512.Algorithm, new DRBGHashSelfTest(Sha512.Algorithm,
                                                new DRBGTestVector(
                                                    FipsShs.CreateDigest(FipsShs.Sha512),
                                                    new KatEntropyProvider().Get(440),
                                                    true,
                                                    "2021222324",
                                                    256,
                                                    new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha512_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha512_B]
     })
                                                .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512_224.Algorithm, new DRBGHashSelfTest(Sha512_224.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha512_224),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        192,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha512_224_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha512_224_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512_256.Algorithm, new DRBGHashSelfTest(Sha512_256.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha512_256),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        256,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgSha512_256_A],
         FipsKats.Values[FipsKats.Vec.DrbgSha512_256_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha1HMac.Algorithm, new DRBGHMACSelfTest(Sha1HMac.Algorithm,
                                                  new DRBGTestVector(
                                                      FipsShs.CreateDigest(FipsShs.Sha1),
                                                      new KatEntropyProvider().Get(440),
                                                      true,
                                                      "2021222324",
                                                      128,
                                                      new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha1_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha1_B]
     })
                                                  .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha224HMac.Algorithm, new DRBGHMACSelfTest(Sha224HMac.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha224),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        192,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha224_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha224_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha256HMac.Algorithm, new DRBGHMACSelfTest(Sha256HMac.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha256),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        256,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha256_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha256_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha384HMac.Algorithm, new DRBGHMACSelfTest(Sha384HMac.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha384),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        256,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha384_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha384_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512HMac.Algorithm, new DRBGHMACSelfTest(Sha512HMac.Algorithm,
                                                    new DRBGTestVector(
                                                        FipsShs.CreateDigest(FipsShs.Sha512),
                                                        new KatEntropyProvider().Get(440),
                                                        true,
                                                        "2021222324",
                                                        256,
                                                        new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_B]
     })
                                                    .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512_224HMac.Algorithm, new DRBGHMACSelfTest(Sha512_224HMac.Algorithm,
                                                        new DRBGTestVector(
                                                            FipsShs.CreateDigest(FipsShs.Sha512_224),
                                                            new KatEntropyProvider().Get(440),
                                                            true,
                                                            "2021222324",
                                                            192,
                                                            new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_224_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_224_B]
     })
                                                        .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         Sha512_256HMac.Algorithm, new DRBGHMACSelfTest(Sha512_256HMac.Algorithm,
                                                        new DRBGTestVector(
                                                            FipsShs.CreateDigest(FipsShs.Sha512_256),
                                                            new KatEntropyProvider().Get(440),
                                                            true,
                                                            "2021222324",
                                                            256,
                                                            new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_256_A],
         FipsKats.Values[FipsKats.Vec.DrbgHMacSha512_256_B]
     })
                                                        .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         CtrTripleDes168.Algorithm, new DRBGCTRSelfTest(CtrTripleDes168.Algorithm,
                                                        new DRBGTestVector(
                                                            FipsTripleDes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL),
                                                            168,
                                                            new KatEntropyProvider().Get(440),
                                                            true,
                                                            "2021222324",
                                                            112,
                                                            new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgCtrTripleDes168_A],
         FipsKats.Values[FipsKats.Vec.DrbgCtrTripleDes168_B]
     })
                                                        .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         CtrAes128.Algorithm, new DRBGCTRSelfTest(CtrAes128.Algorithm,
                                                  new DRBGTestVector(
                                                      FipsAes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL),
                                                      128,
                                                      new KatEntropyProvider().Get(440),
                                                      true,
                                                      "2021222324",
                                                      128,
                                                      new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes128_A],
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes128_B]
     })
                                                  .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         CtrAes192.Algorithm, new DRBGCTRSelfTest(CtrAes192.Algorithm,
                                                  new DRBGTestVector(
                                                      FipsAes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL),
                                                      192,
                                                      new KatEntropyProvider().Get(440),
                                                      true,
                                                      "2021222324",
                                                      192,
                                                      new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes192_A],
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes192_B]
     })
                                                  .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
     SelfTestExecutor.Validate(
         CtrAes256.Algorithm, new DRBGCTRSelfTest(CtrAes256.Algorithm,
                                                  new DRBGTestVector(
                                                      FipsAes.ENGINE_PROVIDER.CreateEngine(EngineUsage.GENERAL),
                                                      256,
                                                      new KatEntropyProvider().Get(440),
                                                      true,
                                                      "2021222324",
                                                      256,
                                                      new byte[][]
     {
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes256_A],
         FipsKats.Values[FipsKats.Vec.DrbgCtrAes256_B]
     })
                                                  .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576")));
 }
コード例 #17
0
            internal RsaKeyUnwrapper(OaepWrapParameters algorithmDetails, IKey key)
            {
                this.algorithmDetails = algorithmDetails;
                this.unwrapper        = new OaepEncoding(ENGINE_PROVIDER.CreateEngine(EngineUsage.DECRYPTION), FipsShs.CreateDigest(algorithmDetails.DigestAlgorithm), FipsShs.CreateDigest(algorithmDetails.MgfDigestAlgorithm), algorithmDetails.GetEncodingParams());

                if (CryptoServicesRegistrar.IsInApprovedOnlyMode())
                {
                    AsymmetricRsaPrivateKey rsaKey = GetPrivateKey(key);
                    int bitLength = rsaKey.Modulus.BitLength;
                    if (bitLength != 2048 && bitLength != 3072 && bitLength != 4096)
                    {
                        throw new CryptoUnapprovedOperationError("Attempt to use RSA key with non-approved size: " + bitLength, key.Algorithm);
                    }
                }

                unwrapper.Init(false, GetPrivateParameters(key, AsymmetricRsaKey.Usage.EncryptOrDecrypt));
            }