Esempio n. 1
0
        public void GenerateConfiguration()
        {
            ThreefishCipher cipher = ThreefishCipher.CreateCipher(m_StateSize);
            UBITweak tweak = new UBITweak();
            ulong[] initial_state = new ulong[m_ConfigValue.Length];

            // Initialize the tweak value
            tweak.StartNewType(UBIType.Config);
            tweak.SetFinalFlag(true);
            tweak.IncrementCount(32);

            cipher.SetKey(initial_state);
            cipher.SetTweak(tweak.Tweak);
            cipher.Encrypt(m_ConfigString, m_ConfigValue);

            m_ConfigValue[0] ^= m_ConfigString[0];
            m_ConfigValue[1] ^= m_ConfigString[1];
        }
Esempio n. 2
0
        public Skein(int state_size, int output_size)
        {
            // Make sure the output bit size > 0
            if (output_size <= 0)
                throw new CryptographicException("Output bit size must be greater than zero.");

            m_CipherStateBits = state_size;
            m_CipherStateBytes = state_size / 8;
            m_CipherStateWords = state_size / 64;

            base.HashSizeValue = output_size;
            m_OutputBytes = (output_size + 7) / 8;

            // Figure out which cipher we need based on
            // the state size
            m_Cipher = ThreefishCipher.CreateCipher(state_size);
            if (m_Cipher == null) throw new CryptographicException("Unsupported state size.");

            // Allocate buffers
            m_InputBuffer = new byte[m_CipherStateBytes];
            m_CipherInput = new ulong[m_CipherStateWords];
            m_State = new ulong[m_CipherStateWords];

            // Allocate tweak
            m_Tweak = new UBITweak();

            // Set default payload type (regular straight hashing)
            m_PayloadType = UBIType.Message;

            // Generate the configuration string
            m_Configuration = new SkeinConfig(this);
            m_Configuration.SetSchema("SHA3");
            m_Configuration.SetVersion(1);
            m_Configuration.GenerateConfiguration();

            // Initialize hash
            Initialize();
        }