~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtomcrypt/pmac_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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, tomstdenis@iahu.ca, 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