1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10
11 /**
12 @file eax_encrypt.c
13 EAX implementation, encrypt block by Tom St Denis
14 */
15 #include "tomcrypt_private.h"
16
17 #ifdef LTC_EAX_MODE
18
19 /**
20 Encrypt with EAX a block of data.
21 @param eax The EAX state
22 @param pt The plaintext to encrypt
23 @param ct [out] The ciphertext as encrypted
24 @param length The length of the plaintext (octets)
25 @return CRYPT_OK if successful
26 */
eax_encrypt(eax_state * eax,const unsigned char * pt,unsigned char * ct,unsigned long length)27 int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct,
28 unsigned long length)
29 {
30 int err;
31
32 LTC_ARGCHK(eax != NULL);
33 LTC_ARGCHK(pt != NULL);
34 LTC_ARGCHK(ct != NULL);
35
36 /* encrypt */
37 if ((err = ctr_encrypt(pt, ct, length, &eax->ctr)) != CRYPT_OK) {
38 return err;
39 }
40
41 /* omac ciphertext */
42 return omac_process(&eax->ctomac, ct, length);
43 }
44
45 #endif
46
47
48 /* ref: $Format:%D$ */
49 /* git commit: $Format:%H$ */
50 /* commit time: $Format:%ai$ */
51