public virtual ReadOnlyMemory <byte> MakeChecksum(
     ReadOnlyMemory <byte> data,
     KerberosKey key,
     KeyUsage usage,
     KeyDerivationMode kdf,
     int hashSize)
 {
     throw new NotImplementedException();
 }
示例#2
0
        private byte[] DK(byte[] key, KeyUsage usage, KeyDerivationMode kdf)
        {
            var constant = new byte[5];

            Endian.ConvertToBigEndian((int)usage, constant);

            constant[4] = (byte)kdf;

            return(DK(key, constant));
        }
示例#3
0
        public override ReadOnlyMemory <byte> MakeChecksum(
            ReadOnlyMemory <byte> data,
            KerberosKey key,
            KeyUsage usage,
            KeyDerivationMode kdf,
            int hashSize
            )
        {
            var ki = this.GetOrDeriveKey(key, usage, kdf).Slice(0, hashSize);

            return(this.Hmac(ki, data).Slice(0, hashSize));
        }
示例#4
0
        public override byte[] MakeChecksum(byte[] data, byte[] key, KeyUsage usage, KeyDerivationMode kdf, int hashSize)
        {
            var ki = DK(key, usage, kdf);

            var hash = Hmac(ki, data);

            var output = new byte[hashSize];

            Buffer.BlockCopy(hash, 0, output, 0, hashSize);

            return(output);
        }
示例#5
0
        public override ReadOnlyMemory <byte> MakeChecksum(
            ReadOnlyMemory <byte> data,
            KerberosKey key,
            KeyUsage usage,
            KeyDerivationMode kdf,
            int hashSize
            )
        {
            var ki = key.GetOrDeriveKey(
                this,
                $"{usage}|{kdf}|{KeySize}|{BlockSize}",
                k => DK(k, usage, kdf, KeySize, BlockSize)
                );

            return(Hmac(ki, data).Slice(0, hashSize));
        }
示例#6
0
        public override ReadOnlyMemory <byte> MakeChecksum(
            ReadOnlyMemory <byte> data,
            KerberosKey key,
            KeyUsage usage,
            KeyDerivationMode kdf,
            int hashSize
            )
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var ki = key.GetOrDeriveKey(
                this,
                $"{usage}|{kdf}|{this.KeySize}|{this.BlockSize}",
                k => DK(k, usage, kdf, this.KeySize, this.BlockSize)
                );

            return(Hmac(ki, data).Slice(0, hashSize));
        }
 public virtual byte[] MakeChecksum(byte[] data, byte[] key, KeyUsage usage, KeyDerivationMode kdf, int hashSize)
 {
     throw new NotImplementedException();
 }
示例#8
0
        private static ReadOnlyMemory <byte> DK(ReadOnlyMemory <byte> key, KeyUsage usage, KeyDerivationMode kdf, int keySize, int blockSize)
        {
            using (var constantPool = CryptoPool.RentUnsafe <byte>(5))
            {
                var constant = constantPool.Memory.Slice(0, 5);

                Span <byte> span = constant.Span;
                span.Clear();
                BinaryPrimitives.WriteInt32BigEndian(span, (int)usage);

                constant.Span[4] = (byte)kdf;

                return(DK(key, constant, keySize, blockSize));
            }
        }
        private static ReadOnlySpan <byte> DK(ReadOnlySpan <byte> key, KeyUsage usage, KeyDerivationMode kdf, int keySize, int blockSize)
        {
            var constant = new Span <byte>(new byte[5]);

            Endian.ConvertToBigEndian((int)usage, constant);

            constant[4] = (byte)kdf;

            return(DK(key, constant, keySize, blockSize));
        }
示例#10
0
        private static ReadOnlyMemory <byte> DK(ReadOnlySpan <byte> key, KeyUsage usage, KeyDerivationMode kdf, int keySize, int blockSize)
        {
            using (var constantPool = CryptoPool.RentUnsafe <byte>(5))
            {
                var constant = constantPool.Memory.Slice(0, 5);

                constant.Span.Fill(0);

                Endian.ConvertToBigEndian((int)usage, constant.Span);

                constant.Span[4] = (byte)kdf;

                return(DK(key, constant, keySize, blockSize));
            }
        }
示例#11
0
 internal new ReadOnlyMemory <byte> GetOrDeriveKey(KerberosKey key, KeyUsage usage, KeyDerivationMode mode)
 {
     return(base.GetOrDeriveKey(key, usage, mode));
 }
示例#12
0
        protected ReadOnlyMemory <byte> GetOrDeriveKey(KerberosKey kerberosKey, KeyUsage usage, KeyDerivationMode mode)
        {
            if (kerberosKey == null)
            {
                throw new InvalidOperationException("Key cannot be null");
            }

            return(kerberosKey.GetOrDeriveKey(
                       this,
                       $"{usage}|{mode}|{this.KeySize}|{this.BlockSize}",
                       key => this.DK(key, usage, mode, this.KeySize, this.BlockSize)
                       ));
        }