1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3
4 /**
5 @file eax_encrypt.c
6 EAX implementation, encrypt block by Tom St Denis
7 */
8 #include "tomcrypt_private.h"
9
10 #ifdef LTC_EAX_MODE
11
12 /**
13 Encrypt with EAX a block of data.
14 @param eax The EAX state
15 @param pt The plaintext to encrypt
16 @param ct [out] The ciphertext as encrypted
17 @param length The length of the plaintext (octets)
18 @return CRYPT_OK if successful
19 */
eax_encrypt(eax_state * eax,const unsigned char * pt,unsigned char * ct,unsigned long length)20 int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct,
21 unsigned long length)
22 {
23 int err;
24
25 LTC_ARGCHK(eax != NULL);
26 LTC_ARGCHK(pt != NULL);
27 LTC_ARGCHK(ct != NULL);
28
29 /* encrypt */
30 if ((err = ctr_encrypt(pt, ct, length, &eax->ctr)) != CRYPT_OK) {
31 return err;
32 }
33
34 /* omac ciphertext */
35 return omac_process(&eax->ctomac, ct, length);
36 }
37
38 #endif
39
40