codephrase

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codephrase generates croc codes and resolves them into relay-room and PAKE components.

Index

Constants

View Source
const (
	SSHCodeWordCount = 6
)

Variables

View Source
var ErrCodeTooShort = errors.New("code is too short (must be at least 6 characters)")

ErrCodeTooShort is returned when a croc code is shorter than six bytes.

View Source
var ErrInvalidRelayCount = errors.New("relay count must be positive")

ErrInvalidRelayCount is returned when a code cannot be assigned because the public relay pool is empty.

View Source
var ErrInvalidRelayIndex = errors.New("relay index is outside the relay pool")

ErrInvalidRelayIndex is returned when a requested relay is outside the pool.

Functions

func Generate

func Generate() (string, error)

Generate returns a cryptographically random three-word EFF code.

func GenerateForRelay

func GenerateForRelay(relayIndex, relayCount int) (string, error)

GenerateForRelay returns a normal three-word EFF code assigned to relayIndex by RelayIndex. On average it generates relayCount candidates.

func GenerateSSH

func GenerateSSH() (string, error)

GenerateSSH returns a cryptographically random six-word SSH invitation.

func RelayIndex

func RelayIndex(code string, relayCount int) (int, error)

RelayIndex deterministically assigns the exact UTF-8 bytes of code to an entry in an ordered relay pool. The complete SHA-256 digest is interpreted as an unsigned big-endian integer before taking the modulo.

Types

type Components

type Components struct {
	RoomName       string
	PAKEPassphrase string
	Format         Format
}

Components contains the protocol inputs derived from a user-facing croc code. RoomName is ready to send to a relay.

func Parse

func Parse(secret string) (Components, error)

Parse resolves a croc code into the relay room and PAKE passphrase used by the protocol. Exactly three lowercase ASCII words use the current three-word format. Four lowercase ASCII words keep compatibility with the previous four-word format; every other valid code uses croc's legacy byte-based split.

type Format

type Format string

Format identifies how a croc code is divided into its room and PAKE parts.

const (
	// FormatLegacy uses the first four bytes for the room and bytes after the
	// fifth byte for PAKE.
	FormatLegacy Format = "legacy"
	// FormatThreeWord uses the first word for the room and the final two words
	// for PAKE.
	FormatThreeWord Format = "three-word"
	// FormatFourWord uses the first two words for the room and the final two
	// words for PAKE. It is retained for compatibility with older codes.
	FormatFourWord Format = "four-word"
)

type SSHComponents

type SSHComponents struct {
	RoomName       string
	PAKEPassphrase string
}

SSHComponents contains the rendezvous and PAKE inputs for a croc SSH invitation. SSH codes deliberately use more entropy than file-transfer codes: two words select an unguessable relay room and four words remain in the PAKE password.

func ParseSSH

func ParseSSH(secret string) (SSHComponents, error)

ParseSSH resolves a six-word SSH invitation into its relay room and PAKE password. Only words from croc's embedded EFF list are accepted, which keeps parsing unambiguous even though one list entry ("yo-yo") contains a hyphen.

Jump to

Keyboard shortcuts

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