1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 PMAC implementation, process a file, by Tom St Denis
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 filename The name of the file to send through PMAC
24 @param out [out] Destination for the authentication tag
25 @param outlen [in/out] Max size and resulting size of the authentication tag
26 @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
28 int pmac_file(int cipher,
29 const unsigned char *key, unsigned long keylen,
31 unsigned char *out, unsigned long *outlen)
34 LTC_UNUSED_PARAM(cipher);
35 LTC_UNUSED_PARAM(key);
36 LTC_UNUSED_PARAM(keylen);
37 LTC_UNUSED_PARAM(filename);
38 LTC_UNUSED_PARAM(out);
39 LTC_UNUSED_PARAM(outlen);
49 LTC_ARGCHK(key != NULL);
50 LTC_ARGCHK(filename != NULL);
51 LTC_ARGCHK(out != NULL);
52 LTC_ARGCHK(outlen != NULL);
54 if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
58 if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
62 in = fopen(filename, "rb");
64 err = CRYPT_FILE_NOTFOUND;
69 x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
70 if ((err = pmac_process(&pmac, buf, (unsigned long)x)) != CRYPT_OK) {
74 } while (x == LTC_FILE_READ_BUFSIZE);
76 if (fclose(in) != 0) {
81 err = pmac_done(&pmac, out, outlen);
84 zeromem(buf, LTC_FILE_READ_BUFSIZE);
86 #ifdef LTC_CLEAN_STACK
87 zeromem(&pmac, sizeof(pmac_state));
96 /* ref: $Format:%D$ */
97 /* git commit: $Format:%H$ */
98 /* commit time: $Format:%ai$ */