示例#1
0
 public FrameMacProcessor(PublicKey remoteNodeId, EncryptionSecrets secrets)
 {
     _remoteNodeId          = remoteNodeId;
     _macSecret             = secrets.MacSecret;
     _egressMac             = secrets.EgressMac;
     _egressMacCopy         = (KeccakDigest)_egressMac.Copy();
     _ingressMac            = secrets.IngressMac;
     _ingressMacCopy        = (KeccakDigest)_ingressMac.Copy();
     _aesEngine             = MakeMacCipher();
     _checkMacBuffer        = new byte[_ingressMac.GetDigestSize()];
     _addMacBuffer          = new byte[_ingressMac.GetDigestSize()];
     _ingressAesBlockBuffer = new byte[_ingressMac.GetDigestSize()];
     _egressAesBlockBuffer  = new byte[_ingressMac.GetDigestSize()];
 }
示例#2
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[48];
                var    fLen  = kCopy.DoFinal(final, 0);

                // 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);
        }