author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 19 Nov 2010 12:23:24 +0100 | |
changeset 158 | 2cddd4d26139 |
parent 136 | d82f65e902d0 |
permissions | -rw-r--r-- |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
1 |
/** |
77 | 2 |
* lsflib/src/md5sum.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
6
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
6
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
*/ |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <string.h> |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <openssl/evp.h> |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
|
121
fef2ccfa7b12
step 2) Header seperation
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
9 |
#include <lsf/lsf.h> |
6
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
unsigned char *md5sum (char *fname) |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
{ |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
EVP_MD_CTX mdctx; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
const EVP_MD *md; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
char line[81]; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
unsigned char md_value[EVP_MAX_MD_SIZE]; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
int md_len, i; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
FILE *f; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
static unsigned char *value = NULL; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
OpenSSL_add_all_digests (); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
if ((f = fopen (fname, "rb")) == NULL) { |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
perror ("FOPEN"); |
136
d82f65e902d0
getdir errors: avoid unneeded memory leaks
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
121
diff
changeset
|
25 |
return NULL; |
6
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
} |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
if ((md = EVP_get_digestbyname ("md5")) == NULL) { |
136
d82f65e902d0
getdir errors: avoid unneeded memory leaks
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
121
diff
changeset
|
29 |
return NULL; |
6
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
} |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
EVP_MD_CTX_init (&mdctx); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
EVP_DigestInit_ex (&mdctx, md, NULL); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
*line = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
while ((i = fread (line, 1, 80, f)) != 0) { |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
EVP_DigestUpdate (&mdctx, line, i); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
} |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
fclose (f); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
EVP_DigestFinal_ex (&mdctx, md_value, (unsigned int *)&md_len); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
EVP_MD_CTX_cleanup (&mdctx); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
value = malloc (md_len + 1); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
for (i = 0; i < md_len; i++) |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
value[i] = md_value[i]; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
value[i] = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
50 |
return value; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
51 |
} |