~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/sha1.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * sha1.c: SHA1 checksum routines
3
 
 *
4
 
 * ====================================================================
5
 
 *    Licensed to the Apache Software Foundation (ASF) under one
6
 
 *    or more contributor license agreements.  See the NOTICE file
7
 
 *    distributed with this work for additional information
8
 
 *    regarding copyright ownership.  The ASF licenses this file
9
 
 *    to you under the Apache License, Version 2.0 (the
10
 
 *    "License"); you may not use this file except in compliance
11
 
 *    with the License.  You may obtain a copy of the License at
12
 
 *
13
 
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 
 *
15
 
 *    Unless required by applicable law or agreed to in writing,
16
 
 *    software distributed under the License is distributed on an
17
 
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
 
 *    KIND, either express or implied.  See the License for the
19
 
 *    specific language governing permissions and limitations
20
 
 *    under the License.
21
 
 * ====================================================================
22
 
 */
23
 
 
24
 
#include <apr_sha1.h>
25
 
 
26
 
#include "sha1.h"
27
 
 
28
 
 
29
 
 
30
 
/* The SHA1 digest for the empty string. */
31
 
static const unsigned char svn_sha1__empty_string_digest_array[] = {
32
 
  0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55,
33
 
  0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09
34
 
};
35
 
 
36
 
const unsigned char *
37
 
svn_sha1__empty_string_digest(void)
38
 
{
39
 
  return svn_sha1__empty_string_digest_array;
40
 
}
41
 
 
42
 
 
43
 
const char *
44
 
svn_sha1__digest_to_cstring_display(const unsigned char digest[],
45
 
                                   apr_pool_t *pool)
46
 
{
47
 
  static const char *hex = "0123456789abcdef";
48
 
  char *str = apr_palloc(pool, (APR_SHA1_DIGESTSIZE * 2) + 1);
49
 
  int i;
50
 
 
51
 
  for (i = 0; i < APR_SHA1_DIGESTSIZE; i++)
52
 
    {
53
 
      str[i*2]   = hex[digest[i] >> 4];
54
 
      str[i*2+1] = hex[digest[i] & 0x0f];
55
 
    }
56
 
  str[i*2] = '\0';
57
 
 
58
 
  return str;
59
 
}
60
 
 
61
 
 
62
 
const char *
63
 
svn_sha1__digest_to_cstring(const unsigned char digest[], apr_pool_t *pool)
64
 
{
65
 
  static const unsigned char zeros_digest[APR_SHA1_DIGESTSIZE] = { 0 };
66
 
 
67
 
  if (memcmp(digest, zeros_digest, APR_SHA1_DIGESTSIZE) != 0)
68
 
    return svn_sha1__digest_to_cstring_display(digest, pool);
69
 
  else
70
 
    return NULL;
71
 
}
72
 
 
73
 
 
74
 
svn_boolean_t
75
 
svn_sha1__digests_match(const unsigned char d1[], const unsigned char d2[])
76
 
{
77
 
  static const unsigned char zeros[APR_SHA1_DIGESTSIZE] = { 0 };
78
 
 
79
 
  return ((memcmp(d1, zeros, APR_SHA1_DIGESTSIZE) == 0)
80
 
          || (memcmp(d2, zeros, APR_SHA1_DIGESTSIZE) == 0)
81
 
          || (memcmp(d1, d2, APR_SHA1_DIGESTSIZE) == 0));
82
 
}