round.h 4.31 KB
Newer Older
Martin Schläffer committed
1 2 3 4 5 6
#ifndef ROUND_H_
#define ROUND_H_

#include "ascon.h"
#include "printstate.h"

Enrico Pozzobon committed
7
forceinline void KINIT(word_t* K0, word_t* K1, word_t* K2) {
Martin Schläffer committed
8 9 10 11 12
  *K0 = WORD_T(0);
  *K1 = WORD_T(0);
  *K2 = WORD_T(0);
}

Enrico Pozzobon committed
13
forceinline void PINIT(state_t* s) {
Martin Schläffer committed
14 15 16 17 18 19 20
  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);
}

Enrico Pozzobon committed
21
forceinline void ROUND(state_t* s, word_t C) {
Martin Schläffer committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  uint32_t tmp0, tmp1, tmp2, tmp3;
  /* clang-format off */
  __asm__ __volatile__(                            \
      "eor %[x2_e], %[x2_e], %[C_e]\n\t"           \
      "eor %[x2_o], %[x2_o], %[C_o]\n\t"           \
      "eor %[x0_e], %[x0_e], %[x4_e]\n\t"          \
      "eor %[x0_o], %[x0_o], %[x4_o]\n\t"          \
      "eor %[x4_e], %[x4_e], %[x3_e]\n\t"          \
      "eor %[x4_o], %[x4_o], %[x3_o]\n\t"          \
      "eor %[x2_e], %[x2_e], %[x1_e]\n\t"          \
      "eor %[x2_o], %[x2_o], %[x1_o]\n\t"          \
      "bic %[tmp0], %[x0_e], %[x4_e]\n\t"          \
      "bic %[tmp1], %[x4_e], %[x3_e]\n\t"          \
      "bic %[tmp2], %[x2_e], %[x1_e]\n\t"          \
      "bic %[tmp3], %[x1_e], %[x0_e]\n\t"          \
      "eor %[x2_e], %[x2_e], %[tmp1]\n\t"          \
      "eor %[x0_e], %[x0_e], %[tmp2]\n\t"          \
      "eor %[x4_e], %[x4_e], %[tmp3]\n\t"          \
      "bic %[tmp3], %[x3_e], %[x2_e]\n\t"          \
      "eor %[x3_e], %[x3_e], %[tmp0]\n\t"          \
      "bic %[tmp2], %[x0_o], %[x4_o]\n\t"          \
      "bic %[tmp0], %[x2_o], %[x1_o]\n\t"          \
      "bic %[tmp1], %[x4_o], %[x3_o]\n\t"          \
      "eor %[x1_e], %[x1_e], %[tmp3]\n\t"          \
      "eor %[x0_o], %[x0_o], %[tmp0]\n\t"          \
      "eor %[x2_o], %[x2_o], %[tmp1]\n\t"          \
      "bic %[tmp3], %[x1_o], %[x0_o]\n\t"          \
      "bic %[tmp0], %[x3_o], %[x2_o]\n\t"          \
      "eor %[x3_o], %[x3_o], %[tmp2]\n\t"          \
      "eor %[x3_o], %[x3_o], %[x2_o]\n\t"          \
      "eor %[x4_o], %[x4_o], %[tmp3]\n\t"          \
      "eor %[x1_o], %[x1_o], %[tmp0]\n\t"          \
      "eor %[x3_e], %[x3_e], %[x2_e]\n\t"          \
      "eor %[x1_e], %[x1_e], %[x0_e]\n\t"          \
      "eor %[x1_o], %[x1_o], %[x0_o]\n\t"          \
      "eor %[x0_e], %[x0_e], %[x4_e]\n\t"          \
      "eor %[x0_o], %[x0_o], %[x4_o]\n\t"          \
      "mvn %[x2_e], %[x2_e]\n\t"                   \
      "mvn %[x2_o], %[x2_o]\n\t"                   \
      "eor %[tmp0], %[x0_e], %[x0_o], ror #4\n\t"  \
      "eor %[tmp1], %[x0_o], %[x0_e], ror #5\n\t"  \
      "eor %[tmp2], %[x1_e], %[x1_e], ror #11\n\t" \
      "eor %[tmp3], %[x1_o], %[x1_o], ror #11\n\t" \
      "eor %[x0_e], %[x0_e], %[tmp1], ror #9\n\t"  \
      "eor %[x0_o], %[x0_o], %[tmp0], ror #10\n\t" \
      "eor %[x1_e], %[x1_e], %[tmp3], ror #19\n\t" \
      "eor %[x1_o], %[x1_o], %[tmp2], ror #20\n\t" \
      "eor %[tmp0], %[x2_e], %[x2_o], ror #2\n\t"  \
      "eor %[tmp1], %[x2_o], %[x2_e], ror #3\n\t"  \
      "eor %[tmp2], %[x3_e], %[x3_o], ror #3\n\t"  \
      "eor %[tmp3], %[x3_o], %[x3_e], ror #4\n\t"  \
      "eor %[x2_e], %[x2_e], %[tmp1]\n\t"          \
      "eor %[x2_o], %[x2_o], %[tmp0], ror #1\n\t"  \
      "eor %[x3_e], %[x3_e], %[tmp2], ror #5\n\t"  \
      "eor %[x3_o], %[x3_o], %[tmp3], ror #5\n\t"  \
      "eor %[tmp0], %[x4_e], %[x4_e], ror #17\n\t" \
      "eor %[tmp1], %[x4_o], %[x4_o], ror #17\n\t" \
      "eor %[x4_e], %[x4_e], %[tmp1], ror #3\n\t"  \
      "eor %[x4_o], %[x4_o], %[tmp0], ror #4\n\t"  \
      : [ x0_e ] "+r"(s->x0.e),                    \
        [ x1_e ] "+r"(s->x1.e),                    \
        [ x2_e ] "+r"(s->x2.e),                    \
        [ x3_e ] "+r"(s->x3.e),                    \
        [ x4_e ] "+r"(s->x4.e),                    \
        [ x0_o ] "+r"(s->x0.o),                    \
        [ x1_o ] "+r"(s->x1.o),                    \
        [ x2_o ] "+r"(s->x2.o),                    \
        [ x3_o ] "+r"(s->x3.o),                    \
        [ x4_o ] "+r"(s->x4.o),                    \
        [ tmp0 ] "=r"(tmp0),                       \
        [ tmp1 ] "=r"(tmp1),                       \
        [ tmp2 ] "=r"(tmp2),                       \
        [ tmp3 ] "=r"(tmp3)                        \
Enrico Pozzobon committed
95 96
      : [ C_e ] "ri"(C.e),                         \
        [ C_o ] "ri"(C.o)                          \
Martin Schläffer committed
97 98 99 100 101 102
      : );
  /* clang-format on */
  printstate(" round output", s);
}

#endif /* ROUND_H_ */