Documentation
¶
Index ¶
- Constants
- Variables
- func AddPadding(data []byte, size int) []byte
- func BlockToBytes(block Block) []byte
- func BytesToUint16(data [2]byte) uint16
- func BytesToUint32(data [4]byte) uint32
- func BytesToUint64(data []byte) uint64
- func FloatToTime(f float64) time.Time
- func GetBytesAsHex(key []byte) []byte
- func GetBytesFromHex(key []byte) []byte
- func GetFileSize(path string) (int64, error)
- func Int64To8Bytes(val int64) [8]byte
- func RandomBytes(size int) []byte
- func SecondsSince(t, start time.Time) float64
- func Sha256Sum(path string) [32]byte
- func ShrinkPadding(data []byte, size int) []byte
- func To2Bytes(b []byte) [2]byte
- func To4Bytes(b []byte) [4]byte
- func To8Bytes(b []byte) [8]byte
- func Uint16To2Bytes(val uint16) [2]byte
- func Uint16ToBytes(val uint16) []byte
- func Uint32To4Bytes(val uint32) [4]byte
- func Uint32ToBytes(val uint32) []byte
- func Uint64To8Bytes(val uint64) [8]byte
- func Uint64ToBytes(val uint64) []byte
- func Xor8Bytes(a, b [8]byte) [8]byte
- type Block
- type Blocks
- type ChaCha20Source
- type Duration
- type Feistel
- type FeistelKey
- type FeistelMasterKey
- type Header
- func (h Header) Kin() uint32
- func (h Header) Pos() uint32
- func (h Header) Profile(profile ProfileType) ProfileStore
- func (h Header) ProfilesToSeq() [16]byte
- func (h Header) Reserved() [8]byte
- func (h Header) Split() int
- func (h Header) ToBlock() HeaderBlock
- func (h Header) ToDataBlock() HeaderDataBlock
- func (h Header) ToInitBlock() HeaderInitBlock
- func (h Header) ValidSignature() bool
- func (h Header) Version() Version
- type HeaderBlock
- type HeaderContent
- type HeaderDataBlock
- type HeaderInitBlock
- type Key
- type MahChaKey
- func (k *MahChaKey) DecryptHeader(cipher []byte) Header
- func (k *MahChaKey) EncryptHeader(header Header) []byte
- func (k *MahChaKey) GetKin() uint32
- func (k *MahChaKey) GetRandomizer() *Randomizer
- func (k *MahChaKey) InitEncode(path string, profile ProfileType, split int) Header
- func (k *MahChaKey) ResetRandomizer()
- type Measure
- type MeasureTask
- type Nonce
- type Profile
- type ProfileStore
- type ProfileType
- type Randomizer
- type SBox
- type Version
- func (v Version) Is(major int, minor int) bool
- func (v Version) IsAtLeast(major int, minor int) bool
- func (v Version) IsAtLeastMajor(major int) bool
- func (v Version) IsAtLeastMinor(minor int) bool
- func (v Version) IsMajor(major int) bool
- func (v Version) IsMinor(minor int) bool
- func (v Version) To2Bytes() [2]byte
- func (v Version) ToBytes() []byte
- func (v Version) ToString() string
Constants ¶
const ( Low Profile = iota Medium High Max Custom Noise ProfileType = iota Mask Round FeistelRound MinSkip = 5731 MaxSkip = 207825 BlockSize = 16 // the size of a Block HeaderLength = 80 // The Header length HeaderInitLength = 8 // The HeaderInitBlock length HeaderDataLength = HeaderLength - HeaderInitLength // The HeaderDataBlock length KeyLength = 32 // The MahChaKey length NonceLength = 12 // The MahChaNonce length KinMin = uint32(1220000000) // The Key Initializer min value KinMax = uint32(4294967295) // The Key Initializer max value )
Variables ¶
var UseSIMD = haveSSE2
useSIMD peut être désactivé manuellement pour forcer le fallback Go
Functions ¶
func AddPadding ¶
Add padding of specified size to data if needed.
func BytesToUint16 ¶ added in v0.0.95
Convert specified []byte data as uint64 (using little endian).
func BytesToUint32 ¶ added in v0.0.95
Convert specified []byte data as uint64 (using little endian).
func BytesToUint64 ¶
Convert specified []byte data as uint64 (using little endian).
func FloatToTime ¶ added in v0.0.75
func GetBytesAsHex ¶ added in v0.0.7
func GetBytesFromHex ¶ added in v0.0.7
func GetFileSize ¶ added in v0.0.7
func Int64To8Bytes ¶ added in v0.0.7
Convert specified uint64 to [8]byte (using little endian).
func RandomBytes ¶
Generate random []byte of specified size using crypto/rand.
func SecondsSince ¶ added in v0.0.75
func ShrinkPadding ¶
Shrink padding on data at specified size.
func To2Bytes ¶ added in v0.0.5
Convert specified []byte to [2]byte. Emit a warning if b length is less than 2.
func To4Bytes ¶ added in v0.0.5
Convert specified []byte to [4]byte. Emit a warning if b length is less than 4.
func To8Bytes ¶ added in v0.0.5
Convert specified []byte to [8]byte. Emit a warning if b length is less than 8.
func Uint16To2Bytes ¶ added in v0.0.5
Convert specified uint32 to [4]byte (using little endian).
func Uint16ToBytes ¶ added in v0.0.5
Convert specified uint16 to []byte (using little endian).
func Uint32To4Bytes ¶ added in v0.0.5
Convert specified uint32 to [4]byte (using little endian).
func Uint32ToBytes ¶ added in v0.0.5
Convert specified uint32 to []byte (using little endian).
func Uint64To8Bytes ¶ added in v0.0.5
Convert specified uint64 to [8]byte (using little endian).
func Uint64ToBytes ¶
Convert specified uint64 to []byte (using little endian).
Types ¶
type Block ¶
type Block [16]byte
Block tyoe definition
type Blocks ¶
type Blocks []Block
func (*Blocks) AppendBytes ¶
Append specified []byte data convert as Block using little endian. It panics if len(data) don't fit BlockSize.
type ChaCha20Source ¶
type ChaCha20Source struct {
// contains filtered or unexported fields
}
Struct to represent a ChaCha20 source. This source has 2 internal counters state wich simulate a 64 bits counter. This means it can generates 2^64 blocks of 64 random bytes, so approximatively 1,048,576 Go (1 Po) of random data for a same key and nonce.
func NewChaCha20Source ¶
func NewChaCha20Source() (*ChaCha20Source, error)
Return a new ChaCha20Source initialized with a new key and a new nonce generated by crypto/rand.
func NewChaCha20SourceFrom ¶
func NewChaCha20SourceFrom(key Key, nonce Nonce) (*ChaCha20Source, error)
Return a new ChaCha20Source initialized with specified key and nonce.
func (*ChaCha20Source) Uint64 ¶
func (s *ChaCha20Source) Uint64() uint64
Generate a random uint64. If internal counterLo overflow, it switch to the counterHi wich simulate a 64 bits counter.
type Feistel ¶
type Feistel struct {
// contains filtered or unexported fields
}
Convenient Struct to represent a Feistel Cipher.
func NewFeistel ¶
func NewFeistel(masterKey FeistelMasterKey, round int) *Feistel
Return a new Feistel with specified masterKey and round. Internal keys will be derive from the masterKey using an Hkdf. Increasing round enhance diffusion.
func (*Feistel) DecryptMeasure ¶ added in v0.0.76
Decrypt specified cipher block and measure each specific operations.
func (*Feistel) EncryptMeasure ¶ added in v0.0.76
Encrypt specified block and measure each specific operations.
type FeistelKey ¶
type FeistelKey []byte // FeistelKey type definition
type FeistelMasterKey ¶
type FeistelMasterKey struct {
// contains filtered or unexported fields
}
Struct to represent a FeistelMasterKey, with salt, info and an hash function.
func NewFeistelMasterKey ¶
func NewFeistelMasterKey(rand *Randomizer, info []byte) FeistelMasterKey
Return a new FeistelMasterKey with key and salt generated by specified Randomizer. The info parameter can be nil.
type Header ¶ added in v0.0.5
type Header struct {
// contains filtered or unexported fields
}
Struct to represent an Header. It's equivalent to an HeaderBlock, but with convenient types.
func NewHeaderFromFile ¶ added in v0.0.5
func NewHeaderFromFile(path string, profile ProfileType, split int) Header
Return a Header for specified file paht, profile type and split number.
func (Header) Profile ¶ added in v0.0.5
func (h Header) Profile(profile ProfileType) ProfileStore
Get related ProfileStore for specified profile.
func (Header) ProfilesToSeq ¶ added in v0.0.5
Convert Profiles to seq as [16]byte
func (Header) ToDataBlock ¶ added in v0.0.5
func (h Header) ToDataBlock() HeaderDataBlock
return an Header Data Block
func (Header) ToInitBlock ¶ added in v0.0.5
func (h Header) ToInitBlock() HeaderInitBlock
return an HeaderInitBlock.
func (Header) ValidSignature ¶ added in v0.0.5
Check if signature is valid.
type HeaderBlock ¶ added in v0.0.5
type HeaderBlock struct {
HeaderInitBlock
HeaderDataBlock
}
Struct to represent a Block Header wich embed Header Init Block and Header Data Block.
func NewHeaderBlockFromContent ¶ added in v0.0.5
func NewHeaderBlockFromContent(content HeaderContent) HeaderBlock
Return a new Header Block from specified HeaderContent.
func (HeaderBlock) ToContent ¶ added in v0.0.7
func (hb HeaderBlock) ToContent() HeaderContent
Convert HeaderBlock to HeaderContent
func (HeaderBlock) ToHeader ¶ added in v0.0.95
func (hb HeaderBlock) ToHeader() Header
Convert HeaderBlock to HeaderContent
type HeaderContent ¶ added in v0.0.5
type HeaderContent [HeaderLength]byte // HeaderContent type definition
type HeaderDataBlock ¶ added in v0.0.5
type HeaderDataBlock struct {
// contains filtered or unexported fields
}
Struct to represent a Data Block Header wich contains related information as []byte to encode/decode a file.
func (HeaderDataBlock) ToBytes ¶ added in v0.0.7
func (hdb HeaderDataBlock) ToBytes() []byte
Convert HeaderDataBlock to []byte
type HeaderInitBlock ¶ added in v0.0.5
type HeaderInitBlock struct {
// contains filtered or unexported fields
}
Struct to represent an Init Block Header wich contains signature & pos of Data Block Header as []byte.
func (HeaderInitBlock) ToBytes ¶ added in v0.0.7
func (hib HeaderInitBlock) ToBytes() []byte
Convert HeaderInitBlock to []byte
type MahChaKey ¶
type MahChaKey struct {
// contains filtered or unexported fields
}
Struct to represent a MahChaKey.
func NewMahChaKey ¶
func NewMahChaKey() *MahChaKey
Return a new MahChaKey with secured key and nonce generated by crypto/rand source generator. The MahChaKey will use internaly a Randomizer sourced by a ChaCha20Source initialized with key and nonce.
func NewMahChaKeyFrom ¶
Return a MahChaKey from specified key and nonce. The MahChaKey will use internaly a Randomizer sourced by a ChaCha20Source initialized with key and nonce.
func (*MahChaKey) DecryptHeader ¶ added in v0.0.11
func (*MahChaKey) EncryptHeader ¶ added in v0.0.7
func (*MahChaKey) GetRandomizer ¶ added in v0.0.16
func (k *MahChaKey) GetRandomizer() *Randomizer
Should be removed
func (*MahChaKey) InitEncode ¶ added in v0.0.8
func (k *MahChaKey) InitEncode(path string, profile ProfileType, split int) Header
Initiate encoding.
func (*MahChaKey) ResetRandomizer ¶
func (k *MahChaKey) ResetRandomizer()
Reset the internal random generator.
type Measure ¶ added in v0.0.75
type Measure struct {
Tasks []*MeasureTask
LabelWidth int
DefaultPrecision int
}
func NewMeasure ¶ added in v0.0.75
func NewMeasure() *Measure
func (*Measure) NewCustomTask ¶ added in v0.0.75
func (m *Measure) NewCustomTask(msg string, precision int) *MeasureTask
func (*Measure) NewTask ¶ added in v0.0.75
func (m *Measure) NewTask(msg string) *MeasureTask
type MeasureTask ¶ added in v0.0.75
func NewMeasureTask ¶ added in v0.0.75
func NewMeasureTask(msg string, precision int, start time.Time) *MeasureTask
func (*MeasureTask) Report ¶ added in v0.0.75
func (mt *MeasureTask) Report(width int) string
func (*MeasureTask) SetEnd ¶ added in v0.0.75
func (mt *MeasureTask) SetEnd()
type Nonce ¶
type Nonce [NonceLength]byte // Nonce type definition
type ProfileStore ¶ added in v0.0.5
type ProfileStore struct {
Type ProfileType
Profile Profile
// contains filtered or unexported fields
}
func GetNoiseProfileStore ¶ added in v0.0.5
func GetNoiseProfileStore(profile ProfileType) ProfileStore
func SeqToProfiles ¶ added in v0.0.95
func SeqToProfiles(seq [16]byte, profile Profile) [4]ProfileStore
type ProfileType ¶ added in v0.0.5
type ProfileType = int // ProfileType Type definition as enum
type Randomizer ¶
type Randomizer struct {
// contains filtered or unexported fields
}
Struct to represent a Randomizer using a ChaCha20 random source generator
func NewRandomizer ¶
func NewRandomizer(src *ChaCha20Source) *Randomizer
Initiate Randomizer with specified ChaCha20 source. If src is nil, it generates a new one.
func (*Randomizer) Bytes ¶
func (r *Randomizer) Bytes(size int) []byte
Generate random []byte. It impacts the internal ChaCha20 source generator state.
func (*Randomizer) CustomMask ¶
func (r *Randomizer) CustomMask(min int, max int) []byte
Generate a custom mask with a random size from specified min to max. It impacts the internal ChaCha20 source generator state.
func (*Randomizer) GetMap ¶
func (r *Randomizer) GetMap(size int) []int
Generate a shuffled map of specified size. It impacts the internal ChaCha20 source generator state.
func (*Randomizer) GetNoiseMap ¶
func (r *Randomizer) GetNoiseMap(size int, min int, max int) []int
Generate a noise map of speicified size, with random noise size between min and max. It impacts the internal ChaCha20 source generator state.
func (*Randomizer) GetRand ¶
func (r *Randomizer) GetRand() *v2.Rand
Return *v2.Rand generator sourced with current *ChaCha20.
func (*Randomizer) Noise ¶
func (r *Randomizer) Noise(size int) []byte
Generate noise as []byte of specified size. Note that it does not impacts the internal ChaCha20 generator state.
type Version ¶ added in v0.0.5
Struct to represent a Version.
func NewVersion ¶ added in v0.0.5
Return a new Version.
func (Version) IsAtLeastMajor ¶ added in v0.0.5
Check if version major is at least.
func (Version) IsAtLeastMinor ¶ added in v0.0.5
check if version minor is at least.