permutations.h 1.36 KB
Newer Older
Martin Schläffer committed
1 2 3 4 5 6 7
#ifndef PERMUTATIONS_H_
#define PERMUTATIONS_H_

#include <stdint.h>

#include "api.h"
#include "ascon.h"
Enrico Pozzobon committed
8
#include "config.h"
Martin Schläffer committed
9
#include "constants.h"
Martin Schläffer committed
10 11 12
#include "printstate.h"
#include "round.h"

Enrico Pozzobon committed
13
forceinline void P12ROUNDS(state_t* s) {
Martin Schläffer committed
14 15 16 17 18 19 20 21 22 23 24 25
  ROUND(s, RC0);
  ROUND(s, RC1);
  ROUND(s, RC2);
  ROUND(s, RC3);
  ROUND(s, RC4);
  ROUND(s, RC5);
  ROUND(s, RC6);
  ROUND(s, RC7);
  ROUND(s, RC8);
  ROUND(s, RC9);
  ROUND(s, RCa);
  ROUND(s, RCb);
Martin Schläffer committed
26 27
}

Enrico Pozzobon committed
28
forceinline void P8ROUNDS(state_t* s) {
Martin Schläffer committed
29 30 31 32 33 34 35 36
  ROUND(s, RC4);
  ROUND(s, RC5);
  ROUND(s, RC6);
  ROUND(s, RC7);
  ROUND(s, RC8);
  ROUND(s, RC9);
  ROUND(s, RCa);
  ROUND(s, RCb);
Martin Schläffer committed
37 38
}

Enrico Pozzobon committed
39
forceinline void P6ROUNDS(state_t* s) {
Martin Schläffer committed
40 41 42 43 44 45
  ROUND(s, RC6);
  ROUND(s, RC7);
  ROUND(s, RC8);
  ROUND(s, RC9);
  ROUND(s, RCa);
  ROUND(s, RCb);
Martin Schläffer committed
46 47
}

Enrico Pozzobon committed
48
#if ASCON_INLINE_PERM && ASCON_UNROLL_LOOPS
Martin Schläffer committed
49

Enrico Pozzobon committed
50 51 52 53
forceinline void P(state_t* s, int nr) {
  if (nr == 12) P12ROUNDS(s);
  if (nr == 8) P8ROUNDS(s);
  if (nr == 6) P6ROUNDS(s);
Martin Schläffer committed
54 55
}

Enrico Pozzobon committed
56
#elif !ASCON_INLINE_PERM && ASCON_UNROLL_LOOPS
Martin Schläffer committed
57

Enrico Pozzobon committed
58 59 60
void P12(state_t* s);
void P8(state_t* s);
void P6(state_t* s);
Martin Schläffer committed
61

Enrico Pozzobon committed
62 63 64 65
forceinline void P(state_t* s, int nr) {
  if (nr == 12) P12(s);
  if (nr == 8) P8(s);
  if (nr == 6) P6(s);
Martin Schläffer committed
66 67
}

Enrico Pozzobon committed
68
#elif ASCON_INLINE_PERM && !ASCON_UNROLL_LOOPS
Martin Schläffer committed
69

Enrico Pozzobon committed
70
forceinline void P(state_t* s, int nr) { PROUNDS(s, nr); }
Martin Schläffer committed
71

Enrico Pozzobon committed
72
#else /* !ASCON_INLINE_PERM && !ASCON_UNROLL_LOOPS */
Martin Schläffer committed
73

Enrico Pozzobon committed
74
void P(state_t* s, int nr);
Martin Schläffer committed
75 76 77 78

#endif

#endif /* PERMUTATIONS_H_ */