rc4

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package rc4 implements the RC4 stream cipher (also known as ARC4, "alleged RC4") as a keystream generator.

GopherTrunk uses it to decode DMR voice traffic protected by ARC4-based "Enhanced Privacy" when the operator already holds the key. The Go standard library's crypto/rc4 is deprecated — it raises staticcheck SA1019 at every call site, which `make lint` rejects — so this small, dependency-free implementation is vendored in its place. It is pinned against the canonical RC4 test vectors in rc4_test.go so codebook drift stays detectable.

RC4 is cryptographically broken and must never be used to PROTECT data. It exists here only to DECODE third-party transmissions whose key the operator is authorized to hold — the same known-key model SDRTrunk, DSD-FME and OP25 use. No key recovery is performed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

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

Cipher is an RC4 keystream generator. A Cipher is stateful: every call to XORKeyStream or KeyStream advances the internal PRGA state, so one Cipher yields a single continuous keystream. A Cipher is not safe for concurrent use; construct one per call chain.

func NewCipher

func NewCipher(key []byte) (*Cipher, error)

NewCipher returns a Cipher keyed with key, which must be 1..256 bytes. The key-scheduling algorithm (KSA) runs here; the returned Cipher is positioned at the first keystream byte.

func (*Cipher) KeyStream

func (c *Cipher) KeyStream(n int) []byte

KeyStream returns the next n bytes of raw keystream and advances the Cipher by n bytes. It is equivalent to XORKeyStream against n zero bytes — convenient when the caller wants the keystream itself, for example to XOR onto a bit-unpacked voice frame.

func (*Cipher) XORKeyStream

func (c *Cipher) XORKeyStream(dst, src []byte)

XORKeyStream XORs each byte of src with the next keystream byte and writes the result to dst, advancing the keystream by len(src). dst must be at least len(src) long; dst and src may be the same slice.

Jump to

Keyboard shortcuts

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