author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:57:58 +0100 | |
changeset 6 | c3dc3eb3b541 |
child 9 | c3fecc82ade6 |
permissions | -rw-r--r-- |
6
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/* |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
2 |
* $Id: md5sum.c 94 2008-04-05 01:27:30Z mbroeker $ |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
3 |
* $URL: http://localhost/svn/c/lsflib/trunk/src/md5sum.c $ |
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 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <stdio.h> |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <string.h> |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
#include <openssl/evp.h> |
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 |
#include <lsf.h> |
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 |
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
|
14 |
{ |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
EVP_MD_CTX mdctx; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
const EVP_MD *md; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
char line[81]; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
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
|
19 |
int md_len, i; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
FILE *f; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
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
|
22 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
OpenSSL_add_all_digests (); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
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
|
26 |
perror ("FOPEN"); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
value = malloc (1); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
value = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
return value; |
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 |
if ((md = EVP_get_digestbyname ("md5")) == NULL) { |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
value = malloc (1); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
value = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
return value; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
} |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
*line = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
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
|
43 |
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
|
44 |
} |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
fclose (f); |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
51 |
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
|
52 |
|
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
value[i] = 0; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
56 |
return value; |
c3dc3eb3b541
a small libtool demo added to the demo distribution
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
57 |
} |