public void ShouldKmac(
            string label,
            string fixedInfoPattern,
            Kda kdfType,
            KdaOneStepAuxFunction kdfAuxFunction,
            int l,
            BitString salt,
            BitString z,
            BitString algorithmId,
            BitString uPartyId,
            BitString uEphemData,
            BitString vPartyid,
            BitString vEphemData,
            BitString issueFixedData,
            BitString issueDkm,
            BitString expectedDkm)
        {
            var param = new KdfParameterOneStep()
            {
                L                  = l,
                Salt               = salt,
                Z                  = z,
                AlgorithmId        = algorithmId,
                AuxFunction        = kdfAuxFunction,
                FixedInfoPattern   = fixedInfoPattern,
                FixedInputEncoding = FixedInfoEncoding.Concatenation
            };

            var fixedInfoFactory   = new FixedInfoFactory(new FixedInfoStrategyFactory());
            var fixedInfoParameter = new FixedInfoParameter()
            {
                AlgorithmId      = algorithmId,
                FixedInfoPattern = fixedInfoPattern,
                Encoding         = FixedInfoEncoding.Concatenation,
                L    = l,
                Salt = salt
            };

            fixedInfoParameter.SetFixedInfo(
                new PartyFixedInfo(uPartyId, uEphemData),
                new PartyFixedInfo(vPartyid, vEphemData));

            var fixedInfo = fixedInfoFactory
                            .Get()
                            .Get(fixedInfoParameter);

            var kdf = _kdfOneStepFactory.GetInstance(param.AuxFunction, true);

            var result = kdf.DeriveKey(param.Z, param.L, fixedInfo, param.Salt);

            Assert.AreEqual(issueFixedData.ToHex(), fixedInfo.ToHex(), nameof(issueFixedData));
            Assert.AreEqual(issueDkm.ToHex(), result.DerivedKey.ToHex(), nameof(issueDkm));
            //Assert.AreEqual(expectedDkm.ToHex(), result.DerivedKey.ToHex(), nameof(expectedDkm));
        }
Exemple #2
0
        /// <summary>
        /// Gets the fixed info to be used as an input to a KDF.
        /// </summary>
        /// <param name="otherPartyKeyingMaterial">The other party keying material.</param>
        /// <returns></returns>
        private BitString GetFixedInfo(ISecretKeyingMaterial otherPartyKeyingMaterial)
        {
            var fixedInfo = _fixedInfoFactory.Get();

            var thisPartyFixedInfo  = GetPartyFixedInfo(ThisPartyKeyingMaterial);
            var otherPartyFixedInfo = GetPartyFixedInfo(otherPartyKeyingMaterial);

            _fixedInfoParameter.SetFixedInfo(
                SchemeParameters.KeyAgreementRole == KeyAgreementRole.InitiatorPartyU
                    ? thisPartyFixedInfo
                    : otherPartyFixedInfo,
                SchemeParameters.KeyAgreementRole == KeyAgreementRole.ResponderPartyV
                    ? thisPartyFixedInfo
                    : otherPartyFixedInfo
                );

            return(fixedInfo.Get(_fixedInfoParameter));
        }
Exemple #3
0
        public void DkmIntermediateValues()
        {
            var l                 = 512;
            var algorithmId       = new BitString("A0752AE1B4165A32C1387D1DA5E9F8AE");
            var fixedInfoPattern  = "algorithmId||l||uPartyInfo||vPartyInfo";
            var fixedInfoEncoding = FixedInfoEncoding.Concatenation;
            var z                 = new BitString("08E11078180FBDA3C73183F116DA038243802E22F165C2EF4C6BD9AC82612F86FD4F8197AB0B4F5A5E14390BD8F01A55B443FEA55A05438978BC8368691CB8013D5BE2312FB7C64125882835EE3BACD0D442C83A636DE2DF81B04F714C75E2874A284784C1EE987D7E61123CE5C53AC82DD0DE4CA3022985DFA320C83444A338C50DFA2803D9A1B28E6C3D8CF2C283A27983B6F0AEA89444504A5D63A127E9BBEE05FE6867B34CE3C18CF438477ACF3D07C1F01D00913DC37661DC4FBD623E83A48407C2FF8A6369A1B682EC6C0BA62C9A1AC5DFAB8D3FF6C7FEF3CA1DED9943786043EEA76A58CCA19BAB408805C26A2CF93D57A5B6E4E872AF2D585704044C");

            var uPartyFixedInfo = new PartyFixedInfo(
                new BitString("CAFE01020304"),
                new BitString("DAC2B3C01810B48A206333183E4E873E139FE6E4EC274EDB44B27419BA96C1401B49670A44C1F89B996C235E242962CF4D39C9F9E99D4281B8D9D75C5129BDB4822B02C0DC8515C60F6C0337D5EFEAA1346EFE2F5A8475C17FCF85B1A536E13B2E6FBA0BA2737409DAECD4F4A36D104DD3BE465AD92CD081959489CCD1B26FE496B2090FB30EE3892C8090DF6EE74661D696F23A2A71F68FB7B395C97236F6B937639891AE1B6EAEC814928B325D9B2F3B7FFBEBE9A718F2964CBA01118EE9D769E769D24ED6553B79D9F82CA62619C3D20105DEF06618B6FAEA7FB358206F628B07AAA5B80AC97D99830D943C1AE78D8F9926CB3A1D004F650FCA0D40117D3C"));

            var vPartyFixedInfo = new PartyFixedInfo(
                new BitString("434156536964"),
                new BitString("121DCC2DD2F243398381290F0F1AE0648F7B1911606BCA5F1065D54578B40CCBCEB3CBC0EF5F7DACAA3567CEEB8B220AE3E257ED325380DDDDBB8C4F9FEE6FEB4F149A3225C447E7684B64E049A81A9CB57433E89F5CE068E6F0843646E6F80F16B1760628D87F17CAF74912BC66CE61F1D33697FD859CC51AC20AA4DB12DEB25D2147180A0C70EB0C316D3C22FA2BF0955F48259856305DC9801298C38B4838346B0DE85763C13AF8CEED2EE266462C5BCE30244A131D6B099E7CCB4668BAFA5F4FA3682786BFC5849238B6C13AFB464C58017D85A887D7D4346F162945CC3184AF68DDAC92845C4CB6CCD1EAF19F78B4A511129A3EA9C82D50FAACE30B7B50"));

            var fixedInfoParam = new FixedInfoParameter()
            {
                AlgorithmId      = algorithmId,
                Encoding         = fixedInfoEncoding,
                L                = l,
                FixedInfoPattern = fixedInfoPattern
            };

            fixedInfoParam.SetFixedInfo(uPartyFixedInfo, vPartyFixedInfo);

            var fixedInfo = _fixedInfoFactory.Get().Get(fixedInfoParam);

            var kdf = _kdfFactory.GetKdf();
            var dkm = kdf.DeriveKey(new KdfParameterOneStep()
            {
                Z                  = z,
                L                  = l,
                AlgorithmId        = algorithmId,
                AuxFunction        = KdaOneStepAuxFunction.SHA2_D256,
                FixedInfoPattern   = fixedInfoPattern,
                FixedInputEncoding = fixedInfoEncoding
            }, fixedInfo);

            Assert.AreEqual(
                new BitString("6D7783F2CB7D9F35A0B8809430A62B152D7C128F960B2827E46130D8955797601DB5263A135BC429D60568EDEB72B656F819CFC348CCC02EEEA7FE589FFA385B").ToHex(),
                dkm.DerivedKey.ToHex());
        }
Exemple #4
0
        /// <summary>
        /// Get the FixedInfo BitString for use in KDFs and KTS.
        /// </summary>
        /// <param name="otherPartyKeyingMaterial">The other party keying material</param>
        /// <param name="excludeEphemeralData">Should the ephemeral data be excluded? (Used for KTS fixed info generation)</param>
        /// <returns></returns>
        protected BitString GetFixedInfo(IIfcSecretKeyingMaterial otherPartyKeyingMaterial, bool excludeEphemeralData = false)
        {
            var fixedInfo = _fixedInfoFactory.Get();

            var thisPartyFixedInfo = GetPartyFixedInfo(ThisPartyKeyingMaterial, SchemeParameters.KeyAgreementRole, excludeEphemeralData);
            var otherPartyRole     =
                KeyGenerationRequirementsHelper.GetOtherPartyKeyAgreementRole(SchemeParameters.KeyAgreementRole);
            var otherPartyFixedInfo = GetPartyFixedInfo(otherPartyKeyingMaterial, otherPartyRole, excludeEphemeralData);

            _fixedInfoParameter.SetFixedInfo(
                SchemeParameters.KeyAgreementRole == KeyAgreementRole.InitiatorPartyU
                    ? thisPartyFixedInfo
                    : otherPartyFixedInfo,
                SchemeParameters.KeyAgreementRole == KeyAgreementRole.ResponderPartyV
                    ? thisPartyFixedInfo
                    : otherPartyFixedInfo
                );

            return(fixedInfo.Get(_fixedInfoParameter));
        }