Documentation
¶
Index ¶
- Constants
- Variables
- func Combine(parts [][]byte) ([]byte, error)
- func CombineSecure(parts [][]byte, expectedThreshold int) ([]byte, error)
- func CombineWithIntegrity(parts [][]byte) ([]byte, error)
- func Split(secret []byte, parts, threshold int) ([][]byte, error)
- func SplitSecure(secret []byte, parts, threshold int, enforceThreshold bool) ([][]byte, error)
- func SplitWithIntegrity(secret []byte, parts, threshold int) ([][]byte, error)
- type ValidationError
Constants ¶
ShareOverhead represents the byte overhead added to each share. Each share contains one additional byte for the x-coordinate identifier.
Variables ¶
var ( // ErrEmptySecret indicates that an empty secret was provided for splitting. ErrEmptySecret = errors.New("shamir: cannot split empty secret") // ErrInvalidParts indicates that the number of parts is outside the valid range [2, 255]. ErrInvalidParts = errors.New("shamir: parts must be between 2 and 255") // ErrInvalidThreshold indicates that the threshold is outside the valid range [2, parts]. ErrInvalidThreshold = errors.New("shamir: threshold must be between 2 and parts") // ErrTooFewParts indicates that fewer than 2 shares were provided for reconstruction. ErrTooFewParts = errors.New("shamir: at least 2 shares required for reconstruction") // ErrDifferentLengths indicates that shares have different lengths, making reconstruction impossible. ErrDifferentLengths = errors.New("shamir: all shares must have the same length") // ErrTooShort indicates that shares are too short to contain valid data. ErrTooShort = errors.New("shamir: shares must be at least 2 bytes long") // ErrDuplicatePart indicates that duplicate shares (same x-coordinate) were provided. // This name is kept for compatibility with existing code. ErrDuplicatePart = errors.New("shamir: duplicate shares detected") // ErrIntegrityCheckFailed indicates that a share's integrity check (CRC32) failed. ErrIntegrityCheckFailed = errors.New("shamir: share integrity check failed") ErrInsufficientShares = errors.New("shamir: insufficient shares for reconstruction") ErrNilShares = errors.New("shamir: shares cannot be nil") // ErrZeroThreshold indicates that a zero threshold was provided. ErrZeroThreshold = errors.New("shamir: threshold cannot be zero") )
Standard errors for Shamir Secret Sharing operations. These errors provide clear, actionable information about what went wrong.
Functions ¶
func Combine ¶
Combine reconstructs the original secret from a set of shares using Lagrange interpolation. Requires at least threshold number of shares that were generated by Split.
Parameters:
- parts: Array of shares (at least 2 shares required)
Returns:
- []byte: The reconstructed secret
- error: Validation error if shares are invalid or insufficient
The reconstruction uses Lagrange interpolation to evaluate the polynomial at x=0, which gives the original secret (the constant term of the polynomial).
func CombineWithIntegrity ¶
func Split ¶
Split divides a secret into n shares using Shamir's Secret Sharing algorithm. The secret can be reconstructed from any k shares where k >= threshold.
Parameters:
- secret: The data to be split (must not be empty)
- parts: Total number of shares to generate (2-255)
- threshold: Minimum shares needed for reconstruction (2 <= threshold <= parts)
Returns:
- [][]byte: Array of shares, each containing the x-coordinate and y-values
- error: Validation error if parameters are invalid
Each share is len(secret)+1 bytes: [x-coordinate][y-values...] The x-coordinate uniquely identifies each share (1-based indexing).
func SplitSecure ¶
Types ¶
type ValidationError ¶
type ValidationError struct { Field string // The field that failed validation Value int // The invalid value Message string // Human-readable error message }
ValidationError represents a validation error with context about what failed.
func NewValidationError ¶
func NewValidationError(field string, value int, message string) *ValidationError
NewValidationError creates a new validation error with context.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string