Esempio n. 1
0
 private void Dispose(bool Disposing)
 {
     if (!m_isDisposed && Disposing)
     {
         try
         {
             if (m_blockCipher != null)
             {
                 m_blockCipher.Clear();
                 m_blockCipher = null;
             }
             if (m_cipherInput != null)
             {
                 Array.Clear(m_cipherInput, 0, m_cipherInput.Length);
                 m_cipherInput = null;
             }
             if (m_digestState != null)
             {
                 Array.Clear(m_digestState, 0, m_digestState.Length);
                 m_digestState = null;
             }
         }
         finally
         {
             m_isDisposed = true;
         }
     }
 }
Esempio n. 2
0
        /// <remarks>
        /// Default generation function
        /// </remarks>
        private void GenerateConfiguration()
        {
            Threefish256 cipher = new Threefish256();
            UbiTweak     tweak  = new UbiTweak();

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

            cipher.SetTweak(tweak.Tweak);
            cipher.Encrypt(m_configString, m_configValue);

            m_configValue[0] ^= m_configString[0];
            m_configValue[1] ^= m_configString[1];
            m_configValue[2] ^= m_configString[2];
        }
Esempio n. 3
0
        public void GenerateConfiguration(UInt64[] InitialState)
        {
            var cipher = new Threefish256();
            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];
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes the Skein hash instance.
        /// </summary>
        ///
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein256(SkeinInitializationType InitializationType = SkeinInitializationType.Normal)
        {
            m_initializationType = InitializationType;
            m_outputBytes        = (STATE_SIZE + 7) / 8;
            m_blockCipher        = new Threefish256();
            // allocate buffers
            m_inputBuffer = new byte[STATE_BYTES];
            m_cipherInput = new ulong[STATE_WORDS];
            m_digestState = new ulong[STATE_WORDS];
            // allocate tweak
            m_ubiParameters = new UbiTweak();
            // generate the configuration string
            // allocate config value
            m_configValue = new ulong[STATE_BYTES];
            // set the state size for the configuration
            m_configString    = new ulong[STATE_BYTES];
            m_configString[1] = (ulong)DigestSize * 8;

            SetSchema(83, 72, 65, 51); // "SHA3"
            SetVersion(1);
            GenerateConfiguration();
            Initialize(InitializationType);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes the Skein hash instance.
        /// </summary>
        ///
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein256(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 Threefish256();

            // 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);
        }
Esempio n. 6
0
        public void GenerateConfiguration(UInt64[] InitialState)
        {
            var cipher = new Threefish256();
            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];
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes the Skein hash instance.
        /// </summary>
        /// 
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein256(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 Threefish256();

            // 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);
        }
Esempio n. 8
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;
         }
     }
 }