Пример #1
0
        protected override Result DoWrite(long offset, ReadOnlySpan <byte> source)
        {
            int  size        = source.Length;
            long sectorIndex = offset / SectorSize;

            if (_writeTransform == null)
            {
                _writeTransform = new Aes128XtsTransform(_key1, _key2, !_decryptRead);
            }

            source.CopyTo(_tempBuffer);
            _writeTransform.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex);

            return(base.DoWrite(offset, _tempBuffer.AsSpan(0, size)));
        }
Пример #2
0
        protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source)
        {
            int  size        = source.Length;
            long sectorIndex = offset / SectorSize;

            if (_encryptor == null)
            {
                _encryptor = new Aes128XtsTransform(_key1, _key2, false);
            }

            source.CopyTo(_tempBuffer);
            _encryptor.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex);

            return(base.WriteImpl(offset, _tempBuffer.AsSpan(0, size)));
        }
Пример #3
0
        protected override Result DoRead(long offset, Span <byte> destination)
        {
            int  size        = destination.Length;
            long sectorIndex = offset / SectorSize;

            if (_readTransform == null)
            {
                _readTransform = new Aes128XtsTransform(_key1, _key2, _decryptRead);
            }

            Result rc = base.DoRead(offset, _tempBuffer.AsSpan(0, size));

            if (rc.IsFailure())
            {
                return(rc);
            }

            _readTransform.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex);
            _tempBuffer.AsSpan(0, size).CopyTo(destination);

            return(Result.Success);
        }