encrypt.c 816 Bytes
Newer Older
Martin Schläffer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "api.h"
#include "ascon.h"
#include "permutations.h"
#include "printstate.h"

void ascon_core(state_t* s, uint8_t* out, const uint8_t* in, uint64_t tlen,
                const uint8_t* ad, uint64_t adlen, const uint8_t* npub,
                const uint8_t* k, uint8_t mode);

int crypto_aead_encrypt(uint8_t* c, uint64_t* clen, const uint8_t* m,
                        uint64_t mlen, const uint8_t* ad, uint64_t adlen,
                        const uint8_t* nsec, const uint8_t* npub,
                        const uint8_t* k) {
  state_t s;
  (void)nsec;
  /* set ciphertext size */
  *clen = mlen + CRYPTO_ABYTES;
  /* ascon encryption */
Martin Schläffer committed
19
  ascon_core(&s, c, m, mlen, ad, adlen, npub, k, ASCON_ENCRYPT);
Martin Schläffer committed
20
  /* set tag */
Martin Schläffer committed
21 22
  STOREBYTES(c + mlen, s.x3, 8);
  STOREBYTES(c + mlen + 8, s.x4, 8);
Martin Schläffer committed
23 24
  return 0;
}