Exemple #1
0
        public void Squeeze(sbyte[] trits, int offset, int?length)
        {
            if (!length.HasValue)
            {
                length = trits.Length;
            }

            if (((length % 243) != 0))
            {
                throw new Exception("Illegal length provided");
            }
            do
            {
                // get the hash digest
                var    kCopy = (Sha3Digest)sha3Digest.Copy();
                byte[] final = new byte[Curl.HASH_LENGTH * 4];
                var    fLen  = kCopy.DoFinal(final, 0);
                final = final.Take(fLen).ToArray();

                // Convert words to trits and then map it into the internal state
                var trit_state = Words.words_to_trits(ConvertToInt32Array(final));

                var i     = 0;
                var limit = (length < Curl.HASH_LENGTH ? length : Curl.HASH_LENGTH);

                while (i < limit)
                {
                    trits[offset++] = trit_state[i++];
                }

                sha3Digest.Reset();

                for (i = 0; i < final.Length; i++)
                {
                    final[i] = (byte)(final[i] ^ 0xFF); //(byte)(final[i] ^ 0xFFFFFFFF);
                }

                sha3Digest.BlockUpdate(final, 0, final.Length);
            } while ((length -= Curl.HASH_LENGTH) > 0);
        }