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); }
internal Bit(SpongeState state, int x, int y, int z) { State = state; X = x; Y = y; Z = z; }
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); }
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); }
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); }
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); }
/// <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); }
internal Slice(SpongeState state, int z) { State = state; Z = z; }
internal Sheet(SpongeState state, int x) { State = state; X = x; }
internal Plane(SpongeState state, int y) { State = state; Y = y; }
internal Lane(SpongeState state, int x, int y) { State = state; X = x; Y = y; }
internal Column(SpongeState state, int x, int z) { State = state; X = x; Z = z; }
internal Row(SpongeState state, int y, int z) { State = state; Y = y; Z = z; }
/// <summary> /// Creates a new <see cref="SpongeConstruction"/>, specifying the size of the construction and its rate. /// </summary> /// <param name="size">The size of the sponge construction.</param> /// <param name="rate">The rate of the sponge construction.</param> protected SpongeConstruction(SpongeSize size, int rate) { State = new SpongeState(size, rate); }