#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) { uint32_t tmp_e, tmp_o; /* 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; tmp_e = s->x0.e & (~s->x4.e); tmp_o = s->x0.o & (~s->x4.o); s->x0.e ^= s->x2.e & (~s->x1.e); s->x0.o ^= s->x2.o & (~s->x1.o); s->x2.e ^= s->x4.e & (~s->x3.e); s->x2.o ^= s->x4.o & (~s->x3.o); s->x4.e ^= s->x1.e & (~s->x0.e); s->x4.o ^= s->x1.o & (~s->x0.o); s->x1.e ^= s->x3.e & (~s->x2.e); s->x1.o ^= s->x3.o & (~s->x2.o); s->x3.e ^= tmp_e; s->x3.o ^= tmp_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 */ tmp_e = s->x0.e ^ ROR32(s->x0.o, 4); tmp_o = s->x0.o ^ ROR32(s->x0.e, 5); s->x0.e ^= ROR32(tmp_o, 9); s->x0.o ^= ROR32(tmp_e, 10); tmp_e = s->x1.e ^ ROR32(s->x1.e, 11); tmp_o = s->x1.o ^ ROR32(s->x1.o, 11); s->x1.e ^= ROR32(tmp_o, 19); s->x1.o ^= ROR32(tmp_e, 20); tmp_e = s->x2.e ^ ROR32(s->x2.o, 2); tmp_o = s->x2.o ^ ROR32(s->x2.e, 3); s->x2.e ^= tmp_o; s->x2.o ^= ROR32(tmp_e, 1); tmp_e = s->x3.e ^ ROR32(s->x3.o, 3); tmp_o = s->x3.o ^ ROR32(s->x3.e, 4); s->x3.e ^= ROR32(tmp_e, 5); s->x3.o ^= ROR32(tmp_o, 5); tmp_e = s->x4.e ^ ROR32(s->x4.e, 17); tmp_o = s->x4.o ^ ROR32(s->x4.o, 17); s->x4.e ^= ROR32(tmp_o, 3); s->x4.o ^= ROR32(tmp_e, 4); s->x2.e = ~s->x2.e; s->x2.o = ~s->x2.o; printstate(" round output", s); } #endif /* ROUND_H_ */