ffrs.RS256#
- class ffrs.RS256#
Reed-Solomon coding over \(GF(2^8)\)
Methods
Instantiate a Reed-Solomon encoder with the given configuration
Systematic decode
Systematic encode
Encode the input buffer in blocks, storing the parity bytes right next to their corresponding block
Attributes
RS256.block_len
RS256.ecc_len
RS256.generator
RS256.generator_roots
RS256.gf
RS256.message_len
- __init__(self: ffrs.RS256, block_len: int | None = None, message_len: int | None = None, ecc_len: int | None = None, primitive: int = 2, polynomial: int = 285) None #
Instantiate a Reed-Solomon encoder with the given configuration
- Examples:
RS256(255, 223)
Equivalent to
RS256(ecc_len=32)
Creates an encoder for 32 bytes of parity, capable of correcting up to 16 errors in a 255-byte block.
RS256(6, 4)
block_len ╭──────┴──────╮ 🟦🟦🟦🟦🟨🟨 ╰────┬───╯╰─┬─╯ message_len ecc_len
- Parameters:
- block_len
- \(n\) – default block size used by
encode_blocks()
block_len = message_len + ecc_len
Defaults to255
Note
The maximum possible
block_len
forRS256
is 255 bytes
- message_len
- \(k\) – number of actual data bytes in a blockCan be omitted if
ecc_len
is supplied
- ecc_len
- \((n - k)\) – number of parity bytes in a blockCan be omitted if
message_len
is supplied
- primitive
- \(a\) – primitive value for
GF256
Defaults to2
- polynomial
- \(P\) – irreducible polynomial for
GF256
Defaults to0x11b
- decode(self: ffrs.RS256, buffer: Buffer) bool #
Systematic decode
- encode(self: ffrs.RS256, buffer: Buffer) None #
Systematic encode
- encode_blocks(self: ffrs.RS256, buffer: Buffer, block_len: int | None = None) bytearray #
Encode the input buffer in blocks, storing the parity bytes right next to their corresponding block
- Example:
Considering
RS256(6, 4)
and 32 bytes of input:
import ffrs, random rs62 = ffrs.RS256(6, 4) input_buffer = random.randbytes(32) output_buffer = rs62.encode_blocks(input_buffer)
Input buffer (32 bytes): 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 Output buffer (32 data bytes + 16 parity bytes): 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨
Note
To allow concatenating the results of multiple calls to
encode_blocks()
, the size ofbuffer
should be a multiple ofRS256.message_len
(orblock_size - RS256.ecc_len
if the argumentblock_size
is notNone
)If the size of the input buffer is not a multiple of
RS256.message_len
the remaining bytes at the end of the buffer will be encoded as if the block size were smaller.- Example:
Considering
RS256(6, 4)
and 29 bytes of input:
Input buffer (29 bytes): 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦🟦🟦🟦 🟦 Output buffer (29 data bytes + 16 parity bytes): 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟨🟨