Пример #1
0
        public void ShouldMultiExpandSameResult()
        {
            var fixedInfo = new BitString(128);
            var salt      = new BitString(128);
            var z         = new BitString(128);
            var hmacAlg   = HashFunctions.Sha2_d256;
            var l         = 256;

            var hkdfParam = new KdfParameterHkdf()
            {
                L       = l,
                Salt    = salt,
                Z       = z,
                HmacAlg = hmacAlg
            };
            var multiExpandHkdfParam = new KdfMultiExpansionParameterHkdf()
            {
                Salt                = salt,
                Z                   = z,
                HmacAlg             = hmacAlg,
                IterationParameters = new List <KdfMultiExpansionIterationParameter>()
                {
                    new KdfMultiExpansionIterationParameter(l, fixedInfo),
                    new KdfMultiExpansionIterationParameter(l, fixedInfo),
                }
            };

            var hkdfResult            = _kdfVisitor.Kdf(hkdfParam, fixedInfo);
            var multiExpandHkdfResult = _kdfMultiExpansionVisitor.Kdf(multiExpandHkdfParam);

            Assert.True(multiExpandHkdfResult.Results.Count == 2);
            Assert.AreEqual(hkdfResult.DerivedKey, multiExpandHkdfResult.Results[0].DerivedKey);
            Assert.AreEqual(hkdfResult.DerivedKey, multiExpandHkdfResult.Results[1].DerivedKey);
        }
        public KdfMultiExpansionResult Kdf(KdfMultiExpansionParameterHkdf param)
        {
            var kdf = _hkdfFactory.GetKdf(ShaAttributes.GetHashFunctionFromEnum(param.HmacAlg));

            List <KdfResult> result = new List <KdfResult>();

            foreach (var iterationParameter in param.IterationParameters)
            {
                result.Add(kdf.DeriveKey(param.Salt, param.Z, iterationParameter.FixedInfo, iterationParameter.L / BitString.BITSINBYTE));
            }

            return(new KdfMultiExpansionResult(result));
        }