Пример #1
0
        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));
        }
Пример #2
0
        public KdfMultiExpansionResult DeriveKey(IKdfMultiExpansionParameter param)
        {
            if (param == null)
            {
                throw new ArgumentNullException($"{nameof(param)} for DeriveKey cannot be null.");
            }

            KdfType = param.KdfType;

            return(param.AcceptKdf(_visitor));
        }
Пример #3
0
        public KdfResult DeriveKey(IKdfParameter param, BitString fixedInfo)
        {
            if (param == null)
            {
                throw new ArgumentNullException($"{nameof(param)} for DeriveKey cannot be null.");
            }

            KdfType = param.KdfType;

            return(param.AcceptKdf(_visitor, fixedInfo));
        }