util_md5.c revision ab5581cc78e9d865b0a6ab1404c53347b3276968
208651a016b098f4fa1f6279559f104d70f1632dtakashi/* ====================================================================
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar * Redistribution and use in source and binary forms, with or without
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * modification, are permitted provided that the following conditions
acc36ab93565d2880447d535da6ca6e5feac7a70nd * are met:
031b91a62d25106ae69d4693475c79618dd5e884fielding * 1. Redistributions of source code must retain the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer.
031b91a62d25106ae69d4693475c79618dd5e884fielding * 2. Redistributions in binary form must reproduce the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer in
acc36ab93565d2880447d535da6ca6e5feac7a70nd * the documentation and/or other materials provided with the
acc36ab93565d2880447d535da6ca6e5feac7a70nd * distribution.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 3. All advertising materials mentioning features or use of this
acc36ab93565d2880447d535da6ca6e5feac7a70nd * software must display the following acknowledgment:
acc36ab93565d2880447d535da6ca6e5feac7a70nd * "This product includes software developed by the Apache Group
acc36ab93565d2880447d535da6ca6e5feac7a70nd * for use in the Apache HTTP server project (http://www.apache.org/)."
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 4. The names "Apache Server" and "Apache Group" must not be used to
acc36ab93565d2880447d535da6ca6e5feac7a70nd * endorse or promote products derived from this software without
7db9f691a00ead175b03335457ca296a33ddf31bnd * prior written permission. For written permission, please contact
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * apache@apache.org.
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * 5. Products derived from this software may not be called "Apache"
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * nor may "Apache" appear in their names without prior written
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * permission of the Apache Group.
208651a016b098f4fa1f6279559f104d70f1632dtakashi * 6. Redistributions of any form whatsoever must retain the following
208651a016b098f4fa1f6279559f104d70f1632dtakashi * acknowledgment:
208651a016b098f4fa1f6279559f104d70f1632dtakashi * "This product includes software developed by the Apache Group
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * for use in the Apache HTTP server project (http://www.apache.org/)."
208651a016b098f4fa1f6279559f104d70f1632dtakashi * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
208651a016b098f4fa1f6279559f104d70f1632dtakashi * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208651a016b098f4fa1f6279559f104d70f1632dtakashi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
208651a016b098f4fa1f6279559f104d70f1632dtakashi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
208651a016b098f4fa1f6279559f104d70f1632dtakashi * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
208651a016b098f4fa1f6279559f104d70f1632dtakashi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
208651a016b098f4fa1f6279559f104d70f1632dtakashi * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
208651a016b098f4fa1f6279559f104d70f1632dtakashi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * OF THE POSSIBILITY OF SUCH DAMAGE.
208651a016b098f4fa1f6279559f104d70f1632dtakashi * ====================================================================
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * This software consists of voluntary contributions made by many
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * individuals on behalf of the Apache Group and was originally based
208651a016b098f4fa1f6279559f104d70f1632dtakashi * on public domain software written at the National Center for
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Supercomputing Applications, University of Illinois, Urbana-Champaign.
208651a016b098f4fa1f6279559f104d70f1632dtakashi * For more information on the Apache Group and the Apache HTTP server
208651a016b098f4fa1f6279559f104d70f1632dtakashi * project, please see <http://www.apache.org/>.
208651a016b098f4fa1f6279559f104d70f1632dtakashi/************************************************************************
208651a016b098f4fa1f6279559f104d70f1632dtakashi * NCSA HTTPd Server
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Software Development Group
208651a016b098f4fa1f6279559f104d70f1632dtakashi * National Center for Supercomputing Applications
208651a016b098f4fa1f6279559f104d70f1632dtakashi * University of Illinois at Urbana-Champaign
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * 605 E. Springfield, Champaign, IL 61820
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * httpd@ncsa.uiuc.edu
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Copyright (C) 1995, Board of Trustees of the University of Illinois
208651a016b098f4fa1f6279559f104d70f1632dtakashi ************************************************************************
208651a016b098f4fa1f6279559f104d70f1632dtakashi * md5.c: NCSA HTTPd code which uses the md5c.c RSA Code
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Original Code Copyright (C) 1994, Jeff Hostetler, Spyglass, Inc.
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Portions of Content-MD5 code Copyright (C) 1993, 1994 by Carnegie Mellon
208651a016b098f4fa1f6279559f104d70f1632dtakashi * University (see Copyright below).
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Portions of Content-MD5 code Copyright (C) 1991 Bell Communications
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Research, Inc. (Bellcore) (see Copyright below).
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Portions extracted from mpack, John G. Myers - jgm+@cmu.edu
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Content-MD5 Code contributed by Martin Hamilton (martin@net.lut.ac.uk)
208651a016b098f4fa1f6279559f104d70f1632dtakashi/* md5.c --Module Interface to MD5. */
208651a016b098f4fa1f6279559f104d70f1632dtakashi/* Jeff Hostetler, Spyglass, Inc., 1994. */
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikiAPI_EXPORT(char *) ap_md5_binary(ap_context_t *p, const unsigned char *buf, int length)
208651a016b098f4fa1f6279559f104d70f1632dtakashi * Take the MD5 hash of the string argument.
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikiAPI_EXPORT(char *) ap_md5(ap_context_t *p, const unsigned char *string)
208651a016b098f4fa1f6279559f104d70f1632dtakashi return ap_md5_binary(p, string, (int) strlen((char *)string));
208651a016b098f4fa1f6279559f104d70f1632dtakashi/* these portions extracted from mpack, John G. Myers - jgm+@cmu.edu */
57fbfdce466d9a43dd4c161c901360f8f2ad2757yoshiki/* (C) Copyright 1993,1994 by Carnegie Mellon University
57fbfdce466d9a43dd4c161c901360f8f2ad2757yoshiki * All Rights Reserved.
57fbfdce466d9a43dd4c161c901360f8f2ad2757yoshiki * Permission to use, copy, modify, distribute, and sell this software
57fbfdce466d9a43dd4c161c901360f8f2ad2757yoshiki * and its documentation for any purpose is hereby granted without
208651a016b098f4fa1f6279559f104d70f1632dtakashi * fee, provided that the above copyright notice appear in all copies
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * and that both that copyright notice and this permission notice
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * appear in supporting documentation, and that the name of Carnegie
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * Mellon University not be used in advertising or publicity
208651a016b098f4fa1f6279559f104d70f1632dtakashi * pertaining to distribution of the software without specific,
208651a016b098f4fa1f6279559f104d70f1632dtakashi * written prior permission. Carnegie Mellon University makes no
208651a016b098f4fa1f6279559f104d70f1632dtakashi * representations about the suitability of this software for any
208651a016b098f4fa1f6279559f104d70f1632dtakashi * purpose. It is provided "as is" without express or implied
208651a016b098f4fa1f6279559f104d70f1632dtakashi * warranty.
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
208651a016b098f4fa1f6279559f104d70f1632dtakashi * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
208651a016b098f4fa1f6279559f104d70f1632dtakashi * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
208651a016b098f4fa1f6279559f104d70f1632dtakashi * SOFTWARE.
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * Permission to use, copy, modify, and distribute this material
208651a016b098f4fa1f6279559f104d70f1632dtakashi * for any purpose and without fee is hereby granted, provided
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * that the above copyright notice and this permission notice
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * appear in all copies, and that the name of Bellcore not be
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki * used in advertising or publicity pertaining to this
208651a016b098f4fa1f6279559f104d70f1632dtakashi * material without the specific, prior written permission
208651a016b098f4fa1f6279559f104d70f1632dtakashi * of an authorized representative of Bellcore. BELLCORE
208651a016b098f4fa1f6279559f104d70f1632dtakashi * MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
208651a016b098f4fa1f6279559f104d70f1632dtakashi * OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
208651a016b098f4fa1f6279559f104d70f1632dtakashi * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikistatic char basis_64[] =
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikiAPI_EXPORT(char *) ap_md5contextTo64(ap_context_t *a, AP_MD5_CTX * context)
208651a016b098f4fa1f6279559f104d70f1632dtakashi encodedDigest = (char *) ap_pcalloc(a, 25 * sizeof(char));
208651a016b098f4fa1f6279559f104d70f1632dtakashi digest[sizeof(digest) - 1] = digest[sizeof(digest) - 2] = 0;
208651a016b098f4fa1f6279559f104d70f1632dtakashi *p++ = basis_64[((digest[i] & 0x3) << 4) | ((int) (digest[i + 1] & 0xF0) >> 4)];
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki *p++ = basis_64[((digest[i + 1] & 0xF) << 2) | ((int) (digest[i + 2] & 0xC0) >> 6)];
208651a016b098f4fa1f6279559f104d70f1632dtakashi *p-- = '\0';
208651a016b098f4fa1f6279559f104d70f1632dtakashi *p-- = '=';
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki *p-- = '=';
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikiAPI_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile, int convert)
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki /* ZZZ use AP func instead of fread. */
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki /* ZZZ use AP seek func instead of REWIND. */
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshikiAPI_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile)
0d419faf71b4d392a596273bd6cc6db401bf6ab7yoshiki /* ZZZ use AP func instead of fread. */
208651a016b098f4fa1f6279559f104d70f1632dtakashi /* ZZZ use AP seek func instead of REWIND. */