fec-0.2.0: Forward error correction of ByteStrings
CopyrightAdam Langley
LicenseGPLv2+|TGPPLv1+ (see README.rst for details)
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Codec.FEC

Description

The module provides k of n encoding - a way to generate (n - k) secondary blocks of data from k primary blocks such that any k blocks (primary or secondary) are sufficient to regenerate all blocks.

All blocks must be the same length and you need to keep track of which blocks you have in order to tell decode. By convention, the blocks are numbered 0..(n - 1) and blocks numbered < k are the primary blocks.

Synopsis

Documentation

data FECParams Source #

Instances

Instances details
Show FECParams Source # 
Instance details

Defined in Codec.FEC

Generic FECParams Source # 
Instance details

Defined in Codec.FEC

Associated Types

type Rep FECParams :: Type -> Type #

NFData FECParams Source # 
Instance details

Defined in Codec.FEC

Methods

rnf :: FECParams -> () #

type Rep FECParams Source # 
Instance details

Defined in Codec.FEC

initialize :: IO () Source #

Initialize the library. This must be done before other APIs can succeed.

fec Source #

Arguments

:: Int

the number of primary blocks

-> Int

the total number blocks, must be < 256

-> FECParams 

Return a FEC with the given parameters.

encode Source #

Arguments

:: FECParams 
-> [ByteString]

a list of k input blocks

-> [ByteString]

(n - k) output blocks

Generate the secondary blocks from a list of the primary blocks. The primary blocks must be in order and all of the same size. There must be k primary blocks.

decode Source #

Arguments

:: FECParams 
-> [(Int, ByteString)]

a list of k blocks and their index

-> [ByteString]

a list the k primary blocks

Recover the primary blocks from a list of k blocks. Each block must be tagged with its number (see the module comments about block numbering)

Utility functions

secureDivide Source #

Arguments

:: Int

the number of parts requested

-> ByteString

the data to be split

-> IO [ByteString] 

Break a ByteString into n parts, equal in length to the original, such that all n are required to reconstruct the original, but having less than n parts reveals no information about the orginal.

This code works in IO monad because it needs a source of random bytes, which it gets from devurandom. If this file doesn't exist an exception results

Not terribly fast - probably best to do it with short inputs (e.g. an encryption key)

secureCombine :: [ByteString] -> ByteString Source #

Reverse the operation of secureDivide. The order of the inputs doesn't matter, but they must all be the same length

enFEC Source #

Arguments

:: Int

the number of blocks required to reconstruct

-> Int

the total number of blocks

-> ByteString

the data to divide

-> [ByteString]

the resulting blocks

A utility function which takes an arbitary input and FEC encodes it into a number of blocks. The order the resulting blocks doesn't matter so long as you have enough to present to deFEC.

deFEC Source #

Arguments

:: Int

the number of blocks required (matches call to enFEC)

-> Int

the total number of blocks (matches call to enFEC)

-> [ByteString]

a list of k, or more, blocks from enFEC

-> ByteString 

Reverses the operation of enFEC.