示例#1
0
        /// <summary>
        /// <para>Do final processing and get the hash value.
        /// Note: Digest is not reset after calling DoFinal.
        /// <see cref="Reset()"/> must be called before a new hash can be generated.</para>
        /// </summary>
        ///
        /// <param name="Output">The Hash value container</param>
        /// <param name="OutOffset">The starting offset within the Output array</param>
        ///
        /// <returns>Size of Hash value</returns>
        ///
        /// <exception cref="CryptoHashException">Thrown if Output array is too small</exception>
        public int DoFinal(byte[] Output, int OutOffset)
        {
            if (Output.Length - OutOffset < DigestSize)
            {
                throw new CryptoHashException("Skein256:DoFinal", "The Output buffer is too short!", new ArgumentOutOfRangeException());
            }

            // pad left over space in input buffer with zeros
            for (int i = m_bytesFilled; i < m_inputBuffer.Length; i++)
            {
                m_inputBuffer[i] = 0;
            }
            // copy to cipher input buffer
            for (int i = 0; i < STATE_WORDS; i++)
            {
                m_cipherInput[i] = BytesToUInt64(m_inputBuffer, i * 8);
            }

            // do final message block
            m_ubiParameters.IsFinalBlock = true;
            ProcessBlock(m_bytesFilled);

            // clear cipher input
            Array.Clear(m_cipherInput, 0, m_cipherInput.Length);
            // do output block counter mode output
            byte[]  hash     = new byte[m_outputBytes];
            ulong[] oldState = new ulong[STATE_WORDS];
            // save old state
            Array.Copy(m_digestState, oldState, m_digestState.Length);

            for (int i = 0; i < m_outputBytes; i += STATE_BYTES)
            {
                m_ubiParameters.StartNewBlockType(UbiType.Out);
                m_ubiParameters.IsFinalBlock = true;
                ProcessBlock(8);

                // output a chunk of the hash
                int outputSize = m_outputBytes - i;
                if (outputSize > STATE_BYTES)
                {
                    outputSize = STATE_BYTES;
                }

                PutBytes(m_digestState, hash, i, outputSize);
                // restore old state
                Array.Copy(oldState, m_digestState, oldState.Length);
                // increment counter
                m_cipherInput[0]++;
            }

            Buffer.BlockCopy(hash, 0, Output, OutOffset, hash.Length);

            return(hash.Length);
        }
示例#2
0
        /// <remarks>
        /// Default generation function
        /// </remarks>
        private void GenerateConfiguration()
        {
            Threefish512 cipher = new Threefish512();
            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];
        }
示例#3
0
        /// <remarks>
        /// Default generation function
        /// </remarks>
        private void GenerateConfiguration()
        {
            var cipher = new Threefish256();
            var tweak  = new UbiTweak();

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

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

            ConfigValue[0] ^= ConfigString[0];
            ConfigValue[1] ^= ConfigString[1];
            ConfigValue[2] ^= ConfigString[2];
        }
示例#4
0
        /// <remarks>
        /// Default generation function
        /// </remarks>
        private void GenerateConfiguration()
        {
            var cipher = new Threefish512();
            var tweak = new UbiTweak();

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

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

            ConfigValue[0] ^= ConfigString[0];
            ConfigValue[1] ^= ConfigString[1];
            ConfigValue[2] ^= ConfigString[2];
        }