Linear Feedback Shift Registers
README.md

lfsr #

Linear Feedback Shift Registers.

A space link that has nothing to send still transmits frames, and CCSDS fills those Only Idle Data (OID) frames with pseudo-noise from a linear feedback shift register, so an observer cannot tell idle traffic from real traffic. lfsr provides configurable registers in Fibonacci form with up to 62 bits of state, and a preset for the CCSDS OID register: 32 cells, polynomial x^32 + x^22 + x^2 + x + 1 (CCSDS 132.0-B-3 Annex D).

In Fibonacci form the register shifts one place per step, and the bit shifted in is the parity (XOR) of the tapped cells. Here the register shifts right, outputs its least significant bit, and feeds the parity of state land taps into its top cell. The CCSDS polynomial taps bits 0, 10, 30 and 31, which is the mask 0xC0000401 in the example below.

Installation #

Install with opam:

$ opam install lfsr

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install lfsr

Usage #

(* CCSDS OID frame randomization: noise XORs with frame data *)
let ccsds = Lfsr.ccsds_oid ()
let noise = Lfsr.generate ccsds 256
let () = Printf.printf "generated %d bytes of noise\n" (Bytes.length noise)

(* Custom LFSR *)
let custom = Lfsr.v ~taps:0xC0000401 ~seed:0xFFFFFFFF ~width:32
let () = Printf.printf "0x%02X\n" (Lfsr.next_byte custom)

API Overview #

  • t is a mutable register.
  • v builds a register from its taps, seed and width (1 to 62 bits).
  • ccsds_oid is the CCSDS 132.0-B-3 OID preset.
  • step advances one bit and returns the output bit, 0 or 1.
  • next_byte advances eight bits and returns them as a byte, MSB first.
  • fill and generate produce pseudo-noise into a buffer or a fresh one.
  • state and width read the register.

License #

ISC