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/contrib/openzfs/include/sys/blake3.h

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 https://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  * Based on BLAKE3 v1.3.1, https://github.com/BLAKE3-team/BLAKE3
   24  * Copyright (c) 2019-2020 Samuel Neves and Jack O'Connor
   25  * Copyright (c) 2021 Tino Reichardt <milky-zfs@mcmilk.de>
   26  */
   27 
   28 #ifndef BLAKE3_H
   29 #define BLAKE3_H
   30 
   31 #ifdef  _KERNEL
   32 #include <sys/types.h>
   33 #else
   34 #include <stdint.h>
   35 #include <stdlib.h>
   36 #endif
   37 
   38 #ifdef __cplusplus
   39 extern "C" {
   40 #endif
   41 
   42 #define BLAKE3_KEY_LEN          32
   43 #define BLAKE3_OUT_LEN          32
   44 #define BLAKE3_MAX_DEPTH        54
   45 #define BLAKE3_BLOCK_LEN        64
   46 #define BLAKE3_CHUNK_LEN        1024
   47 
   48 /*
   49  * This struct is a private implementation detail.
   50  * It has to be here because it's part of BLAKE3_CTX below.
   51  */
   52 typedef struct {
   53         uint32_t cv[8];
   54         uint64_t chunk_counter;
   55         uint8_t buf[BLAKE3_BLOCK_LEN];
   56         uint8_t buf_len;
   57         uint8_t blocks_compressed;
   58         uint8_t flags;
   59 } blake3_chunk_state_t;
   60 
   61 typedef struct {
   62         uint32_t key[8];
   63         blake3_chunk_state_t chunk;
   64         uint8_t cv_stack_len;
   65 
   66         /*
   67          * The stack size is MAX_DEPTH + 1 because we do lazy merging. For
   68          * example, with 7 chunks, we have 3 entries in the stack. Adding an
   69          * 8th chunk requires a 4th entry, rather than merging everything down
   70          * to 1, because we don't know whether more input is coming. This is
   71          * different from how the reference implementation does things.
   72          */
   73         uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
   74 
   75         /* const blake3_ops_t *ops */
   76         const void *ops;
   77 } BLAKE3_CTX;
   78 
   79 /* init the context for hash operation */
   80 void Blake3_Init(BLAKE3_CTX *ctx);
   81 
   82 /* init the context for a MAC and/or tree hash operation */
   83 void Blake3_InitKeyed(BLAKE3_CTX *ctx, const uint8_t key[BLAKE3_KEY_LEN]);
   84 
   85 /* process the input bytes */
   86 void Blake3_Update(BLAKE3_CTX *ctx, const void *input, size_t input_len);
   87 
   88 /* finalize the hash computation and output the result */
   89 void Blake3_Final(const BLAKE3_CTX *ctx, uint8_t *out);
   90 
   91 /* finalize the hash computation and output the result */
   92 void Blake3_FinalSeek(const BLAKE3_CTX *ctx, uint64_t seek, uint8_t *out,
   93     size_t out_len);
   94 
   95 /* these are pre-allocated contexts */
   96 extern void **blake3_per_cpu_ctx;
   97 extern void blake3_per_cpu_ctx_init(void);
   98 extern void blake3_per_cpu_ctx_fini(void);
   99 
  100 /* get count of supported implementations */
  101 extern uint32_t blake3_impl_getcnt(void);
  102 
  103 /* get id of selected implementation */
  104 extern uint32_t blake3_impl_getid(void);
  105 
  106 /* get name of selected implementation */
  107 extern const char *blake3_impl_getname(void);
  108 
  109 /* setup id as fastest implementation */
  110 extern void blake3_impl_set_fastest(uint32_t id);
  111 
  112 /* set implementation by id */
  113 extern void blake3_impl_setid(uint32_t id);
  114 
  115 /* set implementation by name */
  116 extern int blake3_impl_setname(const char *name);
  117 
  118 #ifdef __cplusplus
  119 }
  120 #endif
  121 
  122 #endif  /* BLAKE3_H */

Cache object: 133b03e97aca72551e6575d3508c7ecb


[ 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.