permutation

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

github.com/fasasxc/permutation

Library for generating key-dependent permutations of (potentially big) integers.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArbitraryN

type ArbitraryN struct {
	// contains filtered or unexported fields
}

ArbitraryN builds on one of the block permutations to make a permutation over an arbitrary range. The underlying power-of-2 permutation is iterated to find an in-range result resulting in variable runtime.

func NewN

func NewN(key []byte, n *big.Int) *ArbitraryN

func NewNInt

func NewNInt(key []byte, n int) *ArbitraryN

func (*ArbitraryN) PermuteInPlace

func (p *ArbitraryN) PermuteInPlace(inOut *big.Int, tweak []byte) *big.Int

PermuteInPlace calculates inOut's permutated value and stores it back into inOut. Returns inOut as a convenience.

func (*ArbitraryN) PermuteInt

func (p *ArbitraryN) PermuteInt(in int) int
Example
const n = 5
p := NewNInt([]byte("mykey"), n)
for i := range n {
	fmt.Println(i, "->", p.PermuteInt(i))
}
Output:

0 -> 1
1 -> 4
2 -> 2
3 -> 0
4 -> 3

type FFX

type FFX struct {
	// contains filtered or unexported fields
}

FFX implements a permutation over [0, 2^lengthBits) using the FFX-A2 construction over AES. Key derivation uses HKDF, so the input key can be any length. Where needed, numbers are encoded in big-endian.

func NewFFX

func NewFFX(key []byte, lengthBits int) *FFX

func (*FFX) PermuteInPlace

func (p *FFX) PermuteInPlace(inOut *big.Int, tweak []byte) *big.Int

PermuteInPlace calculates inOut's permutated value and stores it back into inOut. Returns inOut as a convenience.

func (*FFX) PermuteInt

func (p *FFX) PermuteInt(in int) int

func (*FFX) RoundFunc

func (p *FFX) RoundFunc(i int, B uint64, tweak []byte) uint64

type FeistelSHAKE128

type FeistelSHAKE128 struct {
	// contains filtered or unexported fields
}

FeistelSHAKE128 implements a variable-length block cipher to generate a key-dependent permutation over [0, 2^n - 1]. It uses a Feistel construction with SHAKE128 as the PRF for the round function. This allows for arbitrarily-long inputs/outputs.

func NewPowerOf2

func NewPowerOf2(key []byte, lengthBits int) *FeistelSHAKE128

func (*FeistelSHAKE128) PermuteInPlace

func (p *FeistelSHAKE128) PermuteInPlace(inOut *big.Int, tweak []byte) *big.Int

PermuteInPlace calculates inOut's permutated value and stores it back into inOut. Returns inOut as a convenience.

func (*FeistelSHAKE128) PermuteInt

func (p *FeistelSHAKE128) PermuteInt(in int) int

func (*FeistelSHAKE128) RoundFunc

func (p *FeistelSHAKE128) RoundFunc(round int, b, out *big.Int, tweak []byte) *big.Int

type Permutation

type Permutation interface {
	PermuteInt(in int) int
	PermuteInPlace(inOut *big.Int, tweak []byte) *big.Int
}

Jump to

Keyboard shortcuts

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