예제 #1
0
            internal override void Evaluate()
            {
                byte[] nonce = tv.nonce();
                byte[] personalisationString = tv.personalizationString();

                ISP80090Drbg d = new HMacSP800Drbg(new HMac(tv.getDigest()), tv.securityStrength(), tv.entropySource(), personalisationString, nonce);

                byte[] output = new byte[tv.expectedValue(0).Length];

                d.Generate(output, tv.additionalInput(0), tv.predictionResistance());

                byte[] expected = tv.expectedValue(0);

                if (!Arrays.AreEqual(expected, output))
                {
                    Fail("Self test " + algorithm.Name + ".1 failed, expected " + Strings.FromByteArray(Hex.Encode(tv.expectedValue(0))) + " got " + Strings.FromByteArray(Hex.Encode(output)));
                }

                output = new byte[tv.expectedValue(0).Length];

                d.Generate(output, tv.additionalInput(1), tv.predictionResistance());

                expected = tv.expectedValue(1);
                if (!Arrays.AreEqual(expected, output))
                {
                    Fail("Self test " + algorithm.Name + ".2 failed, expected " + Strings.FromByteArray(Hex.Encode(tv.expectedValue(1))) + " got " + Strings.FromByteArray(Hex.Encode(output)));
                }
            }
예제 #2
0
            internal override void Evaluate()
            {
                byte[]         origK             = parent.mK;
                byte[]         origV             = parent.mV;
                long           origReseedCounter = parent.mReseedCounter;
                IEntropySource origEntropySource = parent.mEntropySource;

                try
                {
                    byte[] additionalInput = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576");

                    int      entropyStrength = DrbgUtilities.GetMaxSecurityStrength(parent.mHMac);
                    byte[][] expected        = (byte[][])reseedKats[algorithm.Name];
                    byte[][] internalValues  = (byte[][])reseedValues[algorithm.Name];

                    parent.mK = Arrays.Clone(internalValues[0]);
                    parent.mV = Arrays.Clone(internalValues[1]);

                    parent.mEntropySource = new DrbgUtilities.KatEntropyProvider().Get(entropyStrength);

                    parent.Reseed(additionalInput);

                    if (parent.mReseedCounter != 1)
                    {
                        Fail("DRBG reseedCounter failed to reset");
                    }

                    byte[] output = new byte[expected[0].Length];

                    parent.Generate(output, null, false);
                    if (!Arrays.AreEqual(expected[0], output))
                    {
                        Fail("DRBG Block 1 reseed KAT failure");
                    }

                    output = new byte[expected[1].Length];

                    parent.Generate(output, null, false);
                    if (!Arrays.AreEqual(expected[1], output))
                    {
                        Fail("DRBG Block 2 reseed KAT failure");
                    }

                    try
                    {
                        parent.mEntropySource = new DrbgUtilities.LyingEntropySource(entropyStrength);

                        parent.Reseed(null);

                        Fail("DRBG LyingEntropySource not detected");
                    }
                    catch (InvalidOperationException e)
                    {
                        if (!e.Message.Equals("Insufficient entropy provided by entropy source"))
                        {
                            Fail("DRBG self test failed reseed entropy check");
                        }
                    }
                }
                finally
                {
                    parent.mK             = origK;
                    parent.mV             = origV;
                    parent.mReseedCounter = origReseedCounter;
                    parent.mEntropySource = origEntropySource;
                }
            }
예제 #3
0
            internal override void Evaluate()
            {
                byte[]         origK             = parent.mK;
                byte[]         origV             = parent.mV;
                long           origReseedCounter = parent.mReseedCounter;
                IEntropySource origEntropySource = parent.mEntropySource;

                try
                {
                    byte[] personalization = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F70717273747576");
                    byte[] nonce           = Hex.Decode("2021222324");

                    int entropyStrength = DrbgUtilities.GetMaxSecurityStrength(parent.mHMac);

                    byte[][] expected = (byte[][])kats[algorithm.Name];

                    parent.init(parent.mHMac, parent.mSecurityStrength, new DrbgUtilities.KatEntropyProvider().Get(entropyStrength), personalization, nonce);

                    byte[] output = new byte[expected[0].Length];

                    parent.Generate(output, null, true);
                    if (!Arrays.AreEqual(expected[0], output))
                    {
                        Fail("DRBG Block 1 KAT failure");
                    }

                    output = new byte[expected[1].Length];

                    parent.Generate(output, null, true);
                    if (!Arrays.AreEqual(expected[1], output))
                    {
                        Fail("DRBG Block 2 KAT failure");
                    }

                    try
                    {
                        parent.init(parent.mHMac, parent.mSecurityStrength, new DrbgUtilities.LyingEntropySource(entropyStrength), personalization, nonce);

                        Fail("DRBG LyingEntropySource not detected in init");
                    }
                    catch (InvalidOperationException e)
                    {
                        if (!e.Message.Equals("Insufficient entropy provided by entropy source"))
                        {
                            Fail("DRBG self test failed init entropy check");
                        }
                    }

                    try
                    {
                        parent.init(parent.mHMac, parent.mSecurityStrength, new DrbgUtilities.LyingEntropySource(20), personalization, nonce);

                        Fail("DRBG insufficient EntropySource not detected");
                    }
                    catch (ArgumentException e)
                    {
                        if (!e.Message.Equals("Not enough entropy for security strength required"))
                        {
                            Fail("DRBG self test failed init entropy check");
                        }
                    }

                    try
                    {
                        parent.mEntropySource = new DrbgUtilities.LyingEntropySource(entropyStrength);

                        parent.Reseed(null);

                        Fail("DRBG LyingEntropySource not detected in reseed");
                    }
                    catch (InvalidOperationException e)
                    {
                        if (!e.Message.Equals("Insufficient entropy provided by entropy source"))
                        {
                            Fail("DRBG self test failed reseed entropy check");
                        }
                    }

                    try
                    {
                        parent.init(parent.mHMac, entropyStrength + 1, new DrbgUtilities.KatEntropyProvider().Get(entropyStrength), personalization, nonce);

                        Fail("DRBG successful initialise with too high security strength");
                    }
                    catch (ArgumentException e)
                    {
                        if (!e.Message.Equals("Requested security strength is not supported by the derivation function"))
                        {
                            Fail("DRBG self test failed init security strength check");
                        }
                    }
                }
                finally
                {
                    parent.mK             = origK;
                    parent.mV             = origV;
                    parent.mReseedCounter = origReseedCounter;
                    parent.mEntropySource = origEntropySource;
                }
            }