ffrs.RS256¶
- class ffrs.RS256¶
Reed-Solomon coding over \(GF(2^8)\)
Methods
Instantiate a Reed-Solomon encoder with the given configuration
Encode message, return ecc
Repair message + ecc
Attributes
RS256.block_lenRS256.block_sizeRS256.ecc_lenRS256.ecc_sizeRS256.generatorRS256.generator_rootsRS256.gfRS256.message_lenRS256.message_size- __init__(self: libffrs.RS256, block_len: SupportsInt | SupportsIndex | None = None, message_len: SupportsInt | SupportsIndex | None = None, ecc_len: SupportsInt | SupportsIndex | None = None, primitive: SupportsInt | SupportsIndex = 2, polynomial: SupportsInt | SupportsIndex = 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(8, 6)block_len ╭───────┴───────╮ 🟦🟦🟦🟦🟦🟦🟨🟨 ╰─────┬────╯╰─┬─╯ message_len ecc_len
- Parameters:
- block_len
- \(n\) – default block size used by
encode_blocks()block_len = message_len + ecc_lenDefaults to255Note
The maximum possible
block_lenforRS256is 255 bytes
- message_len
- \(k\) – number of actual data bytes in a blockCan be omitted if
ecc_lenis supplied
- ecc_len
- \((n - k)\) – number of parity bytes in a blockCan be omitted if
message_lenis supplied
- primitive
- \(a\) – primitive value for
GF256Defaults to2
- polynomial
- \(P\) – irreducible polynomial for
GF256Defaults to0x11b
- encode(self: libffrs.RS256, buffer: collections.abc.Buffer) bytearray¶
Encode message, return ecc
- 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 ofbuffershould be a multiple ofRS256.message_len(orblock_size - RS256.ecc_lenif the argumentblock_sizeis notNone)If the size of the input buffer is not a multiple of
RS256.message_lenthe 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): 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨 🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟦🟦🟦🟨🟨🟦🟨🟨
- repair(self: libffrs.RS256, buffer: collections.abc.Buffer, ecc: collections.abc.Buffer) bool¶
Repair message + ecc