internal

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeySize NIST P-256 key size in bytes
	KeySize = 32
	// UncompressedPublicKeySize (1 byte prefix + 32 bytes X + 32 bytes Y)
	UncompressedPublicKeySize = 65
)

Variables

View Source
var (
	// General errors
	ErrInvalidParameters = errors.New("invalid parameters provided")
	ErrInternalError     = errors.New("internal library error")
	ErrMemoryAllocation  = errors.New("memory allocation failed")

	// Key generation errors
	ErrKeyGeneration         = errors.New("failed to generate cryptographic key")
	ErrInsufficientEntropy   = errors.New("insufficient entropy for key generation")
	ErrKeyMaterialExtraction = errors.New("failed to extract key material")

	// Key validation errors
	ErrInvalidKey       = errors.New("invalid cryptographic key")
	ErrInvalidKeyLength = errors.New("invalid key length")
	ErrInvalidKeyFormat = errors.New("invalid key format")
	ErrKeyNotOnCurve    = errors.New("public key point is not on the curve")
	ErrKeyAtInfinity    = errors.New("key point is at infinity (invalid)")
	ErrZeroScalar       = errors.New("private key scalar is zero (invalid)")
	ErrKeyOutOfRange    = errors.New("private key is not in valid range")

	// Cryptographic operation errors
	ErrPointAddition      = errors.New("elliptic curve point addition failed")
	ErrScalarAddition     = errors.New("scalar addition failed")
	ErrResultConversion   = errors.New("failed to convert operation result")
	ErrInsufficientBuffer = errors.New("result buffer is too small")

	// Hash-to-field errors
	ErrHashToField       = errors.New("hash-to-field operation failed")
	ErrExpandMessage     = errors.New("message expansion failed")
	ErrExpansionTooLarge = errors.New("expansion length exceeds buffer limits")

	// Key derivation errors
	ErrKeyDerivation   = errors.New("key derivation failed")
	ErrInputTooLarge   = errors.New("input data too large")
	ErrContextTooLarge = errors.New("context data too large")
	ErrDSTTooLarge     = errors.New("domain separation tag too large")

	// JWK and encoding errors
	ErrJWKCreation        = errors.New("failed to create JWK")
	ErrJWKExtraction      = errors.New("failed to extract key from JWK")
	ErrKeyTypeUnsupported = errors.New("unsupported key type")
	ErrCurveUnsupported   = errors.New("unsupported elliptic curve")

	// Workflow errors (F0, F1 functions)
	ErrEmptyEmailMap       = errors.New("email map cannot be empty")
	ErrEmptyEmail          = errors.New("email cannot be empty")
	ErrEmptyUUID           = errors.New("uuid cannot be empty")
	ErrUserNotFound        = errors.New("user data not found")
	ErrMasterKeyNotSet     = errors.New("master key not available")
	ErrSaltGeneration      = errors.New("failed to generate salt")
	ErrPayloadModification = errors.New("failed to modify VC payload")
)

Base error types for different categories of operations

Functions

func AddPublicKeys

func AddPublicKeys(key1Bytes, key2Bytes []byte) ([]byte, error)

AddPublicKeys adds two NIST P-256 public keys using elliptic curve point addition

func HashToField

func HashToField(hash, hashLen int, dst, message []byte, count int) error

HashToField performs hash-to-field operation for the given input

func IsCryptoError

func IsCryptoError(err error) bool

IsCryptoError checks if an error is related to cryptographic operations

func IsKeyError

func IsKeyError(err error) bool

IsKeyError checks if an error is related to key operations

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if an error is related to input validation

func MapDeriveKeyError

func MapDeriveKeyError(code CErrorCode) error

MapDeriveKeyError maps C key derivation error codes to Go errors

func MapECPError

func MapECPError(code CErrorCode) error

MapECPError maps C ECP (elliptic curve point) operation error codes to Go errors

func MapHashToFieldError

func MapHashToFieldError(code CErrorCode) error

MapHashToFieldError maps C hash-to-field operation error codes to Go errors

func MapSecretKeyError

func MapSecretKeyError(code CErrorCode) error

MapSecretKeyError maps C secret key addition error codes to Go errors

func ValidateBufferSize

func ValidateBufferSize(buffer []byte, requiredSize int, bufferName string) error

ValidateBufferSize validates that a buffer has sufficient capacity

func ValidateInputSize

func ValidateInputSize(data []byte, maxSize int, dataName string) error

ValidateInputSize validates input size against maximum allowed

func ValidateKeyLength

func ValidateKeyLength(keyBytes []byte, expectedLength int, keyName string) error

ValidateKeyLength validates that a key byte slice has the expected length

func ValidateNonEmpty

func ValidateNonEmpty(data []byte, dataName string) error

ValidateNonEmpty validates that data is not empty

func WrapError

func WrapError(err error, context string) error

WrapError wraps an error with additional context

Types

type CErrorCode

type CErrorCode int

CErrorCode represents C library error codes

type KeyMaterial

type KeyMaterial struct {
	PrivateKeyBytes [KeySize]byte
	PublicKeyXBytes [KeySize]byte
	PublicKeyYBytes [KeySize]byte
}

KeyMaterial represents extracted cryptographic key material

func AddSecretKeys

func AddSecretKeys(key1Bytes, key2Bytes []byte) (KeyMaterial, error)

AddSecretKeys adds two NIST P-256 private keys using scalar addition modulo curve order

func DeriveSecretKey

func DeriveSecretKey(masterKeyBytes, context, dst []byte) (KeyMaterial, error)

DeriveSecretKey derives a secret key from master key material using hash-to-field

func GenerateSecretKey

func GenerateSecretKey(seed []byte) (KeyMaterial, error)

GenerateSecretKey generates an NIST P-256 private key using cryptographically secure random data

func (KeyMaterial) GetKeyMaterialBytes

func (km KeyMaterial) GetKeyMaterialBytes() (privateKey, publicKeyX, publicKeyY []byte)

GetKeyMaterialBytes returns the key material as separate byte slices

func (KeyMaterial) IsValid

func (km KeyMaterial) IsValid() bool

IsValid checks if the key material appears to be valid

Jump to

Keyboard shortcuts

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