obytes

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

README

obytes

an easy to use Obfuscated Bytes package.

Description

This simple package provide simple bytes obfuscations mechanisms.

  • merge data with of a set of random bytes according to a user defined bitmask, a single byte becomes two obfuscated bytes.
  • random obfuscated key, random obfuscated nonce, xchacha20+poly1305.

How the obfuscation works

"Masks" defines how random bits are distributed in each obfuscated byte. The default mask is 0x55 : [0101 0101]

The byte obfuscation transform one data byte nibble into one obfuscated byte, such that

  • bits that are 0 become random bits.
  • bits that are 1 become data bits.

You need a mask byte for one byte nibble of data, hence user provided masks requires a nibble high mask and nibble low mask. !IMPORTANT! you should ALWAYS make sure to have evenly distributed random/data bits in each mask.

Carefully chosen masks allows to recover your byte out of 2 obfuscated bytes.

Examples

Obfuscate bytes using default mask:

	obfuscated, err := Obfuscate(input)
	if err != nil {
		// handle error
	}
	// obfuscated is len(input)*2 and is obfuscated

	deobfuscated_input, err := Deobfuscate(obfuscated)
	if err != nil {
		// handle error
	}

Obfuscate bytes using a user defined mask:

	obfuscated, err := ObfuscateWithMask(input, 0xf0, 0x0f)
	if err != nil {
		// handle error
	}
	// obfuscated is len(input)*2 and is obfuscated

	deobfuscated_input, err := DeobfuscateWithMask(obfuscated, 0xf0, 0x0f)
	if err != nil {
		// handle error
	}

Obfuscate using an encrypted blob:

	obfuscated, err := NewBlob(input, 0x55, 0x55, 234)
	if err != nil {
		// handle error
	}
	// obfuscated is a blob of len(input)+(keysize*2)+(noncesize*2)+(aead overhead)+234
	// obfuscated is prefixed by 234 random bytes.

Documentation

Index

Constants

View Source
const (
	ErrInvalidInput = Error("invalid input")
	ErrUnexpected   = Error("unexpected error")
	ErrCrypto       = Error("crypto error")
)
View Source
const (
	HighNibble = 1
	LowNibble  = 0
)

Variables

View Source
var (
	MaskDefault  = [...]byte{0x55, 0x55}
	MaskHalfFlaH = [...]byte{0xf0, 0x0f}
	MaskFlahHalf = [...]byte{0x0f, 0xf0}
)

I NEED TO DEFINE MASKs as a pair of byte constants..

Functions

func Deobfuscate

func Deobfuscate(in []byte) (out []byte, err error)

func DeobfuscateWithMask added in v0.2.0

func DeobfuscateWithMask(in []byte, hi, lo byte) (out []byte, err error)

can process it with any number of bytes

func NewBlob added in v0.2.0

func NewBlob(in []byte, mask_hi, mask_lo byte, prefixlen int) (out []byte, err error)

this just an obfuscation mechanism to hide "structure" in a flow of bytes with an overhead, it is NOT in ANY WAY a way to SECURE DATA, it is a simple obfuscation.

func Obfuscate

func Obfuscate(in []byte) (out []byte, err error)

can process it with any number of bytes

func ObfuscateWithMask added in v0.2.0

func ObfuscateWithMask(in []byte, hi, lo byte) (out []byte, err error)

func OpenBlob added in v0.2.0

func OpenBlob(in []byte, mask_hi, mask_lo byte, prefixlen int) (out []byte, err error)

Types

type Error

type Error string

Error is the type helping defining errors as constants.

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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