crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package crypto provides voice packet encryption and key management.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCiphertext = errors.New("crypto: invalid ciphertext")
	ErrDecryptionFailed  = errors.New("crypto: decryption failed")
)

Functions

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey generates a random AES-128 key (16 bytes).

func GenerateToken

func GenerateToken() (string, error)

GenerateToken generates a random token string (32 bytes, hex-like).

func HashPassword

func HashPassword(password string, salt []byte) []byte

HashPassword hashes a password using Argon2id.

func HashToken

func HashToken(token string) string

HashToken hashes a raw token string with SHA-256.

Types

type VoiceCipher

type VoiceCipher struct {
	// contains filtered or unexported fields
}

VoiceCipher handles AES-128-GCM encryption for voice packets.

func NewVoiceCipher

func NewVoiceCipher(key []byte) (*VoiceCipher, error)

NewVoiceCipher creates a new voice cipher from a 16-byte AES key.

func (*VoiceCipher) Decrypt

func (vc *VoiceCipher) Decrypt(sessionID uint32, seqNum uint32, header, ciphertext []byte) ([]byte, error)

Decrypt decrypts an encrypted Opus frame, verifying the header as additional data.

func (*VoiceCipher) Encrypt

func (vc *VoiceCipher) Encrypt(sessionID uint32, seqNum uint32, header, opus []byte) []byte

Encrypt encrypts an Opus frame, authenticating the header as additional data. Returns ciphertext with appended auth tag.

func (*VoiceCipher) Overhead

func (vc *VoiceCipher) Overhead() int

Overhead returns the number of bytes the AEAD adds to the plaintext (GCM auth tag).

Jump to

Keyboard shortcuts

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