Beispiel #1
0
        /// <summary>
        /// Creates the initial state with zeros instead of the configuration block, then initializes the hash.
        /// This does not start a new UBI block type, and must be done manually.
        /// </summary>
        public void Initialize(SkeinInitializationType initializationType)
        {
            switch (initializationType)
            {
            case SkeinInitializationType.Normal:
                Initialize();
                return;

            case SkeinInitializationType.ZeroedState:
                for (int i = 0; i < state.Length; i++)
                {
                    state[i] = 0;
                }
                break;

            case SkeinInitializationType.ChainedState:
                break;

            case SkeinInitializationType.ChainedConfig:
                Configuration.GenerateConfiguration(state);
                Initialize();
                return;
            }
            bytesFilled = 0;
        }
Beispiel #2
0
        /// <summary>
        /// Creates the initial state with zeros instead of the configuration block, then initializes the hash.
        /// This does not start a new UBI block type, and must be done manually.
        /// </summary>
        public void Initialize(SkeinInitializationType initializationType)
        {
            switch (initializationType)
            {
            case SkeinInitializationType.Normal:
                // Normal initialization
                Init(null);
                return;

            case SkeinInitializationType.ZeroedState:
                // Copy the configuration value to the state
                for (int i = 0; i < _state.Length; i++)
                {
                    _state[i] = 0;
                }
                break;

            case SkeinInitializationType.ChainedState:
                // Keep the state as it is and do nothing
                break;

            case SkeinInitializationType.ChainedConfig:
                // Generate a chained configuration
                Configuration.GenerateConfiguration(_state);
                // Continue initialization
                Init(null);
                return;
            }

            // Reset bytes filled
            _bytesFilled = 0;
        }
Beispiel #3
0
        /// <summary>
        /// Used to re-initialize the digest state.
        /// <para>Creates the initial state with zeros instead of the configuration block, then initializes the hash.
        /// This does not start a new UBI block type, and must be done manually.</para>
        /// </summary>
        ///
        /// <param name="InitializationType">Initialization parameters</param>
        public void Initialize(SkeinInitializationType InitializationType)
        {
            this.InitializationType = InitializationType;

            switch (InitializationType)
            {
            case SkeinInitializationType.Normal:
            {
                // normal initialization
                Initialize();
                return;
            }

            case SkeinInitializationType.ZeroedState:
            {
                // copy the configuration value to the state
                for (int i = 0; i < m_digestState.Length; i++)
                {
                    m_digestState[i] = 0;
                }

                break;
            }

            case SkeinInitializationType.ChainedConfig:
            {
                // generate a chained configuration
                GenerateConfiguration(m_digestState);
                // continue initialization
                Initialize();
                return;
            }

            case SkeinInitializationType.ChainedState:
                // keep the state as it is and do nothing
                break;
            }

            // reset bytes filled
            m_bytesFilled = 0;
        }
Beispiel #4
0
        /// <summary>
        /// Initializes the Skein hash instance
        /// </summary>
        ///
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein512(SkeinInitializationType InitializationType = SkeinInitializationType.Normal)
        {
            m_initializationType = InitializationType;
            m_blockCipher        = new Threefish512();
            // 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();
            // allocate config value
            m_configValue = new ulong[STATE_BYTES];
            // initialize and enerate the configuration string
            m_configString    = new ulong[STATE_BYTES];
            m_configString[1] = (ulong)DigestSize * 8;

            SetSchema(83, 72, 65, 51); // "SHA3"
            SetVersion(1);
            GenerateConfiguration();
            Initialize(InitializationType);
        }
Beispiel #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);
        }
Beispiel #6
0
        /// <summary>
        /// Used to re-initialize the digest state.
        /// <para>Creates the initial state with zeros instead of the configuration block, then initializes the hash. 
        /// This does not start a new UBI block type, and must be done manually.</para>
        /// </summary>
        /// 
        /// <param name="InitializationType">Initialization parameters</param>
        public void Initialize(SkeinInitializationType InitializationType)
        {
            this.InitializationType = InitializationType;

            switch (InitializationType)
            {
                case SkeinInitializationType.Normal:
                    // Normal initialization
                    Initialize();
                    return;

                case SkeinInitializationType.ZeroedState:
                    // Copy the configuration value to the state
                    for (int i = 0; i < _digestState.Length; i++)
                        _digestState[i] = 0;
                    break;

                case SkeinInitializationType.ChainedState:
                    // Keep the state as it is and do nothing
                    break;

                case SkeinInitializationType.ChainedConfig:
                    // Generate a chained configuration
                    GenerateConfiguration(_digestState);
                    // Continue initialization
                    Initialize();
                    return;
            }

            // Reset bytes filled
            _bytesFilled = 0;
        }
Beispiel #7
0
        /// <summary>
        /// Initializes the Skein hash instance
        /// </summary>
        /// 
        /// <param name="InitializationType">Digest initialization type <see cref="SkeinInitializationType"/></param>
        public Skein512(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 Threefish512();

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

            // Allocate tweak
            UbiParameters = new UbiTweak();

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