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 #include "tomcrypt_private.h"
11
12 /**
13 @file pmac_memory.c
14 PMAC implementation, process a block of memory, by Tom St Denis
15 */
16
17 #ifdef LTC_PMAC
18
19 /**
20 PMAC a block of memory
21 @param cipher The index of the cipher desired
22 @param key The secret key
23 @param keylen The length of the secret key (octets)
24 @param in The data you wish to send through PMAC
25 @param inlen The length of data you wish to send through PMAC (octets)
26 @param out [out] Destination for the authentication tag
27 @param outlen [in/out] The max size and resulting size of the authentication tag
28 @return CRYPT_OK if successful
29 */
pmac_memory(int cipher,const unsigned char * key,unsigned long keylen,const unsigned char * in,unsigned long inlen,unsigned char * out,unsigned long * outlen)30 int pmac_memory(int cipher,
31 const unsigned char *key, unsigned long keylen,
32 const unsigned char *in, unsigned long inlen,
33 unsigned char *out, unsigned long *outlen)
34 {
35 int err;
36 pmac_state *pmac;
37
38 LTC_ARGCHK(key != NULL);
39 LTC_ARGCHK(in != NULL);
40 LTC_ARGCHK(out != NULL);
41 LTC_ARGCHK(outlen != NULL);
42
43 /* allocate ram for pmac state */
44 pmac = XMALLOC(sizeof(pmac_state));
45 if (pmac == NULL) {
46 return CRYPT_MEM;
47 }
48
49 if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
50 goto LBL_ERR;
51 }
52 if ((err = pmac_process(pmac, in, inlen)) != CRYPT_OK) {
53 goto LBL_ERR;
54 }
55 if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
56 goto LBL_ERR;
57 }
58
59 err = CRYPT_OK;
60 LBL_ERR:
61 #ifdef LTC_CLEAN_STACK
62 zeromem(pmac, sizeof(pmac_state));
63 #endif
64
65 XFREE(pmac);
66 return err;
67 }
68
69 #endif
70
71 /* ref: $Format:%D$ */
72 /* git commit: $Format:%H$ */
73 /* commit time: $Format:%ai$ */
74