示例#1
0
        private static void Block(ChaCha20 chacha20)
        {
            var temp = chacha20.Copy();

            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);
            FullRound(temp);

            unchecked
            {
                chacha20.State0 += temp.State0;
                chacha20.State1 += temp.State1;
                chacha20.State2 += temp.State2;
                chacha20.State3 += temp.State3;
                chacha20.State4 += temp.State4;
                chacha20.State5 += temp.State5;
                chacha20.State6 += temp.State6;
                chacha20.State7 += temp.State7;
                chacha20.State8 += temp.State8;
                chacha20.State9 += temp.State9;
                chacha20.StateA += temp.StateA;
                chacha20.StateB += temp.StateB;
                chacha20.StateC += temp.StateC;
                chacha20.StateD += temp.StateD;
                chacha20.StateE += temp.StateE;
                chacha20.StateF += temp.StateF;
            }
        }
示例#2
0
 private static void FullRound(ChaCha20 chacha20)
 {
     QuarterRound(ref chacha20.State0, ref chacha20.State4, ref chacha20.State8, ref chacha20.StateC);
     QuarterRound(ref chacha20.State1, ref chacha20.State5, ref chacha20.State9, ref chacha20.StateD);
     QuarterRound(ref chacha20.State2, ref chacha20.State6, ref chacha20.StateA, ref chacha20.StateE);
     QuarterRound(ref chacha20.State3, ref chacha20.State7, ref chacha20.StateB, ref chacha20.StateF);
     QuarterRound(ref chacha20.State0, ref chacha20.State5, ref chacha20.StateA, ref chacha20.StateF);
     QuarterRound(ref chacha20.State1, ref chacha20.State6, ref chacha20.StateB, ref chacha20.StateC);
     QuarterRound(ref chacha20.State2, ref chacha20.State7, ref chacha20.State8, ref chacha20.StateD);
     QuarterRound(ref chacha20.State3, ref chacha20.State4, ref chacha20.State9, ref chacha20.StateE);
 }
示例#3
0
        internal ChaCha20 Copy()
        {
            var temp = new ChaCha20()
            {
                State0 = State0,
                State1 = State1,
                State2 = State2,
                State3 = State3,
                State4 = State4,
                State5 = State5,
                State6 = State6,
                State7 = State7,
                State8 = State8,
                State9 = State9,
                StateA = StateA,
                StateB = StateB,
                StateC = StateC,
                StateD = StateD,
                StateE = StateE,
                StateF = StateF
            };

            return(temp);
        }