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
16 @param fname The name of the file you wish to BLAKE2S MAC
17 @param key The secret key
18 @param keylen The length of the secret key
19 @param mac [out] The BLAKE2S MAC authentication tag
20 @param maclen [in/out] The max size and resulting size of the authentication tag
21 @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
23 int blake2smac_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen)
26 LTC_UNUSED_PARAM(fname);
27 LTC_UNUSED_PARAM(key);
28 LTC_UNUSED_PARAM(keylen);
29 LTC_UNUSED_PARAM(mac);
30 LTC_UNUSED_PARAM(maclen);
39 LTC_ARGCHK(fname != NULL);
40 LTC_ARGCHK(key != NULL);
41 LTC_ARGCHK(mac != NULL);
42 LTC_ARGCHK(maclen != NULL);
44 if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
48 if ((err = blake2smac_init(&st, *maclen, key, keylen)) != CRYPT_OK) {
52 in = fopen(fname, "rb");
54 err = CRYPT_FILE_NOTFOUND;
59 x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
60 if ((err = blake2smac_process(&st, buf, (unsigned long)x)) != CRYPT_OK) {
64 } while (x == LTC_FILE_READ_BUFSIZE);
66 if (fclose(in) != 0) {
71 err = blake2smac_done(&st, mac, maclen);
74 zeromem(buf, LTC_FILE_READ_BUFSIZE);
76 #ifdef LTC_CLEAN_STACK
77 zeromem(&st, sizeof(blake2smac_state));
86 /* ref: $Format:%D$ */
87 /* git commit: $Format:%H$ */
88 /* commit time: $Format:%ai$ */