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

Martin Schläffer committed
7 8 9
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
10

Martin Schläffer committed
11 12 13 14 15 16 17
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
18
  *clen = mlen + CRYPTO_ABYTES;
Martin Schläffer committed
19
  /* ascon encryption */
Christoph Dobraunig committed
20
  ascon_core(&s, c, m, mlen, ad, adlen, npub, k, ASCON_ENC);
Martin Schläffer committed
21 22 23
  /* set tag */
  STORE64(c + mlen, s.x3);
  STORE64(c + mlen + 8, s.x4);
Christoph Dobraunig committed
24 25
  return 0;
}