Exemple #1
0
 private void Dispose(bool Disposing)
 {
     if (!_isDisposed && Disposing)
     {
         try
         {
             if (_blockCipher != null)
             {
                 _blockCipher.Clear();
                 _blockCipher = null;
             }
             if (_cipherInput != null)
             {
                 Array.Clear(_cipherInput, 0, _cipherInput.Length);
                 _cipherInput = null;
             }
             if (_digestState != null)
             {
                 Array.Clear(_digestState, 0, _digestState.Length);
                 _digestState = null;
             }
         }
         finally
         {
             _isDisposed = true;
         }
     }
 }
Exemple #2
0
        public void GenerateConfiguration(UInt64[] InitialState)
        {
            var cipher = new Threefish1024();
            var tweak = new UbiTweak();

            // Initialize the tweak value
            tweak.StartNewBlockType(UbiType.Config);
            tweak.IsFinalBlock = true;
            tweak.BitsProcessed = 32;

            cipher.SetKey(InitialState);
            cipher.SetTweak(tweak.Tweak);
            cipher.Encrypt(ConfigString, ConfigValue);

            ConfigValue[0] ^= ConfigString[0];
            ConfigValue[1] ^= ConfigString[1];
            ConfigValue[2] ^= ConfigString[2];
        }
Exemple #3
0
        /// <summary>
        /// Initializes the Skein hash instance
        /// </summary>
        /// 
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein1024(SkeinInitializationType InitializationType = SkeinInitializationType.Normal)
        {
            this.InitializationType = InitializationType;

            _cipherStateBits = STATE_SIZE;
            _cipherStateBytes = STATE_SIZE / 8;
            _cipherStateWords = STATE_SIZE / 64;
            _outputBytes = (STATE_SIZE + 7) / 8;
            _blockCipher = new Threefish1024();

            // Allocate buffers
            _inputBuffer = new byte[_cipherStateBytes];
            _cipherInput = new UInt64[_cipherStateWords];
            _digestState = new UInt64[_cipherStateWords];

            // Allocate tweak
            UbiParameters = new UbiTweak();

            // Generate the configuration string
            SkeinConfig();
            SetSchema(83, 72, 65, 51); // "SHA3"
            SetVersion(1);
            GenerateConfiguration();
            Initialize(InitializationType);
        }