Example #1
0
        public static RecoveryState Read(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var newPartialKey           = PartialKey.Read(reader);
            var newEncryptedHeaderBlock = Block.Read(reader);
            var newPlaintextHeaderBlock = Block.Read(reader);

            int b0BlockCount = reader.ReadInt32();

            var newB0Blocks = new List <Block>(b0BlockCount);

            for (int i = 0; i < b0BlockCount; i++)
            {
                newB0Blocks.Add(Block.Read(reader));
            }

            int sequentialBlockCount = reader.ReadInt32();

            var newSequentialBlocks = new List <Block>(sequentialBlockCount);

            for (int i = 0; i < sequentialBlockCount; i++)
            {
                newSequentialBlocks.Add(Block.Read(reader));
            }

            return(new RecoveryState(newPartialKey, newB0Blocks, newSequentialBlocks, newEncryptedHeaderBlock, newPlaintextHeaderBlock));
        }
Example #2
0
        /// <summary>
        /// Scans the given key index to find a set of potential values that can decrypt the header block. Takes all 64 bits into consideration.
        /// </summary>
        /// <param name="keyIndex"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IEnumerable <RecoveryState> > IndexScan(int keyIndex, CancellationToken cancellationToken)
        {
            var results = await PartialKey.KeyIndexScan(keyIndex, EncryptedHeaderBlock, PlaintextHeaderBlock, cancellationToken)
                          .ConfigureAwait(false);

            return(results.Select(r => new RecoveryState(this, r.Key, r.Value)));
        }
Example #3
0
        public void Write(BinaryWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            PartialKey.Write(writer);
            EncryptedHeaderBlock.Write(writer);
            PlaintextHeaderBlock.Write(writer);

            writer.Write(B0Blocks.Count());

            foreach (var block in B0Blocks)
            {
                block.Write(writer);
            }

            writer.Write(SequentialBlocks.Count());

            foreach (var block in SequentialBlocks)
            {
                block.Write(writer);
            }
        }
Example #4
0
 private RecoveryState(RecoveryState parent, PartialKey partialKey, IEnumerable <Block> b0Blocks, IEnumerable <Block> sequentialBlocks, Block encryptedHeaderBlock, Block plaintextHeaderBlock)
 {
     Parent               = parent;
     PartialKey           = partialKey ?? throw new ArgumentNullException(nameof(partialKey));
     B0Blocks             = b0Blocks ?? throw new ArgumentNullException(nameof(b0Blocks));
     SequentialBlocks     = sequentialBlocks ?? throw new ArgumentNullException(nameof(sequentialBlocks));
     EncryptedHeaderBlock = encryptedHeaderBlock ?? throw new ArgumentNullException(nameof(encryptedHeaderBlock));
     PlaintextHeaderBlock = plaintextHeaderBlock ?? throw new ArgumentNullException(nameof(plaintextHeaderBlock));
 }
Example #5
0
        public override int GetHashCode()
        {
            var hashCode = 2040108761;

            hashCode = hashCode * -1521134295 + PartialKey.GetHashCode();
            hashCode = hashCode * -1521134295 + B0Blocks.Count().GetHashCode();
            hashCode = hashCode * -1521134295 + SequentialBlocks.Count().GetHashCode();
            return(hashCode);
        }
Example #6
0
 private RecoveryState(RecoveryState parent, PartialKey partialKey, Block partiallyDecryptedBlock)
     : this(
         parent : parent,
         partialKey : partialKey,
         b0Blocks : parent.B0Blocks,
         sequentialBlocks : parent.SequentialBlocks,
         encryptedHeaderBlock : partiallyDecryptedBlock,
         plaintextHeaderBlock : parent.PlaintextHeaderBlock)
 {
 }
Example #7
0
 private RecoveryState(PartialKey partialKey, IEnumerable <Block> b0Blocks, IEnumerable <Block> sequentialBlocks, Block encryptedHeaderBlock, Block plaintextHeaderBlock)
     : this(
         parent : null,
         partialKey : partialKey,
         b0Blocks : b0Blocks,
         sequentialBlocks : sequentialBlocks,
         encryptedHeaderBlock : encryptedHeaderBlock,
         plaintextHeaderBlock : plaintextHeaderBlock)
 {
 }
Example #8
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
        public int CompareTo(RecoveryState other)
        {
            int cmp = other.B0Blocks.Count() - B0Blocks.Count();

            if (cmp == 0)
            {
                cmp = other.SequentialBlocks.Count() - SequentialBlocks.Count();

                if (cmp == 0)
                {
                    cmp = PartialKey.CompareTo(other.PartialKey);
                }
            }

            return(cmp);
        }
Example #9
0
 public override string ToString()
 {
     return($"RecoveryState({B0Blocks.Count()},{SequentialBlocks.Count()},{PartialKey.ToString()})");
 }