Ejemplo n.º 1
0
        public void ShouldCorrectlyDeriveKey(MacModes mac, CounterLocations ctrLocation, int rLen, int outLen, string kI, string fixedInput, string kO)
        {
            var keyIn          = new BitString(kI);
            var fixedInputData = new BitString(fixedInput);
            var expectedKey    = new BitString(kO);

            var kdf = _factory.GetKdfInstance(KdfModes.Pipeline, mac, ctrLocation, rLen);

            var result = kdf.DeriveKey(keyIn, fixedInputData, outLen);

            Assert.IsTrue(result.Success, result.ErrorMessage);
            Assert.AreEqual(expectedKey, result.DerivedKey);
        }
Ejemplo n.º 2
0
        public IKdf GetKdfInstance(KdfModes kdfMode, MacModes macMode, CounterLocations counterLocation, int counterLength = 0)
        {
            var mac = GetMacInstance(macMode);

            switch (kdfMode)
            {
            case KdfModes.Counter:
                return(new CounterKdf(mac, counterLocation, counterLength));

            case KdfModes.Feedback:
                return(new FeedbackKdf(mac, counterLocation, counterLength));

            case KdfModes.Pipeline:
                return(new PipelineKdf(mac, counterLocation, counterLength));

            default:
                throw new ArgumentException("KDF Mode not supported");
            }
        }
Ejemplo n.º 3
0
 public FeedbackKdf(IMac mac, CounterLocations counterLocation, int counterLength = 0) : base(mac)
 {
     _counterLocation = counterLocation;
     _counterLength   = counterLength;
 }
Ejemplo n.º 4
0
 public PipelineKdf(IMac mac, CounterLocations counterLocation, int counterLength) : base(mac)
 {
     _counterLocation = counterLocation;
     _counterLength   = counterLength;
 }
Ejemplo n.º 5
0
        public void ShouldCorrectlyDeriveKeyNoTestNameMessingUpTestRunner(string label, MacModes mac, CounterLocations ctrLocation, int rLen, int outLen, string kI, string fixedInput, string kO, int breakLocation = 0)
        {
            var keyIn          = new BitString(kI);
            var fixedInputData = new BitString(fixedInput);
            var expectedKey    = new BitString(kO);

            var kdf = _factory.GetKdfInstance(KdfModes.Counter, mac, ctrLocation, rLen);

            var result = kdf.DeriveKey(keyIn, fixedInputData, outLen, breakLocation: breakLocation);

            Assert.IsTrue(result.Success, result.ErrorMessage);
            Assert.AreEqual(expectedKey, result.DerivedKey);
        }