update.c 777 Bytes
Newer Older
Martin Schlaeffer committed
1 2 3 4 5 6 7
#include "api.h"
#include "ascon.h"
#include "permutations.h"
#include "printstate.h"

void ascon_update(state_t* s, uint8_t* out, const uint8_t* in, uint64_t len,
                  uint8_t mode) {
Enrico Pozzobon committed
8 9
  const int rate = 8;
  const int nr = 6;
Martin Schlaeffer committed
10 11 12 13
  word_t tmp0;
  int n = 0;
  while (len) {
    /* determine block size */
Enrico Pozzobon committed
14
    n = len < rate ? len : rate;
Martin Schlaeffer committed
15 16 17 18 19 20 21 22 23 24 25
    /* absorb data */
    tmp0 = LOAD(in, n);
    s->x0 = XOR(s->x0, tmp0);
    /* extract data */
    if (mode & ASCON_SQUEEZE) STORE(out, s->x0, n);
    /* insert data */
    if (mode & ASCON_INSERT) {
      s->x0 = CLEAR(s->x0, n);
      s->x0 = XOR(s->x0, tmp0);
    }
    /* compute permutation for full blocks */
Enrico Pozzobon committed
26
    if (n == rate) P(s, nr);
Martin Schlaeffer committed
27 28 29 30 31 32
    in += n;
    out += n;
    len -= n;
  }
  s->x0 = XOR(s->x0, PAD(n % 8));
}