github.com/ethersphere/bee/v2@v2.2.0/pkg/bmt/doc.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package bmt implements Binary Merkle Tree hash.
     6  // Binary Merkle Tree Hash is a hash function over arbitrary byte slices of limited size.
     7  // The BMT hash is defined as H(header|bmt-root) where header is an 8-byte metadata prefix and
     8  // bmt-root is the root hash of the binary merkle tree built over fixed size segments
     9  // of the underlying chunk using any base hash function H (e.g., keccak 256 SHA3).
    10  // The segment size is the same as the hash size of H.
    11  // The number of segments on the base must be a power of 2 so that the resulting tree is balanced.
    12  // Chunks with data shorter than the fixed size are hashed as if they had zero padding.
    13  //
    14  // BMT hash is used as the chunk hash function in swarm which in turn is the basis for the
    15  // 128 branching swarm hash used to represent files.
    16  //
    17  // The BMT is optimal for providing compact inclusion proofs, i.e. prove that a
    18  // segment is a substring of a chunk starting at a particular offset.
    19  // The size of the underlying segments is fixed to the size of the base hash (called the resolution
    20  // of the BMT hash), Using Keccak256 SHA3 hash is 32 bytes, the EVM word size to optimize for on-chain BMT verification
    21  // as well as the hash size optimal for inclusion proofs in the merkle tree of the swarm hash.
    22  //
    23  // Two implementations are provided:
    24  //
    25  // RefHasher is optimized for code simplicity and meant as a reference implementation
    26  // that is simple to understand
    27  //
    28  // Hasher is optimized for speed taking advantage of concurrency with minimalistic concurrency control.
    29  //
    30  // BMT Hasher implements the following interfaces:
    31  //
    32  // - standard golang hash.Hash - synchronous, reusable
    33  //
    34  // - io.Writer - synchronous left-to-right datawriter.
    35  package bmt