Esempio n. 1
0
        public int Generate(byte[] output, byte[] additionalInput, bool predictionResistant)
        {
            lock (this)
            {
                lazyInitDRBG();

                if (predictionResistant)
                {
                    // FSM_STATE:5.7, "DRBG RESEED HEALTH CHECK", "The module is performing DRBG Reseed Health Check self-test"
                    // FSM_TRANS:5.7, "CONDITIONAL TEST", "DRBG RESEED HEALTH CHECKS", "Invoke DRBG Reseed Health Check"
                    SelfTestExecutor.Validate(algorithm, drbg.CreateReseedSelfTest(algorithm));    // reseed health test
                    // FSM_TRANS:5.8, "DRBG RESEED HEALTH CHECKS", "CONDITIONAL TEST", "DRBG Reseed Health Check successful"
                }

                // check if a reseed is required...
                if (drbg.Generate(output, additionalInput, predictionResistant) < 0)
                {
                    // FSM_STATE:5.7, "DRBG RESEED HEALTH CHECK", "The module is performing DRBG Reseed Health Check self-test"
                    // FSM_TRANS:5.7, "CONDITIONAL TEST", "DRBG RESEED HEALTH CHECKS", "Invoke DRBG Reseed Health Check"
                    SelfTestExecutor.Validate(algorithm, drbg.CreateReseedSelfTest(algorithm));    // reseed health test
                    // FSM_TRANS:5.8, "DRBG RESEED HEALTH CHECKS", "CONDITIONAL TEST", "DRBG Reseed Health Check successful"

                    drbg.Reseed(null);
                    return(drbg.Generate(output, additionalInput, predictionResistant));
                }

                return(output.Length);
            }
        }
Esempio n. 2
0
            public Internal.IMac CreateEngine(EngineUsage usage)
            {
                Internal.IMac engine = SelfTestExecutor.Validate(Alg, new Internal.Macs.Poly1305(), new EngineSelfTest());
                if (keyParameter != null)
                {
                    engine.Init(keyParameter);
                }

                return(engine);
            }
Esempio n. 3
0
            public Internal.IBlockCipher CreateEngine(EngineUsage usage)
            {
                Internal.IBlockCipher engine = SelfTestExecutor.Validate(Alg, new DesEdeEngine(), new TripleDesSelfTest());
                if (keyParameter != null)
                {
                    engine.Init(usage == EngineUsage.ENCRYPTION, keyParameter);
                }

                return(engine);
            }
Esempio n. 4
0
            public Internal.IStreamCipher CreateEngine(EngineUsage usage)
            {
                Internal.IStreamCipher engine = SelfTestExecutor.Validate(Alg, new ChaChaEngine(), new EngineSelfTest());
                if (keyParameter != null)
                {
                    engine.Init(usage == EngineUsage.ENCRYPTION, keyParameter);
                }

                return(engine);
            }
Esempio n. 5
0
 private void lazyInitDRBG()
 {
     if (drbg == null)
     {
         drbg = drbgProvider.Get(entropySource);
         // FSM_STATE:5.6, "DRBG HEALTH CHECKS", "The module is performing DRBG Health Check self-test"
         // FSM_TRANS:5.5, "CONDITIONAL TEST", "DRBG HEALTH CHECKS", "Invoke DRBG Health Check"
         SelfTestExecutor.Validate(algorithm, drbg.CreateSelfTest(algorithm));   // instance health test
         // FSM_TRANS:5.6, "DRBG HEALTH CHECKS", "CONDITIONAL TEST", "DRBG Health Check successful"
     }
 }
Esempio n. 6
0
        public void Reseed(byte[] additionalInput)
        {
            lock (this)
            {
                lazyInitDRBG();

                // FSM_STATE:5.7, "DRBG RESEED HEALTH CHECK", "The module is performing DRBG Reseed Health Check self-test"
                // FSM_TRANS:5.7, "CONDITIONAL TEST", "DRBG RESEED HEALTH CHECKS", "Invoke DRBG Reseed Health Check"
                SelfTestExecutor.Validate(algorithm, drbg.CreateReseedSelfTest(algorithm));   // reseed health test.
                // FSM_TRANS:5.8, "DRBG RESEED HEALTH CHECKS", "CONDITIONAL TEST", "DRBG Reseed Health Check successful"

                drbg.Reseed(additionalInput);
            }
        }
Esempio n. 7
0
        private static void validateKeyPair(FipsAlgorithm algorithm, AsymmetricCipherKeyPair kp)
        {
            switch (algorithm.Mode)
            {
            case AlgorithmMode.NONE:
            case AlgorithmMode.DSA:
                SelfTestExecutor.Validate(algorithm, kp, new DsaConsistencyTest());
                break;

            case AlgorithmMode.CDH:
                SelfTestExecutor.Validate(algorithm, kp, new CdhConsistencyTest());
                break;

            default:
                throw new InvalidOperationException("Unhandled EC algorithm: " + algorithm.Name);
            }
        }
Esempio n. 8
0
 public DsaSigner CreateEngine(EngineUsage usage)
 {
     // We do this using a pair-wise consistency test as per the IG 2nd March 2015, Section 9.4
     return(SelfTestExecutor.Validate(Alg, new DsaSigner(), new DsaKatTest()));
 }
Esempio n. 9
0
 private static void CMacStartUpTest(EngineProvider provider)
 {
     SelfTestExecutor.Validate(CMac.Algorithm, provider, new CMacStartupTest());
 }
Esempio n. 10
0
 private static void rsaKeyTransportTest(IEngineProvider <RsaBlindedEngine> provider)
 {
     SelfTestExecutor.Validate(WrapOaep.Algorithm, new RsaOaepKeyTransportTest(provider));
 }
Esempio n. 11
0
 private static void GcmStartUpTest(EngineProvider provider)
 {
     SelfTestExecutor.Validate(Gcm.Algorithm, provider, new GcmStartupTest());
 }
Esempio n. 12
0
 public override IXof CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Algorithm.SHAKE256, new ShakeDigest(256), new XofKatTest(FipsKats.Values[FipsKats.Vec.Shake256])));
 }
Esempio n. 13
0
 public override IDigest CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Algorithm.SHA512_256, new Sha512tDigest(256), new ShaKatTest(FipsKats.Values[FipsKats.Vec.Sha512_256])));
 }
Esempio n. 14
0
 private static void validateKeyPair(AsymmetricCipherKeyPair kp)
 {
     SelfTestExecutor.Validate(Alg, kp, new DsaKeyPairValidationTest());
 }
Esempio n. 15
0
 private static void ecPrimitiveZTest()
 {
     SelfTestExecutor.Validate(Alg, new PrimitiveZTest());
 }
Esempio n. 16
0
 public ECDHCBasicAgreement CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Alg, new ECDHCBasicAgreement(), new DhcKatTest()));
 }
Esempio n. 17
0
 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")));
 }
Esempio n. 18
0
 public IDigest CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Tls1_0.Algorithm, new MD5Digest(), new Md5KatTest()));
 }
Esempio n. 19
0
 private static void ValidateKeyPair(AsymmetricCipherKeyPair kp)
 {
     SelfTestExecutor.Validate(Alg, kp, new RsaKeyPairConsistencyTest());
 }
Esempio n. 20
0
 public override IDigest CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Algorithm.SHA3_512, new Sha3Digest(512), new ShaKatTest(FipsKats.Values[FipsKats.Vec.Sha3_512])));
 }
Esempio n. 21
0
 public RsaBlindedEngine CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Alg, new RsaBlindedEngine(), new RsaEngineTest()));
 }
Esempio n. 22
0
 public override IMac CreateEngine(EngineUsage usage)
 {
     return(SelfTestExecutor.Validate(Algorithm.SHA512_256_HMAC, new HMac(new Sha512tDigest(256)), new HMacKatTest(FipsKats.Values[FipsKats.Vec.Sha512_256HMac])));
 }
Esempio n. 23
0
 private static void rsaSignTest(IEngineProvider <RsaBlindedEngine> provider)
 {
     SelfTestExecutor.Validate(Pkcs1v15.Algorithm, new RsaSignTest(provider));
 }