/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://opensource.org/licenses/CDDL-1.0.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/20/*21* Copyright 2013 Saso Kiselkov. All rights reserved.22*/23#include <skein.h>2425/*26* Computes a native 256-bit skein MAC checksum. Please note that this27* function requires the presence of a ctx_template that should be allocated28* using zio_checksum_skein_tmpl_init.29*/30/*ARGSUSED*/31static void32zio_checksum_skein_native(const void *buf, uint64_t size,33const void *ctx_template, zio_cksum_t *zcp)34{35Skein_512_Ctxt_t ctx;3637ASSERT(ctx_template != NULL);38bcopy(ctx_template, &ctx, sizeof (ctx));39(void) Skein_512_Update(&ctx, buf, size);40(void) Skein_512_Final(&ctx, (uint8_t *)zcp);41bzero(&ctx, sizeof (ctx));42}4344/*45* Byteswapped version of zio_checksum_skein_native. This just invokes46* the native checksum function and byteswaps the resulting checksum (since47* skein is internally endian-insensitive).48*/49static void50zio_checksum_skein_byteswap(const void *buf, uint64_t size,51const void *ctx_template, zio_cksum_t *zcp)52{53zio_cksum_t tmp;5455zio_checksum_skein_native(buf, size, ctx_template, &tmp);56zcp->zc_word[0] = BSWAP_64(tmp.zc_word[0]);57zcp->zc_word[1] = BSWAP_64(tmp.zc_word[1]);58zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]);59zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]);60}6162/*63* Allocates a skein MAC template suitable for using in skein MAC checksum64* computations and returns a pointer to it.65*/66static void *67zio_checksum_skein_tmpl_init(const zio_cksum_salt_t *salt)68{69Skein_512_Ctxt_t *ctx;7071ctx = malloc(sizeof (*ctx));72bzero(ctx, sizeof (*ctx));73(void) Skein_512_InitExt(ctx, sizeof (zio_cksum_t) * 8, 0,74salt->zcs_bytes, sizeof (salt->zcs_bytes));75return (ctx);76}7778/*79* Frees a skein context template previously allocated using80* zio_checksum_skein_tmpl_init.81*/82static void83zio_checksum_skein_tmpl_free(void *ctx_template)84{85Skein_512_Ctxt_t *ctx = ctx_template;8687bzero(ctx, sizeof (*ctx));88free(ctx);89}909192