Mercurial > dropbear
comparison pmac_file.c @ 0:d7da3b1e1540 libtomcrypt
put back the 0.95 makefile which was inadvertently merged over
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:21:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7da3b1e1540 |
---|---|
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 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 | |
12 /* PMAC implementation by Tom St Denis */ | |
13 #include "mycrypt.h" | |
14 | |
15 #ifdef PMAC | |
16 | |
17 int pmac_file(int cipher, | |
18 const unsigned char *key, unsigned long keylen, | |
19 const char *filename, | |
20 unsigned char *out, unsigned long *outlen) | |
21 { | |
22 #ifdef NO_FILE | |
23 return CRYPT_NOP; | |
24 #else | |
25 int err, x; | |
26 pmac_state pmac; | |
27 FILE *in; | |
28 unsigned char buf[512]; | |
29 | |
30 | |
31 _ARGCHK(key != NULL); | |
32 _ARGCHK(filename != NULL); | |
33 _ARGCHK(out != NULL); | |
34 _ARGCHK(outlen != NULL); | |
35 | |
36 in = fopen(filename, "rb"); | |
37 if (in == NULL) { | |
38 return CRYPT_FILE_NOTFOUND; | |
39 } | |
40 | |
41 if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) { | |
42 fclose(in); | |
43 return err; | |
44 } | |
45 | |
46 do { | |
47 x = fread(buf, 1, sizeof(buf), in); | |
48 if ((err = pmac_process(&pmac, buf, x)) != CRYPT_OK) { | |
49 fclose(in); | |
50 return err; | |
51 } | |
52 } while (x == sizeof(buf)); | |
53 fclose(in); | |
54 | |
55 if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) { | |
56 return err; | |
57 } | |
58 | |
59 #ifdef CLEAN_STACK | |
60 zeromem(buf, sizeof(buf)); | |
61 #endif | |
62 | |
63 return CRYPT_OK; | |
64 #endif | |
65 } | |
66 | |
67 #endif |