Print this page
4185 New hash algorithm support

@@ -20,16 +20,21 @@
  */
 /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright 2013 Saso Kiselkov. All rights reserved.
+ */
 #include <sys/zfs_context.h>
 #include <sys/zio.h>
 #include <sys/sha2.h>
 
+/*ARGSUSED*/
 void
-zio_checksum_SHA256(const void *buf, uint64_t size, zio_cksum_t *zcp)
+zio_checksum_SHA256(const void *buf, uint64_t size,
+    const zio_cksum_salt_t *salt, const void *ctx_template, zio_cksum_t *zcp)
 {
         SHA2_CTX ctx;
         zio_cksum_t tmp;
 
         SHA2Init(SHA256, &ctx);

@@ -45,6 +50,32 @@
          */
         zcp->zc_word[0] = BE_64(tmp.zc_word[0]);
         zcp->zc_word[1] = BE_64(tmp.zc_word[1]);
         zcp->zc_word[2] = BE_64(tmp.zc_word[2]);
         zcp->zc_word[3] = BE_64(tmp.zc_word[3]);
+}
+
+/*ARGSUSED*/
+void
+zio_checksum_SHA512_native(const void *buf, uint64_t size,
+    const zio_cksum_salt_t *salt, const void *ctx_template, zio_cksum_t *zcp)
+{
+        SHA2_CTX        ctx;
+
+        SHA2Init(SHA512_256, &ctx);
+        SHA2Update(&ctx, buf, size);
+        SHA2Final(zcp, &ctx);
+}
+
+/*ARGSUSED*/
+void
+zio_checksum_SHA512_byteswap(const void *buf, uint64_t size,
+    const zio_cksum_salt_t *salt, const void *ctx_template, zio_cksum_t *zcp)
+{
+        zio_cksum_t     tmp;
+
+        zio_checksum_SHA512_native(buf, size, salt, ctx_template, &tmp);
+        zcp->zc_word[0] = BSWAP_64(tmp.zc_word[0]);
+        zcp->zc_word[1] = BSWAP_64(tmp.zc_word[1]);
+        zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]);
+        zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]);
 }