# lfsr Linear Feedback Shift Registers for OCaml. Configurable LFSRs (Fibonacci form) with up to 62-bit state. Includes a preset for CCSDS OID frame randomization (32-cell, polynomial x^32 + x^22 + x^2 + x + 1, per CCSDS 132.0-B-3 Annex D). Used for TRANSEC traffic flow confidentiality in satellite links. ## Installation Install with opam: ```sh $ 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: ```sh $ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git $ opam update $ opam install lfsr ``` ## Usage ```ocaml (* 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 - **`type t`** -- Mutable LFSR state - **`v`** -- Create LFSR with custom taps, seed, and width (1-62 bits) - **`ccsds_oid`** -- Preset for CCSDS 132.0-B-3 OID frame randomization - **`step`** -- Advance one bit, return output bit (0 or 1) - **`next_byte`** -- Advance 8 bits, return byte (MSB-first) - **`fill`** -- Fill a buffer with pseudo-noise - **`generate`** -- Generate n bytes of pseudo-noise - **`state`**, **`width`** -- Query register state ## License MIT