permutations.c 968 Bytes
Newer Older
Christoph Dobraunig committed
1 2
#include "permutations.h"

Martin Schläffer committed
3
#include "round.h"
Christoph Dobraunig committed
4

Martin Schläffer committed
5 6 7 8 9 10 11 12 13 14 15
#if !ASCON_UNROLL_LOOPS || ASCON_SINGLE_PERM

const uint8_t constants[][2] = {{0xc, 0xc}, {0x9, 0xc}, {0xc, 0x9}, {0x9, 0x9},
                                {0x6, 0xc}, {0x3, 0xc}, {0x6, 0x9}, {0x3, 0x9},
                                {0xc, 0x6}, {0x9, 0x6}, {0xc, 0x3}, {0x9, 0x3}};

#endif

#if ASCON_INLINE_PERM

#elif ASCON_SINGLE_PERM
Christoph Dobraunig committed
16

Martin Schläffer committed
17 18 19 20
void P(state_t* s, uint8_t rounds) {
  printstate(" permutation input", s);
  for (int i = START(rounds); i < 12; i++)
    ROUND(s, constants[i][0], constants[i][1]);
Christoph Dobraunig committed
21
}
Martin Schläffer committed
22 23 24

#else /* !ASCON_INLINE_PERM && !ASCON_SINGLE_PERM */

Martin Schläffer committed
25 26 27 28
void P12(state_t* s) {
  printstate(" permutation input", s);
  P12ROUNDS(s);
}
Martin Schläffer committed
29 30

#if defined(CRYPTO_ABYTES) && ASCON_RATE == 16
Martin Schläffer committed
31 32 33 34
void P8(state_t* s) {
  printstate(" permutation input", s);
  P8ROUNDS(s);
}
Martin Schläffer committed
35 36 37
#endif

#if defined(CRYPTO_ABYTES) && ASCON_RATE == 8
Martin Schläffer committed
38 39 40 41
void P6(state_t* s) {
  printstate(" permutation input", s);
  P6ROUNDS(s);
}
Martin Schläffer committed
42 43 44
#endif

#endif