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 f9 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 fname The name of the file you wish to f9
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 f9_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(fname);
38 LTC_UNUSED_PARAM(out);
39 LTC_UNUSED_PARAM(outlen);
48 LTC_ARGCHK(key != NULL);
49 LTC_ARGCHK(fname != NULL);
50 LTC_ARGCHK(out != NULL);
51 LTC_ARGCHK(outlen != NULL);
53 if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
57 if ((err = f9_init(&f9, cipher, key, keylen)) != CRYPT_OK) {
61 in = fopen(fname, "rb");
63 err = CRYPT_FILE_NOTFOUND;
68 x = fread(buf, 1, LTC_FILE_READ_BUFSIZE, in);
69 if ((err = f9_process(&f9, buf, (unsigned long)x)) != CRYPT_OK) {
73 } while (x == LTC_FILE_READ_BUFSIZE);
75 if (fclose(in) != 0) {
80 err = f9_done(&f9, out, outlen);
83 zeromem(buf, LTC_FILE_READ_BUFSIZE);
85 #ifdef LTC_CLEAN_STACK
86 zeromem(&f9, sizeof(f9_state));
95 /* ref: $Format:%D$ */
96 /* git commit: $Format:%H$ */
97 /* commit time: $Format:%ai$ */