/// <summary>
        /// Return list of free cluster runs.
        /// </summary>
        /// <returns>key is cluster LCN, value is run length</returns>
        private KeyValuePairList <long, long> FindClustersToAllocate(long desiredStartLCN, long numberOfClusters)
        {
            KeyValuePairList <long, long> result = new KeyValuePairList <long, long>();

            long leftToFind;
            long endLCN = m_numberOfClustersInVolume - 1;
            KeyValuePairList <long, long> segment = FindClustersToAllocate(desiredStartLCN, endLCN, numberOfClusters, out leftToFind);

            result.AddRange(segment);

            if (leftToFind > 0 && desiredStartLCN > 0)
            {
                segment = FindClustersToAllocate(0, desiredStartLCN - 1, leftToFind, out leftToFind);
                result.AddRange(segment);
            }

            if (leftToFind > 0)
            {
                return(null);
            }

            return(result);
        }
        /// <summary>
        /// Return list of free cluster runs, key is cluster LCN, value is run length
        /// </summary>
        private KeyValuePairList <ulong, long> FindClustersToAllocate(ulong desiredStartLCN, long numberOfClusters)
        {
            KeyValuePairList <ulong, long> result = new KeyValuePairList <ulong, long>();

            long  leftToAllocate;
            ulong endLCN = (ulong)(m_volume.Size / m_volume.BytesPerCluster) - 1;
            KeyValuePairList <ulong, long> segment = FindClustersToAllocate(desiredStartLCN, endLCN, numberOfClusters, out leftToAllocate);

            result.AddRange(segment);

            if (leftToAllocate > 0 && desiredStartLCN > 0)
            {
                segment = FindClustersToAllocate(0, desiredStartLCN - 1, leftToAllocate, out leftToAllocate);
                result.AddRange(segment);
            }

            if (leftToAllocate > 0)
            {
                throw new Exception("Could not allocate clusters. Not enough free disk space");
            }

            return(result);
        }
예제 #3
0
        public static void XTSChainDecrypt(KeyValuePairList <SymmetricAlgorithm, byte[]> algorithmChain, ulong dataUnitIndex, byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
        {
            Array.Copy(inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);

            KeyValuePairList <SymmetricAlgorithm, byte[]> reversedChain = new KeyValuePairList <SymmetricAlgorithm, byte[]>();

            reversedChain.AddRange(algorithmChain);
            reversedChain.Reverse();

            foreach (KeyValuePair <SymmetricAlgorithm, byte[]> algorithm in reversedChain)
            {
                byte[] key1 = new byte[32];
                byte[] key2 = new byte[32];
                Array.Copy(algorithm.Value, 0, key1, 0, 32);
                Array.Copy(algorithm.Value, 32, key2, 0, 32);

                XTSDecrypt(algorithm.Key, key1, key2, dataUnitIndex, outputBuffer, outputOffset, inputCount, outputBuffer, outputOffset);
            }
        }