1 /* General MD5 support.
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GNU Wget.
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.
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.
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. */
25 #ifdef HAVE_BUILTIN_MD5
27 typedef struct md5_ctx gen_md5_context_imp;
30 #ifdef HAVE_SOLARIS_MD5
32 typedef MD5_CTX gen_md5_context_imp;
35 #ifdef HAVE_OPENSSL_MD5
36 # include <openssl/md5.h>
37 typedef MD5_CTX gen_md5_context_imp;
40 struct gen_md5_context {
41 gen_md5_context_imp imp;
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>. */
51 gen_md5_context_size (void)
53 return sizeof (struct gen_md5_context);
57 gen_md5_init (gen_md5_context *ctx)
59 gen_md5_context_imp *ctx_imp = &ctx->imp;
61 #ifdef HAVE_BUILTIN_MD5
62 md5_init_ctx (ctx_imp);
65 #ifdef HAVE_SOLARIS_MD5
69 #ifdef HAVE_OPENSSL_MD5
75 gen_md5_update (unsigned const char *buffer, int len, gen_md5_context *ctx)
77 gen_md5_context_imp *ctx_imp = &ctx->imp;
79 #ifdef HAVE_BUILTIN_MD5
80 md5_process_bytes (buffer, len, ctx_imp);
83 #ifdef HAVE_SOLARIS_MD5
84 MD5Update (ctx_imp, (unsigned char *)buffer, len);
87 #ifdef HAVE_OPENSSL_MD5
88 MD5_Update (ctx_imp, buffer, len);
93 gen_md5_finish (gen_md5_context *ctx, unsigned char *result)
95 gen_md5_context_imp *ctx_imp = &ctx->imp;
97 #ifdef HAVE_BUILTIN_MD5
98 md5_finish_ctx (ctx_imp, result);
101 #ifdef HAVE_SOLARIS_MD5
102 MD5Final (result, ctx_imp);
105 #ifdef HAVE_OPENSSL_MD5
106 MD5_Final (result, ctx_imp);