Beispiel #1
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 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));
            }
        }