~ubuntu-branches/ubuntu/trusty/httrack/trusty

« back to all changes in this revision

Viewing changes to src/htsmd5.c

  • Committer: Package Import Robot
  • Author(s): Xavier Roche
  • Date: 2013-05-17 21:18:50 UTC
  • mfrom: (5.2.33 sid)
  • Revision ID: package-import@ubuntu.com-20130517211850-604ltzlucy7th6ai
Tags: 3.47.12-1
Updated to 3.47.12 (3.47-12)
closes:#708707

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
along with this program; if not, write to the Free Software
18
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
19
 
20
 
 
21
20
Important notes:
22
21
 
23
22
- We hereby ask people using this source NOT to use it in purpose of grabbing
24
23
emails addresses, or collecting any other private information on persons.
25
24
This would disgrace our work, and spoil the many hours we spent on it.
26
25
 
27
 
 
28
26
Please visit our Website: http://www.httrack.com
29
27
*/
30
28
 
31
 
 
32
29
/* ------------------------------------------------------------ */
33
30
/* File: htsmd5.c subroutines:                                  */
34
31
/*       generate a md5 hash                                    */
48
45
#include "htsmd5.h"
49
46
#include "md5.h"
50
47
 
51
 
int domd5mem(const char * buf, size_t len, char * digest, int asAscii) {
 
48
int domd5mem(const char *buf, size_t len, char *digest, int asAscii) {
52
49
  int endian = 1;
53
50
  unsigned char bindigest[16];
54
51
  MD5_CTX ctx;
55
52
 
56
 
  MD5Init(&ctx, * ( (char*) &endian));
57
 
  MD5Update(&ctx, (const unsigned char*) buf, (unsigned int) len);
 
53
  MD5Init(&ctx, *((char *) &endian));
 
54
  MD5Update(&ctx, (const unsigned char *) buf, (unsigned int) len);
58
55
  MD5Final(bindigest, &ctx);
59
56
 
60
57
  if (!asAscii) {
61
58
    memcpy(digest, bindigest, 16);
62
59
  } else {
63
 
    sprintf(digest, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
64
 
      "%02x%02x%02x%02x%02x",
65
 
      bindigest[0],  bindigest[1],  bindigest[2],  bindigest[3],
66
 
      bindigest[4],  bindigest[5],  bindigest[6],  bindigest[7],
67
 
      bindigest[8],  bindigest[9],  bindigest[10], bindigest[11],
68
 
      bindigest[12], bindigest[13], bindigest[14], bindigest[15]);
 
60
    sprintf(digest,
 
61
            "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 
62
            "%02x%02x%02x%02x%02x", bindigest[0], bindigest[1], bindigest[2],
 
63
            bindigest[3], bindigest[4], bindigest[5], bindigest[6],
 
64
            bindigest[7], bindigest[8], bindigest[9], bindigest[10],
 
65
            bindigest[11], bindigest[12], bindigest[13], bindigest[14],
 
66
            bindigest[15]);
69
67
  }
70
 
  
 
68
 
71
69
  return 0;
72
70
}
73
71
 
74
 
unsigned long int md5sum32(const char* buff) {
 
72
unsigned long int md5sum32(const char *buff) {
75
73
  union {
76
74
    char md5digest[16];
77
75
    unsigned long int hash;
78
76
  } u;
 
77
 
79
78
  domd5mem(buff, strlen(buff), u.md5digest, 0);
80
79
  return u.hash;
81
80
}