hashtree

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 7 Imported by: 1

README

hashtree-bindings

Go bindings for the high-performance hashtree SHA-256 library with CPU-optimized implementations.

Overview

This repository provides Go bindings for the hashtree library, which implements highly optimized SHA-256 hashing with support for:

  • x86-64: AVX2, AVX512, SHA-NI (Intel SHA Extensions)
  • ARM64: NEON, ARM SHA2 crypto extensions
  • Fallback: Pure Go implementation for unsupported architectures

The library automatically selects the best available implementation at runtime based on CPU capabilities.

Hashtree Version

Built from hashtree library:

  • Commit: 8e32ae9
  • Version: untagged

Installation

go get github.com/pk910/hashtree-bindings

Usage

package main

import (
    "fmt"
    hashtree "github.com/pk910/hashtree-bindings"
)

func main() {
    // Single hash
    data := []byte("hello world")
    hash := hashtree.Hash(data)
    fmt.Printf("SHA256: %x\n", hash)
    
    // Parallel hashing (optimized for multiple inputs)
    inputs := [][]byte{
        []byte("input1"),
        []byte("input2"),
        []byte("input3"),
        []byte("input4"),
    }
    hashes := hashtree.HashParallel(inputs)
    for i, hash := range hashes {
        fmt.Printf("Hash[%d]: %x\n", i, hash)
    }
}

Performance

The hashtree library provides significant performance improvements over standard implementations:

  • Up to 8x faster than pure Go crypto/sha256 on AVX512 CPUs
  • Up to 4x faster on CPUs with SHA-NI support
  • Optimized parallel hashing for batch operations

Supported Platforms

Platform Architecture Optimizations
Linux amd64 AVX2, AVX512, SHA-NI
Linux arm64 NEON, SHA2
macOS arm64 (Apple Silicon) SHA2
Windows amd64 AVX2, AVX512, SHA-NI
Others any Pure Go fallback

Build Process

This repository uses GitHub Actions to automatically build and update static libraries from the hashtree submodule. The workflow:

  1. Runs daily to check for upstream changes
  2. Builds platform-specific static libraries
  3. Automatically commits updates when libraries change
Manual Build

To build the libraries manually:

# Clone with submodules
git clone --recursive https://github.com/pk910/hashtree-bindings
cd hashtree-bindings

# Build hashtree C library
cd hashtree
make libhashtree

# Build Go bindings
cd ..
go build

License

This project is licensed under the MIT License. See the LICENSE file for details.

The hashtree library implementation is based on work by:

Acknowledgments

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOddChunks is returned when the number of chunks is odd.
	ErrOddChunks = errors.New("odd number of chunks")
	// ErrNotEnoughDigests is returned when the number of digests is not enough.
	ErrNotEnoughDigests = errors.New("not enough digest length")
	// ErrChunksNotMultipleOf64 is returned when the chunks are not multiple of 64 bytes.
	ErrChunksNotMultipleOf64 = errors.New("chunks not multiple of 64 bytes")
	// ErrDigestsNotMultipleOf32 is returned when the digests are not multiple of 32 bytes.
	ErrDigestsNotMultipleOf32 = errors.New("digests not multiple of 32 bytes")
)

Functions

func Hash

func Hash(digests [][32]byte, chunks [][32]byte) error

Hash hashes the chunks two at the time and outputs the digests on the first argument. It does check for lengths on the inputs.

func HashByteSlice

func HashByteSlice(digests []byte, chunks []byte) error

HashByteSlice is the same as hash but it takes byte slices instead of slices of arrays.

func HashtreeHash

func HashtreeHash(output *byte, input *byte, count uint64)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL