sign/encoding/signature_codec library

Compression and decompression of Falcon signature vectors.

Bit-for-bit port of compress / decompress from the Python reference (encoding.py). The scheme encodes each coefficient as:

  • 1 sign bit (1 when negative, 0 otherwise);
  • the 7 low bits of abs(coef), most-significant-bit first;
  • the high bits abs(coef) >> 7 in unary: that many 0 bits, then a terminating 1. All coefficients are concatenated into one bit string, zero-padded to 8 * slen bits, and packed MSB-first into bytes.

Web-safety: every value handled here is a small signature coefficient (well under 2^53) or a single bit, so plain ints are sufficient throughout.

Functions

compress(List<int> v, int slen) Uint8List?
Compress v into a bytestring of length slen.
decompress(Uint8List x, int slen, int n) List<int>?
Decompress x (of nominal length slen) into a vector of exactly n coefficients.