Coverage Report

Created: 2023-03-26 06:28

/src/httpd/server/util_md5.c
Line
Count
Source (jump to first uncovered line)
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
23
 * httpd@ncsa.uiuc.edu
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 - jgm+@cmu.edu
37
 *  Content-MD5 Code contributed by Martin Hamilton (martin@net.lut.ac.uk)
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
53
AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int length)
54
0
{
55
0
    apr_md5_ctx_t my_md5;
56
0
    unsigned char hash[APR_MD5_DIGESTSIZE];
57
0
    char *result;
58
59
    /*
60
     * Take the MD5 hash of the string argument.
61
     */
62
63
0
    apr_md5_init(&my_md5);
64
#if APR_CHARSET_EBCDIC
65
    apr_md5_set_xlate(&my_md5, ap_hdrs_to_ascii);
66
#endif
67
0
    apr_md5_update(&my_md5, buf, (unsigned int)length);
68
0
    apr_md5_final(hash, &my_md5);
69
70
0
    result = apr_palloc(p, 2 * APR_MD5_DIGESTSIZE + 1);
71
0
    ap_bin2hex(hash, APR_MD5_DIGESTSIZE, result); /* sets final '\0' */
72
0
    return result;
73
0
}
74
75
AP_DECLARE(char *) ap_md5(apr_pool_t *p, const unsigned char *string)
76
0
{
77
0
    return ap_md5_binary(p, string, (int) strlen((char *)string));
78
0
}