Apache HTTPD
util_md5.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/************************************************************************
18 * NCSA HTTPd Server
19 * Software Development Group
20 * National Center for Supercomputing Applications
21 * University of Illinois at Urbana-Champaign
22 * 605 E. Springfield, Champaign, IL 61820
24 *
25 * Copyright (C) 1995, Board of Trustees of the University of Illinois
26 *
27 ************************************************************************
28 *
29 * md5.c: NCSA HTTPd code which uses the md5c.c RSA Code
30 *
31 * Original Code Copyright (C) 1994, Jeff Hostetler, Spyglass, Inc.
32 * Portions of Content-MD5 code Copyright (C) 1993, 1994 by Carnegie Mellon
33 * University (see Copyright below).
34 * Portions of Content-MD5 code Copyright (C) 1991 Bell Communications
35 * Research, Inc. (Bellcore) (see Copyright below).
36 * Portions extracted from mpack, John G. Myers - [email protected]
37 * Content-MD5 Code contributed by Martin Hamilton ([email protected])
38 *
39 */
40
41
42
43/* md5.c --Module Interface to MD5. */
44/* Jeff Hostetler, Spyglass, Inc., 1994. */
45
46#include "ap_config.h"
47#include "apr_portable.h"
48#include "apr_strings.h"
49#include "httpd.h"
50#include "util_md5.h"
51#include "util_ebcdic.h"
52
53AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int length)
54{
56 unsigned char hash[APR_MD5_DIGESTSIZE];
57 char *result;
58
59 /*
60 * Take the MD5 hash of the string argument.
61 */
62
64#if APR_CHARSET_EBCDIC
66#endif
67 apr_md5_update(&my_md5, buf, (unsigned int)length);
69
71 ap_bin2hex(hash, APR_MD5_DIGESTSIZE, result); /* sets final '\0' */
72 return result;
73}
74
75AP_DECLARE(char *) ap_md5(apr_pool_t *p, const unsigned char *string)
76{
77 return ap_md5_binary(p, string, (int) strlen((char *)string));
78}
79
80/* these portions extracted from mpack, John G. Myers - [email protected] */
81
82/* (C) Copyright 1993,1994 by Carnegie Mellon University
83 * All Rights Reserved.
84 *
85 * Permission to use, copy, modify, distribute, and sell this software
86 * and its documentation for any purpose is hereby granted without
87 * fee, provided that the above copyright notice appear in all copies
88 * and that both that copyright notice and this permission notice
89 * appear in supporting documentation, and that the name of Carnegie
90 * Mellon University not be used in advertising or publicity
91 * pertaining to distribution of the software without specific,
92 * written prior permission. Carnegie Mellon University makes no
93 * representations about the suitability of this software for any
94 * purpose. It is provided "as is" without express or implied
95 * warranty.
96 *
97 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
98 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
99 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
100 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
101 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
102 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
103 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
104 * SOFTWARE.
105 */
106
107/*
108 * Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
109 *
110 * Permission to use, copy, modify, and distribute this material
111 * for any purpose and without fee is hereby granted, provided
112 * that the above copyright notice and this permission notice
113 * appear in all copies, and that the name of Bellcore not be
114 * used in advertising or publicity pertaining to this
115 * material without the specific, prior written permission
116 * of an authorized representative of Bellcore. BELLCORE
117 * MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
118 * OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
119 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
120 */
121
122static char basis_64[] =
123"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
124
126{
127 unsigned char digest[18];
128 char *encodedDigest;
129 int i;
130 char *p;
131
132 encodedDigest = (char *) apr_pcalloc(a, 25 * sizeof(char));
133
135 digest[sizeof(digest) - 1] = digest[sizeof(digest) - 2] = 0;
136
138 for (i = 0; i < sizeof(digest); i += 3) {
139 *p++ = basis_64[digest[i] >> 2];
140 *p++ = basis_64[((digest[i] & 0x3) << 4) | ((int) (digest[i + 1] & 0xF0) >> 4)];
141 *p++ = basis_64[((digest[i + 1] & 0xF) << 2) | ((int) (digest[i + 2] & 0xC0) >> 6)];
142 *p++ = basis_64[digest[i + 2] & 0x3F];
143 }
144 *p-- = '\0';
145 *p-- = '=';
146 *p-- = '=';
147 return encodedDigest;
148}
149
151{
153 unsigned char buf[4096]; /* keep this a multiple of 64 */
155 apr_off_t offset = 0L;
156
158 nbytes = sizeof(buf);
159 while (apr_file_read(infile, buf, &nbytes) == APR_SUCCESS) {
161 nbytes = sizeof(buf);
162 }
164 return ap_md5contextTo64(p, &context);
165}
166
Symbol export macros and hook functions.
#define AP_DECLARE(type)
Definition ap_config.h:67
APR Portability Routines.
#define hash(h, r, b, n)
Definition apr_random.c:51
APR Strings library.
const unsigned char * buf
Definition util_md5.h:50
apr_file_t * infile
Definition util_md5.h:65
apr_md5_ctx_t * context
Definition util_md5.h:58
#define APR_MD5_DIGESTSIZE
Definition apr_md5.h:68
apr_bucket apr_bucket_brigade * a
int apr_off_t * length
void ap_bin2hex(const void *src, apr_size_t srclen, char *dest)
Definition util.c:2314
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
void apr_size_t * nbytes
apr_seek_where_t apr_off_t * offset
#define APR_SET
apr_array_header_t ** result
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
int i
Definition mod_so.c:347
const char * digest
Definition testmd5.c:30
Utilities for EBCDIC conversion.
char * ap_md5contextTo64(apr_pool_t *a, apr_md5_ctx_t *context)
Definition util_md5.c:125
char * ap_md5(apr_pool_t *p, const unsigned char *string)
Definition util_md5.c:75
char * ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int length)
Definition util_md5.c:53
static char basis_64[]
Definition util_md5.c:122
char * ap_md5digest(apr_pool_t *p, apr_file_t *infile)
Definition util_md5.c:150
Apache MD5 library.
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray