1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file xcbc_process.c
7 XCBC Support, XCBC-MAC a block of memory
8 */
9
10 #ifdef LTC_XCBC
11
12 /** XCBC-MAC a block of memory
13 @param cipher Index of cipher to use
14 @param key [in] Secret key
15 @param keylen Length of key in octets
16 @param in [in] Message to MAC
17 @param inlen Length of input in octets
18 @param out [out] Destination for the MAC tag
19 @param outlen [in/out] Output size and final tag size
20 Return CRYPT_OK on success.
21 */
xcbc_memory(int cipher,const unsigned char * key,unsigned long keylen,const unsigned char * in,unsigned long inlen,unsigned char * out,unsigned long * outlen)22 int xcbc_memory(int cipher,
23 const unsigned char *key, unsigned long keylen,
24 const unsigned char *in, unsigned long inlen,
25 unsigned char *out, unsigned long *outlen)
26 {
27 xcbc_state *xcbc;
28 int err;
29
30 /* is the cipher valid? */
31 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
32 return err;
33 }
34
35 /* Use accelerator if found */
36 if (cipher_descriptor[cipher]->xcbc_memory != NULL) {
37 return cipher_descriptor[cipher]->xcbc_memory(key, keylen, in, inlen, out, outlen);
38 }
39
40 xcbc = XCALLOC(1, sizeof(*xcbc));
41 if (xcbc == NULL) {
42 return CRYPT_MEM;
43 }
44
45 if ((err = xcbc_init(xcbc, cipher, key, keylen)) != CRYPT_OK) {
46 goto done;
47 }
48
49 if ((err = xcbc_process(xcbc, in, inlen)) != CRYPT_OK) {
50 goto done;
51 }
52
53 err = xcbc_done(xcbc, out, outlen);
54 done:
55 XFREE(xcbc);
56 return err;
57 }
58
59 #endif
60