Example #1
0
 internal Bit(SpongeState state, int x, int y, int z)
 {
     State = state;
     X     = x;
     Y     = y;
     Z     = z;
 }
Example #2
0
        private static SpongeState Theta(SpongeState state)
        {
            int w = state.Size.W;

            bool[,] c = new bool[5, w];
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < w; z++)
                {
                    c[x, z] = state.GetColumn(x, z).GetBits().Aggregate((bool lhs, bool rhs) => { return(lhs ^ rhs); });
                }
            }
            bool[,] d = new bool[5, w];
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < w; z++)
                {
                    d[x, z] = c[Bin.Mod(x - 1, 5), z] ^ c[Bin.Mod(x + 1, 5), Bin.Mod(z - 1, w)];
                }
            }
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < w; z++)
                {
                    bool bit = d[x, z];
                    for (int y = 0; y < 5; y++)
                    {
                        state[x, y, z] ^= bit;
                    }
                }
            }
            return(state);
        }
Example #3
0
        private static SpongeState Pi(SpongeState state)
        {
            SpongeState newState = new SpongeState(state.Size, state.Rate);
            int         w        = state.Size.W;

            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    for (int z = 0; z < w; z++)
                    {
                        newState[x, y, z] = state[Bin.Mod(x + 3 * y, 5), x, z];
                    }
                }
            }
            state.SetBitstring(newState.Bitstring);
            return(state);
        }
Example #4
0
        private static SpongeState Khi(SpongeState state)
        {
            SpongeState newState = new SpongeState(state.Size, state.Rate);
            int         w        = state.Size.W;

            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    for (int z = 0; z < w; z++)
                    {
                        newState[x, y, z] = state[x, y, z]
                                            ^ ((state[Bin.Mod(x + 1, 5), y, z] ^ true) && state[Bin.Mod(x + 2, 5), y, z]);
                    }
                }
            }
            state.SetBitstring(newState.Bitstring);
            return(state);
        }
Example #5
0
        private static SpongeState Iota(SpongeState state, int round)
        {
            int       w  = state.Size.W;
            int       l  = state.Size.L;
            Bitstring rc = Bitstring.Zeroes(w);
            RoundT    roundT;
            int       t;
            int       rnd = 7 * round;

            for (int j = 0; j <= l; j++)
            {
                t      = j + rnd;
                roundT = new RoundT(round, t);
                if (!_roundTConstants.ContainsKey(roundT))
                {
                    _roundTConstants.Add(roundT, RoundConstant(t));
                }
                rc[(1 << j) - 1] = _roundTConstants[roundT];
            }
            state.XorLane(state.GetLane(0, 0), rc);
            return(state);
        }
Example #6
0
        private static SpongeState Rho(SpongeState state)
        {
            SpongeState newState = new SpongeState(state.Size, state.Rate);
            int         w        = state.Size.W;

            newState.SetLane(newState.GetLane(0, 0), state.GetLane(0, 0).GetBits());
            int x = 1;
            int y = 0;
            int u, oldX;

            for (int t = 0; t < 24; t++)
            {
                u = ((t + 1) * (t + 2)) >> 1;
                for (int z = 0; z < w; z++)
                {
                    newState[x, y, z] = state[x, y, Bin.Mod(z - u, w)];
                }
                oldX = x;
                x    = y;
                y    = Bin.Mod(2 * oldX + 3 * y, 5);
            }
            state.SetBitstring(newState.Bitstring);
            return(state);
        }
Example #7
0
 /// <summary>
 /// Creates a new <see cref="SpongeState"/> from an existing one.
 /// </summary>
 /// <param name="state">The sponge state to copy.</param>
 public SpongeState(SpongeState state)
 {
     _size      = state._size;
     _rate      = state._rate;
     _bitstring = new Bitstring(state._bitstring);
 }
Example #8
0
 internal Slice(SpongeState state, int z)
 {
     State = state;
     Z     = z;
 }
Example #9
0
 internal Sheet(SpongeState state, int x)
 {
     State = state;
     X     = x;
 }
Example #10
0
 internal Plane(SpongeState state, int y)
 {
     State = state;
     Y     = y;
 }
Example #11
0
 internal Lane(SpongeState state, int x, int y)
 {
     State = state;
     X     = x;
     Y     = y;
 }
Example #12
0
 internal Column(SpongeState state, int x, int z)
 {
     State = state;
     X     = x;
     Z     = z;
 }
Example #13
0
 internal Row(SpongeState state, int y, int z)
 {
     State = state;
     Y     = y;
     Z     = z;
 }