1*45818ee1SMatthew Ahrens /* 2*45818ee1SMatthew Ahrens * CDDL HEADER START 3*45818ee1SMatthew Ahrens * 4*45818ee1SMatthew Ahrens * The contents of this file are subject to the terms of the 5*45818ee1SMatthew Ahrens * Common Development and Distribution License (the "License"). 6*45818ee1SMatthew Ahrens * You may not use this file except in compliance with the License. 7*45818ee1SMatthew Ahrens * 8*45818ee1SMatthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*45818ee1SMatthew Ahrens * or http://opensource.org/licenses/CDDL-1.0. 10*45818ee1SMatthew Ahrens * See the License for the specific language governing permissions 11*45818ee1SMatthew Ahrens * and limitations under the License. 12*45818ee1SMatthew Ahrens * 13*45818ee1SMatthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each 14*45818ee1SMatthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*45818ee1SMatthew Ahrens * If applicable, add the following below this CDDL HEADER, with the 16*45818ee1SMatthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying 17*45818ee1SMatthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18*45818ee1SMatthew Ahrens * 19*45818ee1SMatthew Ahrens * CDDL HEADER END 20*45818ee1SMatthew Ahrens */ 21*45818ee1SMatthew Ahrens /* 22*45818ee1SMatthew Ahrens * Copyright 2013 Saso Kiselkov. All rights reserved. 23*45818ee1SMatthew Ahrens */ 24*45818ee1SMatthew Ahrens #include <sys/zfs_context.h> 25*45818ee1SMatthew Ahrens #include <sys/zio.h> 26*45818ee1SMatthew Ahrens #include <sys/skein.h> 27*45818ee1SMatthew Ahrens 28*45818ee1SMatthew Ahrens /* 29*45818ee1SMatthew Ahrens * Computes a native 256-bit skein MAC checksum. Please note that this 30*45818ee1SMatthew Ahrens * function requires the presence of a ctx_template that should be allocated 31*45818ee1SMatthew Ahrens * using zio_checksum_skein_tmpl_init. 32*45818ee1SMatthew Ahrens */ 33*45818ee1SMatthew Ahrens /*ARGSUSED*/ 34*45818ee1SMatthew Ahrens void 35*45818ee1SMatthew Ahrens zio_checksum_skein_native(const void *buf, uint64_t size, 36*45818ee1SMatthew Ahrens const void *ctx_template, zio_cksum_t *zcp) 37*45818ee1SMatthew Ahrens { 38*45818ee1SMatthew Ahrens Skein_512_Ctxt_t ctx; 39*45818ee1SMatthew Ahrens 40*45818ee1SMatthew Ahrens ASSERT(ctx_template != NULL); 41*45818ee1SMatthew Ahrens bcopy(ctx_template, &ctx, sizeof (ctx)); 42*45818ee1SMatthew Ahrens (void) Skein_512_Update(&ctx, buf, size); 43*45818ee1SMatthew Ahrens (void) Skein_512_Final(&ctx, (uint8_t *)zcp); 44*45818ee1SMatthew Ahrens bzero(&ctx, sizeof (ctx)); 45*45818ee1SMatthew Ahrens } 46*45818ee1SMatthew Ahrens 47*45818ee1SMatthew Ahrens /* 48*45818ee1SMatthew Ahrens * Byteswapped version of zio_checksum_skein_native. This just invokes 49*45818ee1SMatthew Ahrens * the native checksum function and byteswaps the resulting checksum (since 50*45818ee1SMatthew Ahrens * skein is internally endian-insensitive). 51*45818ee1SMatthew Ahrens */ 52*45818ee1SMatthew Ahrens void 53*45818ee1SMatthew Ahrens zio_checksum_skein_byteswap(const void *buf, uint64_t size, 54*45818ee1SMatthew Ahrens const void *ctx_template, zio_cksum_t *zcp) 55*45818ee1SMatthew Ahrens { 56*45818ee1SMatthew Ahrens zio_cksum_t tmp; 57*45818ee1SMatthew Ahrens 58*45818ee1SMatthew Ahrens zio_checksum_skein_native(buf, size, ctx_template, &tmp); 59*45818ee1SMatthew Ahrens zcp->zc_word[0] = BSWAP_64(tmp.zc_word[0]); 60*45818ee1SMatthew Ahrens zcp->zc_word[1] = BSWAP_64(tmp.zc_word[1]); 61*45818ee1SMatthew Ahrens zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]); 62*45818ee1SMatthew Ahrens zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]); 63*45818ee1SMatthew Ahrens } 64*45818ee1SMatthew Ahrens 65*45818ee1SMatthew Ahrens /* 66*45818ee1SMatthew Ahrens * Allocates a skein MAC template suitable for using in skein MAC checksum 67*45818ee1SMatthew Ahrens * computations and returns a pointer to it. 68*45818ee1SMatthew Ahrens */ 69*45818ee1SMatthew Ahrens void * 70*45818ee1SMatthew Ahrens zio_checksum_skein_tmpl_init(const zio_cksum_salt_t *salt) 71*45818ee1SMatthew Ahrens { 72*45818ee1SMatthew Ahrens Skein_512_Ctxt_t *ctx; 73*45818ee1SMatthew Ahrens 74*45818ee1SMatthew Ahrens ctx = kmem_zalloc(sizeof (*ctx), KM_SLEEP); 75*45818ee1SMatthew Ahrens (void) Skein_512_InitExt(ctx, sizeof (zio_cksum_t) * 8, 0, 76*45818ee1SMatthew Ahrens salt->zcs_bytes, sizeof (salt->zcs_bytes)); 77*45818ee1SMatthew Ahrens return (ctx); 78*45818ee1SMatthew Ahrens } 79*45818ee1SMatthew Ahrens 80*45818ee1SMatthew Ahrens /* 81*45818ee1SMatthew Ahrens * Frees a skein context template previously allocated using 82*45818ee1SMatthew Ahrens * zio_checksum_skein_tmpl_init. 83*45818ee1SMatthew Ahrens */ 84*45818ee1SMatthew Ahrens void 85*45818ee1SMatthew Ahrens zio_checksum_skein_tmpl_free(void *ctx_template) 86*45818ee1SMatthew Ahrens { 87*45818ee1SMatthew Ahrens Skein_512_Ctxt_t *ctx = ctx_template; 88*45818ee1SMatthew Ahrens 89*45818ee1SMatthew Ahrens bzero(ctx, sizeof (*ctx)); 90*45818ee1SMatthew Ahrens kmem_free(ctx, sizeof (*ctx)); 91*45818ee1SMatthew Ahrens } 92