public void AcceptBlock(ISBlock block)
 {
     if(HeadBlock == null)
     {
         HeadBlock = block;
         HeadBlock.PreviousBlockHash = null;
     }
     CurrentBlock = block;
     Blocks.Add(block);
 }
Example #2
0
        public GostManager(byte[] key, byte[] iv, byte[] message, CipherTypes cipherType = CipherTypes.Substitution, SBlockTypes sBlockType = SBlockTypes.GOST)
        {
            released = false;
            _subKeys = new List <uint>();

            Key     = key;
            IV      = iv;
            Message = message;

            GenerateSubKeys();

            _sBlock = SBlockFactory.SBlock(sBlockType);
            _cipher = CipherFactory.Cipher(_iv, _subKeys, cipherType, _sBlock);
        }
Example #3
0
        public void SetBlockHash(ISBlock parent)
        {
            if (parent != null)
            {
                PreviousBlockHash = parent.BlockHash;
                parent.NextBlock  = this;
            }
            else
            {
                // Previous block is the genesis block.
                PreviousBlockHash = null;
            }

            BlockHash = CalculateBlockHash(PreviousBlockHash);
        }
Example #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!released)
            {
                if (disposing)
                {
                    _sBlock  = null;
                    _cipher  = null;
                    _iv      = null;
                    _key     = null;
                    _message = null;
                    _subKeys = null;
                }

                released = true;
            }
        }
Example #5
0
 public SBlock(int blockNumber,
               string claimNumber,
               decimal settlementAmount,
               DateTime settlementDate,
               string carRegistration,
               int mileage,
               ClaimType claimType,
               ISBlock parent)
 {
     BlockNumber      = blockNumber;
     ClaimNumber      = claimNumber;
     SettlementAmount = settlementAmount;
     SettlementDate   = settlementDate;
     CarRegistration  = carRegistration;
     Mileage          = mileage;
     ClaimType        = claimType;
     CreatedDate      = DateTime.UtcNow;
     SetBlockHash(parent);
 }
Example #6
0
 public SubstitutionCipher(ISBlock sBlock)
 {
     _sBlock = sBlock;
 }
Example #7
0
 public CbfCipher(byte[] iv, ISBlock sblock) : base(sblock)
 {
     SetIV(iv);
 }
Example #8
0
 public static ICipher Cipher(byte[] iv, List <uint> subKeys, CipherTypes cipher, ISBlock sBlock)
 {
     return(cipher switch
     {
         CipherTypes.Substitution => new SubstitutionCipher(sBlock),
         CipherTypes.Cfb => new CbfCipher(iv, sBlock),
         CipherTypes.Xor => new XorCipher(iv, subKeys, sBlock),
         _ => throw new ArgumentException(nameof(cipher)),
     });
Example #9
0
 public MacGenerator(ISBlock sBlock)
 {
     substitution = new SubstitutionCipher(sBlock);
 }
Example #10
0
 public XorCipher(byte[] iv, List <uint> subKeys, ISBlock sBlock) : base(sBlock)
 {
     SetIV(iv, subKeys);
 }