1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9 #include "tomcrypt.h"
10
11 /**
12 @file pmac_memory.c
13 PMAC implementation, process a block of memory, by Tom St Denis
14 */
15
16 #ifdef LTC_PMAC
17
18 /**
19 PMAC a block of memory
20 @param cipher The index of the cipher desired
21 @param key The secret key
22 @param keylen The length of the secret key (octets)
23 @param in The data you wish to send through PMAC
24 @param inlen The length of data you wish to send through PMAC (octets)
25 @param out [out] Destination for the authentication tag
26 @param outlen [in/out] The max size and resulting size of the authentication tag
27 @return CRYPT_OK if successful
28 */
pmac_memory(int cipher,const unsigned char * key,unsigned long keylen,const unsigned char * in,unsigned long inlen,unsigned char * out,unsigned long * outlen)29 int pmac_memory(int cipher,
30 const unsigned char *key, unsigned long keylen,
31 const unsigned char *in, unsigned long inlen,
32 unsigned char *out, unsigned long *outlen)
33 {
34 int err;
35 pmac_state *pmac;
36
37 LTC_ARGCHK(key != NULL);
38 LTC_ARGCHK(in != NULL);
39 LTC_ARGCHK(out != NULL);
40 LTC_ARGCHK(outlen != NULL);
41
42 /* allocate ram for pmac state */
43 pmac = XMALLOC(sizeof(pmac_state));
44 if (pmac == NULL) {
45 return CRYPT_MEM;
46 }
47
48 if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
49 goto LBL_ERR;
50 }
51 if ((err = pmac_process(pmac, in, inlen)) != CRYPT_OK) {
52 goto LBL_ERR;
53 }
54 if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
55 goto LBL_ERR;
56 }
57
58 err = CRYPT_OK;
59 LBL_ERR:
60 #ifdef LTC_CLEAN_STACK
61 zeromem(pmac, sizeof(pmac_state));
62 #endif
63
64 XFREE(pmac);
65 return err;
66 }
67
68 #endif
69
70 /* ref: HEAD -> master, tag: v1.18.2 */
71 /* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
72 /* commit time: 2018-07-01 22:49:01 +0200 */
73