Beispiel #1
0
 /// <summary>
 /// Initializes the Skein hash instance.
 /// </summary>
 /// <param name="stateSize">The internal state size of the hash in bits.
 /// Supported values are 256, 512, and 1024.</param>
 /// <param name="outputSize">The output size of the hash in bits.
 /// Output size must be divisible by 8 and greater than zero.</param>
 public Skein(int stateSize, int outputSize)
 {
     if (outputSize <= 0)
     {
         throw new CryptographicException("Output bit size must be greater than zero.");
     }
     if (outputSize % 8 != 0)
     {
         throw new CryptographicException("Output bit size must be divisible by 8.");
     }
     cipherStateBits  = stateSize;
     cipherStateBytes = stateSize / 8;
     cipherStateWords = stateSize / 64;
     HashSizeValue    = outputSize;
     outputBytes      = (outputSize + 7) / 8;
     cipher           = ThreefishCipher.CreateCipher(stateSize);
     if (cipher == null)
     {
         throw new CryptographicException("Unsupported state size.");
     }
     inputBuffer   = new byte[cipherStateBytes];
     cipherInput   = new ulong[cipherStateWords];
     state         = new ulong[cipherStateWords];
     UbiParameters = new UbiTweak();
     Configuration = new SkeinConfig(this);
     Configuration.SetSchema(83, 72, 65, 51); // "SHA3"
     Configuration.SetVersion(1);
     Configuration.GenerateConfiguration();
     Initialize();
 }
Beispiel #2
0
        /// <summary>
        /// Initializes the Skein hash instance.
        /// </summary>
        /// <param name="stateSize">The internal state size of the hash in bits.
        /// Supported values are 256, 512, and 1024.</param>
        /// <param name="outputSize">The output size of the hash in bits.
        /// Output size must be divisible by 8 and greater than zero.</param>
        public Skein(int stateSize, int outputSize)
        {
            // Make sure the output bit size > 0
            if (outputSize <= 0)
            {
                throw new CryptographicException("Output bit size must be greater than zero.");
            }

            // Make sure output size is divisible by 8
            if (outputSize % 8 != 0)
            {
                throw new CryptographicException("Output bit size must be divisible by 8.");
            }

            _cipherStateBits  = stateSize;
            _cipherStateBytes = stateSize / 8;
            _cipherStateWords = stateSize / 64;

            base.HashSizeValue = outputSize;
            _outputBytes       = (outputSize + 7) / 8;

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

            // Allocate buffers
            _inputBuffer = new byte[_cipherStateBytes];
            _cipherInput = new ulong[_cipherStateWords];
            _state       = new ulong[_cipherStateWords];

            // Allocate tweak
            UbiParameters = new UbiTweak();

            // Generate the configuration string
            Configuration = new SkeinConfig(this);
            Configuration.SetSchema(83, 72, 65, 51); // "SHA3"
            Configuration.SetVersion(1);
            Configuration.GenerateConfiguration();
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the Skein hash instance.
        /// </summary>
        /// <param name="stateSize">The internal state size of the hash in bits.
        /// Supported values are 256, 512, and 1024.</param>
        /// <param name="outputSize">The output size of the hash in bits.
        /// Output size must be divisible by 8 and greater than zero.</param>
        public Skein(int stateSize, int outputSize)
        {
            // Make sure the output bit size > 0
            if (outputSize <= 0)
                throw new CryptographicException("Output bit size must be greater than zero.");

            // Make sure output size is divisible by 8
            if (outputSize % 8 != 0)
                throw new CryptographicException("Output bit size must be divisible by 8.");

            _cipherStateBits = stateSize;
            _cipherStateBytes = stateSize / 8;
            _cipherStateWords = stateSize / 64;

            base.HashSizeValue = outputSize;
            _outputBytes = (outputSize + 7) / 8;

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

            // Allocate buffers
            _inputBuffer = new byte[_cipherStateBytes];
            _cipherInput = new ulong[_cipherStateWords];
            _state = new ulong[_cipherStateWords];

            // Allocate tweak
            UbiParameters = new UbiTweak();

            // Generate the configuration string
            Configuration = new SkeinConfig(this);
            Configuration.SetSchema(83, 72, 65, 51); // "SHA3"
            Configuration.SetVersion(1);
            Configuration.GenerateConfiguration();
        }