egrw

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package egrw implements the Expander Graph Random Walk problem for kMOSAIC.

Index

Constants

View Source
const (
	DomainStart   = "kmosaic-egrw-start-v1"
	DomainWalk    = "kmosaic-egrw-walk-v1"
	DomainEncrypt = "kmosaic-egrw-encrypt-v1"
	DomainMask    = "kmosaic-egrw-mask-v1"
)

Variables

This section is empty.

Functions

func ApplyGenerator

func ApplyGenerator(element kmosaic.SL2Element, genIdx, p int) kmosaic.SL2Element

ApplyGenerator multiplies an element by one of the generators. genIdx is an index into the generator list returned by GetGenerators.

func ApplyWalk

func ApplyWalk(start kmosaic.SL2Element, walk []int, p int) kmosaic.SL2Element

ApplyWalk applies a sequence of generator multiplications starting from 'start'. The walk is defined by a sequence of generator indices.

func BytesToSL2

func BytesToSL2(data []byte) kmosaic.SL2Element

BytesToSL2 deserializes a 16-byte slice to an SL(2, Z_p) element. Panics if data is less than 16 bytes; callers must validate input length.

func Decrypt

Decrypt decrypts an EGRW ciphertext

func DeserializePublicKey added in v1.0.1

func DeserializePublicKey(data []byte) (*kmosaic.EGRWPublicKey, error)

DeserializePublicKey deserializes EGRW public key

func Encrypt

func Encrypt(pk kmosaic.EGRWPublicKey, message []byte, params kmosaic.EGRWParams, randomness []byte) (*kmosaic.EGRWCiphertext, error)

Encrypt encrypts a message fragment using EGRW

func GetGenerators

func GetGenerators(p int) []kmosaic.SL2Element

GetGenerators returns the standard generating set for SL(2, Z_p). The generators are S = [[0, -1], [1, 0]] and T = [[1, 1], [0, 1]], along with their inverses. The results are cached to avoid recomputation.

func KeyGen

func KeyGen(params kmosaic.EGRWParams, seed []byte) (*kmosaic.EGRWKeyPair, error)

KeyGen generates EGRW key pair

func ModInverse

func ModInverse(a, p int) (int, error)

ModInverse computes the modular multiplicative inverse a^(-1) mod p. It uses the extended Euclidean algorithm. Returns an error if a is 0.

func SL2Inverse

func SL2Inverse(m kmosaic.SL2Element, p int) kmosaic.SL2Element

SL2Inverse computes the inverse of an SL(2, Z_p) element. For a matrix [[A, B], [C, D]] with determinant 1, the inverse is [[D, -B], [-C, A]].

func SL2Multiply

func SL2Multiply(m1, m2 kmosaic.SL2Element, p int) kmosaic.SL2Element

SL2Multiply multiplies two SL(2, Z_p) elements. The result is (m1 * m2) mod p.

func SL2ToBytes

func SL2ToBytes(m kmosaic.SL2Element) []byte

SL2ToBytes serializes an SL(2, Z_p) element to a 16-byte slice. Each component (A, B, C, D) is stored as a 4-byte little-endian integer.

func SerializePublicKey

func SerializePublicKey(pk kmosaic.EGRWPublicKey) []byte

SerializePublicKey serializes EGRW public key

Types

This section is empty.

Jump to

Keyboard shortcuts

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