permutations.h 3.84 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 10 11 12 13 14 15 16 17
#include "printstate.h"
#include "round.h"

#define ASCON_128_KEYBYTES 16
#define ASCON_128A_KEYBYTES 16
#define ASCON_80PQ_KEYBYTES 20

#define ASCON_128_RATE 8
#define ASCON_128A_RATE 16
Enrico Pozzobon committed
18
#define ASCON_HASH_RATE 8
Martin Schläffer committed
19 20 21

#define ASCON_128_PA_ROUNDS 12
#define ASCON_128_PB_ROUNDS 6
Enrico Pozzobon committed
22 23

#define ASCON_128A_PA_ROUNDS 12
Martin Schläffer committed
24 25
#define ASCON_128A_PB_ROUNDS 8

Enrico Pozzobon committed
26 27 28 29 30 31
#define ASCON_HASH_PA_ROUNDS 12
#define ASCON_HASH_PB_ROUNDS 12

#define ASCON_HASHA_PA_ROUNDS 12
#define ASCON_HASHA_PB_ROUNDS 8

Martin Schläffer committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
#define ASCON_HASH_BYTES 32

#define ASCON_128_IV WORD_T(0x8040000020301000ull)
#define ASCON_128A_IV WORD_T(0xc000000030200000ull)
#define ASCON_80PQ_IV WORD_T(0x8040800020301000ull)
#define ASCON_HASH_IV WORD_T(0x0040000020200002ull)
#define ASCON_XOF_IV WORD_T(0x0040000020200000ull)

#define ASCON_HASH_IV0 WORD_T(0xfa8e976bb985dc4dull)
#define ASCON_HASH_IV1 WORD_T(0xc8085072a40ccd94ull)
#define ASCON_HASH_IV2 WORD_T(0xfe1781be5a847314ull)
#define ASCON_HASH_IV3 WORD_T(0x2f871f6c6d0082b2ull)
#define ASCON_HASH_IV4 WORD_T(0x7a1ba68850ec407eull)

Enrico Pozzobon committed
46 47 48 49 50 51
#define ASCON_HASHA_IV0 WORD_T(0x194c0f180a5d41e4ull)
#define ASCON_HASHA_IV1 WORD_T(0x7faa87825647f3a7ull)
#define ASCON_HASHA_IV2 WORD_T(0x606dbe06db8da430ull)
#define ASCON_HASHA_IV3 WORD_T(0xe0dd6bcf19fbce3bull)
#define ASCON_HASHA_IV4 WORD_T(0x9720dc4446473d8bull)

Martin Schläffer committed
52 53 54 55 56 57
#define ASCON_XOF_IV0 WORD_T(0x8a46f0d354e771b8ull)
#define ASCON_XOF_IV1 WORD_T(0x04489f4084368cd0ull)
#define ASCON_XOF_IV2 WORD_T(0x6c94f2150dbcf66cull)
#define ASCON_XOF_IV3 WORD_T(0x48965294f143b44eull)
#define ASCON_XOF_IV4 WORD_T(0x0788515fe0e5fb8aull)

Enrico Pozzobon committed
58 59 60 61 62
#define ASCON_XOFA_IV0 WORD_T(0x4ab43d4f16a80d2cull)
#define ASCON_XOFA_IV1 WORD_T(0xd0ae310bf0f619ceull)
#define ASCON_XOFA_IV2 WORD_T(0xc08cf3c801d89cf3ull)
#define ASCON_XOFA_IV3 WORD_T(0x3859d2094dac0b35ull)
#define ASCON_XOFA_IV4 WORD_T(0xd274992be52b5357ull)
Martin Schläffer committed
63 64

#define START(n) (12 - n)
Enrico Pozzobon committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#define RC(c) WORD_T(c)

forceinline void P12ROUNDS(state_t* s) {
  ROUND(s, RC(0x0101010100000000ull));
  ROUND(s, RC(0x0101010000000001ull));
  ROUND(s, RC(0x0101000100000100ull));
  ROUND(s, RC(0x0101000000000101ull));
  ROUND(s, RC(0x0100010100010000ull));
  ROUND(s, RC(0x0100010000010001ull));
  ROUND(s, RC(0x0100000100010100ull));
  ROUND(s, RC(0x0100000000010101ull));
  ROUND(s, RC(0x0001010101000000ull));
  ROUND(s, RC(0x0001010001000001ull));
  ROUND(s, RC(0x0001000101000100ull));
  ROUND(s, RC(0x0001000001000101ull));
Martin Schläffer committed
80 81
}

Enrico Pozzobon committed
82 83 84 85 86 87 88 89 90
forceinline void P8ROUNDS(state_t* s) {
  ROUND(s, RC(0x0100010100010000ull));
  ROUND(s, RC(0x0100010000010001ull));
  ROUND(s, RC(0x0100000100010100ull));
  ROUND(s, RC(0x0100000000010101ull));
  ROUND(s, RC(0x0001010101000000ull));
  ROUND(s, RC(0x0001010001000001ull));
  ROUND(s, RC(0x0001000101000100ull));
  ROUND(s, RC(0x0001000001000101ull));
Martin Schläffer committed
91 92
}

Enrico Pozzobon committed
93 94 95 96 97 98 99
forceinline void P6ROUNDS(state_t* s) {
  ROUND(s, RC(0x0100000100010100ull));
  ROUND(s, RC(0x0100000000010101ull));
  ROUND(s, RC(0x0001010101000000ull));
  ROUND(s, RC(0x0001010001000001ull));
  ROUND(s, RC(0x0001000101000100ull));
  ROUND(s, RC(0x0001000001000101ull));
Martin Schläffer committed
100 101 102 103
}

extern const uint64_t constants[12];

Enrico Pozzobon committed
104 105
forceinline void PROUNDS(state_t* s, int nr) {
  for (int i = START(nr); i < 12; i++) ROUND(s, RC(constants[i]));
Martin Schläffer committed
106 107
}

Enrico Pozzobon committed
108
#if ASCON_INLINE_PERM && ASCON_UNROLL_LOOPS
Martin Schläffer committed
109

Enrico Pozzobon committed
110 111 112 113
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
114 115
}

Enrico Pozzobon committed
116
#elif !ASCON_INLINE_PERM && ASCON_UNROLL_LOOPS
Martin Schläffer committed
117

Enrico Pozzobon committed
118 119 120
void P12(state_t* s);
void P8(state_t* s);
void P6(state_t* s);
Martin Schläffer committed
121

Enrico Pozzobon committed
122 123 124 125
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
126 127
}

Enrico Pozzobon committed
128
#elif ASCON_INLINE_PERM && !ASCON_UNROLL_LOOPS
Martin Schläffer committed
129

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

Enrico Pozzobon committed
132
#else /* !ASCON_INLINE_PERM && !ASCON_UNROLL_LOOPS */
Martin Schläffer committed
133

Enrico Pozzobon committed
134
void P(state_t* s, int nr);
Martin Schläffer committed
135 136 137 138

#endif

#endif /* PERMUTATIONS_H_ */