~ubuntu-branches/debian/lenny/dropbear/lenny

« back to all changes in this revision

Viewing changes to libtomcrypt/pkcs_5_1.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2005-05-25 22:38:17 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050525223817-fdl653extybmz1zb
Tags: 0.45-3
* debian/dropbear.init: init script prints human readable message in case
  it's disabled (closes: #309099).
* debian/dropbear.postinst: configure: restart service through init script
  instead of start.
* debian/dropbear.prerm: set -u -> set -e.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
{
21
21
   int err;
22
22
   unsigned long x;
23
 
   hash_state md;
24
 
   unsigned char buf[MAXBLOCKSIZE];
 
23
   hash_state    *md;
 
24
   unsigned char *buf;
25
25
 
26
26
   _ARGCHK(password != NULL);
27
27
   _ARGCHK(salt     != NULL);
33
33
      return err;
34
34
   }
35
35
 
 
36
   /* allocate memory */
 
37
   md  = XMALLOC(sizeof(hash_state));
 
38
   buf = XMALLOC(MAXBLOCKSIZE);
 
39
   if (md == NULL || buf == NULL) {
 
40
      if (md != NULL) {
 
41
         XFREE(md);
 
42
      }
 
43
      if (buf != NULL) { 
 
44
         XFREE(buf);
 
45
      }
 
46
      return CRYPT_MEM;
 
47
   }        
 
48
 
36
49
   /* hash initial password + salt */
37
 
   hash_descriptor[hash_idx].init(&md);
38
 
   hash_descriptor[hash_idx].process(&md, password, password_len);
39
 
   hash_descriptor[hash_idx].process(&md, salt, 8);
40
 
   hash_descriptor[hash_idx].done(&md, buf);
 
50
   if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
 
51
       goto __ERR;
 
52
   }
 
53
   if ((err = hash_descriptor[hash_idx].process(md, password, password_len)) != CRYPT_OK) {
 
54
       goto __ERR;
 
55
   }
 
56
   if ((err = hash_descriptor[hash_idx].process(md, salt, 8)) != CRYPT_OK) {
 
57
       goto __ERR;
 
58
   }
 
59
   if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
 
60
       goto __ERR;
 
61
   }
41
62
 
42
63
   while (--iteration_count) {
43
64
      // code goes here.
44
 
      x = sizeof(buf);
 
65
      x = MAXBLOCKSIZE;
45
66
      if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
46
 
         return err;
 
67
         goto __ERR;
47
68
      }
48
69
   }
49
70
 
52
73
       out[x] = buf[x];
53
74
   }
54
75
   *outlen = x;
55
 
 
 
76
   err = CRYPT_OK;
 
77
__ERR:
56
78
#ifdef CLEAN_STACK 
57
 
   zeromem(buf, sizeof(buf));
 
79
   zeromem(buf, MAXBLOCKSIZE);
 
80
   zeromem(md, sizeof(hash_state));
58
81
#endif
59
82
 
60
 
   return CRYPT_OK;
 
83
   XFREE(buf);
 
84
   XFREE(md);
 
85
 
 
86
   return err;
61
87
}
62
88
 
63
89
#endif