compress

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: ISC Imports: 2 Imported by: 0

README

compress

Build Status ISC License Doc

Overview

Package compress implements the BLAKE-224 and BLAKE-256 block compression function. It provides a pure Go implementation as well as specialized implementations that take advantage of vector extensions (SSE2, SSE4.1, and AVX) on the amd64 architecture when they are supported.

The package detects hardware support and arranges for the exported Blocks function to automatically use the fastest available supported hardware extensions that are not disabled.

Tests and Benchmarks

The package also provides full tests for all implementations as well as benchmarks. However, do note that since the specialized implementations require hardware support, the tests and benchmarks for them will be skipped when running on hardware that does not support the required extensions.

It is possible to test all implementations without hardware support by using software such as the Intel Software Development Emulator.

Some relevant flags for testing purposes with the Intel SDE are:

  • SSE2: -p4p Set chip-check and CPUID for Intel(R) Pentium4 Prescott CPU
  • SSE41: -pnr Set chip-check and CPUID for Intel(R) Penryn CPU
  • AVX: -snb Set chip-check and CPUID for Intel(R) Sandy Bridge CPU

Disabling Assembler Optimizations

The purego build tag may be used to disable all assembly code.

Additionally, when built normally without the purego build tag, the assembly optimizations for each of the supported vector extensions can individually be disabled at runtime by setting the following environment variables to 1.

  • BLAKE256_DISABLE_AVX=1: Disable Advanced Vector Extensions (AVX) optimizations
  • BLAKE256_DISABLE_SSE41=1: Disable Streaming SIMD Extensions 4.1 (SSE4.1) optimizations
  • BLAKE256_DISABLE_SSE2=1: Disable Streaming SIMD Extensions 2 (SSE2) optimizations

Installation and Updating

This package is internal and therefore is neither directly installed nor needs to be manually updated.

License

Package compress is licensed under the copyfree ISC License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blocks

func Blocks(state *State, msg []byte, counter uint64)

Blocks performs BLAKE-224 and BLAKE-256 block compression using processor specific vector extensions when available. It will compress as many full blocks as are available in the provided message.

The parameters are:

state: the block compression state with the chain value and salt
msg: the padded message to compress (must be at least 64 bytes)
counter: the total number of message bits hashed so far

It will panic if the provided message block does not have at least 64 bytes.

The chain value in the passed state is updated in place.

Types

type State

type State struct {
	CV [8]uint32 // the current chain value
	S  [4]uint32 // salt (zero by default)
}

State houses the current chain value and salt used during block compression. It is housed in a separate struct in order to reduce the number of parameters to help prevent register spillage on platforms with a limited number of registers for better performance.

Jump to

Keyboard shortcuts

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