]> sjero.net Git - wget/blob - src/gen-md5.c
[svn] Remove char/unsigned char warnings emitted by Sun cc.
[wget] / src / gen-md5.c
1 /* General MD5 support.
2    Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This file is part of GNU Wget.
5
6 GNU Wget is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 GNU Wget is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Wget; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <config.h>
21 #include "wget.h"
22
23 #include "gen-md5.h"
24
25 #ifdef HAVE_BUILTIN_MD5
26 # include <gnu-md5.h>
27 typedef struct md5_ctx gen_md5_context_imp;
28 #endif
29
30 #ifdef HAVE_SOLARIS_MD5
31 # include <md5.h>
32 typedef MD5_CTX gen_md5_context_imp;
33 #endif
34
35 #ifdef HAVE_OPENSSL_MD5
36 # include <openssl/md5.h>
37 typedef MD5_CTX gen_md5_context_imp;
38 #endif
39
40 struct gen_md5_context {
41   gen_md5_context_imp imp;
42 };
43
44 /* Originally I planned for these to be macros, but that's very hard
45    because some of these MD5 implementations use the same names for
46    their types.  For example, it is impossible to include <md5.h> and
47    <openssl/ssl.h> on Solaris, because the latter includes its own MD5
48    implementation, which clashes with <md5.h>.  */
49
50 int
51 gen_md5_context_size (void)
52 {
53   return sizeof (struct gen_md5_context);
54 }
55
56 void
57 gen_md5_init (gen_md5_context *ctx)
58 {
59   gen_md5_context_imp *ctx_imp = &ctx->imp;
60
61 #ifdef HAVE_BUILTIN_MD5
62   md5_init_ctx (ctx_imp);
63 #endif
64
65 #ifdef HAVE_SOLARIS_MD5
66   MD5Init (ctx_imp);
67 #endif
68
69 #ifdef HAVE_OPENSSL_MD5
70   MD5_Init (ctx_imp);
71 #endif
72 }
73
74 void
75 gen_md5_update (unsigned const char *buffer, int len, gen_md5_context *ctx)
76 {
77   gen_md5_context_imp *ctx_imp = &ctx->imp;
78
79 #ifdef HAVE_BUILTIN_MD5
80   md5_process_bytes (buffer, len, ctx_imp);
81 #endif
82
83 #ifdef HAVE_SOLARIS_MD5
84   MD5Update (ctx_imp, (unsigned char *)buffer, len);
85 #endif
86
87 #ifdef HAVE_OPENSSL_MD5
88   MD5_Update (ctx_imp, buffer, len);
89 #endif
90 }
91
92 void
93 gen_md5_finish (gen_md5_context *ctx, unsigned char *result)
94 {
95   gen_md5_context_imp *ctx_imp = &ctx->imp;
96
97 #ifdef HAVE_BUILTIN_MD5
98   md5_finish_ctx (ctx_imp, result);
99 #endif
100
101 #ifdef HAVE_SOLARIS_MD5
102   MD5Final (result, ctx_imp);
103 #endif
104
105 #ifdef HAVE_OPENSSL_MD5
106   MD5_Final (result, ctx_imp);
107 #endif
108 }