Documentation
¶
Overview ¶
Package crypto provides cryptographic primitives for secure anonymous communication.
This package implements the core cryptographic operations required for anonymous broadcast protocols, including:
- Field arithmetic for finite field operations (auction data)
- Key management (Ed25519 signing, P-256 key exchange)
- XOR-based blinding vector generation for privacy-preserving message aggregation
- Field-based blinding for auction data aggregation
Field Operations ¶
The package uses a 384-bit prime field (AuctionFieldOrder) for auction-related operations where homomorphic addition is required.
Blinding ¶
Two blinding mechanisms are provided:
- XOR-based blinding for message vectors (DeriveXorBlindingVector)
- Field arithmetic blinding for auction IBLT vectors (DeriveBlindingVector)
Security Note ¶
Not all operations are constant-time (particularly field arithmetic). This may leak timing information about field element values.
Index ¶
- Variables
- func Decrypt(recipientPrivKey *ecdh.PrivateKey, msg *EncryptedMessage) ([]byte, error)
- func DeriveBlindingVector(sharedSecrets []SharedKey, round uint32, nEls int32, fieldOrder *big.Int) []*big.Int
- func DeriveXorBlindingVector(sharedSecrets []SharedKey, round uint32, nBytes int) []byte
- func FieldAddInplace(l *big.Int, r *big.Int, fieldOrder *big.Int) *big.Int
- func FieldSubInplace(l *big.Int, r *big.Int, fieldOrder *big.Int) *big.Int
- func GenerateKeyPair() (PublicKey, PrivateKey, error)
- func ServerIDsToXEvals(roundSIds []ServerID, availableSIds []ServerID) []*big.Int
- func XorInplace(l, r []byte) []byte
- type EncryptedMessage
- type PrivateKey
- type PublicKey
- type ServerID
- type SharedKey
- type Signature
Constants ¶
This section is empty.
Variables ¶
var AuctionFieldOrder *big.Int
AuctionFieldOrder defines the finite field order for auction operations
Functions ¶
func Decrypt ¶
func Decrypt(recipientPrivKey *ecdh.PrivateKey, msg *EncryptedMessage) ([]byte, error)
Decrypt decrypts an ECIES-encrypted message using the recipient's private key.
func DeriveBlindingVector ¶
func DeriveBlindingVector(sharedSecrets []SharedKey, round uint32, nEls int32, fieldOrder *big.Int) []*big.Int
DeriveBlindingVector generates field element blinding factors from shared secrets. Used for auction IBLT blinding where field arithmetic is required.
func DeriveXorBlindingVector ¶
DeriveXorBlindingVector generates XOR blinding bytes from shared secrets. Used for message vector blinding where XOR-based privacy is sufficient.
func FieldAddInplace ¶
FieldAddInplace performs modular addition in-place: l = (l + r) mod fieldOrder. The result is stored in l and also returned.
func FieldSubInplace ¶
FieldSubInplace performs modular subtraction in-place: l = (l - r) mod fieldOrder. The result is stored in l and also returned.
func GenerateKeyPair ¶
func GenerateKeyPair() (PublicKey, PrivateKey, error)
GenerateKeyPair generates a new Ed25519 key pair for signing and verification.
func ServerIDsToXEvals ¶
ServerIDsToXEvals converts server IDs to x-coordinates for polynomial evaluation. Maps server IDs to sequential integers 1..n based on sorted order.
func XorInplace ¶
XorInplace performs byte-wise XOR: l[i] ^= r[i] for all i. Returns l for chaining.
Types ¶
type EncryptedMessage ¶
type EncryptedMessage struct {
EphemeralPubKey []byte // P-256 uncompressed public key
Nonce []byte // AES-GCM nonce
Ciphertext []byte // Encrypted data with auth tag
}
EncryptedMessage contains ECIES-encrypted data. Format: ephemeral pubkey (65 bytes) || nonce (12 bytes) || ciphertext+tag
func Encrypt ¶
func Encrypt(recipientPubKey *ecdh.PublicKey, plaintext []byte) (*EncryptedMessage, error)
Encrypt encrypts plaintext to a recipient's ECDH public key using ECIES. Uses ephemeral ECDH key agreement and AES-256-GCM for authenticated encryption.
func ParseEncryptedMessage ¶
func ParseEncryptedMessage(data []byte) (*EncryptedMessage, error)
ParseEncryptedMessage deserializes an encrypted message.
func (*EncryptedMessage) Bytes ¶
func (m *EncryptedMessage) Bytes() []byte
Bytes serializes an encrypted message.
type PrivateKey ¶
type PrivateKey []byte
PrivateKey represents a private key used for signing and key exchange. The implementation uses Ed25519 private keys.
func NewPrivateKeyFromBytes ¶
func NewPrivateKeyFromBytes(data []byte) PrivateKey
NewPrivateKeyFromBytes creates a PrivateKey from a byte slice.
func (PrivateKey) Bytes ¶
func (sk PrivateKey) Bytes() []byte
Bytes returns the private key as a byte slice.
func (PrivateKey) PublicKey ¶
func (sk PrivateKey) PublicKey() (PublicKey, error)
PublicKey derives the public key corresponding to this private key.
type PublicKey ¶
type PublicKey []byte
PublicKey represents a public key used for authentication and encryption. In ADCNet, public keys are used to verify signatures and as client/server identifiers. The implementation uses Ed25519 public keys.
func NewPublicKeyFromBytes ¶
NewPublicKeyFromBytes creates a PublicKey from a byte slice.
func NewPublicKeyFromString ¶
NewPublicKeyFromString creates a PublicKey from a hex-encoded string.
type ServerID ¶
type ServerID uint32
ServerID is a unique identifier for a server derived from its public key.
func PublicKeyToServerID ¶
PublicKeyToServerID derives a server ID from a public key using SHA256.
type SharedKey ¶
type SharedKey []byte
SharedKey represents a Diffie-Hellman shared secret used for deriving blinding vectors.
func NewSharedKey ¶
NewSharedKey creates a SharedKey from a byte slice.
type Signature ¶
type Signature []byte
Signature represents a digital signature produced with a private key.
func NewSignature ¶
NewSignature creates a Signature from a byte slice.
func Sign ¶
func Sign(privateKey PrivateKey, data []byte) (Signature, error)
Sign signs data with the given private key using Ed25519.