komblobulate

package module
v0.0.0-...-58b9ba7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2016 License: MIT Imports: 12 Imported by: 0

README

Komblobulate

Komblobulate is an encrypting, error resistant file container format, and a Go library for wrapping a file in this format. The library is available freely under the MIT license.

For a simple example of usage, see my kblob_cmd project, which implements a command line interface. Some day I might write some documentation.

Komblobulate provides:

  • Resistance against random bit flips in the file data
  • An encryption layer which may or may not prevent a user without the password from acquiring the plaintext of the file :)

Documentation

Index

Constants

View Source
const (
	NonceSize   = 12
	PreludeSize = 16
)
View Source
const (
	ResistType_None = byte(0)
	ResistType_Rs   = byte(1)

	CipherType_None = byte(0)
	CipherType_Aead = byte(1)
)
View Source
const (
	ConfigSize = 32 // bytes
)
View Source
const (
	CrcSize = 4
)
View Source
const (
	CurrentVersion = byte(1)
)
View Source
const (
	// The amount by which plaintext expanded into
	// ciphertext
	ExpansionAmount = 16
)

Variables

This section is empty.

Functions

func FillRandom

func FillRandom(buf []byte)

func NewReader

func NewReader(kblob io.ReadSeeker, params KCodecParams) (unblob io.Reader, err error)

Given a reader of a kblobbed output, creates a reader of the unblobbed contents. The kblob itself will contain its configuration.

func NewWriter

func NewWriter(kblob io.WriteSeeker, resistType byte, cipherType byte, params KCodecParams) (unblob io.WriteCloser, err error)

Given a writer of where the user wants the kblobbed output to go and a configuration, creates a writer for unblobbed contents.

func ReadAllOf

func ReadAllOf(reader io.Reader, buf []byte, offset int) (n int, err error)

Reads bytes into buf starting at offset. Returns (count read, error), where the output count will only ever be less than the input buffer length (minus the offset) if we hit an error.

func ReadConfig

func ReadConfig(reader io.ReadSeeker, offset int64) (config *Config, resist KCodec, cipher KCodec, err error)

func WriteAllOf

func WriteAllOf(writer io.Writer, buf []byte, offset int) (n int, err error)

Similarly, writes bytes from buf starting at offset, never fewer than the length of buf unless an error occurs.

Types

type AeadConfig

type AeadConfig struct {
	// This is the size of the chunks of actual plaintext that
	// we encrypt in one go.
	//
	// We actually encipher:
	// - 16 bytes random
	// - plaintext
	//
	// The data that we write to the
	// underlying stream will consist of:
	// - 12 bytes nonce
	// - ciphertext
	ChunkSize int64

	Salt [8]byte
}

func NewAeadConfig

func NewAeadConfig(chunkSize int64) (*AeadConfig, error)

func ReadAeadConfig

func ReadAeadConfig(reader io.Reader) (*AeadConfig, error)

func (*AeadConfig) ConfigEquals

func (c *AeadConfig) ConfigEquals(other interface{}) bool

func (*AeadConfig) NewReader

func (c *AeadConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (inner io.Reader, innerLength int64, err error)

func (*AeadConfig) NewWriter

func (c *AeadConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)

func (*AeadConfig) WriteConfig

func (c *AeadConfig) WriteConfig(writer io.Writer) (err error)

type AeadReaderWorker

type AeadReaderWorker struct {
	Config *AeadConfig
	Aead   cipher.AEAD

	CipherText       io.Reader
	CipherTextLength int64

	Nonce, Sealed, Chunk, Ad []byte

	// This tracks how much ciphertext we've read
	TextRead int64
}

func (*AeadReaderWorker) Ready

func (a *AeadReaderWorker) Ready(putChunk func([]byte) error) (err error)

type AeadWriterWorker

type AeadWriterWorker struct {
	Config *AeadConfig
	Aead   cipher.AEAD

	CipherText io.Writer

	Nonce, Chunk, Sealed, Ad []byte
}

func (*AeadWriterWorker) ChunkSize

func (a *AeadWriterWorker) ChunkSize() int

func (*AeadWriterWorker) Close

func (a *AeadWriterWorker) Close() error

func (*AeadWriterWorker) Ready

func (a *AeadWriterWorker) Ready(getPlain func([]byte) (int, error)) (err error)

type Config

type Config struct {
	Version    byte
	ResistType byte
	CipherType byte
}

func (*Config) ConfigEquals

func (c *Config) ConfigEquals(other *Config) bool

func (*Config) WriteConfig

func (c *Config) WriteConfig(writer io.Writer, resist KCodec, cipher KCodec) (err error)

type KCodec

type KCodec interface {
	// Checks for config equality.
	ConfigEquals(other interface{}) bool

	// This *must* write ConfigSize bytes.
	WriteConfig(io.Writer) error

	// Wraps a reader in a reader that decodes this kcodec
	// and returns it and the expected length of the decoded
	// data.
	// (reader, length available, parameters).
	NewReader(io.Reader, int64, KCodecParams) (io.Reader, int64, error)

	// Wraps a writer in a writer that decodes this kcodec.
	NewWriter(io.Writer, KCodecParams) (io.WriteCloser, error)
}

type KCodecParams

type KCodecParams interface {
	// Returns (data piece size, data piece count, parity piece count).
	GetRsParams() (int, int, int)

	GetAeadChunkSize() int
	GetAeadPassword() string
}

How to fetch the optional parameters for the codecs. We'll only call these if necessary. On read, only parameters not encoded in the file (i.e. GetAeadPassword() ) will be called.

type KblobReader

type KblobReader struct {
	Kblob  io.ReadSeeker
	Length int64
	Offset int64
}

func NewKblobReader

func NewKblobReader(kblob io.ReadSeeker, bloblen int64) (*KblobReader, error)

func (*KblobReader) Read

func (kb *KblobReader) Read(p []byte) (n int, err error)

type KblobWriter

type KblobWriter struct {
	Config *Config
	Resist KCodec
	Cipher KCodec

	OuterWriter  io.WriteSeeker
	ResistWriter io.WriteCloser
	CipherWriter io.WriteCloser
}

func (*KblobWriter) Close

func (kb *KblobWriter) Close() (err error)

func (*KblobWriter) Write

func (kb *KblobWriter) Write(p []byte) (n int, err error)

type NullConfig

type NullConfig struct{}

func (*NullConfig) ConfigEquals

func (c *NullConfig) ConfigEquals(other interface{}) bool

func (*NullConfig) NewReader

func (c *NullConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (io.Reader, int64, error)

func (*NullConfig) NewWriter

func (c *NullConfig) NewWriter(outer io.Writer, params KCodecParams) (io.WriteCloser, error)

func (*NullConfig) WriteConfig

func (c *NullConfig) WriteConfig(writer io.Writer) error

type NullWriteCloser

type NullWriteCloser struct {
	Outer io.Writer
}

func (*NullWriteCloser) Close

func (w *NullWriteCloser) Close() error

func (*NullWriteCloser) Write

func (w *NullWriteCloser) Write(p []byte) (int, error)

type ReaderWorker

type ReaderWorker interface {
	// Called whenever we're ready to receive a chunk,
	// with a function that will write the chunk
	// into the read buffer.
	Ready(func([]byte) error) error
}

type RsConfig

type RsConfig struct {
	// The byte size of each piece, minus the CRC
	DataPieceSize int32

	// The number of data pieces in each separate
	// RS matrix.
	DataPieceCount int8

	// The number of parity pieces in each separate
	// RS matrix.
	ParityPieceCount int8

	// The total number of data bytes contained inside the
	// reed-solomon encoding.  (The encoded data may have
	// been padded at the end.)
	TotalInnerLength int64
}

func ReadRsConfig

func ReadRsConfig(reader io.Reader) (*RsConfig, error)

func (*RsConfig) ConfigEquals

func (c *RsConfig) ConfigEquals(other interface{}) bool

func (*RsConfig) NewReader

func (c *RsConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (inner io.Reader, innerLength int64, err error)

func (*RsConfig) NewWriter

func (c *RsConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)

func (*RsConfig) WriteConfig

func (c *RsConfig) WriteConfig(writer io.Writer) (err error)

type RsReaderWorker

type RsReaderWorker struct {
	Config *RsConfig

	ResistText io.Reader

	Pieces        [][]byte
	PieceNum      int
	MissingPieces int

	// This tracks how much data we've decoded
	InnerLengthRead int64

	CrcTab *crc32.Table
	Enc    reedsolomon.Encoder
}

func (*RsReaderWorker) Ready

func (r *RsReaderWorker) Ready(putChunk func([]byte) error) (err error)

type RsWriterWorker

type RsWriterWorker struct {
	Config *RsConfig

	ResistText io.Writer

	Chunk    []byte
	Pieces   [][]byte
	PieceNum int

	CrcTab *crc32.Table
	Enc    reedsolomon.Encoder
}

func (*RsWriterWorker) ChunkSize

func (r *RsWriterWorker) ChunkSize() int

func (*RsWriterWorker) Close

func (r *RsWriterWorker) Close() (err error)

func (*RsWriterWorker) Ready

func (r *RsWriterWorker) Ready(getPlain func([]byte) (int, error)) (err error)

type WorkerReader

type WorkerReader struct {
	Worker ReaderWorker

	Bufs            [2]bytes.Buffer
	CurrentInputBuf int
	Ready           chan int
	Error           chan error
}

func NewAeadReader

func NewAeadReader(config *AeadConfig, aead cipher.AEAD, outer io.Reader, outerLength int64) *WorkerReader

func NewRsReader

func NewRsReader(config *RsConfig, outer io.Reader) *WorkerReader

func NewWorkerReader

func NewWorkerReader(worker ReaderWorker) *WorkerReader

func (*WorkerReader) Decode

func (w *WorkerReader) Decode(bufIdx int)

func (*WorkerReader) Read

func (w *WorkerReader) Read(p []byte) (n int, err error)

type WorkerWriter

type WorkerWriter struct {
	Worker WriterWorker

	Bufs            [2]bytes.Buffer
	CurrentInputBuf int
	Ready           chan int
	Finished        chan error
}

func NewAeadWriter

func NewAeadWriter(config *AeadConfig, aead cipher.AEAD, outer io.Writer) *WorkerWriter

func NewRsWriter

func NewRsWriter(config *RsConfig, outer io.Writer) *WorkerWriter

func NewWorkerWriter

func NewWorkerWriter(worker WriterWorker) *WorkerWriter

func (*WorkerWriter) Close

func (w *WorkerWriter) Close() (err error)

func (*WorkerWriter) Encode

func (w *WorkerWriter) Encode()

func (*WorkerWriter) UpdateConfig

func (w *WorkerWriter) UpdateConfig(config KCodec)

func (*WorkerWriter) Write

func (w *WorkerWriter) Write(p []byte) (n int, err error)

type WriterWorker

type WriterWorker interface {
	// The chunk size to send to the worker;
	// this should be a constant value.
	ChunkSize() int

	// Called whenever a chunk is ready, with a
	// function that reads the chunk into a slice and
	// returns how many bytes were read.
	Ready(func([]byte) (int, error)) error

	// Called at the end of the encode to finish up:
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL