Beispiel #1
0
        public KdfResult Kdf(KdfParameterHkdf param, BitString fixedInfo)
        {
            var kdf = _hkdfFactory.GetKdf(ShaAttributes.GetHashFunctionFromEnum(param.HmacAlg));

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

            if (result.Success)
            {
                return(new KdfResult(result.DerivedKey));
            }

            return(new KdfResult(result.ErrorMessage));
        }
        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));
        }
Beispiel #3
0
        public KdfResult Kdf(KdfParameterTls12 param, BitString fixedInfo = null)
        {
            var hashFunction = ShaAttributes.GetHashFunctionFromEnum(param.HashFunction);

            var kdf = _tlsFactory.GetTlsKdfInstance(TlsModes.v12, hashFunction);

            var result = kdf.DeriveKey(
                param.Z,
                param.InitiatorEphemeralData,
                param.ResponderEphemeralData,
                param.AdditionalInitiatorNonce,
                param.AdditionalResponderNonce,
                param.L);

            return(new KdfResult(result.DerivedKey));
        }
Beispiel #4
0
        public KdfResult Kdf(KdfParameterIkeV2 param, BitString fixedInfo = null)
        {
            var hashFunction = ShaAttributes.GetHashFunctionFromEnum(param.HashFunction);

            var kdf = _ikeV2Factory.GetInstance(hashFunction);

            var result = kdf.GenerateDkmIke(
                param.InitiatorEphemeralData,
                param.ResponderEphemeralData,
                param.Z,
                param.AdditionalInitiatorNonce,
                param.AdditionalResponderNonce,
                param.L);

            return(new KdfResult(result));
        }
Beispiel #5
0
        public KdfResult Kdf(KdfParameterIkeV1 param, BitString fixedInfo = null)
        {
            var hashFunction = ShaAttributes.GetHashFunctionFromEnum(param.HashFunction);

            var kdf = _ikeV1Factory.GetIkeV1Instance(AuthenticationMethods.Dsa, hashFunction);

            var result = kdf.GenerateIke(param.InitiatorEphemeralData, param.ResponderEphemeralData, param.Z,
                                         param.AdditionalInitiatorNonce, param.AdditionalResponderNonce, null);

            var dkm = new BitString(0)
                      .ConcatenateBits(result.SKeyIdD)
                      .ConcatenateBits(result.SKeyIdA)
                      .ConcatenateBits(result.SKeyIdE);

            return(new KdfResult(dkm.GetMostSignificantBits(param.L)));
        }
Beispiel #6
0
        public ITlsKdf_v1_3 GetInstance(HashFunctions hashFunction)
        {
            var hf = ShaAttributes.GetHashFunctionFromEnum(hashFunction);

            return(new TlsKdfv13(_hkdfFactory.GetKdf(hf), _shaFactory.GetShaInstance(hf), hf.OutputLen));
        }