Exemplo n.º 1
0
        public override void WriteSectors(long sectorIndex, byte[] data)
        {
            CheckBoundaries(sectorIndex, data.Length / this.BytesPerSector);

            int  sectorCount      = data.Length / m_volume.BytesPerSector;
            long imageSectorIndex = sectorIndex + (long)m_header.MasterKeyScopeOffset / m_volume.BytesPerSector;

            byte[] encryptedData = new byte[data.Length];
            Parallel.For(0, sectorCount, delegate(int index)
            {
                int offset = index * m_volume.BytesPerSector;
                XTSHelper.XTSChainEncrypt(m_header.AlgorithmChain, (ulong)(imageSectorIndex + index), data, offset, m_volume.BytesPerSector, encryptedData, offset);
            });
            m_volume.WriteSectors(imageSectorIndex, encryptedData);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Including the prefixed salt
        /// </summary>
        public byte[] GetBytes(byte[] password)
        {
            byte[] headerBytes = GetDecryptedHeaderBytes();

            int    iterations = m_hmac is HMACRIPEMD160 ? 2000 : 1000;
            Pbkdf2 pbkdf2     = new Pbkdf2(m_hmac, password, Salt, iterations);

            byte[] headerKey = pbkdf2.GetBytes(192);

            AssignKey(m_algorithmChain, headerKey);
            byte[] encrypted = XTSHelper.XTSChainEncrypt(m_algorithmChain, 0, headerBytes, 0, headerBytes.Length);
            AssignKey(m_algorithmChain, MasterKey);

            byte[] buffer = new byte[512];
            ByteWriter.WriteBytes(buffer, 0, Salt);
            ByteWriter.WriteBytes(buffer, 64, encrypted);

            return(buffer);
        }