utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrecomputedRandomness []byte

Global variable to hold precomputed randomness

View Source
var RandomnessIndex int

Functions

func CalculateBetaDelta

func CalculateBetaDelta(p uint64, B float64, q uint64) *big.Int

CalculateBetaDelta computes ((B * p) - q) / (2 * q) as a big.Int

func CompareSecrets

func CompareSecrets(r *ring.Ring, reconstructed, original structs.Vector[ring.Poly]) bool

CompareSecrets compares the reconstructed secret with the original.

func ConvertMatrixFromNTT

func ConvertMatrixFromNTT(r *ring.Ring, M structs.Matrix[ring.Poly])

ConvertMatrixFromNTT converts a matrix of polynomials from the NTT domain back to the standard domain.

func ConvertMatrixToNTT

func ConvertMatrixToNTT(r *ring.Ring, M structs.Matrix[ring.Poly])

ConvertMatrixToNTT converts a matrix of polynomials to the NTT domain.

func ConvertVectorFromNTT

func ConvertVectorFromNTT(r *ring.Ring, vec structs.Vector[ring.Poly])

ConvertVectorFromNTT converts a vector of polynomials from the NTT domain back to the standard domain.

func ConvertVectorToNTT

func ConvertVectorToNTT(r *ring.Ring, vec structs.Vector[ring.Poly])

ConvertVectorToNTT converts a vector of polynomials to the NTT domain.

func CopyMatrixMap

func CopyMatrixMap(original map[int]structs.Matrix[ring.Poly]) map[int]structs.Matrix[ring.Poly]

func CopyVectorMap

func CopyVectorMap(original map[int]structs.Vector[ring.Poly]) map[int]structs.Vector[ring.Poly]

func FormatBigIntSlice

func FormatBigIntSlice(slice []*big.Int) string

func GaussianEliminationModQ

func GaussianEliminationModQ(mat [][]*big.Int, q *big.Int) bool

GaussianEliminationModQ performs Gaussian elimination mod q and checks if the matrix is full rank

func GetRandomBytes

func GetRandomBytes(n int) []byte

GetRandomBytes returns the next n bytes of precomputed randomness

func GetRandomInt

func GetRandomInt(q *big.Int) *big.Int

GetRandomInt returns a random integer from the precomputed randomness

func InitializeMatrix

func InitializeMatrix(r *ring.Ring, rows, cols int) structs.Matrix[ring.Poly]

InitializeMatrix creates and returns a matrix of the given dimensions, initializing each element as a new polynomial.

func InitializeVector

func InitializeVector(r *ring.Ring, length int) structs.Vector[ring.Poly]

InitializeVector creates and returns a vector of the given length, initializing each element as a new polynomial.

func MatrixAdd

func MatrixAdd(r *ring.Ring, M1, M2, result structs.Matrix[ring.Poly])

MatrixAdd adds two matrices of ring.Poly element-wise and stores the result in a given result matrix.

func MatrixMatrixMul

func MatrixMatrixMul(r *ring.Ring, M1, M2 structs.Matrix[ring.Poly], result structs.Matrix[ring.Poly])

MatrixMatrixMul performs matrix-matrix multiplication.

func MatrixMatrixMulNTT

func MatrixMatrixMulNTT(r *ring.Ring, M1, M2 structs.Matrix[ring.Poly], result structs.Matrix[ring.Poly])

MatrixMatrixMul performs matrix-matrix multiplication.

func MatrixMatrixMulNaive

func MatrixMatrixMulNaive(r *ring.Ring, M1, M2 structs.Matrix[ring.Poly], result structs.Matrix[ring.Poly])

MatrixMatrixMul performs matrix-matrix multiplication. It takes two matrices of ring.Poly pointers, M1 of dimensions m x p and M2 of dimensions p x n, and outputs the result in a given result matrix of dimensions m x n.

func MatrixVectorMul

func MatrixVectorMul(r *ring.Ring, M structs.Matrix[ring.Poly], vec structs.Vector[ring.Poly], result structs.Vector[ring.Poly])

MatrixVectorMul performs matrix-vector multiplication.

func MatrixVectorMulNTT

func MatrixVectorMulNTT(r *ring.Ring, M structs.Matrix[ring.Poly], vec structs.Vector[ring.Poly], result structs.Vector[ring.Poly])

MatrixVectorMul performs matrix-vector multiplication.

func MatrixVectorMulNaive

func MatrixVectorMulNaive(r *ring.Ring, M structs.Matrix[ring.Poly], vec structs.Vector[ring.Poly], result structs.Vector[ring.Poly])

MatrixVectorMul performs matrix-vector multiplication. It takes a matrix of ring.Poly pointers, a vector of ring.Poly pointers, and outputs the result in a given result vector.

func MulCoeffsNTT

func MulCoeffsNTT(r *ring.Ring, p1, p2, result ring.Poly)

MulCoeffsNTT performs coefficient-wise multiplication of two polynomials in the NTT domain.

func MulPolyNTT

func MulPolyNTT(r *ring.Ring, p1 ring.Poly, p2 ring.Poly, p3 ring.Poly)

Sets p3 = p1 * p2 by first converting into NTT, multiplying coefficient-wise, and then converting out of NTT with INTT

func MulPolyNaive

func MulPolyNaive(r *ring.Ring, p1 ring.Poly, p2 ring.Poly, p3 ring.Poly)

func PrecomputeRandomness

func PrecomputeRandomness(size int, key []byte)

PrecomputeRandomness precomputes all necessary randomness and stores it in the global variable

func PrintBigIntVector

func PrintBigIntVector(label string, vector structs.Vector[[]*big.Int])

PrintBigIntVector prints a vector of slices of *big.Int elements

func PrintMatrix

func PrintMatrix(label string, matrix structs.Matrix[ring.Poly])

func PrintPolynomial

func PrintPolynomial(label string, poly ring.Poly)

func PrintSignRepresentation

func PrintSignRepresentation(r *ring.Ring, poly ring.Poly, modulus uint64)

func PrintSignRepresentationMatrix

func PrintSignRepresentationMatrix(r *ring.Ring, matrix structs.Matrix[ring.Poly], modulus uint64)

func PrintSignRepresentationVector

func PrintSignRepresentationVector(r *ring.Ring, vec structs.Vector[ring.Poly], modulus uint64)

func PrintVector

func PrintVector(label string, vector structs.Vector[ring.Poly])

func ReconstructSecret

func ReconstructSecret(r *ring.Ring, shares map[int]structs.Vector[ring.Poly], lagrangeCoeffs map[int]ring.Poly) structs.Vector[ring.Poly]

ReconstructSecret reconstructs the secret using the shares and Lagrange coefficients.

func RestoreCoefficients

func RestoreCoefficients(r *ring.Ring, newRing *ring.Ring, poly ring.Poly, roundingVal uint) ring.Poly

RestoreCoefficients multiplies each coefficient of the polynomial by 2^roundingVal

func RestoreVector

func RestoreVector(r *ring.Ring, newRing *ring.Ring, v structs.Vector[ring.Poly], roundingVal uint) structs.Vector[ring.Poly]

RestoreVector multiplies each polynomial in the vector by 2^roundingVal

func RoundCoefficients

func RoundCoefficients(r *ring.Ring, newRing *ring.Ring, poly ring.Poly, roundingVal uint) ring.Poly

RoundCoefficients rounds each coefficient of the polynomial as specified

func RoundVector

func RoundVector(r *ring.Ring, newRing *ring.Ring, v structs.Vector[ring.Poly], roundingVal uint) structs.Vector[ring.Poly]

RoundVector rounds each polynomial in the vector

func SamplePolyMatrix

func SamplePolyMatrix(r *ring.Ring, rows, cols int, sampler ring.Sampler, NTT bool, montgomery bool) structs.Matrix[ring.Poly]

SamplePolyMatrix samples a matrix of polynomials with given dimensions (rows and cols) using the provided sampler.

func SamplePolyVector

func SamplePolyVector(r *ring.Ring, length int, sampler ring.Sampler, NTT bool, montgomery bool) structs.Vector[ring.Poly]

SamplePolyVector samples a vector of polynomials of a given length using the provided sampler.

func SignedRepresentation

func SignedRepresentation(coeffs []*big.Int, Q uint64)

Convert to signed representation

func VectorAdd

func VectorAdd(r *ring.Ring, v1, v2, result structs.Vector[ring.Poly])

VectorAdd adds two vectors of ring.Poly element-wise and stores the result in a result vector.

func VectorPolyMul

func VectorPolyMul(r *ring.Ring, vec structs.Vector[ring.Poly], poly ring.Poly, result structs.Vector[ring.Poly])

VectorPolyMul performs element-wise multiplication of a vector by a polynomial.

func VectorPolyMulNTT

func VectorPolyMulNTT(r *ring.Ring, vec structs.Vector[ring.Poly], poly ring.Poly, result structs.Vector[ring.Poly])

VectorPolyMul performs element-wise multiplication of a vector by a polynomial.

func VectorPolyMulNaive

func VectorPolyMulNaive(r *ring.Ring, vec structs.Vector[ring.Poly], poly ring.Poly, result structs.Vector[ring.Poly])

VectorPolyMulNaive performs element-wise multiplication of a vector by a polynomial. It takes a vector of ring.Poly pointers, a single ring.Poly pointer, and outputs the result in a given result vector.

func VectorSub

func VectorSub(r *ring.Ring, v1, v2, result structs.Vector[ring.Poly])

VectorSub subtracts two vectors of ring.Poly element-wise and stores the result in a result vector.

Types

This section is empty.

Jump to

Keyboard shortcuts

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