encrypt.c 816 Bytes
Newer Older
Martin Schläffer committed
1 2 3 4
#include "api.h"
#include "ascon.h"
#include "permutations.h"
#include "printstate.h"
Christoph Dobraunig committed
5

Martin Schläffer committed
6 7 8
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);
Christoph Dobraunig committed
9

Martin Schläffer committed
10 11 12 13 14 15 16
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 */
Christoph Dobraunig committed
17
  *clen = mlen + CRYPTO_ABYTES;
Martin Schläffer committed
18
  /* 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);
Christoph Dobraunig committed
23 24
  return 0;
}