siphash

package
v0.1.59999 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 2 Imported by: 0

README

siphash

Wrapper around github.com/dchest/siphash providing SipHash-2-4 for the go-i2p/crypto ecosystem.

SipHash is used by NTCP2 for obfuscated frame-length encoding.

Functions

Function Description
Hash(k0, k1, data) SipHash-2-4 → 64-bit digest
Hash128(k0, k1, data) SipHash-2-4-128 → two 64-bit halves
New(key) Streaming hash.Hash64 for incremental hashing
New128(key) Streaming hash.Hash for 128-bit SipHash

Documentation

Overview

Package siphash provides a thin wrapper around github.com/dchest/siphash, centralising third-party SipHash access within the go-i2p/crypto layer.

SipHash is a fast, cryptographically strong pseudorandom function optimised for short inputs. In I2P it is used by NTCP2 for obfuscated frame-length encoding (SipHash-2-4 with a 128-bit key derived during the handshake).

All callers in the go-i2p ecosystem SHOULD import this package instead of the upstream library directly, so that the implementation can be audited and swapped in a single location.

Example usage:

key0, key1 := binary.LittleEndian.Uint64(k[0:8]), binary.LittleEndian.Uint64(k[8:16])
hash := siphash.Hash(key0, key1, data)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(k0, k1 uint64, data []byte) uint64

Hash returns the SipHash-2-4 of the given message with two 64-bit key parts. This is the primary entry-point used by NTCP2 frame-length obfuscation.

Parameters:

  • k0: First 64-bit half of the 128-bit SipHash key
  • k1: Second 64-bit half of the 128-bit SipHash key
  • data: The message to hash

Returns:

  • uint64: The 64-bit SipHash-2-4 digest

func Hash128

func Hash128(k0, k1 uint64, data []byte) (lo, hi uint64)

Hash128 returns both 64-bit halves of a SipHash-2-4-128 digest. Some protocols require the full 128-bit output for stronger collision resistance or to derive two independent values from a single hash.

Parameters:

  • k0: First 64-bit half of the 128-bit SipHash key
  • k1: Second 64-bit half of the 128-bit SipHash key
  • data: The message to hash

Returns:

  • lo: Lower 64 bits of the 128-bit digest
  • hi: Upper 64 bits of the 128-bit digest

func New

func New(key []byte) hash.Hash64

New returns a new hash.Hash64 computing SipHash-2-4 with the given 128-bit key. The key slice must be exactly 16 bytes long.

The returned hash.Hash64 implements streaming writes via Write() and final digest retrieval via Sum64(), which is useful when data is accumulated incrementally.

Parameters:

  • key: A 16-byte (128-bit) SipHash key

Returns:

  • hash.Hash64: A streaming SipHash-2-4 instance

func New128

func New128(key []byte) hash.Hash

New128 returns a new hash.Hash computing SipHash-2-4-128 with the given 128-bit key. The key slice must be exactly 16 bytes long.

Parameters:

  • key: A 16-byte (128-bit) SipHash key

Returns:

  • hash.Hash: A streaming SipHash-2-4-128 instance

Types

This section is empty.

Jump to

Keyboard shortcuts

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