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 OMAC1 support, process a file, 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 you wish to OMAC
24 @param out [out] Where the authentication tag is to be stored
25 @param outlen [in/out] The 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 omac_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);
48 LTC_ARGCHK(key != NULL);
49 LTC_ARGCHK(filename != NULL);
50 LTC_ARGCHK(out != NULL);
51 LTC_ARGCHK(outlen != NULL);
53 if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
57 if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
61 in = fopen(filename, "rb");
63 err = CRYPT_FILE_NOTFOUND;
68 x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
69 if ((err = omac_process(&omac, buf, (unsigned long)x)) != CRYPT_OK) {
73 } while (x == LTC_FILE_READ_BUFSIZE);
75 if (fclose(in) != 0) {
80 err = omac_done(&omac, out, outlen);
83 zeromem(buf, LTC_FILE_READ_BUFSIZE);
85 #ifdef LTC_CLEAN_STACK
86 zeromem(&omac, sizeof(omac_state));
95 /* ref: $Format:%D$ */
96 /* git commit: $Format:%H$ */
97 /* commit time: $Format:%ai$ */