permutations.h 3.09 KB
Newer Older
lwc-tester committed
1 2 3
#ifndef PERMUTATIONS_H_
#define PERMUTATIONS_H_

Martin Schläffer committed
4
#include <stdint.h>
lwc-tester committed
5

Martin Schläffer committed
6 7 8
#include "ascon.h"
#include "printstate.h"
#include "round.h"
lwc-tester committed
9

Martin Schläffer committed
10 11 12
#define ASCON_128_KEYBYTES 16
#define ASCON_128A_KEYBYTES 16
#define ASCON_80PQ_KEYBYTES 20
lwc-tester committed
13

Martin Schläffer committed
14 15
#define ASCON_128_RATE 8
#define ASCON_128A_RATE 16
Enrico Pozzobon committed
16
#define ASCON_HASH_RATE 8
lwc-tester committed
17

Martin Schläffer committed
18 19
#define ASCON_128_PA_ROUNDS 12
#define ASCON_128_PB_ROUNDS 6
Enrico Pozzobon committed
20 21

#define ASCON_128A_PA_ROUNDS 12
Martin Schläffer committed
22
#define ASCON_128A_PB_ROUNDS 8
lwc-tester committed
23

Enrico Pozzobon committed
24 25 26 27 28 29
#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
30
#define ASCON_HASH_BYTES 32
lwc-tester committed
31

Martin Schläffer committed
32 33 34 35 36
#define ASCON_128_IV                            \
  (((uint64_t)(ASCON_128_KEYBYTES * 8) << 56) | \
   ((uint64_t)(ASCON_128_RATE * 8) << 48) |     \
   ((uint64_t)(ASCON_128_PA_ROUNDS) << 40) |    \
   ((uint64_t)(ASCON_128_PB_ROUNDS) << 32))
lwc-tester committed
37

Enrico Pozzobon committed
38 39 40 41
#define ASCON_128A_IV                            \
  (((uint64_t)(ASCON_128A_KEYBYTES * 8) << 56) | \
   ((uint64_t)(ASCON_128A_RATE * 8) << 48) |     \
   ((uint64_t)(ASCON_128A_PA_ROUNDS) << 40) |    \
Martin Schläffer committed
42
   ((uint64_t)(ASCON_128A_PB_ROUNDS) << 32))
lwc-tester committed
43

Martin Schläffer committed
44 45 46 47 48
#define ASCON_80PQ_IV                            \
  (((uint64_t)(ASCON_80PQ_KEYBYTES * 8) << 56) | \
   ((uint64_t)(ASCON_128_RATE * 8) << 48) |      \
   ((uint64_t)(ASCON_128_PA_ROUNDS) << 40) |     \
   ((uint64_t)(ASCON_128_PB_ROUNDS) << 32))
lwc-tester committed
49

Enrico Pozzobon committed
50 51 52 53 54 55 56 57 58 59
#define ASCON_HASH_IV                                                \
  (((uint64_t)(ASCON_HASH_RATE * 8) << 48) |                         \
   ((uint64_t)(ASCON_HASH_PA_ROUNDS) << 40) |                        \
   ((uint64_t)(ASCON_HASH_PA_ROUNDS - ASCON_HASH_PB_ROUNDS) << 32) | \
   ((uint64_t)(ASCON_HASH_BYTES * 8) << 0))

#define ASCON_HASHA_IV                                                 \
  (((uint64_t)(ASCON_HASH_RATE * 8) << 48) |                           \
   ((uint64_t)(ASCON_HASHA_PA_ROUNDS) << 40) |                         \
   ((uint64_t)(ASCON_HASHA_PA_ROUNDS - ASCON_HASHA_PB_ROUNDS) << 32) | \
Martin Schläffer committed
60
   ((uint64_t)(ASCON_HASH_BYTES * 8) << 0))
lwc-tester committed
61

Enrico Pozzobon committed
62 63 64 65 66 67 68 69 70
#define ASCON_XOF_IV                          \
  (((uint64_t)(ASCON_HASH_RATE * 8) << 48) |  \
   ((uint64_t)(ASCON_HASH_PA_ROUNDS) << 40) | \
   ((uint64_t)(ASCON_HASH_PA_ROUNDS - ASCON_HASH_PB_ROUNDS) << 32))

#define ASCON_XOFA_IV                          \
  (((uint64_t)(ASCON_HASH_RATE * 8) << 48) |   \
   ((uint64_t)(ASCON_HASHA_PA_ROUNDS) << 40) | \
   ((uint64_t)(ASCON_HASHA_PA_ROUNDS - ASCON_HASHA_PB_ROUNDS) << 32))
Martin Schläffer committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

static inline void P12(state_t* s) {
  printstate(" permutation input", s);
  ROUND(s, 0xf0);
  ROUND(s, 0xe1);
  ROUND(s, 0xd2);
  ROUND(s, 0xc3);
  ROUND(s, 0xb4);
  ROUND(s, 0xa5);
  ROUND(s, 0x96);
  ROUND(s, 0x87);
  ROUND(s, 0x78);
  ROUND(s, 0x69);
  ROUND(s, 0x5a);
  ROUND(s, 0x4b);
lwc-tester committed
86 87
}

Martin Schläffer committed
88 89 90 91 92 93 94 95 96 97
static inline void P8(state_t* s) {
  printstate(" permutation input", s);
  ROUND(s, 0xb4);
  ROUND(s, 0xa5);
  ROUND(s, 0x96);
  ROUND(s, 0x87);
  ROUND(s, 0x78);
  ROUND(s, 0x69);
  ROUND(s, 0x5a);
  ROUND(s, 0x4b);
lwc-tester committed
98 99
}

Martin Schläffer committed
100 101 102 103 104 105 106 107 108
static inline void P6(state_t* s) {
  printstate(" permutation input", s);
  ROUND(s, 0x96);
  ROUND(s, 0x87);
  ROUND(s, 0x78);
  ROUND(s, 0x69);
  ROUND(s, 0x5a);
  ROUND(s, 0x4b);
}
lwc-tester committed
109

Martin Schläffer committed
110
#endif /* PERMUTATIONS_H_ */