#ifndef ROUND_H_ #define ROUND_H_ #include "ascon.h" #include "printstate.h" __forceinline void KINIT(word_t* K0, word_t* K1, word_t* K2) { *K0 = WORD_T(0); *K1 = WORD_T(0); *K2 = WORD_T(0); } __forceinline void PINIT(state_t* s) { s->x0 = WORD_T(0); s->x1 = WORD_T(0); s->x2 = WORD_T(0); s->x3 = WORD_T(0); s->x4 = WORD_T(0); } __forceinline void ROUND(state_t* s, uint32_t C_e, uint32_t C_o) { state_t t; /* round constant */ s->x2.e ^= C_e; s->x2.o ^= C_o; /* s-box layer */ s->x0.e ^= s->x4.e; s->x0.o ^= s->x4.o; s->x4.e ^= s->x3.e; s->x4.o ^= s->x3.o; s->x2.e ^= s->x1.e; s->x2.o ^= s->x1.o; t.x0.e = s->x0.e; t.x0.o = s->x0.o; t.x4.e = s->x4.e; t.x4.o = s->x4.o; t.x3.e = s->x3.e; t.x3.o = s->x3.o; t.x1.e = s->x1.e; t.x1.o = s->x1.o; t.x2.e = s->x2.e; t.x2.o = s->x2.o; s->x0.e = t.x0.e ^ (~t.x1.e & t.x2.e); s->x0.o = t.x0.o ^ (~t.x1.o & t.x2.o); s->x2.e = t.x2.e ^ (~t.x3.e & t.x4.e); s->x2.o = t.x2.o ^ (~t.x3.o & t.x4.o); s->x4.e = t.x4.e ^ (~t.x0.e & t.x1.e); s->x4.o = t.x4.o ^ (~t.x0.o & t.x1.o); s->x1.e = t.x1.e ^ (~t.x2.e & t.x3.e); s->x1.o = t.x1.o ^ (~t.x2.o & t.x3.o); s->x3.e = t.x3.e ^ (~t.x4.e & t.x0.e); s->x3.o = t.x3.o ^ (~t.x4.o & t.x0.o); s->x1.e ^= s->x0.e; s->x1.o ^= s->x0.o; s->x3.e ^= s->x2.e; s->x3.o ^= s->x2.o; s->x0.e ^= s->x4.e; s->x0.o ^= s->x4.o; /* linear layer */ t.x0.e = s->x0.e ^ ROR32(s->x0.o, 4); t.x0.o = s->x0.o ^ ROR32(s->x0.e, 5); t.x1.e = s->x1.e ^ ROR32(s->x1.e, 11); t.x1.o = s->x1.o ^ ROR32(s->x1.o, 11); t.x2.e = s->x2.e ^ ROR32(s->x2.o, 2); t.x2.o = s->x2.o ^ ROR32(s->x2.e, 3); t.x3.e = s->x3.e ^ ROR32(s->x3.o, 3); t.x3.o = s->x3.o ^ ROR32(s->x3.e, 4); t.x4.e = s->x4.e ^ ROR32(s->x4.e, 17); t.x4.o = s->x4.o ^ ROR32(s->x4.o, 17); s->x0.e ^= ROR32(t.x0.o, 9); s->x0.o ^= ROR32(t.x0.e, 10); s->x1.e ^= ROR32(t.x1.o, 19); s->x1.o ^= ROR32(t.x1.e, 20); s->x2.e ^= t.x2.o; s->x2.o ^= ROR32(t.x2.e, 1); s->x3.e ^= ROR32(t.x3.e, 5); s->x3.o ^= ROR32(t.x3.o, 5); s->x4.e ^= ROR32(t.x4.o, 3); s->x4.o ^= ROR32(t.x4.e, 4); s->x2.e = ~s->x2.e; s->x2.o = ~s->x2.o; printstate(" round output", s); } #endif /* ROUND_H_ */