The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/cddl/boot/zfs/blake3_zfs.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 631a4f0a5decff36dd62497291854511


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.