Print this page
4185 New hash algorithm support

Split Close
Expand all
Collapse all
          --- old/usr/src/common/zfs/zfs_fletcher.c
          +++ new/usr/src/common/zfs/zfs_fletcher.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
       25 +/*
       26 + * Copyright 2013 Saso Kiselkov. All rights reserved.
       27 + */
  25   28  
  26   29  /*
  27   30   * Fletcher Checksums
  28   31   * ------------------
  29   32   *
  30   33   * ZFS's 2nd and 4th order Fletcher checksums are defined by the following
  31   34   * recurrence relations:
  32   35   *
  33   36   *      a  = a    + f
  34   37   *       i    i-1    i-1
↓ open down ↓ 89 lines elided ↑ open up ↑
 124  127   * For both cached and uncached data, both fletcher checksums are much faster
 125  128   * than sha-256, and slower than 'off', which doesn't touch the data at all.
 126  129   */
 127  130  
 128  131  #include <sys/types.h>
 129  132  #include <sys/sysmacros.h>
 130  133  #include <sys/byteorder.h>
 131  134  #include <sys/zio.h>
 132  135  #include <sys/spa.h>
 133  136  
      137 +/*ARGSUSED*/
 134  138  void
 135      -fletcher_2_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
      139 +fletcher_2_native(const void *buf, uint64_t size, const zio_cksum_salt_t *salt,
      140 +    const void *ctx_template, zio_cksum_t *zcp)
 136  141  {
 137  142          const uint64_t *ip = buf;
 138  143          const uint64_t *ipend = ip + (size / sizeof (uint64_t));
 139  144          uint64_t a0, b0, a1, b1;
 140  145  
 141  146          for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
 142  147                  a0 += ip[0];
 143  148                  a1 += ip[1];
 144  149                  b0 += a0;
 145  150                  b1 += a1;
 146  151          }
 147  152  
 148  153          ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
 149  154  }
 150  155  
      156 +/*ARGSUSED*/
 151  157  void
 152      -fletcher_2_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
      158 +fletcher_2_byteswap(const void *buf, uint64_t size,
      159 +    const zio_cksum_salt_t *salt, const void *ctx_template, zio_cksum_t *zcp)
 153  160  {
 154  161          const uint64_t *ip = buf;
 155  162          const uint64_t *ipend = ip + (size / sizeof (uint64_t));
 156  163          uint64_t a0, b0, a1, b1;
 157  164  
 158  165          for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
 159  166                  a0 += BSWAP_64(ip[0]);
 160  167                  a1 += BSWAP_64(ip[1]);
 161  168                  b0 += a0;
 162  169                  b1 += a1;
 163  170          }
 164  171  
 165  172          ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
 166  173  }
 167  174  
      175 +/*ARGSUSED*/
 168  176  void
 169      -fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
      177 +fletcher_4_native(const void *buf, uint64_t size, const zio_cksum_salt_t *salt,
      178 +    const void *ctx_template, zio_cksum_t *zcp)
 170  179  {
 171  180          const uint32_t *ip = buf;
 172  181          const uint32_t *ipend = ip + (size / sizeof (uint32_t));
 173  182          uint64_t a, b, c, d;
 174  183  
 175  184          for (a = b = c = d = 0; ip < ipend; ip++) {
 176  185                  a += ip[0];
 177  186                  b += a;
 178  187                  c += b;
 179  188                  d += c;
 180  189          }
 181  190  
 182  191          ZIO_SET_CHECKSUM(zcp, a, b, c, d);
 183  192  }
 184  193  
      194 +/*ARGSUSED*/
 185  195  void
 186      -fletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
      196 +fletcher_4_byteswap(const void *buf, uint64_t size,
      197 +    const zio_cksum_salt_t *salt, const void *ctx_template, zio_cksum_t *zcp)
 187  198  {
 188  199          const uint32_t *ip = buf;
 189  200          const uint32_t *ipend = ip + (size / sizeof (uint32_t));
 190  201          uint64_t a, b, c, d;
 191  202  
 192  203          for (a = b = c = d = 0; ip < ipend; ip++) {
 193  204                  a += BSWAP_32(ip[0]);
 194  205                  b += a;
 195  206                  c += b;
 196  207                  d += c;
↓ open down ↓ 50 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX